91 lines
2.0 KiB
TypeScript
91 lines
2.0 KiB
TypeScript
import {filter, MapSchema, Schema, SetSchema, type} from "@colyseus/schema";
|
|
import {Pet} from "./Pet";
|
|
import {Card} from "./Card";
|
|
import {GameEnv} from "../../cfg/GameEnv";
|
|
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
|
|
|
|
|
export class Player extends Schema {
|
|
@type("string")
|
|
id: string;
|
|
|
|
@type("number")
|
|
heroId: number;
|
|
/**
|
|
* 手牌
|
|
*/
|
|
@filter(function(this: Player, client, value, root) {
|
|
return (client.sessionId == this.id);
|
|
})
|
|
@type({ map: Card })
|
|
cards = new MapSchema<Card>();
|
|
|
|
@type({ set: "string" })
|
|
cardSet = new SetSchema<string>();
|
|
/**
|
|
* 当前hp
|
|
*/
|
|
@type("number")
|
|
hp: number;
|
|
|
|
/**
|
|
* 状态
|
|
* 0: 正常状态
|
|
* 1: 已准备好
|
|
* 2: 死亡
|
|
* 3: 已换完牌
|
|
* 4: 玩家已选择英雄
|
|
* 9: 掉线
|
|
*/
|
|
@type("number")
|
|
state: number;
|
|
/**
|
|
* 随从
|
|
*/
|
|
@type({ map: Pet })
|
|
pets = new MapSchema<Pet>();
|
|
|
|
/**
|
|
* 队伍
|
|
*/
|
|
@type("number")
|
|
team: number;
|
|
/**
|
|
* 玩家灵活时限, 客户端每次显示倒计时的时候, 需读取该时间
|
|
*/
|
|
@type("number")
|
|
extraTime: number;
|
|
/**
|
|
* 当前游戏总抽卡数量
|
|
*/
|
|
countTotal: number;
|
|
/**
|
|
* 当前累计抽卡
|
|
*/
|
|
countPresent: number;
|
|
|
|
/**
|
|
* 英雄绑定的卡组, 选好英雄后, 从默认配置或玩家卡组(待实现)中获取
|
|
* [随从id, 权重]
|
|
*/
|
|
unitCfgs: number[][];
|
|
|
|
constructor(id: string, heroId: number, team: number) {
|
|
super();
|
|
this.id = id;
|
|
this.state = PlayerStateConst.PLAYER_NORMAL;
|
|
this.hp = 0;
|
|
this.heroId = heroId;
|
|
this.team = team;
|
|
this.countTotal = 0;
|
|
this.countPresent = 0;
|
|
for (let i = 0; i < new GameEnv().maxPlayerPetCount + 1; i++) {
|
|
let pet = new Pet(i);
|
|
pet.state = 0;
|
|
pet.isHero = i === 0;
|
|
this.pets.set(i+'', pet);
|
|
|
|
}
|
|
}
|
|
}
|