aboutsummaryrefslogtreecommitdiff
path: root/go/game/action.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-26 22:16:10 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:44 +0100
commit926ca5cdd20a39e3e05aaa3486cb166718dab5ca (patch)
tree3d7bc8a0e1e0be1ce8d92d5503bdede878e718e9 /go/game/action.go
parent8720ebf9c74d9e11001772b5c00c293fa3a8b9e5 (diff)
downloadmuhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.tar.gz
muhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.zip
intermeditae commit
Diffstat (limited to 'go/game/action.go')
-rw-r--r--go/game/action.go110
1 files changed, 78 insertions, 32 deletions
diff --git a/go/game/action.go b/go/game/action.go
index c121d0c8..f3b242b5 100644
--- a/go/game/action.go
+++ b/go/game/action.go
@@ -8,7 +8,6 @@ import (
type ActionPrototype interface {
Specialize(...interface{}) Action
String() string
- CanPayCosts(s *State) bool
}
type Action interface {
@@ -19,19 +18,15 @@ type Action interface {
type PassPriorityAction struct{ Source *Player }
-func (*PassPriorityAction) Declare(*State) {}
func (*PassPriorityAction) Resolve(*State) {}
func (*PassPriorityAction) PayCosts(*State) bool { return true }
func (*PassPriorityAction) String() string { return "pass" }
func NewPassPriorityAction(p *Player) Action { return &PassPriorityAction{p} }
-type FastAction interface {
- Action
-}
-
type ActionBase struct {
Source interface{}
Card *Card
+ Targets interface{}
resolveFunc func(s *State)
costFunc func(s *State) bool
desc string
@@ -59,16 +54,16 @@ func (a *ActionBase) String() string {
type PlayAction struct {
ActionBase
- targets interface{}
}
func NewPlayAction(p *Player, c *Card, targets interface{}) Action {
costFunc := func(*State) bool {
cost := c.GetPlayCosts()
- if p.Ressource < cost {
+
+ if p.Resource < cost {
return false
}
- p.Ressource -= cost
+ p.Resource -= cost
return true
}
return NewPlayActionWithSpecialCosts(p, c, targets, costFunc)
@@ -83,8 +78,12 @@ func NewPlayActionWithSpecialCosts(p *Player, c *Card, targets interface{},
s.ResolvePlay(p, c, targets)
}
- desc := fmt.Sprintf("p %s@%v", c.Name, targets)
- return &PlayAction{ActionBase{p, c, resolveFunc, costFunc, desc}, targets}
+ desc := fmt.Sprintf("play %s@%v", c.Name, targets)
+ return &PlayAction{ActionBase{p, c, targets, resolveFunc, costFunc, desc}}
+}
+
+type MoveAction struct {
+ ActionBase
}
type MoveActionPrototype struct {
@@ -95,10 +94,6 @@ func NewMoveActionPrototype(u *Unit) *MoveActionPrototype {
return &MoveActionPrototype{u}
}
-func (proto *MoveActionPrototype) CanPayCosts(s *State) bool {
- return proto.Unit.AvailMoveActions > 0
-}
-
func (proto *MoveActionPrototype) String() string {
return fmt.Sprintf("move %s", proto.Unit.Movement.String())
}
@@ -112,7 +107,6 @@ func (proto *MoveActionPrototype) Specialize(args ...interface{}) Action {
}
costFunc := func(*State) bool {
- log.Printf("Move Actions of %s: %d\n", u.GetCard().Name, u.AvailMoveActions)
if u.AvailMoveActions < 1 {
return false
}
@@ -121,15 +115,15 @@ func (proto *MoveActionPrototype) Specialize(args ...interface{}) Action {
}
desc := fmt.Sprintf("-> %s", target.Position.String())
- return &ActionBase{u, u.GetCard(), resolveFunc, costFunc, desc}
+ return &MoveAction{ActionBase{u, u.GetCard(), target, resolveFunc, costFunc, desc}}
}
-type AttackActionPrototype struct {
- Unit *Unit
+type AttackAction struct {
+ ActionBase
}
-func (proto *AttackActionPrototype) CanPayCosts(s *State) bool {
- return proto.Unit.AvailAttackActions > 0
+type AttackActionPrototype struct {
+ Unit *Unit
}
func NewAttackActionPrototype(u *Unit) *AttackActionPrototype {
@@ -157,7 +151,7 @@ func (proto *AttackActionPrototype) Specialize(args ...interface{}) Action {
}
desc := fmt.Sprintf("x %s", target.GetTile().Position.String())
- return &ActionBase{u, u.GetCard(), resolveFunc, costFunc, desc}
+ return &AttackAction{ActionBase{u, u.GetCard(), target, resolveFunc, costFunc, desc}}
}
type FullActionPrototype struct {
@@ -168,10 +162,6 @@ func NewFullActionPrototype(u *Unit) *FullActionPrototype {
return &FullActionPrototype{u}
}
-func (proto *FullActionPrototype) CanPayCosts(s *State) bool {
- return proto.Unit.AvailAttackActions > 0 && proto.Unit.AvailMoveActions > 0
-}
-
func (proto *FullActionPrototype) String() string {
return "full_action"
}
@@ -188,7 +178,7 @@ func (proto *FullActionPrototype) Specialize(args ...interface{}) Action {
return true
}
desc := "full_action"
- return &ActionBase{u, u.GetCard(), resolveFunc, costFunc, desc}
+ return &ActionBase{u, u.GetCard(), nil, resolveFunc, costFunc, desc}
}
type FreeActionPrototype struct {
@@ -196,10 +186,6 @@ type FreeActionPrototype struct {
canPayFunc func(s *State) bool
}
-func (proto *FreeActionPrototype) CanPayCosts(s *State) bool {
- return proto.canPayFunc(s)
-}
-
func (proto *FreeActionPrototype) String() string {
return "free_action"
}
@@ -209,9 +195,69 @@ func (proto *FreeActionPrototype) Specialize(args ...interface{}) Action {
resolveFunc := args[0].(func(s *State))
costFunc := args[1].(func(s *State) bool)
desc := "free_action"
- return &FreeAction{ActionBase{p, p.GetCard(), resolveFunc, costFunc, desc}}
+ return &FreeAction{ActionBase{p, p.GetCard(), nil, resolveFunc, costFunc, desc}}
}
type FreeAction struct {
ActionBase
}
+
+type BuyAction struct {
+ player *Player
+ card *Card
+}
+
+func (a *BuyAction) Resolve(s *State) {
+ log.Println("Move", a.card.Name, "into", a.player.Name, "discard pile")
+ a.player.Store.MoveCard(a.card, a.player.DiscardPile)
+}
+
+func (a *BuyAction) PayCosts(*State) bool {
+ if a.card.BuyCost < 0 || a.card.BuyCost > a.player.Resource {
+ return false
+ }
+
+ a.player.Resource -= a.card.BuyCost
+ return true
+}
+
+func (a *BuyAction) String() string { return fmt.Sprintf("%s buy %s", a.player.Name, a.card.Name) }
+
+func NewBuyAction(p *Player, c *Card) *BuyAction {
+ return &BuyAction{p, c}
+}
+
+type UpkeepAction struct {
+ player *Player
+ unit *Unit
+ pay bool
+}
+
+func (a *UpkeepAction) Resolve(s *State) {
+ if a.pay {
+ a.player.Resource -= a.unit.Upkeep
+ } else {
+ s.DestroyPermanent(a.unit)
+ }
+}
+
+func (a *UpkeepAction) PayCosts(*State) bool {
+ if a.unit.Upkeep > a.player.Resource {
+ return false
+ }
+
+ a.player.Resource -= a.unit.Upkeep
+ return true
+}
+
+func (a *UpkeepAction) String() string {
+ if a.pay {
+ return fmt.Sprintf("%s keep %s", a.player.Name, a.unit.Tile.Position.String())
+ }
+
+ return fmt.Sprintf("%s disband %s", a.player.Name, a.unit.Tile.Position.String())
+}
+
+func NewUpkeepAction(p *Player, u *Unit, pay bool) *UpkeepAction {
+ return &UpkeepAction{p, u, pay}
+}