1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
########################################################################################
# This file is part of Spheres.
# Copyright (C) 2019 Jesusalva
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
########################################################################################
# Battle Module - Spheres
from utils import stdout, Battle
from consts import (SPH_WIDEATTACK, SPH_PIERCE, SPH_ASSAULT, SPH_HEAL, SPH_HEALALL,
SPH_NONE, SPH_ATKUP, SPH_DEFUP, SC_ATKUP, SC_DEFUP)
from battle.common import find_target, attackall, calc_dmg
# Handle sphere attacks. Unit is a member from Battle[token][scope]
def sphere_attack(token, unit, sphere, idx=0):
stdout("%s is attacking" % str(unit), 2)
stdout("Sphere selected: %d" % sphere, 2)
# Select the enemy which should be attacked
target_id=find_target(token, "enemy")
stdout("Enemy selected: %d" % target_id, 2)
target=Battle[token]["enemy"][target_id]
# Now cycle though spheres
if (sphere == SPH_WIDEATTACK):
# Wide Attack sphere
attackall(token, unit, "enemy")
elif (sphere == SPH_PIERCE):
# Pierce sphere (100% critical chance)
target["hp"]-=calc_dmg(token, unit, target, unit["atk"], 1.0)
elif (sphere == SPH_ASSAULT):
# Assault sphere (50% critical chance)
target["hp"]-=calc_dmg(token, unit, target, unit["atk"], 0.5)
elif (sphere == SPH_HEAL):
# Heal sphere (30% healing). Need to redefine target
target_id=find_target(token, "party")
target=Battle[token]["party"][target_id]
target["hp"]+=int(target["max_hp"]*0.3)
if (target["hp"] > target["max_hp"]):
target["hp"]=0+target["max_hp"]
elif (sphere == SPH_HEALALL):
# Heal All (negative damage to party)
unit["atk"]*=-1
attackall(token, unit, "party")
unit["atk"]*=-1
elif (sphere == SPH_NONE):
# Normal Attack
stdout("It's a normal attack!", 2)
target["hp"]-=calc_dmg(token, unit, target, unit["atk"])
elif (sphere == SPH_ATKUP):
# Attack up sphere: Add SC_ATKUP to all members (even dead ones)
for target in Battle[token]["party"]:
if not (target["status_effects"] & SC_ATKUP):
target["status_effects"]=target["status_effects"]|SC_ATKUP
elif (sphere == SPH_DEFUP):
# Defense up sphere: Add SC_DEFUP to all members (even dead ones)
for target in Battle[token]["party"]:
if not (target["status_effects"] & SC_DEFUP):
target["status_effects"]=target["status_effects"]|SC_DEFUP
else:
# Something went wrong, report and do nothing
print ("\033[1;31mERROR, INVALID SPHERE ID: %d\033[0m\n" % sphere)
return False
# We are done!
#stdout("Attack completed")
Battle[token]["log"].append(["party", idx, sphere, "enemy", target_id])
return True
|