diff options
Diffstat (limited to 'go/game/cardParsing.go')
| -rw-r--r-- | go/game/cardParsing.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/go/game/cardParsing.go b/go/game/cardParsing.go index af8e1560..3a316c4f 100644 --- a/go/game/cardParsing.go +++ b/go/game/cardParsing.go @@ -2,6 +2,7 @@ package game import ( "log" + "regexp" "strconv" "strings" ) @@ -39,6 +40,11 @@ func newParsedCardImplementation(c *Card) *parsedCardImplementation { for _, effect := range c.getEffects() { impl.parseEffect(effect) } + + for _, fullAction := range c.getCanonicalValues("full_action") { + impl.parseFullAction(fullAction) + } + return impl } @@ -48,6 +54,38 @@ func (impl *parsedCardImplementation) parseEffect(effect string) { } } +func (impl *parsedCardImplementation) parseFullAction(fullAction string) { + var resolveProtos []func(*State, *Unit) func(*State) + gainRessourceRegex := regexp.MustCompile(`gain [1-9][0-9]* resource`) + + if find := gainRessourceRegex.Find([]byte(fullAction)); find != nil { + tokens := strings.SplitN(string(find), " ", 3) + gain, err := strconv.Atoi(tokens[1]) + if err != nil { + log.Fatalf("Failed to parse resource gain full action: %s", err) + } + + resolveProto := func(_ *State, u *Unit) func(*State) { + return func(*State) { + u.controller.gainResource(gain) + } + } + resolveProtos = append(resolveProtos, resolveProto) + } + + if resolveProtos != nil { + impl.genFullActionPrototypes = func(u *Unit) []*FullActionPrototype { + fullActionPrototypes := make([]*FullActionPrototype, 0, len(resolveProtos)) + + for _, proto := range resolveProtos { + fullActionPrototypes = append(fullActionPrototypes, NewFullActionPrototype(u, proto)) + } + + return fullActionPrototypes + } + } +} + func parseUnitConstrain(constrain string) func(ctx interface{}, u *Unit) bool { enemy := strings.Contains(constrain, "enemy") if enemy { |
