Skip to content

Commit

Permalink
client/towers: Now towers shoot the closes unit to them
Browse files Browse the repository at this point in the history
  • Loading branch information
xescugc committed Sep 6, 2023
1 parent 0edacc8 commit 107fd3c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions client/towers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,24 @@ func (ts *TowersStore) Reduce(state, a interface{}) interface{} {
func (ts *TowersStore) Update() error {
uts := ts.game.Units.GetState().(UnitsState).Units
tws := ts.GetState().(TowersState).Towers
for uid, u := range uts {
if len(uts) != 0 {
for _, t := range tws {
if t.Distance(u.Object) <= towerRange {
actionDispatcher.TowerAttack(uid)
var (
minDist float64 = 0
minDistUnit int
)
for uid, u := range uts {
d := t.Distance(u.Object)
if minDist == 0 {
minDist = d
}
if d <= towerRange && d < minDist {
minDist = d
minDistUnit = uid
}
}
if minDistUnit != 0 {
actionDispatcher.TowerAttack(minDistUnit)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/units.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (us *UnitsStore) Reduce(state, a interface{}) interface{} {
PlayerID: act.SummonUnit.PlayerID,
PlayerLineID: act.SummonUnit.PlayerLineID,
CurrentLineID: act.SummonUnit.CurrentLineID,
Health: 100,
Health: 10,
}
ts := us.game.Towers.GetState().(TowersState)
tws := make([]Object, 0, 0)
Expand Down

0 comments on commit 107fd3c

Please sign in to comment.