Improve player.getCard()

This commit is contained in:
WEBXOSS 2016-11-10 17:07:00 +08:00
parent 86e7897f62
commit 890a54d1ad

View file

@ -2162,48 +2162,43 @@ Player.prototype.setCrossPair = function () {
// For test: // For test:
Player.prototype.getCard = function (cid) { Player.prototype.matchCard = function (arg) {
if (isStr(cid)) { var cid = 0;
for (var i = 0; i < this.game.cards.length; i++) { for (var i = 0; i < this.game.cards.length; i++) {
var card = this.game.cards[i]; var card = this.game.cards[i];
if (CardInfo[card.cid].name_zh_CN === cid) { var info = CardInfo[card.cid];
cid = card.cid; var matched = info.name === arg ||
break; info.name_zh_CN === arg ||
} info.cid === arg ||
info.wxid === arg;
if (matched) {
cid = card.cid;
break;
} }
if (isStr(cid)) return null;
} }
if (!cid) return null;
var cards = concat(this.mainDeck.cards,this.trashZone.cards,this.enerZone.cards,this.lifeClothZone.cards); var cards = concat(this.mainDeck.cards,this.trashZone.cards,this.enerZone.cards,this.lifeClothZone.cards);
for (var i = 0; i < cards.length; i++) { for (var i = 0; i < cards.length; i++) {
var card = cards[i]; var card = cards[i];
if (card.cid === cid) { if (card.cid === cid) {
card.moveTo(this.handZone);
return card; return card;
} }
} }
return null; return null;
}; };
Player.prototype.getCard = function (arg) {
var card = this.matchCard(arg);
if (!card) return null;
card.moveTo(this.handZone);
return card;
};
Player.prototype.putCardToLifeCloth = function (cid) { Player.prototype.putCardToLifeCloth = function (cid) {
if (isStr(cid)) { var card = this.matchCard(arg);
for (var i = 0; i < this.game.cards.length; i++) { if (!card) return null;
var card = this.game.cards[i]; card.moveTo(this.lifeClothZone);
if (CardInfo[card.cid].name_zh_CN === cid) { return card;
cid = card.cid;
break;
}
}
if (isStr(cid)) return null;
}
var cards = concat(this.mainDeck.cards,this.trashZone.cards,this.enerZone.cards,this.hands,this.signis);
for (var i = 0; i < cards.length; i++) {
var card = cards[i];
if (card.cid === cid) {
card.moveTo(this.lifeClothZone);
return card;
}
}
return null;
}; };
global.Player = Player; global.Player = Player;