-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathCreateSummonSpell.java
71 lines (66 loc) · 3.03 KB
/
CreateSummonSpell.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package net.demilich.metastone.game.spells;
import net.demilich.metastone.game.GameContext;
import net.demilich.metastone.game.Player;
import net.demilich.metastone.game.cards.Card;
import com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType;
import com.hiddenswitch.spellsource.rpc.Spellsource.RarityMessage.Rarity;
import net.demilich.metastone.game.cards.desc.CardDesc;
import net.demilich.metastone.game.entities.Entity;
import net.demilich.metastone.game.entities.heroes.HeroClass;
import net.demilich.metastone.game.entities.minions.Minion;
import net.demilich.metastone.game.spells.custom.CreateCardFromChoicesSpell;
import net.demilich.metastone.game.spells.desc.SpellArg;
import net.demilich.metastone.game.spells.desc.SpellDesc;
import net.demilich.metastone.game.cards.Attribute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This spell is fairly brittle and you will be better off implementing the intended effects directly. See {@link
* CreateCardFromChoicesSpell} for an example.
*/
@Deprecated
public class CreateSummonSpell extends Spell {
Logger logger = LoggerFactory.getLogger(CreateSummonSpell.class);
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
String description = "";
CardDesc cardDesc = new CardDesc();
cardDesc.setId(context.getLogic().generateCardId());
cardDesc.setName(desc.getString(SpellArg.NAME));
if (desc.containsKey(SpellArg.RACE)) {
cardDesc.setRace((String) desc.get(SpellArg.RACE));
}
cardDesc.setBaseAttack(desc.getValue(SpellArg.ATTACK_BONUS, context, player, target, source, 0));
cardDesc.setBaseHp(desc.getValue(SpellArg.HP_BONUS, context, player, target, source, 0));
cardDesc.setHeroClass(HeroClass.ANY);
cardDesc.setType(CardType.MINION);
cardDesc.setRarity(Rarity.FREE);
cardDesc.setDescription(description);
Attribute attribute = (Attribute) desc.get(SpellArg.ATTRIBUTE);
if (attribute != null) {
cardDesc.getAttributes().put(attribute, true);
}
cardDesc.setSet("BASIC");
cardDesc.setCollectible(false);
cardDesc.setBaseManaCost(desc.getValue(SpellArg.MANA, context, player, target, source, 0));
Card newCard = cardDesc.create();
context.addTempCard(newCard);
int boardPosition = SpellUtils.getBoardPosition(context, player, desc, source);
int count = desc.getValue(SpellArg.VALUE, context, player, target, source, 1);
SpellDesc spell = (SpellDesc) desc.get(SpellArg.SPELL);
SpellDesc successfulSummonSpell = (SpellDesc) desc.get(SpellArg.SPELL1);
for (int i = 0; i < count; i++) {
Card card = newCard.clone();
Minion minion = card.minion();
if (context.getLogic().summon(player.getId(), minion, source, boardPosition, false) && successfulSummonSpell != null) {
Entity newMinion = minion.transformResolved(context);
if (minion.isInPlay()) {
SpellUtils.castChildSpell(context, player, successfulSummonSpell, source, newMinion, newMinion);
}
}
if (spell != null) {
SpellUtils.castChildSpell(context, player, spell, source, target, minion);
}
}
}
}