Skip to content

Commit

Permalink
implemented Conceal
Browse files Browse the repository at this point in the history
  • Loading branch information
oyachai committed Aug 10, 2015
1 parent f62f74a commit 4416200
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected boolean includeOwnMinions() {

private final static EffectCharacter battlecryAction = (originSide, origin, targetSide, targetCharacterIndex, boardState) -> {
Minion targetMinion = boardState.data_.modelForSide(targetSide).getCharacter(targetCharacterIndex);
targetMinion.setStealthed(true);
targetMinion.setStealthedUntilRevealed(true);
return boardState;
};

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/hearthsim/card/classic/spell/common/Conceal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hearthsim.card.classic.spell.common;

import com.hearthsim.card.spellcard.SpellCard;
import com.hearthsim.event.effect.EffectCharacter;
import com.hearthsim.event.effect.EffectOnResolveAoe;
import com.hearthsim.event.filter.FilterCharacter;

/**
* Created by oyachai on 8/10/15.
*/
public class Conceal extends SpellCard implements EffectOnResolveAoe {

public Conceal() {
super();
}

@Override
public EffectCharacter getAoeEffect() {
return EffectCharacter.STEALTH_UNTIL_NEXT_TURN;
}

@Override
public FilterCharacter getAoeFilter() {
return FilterCharacter.FRIENDLY_MINIONS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class OneEyedCheat extends Minion implements CardPlayBeginInterface {

private final static EffectCharacter<Card> effect = (originSide, origin, targetSide, targetCharacterIndex, boardState) -> {
Minion minion = boardState.data_.getCharacter(targetSide, targetCharacterIndex);
minion.setStealthed(true);
minion.setStealthedUntilRevealed(true);
return boardState;
};

Expand Down
50 changes: 36 additions & 14 deletions src/main/java/com/hearthsim/card/minion/Minion.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public static MinionTribe StringToMinionTribe(String race) {

private boolean frozen_;
protected boolean silenced_;
private boolean stealthed_;
private boolean stealthedUntilRevealed;
private boolean stealthedUntilNextTurn = false;
protected boolean heroTargetable_ = true;

protected byte health_;
Expand Down Expand Up @@ -102,7 +103,7 @@ protected void initFromImplementedCard(ImplementedCardList.ImplementedCard imple
this.divineShield_ = implementedCard.divineShield_;
this.windFury_ = implementedCard.windfury_;
this.charge_ = implementedCard.charge_;
this.stealthed_ = implementedCard.stealth_;
this.stealthedUntilRevealed = implementedCard.stealth_;
this.spellDamage_ = (byte) implementedCard.spellDamage;
this.cantAttack = implementedCard.cantAttack;
}
Expand Down Expand Up @@ -301,12 +302,24 @@ public void removeAuraHealth(byte value) {
auraHealth_ -= value;
}

public boolean getStealthed() {
return stealthed_;
public boolean isStealthed() {
return stealthedUntilRevealed || stealthedUntilNextTurn;
}

public void setStealthed(boolean value) {
stealthed_ = value;
public boolean getStealthedUntilRevealed() {
return this.stealthedUntilRevealed;
}

public void setStealthedUntilRevealed(boolean value) {
stealthedUntilRevealed = value;
}

public boolean getStealthedUntilNextTurn() {
return this.stealthedUntilNextTurn;
}

public void setStealthedUntilNextTurn(boolean stealthedUntilNextTurn) {
this.stealthedUntilNextTurn = stealthedUntilNextTurn;
}

public boolean getImmune() {
Expand Down Expand Up @@ -365,6 +378,8 @@ public HearthTreeNode startTurn(PlayerSide thisMinionPlayerIndex, HearthTreeNode
// toRet = this.destroyAndNotify(thisMinionPlayerIndex, toRet, deckPlayer0, deckPlayer1);
this.setHealth((byte) -99);
}
if (stealthedUntilNextTurn)
this.setStealthedUntilNextTurn(false);
return boardModel;
}

Expand Down Expand Up @@ -468,7 +483,8 @@ public void silenced(PlayerSide thisPlayerSide, BoardModel boardState) {
frozen_ = false;
windFury_ = false;
deathrattleAction_ = null;
stealthed_ = false;
stealthedUntilRevealed = false;
stealthedUntilNextTurn = false;
heroTargetable_ = true;
cantAttack = false;

Expand Down Expand Up @@ -716,7 +732,7 @@ protected HearthTreeNode summonMinion_core(PlayerSide targetSide, CharacterIndex
public HearthTreeNode attack(PlayerSide targetMinionPlayerSide, Minion targetMinion, HearthTreeNode boardState) throws HSException {

// can't attack a stealthed target
if (targetMinion.getStealthed())
if (targetMinion.isStealthed())
return null;

if (!this.canAttack()) {
Expand Down Expand Up @@ -746,8 +762,10 @@ public HearthTreeNode attack(PlayerSide targetMinionPlayerSide, Minion targetMin
}

// Attacking means you lose stealth
if (toRet != null)
this.stealthed_ = false;
if (toRet != null) {
this.stealthedUntilRevealed = false;
this.stealthedUntilNextTurn = false;
}

return toRet;
}
Expand Down Expand Up @@ -825,7 +843,8 @@ public Card deepCopy() {
minion.hasWindFuryAttacked_ = hasWindFuryAttacked_;
minion.frozen_ = frozen_;
minion.silenced_ = silenced_;
minion.stealthed_ = stealthed_;
minion.stealthedUntilRevealed = stealthedUntilRevealed;
minion.stealthedUntilNextTurn = stealthedUntilNextTurn;
minion.heroTargetable_ = heroTargetable_;
minion.destroyOnTurnStart_ = destroyOnTurnStart_;
minion.destroyOnTurnEnd_ = destroyOnTurnEnd_;
Expand Down Expand Up @@ -866,7 +885,9 @@ public boolean equals(Object other) {
return false;
if (charge_ != otherMinion.charge_)
return false;
if (stealthed_ != otherMinion.stealthed_)
if (stealthedUntilRevealed != otherMinion.stealthedUntilRevealed)
return false;
if (stealthedUntilNextTurn != otherMinion.stealthedUntilNextTurn)
return false;
if (hasAttacked_ != otherMinion.hasAttacked_)
return false;
Expand Down Expand Up @@ -907,7 +928,8 @@ public int hashCode() {
result = 31 * result + (hasWindFuryAttacked_ ? 1 : 0);
result = 31 * result + (frozen_ ? 1 : 0);
result = 31 * result + (silenced_ ? 1 : 0);
result = 31 * result + (stealthed_ ? 1 : 0);
result = 31 * result + (stealthedUntilRevealed ? 1 : 0);
result = 31 * result + (stealthedUntilNextTurn ? 1 : 0);
result = 31 * result + (heroTargetable_ ? 1 : 0);
result = 31 * result + health_;
result = 31 * result + maxHealth_;
Expand Down Expand Up @@ -953,7 +975,7 @@ public Minion(String name, byte mana, byte attack, byte health, byte baseAttack,

spellDamage_ = spellDamage;

stealthed_ = stealthed;
stealthedUntilRevealed = stealthed;
heroTargetable_ = heroTargetable;
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/hearthsim/card/spellcard/SpellCard.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.hearthsim.card.spellcard;

import com.hearthsim.card.Card;
import com.hearthsim.card.minion.Minion;
import com.hearthsim.model.BoardModel;
import com.hearthsim.model.PlayerSide;
import org.json.JSONObject;

public abstract class SpellCard extends Card {
Expand All @@ -20,4 +23,17 @@ public JSONObject toJSON() {
json.put("type", "SpellCard");
return json;
}

@Override
public boolean canBeUsedOn(PlayerSide playerSide, Minion minion, BoardModel boardModel) {
if (!super.canBeUsedOn(playerSide, minion, boardModel))
return false;

if (playerSide == PlayerSide.WAITING_PLAYER && minion.isStealthed()) {
return false;
}

return true;
}

}
6 changes: 6 additions & 0 deletions src/main/java/com/hearthsim/event/effect/EffectCharacter.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public default HearthTreeNode applyEffect(PlayerSide originSide, T origin, Playe
return boardState;
};

public final static EffectCharacter STEALTH_UNTIL_NEXT_TURN = (originSide, origin, targetSide, targetCharacterIndex, boardState) -> {
Minion targetMinion = boardState.data_.modelForSide(targetSide).getCharacter(targetCharacterIndex);
targetMinion.setStealthedUntilNextTurn(true);
return boardState;
};

public final static EffectCharacter MIND_CONTROL = (originSide, origin, targetSide, targetCharacterIndex, boardState) -> {
Minion targetMinion = boardState.data_.modelForSide(targetSide).getCharacter(targetCharacterIndex);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public boolean targetMatches(PlayerSide originSide, Card origin, PlayerSide targ
return false;
}

if (originSide != targetSide && targetCharacter.getStealthed()) {
if (originSide != targetSide && targetCharacter.isStealthed()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public boolean targetMatches(PlayerSide originSide, Card origin, PlayerSide targ
return false;
}

if (originSide != targetSide && targetCharacter.getStealthed()) {
if (originSide != targetSide && targetCharacter.isStealthed()) {
return false;
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/implemented_cards.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
"id": "EX1_103",
"name": "Coldlight Seer"
},
{
"class": "com.hearthsim.card.classic.spell.common.Conceal",
"id": "EX1_128",
"name": "Conceal"
},
{
"class": "com.hearthsim.card.basic.spell.Consecration",
"id": "CS2_093",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class CardSpec extends Specification {
assert oldMinion.hasAttacked() == newMinion.hasAttacked()
assert oldMinion.heroTargetable == newMinion.heroTargetable
assert oldMinion.silenced == newMinion.silenced
assert oldMinion.stealthed == newMinion.stealthed
assert oldMinion.stealthedUntilRevealed == newMinion.stealthedUntilRevealed
assert oldMinion.stealthedUntilNextTurn == newMinion.stealthedUntilNextTurn
assert oldMinion.hasBeenUsed == newMinion.hasBeenUsed
assert oldMinion == newMinion //catch all
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MasterOfDisguiseSpec extends CardSpec {

assertBoardDelta(copiedBoard, ret.data_) {
currentPlayer {
updateMinion(CharacterIndex.MINION_1, [stealthed: true])
updateMinion(CharacterIndex.MINION_1, [stealthedUntilRevealed: true])
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PatientAssassinSpec extends CardSpec {
currentPlayer {
playMinion(PatientAssassin)
mana(5)
updateMinion(CharacterIndex.MINION_1, [hasAttacked: true, stealthed: false])
updateMinion(CharacterIndex.MINION_1, [hasAttacked: true, stealthedUntilRevealed: false])
numCardsUsed(1)
}
waitingPlayer {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.hearthsim.test.groovy.card.classic.spell

import com.hearthsim.Game
import com.hearthsim.card.CharacterIndex
import com.hearthsim.card.basic.minion.BloodfenRaptor
import com.hearthsim.card.basic.minion.WarGolem
import com.hearthsim.card.classic.spell.common.Conceal
import com.hearthsim.model.BoardModel
import com.hearthsim.test.groovy.card.CardSpec
import com.hearthsim.test.helpers.BoardModelBuilder
import com.hearthsim.util.tree.HearthTreeNode

import static com.hearthsim.model.PlayerSide.CURRENT_PLAYER
import static org.junit.Assert.assertEquals

/**
* Created by oyachai on 8/10/15.
*/
class ConcealSpec extends CardSpec {

HearthTreeNode root
BoardModel startingBoard

def setup() {

startingBoard = new BoardModelBuilder().make {
currentPlayer {
hand([Conceal])
field([[minion: WarGolem], [minion: BloodfenRaptor]])
mana(10)
}
waitingPlayer {
field([[minion: WarGolem]])
}
}

root = new HearthTreeNode(startingBoard)
}

def "Stealthed until next turn"() {
def copiedBoard = startingBoard.deepCopy()

def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)

expect:
assertEquals(root, ret);

assertBoardDelta(copiedBoard, ret.data_) {
currentPlayer {
removeCardFromHand(Conceal)
mana(9)
numCardsUsed(1)
updateMinion(CharacterIndex.MINION_1, [stealthedUntilNextTurn: true])
updateMinion(CharacterIndex.MINION_2, [stealthedUntilNextTurn: true])
}
}
}

def "no longer stealthed when the next turn begins"() {
def copiedBoard = startingBoard.deepCopy()

def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, CharacterIndex.HERO, root)

def ret2 = new HearthTreeNode(Game.beginTurn(ret.data_.deepCopy()))

expect:
assertEquals(root, ret);

assertBoardDelta(copiedBoard, ret.data_) {
currentPlayer {
removeCardFromHand(Conceal)
mana(9)
numCardsUsed(1)
updateMinion(CharacterIndex.MINION_1, [stealthedUntilNextTurn: true])
updateMinion(CharacterIndex.MINION_2, [stealthedUntilNextTurn: true])
}
}

assertBoardDelta(ret.data_, ret2.data_) {
currentPlayer {
mana(10)
numCardsUsed(0)
fatigueDamage(2)
heroHealth(29) //fatigue damage
updateMinion(CharacterIndex.MINION_1, [stealthedUntilNextTurn: false])
updateMinion(CharacterIndex.MINION_2, [stealthedUntilNextTurn: false])
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OneEyedCheatSpec extends CardSpec {
playMinion(BloodsailRaider, CharacterIndex.HERO)
mana(8)
numCardsUsed(1)
updateMinion(CharacterIndex.MINION_2, [stealthed: true])
updateMinion(CharacterIndex.MINION_2, [stealthedUntilRevealed: true])
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ class BoardModelBuilder {

minion.hasAttacked_ = options.containsKey('hasAttacked') ? options.hasAttacked : minion.hasAttacked_
minion.hasBeenUsed = options.containsKey('hasBeenUsed') ? options.hasBeenUsed : minion.hasBeenUsed
minion.stealthed = options.containsKey('stealthed') ? options.stealthed : minion.stealthed

minion.stealthedUntilNextTurn = options.containsKey('stealthedUntilNextTurn') ? options.stealthedUntilNextTurn : minion.stealthedUntilNextTurn
minion.stealthedUntilRevealed = options.containsKey('stealthedUntilRevealed') ? options.stealthedUntilRevealed : minion.stealthedUntilRevealed

minion.charge = options.containsKey('charge') ? options.charge : minion.charge
minion.frozen = options.containsKey('frozen') ? options.frozen : minion.frozen
minion.silenced = options.containsKey('silenced') ? options.silenced : minion.silenced
Expand Down
Loading

0 comments on commit 4416200

Please sign in to comment.