mirror of
https://github.com/magefree/mage.git
synced 2026-01-10 12:52:06 -08:00
[MAT] implemented Ob Nixilis, Captive Kingpin, refactored life lose and batches events (#11974)
This commit is contained in:
parent
0987e01f92
commit
50c75f05bd
8 changed files with 424 additions and 2 deletions
|
|
@ -808,6 +808,25 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
return !simultaneousEvents.isEmpty();
|
||||
}
|
||||
|
||||
public void addSimultaneousLifeLossEventToBatches(LifeLostEvent lifeLossEvent, Game game) {
|
||||
// Combine multiple life loss events in the single event (batch)
|
||||
// see GameEvent.LOST_LIFE_BATCH
|
||||
|
||||
// existing batch
|
||||
boolean isLifeLostBatchUsed = false;
|
||||
for (GameEvent event : simultaneousEvents) {
|
||||
if (event instanceof LifeLostBatchEvent) {
|
||||
((LifeLostBatchEvent) event).addEvent(lifeLossEvent);
|
||||
isLifeLostBatchUsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// new batch
|
||||
if (!isLifeLostBatchUsed) {
|
||||
addSimultaneousEvent(new LifeLostBatchEvent(lifeLossEvent), game);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSimultaneousDamage(DamagedEvent damagedEvent, Game game) {
|
||||
// Combine multiple damage events in the single event (batch)
|
||||
// * per damage type (see GameEvent.DAMAGED_BATCH_FOR_PERMANENTS, GameEvent.DAMAGED_BATCH_FOR_PLAYERS)
|
||||
|
|
|
|||
|
|
@ -142,6 +142,10 @@ public class GameEvent implements Serializable {
|
|||
amount amount of life loss
|
||||
flag true = from combat damage - other from non combat damage
|
||||
*/
|
||||
LOST_LIFE_BATCH,
|
||||
/* LOST_LIFE_BATCH
|
||||
combines all player life lost events to a single batch (event)
|
||||
*/
|
||||
PLAY_LAND, LAND_PLAYED,
|
||||
CREATURE_CHAMPIONED,
|
||||
/* CREATURE_CHAMPIONED
|
||||
|
|
|
|||
69
Mage/src/main/java/mage/game/events/LifeLostBatchEvent.java
Normal file
69
Mage/src/main/java/mage/game/events/LifeLostBatchEvent.java
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package mage.game.events;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author jimga150
|
||||
*/
|
||||
public class LifeLostBatchEvent extends GameEvent implements BatchGameEvent<LifeLostEvent> {
|
||||
|
||||
private final Set<LifeLostEvent> events = new HashSet<>();
|
||||
|
||||
public LifeLostBatchEvent(LifeLostEvent event) {
|
||||
super(EventType.LOST_LIFE_BATCH, null, null, null);
|
||||
addEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<LifeLostEvent> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getTargets() {
|
||||
return events.stream()
|
||||
.map(GameEvent::getTargetId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return events
|
||||
.stream()
|
||||
.mapToInt(GameEvent::getAmount)
|
||||
.sum();
|
||||
}
|
||||
|
||||
public int getLifeLostByPlayer(UUID playerID) {
|
||||
return events
|
||||
.stream()
|
||||
.filter(ev -> ev.getTargetId().equals(playerID))
|
||||
.mapToInt(GameEvent::getAmount)
|
||||
.sum();
|
||||
}
|
||||
|
||||
public boolean isLifeLostByCombatDamage() {
|
||||
return events.stream().anyMatch(LifeLostEvent::isCombatDamage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // events can store a diff value, so search it from events list instead
|
||||
public UUID getTargetId() {
|
||||
throw new IllegalStateException("Wrong code usage. Must search value from a getEvents list or use CardUtil.getEventTargets(event)");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // events can store a diff value, so search it from events list instead
|
||||
public UUID getSourceId() {
|
||||
throw new IllegalStateException("Wrong code usage. Must search value from a getEvents list.");
|
||||
}
|
||||
|
||||
public void addEvent(LifeLostEvent event) {
|
||||
this.events.add(event);
|
||||
}
|
||||
}
|
||||
19
Mage/src/main/java/mage/game/events/LifeLostEvent.java
Normal file
19
Mage/src/main/java/mage/game/events/LifeLostEvent.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package mage.game.events;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author jimga150
|
||||
*/
|
||||
public class LifeLostEvent extends GameEvent{
|
||||
public LifeLostEvent(UUID playerId, Ability source, int amount, boolean atCombat){
|
||||
super(GameEvent.EventType.LOST_LIFE,
|
||||
playerId, source, playerId, amount, atCombat);
|
||||
}
|
||||
|
||||
public boolean isCombatDamage() {
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
|
@ -2175,8 +2175,9 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
+ (atCombat ? " at combat" : "") + CardUtil.getSourceLogName(game, " from ", needId, "", ""));
|
||||
}
|
||||
if (event.getAmount() > 0) {
|
||||
game.fireEvent(new GameEvent(GameEvent.EventType.LOST_LIFE,
|
||||
playerId, source, playerId, event.getAmount(), atCombat));
|
||||
LifeLostEvent lifeLostEvent = new LifeLostEvent(playerId, source, event.getAmount(), atCombat);
|
||||
game.fireEvent(lifeLostEvent);
|
||||
game.getState().addSimultaneousLifeLossEventToBatches(lifeLostEvent, game);
|
||||
}
|
||||
return event.getAmount();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue