From 45df9bf319d38db916ca983b8c92bb912f5ce9ee Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 8 Feb 2023 17:50:10 +0100 Subject: intermediate commit --- go/game/unit.go | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'go/game/unit.go') diff --git a/go/game/unit.go b/go/game/unit.go index 8b57b0ae..adb608ab 100644 --- a/go/game/unit.go +++ b/go/game/unit.go @@ -1,6 +1,7 @@ package game import ( + "fmt" "log" ) @@ -14,7 +15,7 @@ type Unit struct { Health int Movement Movement Attack Attack - Upkeep int + upkeep int FullActions []*FullAction FreeActions []*FreeAction // Effects []Effects @@ -48,7 +49,7 @@ func NewUnit(card *Card, tile *Tile, owner *Player) *Unit { Health: card.Values["health"].(int), Movement: movement, Attack: attack, - Upkeep: upkeep, + upkeep: upkeep, AvailMoveActions: DEFAULT_AVAIL_MOVE_ACTIONS, AvailAttackActions: DEFAULT_AVAIL_ATTACK_ACTIONS, } @@ -61,10 +62,22 @@ func NewUnit(card *Card, tile *Tile, owner *Player) *Unit { return u } +func (u *Unit) Fmt() string { + return fmt.Sprintf("%s@%v", u.Card().Name, u.TileOrContainingPermTile()) +} + +func (u *Unit) FmtWController() string { + return fmt.Sprintf("%s's %s@%v", u.Controller().Name, u.Card().Name, u.TileOrContainingPermTile()) +} + func NewUnitFromPath(cardPath string, tile *Tile, owner *Player) *Unit { return NewUnit(NewCard(cardPath), tile, owner) } +func (u *Unit) UpkeepCost() int { + return u.upkeep +} + func (u *Unit) resetBaseActions() { u.AvailMoveActions = DEFAULT_AVAIL_MOVE_ACTIONS + u.additionalMoveActions u.AvailAttackActions = DEFAULT_AVAIL_ATTACK_ACTIONS + u.additionalAttackActions @@ -238,3 +251,23 @@ func (u *Unit) onUnpile(containing Permanent) { func (u *Unit) onDrop(containing Permanent) { u.onUnpile(containing) } + +func (u *Unit) removeFullAction(tag string) { + for i, fa := range u.FullActions { + if fa.tag != tag { + continue + } + u.FullActions[i] = u.FullActions[len(u.FullActions)-1] + u.FullActions = u.FullActions[:len(u.FullActions)-1] + break + } +} + +func (u *Unit) AddDamage(damage int) { + if u.Marks(UnitMarks.Ward) > 0 { + u.adjustMarks(UnitMarks.Ward, -1) + return + } + + u.PermanentBase.AddDamage(damage) +} -- cgit v1.2.3