Skip to content

Commit c8386ba

Browse files
committed
Readability udpates and statusrules.
1 parent 115aa27 commit c8386ba

File tree

7 files changed

+65
-44
lines changed

7 files changed

+65
-44
lines changed

Projects/damage-engine/scripts/combatant.gd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ const BACK := 1
1111
@export var weapon: Equipment
1212
@export var armor: Equipment
1313

14-
# Defender’s per-element tags: { Element.Type.FIRE: "weak"/"resist"/"immune"/"absorb"/"normal" }
15-
@export var element_resist: Dictionary[Element.Type, String] = {}
14+
# Defender’s per-element tags using Element.ResistTag
15+
# Example: { Element.Type.FIRE: Element.ResistTag.WEAK }
16+
@export var element_resist: Dictionary[Element.Type, Element.ResistTag] = {}
1617

1718
# Active status flags
1819
var status: Dictionary[StatusEffects.Status, bool] = {}

Projects/damage-engine/scripts/damage_engine.gd

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# res://scripts/DamageEngine.gd
1+
# res://scripts/damage_engine.gd
22
extends Node
33
class_name FF4DamageEngine
44

5-
# ---------- Inner result type ----------
5+
# Result type for combat resolution
66
class CombatResult:
77
var amount: int
88
var crit: bool
@@ -28,7 +28,7 @@ class CombatResult:
2828
func pretty_str() -> String:
2929
return "{amount:%d, hit:%s, crit:%s, absorbed:%s, elements:%s}" % [amount, str(hit), str(crit), str(absorbed), str(elements)]
3030

31-
# ---------- Tunables ----------
31+
# Tunables
3232
const CRIT_BASE := 0.03 # base crit chance (no LUK)
3333
const CRIT_AGI_SCALE := 0.0015 # +0.15% crit per AGI
3434
const CRIT_MULT := 1.5
@@ -47,14 +47,14 @@ const BLIND_HIT_MULT := 0.5 # blind halves hit chance
4747
const BACKROW_OUT := 0.5
4848
const BACKROW_IN := 0.5
4949

50-
# ---------- Helpers ----------
50+
# Helpers
5151
static func _rand_range(a: float, b: float) -> float:
5252
return a + randf() * (b - a)
5353

5454
static func _roll_crit(agi: int) -> bool:
5555
return randf() < (CRIT_BASE + float(agi) * CRIT_AGI_SCALE)
5656

57-
static func _element_mult(attacker_elems: Array[Element.Type], defender_resist: Dictionary[Element.Type, String]) -> float:
57+
static func _element_mult(attacker_elems: Array[Element.Type], defender_resist: Dictionary[Element.Type, Element.ResistTag]) -> float:
5858
return Element.vs_defender(attacker_elems, defender_resist)
5959

6060
static func _row_mult(attacker: Combatant, defender: Combatant) -> float:
@@ -81,13 +81,13 @@ static func physical_damage(attacker: Combatant, defender: Combatant) -> CombatR
8181
var elems_miss := attacker.weapon_elements()
8282
return CombatResult.new(0, false, false, elems_miss, false)
8383

84-
var A := attacker.total_stats()
85-
var D := defender.total_stats()
84+
var att_stats := attacker.total_stats()
85+
var def_stats := defender.total_stats()
8686

87-
var atk_term := A.atk + int(floor(A.strn / 2.0))
88-
var def_term := D.def_ + int(floor(D.vit / 2.0))
87+
var atk_term := att_stats.atk + int(floor(att_stats.strn / 2.0))
88+
var def_term := def_stats.def_ + int(floor(def_stats.vit / 2.0))
8989

90-
var crit := _roll_crit(A.agi)
90+
var crit := _roll_crit(att_stats.agi)
9191
var def_factor : float
9292
if crit:
9393
def_factor = 0.25
@@ -118,11 +118,11 @@ static func physical_damage(attacker: Combatant, defender: Combatant) -> CombatR
118118
# ---------- Magical damage (single-element) ----------
119119
# Uses WIS for offense, WIL for resistance.
120120
static func magical_damage(attacker: Combatant, defender: Combatant, power: int, elem: Element.Type) -> CombatResult:
121-
var A := attacker.total_stats()
122-
var D := defender.total_stats()
121+
var att_stats := attacker.total_stats()
122+
var def_stats := defender.total_stats()
123123

124-
var mag_term := power + int(floor(A.wis / 2.0)) + int(floor(A.mag / 2.0))
125-
var mres := int(floor(D.mdef / 2.0) + floor(D.wil / 2.0))
124+
var mag_term := power + int(floor(att_stats.wis / 2.0)) + int(floor(att_stats.mag / 2.0))
125+
var mres := int(floor(def_stats.mdef / 2.0) + floor(def_stats.wil / 2.0))
126126

127127
var base : int = max(1, mag_term - mres)
128128
base = int(round(base * _rand_range(VARIANCE_LOW, VARIANCE_HIGH)))

Projects/damage-engine/scripts/damage_test.gd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ func _ready():
2626
randomize()
2727
# Example enemy resistances
2828
foe.element_resist = {
29-
Element.Type.FIRE: "weak",
30-
Element.Type.ICE: "resist",
31-
Element.Type.HOLY: "immune",
32-
Element.Type.DARK: "absorb"
29+
Element.Type.FIRE: Element.ResistTag.WEAK,
30+
Element.Type.ICE: Element.ResistTag.RESIST,
31+
Element.Type.HOLY: Element.ResistTag.IMMUNE,
32+
Element.Type.DARK: Element.ResistTag.ABSORB
3333
}
3434

3535
# Baseline (no statuses)

Projects/damage-engine/scripts/element.gd

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ extends Resource
33

44
enum Type { NONE, FIRE, ICE, LIGHTNING, HOLY, DARK, POISON }
55

6-
# Defender resist tags
7-
# normal = 1.0
8-
# weak = 1.5
9-
# resist = 0.5
10-
# immune = 0.0
11-
# absorb = -1.0 (heals)
12-
const MULT := {
13-
"normal": 1.0,
14-
"weak": 1.5,
15-
"resist": 0.5,
16-
"immune": 0.0,
17-
"absorb": -1.0
6+
# Enumerated defender resistance tag
7+
enum ResistTag { NORMAL, WEAK, RESIST, IMMUNE, ABSORB }
8+
9+
# Defender resist multipliers by tag
10+
# NORMAL: 1.0
11+
# WEAK: 1.5
12+
# RESIST: 0.5
13+
# IMMUNE: 0.0
14+
# ABSORB: -1.0 (heals)
15+
const MULT: Dictionary[ResistTag, float] = {
16+
ResistTag.NORMAL: 1.0,
17+
ResistTag.WEAK: 1.5,
18+
ResistTag.RESIST: 0.5,
19+
ResistTag.IMMUNE: 0.0,
20+
ResistTag.ABSORB: -1.0
1821
}
1922

2023
static func combine(elems: Array[Element.Type]) -> Array[Element.Type]:
@@ -24,10 +27,11 @@ static func combine(elems: Array[Element.Type]) -> Array[Element.Type]:
2427
out.append(e)
2528
return out
2629

27-
static func vs_defender(attacker_elems: Array[Element.Type], defender_resist: Dictionary[Element.Type, String]) -> float:
28-
if attacker_elems.is_empty(): return 1.0
30+
static func vs_defender(attacker_elems: Array[Element.Type], defender_resist: Dictionary[Element.Type, ResistTag]) -> float:
31+
if attacker_elems.is_empty():
32+
return 1.0
2933
var m := 1.0
3034
for e in attacker_elems:
31-
var tag := str(defender_resist.get(e, "normal"))
35+
var tag: ResistTag = defender_resist.get(e, ResistTag.NORMAL)
3236
m *= float(MULT.get(tag, 1.0))
3337
return m
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
class_name StatusEffects
22
extends Resource
3+
const DefaultStatusRules = preload("res://scripts/status_rules.gd")
34

45
# Enumerated status flags
56
enum Status { DEFENDING, PROTECT, SHELL, BLIND, BERSERK, POISON }
67

7-
# Default boolean flags keyed by Status enum
8+
# Rules resource allows designers to tweak multipliers without code changes
9+
static var RULES: StatusRules = StatusRules.new()
10+
11+
static func set_rules(rules: StatusRules) -> void:
12+
RULES = rules
13+
814
const KEYS: Dictionary[Status, bool] = {
915
Status.DEFENDING: false, # Defend command (halves incoming)
1016
Status.PROTECT: false, # Physical incoming halved
@@ -17,19 +23,19 @@ const KEYS: Dictionary[Status, bool] = {
1723
static func has(s: Dictionary[Status, bool], k: Status) -> bool:
1824
return bool(s.get(k, false))
1925

20-
static func physical_out_mult(s: Dictionary[Status, bool]) -> float:
26+
static func physical_out_mult(s: Dictionary[Status, bool], rules: StatusRules = RULES) -> float:
2127
var m := 1.0
22-
if has(s, Status.BERSERK): m *= 1.5
23-
if has(s, Status.BLIND): m *= 0.75
28+
if has(s, Status.BERSERK): m *= rules.berserk_out_mult
29+
if has(s, Status.BLIND): m *= rules.blind_out_mult
2430
return m
2531

26-
static func physical_in_mult(s: Dictionary[Status, bool]) -> float:
32+
static func physical_in_mult(s: Dictionary[Status, bool], rules: StatusRules = RULES) -> float:
2733
var m := 1.0
28-
if has(s, Status.PROTECT): m *= 0.5
29-
if has(s, Status.DEFENDING): m *= 0.5
34+
if has(s, Status.PROTECT): m *= rules.protect_in_mult
35+
if has(s, Status.DEFENDING): m *= rules.defending_in_mult
3036
return m
3137

32-
static func magical_in_mult(s: Dictionary[Status, bool]) -> float:
38+
static func magical_in_mult(s: Dictionary[Status, bool], rules: StatusRules = RULES) -> float:
3339
var m := 1.0
34-
if has(s, Status.SHELL): m *= 0.5
40+
if has(s, Status.SHELL): m *= rules.shell_in_mult
3541
return m
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extends Resource
2+
class_name StatusRules
3+
4+
# Designer-tunable multipliers for status effects
5+
@export var berserk_out_mult: float = 1.5
6+
@export var blind_out_mult: float = 0.75
7+
@export var protect_in_mult: float = 0.5
8+
@export var defending_in_mult: float = 0.5
9+
@export var shell_in_mult: float = 0.5
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://kumkbswxkkvw

0 commit comments

Comments
 (0)