public Stream<Entity> getAllTargets() { return targetSets.stream().flatMap(e -> e.getChosenTargets().stream()); }
private ReplayAction(ActionPerformEvent event) { this.entity = event.getEntity().getId(); this.performer = event.getPerformer().getId(); this.actionName = event.getAction().getName(); this.targets = event.getAction().getTargetSets().stream() .map(targetSet -> targetSet.getChosenTargets().stream() .map(e -> e.getId()).collect(Collectors.toList())) .collect(Collectors.toList()); }
private void performAction(ECSAction mulliganAction) { List<Entity> chosenTargets = mulliganAction.getTargetSets().get(0).getChosenTargets(); chosenTargets.forEach(this::switchCard); Entity owner = mulliganAction.getOwner(); owner.getComponent(ActionComponent.class).removeAction(ACTION_NAME); owner.getComponent(DeckComponent.class).shuffle(); if (remainingPerforms.decrementAndGet() == 0) { phases.nextPhase(); } }
public ECSAction copy(Entity copyTo) { ECSAction action = new ECSAction(copyTo, this.name, this.allowed, this.perform); for (TargetSet set : targetSets) { action.addTargetSet(set.getMin(), set.getMax()); TargetSet lastSet = action.getTargetSets().get(action.getTargetSets().size() - 1); set.getChosenTargets().forEach(target -> lastSet.addTarget(target)); } return action; }
@Override protected void onPerform(ActionPerformEvent event) { Entity target = event.getAction().getTargetSets().get(0).getChosenTargets().get(0); Entity enchantment = event.getEntity(); for (ECSResource resource : resources) { ResourceRetriever res = ResourceRetriever.forResource(resource); int enchantmentValue = res.getFor(enchantment); res.resFor(target).change(enchantmentValue); } enchantment.destroy(); }
@Override protected void onPerform(ActionPerformEvent event) { Entity source = event.getEntity(); Entity target = event.getAction().getTargetSets().get(0).getChosenTargets().get(0); AttackEvent attackEvent = new AttackEvent(source, target); source.getGame().executeCancellableEvent(attackEvent, () -> { int attackDamage = attack.getFor(source); int defenseDamage = attack.getFor(target); int attackHealth = health.getFor(source); int defenseHealth = health.getFor(target); ECSGame game = source.getGame(); attackDamage = damage(attackEvent, attackDamage, target, source, game); boolean counterAttack = allowCounterAttack.test(source, target); if (counterAttack) { defenseDamage = damage(attackEvent, defenseDamage, source, target, game); } checkKill(target, attackDamage, defenseHealth); if (counterAttack) { checkKill(source, defenseDamage, attackHealth); } }); }
@Override protected void onPerform(ActionPerformEvent event) { Entity source = event.getEntity(); Entity target = event.getAction().getTargetSets().get(0).getChosenTargets().get(0); ECSGame game = event.getEntity().getGame(); int attackDamage = attack.getFor(source); int defenseDamage = attack.getFor(target); if (target.hasComponent(PlayerComponent.class)) { damage(event, attackDamage, target, source, game); } else { DamageEvent damageEvent = new DamageEvent(event, target, source, attackDamage); game.getEvents().executeEvent(damageEvent, e -> { }); destroyOrNothing(damageEvent.getDamage(), target); } if (allowCounterAttack.test(source, target)) { destroyOrNothing(defenseDamage, source); } }