86 lines
3.3 KiB
TypeScript
86 lines
3.3 KiB
TypeScript
import {Command} from "@colyseus/command";
|
|
import {CardGameState} from "../schema/CardGameState";
|
|
import {Client} from "colyseus";
|
|
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
|
import {BeginGameCommand} from "./BeginGameCommand";
|
|
import {BaseConst} from "../../constants/BaseConst";
|
|
import {error} from "../../common/Debug";
|
|
import {GameEnv} from "../../cfg/GameEnv";
|
|
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
|
|
|
/**
|
|
* 选择英雄
|
|
*/
|
|
export class SelectHeroCommand extends Command<CardGameState, { client: Client, heroId: number, cardGroup?: string }> {
|
|
execute({client, heroId, cardGroup} = this.payload) {
|
|
let player = this.state.players.get(client.sessionId);
|
|
if (player.state != PlayerStateConst.PLAYER_READY) {
|
|
return;
|
|
}
|
|
const heroMap = global.$cfg.get(BaseConst.HERO);
|
|
if (!heroMap || !heroMap.has(heroId)) {
|
|
this.room.sSelectHero(client, {errcode: 1, errmsg: '无法找到对应英雄的配置'});
|
|
return;
|
|
}
|
|
const heroData = heroMap.get(heroId);
|
|
player.heroId = heroId;
|
|
const unitMap = global.$cfg.get(BaseConst.UNIT);
|
|
const unitData = unitMap.get(heroData.herounit_id);
|
|
if (!unitData) {
|
|
error(`未找到英雄的Unit配置: ${heroId}`);
|
|
}
|
|
for (let key in StateTypeEnum) {
|
|
if (!isNaN(Number(key))) {
|
|
// @ts-ignore
|
|
let type: StateTypeEnum = key;
|
|
player.statData.set(type, 0);
|
|
}
|
|
}
|
|
|
|
player.state = PlayerStateConst.PLAYER_SELECT_HERO;
|
|
player.hp = unitData.hero_hp;
|
|
player.extraTime = new GameEnv().maxExtTime * 1000;
|
|
let heroPet = player.pets.get('0');
|
|
heroPet.ap = unitData.powernum;
|
|
heroPet.state = 1;
|
|
heroPet.id = unitData.id;
|
|
if (unitData.base_skill1id) heroPet.skills.push(unitData.base_skill1id);
|
|
if (unitData.base_skill2id) heroPet.skills.push(unitData.base_skill2id);
|
|
if (unitData.base_skill3id) heroPet.skills.push(unitData.base_skill3id);
|
|
const effectMap = global.$cfg.get(BaseConst.EFFECTCARD);
|
|
// TODO: // 根据传入的卡组id去设置英雄可用的unit
|
|
for (let i = 1; i < 10; i++) {
|
|
if (!heroData[`follower${i}id`]) {
|
|
break;
|
|
}
|
|
let unitId = heroData[`follower${i}id`];
|
|
|
|
let weight = 0;
|
|
let effectId;
|
|
for (let [,eff] of effectMap) {
|
|
if (eff.stageunit_id == unitId) {
|
|
weight = eff.weight;
|
|
effectId = eff.id;
|
|
break;
|
|
}
|
|
}
|
|
if (!effectId) {
|
|
error(`未找到效果卡的配置: ${unitId}`);
|
|
}
|
|
player.unitCfgs.set(effectId+'', weight);
|
|
}
|
|
this.room.battleMan.updatePlayer(player.id, player);
|
|
this.room.bSelectHero({errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId});
|
|
let readyCount = 0;
|
|
for (let [, player] of this.state.players) {
|
|
if (player.state === PlayerStateConst.PLAYER_SELECT_HERO) {
|
|
readyCount++;
|
|
}
|
|
}
|
|
if (readyCount >= this.room.maxClients) {
|
|
this.room.stopSchedule('pick_hero');
|
|
return [new BeginGameCommand()];
|
|
}
|
|
}
|
|
}
|