commit 4323a9dda78bae3b59a6033221f9dfd774b6b240
parent ab5d66fb6f889110148f82e8ad3f028da036d4c7
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Wed, 25 Nov 2020 11:20:08 -0600
Added affinity calc to damage
Diffstat:
2 files changed, 45 insertions(+), 13 deletions(-)
diff --git a/src/constants.py b/src/constants.py
@@ -43,6 +43,14 @@ SCENE_JSON_PATH = os.path.join(JSON_PATH, "scenes")
# Piece constants
CHARBASE = json.load(open(os.path.join(JSON_PATH, "pieces.json")))
AFFINITIES = ("Fire", "Wind", "Life", "Miasma", "Water", "Lightning")
+AFFINITY_RELATIONS = {
+ "Fire" : { "Opposite" : "Wind", "Weak" : "Water", "Strong" : "Life" },
+ "Wind" : { "Opposite" : "Fire", "Weak" : "Lightning", "Strong" : "Miasma" },
+ "Life" : { "Opposite" : "Miasma", "Weak" : "Fire", "Strong" : "Water" },
+ "Miasma" : { "Opposite" : "Life", "Weak" : "Wind", "Strong" : "Lightning" },
+ "Water" : { "Opposite" : "Lightning", "Weak" : "Life", "Strong" : "Fire" },
+ "Lightning" : { "Opposite" : "Water", "Weak" : "Miasma", "Strong" : "Wind" }
+}
# Item constants
ITEMBASE = json.load(open(os.path.join(JSON_PATH, "items.json")))
@@ -83,7 +91,7 @@ STATE_MODES = enum.Enum('STATE_MODES', 'Main_Menu_Mode Battle_Mode Still_Scene_M
CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Turn_Normal Turn_Select_Move Turn_Select_Attack Turn_Watch_Move Turn_Watch_Attack Turn_Display_Stats Still_Scene_Normal')
FACE_DIR = enum.Enum('FACE_DIR', 'U D L R')
GAME_EFFECTS = enum.Enum('GAME_EFFECTS', 'ef_game_quit ef_game_switch_mode')
-ATTACK_NOTATIONS = enum.Enum('ATTACK_NOTATIONS', 'backattack critical counter opposite weakness riposte ignoredef parry block sweep miss onetwo stun')
+ATTACK_NOTATIONS = enum.Enum('ATTACK_NOTATIONS', 'backattack critical counter opposite weakness resist riposte ignoredef parry block sweep miss onetwo stun')
# Error types
class ManagerBusError(Exception):
diff --git a/src/piece.py b/src/piece.py
@@ -479,6 +479,11 @@ class Piece(entity.Entity):
self.attack_anim_timer = 90
# Tell the other guy to be damaged
+ # Affinities
+ aff = None
+ if ITEMBASE[self.equipment["weapon"]]["type"] in ("Staff", "Book", "Wand"):
+ aff = self.affinity
+ # Attack notations
notelist = []
# Bonus for back attack
ba = 0
@@ -497,33 +502,52 @@ class Piece(entity.Entity):
raw_dam += round((self.active_stats[bon] + random.randint(0, self.active_stats["LUK"] // 2)) * 0.2)
elif raw_dam < 0:
raw_dam = 0
- self.attack_target.set_be_damaged_action(round(raw_dam * ca), notelist)
+ self.attack_target.set_be_damaged_action(round(raw_dam * ca), aff, notelist)
- def set_be_damaged_action(self, raw_damage, notations):
+ def set_be_damaged_action(self, raw_damage, affinity, notations):
"""
- Setup the action of being damaged. 'notations'
- is a list of enum vals that are parsed to
+ Setup the action of being damaged. 'affinity'
+ is the elemental affinity of the attack. It is
+ figured into damage calclulation here in the
+ defensive portion of the action. The 'notations'
+ var is a list of enum vals that are parsed to
indicate special things that caused the amount
of damage to change. Certain notations can also
indicate that the colors of the damage numbers
should change.
"""
- # TODO: This could eventually take a 'damage_aff' var which determines
- # the element of the damage and could be figured into the post-def
- # calculations to account for elemental strength/weakness
-
- # First, notation handling
+ # First, calculate based on affinity
+ affmod = 1
+ if affinity != None:
+ if affinity == AFFINITY_RELATIONS[self.affinity]["Opposite"]:
+ affmod = 1.5
+ notations.append(ATTACK_NOTATIONS.opposite)
+ elif affinity == AFFINITY_RELATIONS[self.affinity]["Weak"]:
+ affmod = 2.5
+ notations.append(ATTACK_NOTATIONS.weakness)
+ elif affinity == AFFINITY_RELATIONS[self.affinity]["Strong"]:
+ affmod = 0.5
+ notations.append(ATTACK_NOTATIONS.resist)
+
+ # Next, notation handling
for n in notations:
if n == ATTACK_NOTATIONS.backattack:
self.damage_notations.append("Back Attack!")
elif n == ATTACK_NOTATIONS.critical:
self.damage_notations.append("Critical!")
-
+ elif n == ATTACK_NOTATIONS.opposite:
+ self.damage_notations.append("Conflict!")
+ elif n == ATTACK_NOTATIONS.weakness:
+ self.damage_notations.append("Weak!")
+ elif n == ATTACK_NOTATIONS.resist:
+ self.damage_notations.append("Resist!")
+
+ # Lastly, go through with the damage
if raw_damage <= 0:
self.damage_to_receive = 0
else:
- self.damage_to_receive = max(0, (raw_damage - round(self.active_stats["DEF"] * 1.4)) + random.randint(-(self.active_stats["LUK"] // 2),
- self.active_stats["LUK"]))
+ self.damage_to_receive = max(0,
+ round((raw_damage - (self.active_stats["DEF"] * 1.4)) + random.randint(-(self.active_stats["LUK"] // 2), self.active_stats["LUK"])) * affmod)
self.damage_timer = 100
self.being_damaged = True
self.render_damage_number()