private ECSGame game() { return action.getOwner().getGame(); }
public static double health(ECSAction action, ScoreParameters<Entity> params) { return health.getOrDefault(action.getOwner(), 0); }
public static double attack(ECSAction action, ScoreParameters<Entity> params) { return attack.getOrDefault(action.getOwner(), 0); }
private ECSAction moveAction(String name, Entity entity, Class<? extends ZoneComponent> zone, boolean switchPlayer) { return new ECSAction(entity, name, act -> true, act -> { CardComponent card = act.getOwner().getComponent(CardComponent.class); Entity player = Players.findOwnerFor(act.getOwner()); final Entity origPlayer = player; if (switchPlayer) { Set<Entity> players = entity.getGame().getEntitiesWithComponent(PlayerComponent.class); player = players.stream().filter(pl -> pl != origPlayer).findAny().get(); } card.moveToBottom(player.getComponent(zone)); }); }
public static double attackScore(ECSAction action, ScoreParameters<Entity> params) { if (!action.getName().equals(CyborgChroniclesGame.ATTACK_ACTION)) { return 0; } TargetSet targets = action.getTargetSets().get(0); targets.clearTargets(); List<Entity> possibleTargets = targets.findPossibleTargets(); Optional<Entity> player = possibleTargets.stream().filter(e -> e.hasComponent(PlayerComponent.class)).findAny(); if (player.isPresent()) { // attacking a player is really the best option there is targets.addTarget(player.get()); return 100; } if (possibleTargets.isEmpty()) { throw new RuntimeException("Attack action has no targets: " + action); } possibleTargets.sort(Comparator.comparingInt(e -> attackVS(action.getOwner(), e))); Entity chosenTarget = possibleTargets.get(possibleTargets.size() - 1); targets.addTarget(chosenTarget); return attackVS(action.getOwner(), chosenTarget); }
public boolean check(TargetableCheckEvent event) { return filter.test(event.getAction().getOwner(), event.getTarget()); }
public static double scrapNeeded(ECSAction action, ScoreParameters<Entity> params) { if (!action.getName().equals(CyborgChroniclesGame.SCRAP_ACTION)) { return 0; } Entity entity = action.getOwner(); ComponentRetriever<CardComponent> card = Retrievers.component(CardComponent.class); Entity owner = card.get(entity).getOwner(); HandComponent hand = owner.getComponent(HandComponent.class); return hand.stream().mapToInt(e -> scrapCost.getOrDefault(e, 0)).sum(); }
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 static double scrapScore(ECSAction action, ScoreParameters<Entity> params) { if (!action.getName().equals(CyborgChroniclesGame.SCRAP_ACTION)) { return 0; } Entity entity = action.getOwner(); ComponentRetriever<CardComponent> card = Retrievers.component(CardComponent.class); ZoneComponent battlefield = card.get(entity).getCurrentZone(); List<Entity> creatures = battlefield.getCards(); if (creatures.size() <= 3) { return -health.getFor(entity); } creatures.sort(Comparator.comparingInt(e -> health.getFor(e) + attack.getFor(e))); if (entity == creatures.get(0)) { // Only consider scrapping the creature with lowest health return 4 - health.getFor(entity); } return -1; }
public static double enchantScore(ECSAction action, ScoreParameters<Entity> params) { if (!action.getName().equals(CyborgChroniclesGame.ENCHANT_ACTION)) { return 0; } TargetSet targets = action.getTargetSets().get(0); targets.clearTargets(); List<Entity> possibleTargets = targets.findPossibleTargets(); if (possibleTargets.isEmpty()) { return -1; } Entity enchantment = action.getOwner(); int attackBonus = attack.getFor(enchantment); int healthBonus = health.getFor(enchantment); possibleTargets.sort(Comparator.comparingDouble(e -> enchantScore(e, attackBonus, healthBonus))); Entity chosenTarget = possibleTargets.get(possibleTargets.size() - 1); targets.addTarget(chosenTarget); return enchantScore(chosenTarget, attackBonus, healthBonus); }
Entity entity = action.getOwner(); ComponentRetriever<CardComponent> card = Retrievers.component(CardComponent.class); Entity owner = card.get(entity).getOwner();
/** * Looks at all Clients, resets their actions, then gets all actions for each and sends them. */ private void sendAvailableActions() { for (ClientIO io : this.getPlayers()) { io.sendToClient(new ResetAvailableActionsMessage()); if (game.isGameOver()) { continue; } Entity player = playerFor(io); getAllActions(game).filter(action -> action.isAllowed(player)) .forEach(action -> io.sendToClient(new UsableActionMessage(action.getOwner().getId(), action.getName(), !action.getTargetSets().isEmpty()))); } }
private void targetAllowed(TargetableCheckEvent event) { if (!event.getAction().getName().equals(ACTION_NAME)) { return; } if (!event.getTarget().hasComponent(CardComponent.class)) { event.setAllowed(false); return; } if (!Cards.isOnZone(event.getTarget(), HandComponent.class)) { event.setAllowed(false); } if (!Cards.isOwnedBy(event.getTarget(), event.getAction().getOwner())) { event.setAllowed(false); } }