Skip to content

Commit

Permalink
implemented The Beast
Browse files Browse the repository at this point in the history
  • Loading branch information
oyachai committed Jun 7, 2015
1 parent e626053 commit a27d662
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 5 deletions.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Mon Sep 08 10:27:23 EDT 2014
#Sun Jun 07 16:17:58 BST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
@@ -0,0 +1,13 @@
package com.hearthsim.card.classic.minion.legendary;

import com.hearthsim.card.minion.Minion;

/**
* Created by oyachai on 6/7/15.
*/
public class FinkleEinhorn extends Minion {

public FinkleEinhorn() {
super();
}
}
@@ -0,0 +1,18 @@
package com.hearthsim.card.classic.minion.legendary;

import com.hearthsim.card.minion.Minion;
import com.hearthsim.event.deathrattle.DeathrattleSummonMinionAction;
import com.hearthsim.model.PlayerSide;

/**
* Created by oyachai on 6/7/15.
*/
public class TheBeast extends Minion {

public TheBeast() {
super();

deathrattleAction_ = new DeathrattleSummonMinionAction(FinkleEinhorn.class, 1, PlayerSide.WAITING_PLAYER);
}

}
Expand Up @@ -10,20 +10,32 @@ public class DeathrattleSummonMinionAction extends DeathrattleAction {

private final int numMinions_;
private final Class<? extends Minion> minionClass_;
private final PlayerSide sideToSummon;

public DeathrattleSummonMinionAction(Class<? extends Minion> minionClass, int numMnions) {
public DeathrattleSummonMinionAction(Class<? extends Minion> minionClass, int numMinions) {
this(minionClass, numMinions, PlayerSide.CURRENT_PLAYER);
}

public DeathrattleSummonMinionAction(Class<? extends Minion> minionClass, int numMnions, PlayerSide sideToSummon) {
numMinions_ = numMnions;
minionClass_ = minionClass;
this.sideToSummon = sideToSummon;
}

@Override
public HearthTreeNode performAction(Card origin, PlayerSide playerSide, HearthTreeNode boardState, boolean singleRealizationOnly) {

HearthTreeNode toRet = super.performAction(origin, playerSide, boardState, singleRealizationOnly);

PlayerModel targetPlayer = toRet.data_.modelForSide(playerSide);
PlayerSide targetPlayerSide = playerSide;
if (sideToSummon == PlayerSide.WAITING_PLAYER) {
targetPlayer = toRet.data_.modelForSide(playerSide.getOtherPlayer());
targetPlayerSide = playerSide.getOtherPlayer();
}

int targetIndex = targetPlayer.getNumMinions();
if (origin instanceof Minion) {
if (origin instanceof Minion && targetPlayerSide == playerSide) {
targetIndex = targetPlayer.getIndexForCharacter((Minion)origin) - 1;
toRet.data_.removeMinion((Minion) origin);
}
Expand All @@ -36,7 +48,7 @@ public HearthTreeNode performAction(Card origin, PlayerSide playerSide, HearthTr
for (int index = 0; index < numMinionsToActuallySummon; ++index) {
try {
Minion newMinion = minionClass_.newInstance();
toRet = newMinion.summonMinion(playerSide, targetIndex, toRet, false, true);
toRet = newMinion.summonMinion(targetPlayerSide, targetIndex, toRet, false, true);
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Unable to instantiate card.");
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/implemented_cards.json
Expand Up @@ -484,6 +484,10 @@
"name": "Fiery War Axe",
"class": "com.hearthsim.card.basic.weapon.FieryWarAxe"
},
{
"name": "Finkle Einhorn",
"class": "com.hearthsim.card.classic.minion.legendary.FinkleEinhorn"
},
{
"name": "Fire Elemental",
"class": "com.hearthsim.card.basic.minion.FireElemental"
Expand Down Expand Up @@ -1364,6 +1368,10 @@
"name": "The Black Knight",
"class": "com.hearthsim.card.classic.minion.legendary.TheBlackKnight"
},
{
"name": "The Beast",
"class": "com.hearthsim.card.classic.minion.legendary.TheBeast"
},
{
"name": "Thrallmar Farseer",
"class": "com.hearthsim.card.classic.minion.common.ThrallmarFarseer"
Expand Down
@@ -0,0 +1,60 @@
package com.hearthsim.test.groovy.card.classic.minion

import com.hearthsim.card.basic.minion.GoldshireFootman
import com.hearthsim.card.basic.minion.WarGolem
import com.hearthsim.card.basic.spell.ShadowWordDeath
import com.hearthsim.card.classic.minion.legendary.FinkleEinhorn
import com.hearthsim.card.classic.minion.legendary.TheBeast
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.assertFalse

/**
* Created by oyachai on 6/7/15.
*/
class TheBeastSpec extends CardSpec {

HearthTreeNode root
BoardModel startingBoard

def "killing The Beast summons a Finkle Einhorn"() {
startingBoard = new BoardModelBuilder().make {
currentPlayer {
hand([ShadowWordDeath])
field([[minion:TheBeast]])
mana(9)
}
waitingPlayer {
field([[minion: WarGolem],
[minion: GoldshireFootman]])
mana(4)
}
}

root = new HearthTreeNode(startingBoard)

def copiedBoard = startingBoard.deepCopy()
def theCard = root.data_.getCurrentPlayer().getHand().get(0)
def ret = theCard.useOn(CURRENT_PLAYER, 1, root)

expect:
assertFalse(ret == null);

assertBoardDelta(copiedBoard, ret.data_) {
currentPlayer {
removeCardFromHand(ShadowWordDeath)
removeMinion(0)
mana(6)
numCardsUsed(1)
}
waitingPlayer {
addMinionToField(FinkleEinhorn)
}
}

}
}

0 comments on commit a27d662

Please sign in to comment.