aboutsummaryrefslogtreecommitdiff
path: root/go/game/effect.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-25 23:08:47 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:06 +0200
commit3d36d1d0254b8aeecc889a2a49cbcced458cbe9c (patch)
tree38dd0851d8eaa6535d05b97f29f65fc35655a5ef /go/game/effect.go
parent19fb1a7e5c5883f49e944b6499fa1ced207a3e39 (diff)
downloadmuhqs-game-3d36d1d0254b8aeecc889a2a49cbcced458cbe9c.tar.gz
muhqs-game-3d36d1d0254b8aeecc889a2a49cbcced458cbe9c.zip
intermediate commit
* Implement move artifact action * Fix widget update memory leak * update the highlights not during on each frame * do not update the unchanged label of a button * Allow to exit the game by pressing 'q' * Implement some cards from the magic set * Improve permanent formatting * Some tweaks to UnitAI code
Diffstat (limited to 'go/game/effect.go')
-rw-r--r--go/game/effect.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/go/game/effect.go b/go/game/effect.go
new file mode 100644
index 00000000..1fc6d5b0
--- /dev/null
+++ b/go/game/effect.go
@@ -0,0 +1,47 @@
+package game
+
+type effect interface {
+ apply(*State)
+ end(*State)
+}
+
+type dynamicEffect struct {
+ _apply func(*State)
+ _end func(*State)
+}
+
+func (e *dynamicEffect) apply(s *State) {
+ e._apply(s)
+}
+
+func (e *dynamicEffect) end(s *State) {
+ e._end(s)
+}
+
+func newAdjustmentEffect(adjust func(Permanent, int), u *Unit, delta int) effect {
+ apply := func(*State) { adjust(u, delta) }
+ end := func(*State) { adjust(u, -delta) }
+ return &dynamicEffect{apply, end}
+}
+
+func newMeleeModificationEffect(u *Unit, delta int) effect {
+ return newAdjustmentEffect(adjustMelee, u, delta)
+}
+
+func newAttackModificationEffect(u *Unit, delta int) effect {
+ return newAdjustmentEffect(adjustAttack, u, delta)
+}
+
+func newMovementModificationEffect(u *Unit, delta int) effect {
+ return newAdjustmentEffect(adjustMovement, u, delta)
+}
+
+func newHealthModificationEffect(u *Unit, delta int) effect {
+ return newAdjustmentEffect(adjustHealth, u, delta)
+}
+
+func newTmpEffect(p Permanent, effect string) effect {
+ apply := func(*State) { p.addTmpEffect(effect) }
+ end := func(*State) { p.removeTmpEffect(effect) }
+ return &dynamicEffect{apply, end}
+}