aboutsummaryrefslogtreecommitdiff
path: root/go/game/permanent.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-08-15 20:52:55 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:38 +0200
commit488f6377e6f6fd3099bb927a986d548fbc1eb63f (patch)
tree6cf6a3daed56b279a1f708cc03e551a387810640 /go/game/permanent.go
parent139ad01740eba2ff1e0a9d46593d2278b32310ce (diff)
downloadmuhqs-game-488f6377e6f6fd3099bb927a986d548fbc1eb63f.tar.gz
muhqs-game-488f6377e6f6fd3099bb927a986d548fbc1eb63f.zip
implement mace and add damage dealt events/triggers
Diffstat (limited to 'go/game/permanent.go')
-rw-r--r--go/game/permanent.go26
1 files changed, 10 insertions, 16 deletions
diff --git a/go/game/permanent.go b/go/game/permanent.go
index 4c73a26a..54404b77 100644
--- a/go/game/permanent.go
+++ b/go/game/permanent.go
@@ -135,7 +135,11 @@ func DealDamage(src, dest Permanent, damage int) {
reduction := max(armor-piercing, 0)
actualDamage = max(actualDamage-reduction, 0)
}
- dest.adjustDamage(actualDamage)
+ if actualDamage > 0 {
+ dest.adjustDamage(actualDamage)
+ src.Controller().gameState.fireEvent(
+ Event{eventType: damageDealt, affected: []any{dest}, sources: []any{src}})
+ }
}
func (p *permanentBase) adjustDamage(damage int) {
@@ -263,12 +267,7 @@ func movePermanent(p Permanent, t *Tile) {
log.Panicf("moving %v to not available tile %v", p, t)
}
- if p.ContainingPerm() != nil {
- removePermanentFromPile(p.ContainingPerm(), p)
- } else {
- leaveTile(p)
- }
-
+ leaveTileOrPile(p)
enterTileOrPile(p, t)
}
@@ -287,15 +286,10 @@ func enterTileOrPile(p Permanent, t *Tile) {
}
}
-func _leaveTile(p Permanent) {
- if p.Tile() != nil {
- p.Card().Impl.onLeaving(p.Tile())
- p.Tile().leaving(p)
- }
-}
-
-func leaveTile(p Permanent) {
- if p.Tile() != nil {
+func leaveTileOrPile(p Permanent) {
+ if cont := p.ContainingPerm(); cont != nil {
+ removePermanentFromPile(cont, p)
+ } else {
p.Card().Impl.onLeaving(p.Tile())
p.Tile().leaving(p)
p.SetTile(nil)