merged with changes to statics

master
beholder 2011-09-22 05:53:59 +02:00
commit d4114ded51
12 changed files with 130 additions and 20 deletions

View File

@ -11,10 +11,11 @@ Starting Magarena:
On Mac, run Magarena.command
Magarena supports the following keyboard shortcuts :
Space or Right key : action button
Escape or Left key : undo button
Enter key : switch between graphical and text mode
F1 or M key : show or hide game messages
Space or Right key : action button
Escape or Left key : undo button
Control or Up key : same as clicking the left mouse button
F1 or M key : show or hide game messages
Enter key : switch between graphical and text mode
Selecting the AI to play against:
The desired AI can be selected in the "New duel" dialog (Arena -> New duel).
@ -47,7 +48,7 @@ Thanks to
Thank you for your support and have fun!
Release 2270 (September 23, 2011)
Release 1.18 (September 23, 2011)
============
brought to you by beholder, melvin, and wait321
@ -65,7 +66,8 @@ brought to you by beholder, melvin, and wait321
- improved crash handling to handle unhandled exception from any part of the
program
- improved how AI plays cards it doesn't have to pay the mana cost for
- added option in preferences to select type of card highlighting
- added option in preferences to select type of card highlighting
- added shortcut (Control or Up key) to simulate clicking mouse
- fixed a bug where the "When Targeted" trigger does not activate for spells
with kicker

View File

@ -3811,3 +3811,13 @@ color=w
converted=4
cost={3}{W}
timing=enchantment
>Karn's Touch
image=http://magiccards.info/scans/en/mm/86.jpg
value=3
rarity=R
type=Instant
color=u
converted=2
cost={U}{U}
timing=animate

View File

@ -0,0 +1,71 @@
package magic.card;
import magic.model.MagicAbility;
import magic.model.MagicGame;
import magic.model.MagicPermanent;
import magic.model.MagicPowerToughness;
import magic.model.MagicPlayer;
import magic.model.MagicType;
import magic.model.MagicPayedCost;
import magic.model.action.MagicPermanentAction;
import magic.model.action.MagicMoveCardAction;
import magic.model.stack.MagicCardOnStack;
import magic.model.choice.MagicTargetChoice;
import magic.model.target.MagicTargetPicker;
import magic.model.action.MagicBecomesCreatureAction;
import magic.model.event.MagicEvent;
import magic.model.event.MagicSpellCardEvent;
import magic.model.mstatic.MagicStatic;
import magic.model.mstatic.MagicLayer;
public class Karn_s_Touch {
private static final MagicStatic PT = new MagicStatic(MagicLayer.SetPT, MagicStatic.UntilEOT) {
@Override
public void getPowerToughness(final MagicGame game,final MagicPermanent permanent,final MagicPowerToughness pt) {
final int cmc = permanent.getCardDefinition().getConvertedCost();
pt.set(cmc,cmc);
}
};
private static final MagicStatic ST = new MagicStatic(MagicLayer.Type, MagicStatic.UntilEOT) {
@Override
public int getTypeFlags(final MagicPermanent permanent,final int flags) {
return flags|MagicType.Artifact.getMask()|MagicType.Creature.getMask();
}
};
private static final MagicTargetPicker<MagicPermanent> TP = new MagicTargetPicker<MagicPermanent>() {
@Override
protected int getTargetScore(final MagicGame game,final MagicPlayer player,final MagicPermanent permanent) {
final MagicPowerToughness pt=permanent.getPowerToughness(game);
final int power = permanent.getCardDefinition().getConvertedCost();
final int toughness = permanent.getCardDefinition().getConvertedCost();
int score=(pt.power()-power)*2+(pt.toughness()-toughness);
return permanent.getController()==player?-score:score;
}
};
public static final MagicSpellCardEvent S = new MagicSpellCardEvent() {
@Override
public MagicEvent getEvent(final MagicCardOnStack cardOnStack,final MagicPayedCost payedCost) {
final MagicPlayer player = cardOnStack.getController();
return new MagicEvent(
cardOnStack.getCard(),
player,
MagicTargetChoice.POS_TARGET_NONCREATURE_ARTIFACT,
TP,
new Object[]{cardOnStack,player},this,
"Target noncreature artifact$ becomes an artifact creature with " +
"power and toughness each equal to its converted mana cost until end of turn");
}
@Override
public void executeEvent(final MagicGame game,final MagicEvent event,final Object[] data,final Object[] choiceResults) {
game.doAction(new MagicMoveCardAction((MagicCardOnStack)data[0]));
event.processTargetPermanent(game,choiceResults,0,new MagicPermanentAction() {
public void doAction(final MagicPermanent creature) {
game.doAction(new MagicBecomesCreatureAction(creature,PT,ST));
}
});
}
};
}

View File

@ -1051,12 +1051,16 @@ public class MagicGame {
// ***** STATICS *****
public void addStatic(final MagicPermanent permanent) {
public void addCardStatics(final MagicPermanent permanent) {
for (final MagicStatic mstatic : permanent.getCardDefinition().getStatics()) {
addStatic(permanent, mstatic);
}
}
public Collection<MagicPermanentStatic> removeCardStatics(final MagicPermanent permanent) {
return statics.remove(permanent, permanent.getCardDefinition().getStatics());
}
public void addStatic(final MagicPermanent permanent, final MagicStatic mstatic) {
addStatic(new MagicPermanentStatic(getUniqueId(),permanent,mstatic));
}
@ -1079,7 +1083,7 @@ public class MagicGame {
return statics.removeTurn();
}
public Collection<MagicPermanentStatic> removeStatics(final MagicPermanent permanent) {
public Collection<MagicPermanentStatic> removeAllStatics(final MagicPermanent permanent) {
return statics.remove(permanent);
}
@ -1095,7 +1099,7 @@ public class MagicGame {
this.immediate=immediate;
}
public void addTrigger(final MagicPermanent permanent) {
public void addTriggers(final MagicPermanent permanent) {
for (final MagicTrigger trigger : permanent.getCardDefinition().getTriggers()) {
addTrigger(permanent, trigger);
}

View File

@ -556,7 +556,9 @@ public class MagicPermanent implements MagicSource,MagicTarget,Comparable<MagicP
} else if (toughness-damage<=0) {
actions.add(new MagicDestroyAction(this));
}
} else if (cardDefinition.isAura()) {
}
if (cardDefinition.isAura()) {
final MagicPlayAuraEvent auraEvent = (MagicPlayAuraEvent)cardDefinition.getCardEvent();
//not targeting since Aura is already attached
final MagicTargetChoice tchoice = new MagicTargetChoice(auraEvent.getTargetChoice(), false);
@ -566,8 +568,10 @@ public class MagicPermanent implements MagicSource,MagicTarget,Comparable<MagicP
game.logAppendMessage(controller,getName()+" is put into its owner's graveyard.");
actions.add(new MagicRemoveFromPlayAction(this,MagicLocationType.Graveyard));
}
} else if (cardDefinition.isEquipment() && equippedCreature.isValid()) {
if (!equippedCreature.isCreature(game) || equippedCreature.hasProtectionFrom(game,this)) {
}
if (cardDefinition.isEquipment() && equippedCreature.isValid()) {
if (isCreature(game) || !equippedCreature.isCreature(game) || equippedCreature.hasProtectionFrom(game,this)) {
actions.add(new MagicAttachEquipmentAction(this,MagicPermanent.NONE));
}
}

View File

@ -58,8 +58,8 @@ public class MagicAttachEquipmentAction extends MagicAction {
equipment.setEquippedCreature(creature);
//update the timestamp of the equipment's effects
oldStatics = game.removeStatics(equipment);
game.addStatic(equipment);
oldStatics = game.removeCardStatics(equipment);
game.addCardStatics(equipment);
score+=creature.getScore(game);
} else {
@ -77,7 +77,7 @@ public class MagicAttachEquipmentAction extends MagicAction {
if (validCreature) {
creature.removeEquipment(equipment);
game.removeStatics(equipment);
game.removeCardStatics(equipment);
game.addStatics(oldStatics);
}

View File

@ -31,8 +31,8 @@ public abstract class MagicPutIntoPlayAction extends MagicAction {
permanent.setEnchantedCreature(enchantedPermanent);
}
game.addTrigger(permanent);
game.addStatic(permanent);
game.addTriggers(permanent);
game.addCardStatics(permanent);
//execute come into play triggers
for (final MagicTrigger trigger : permanent.getCardDefinition().getComeIntoPlayTriggers()) {
@ -56,7 +56,7 @@ public abstract class MagicPutIntoPlayAction extends MagicAction {
}
permanent.getController().removePermanent(permanent);
game.removeTriggers(permanent);
game.removeStatics(permanent);
game.removeCardStatics(permanent);
}
void setEnchantedPermanent(final MagicPermanent aEnchantedPermanent) {

View File

@ -68,7 +68,7 @@ public class MagicRemoveFromPlayAction extends MagicAction {
removedTriggers = game.removeTriggers(permanent);
// Static
removedStatics = game.removeStatics(permanent);
removedStatics = game.removeAllStatics(permanent);
game.doAction(new MagicMoveCardAction(permanent,toLocation));
game.setStateCheckRequired();

View File

@ -90,6 +90,8 @@ public class MagicTargetChoice extends MagicChoice {
new MagicTargetChoice(MagicTargetFilter.TARGET_NONLAND_PERMANENT,true,MagicTargetHint.Negative,"target nonland permanent");
public static final MagicTargetChoice NEG_TARGET_ARTIFACT=
new MagicTargetChoice(MagicTargetFilter.TARGET_ARTIFACT,true,MagicTargetHint.Negative,"target artifact");
public static final MagicTargetChoice TARGET_NONCREATURE_ARTIFACT=
new MagicTargetChoice(MagicTargetFilter.TARGET_NONCREATURE_ARTIFACT,true,MagicTargetHint.None,"target noncreature artifact");
public static final MagicTargetChoice POS_TARGET_NONCREATURE_ARTIFACT=
new MagicTargetChoice(MagicTargetFilter.TARGET_NONCREATURE_ARTIFACT,true,MagicTargetHint.Positive,"target noncreature artifact");
public static final MagicTargetChoice TARGET_ARTIFACT_OR_ENCHANTMENT=

View File

@ -84,4 +84,20 @@ public class MagicPermanentStaticMap {
}
}
}
public Collection<MagicPermanentStatic> remove(final MagicPermanent permanent, final Collection<MagicStatic> statics) {
final Collection<MagicPermanentStatic> removedStatics = new ArrayList<MagicPermanentStatic>();
for (final MagicStatic mstatic : statics) {
final Collection<MagicPermanentStatic> mpstatics = effects.get(mstatic.getLayer());
for (final Iterator<MagicPermanentStatic> iterator = mpstatics.iterator();iterator.hasNext();) {
final MagicPermanentStatic permanentStatic = iterator.next();
if (permanentStatic.getPermanent() == permanent && permanentStatic.getStatic() == mstatic) {
iterator.remove();
removedStatics.add(permanentStatic);
break;
}
}
}
return removedStatics;
}
}

View File

@ -206,7 +206,7 @@ public interface MagicTargetFilter {
MagicTargetFilter TARGET_NONCREATURE_ARTIFACT=new MagicTargetFilter() {
public boolean accept(final MagicGame game,final MagicPlayer player,final MagicTarget target) {
final MagicPermanent targetPermanent=(MagicPermanent)target;
return targetPermanent.isArtifact() || !targetPermanent.isCreature(game);
return targetPermanent.isArtifact() && !targetPermanent.isCreature(game);
}
public boolean acceptType(final MagicTargetType targetType) {
return targetType==MagicTargetType.Permanent;

View File

@ -30,6 +30,7 @@ class TestStatics extends TestGameBuilder {
addToLibrary(P, "Plains", 10);
createPermanent(game,P,"Rupture Spire",false,8);
createPermanent(game,P,"Creeping Tar Pit",false,1);
createPermanent(game,P,"Raging Ravine",false,1);
createPermanent(game,P,"Phyrexian Crusader",false,3);
addToHand(P,"Glorious Anthem",1);
addToHand(P,"Godhead of Awe",1);