本文会简单介绍action的一般写法
基础
如果现在我想自定义一张效果为“获得3点格挡,抽1张牌,若自身力量小于1则获得一点力量”的1费技能卡,升级后格挡数+4,这其实完全可以直接在卡牌里面写
public class Strengthen extends AbstractModCard {
public static final String ID = "Mod:Strengthen";
public Strengthen() {
super(ID, 1, CardType.SKILL, CardRarity.COMMON);
this.baseBlock = 3;
}
@Override
public void use(AbstractPlayer p, AbstractMonster m) {
addToBot(new GainBlockAction(p,this.baseBlock));
addToBot(new DrawCardAction(1));
if(p.hasPower(StrengthPower.POWER_ID)){
if(p.getPower(StrengthPower.POWER_ID).amount < 1){
addToBot(new ApplyPowerAction(p,p,new StrengthPower(p,1)));
}
}
}
@Override
public void upgrade(){
if(!this.upgraded){
upgradeBlock(4);
upgradeName();
}
}
}
当然我们也可以将这一操作包装成一个action以便以后重复使用
需要继承AbstractGameAction
public class StrengthenAction extends AbstractGameAction {
AbstractPlayer p;
int block;
int draw;
public StrengthenAction(AbstractPlayer p,int block){
this.p = p;
this.block = block;
draw = 1;
}
@Override
public void update() {
addToBot(new GainBlockAction(p,block));
addToBot(new DrawCardAction(draw));
if(p.hasPower(StrengthPower.POWER_ID)){
if(p.getPower(StrengthPower.POWER_ID).amount < 1){
addToBot(new ApplyPowerAction(p,p,new StrengthPower(p,1)));
}
}
isDone = true;
}
}
注意,在update方法结尾需要用isDone=true来表示action结束
现在我们可以直接使用这个action来实现卡牌效果
public class Strengthen extends AbstractModCard {
public static final String ID = "Mod:Strengthen";
public Strengthen() {
super(ID, 1, CardType.SKILL, CardRarity.COMMON);
this.baseBlock = 3;
}
@Override
public void use(AbstractPlayer p, AbstractMonster m) {
addToBot(new StrengthenAction(p,this.baseBlock));
}
@Override
public void upgrade(){
if(!this.upgraded){
upgradeBlock(4);
upgradeName();
}
}
}
不要忘了本地化
{
"Mod:Strike":{
"NAME" :"打击",
"DESCRIPTION": "造成 !D! 点伤害。"
},
"Mod:Defend":{
"NAME": "防御",
"DESCRIPTION": "获得 !B! 点 格挡 。"
},
"Mod:Strengthen":{
"NAME":"我要变强!"
"DESCRIPTION":"获得 !B! 点格挡,抽1张牌,若自身力量小于1则获得一点力量"
}
}
代码、本地化、配图、注册 是每张卡都是要进行的。
“抉择”式卡牌
抉择真帅吧(无端
我想设计一个叠甲、抽牌、加力量三选一的卡怎么写?
首先要把这三个选项分别写成一张卡
叠甲选项
public class BlockChoice extends AbstractModCard {
public static final String ID = "Mod:BlockChoice";
public BlockChoice(){
super(ID,-2, CardType.SKILL, CardColor.COLORLESS,CardRarity.COMMON,CardTarget.NONE);
this.baseBlock = 8;
}
@Override
public void use(AbstractPlayer p, AbstractMonster m){
this.onChoseThisOption();
}
@Override
public void onChoseThisOption(){
AbstractPlayer p = AbstractDungeon.player;
addToBot(new GainBlockAction(p,this.baseBlock));
}
}
另外两张选项卡同理,使用的action上文已提及,不再赘述
创建一个action
public class ChooseAction extends AbstractGameAction {
@Override
public void update() {
ArrayList<AbstractCard> choices = new ArrayList<>();
choices.add(new BlockChoice());
choices.add(new DrawChoice());
choices.add(new StrengthChoice());
if(!choices.isEmpty()){
addToBot(new ChooseOneAction(choices));
}
this.isDone = true;
}
}
只需要在卡牌中调用此action便可以实现上述的“抉择”功能
未完待续。。。。