1 Star 2 Fork 0

散漫的水元素 / game

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
team.js 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
wangm 提交于 2017-06-23 14:05 . 完成
const Role = require('./role');
class Team {
constructor(server, option, creator) {
this.server = server;
this.option = option;
this.size = this.server.config.team.size;
this.roles = new Array(this.size).fill(creator || true, 0, 1).fill(true, 1);
}
add(role) {
if (this.roles[role.index] === true) {
this.roles[role.index] = role;
} else {
throw '';
}
}
remove(role) {
if (this.roles[role.index] === role) {
this.roles[role.index] = true;
} else {
throw '';
}
}
dispose() {
this.roles.forEach(role => role instanceof Role && delete role.player.room);
this.roles = new Array(this.size).fill(true);
}
get count() {
return this.roles.filter(role => role instanceof Role).length;
}
get emptyIndex() {
return this.roles.findIndex(role => role === true);
}
get emptyCount() {
return this.roles.filter(role => role === true).length;
}
get openCount() {
return this.roles.filter(role => role !== false).length;
}
get data() {
return {
name: this.option.name,
color: this.option.color,
icon: this.option.icon,
roles: this.roles.map(role => role instanceof Role ? role.data : role)
}
}
static create(server, option, creator) {
return new (server.config.Team || Team)(server, option, creator);
}
static createTeams(server, creator) {
let teams = server.config.teams;
if (teams && teams.length) {
return [ Team.create(server, teams[0], creator), ...teams.slice(1).map(team => Team.create(server, team)) ];
} else {
return [ Team.create(server, { }, creator) ];
}
}
}
module.exports = Team;
JavaScript
1
https://gitee.com/wm123450405/game.git
git@gitee.com:wm123450405/game.git
wm123450405
game
game
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891