Skip to content

Commit

Permalink
Merge pull request #301 from DanieloV/fix-PropellerMutant-discarding-…
Browse files Browse the repository at this point in the history
…wrong-card

Fix Propeller Mutant discarding wrong card
  • Loading branch information
sindreslungaard authored Nov 8, 2024
2 parents 162201b + 12f24bd commit a040ed2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion game/cards/dm07/hedrian.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"duel-masters/game/family"
"duel-masters/game/fx"
"duel-masters/game/match"
"fmt"
"math/rand"
)

func BattleshipMutant(c *match.Card) {
Expand Down Expand Up @@ -39,6 +41,35 @@ func PropellerMutant(c *match.Card) {
c.ManaCost = 2
c.ManaRequirement = []string{civ.Darkness}

c.Use(fx.Creature, fx.When(fx.Destroyed, fx.OpponentDiscardsRandomCard))
c.Use(fx.Creature, fx.When(fx.Destroyed, func(card *match.Card, ctx *match.Context) {

// Reimplementing here OpponentDiscardsRandomCard with a twist. Since the discard is activated when this creature is destroyed,
// if it is destoryed by a spell, witouht this, there is a chance you would discard that spell from the hand since we only
// move the card from hand after its effect was applied.
// The proper solution would be to use a spellzone for when spells are active. This is a work around.

event, ok := ctx.Event.(*match.CardMoved)
if !ok {
return
}

hand, err := ctx.Match.Opponent(card.Player).Container(match.HAND)
if err != nil || len(hand) < 1 {
return
}

randomcard := hand[rand.Intn(len(hand))]
for randomcard.ID == event.Source {
if len(hand) == 1 {
return
}
randomcard = hand[rand.Intn(len(hand))]
}

discardedCard, err := ctx.Match.Opponent(card.Player).MoveCard(randomcard.ID, match.HAND, match.GRAVEYARD, card.ID)
if err == nil {
ctx.Match.ReportActionInChat(ctx.Match.Opponent(card.Player), fmt.Sprintf("%s was discarded from %s's hand by %s", discardedCard.Name, discardedCard.Player.Username(), card.Name))
}
}))

}
2 changes: 1 addition & 1 deletion game/fx/creature.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ func Creature(card *match.Card, ctx *match.Context) {
}

ctx.ScheduleAfter(func() {
card.Player.MoveCard(card.ID, match.BATTLEZONE, match.GRAVEYARD, card.ID)
card.Player.MoveCard(card.ID, match.BATTLEZONE, match.GRAVEYARD, event.Source.ID)
})
}

Expand Down

0 comments on commit a040ed2

Please sign in to comment.