aboutsummaryrefslogtreecommitdiff
path: root/go/client
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-20 21:13:47 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:51 +0100
commit74ae4f091755544906bb2bb38bd360cc4d7b6237 (patch)
tree01dc6ae303daaa671edbc2223091a5ffb64e6f1e /go/client
parent14f7b0274a20ffc8189d18de5031defcc15e9890 (diff)
downloadmuhqs-game-74ae4f091755544906bb2bb38bd360cc4d7b6237.tar.gz
muhqs-game-74ae4f091755544906bb2bb38bd360cc4d7b6237.zip
implement equip action
Diffstat (limited to 'go/client')
-rw-r--r--go/client/game.go53
1 files changed, 46 insertions, 7 deletions
diff --git a/go/client/game.go b/go/client/game.go
index 5ae2fbe8..f4e0f817 100644
--- a/go/client/game.go
+++ b/go/client/game.go
@@ -10,6 +10,7 @@ import (
"muhq.space/muhqs-game/go/game"
"muhq.space/muhqs-game/go/ui"
+ "muhq.space/muhqs-game/go/utils"
)
const (
@@ -214,14 +215,48 @@ func (g *Game) addPermActionChoice(perm game.Permanent, x, y int) {
p := perms[c.GetChoosen(x, y)]
g.addActionChoice(p, x, y)
}
- g.choice = ui.NewPermChoice(x, y, perms, onClick)
- g.AddWidget(g.choice)
+ g.addChoice(ui.NewPermChoice(x, y, perms, onClick))
} else {
g.selectedObject = perms[0]
g.addActionChoice(perms[0], x, y)
}
}
+func (g *Game) declareOrPromptTargets(a game.Action) {
+ if a.Targets() != nil && a.Targets().RequireSelection() {
+ g.addPrompt(a, fmt.Sprintf("Select targets for %v", a))
+ } else {
+ g.declareAction(a)
+ }
+}
+
+func (g *Game) addActionCostChoice(a game.Action, x, y int) {
+ u := a.Source().(*game.Unit)
+ if u.AvailMoveActions > 0 && u.AvailAttackActions == 0 {
+ game.UseMoveAction(a)
+ } else if u.AvailAttackActions > 0 && u.AvailMoveActions == 0 {
+ game.UseAttackAction(a)
+ }
+
+ if !a.NeedsActionCostChoice() {
+ g.declareOrPromptTargets(a)
+ return
+ }
+
+ choices := []string{"move", "attack"}
+ onClick := func(c *ui.Choice, x, y int) {
+ g.removeChoice()
+ switch choices[c.GetChoosen(x, y)] {
+ case "move":
+ game.UseMoveAction(a)
+ case "attack":
+ game.UseAttackAction(a)
+ }
+ g.declareOrPromptTargets(a)
+ }
+ g.addChoice(ui.NewChoice(x, y, utils.TypedSliceToInterfaceSlice(choices), onClick))
+}
+
func (g *Game) addActionChoice(perm game.Permanent, x, y int) {
actions := perm.CurrentlyAvailActions()
if len(actions) > 0 {
@@ -229,17 +264,21 @@ func (g *Game) addActionChoice(perm game.Permanent, x, y int) {
onClick := func(c *ui.Choice, x, y int) {
g.removeChoice()
a := actions[c.GetChoosen(x, y)]
- if a.Targets() != nil && a.Targets().RequireSelection() {
- g.addPrompt(a, fmt.Sprintf("Select targets for %v", a))
+ if a.NeedsActionCostChoice() {
+ g.addActionCostChoice(a, x, y)
} else {
- g.declareAction(a)
+ g.declareOrPromptTargets(a)
}
}
- g.choice = ui.NewActionChoice(x, y, actions, onClick)
- g.AddWidget(g.choice)
+ g.addChoice(ui.NewActionChoice(x, y, actions, onClick))
}
}
+func (g *Game) addChoice(choice *ui.Choice) {
+ g.choice = choice
+ g.AddWidget(choice)
+}
+
func (g *Game) removeChoice() {
g.RemoveWidget(g.choice)
g.choice = nil