From 3dc052d23f554138f74ba86b4f08f41242bd9623 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 12 Aug 2025 08:25:58 +0200 Subject: support parsing of simple equipment effects --- go/game/cardParsing.go | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'go/game/cardParsing.go') 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) + } + } +} -- cgit v1.2.3