@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; }
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 public void startGame(ECSGame game) { ComponentRetriever<ActionComponent> actions = ComponentRetriever.retreiverFor(ActionComponent.class); game.getEvents().registerHandlerAfter(this, TargetableCheckEvent.class, this::targetAllowed); game.getEvents().registerHandlerAfter(this, ActionAllowedCheckEvent.class, this::actionAllowed); Set<Entity> players = game.getEntitiesWithComponent(PlayerComponent.class); remainingPerforms.set(players.size()); for (Entity player : players) { ActionComponent playerActions = player.get(actions); if (playerActions == null) { playerActions = new ActionComponent(); player.addComponent(playerActions); } playerActions.addAction(createMulliganAction(player)); } }
@Before public void before() { game = new ECSGame(); entity = game.newEntity().addComponent(new ActionComponent()); }
@Test public void removeSystemTest() { ECSGame game = new ECSGame(); ActionComponent act = new ActionComponent(); Entity entity = game.newEntity().addComponent(act); act.addAction(new ECSAction(entity, "Test", e -> true, e -> {})); system = new SpecificActionSystem("Test") { @Override protected void onPerform(ActionPerformEvent event) { value.getAndIncrement(); event.getEntity().getGame().removeSystem(system); } }; game.addSystem(system); game.startGame(); assertEquals(0, value.get()); act.getAction("Test").perform(entity); assertEquals(1, value.get()); act.getAction("Test").perform(entity); assertEquals(1, value.get()); game.addSystem(system); act.getAction("Test").perform(entity); assertEquals(2, value.get()); }
private void createCards(ZoneComponent hand) { for (int i = 0; i < 5; i++) { Entity entity = hand.getOwner().getGame().newEntity(); ECSResourceMap.createFor(entity) .set(CyborgChroniclesGame.CyborgChroniclesResources.HEALTH, 3) .set(CyborgChroniclesGame.CyborgChroniclesResources.MAX_HEALTH, 3); ECSAttributeMap.createFor(entity).set(Attributes.NAME, "Test"); ActionComponent action = new ActionComponent(); entity.addComponent(action); action.addAction(moveAction("Field", entity, BattlefieldComponent.class, false)); action.addAction(moveAction("Hand", entity, HandComponent.class, false)); action.addAction(moveAction("Deck", entity, DeckComponent.class, false)); action.addAction(moveAction("2-Field", entity, BattlefieldComponent.class, true)); action.addAction(moveAction("2-Hand", entity, HandComponent.class, true)); action.addAction(moveAction("2-Deck", entity, DeckComponent.class, true)); action.addAction(damageAction(entity)); hand.addOnBottom(entity); } }
phaseController.addPhase(playerPhase); ActionComponent actions = new ActionComponent(); player.addComponent(actions);