Skip to content

Commit

Permalink
added MAX_HEALTH to players. Healing with Field Medic does not go abo…
Browse files Browse the repository at this point in the history
…ve MAX_HEALTH
  • Loading branch information
Zomis committed Jan 30, 2015
1 parent 31e5706 commit 59d28f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
@@ -1,7 +1,9 @@
package net.zomis.cardshifter.ecs.usage;

import java.util.Map.Entry;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.ToIntFunction;
import java.util.function.UnaryOperator;

import com.cardshifter.modapi.phase.*;
Expand Down Expand Up @@ -92,7 +94,10 @@ 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);
ResourceRetriever healthMax = ResourceRetriever.forResource(PhrancisResources.MAX_HEALTH);
Consumer<Entity> noSickness = e -> sickness.resFor(e).set(0);
BiFunction<Entity, Integer, Integer> restoreHealth = (e, value) ->
Math.max(Math.min(healthMax.getFor(e) - health.getFor(e), value), 0);

// Mechs (ManaCost, zone, Attack, Health, "Type", ScrapValue, "CardName")
createCreature(0, zone, 0, 1, "Mech", 3, "Spareparts");
Expand All @@ -114,9 +119,10 @@ public void addCards(ZoneComponent zone) {
createCreature(4, zone, 2, 3, "Bio", 0, "Bodyman");
createCreature(5, zone, 3, 3, "Bio", 0, "Vetter");
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(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(restoreHealth.apply(e, 1))))));
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 @@ -184,6 +190,7 @@ public void setupGame(ECSGame game) {

ECSResourceMap.createFor(player)
.set(PhrancisResources.HEALTH, 30)
.set(PhrancisResources.MAX_HEALTH, 30)
.set(PhrancisResources.MANA, 0)
.set(PhrancisResources.SCRAP, 0);

Expand Down
Expand Up @@ -85,19 +85,21 @@ public void healEndOfTurn() {

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

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

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

assertEquals(health + 2, this.health.getFor(player));
// Health does not go above HEALTH_MAX
assertEquals(30, this.health.getFor(player));
}

private void addCard(DeckConfig config, Predicate<Entity> condition) {
Expand Down

0 comments on commit 59d28f9

Please sign in to comment.