webxoss-core/Zone.js

97 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-10-23 07:56:45 +02:00
'use strict';
function Zone (game,player,name,args,pids) {
args = args.split(' ');
// 引用
this.game = game;
this.player = player;
// 基本属性
this.name = name;
this.checkable = inArr('checkable',args); // 表示该区域,玩家可以查看里侧的牌.
this.up = inArr('up',args); // 表示该区域,卡片默认竖置.
this.faceup = inArr('faceup',args); // 表示该区域,卡片默认正面朝上.
this.bottom = inArr('bottom',args); // 表示该区域,卡片放入的时候,默认放进底部.
this.inhand = inArr('inhand',args); // 表示该区域,卡片是拿在玩家手里的,这意味着:
// 1. 该区域的卡,在游戏逻辑中,是里侧表示的,
// 而在UI中,对己方玩家是表侧表示的.
// 2. 该区域的卡,玩家可以随时洗切.
// 注册
game.register(this);
// 卡片
this.cards = [];
if (isArr(pids)) {
pids.forEach(function (pid) {
2016-10-25 12:14:51 +02:00
var card = new Card(game,player,this,pid);
this.cards.push(card);
if (card.sideA) this.cards.push(card.sideA);
if (card.sideB) this.cards.push(card.sideB);
2016-10-23 07:56:45 +02:00
},this);
}
// 附加的属性
this.disabled = false; // <ワーム・ホール>
this.powerDown = false; // <黒幻蟲 サソリス>
2017-03-29 16:26:21 +02:00
this.virus = false;
2017-03-30 05:39:44 +02:00
this.trap = null;
2016-10-23 07:56:45 +02:00
}
Zone.prototype.getTopCards = function (n) {
// var cards = [];
// for (var i = 0; i < n; i++) {
// var card = this.cards[i];
// if (!card) break;
// cards.push(card);
// }
// return cards;
return this.cards.slice(0,n);
};
// SIGNI 区中,魅饰卡及其它下方的卡在块结束时送至废弃区,
// 该函数返回区域中除了这些卡的卡.
Zone.prototype.getActualCards = function () {
return this.cards.filter(function (card) {
return !inArr(card,this.game.trashingCharms) &&
!inArr(card,this.game.trashingCards);
2016-11-05 11:40:21 +01:00
},this);
};
2017-03-31 19:10:44 +02:00
Zone.prototype.getSigni = function() {
return this.player.signis.filter(function (signi) {
return signi.zone === this;
},this)[0] || null;
};
2016-10-23 07:56:45 +02:00
Zone.prototype.moveCardsToTop = function (cards) {
cards = cards.filter(function (card) {
return inArr(card,this.cards);
},this);
2016-10-23 07:56:45 +02:00
cards.forEach(function (card) {
removeFromArr(card,this.cards);
},this);
this.cards.unshift.apply(this.cards,cards);
};
Zone.prototype.moveCardsToBottom = function (cards) {
cards = cards.filter(function (card) {
return inArr(card,this.cards);
},this);
2016-10-23 07:56:45 +02:00
cards.forEach(function (card) {
removeFromArr(card,this.cards);
},this);
this.cards.push.apply(this.cards,cards);
};
Zone.prototype.getStates = function () {
var states = [];
if (this.powerDown) states.push('powerDown');
if (this.disabled) states.push('disabled');
2017-03-29 16:26:21 +02:00
if (this.virus) states.push('infected');
2016-10-23 07:56:45 +02:00
return states;
};
global.Zone = Zone;