import { Player } from "../../schema/Player"; import { PetHandler } from "./PetHandler"; import { HeroCfg } from "../../../cfg/parsers/HeroCfg"; import { BattleHandler } from "./BattleHandler"; import CfgMan from "../CfgMan"; import { Card } from "rooms/schema/Card"; import { Pet } from "rooms/schema/Pet"; import { EffectCardType, GameUnitType } from "../skill/SkillConst"; import { UnitCfg } from "cfg/parsers/UnitCfg"; import { Skill } from "../skill/Skill"; import { SkillParam, SkillTarget } from "../skill/SkillParam"; export class PlayerHandler { public _player: Player; public _playercfg: HeroCfg; public _self: PetHandler; public _unitcfg: UnitCfg; public _pets: PetHandler[] = []; public _skills: Skill[] = []; public _exskills: Skill[] = []; public _owner: BattleHandler; _friend: PlayerHandler; public init(aplayer: Player, owner: BattleHandler){ this._owner = owner; this._player = aplayer; this._playercfg = CfgMan.findPlayerCfg(this._player.heroId); this._self = new PetHandler(); this._self.init(null, this, 0); this._self._isHero = true; let lst = this._playercfg.ex_skill? [this._playercfg.ex_skill]: null; this._self.setParam({id: this._playercfg.herounit_id, exskillid: lst}); this._unitcfg = this._playercfg && CfgMan.findUnitCfg(this._playercfg.herounit_id); }; public getCurrCardCount(){ return 0; }; public getTotalCardCount(){ return 0; }; public getId(): string{ return this._player.id + ''; }; public newPet(): PetHandler { let res = null; let pr = null; let n = 0; for(let [key, obj] of this._player.pets){ if(obj.ap == 0){ res = obj; break; } ++n; } if(res){ pr = new PetHandler; pr.init(res, this, n); this._pets.push(pr); } return pr; }; public getPet(pet: Pet){ return this._pets.find((item:PetHandler)=>{ return item._pet == pet; }) }; public exportAllPets(ct: GameUnitType, param: SkillParam, expet: PetHandler, dst: SkillTarget[]): SkillTarget[]{ if(!dst){ return null; } switch(ct){ case GameUnitType.BATTLEUNIT: let lst = this._pets.reverse(); lst.forEach(element => { if(expet != element){ dst.push(new SkillTarget(param.srcplayer, param.srcpet, param.skill, element, GameUnitType.PET)); } }); (expet != this._self) && dst.push(new SkillTarget(param.srcplayer, param.srcpet, param.skill, this._self, GameUnitType.PET)); break; case GameUnitType.HERO: (expet != this._self) && dst.push(new SkillTarget(param.srcplayer, param.srcpet, param.skill, this._self, GameUnitType.PET)); break; case GameUnitType.PET: lst.forEach(element => { if(expet != element){ dst.push(new SkillTarget(param.srcplayer, param.srcpet, param.skill, element, GameUnitType.PET)); } }); break; default: break; } return dst; }; public useCard(obj: SkillParam) { let cfg = CfgMan.findEffCardCfg(obj.cardid); if(!cfg){ return false; } if(cfg.type_id == EffectCardType.NPC){ let pet = this.newPet(); if(!pet){ return false; } pet.setParam({id: cfg.stageunit_id, ap:obj.cardpoint, effcnt: obj.edd_cnt, exskillid: [cfg.quoteskill1id, cfg.quoteskill2id, cfg.quoteskill3id, cfg.quoteskill4id]}); obj.srcpet = pet; pet.born(obj); }else if(cfg.type_id == EffectCardType.MAGIC){ } }; public useSkill(obj: SkillParam) { }; public addSkill(skillid: number){ }; public addCard(count: number){ return this._owner.onPlayerAddCard(this, count, 0); }; public addCardLimit(maxcount: number){ return this._owner.onPlayerAddCard(this, 0, maxcount); }; public stealCard(dstplayer: PlayerHandler, count: number){ return this._owner.onPlayerStealCard(this, dstplayer, count); }; public addHP(value: number){ this._player.hp += value; if(value < 0){ this.die(); } return value; }; public getHP(){ return this._player.hp; }; public checkHalo(apet:PetHandler){ this._pets.forEach((obj: PetHandler)=>{ if(obj != apet){ obj.checkHalo(apet); } apet.checkHalo(obj); }); }; public setFriend(aplayer: PlayerHandler){ this._friend = aplayer; }; public die(){ //todo: }; public onPetBorned(apet: PetHandler, param: SkillParam){ //todo: build pet init json -> client this._owner.onAddPetNotify(apet); // 战吼 let reslst: SkillTarget[] = []; apet._bornSkills.forEach((item: Skill)=>{ let lst = item.trigger(param); reslst = reslst.concat(lst); }); //todo: build bornskill json -> client // 光环 this.checkHalo(apet); //todo: build haloskill json -> client }; public onPetDied(apet: PetHandler){ }; public isMyPet(apet: PetHandler){ return this._pets.includes(apet); }; public hasTransEffCardSkill(): boolean{ if(!this._self){ return false; } let bok = false; for(let [key, val] of this._self._skills){ if(val.isTransEffCardSkill()){ bok = true; break; } } return bok; }; }