Skip to content

Commit

Permalink
added healing functionality for Field Medic
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Jan 30, 2015
1 parent dc0ba87 commit 31e5706
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
Expand Up @@ -4,13 +4,12 @@
import java.util.function.Consumer;
import java.util.function.UnaryOperator;

import com.cardshifter.modapi.phase.*;
import com.cardshifter.modapi.players.Players;
import net.zomis.cardshifter.ecs.config.ConfigComponent;
import com.cardshifter.api.config.DeckConfig;
import net.zomis.cardshifter.ecs.config.DeckConfigFactory;
import net.zomis.cardshifter.ecs.effects.EffectActionSystem;
import net.zomis.cardshifter.ecs.effects.EffectComponent;
import net.zomis.cardshifter.ecs.effects.EffectTargetFilterSystem;
import net.zomis.cardshifter.ecs.effects.FilterComponent;
import net.zomis.cardshifter.ecs.effects.*;

import com.cardshifter.modapi.actions.ActionComponent;
import com.cardshifter.modapi.actions.ECSAction;
Expand Down Expand Up @@ -44,11 +43,6 @@
import com.cardshifter.modapi.cards.PlayFromHandSystem;
import com.cardshifter.modapi.cards.RemoveDeadEntityFromZoneSystem;
import com.cardshifter.modapi.cards.ZoneComponent;
import com.cardshifter.modapi.phase.GainResourceSystem;
import com.cardshifter.modapi.phase.PerformerMustBeCurrentPlayer;
import com.cardshifter.modapi.phase.Phase;
import com.cardshifter.modapi.phase.PhaseController;
import com.cardshifter.modapi.phase.RestoreResourcesSystem;
import com.cardshifter.modapi.resources.ECSResource;
import com.cardshifter.modapi.resources.ECSResourceMap;
import com.cardshifter.modapi.resources.GameOverIfNoHealth;
Expand Down Expand Up @@ -97,6 +91,7 @@ public void declareConfiguration(ECSGame game) {
public void addCards(ZoneComponent zone) {
// Create card models that should be possible to choose from
ResourceRetriever sickness = ResourceRetriever.forResource(PhrancisResources.SICKNESS);
ResourceRetriever health = ResourceRetriever.forResource(PhrancisResources.HEALTH);
Consumer<Entity> noSickness = e -> sickness.resFor(e).set(0);

// Mechs (ManaCost, zone, Attack, Health, "Type", ScrapValue, "CardName")
Expand All @@ -118,7 +113,10 @@ public void addCards(ZoneComponent zone) {
createCreature(3, zone, 3, 2, "Bio", 0, "Longshot");
createCreature(4, zone, 2, 3, "Bio", 0, "Bodyman");
createCreature(5, zone, 3, 3, "Bio", 0, "Vetter");
createCreature(5, zone, 1, 5, "Bio", 0, "Field Medic");
Effects effects = new Effects();
createCreature(5, zone, 1, 5, "Bio", 0, "Field Medic").addComponent(effects.giveSelf(effects.triggerSystem(PhaseEndEvent.class,
(me, event) -> Players.findOwnerFor(me) == event.getOldPhase().getOwner(),
(me, event) -> Players.findOwnerFor(me).apply(e -> health.resFor(e).change(1))))); // heals player for 1 health at end of turn
createCreature(6, zone, 4, 4, "Bio", 0, "Wastelander");
createCreature(6, zone, 5, 3, "Bio", 0, "Commander").apply(noSickness);
createCreature(6, zone, 3, 5, "Bio", 0, "Cyberpimp");
Expand Down
Expand Up @@ -8,6 +8,8 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import com.cardshifter.modapi.attributes.AttributeRetriever;
import com.cardshifter.modapi.attributes.Attributes;
import net.zomis.cardshifter.ecs.config.ConfigComponent;
import com.cardshifter.api.config.DeckConfig;
import net.zomis.cardshifter.ecs.usage.PhrancisGame;
Expand Down Expand Up @@ -43,7 +45,11 @@ public class PhrancisTest extends GameTest {
private final ComponentRetriever<BattlefieldComponent> field = ComponentRetriever.retreiverFor(BattlefieldComponent.class);

private final Predicate<Entity> isCreature = entity -> entity.hasComponent(CreatureTypeComponent.class);

private final Predicate<Entity> hasName(String str) {
AttributeRetriever name = AttributeRetriever.forAttribute(Attributes.NAME);
return e -> name.getOrDefault(e, "").equals(str);
}

private final PhrancisGame mod = new PhrancisGame();

@Override
Expand All @@ -64,12 +70,36 @@ protected void setupGame(ECSGame game) {
addCard(deckConf, isCreature.and(manaCost(1)));
addCard(deckConf, isCreature.and(manaCost(1)));
addCard(deckConf, isCreatureType("Bio").and(health(4)));
addCard(deckConf, hasName("Field Medic"));
addCard(deckConf, e -> scrapCost.getFor(e) == 1 && health.getFor(e) == 1);
}

mod.setupGame(game);
}

@Test
public void healEndOfTurn() {
while (mana.getFor(currentPlayer()) < 5) {
nextPhase();
}

Entity player = currentPlayer();
Entity medic = cardToHand(hasName("Field Medic"));
int health = this.health.getFor(player);
useAction(medic, PhrancisGame.PLAY_ACTION);
assertEquals(health, this.health.getFor(player));
nextPhase();

assertEquals(health + 1, this.health.getFor(player));
nextPhase();

assertEquals(player, currentPlayer());
assertEquals(health + 1, this.health.getFor(player));
nextPhase();

assertEquals(health + 2, this.health.getFor(player));
}

private void addCard(DeckConfig config, Predicate<Entity> condition) {
Set<Entity> availableCards = game.getEntitiesWithComponent(ZoneComponent.class);
ZoneComponent zone = availableCards.iterator().next().getComponent(ZoneComponent.class);
Expand Down

0 comments on commit 31e5706

Please sign in to comment.