diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-08-15 21:36:14 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:38 +0200 |
| commit | d1d2243527ff2fb7fcbf67f96622e9bd5c279d89 (patch) | |
| tree | 09aff37ad9ec06e8bfe132cea519bfc54778e9ce | |
| parent | 5d0b3ee308cd4ef93eeacc90da215cffa856d9e8 (diff) | |
| download | muhqs-game-d1d2243527ff2fb7fcbf67f96622e9bd5c279d89.tar.gz muhqs-game-d1d2243527ff2fb7fcbf67f96622e9bd5c279d89.zip | |
fix armor parsing and effective XEffect calculation
| -rw-r--r-- | go/game/cardImplementations_test.go | 23 | ||||
| -rw-r--r-- | go/game/cardParsing.go | 6 | ||||
| -rw-r--r-- | go/game/permanent.go | 18 |
3 files changed, 39 insertions, 8 deletions
diff --git a/go/game/cardImplementations_test.go b/go/game/cardImplementations_test.go index 14339df7..5cef65ca 100644 --- a/go/game/cardImplementations_test.go +++ b/go/game/cardImplementations_test.go @@ -232,3 +232,26 @@ func TestMace(t *testing.T) { t.Fatal("mace trigger not removed") } } + +func TestArmor(t *testing.T) { + s := NewLocalState() + m := newEmpty2x2Map() + s.SetMap(m) + + player := s.AddNewPlayer("p", NewDeck()) + opo := s.AddNewPlayer("o", NewDeck()) + + a := s.addNewUnit(NewCard("base/archer"), Position{0, 0}, player) + p := s.addNewUnit(NewCard("base/pioneer"), Position{0, 1}, opo) + armor := newEquipment(NewCard("equipments/armor"), p, opo) + s.addPermanent(armor) + + if armor, err := p.XEffect("armor"); armor != 1 { + t.Fatal("pioneer not armored", armor, err) + } + + s.fight(a, p) + if p.Damage() != 0 { + t.Fatal("pioneer received damage") + } +} diff --git a/go/game/cardParsing.go b/go/game/cardParsing.go index 9091c1fc..c08a241f 100644 --- a/go/game/cardParsing.go +++ b/go/game/cardParsing.go @@ -273,15 +273,15 @@ func (impl *dynamicCardImplementation) parseEquipmentGetEffect(effect string) { 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 + } else if strings.Contains(x.raw, "armor") { + apply = append(apply, func(p Permanent) { p.addTmpEffect(token) }) + remove = append(apply, func(p Permanent) { p.removeTmpEffect(token) }) } } } diff --git a/go/game/permanent.go b/go/game/permanent.go index 54404b77..051e0f74 100644 --- a/go/game/permanent.go +++ b/go/game/permanent.go @@ -171,27 +171,31 @@ func (p *permanentBase) HasEffect(effect string) bool { } func (p *permanentBase) XEffect(effect string) (int, error) { + found := false x := 0 xE, err := p.card.getXEffect(effect) - if err != nil { - return 0, err + if err == nil { + x = xE.x + found = true } - x = xE.x if x < 0 { log.Panic("initial negativ x effect") } for _, e := range p.tmpEffects { + log.Println(effect, e) if !strings.Contains(e, effect) { continue } tmpX, err := parseXEffect(e) if err != nil { - return 0, err + continue } + found = true + // TODO: implement layers if tmpX.set { x = tmpX.x @@ -200,7 +204,11 @@ func (p *permanentBase) XEffect(effect string) (int, error) { } } - return x, err + if found { + return x, nil + } else { + return 0, err + } } func (p *permanentBase) Marks(mark PermanentMark) int { |
