aboutsummaryrefslogtreecommitdiff
path: root/go/game/cardParsing.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-08-12 08:25:58 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-12 08:25:58 +0200
commit3dc052d23f554138f74ba86b4f08f41242bd9623 (patch)
tree036805e7420e8799dbfd260529136517e88fe92a /go/game/cardParsing.go
parent4318677831e1ada30d3399f3da1dd803ceb1cbbb (diff)
downloadmuhqs-game-3dc052d23f554138f74ba86b4f08f41242bd9623.tar.gz
muhqs-game-3dc052d23f554138f74ba86b4f08f41242bd9623.zip
support parsing of simple equipment effects
Diffstat (limited to 'go/game/cardParsing.go')
-rw-r--r--go/game/cardParsing.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/go/game/cardParsing.go b/go/game/cardParsing.go
index 3b1e7cdb..1bc627b5 100644
--- a/go/game/cardParsing.go
+++ b/go/game/cardParsing.go
@@ -125,6 +125,15 @@ func (impl *dynamicCardImplementation) parseEffect(effect string) {
if strings.Contains(effect, "can be played") {
impl.parsePlayModification(effect)
}
+ // TODO: support gets and has effects
+ if strings.Contains(effect, "equipped unit gets") {
+
+ impl.parseEquipmentGetEffect(effect)
+ }
+ if strings.Contains(effect, "equipped unit has") {
+
+ impl.parseEquipmentHasEffect(effect)
+ }
}
func (impl *dynamicCardImplementation) parseFullAction(fullAction string) {
@@ -248,3 +257,70 @@ func (impl *dynamicCardImplementation) parsePlayModification(effect string) {
log.Println("Play modification for other cards are not implemented")
}
}
+
+func (impl *dynamicCardImplementation) parseEquipmentGetEffect(effect string) {
+ tokens := strings.SplitAfterN(effect, "equipped unit gets ", 2)
+ tokens = tokens[1:]
+
+ tokens = strings.Split(tokens[0], " and ")
+
+ var (
+ apply []func(Permanent)
+ remove []func(Permanent)
+ )
+
+ for _, token := range tokens {
+ x, err := parseXEffect(token)
+ if err == nil {
+ if strings.Contains(x.raw, "movement") {
+ apply = append(apply, func(p Permanent) { adjustMovement(p, x.x) })
+ remove = append(apply, func(p Permanent) { adjustMovement(p, -1*x.x) })
+ continue
+ } else if strings.Contains(x.raw, "melee") {
+ apply = append(apply, func(p Permanent) { adjustMelee(p, x.x) })
+ remove = append(apply, func(p Permanent) { adjustMelee(p, -1*x.x) })
+ continue
+ } else if strings.Contains(x.raw, "health") {
+ apply = append(apply, func(p Permanent) { adjustHealth(p, x.x) })
+ remove = append(apply, func(p Permanent) { adjustHealth(p, -1*x.x) })
+ continue
+ }
+ }
+ }
+
+ if len(apply) == 0 {
+ return
+ }
+
+ impl._onPile = func(p Permanent) {
+ for _, a := range apply {
+ a(p)
+ }
+ }
+ impl._onUnpile = func(p Permanent) {
+ for _, r := range remove {
+ r(p)
+ }
+ }
+}
+
+func (impl *dynamicCardImplementation) parseEquipmentHasEffect(effect string) {
+ tokens := strings.SplitAfterN(effect, "equipped unit has ", 2)
+ tokens = tokens[1:]
+
+ tokens = strings.Split(tokens[0], " and ")
+ if len(tokens) == 0 {
+ return
+ }
+
+ impl._onPile = func(p Permanent) {
+ for _, token := range tokens {
+ p.addTmpEffect(token)
+ }
+ }
+ impl._onUnpile = func(p Permanent) {
+ for _, token := range tokens {
+ p.removeTmpEffect(token)
+ }
+ }
+}