implement bet

This commit is contained in:
WEBXOSS 2017-02-26 14:15:18 +08:00
parent 1d28364349
commit a8131ba290
3 changed files with 41 additions and 8 deletions

19
Card.js
View file

@ -302,9 +302,11 @@ Card.prototype.getGrowCostObj = function () {
return obj;
};
Card.prototype.getChainedCostObj = function () {
if (!this.player.chain) return this;
var obj = Object.create(this);
Card.prototype.getChainedCostObj = function (obj) {
if (!obj) {
obj = Object.create(this);
}
if (!this.player.chain) return obj;
obj.costWhite -= this.player.chain.costWhite || 0;
obj.costBlack -= this.player.chain.costBlack || 0;
obj.costRed -= this.player.chain.costRed || 0;
@ -524,8 +526,17 @@ Card.prototype.canUse = function (timming,ignoreCost) {
if (this.player.artsBanned) return false;
if (!inArr(timming,this.timmings)) return false;
if (this.player.oneArtEachTurn && this.game.getData(this.player,'flagArtsUsed')) return false;
// cost 判断
if (ignoreCost) return true;
return this.player.enoughCost(this.getChainedCostObj());
var cost = this.getChainedCostObj()
if (this.player.enoughCost(cost)) return true;
// bet 相关
if (this.bet && this.bettedCost) {
cost = this.getChainedCostObj(this.bettedCost)
if (this.player.enoughCost(cost)) return true;
}
return false;
}
return false;
};

View file

@ -124858,6 +124858,7 @@ var CardInfo = {
"Banish all of your opponent's SIGNI."
],
bet: 2,
bettedCost: {},
artsEffect: {
actionAsyn: function () {
return this.game.banishCardsAsyn(this.player.opponent.signis);

View file

@ -649,6 +649,23 @@ Player.prototype.handleArtsAsyn = function (card,ignoreCost) {
this.game.blockStart();
// 1. 放到检查区
card.moveTo(this.checkZone);
// bet
if (!card.bet) return;
if (this.coin < card.bet) return;
var bettedCost = Object.create(costObj);
if (card.bettedCost) {
bettedCost = this.getChainedCostObj(card.bettedCost);
}
bettedCost.costCoin += card.bet;
if (!this.enoughCost(costObj)) {
// 必须 bet
return costObj = bettedCost;
}
return this.player.confirmAsyn('BET').callback(this,function (answer) {
if (!answer) return;
costObj = bettedCost;
})
}).callback(this,function () {
// 如果效果不止一个,选择其中n个发动
if (card.artsEffects.length === 1) {
effects = card.artsEffects.slice();
@ -669,8 +686,7 @@ Player.prototype.handleArtsAsyn = function (card,ignoreCost) {
});
}
}).callback(this,function () {
// 2. 支付费用
// アンコール费用,约定: 除了颜色费用,其它属性直接覆盖
// encore 费用,约定: 除了颜色费用,其它属性直接覆盖
if (!card.encore) return;
var encoredCost = Object.create(costObj);
encoredCost.source = card;
@ -1829,8 +1845,8 @@ Player.prototype.payCostAsyn = function (obj,cancelable) {
}
// Coin
if (obj.costCoin) {
this.coin -= obj.costCoin
if (this.coin < 0) this.coin = 0
this.loseCoins(obj.costCoin);
costArg.bet = costCoin;
}
// 其它
if (obj.costAsyn) {
@ -2221,6 +2237,11 @@ Player.prototype.gainCoins = function(count) {
}
};
Player.prototype.loseCoins = function(count) {
this.coin -= count;
if (this.coin < 0) this.coin = 0;
};
// For test:
Player.prototype.matchCard = function (arg) {