private void canAfford(ActionAllowedCheckEvent event) { if (!isInterestingAction(event.getAction())) { return; } this.isAllowed(event); }
private void perform(ActionPerformEvent event) { if (!isInterestingAction(event.getAction())) { return; } this.onPerform(event); }
@Override protected void isAllowed(ActionAllowedCheckEvent event) { if (event.getEntity() == entity) { event.setAllowed(false); } }
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; }
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 giveReplayControls(Entity player) { ActionComponent actions = player.getComponent(ActionComponent.class); if (actions == null) { actions = new ActionComponent(); player.addComponent(actions); } actions.addAction(new ECSAction(player, NEXT_STEP, e -> true, this::nextStep)); }
@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 public Component copy(Entity copyTo) { ActionComponent copy = new ActionComponent(); for (Entry<String, ECSAction> entry : actions.entrySet()) { copy.addAction(entry.getValue().copy(copyTo)); } return copy; }
@Override protected void isAllowed(ActionAllowedCheckEvent event) { event.setAllowed(event.getEntity() == event.getPerformer()); }
private ECSAction createMulliganAction(Entity player) { return new ECSAction(player, ACTION_NAME, act -> true, this::performAction).addTargetSet(0, Integer.MAX_VALUE); }
private void targetableCheck(TargetableCheckEvent event) { if (event.getAction().getName().equals(actionName)) { this.checkTargetable(event); } }
@Override protected void checkTargetable(TargetableCheckEvent event) { if (filter.has(event.getAction().getOwner())) { FilterComponent comp = filter.get(event.getAction().getOwner()); event.setAllowed(comp.check(event)); } }
public static ECSAction getAction(Entity performer, String actionName) { ActionComponent actionComponent = actions.get(performer); if (actionComponent == null) { return null; } return actionComponent.getAction(actionName); }
public boolean isTargetable(Entity target) { TargetableCheckEvent event = new TargetableCheckEvent(action, this, target); events().executePostEvent(event); return event.isAllowed(); }
@Override protected void isAllowed(ActionAllowedCheckEvent event) { event.setAllowed(false); }
public ECSAction copy() { return copy(owner); }
@Override public String toString() { return description != null ? description : "UseCostSystem [action=" + getActionName() + ", useResource=" + useResource + "]"; }
public boolean addTarget(Entity target) { // events().executePostEvent(new TargetEvent(action, this, target)); if (!isTargetable(target)) { return false; } chosenTargets.add(target); return true; }
@Override protected void isAllowed(ActionAllowedCheckEvent event) { if (!Cards.isOwnedByCurrentPlayer(event.getEntity())) { event.setAllowed(false); } if (!Cards.isOnZone(event.getEntity(), BattlefieldComponent.class)) { event.setAllowed(false); } }