forked from Card-Forge/forge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIP: Radiation mechanic implementation
- Loading branch information
Showing
27 changed files
with
321 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
forge-game/src/main/java/forge/game/ability/effects/RadiationEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package forge.game.ability.effects; | ||
|
||
import com.google.common.collect.Maps; | ||
import forge.game.Game; | ||
import forge.game.GameEntityCounterTable; | ||
import forge.game.ability.AbilityUtils; | ||
import forge.game.ability.SpellAbilityEffect; | ||
import forge.game.card.Card; | ||
import forge.game.card.CounterEnumType; | ||
import forge.game.event.GameEventPlayerRadiation; | ||
import forge.game.player.Player; | ||
import forge.game.spellability.SpellAbility; | ||
|
||
import java.util.Map; | ||
|
||
public class RadiationEffect extends SpellAbilityEffect { | ||
|
||
@Override | ||
public void resolve(SpellAbility sa) { | ||
final Card host = sa.getHostCard(); | ||
final Game game = host.getGame(); | ||
final int toAdd = AbilityUtils.calculateAmount(host, sa.getParamOrDefault("Add", "0"), sa); | ||
final int toRem = AbilityUtils.calculateAmount(host, sa.getParamOrDefault("Remove", "0"), sa); | ||
final Map<Player, Integer> list = Maps.newHashMap(); | ||
|
||
GameEntityCounterTable table = new GameEntityCounterTable(); | ||
|
||
for (final Player p : getTargetPlayers(sa)) { | ||
if (!p.isInGame()) continue; | ||
|
||
list.put(p, p.getCounters(CounterEnumType.RAD)); | ||
if (toAdd >= 1) p.addRadCounters(toAdd, host, table); | ||
else if (toRem >= 1) p.removeRadCounters(toRem, host); | ||
} | ||
table.replaceCounterEffect(game, sa, true); | ||
for (final Player p : list.keySet()) { | ||
int oldCount = list.get(p); | ||
int newCount = p.getCounters(CounterEnumType.RAD); | ||
if (newCount > 0 && !p.hasRadiationEffect()) p.createRadiationEffect(host.getSetCode()); | ||
if (oldCount < newCount) game.fireEvent(new GameEventPlayerRadiation(p, host, newCount - oldCount)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -425,6 +425,8 @@ public enum CounterEnumType { | |
|
||
POISON("POISN"), | ||
|
||
RAD("RAD"), | ||
|
||
TICKET("TICKET"), | ||
|
||
// Keyword Counters | ||
|
21 changes: 21 additions & 0 deletions
21
forge-game/src/main/java/forge/game/event/GameEventPlayerRadiation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package forge.game.event; | ||
|
||
import forge.game.card.Card; | ||
import forge.game.player.Player; | ||
|
||
public class GameEventPlayerRadiation extends GameEvent { | ||
public final Player receiver; | ||
public final Card source; | ||
public final int change; | ||
|
||
public GameEventPlayerRadiation(Player recv, Card src, int chng) { | ||
receiver = recv; | ||
source = src; | ||
change = chng; | ||
} | ||
|
||
@Override | ||
public <T> T visit(IGameEventVisitor<T> visitor) { | ||
return visitor.visit(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.