diff options
Diffstat (limited to 'go/game/unit.go')
| -rw-r--r-- | go/game/unit.go | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/go/game/unit.go b/go/game/unit.go index aa535086..f4f7d9cc 100644 --- a/go/game/unit.go +++ b/go/game/unit.go @@ -1,9 +1,5 @@ package game -import ( - "log" -) - type UnitState int const ( @@ -51,18 +47,18 @@ func NewUnit(card *Card, tile *Tile, owner *Player) *Unit { } u := &Unit{ - NewPermanentBase(card, tile, owner), - card.Values["health"].(int), - movement, - attack, - upkeep, - []*FullActionPrototype{}, - []*FreeActionPrototype{}, - []UnitState{}, - 1, - 1, + PermanentBase: NewPermanentBase(card, tile, owner), + Health: card.Values["health"].(int), + Movement: movement, + Attack: attack, + Upkeep: upkeep, + AvailMoveActions: 1, + AvailAttackActions: 1, } + u.FullActions = card.Impl.fullActionPrototypes(u) + u.FreeActions = card.Impl.freeActionPrototypes(u) + tile.Permanent = u return u } @@ -72,16 +68,16 @@ func NewUnitFromPath(cardPath string, tile *Tile, owner *Player) *Unit { } func (u *Unit) move(s *State, tile *Tile) { - u.Tile.Permanent = nil + u.tile.Permanent = nil tile.Permanent = u - u.Tile = tile + u.tile = tile } func (u *Unit) MoveRangeTiles(m *Map) []*Tile { tiles := []*Tile{} // TODO: build graph only containing possible tile in movement range graph := m.generateMapGraphFor(u) - for _, pos := range PositionsInRange(u.Tile.Position, u.Movement.Range, false) { + for _, pos := range PositionsInRange(u.tile.Position, u.Movement.Range, false) { tile := m.TileAt(pos) if tile == nil || !u.IsAvailableTile(tile) { continue @@ -116,11 +112,11 @@ func (u *Unit) AttackablePermanents(m *Map) []Permanent { } func (u *Unit) AttackableEnemyPermanents(m *Map) []Permanent { - controller := u.GetController() + controller := u.Controller() permanents := []Permanent{} for _, t := range u.AttackableTiles(m) { if t.Permanent != nil && t.Permanent.Attackable() && - t.Permanent.GetController() != controller { + t.Permanent.Controller() != controller { permanents = append(permanents, t.Permanent) } @@ -129,15 +125,15 @@ func (u *Unit) AttackableEnemyPermanents(m *Map) []Permanent { } func (u *Unit) IsAvailableTile(tile *Tile) bool { - return tile.IsAvailableForCard(u.Card) + return tile.IsAvailableForCard(u.card) } func (u *Unit) Fight(p Permanent) { - p.AddDamage(u.Attack.Damage) + DealDamage(u, p, u.Attack.Damage) } func (u *Unit) IsDestroyed() bool { - return u.PermanentBase.Damage >= u.Health + return u.damage >= u.Health } func (u *Unit) Attackable() bool { @@ -151,13 +147,13 @@ func (u *Unit) HasFullAction() bool { func (u *Unit) FullAction() { } -func (u *Unit) GetAvailActionPrototypes() []ActionPrototype { +func (u *Unit) AvailActionPrototypes() []ActionPrototype { prototypes := []ActionPrototype{} if u.AvailMoveActions > 0 && u.Movement != INVALID_MOVEMENT() { prototypes = append(prototypes, NewMoveActionPrototype(u)) } - m := u.GetController().gameState.Map + m := u.Controller().gameState.Map if u.AvailAttackActions > 0 && u.Attack != INVALID_ATTACK() && len(u.AttackableEnemyPermanents(m)) > 0 { |
