增加角色死亡消息

This commit is contained in:
yuexin 2021-03-01 17:22:48 +08:00
parent 080badc9cd
commit 4aff24ba8d
3 changed files with 84 additions and 23 deletions

View File

@ -5,7 +5,7 @@ import { PlayerHandler } from "./PlayerHandler";
import CfgMan from "../CfgMan";
import { EffectCardType, GameCampType, GameUnitType, SkillEffectType, SkillRangeUnitType } from "../skill/SkillConst";
import { Pet } from "rooms/schema/Pet";
import {PetUpdateProcess, SkillParam, SkillResult, SkillTarget} from "../skill/SkillParam";
import {PetUpdateProcess, PlayerRemoveMsg, SkillParam, SkillResult, SkillTarget} from "../skill/SkillParam";
import { nosync, Room } from "colyseus";
import { Skill } from "../skill/Skill";
import { PetHandler } from "./PetHandler";
@ -13,6 +13,7 @@ import { SKillEffectData, SkillInfoMsg } from "message/SkillInfo";
import { PetInfo } from "message/PetInfo";
import arrUtil from "../../../utils/array.util";
import { debugRoom } from "../../../common/Debug";
import { RemovePetMsg } from "message/RemovePetMsg";
export class BattleHandler {
@ -30,6 +31,8 @@ export class BattleHandler {
private _cacheSkills: SkillTarget[] = [];
private _cachePets: PetHandler[] = [];
private _cachePlayerMsgs: PlayerRemoveMsg[] = [];
private _lastlinkph: PlayerHandler;
//--------------------对外接口--player相关---(外部调用)----------------------------
@ -488,6 +491,7 @@ export class BattleHandler {
this._sktime = 0;
this._cacheSkills.length = 0;
this._cachePets.length = 0;
this._cachePlayerMsgs.length = 0;
}
this._flowcount++;
@ -505,23 +509,18 @@ export class BattleHandler {
debugRoom(`[endFlow]${step}|${res}`);
if(res == 0){
if(this._cacheSkills.length > 0){
this.onSkillResultNotify(this._cacheSkills);
this._cacheSkills.length = 0;
}
this.handleCacheSkills();
let nt = this._sktime * 1000;
if(this._cachePets.length > 0){
if(this._cachePets.length > 0 || this._cachePlayerMsgs.length > 0){
if(nt > 0){
nt += 100; // 延时100ms处理随从
this._room.clock.setTimeout(()=>{
this.onUpdatePets(this._cachePets, null);
this.checkPets(this._cachePets);
this._cachePets.length = 0;
this.handleCachePets();
this.handleCachePlayers();
}, nt);
}else{
this.onUpdatePets(this._cachePets, null);
this.checkPets(this._cachePets);
this._cachePets.length = 0;
this.handleCachePets();
this.handleCachePlayers();
}
}
this._flowcount = res;
@ -533,6 +532,28 @@ export class BattleHandler {
return 0;
};
public handleCacheSkills(){
if(this._cacheSkills.length > 0){
this.onSkillResultNotify(this._cacheSkills);
this._cacheSkills.length = 0;
}
};
public handleCachePets(){
if(this._cachePets.length > 0){
this.onUpdatePets(this._cachePets, null);
this.checkPets(this._cachePets);
this._cachePets.length = 0;
}
};
public handleCachePlayers(){
if(this._cachePlayerMsgs.length > 0){
this.onPlayerDiedNotify(this._cachePlayerMsgs);
this._cachePlayerMsgs.length = 0;
}
};
public onPlayerCardChanged(player: PlayerHandler){
this._players.forEach((item: PlayerHandler) => {
item.onCardChanged(player);
@ -785,7 +806,18 @@ export class BattleHandler {
*/
public onPlayerDead(aplayer: Player){
let ph = this.getPlayer(aplayer);
ph && ph.die();
if(!ph){
return 0;
}
if(this.isFlowing()){
let obj = this._cachePlayerMsgs.find((v: PlayerRemoveMsg)=>{
return ph.getId() == v.id;
});
if(!obj){
this._cachePlayerMsgs.push(ph.exportRemoveMsg());
}
}
ph.die(this.isFlowing());
this._players.forEach((item: PlayerHandler) => {
(item != ph) && item.onPlayerDie(ph);
});
@ -816,6 +848,15 @@ export class BattleHandler {
// --------------------调用外部接口函数--------------------------
public onPlayerDiedNotify(players: PlayerRemoveMsg[]){
players && players.forEach((item: PlayerRemoveMsg)=>{
item.pets.forEach((pet: RemovePetMsg) =>{
this._room.bRemovePet(pet);
});
this._room.bPlayerDead({id: item.id});
});
};
public onAddPetNotify(apet: PetHandler){
return this._room.bAddPet(apet.exportInfoMsg());
};

View File

@ -7,7 +7,7 @@ import { Pet } from "rooms/schema/Pet";
import { CondDecideType, CondType, EffectCardType, GameUnitType, SkillEffectType, SkillType, SkillUserType, TriggerType } from "../skill/SkillConst";
import { UnitCfg } from "cfg/parsers/UnitCfg";
import { Skill } from "../skill/Skill";
import { SkillParam, SkillTarget } from "../skill/SkillParam";
import { PlayerRemoveMsg, SkillParam, SkillTarget } from "../skill/SkillParam";
import SkillMan from "../skill/SkillMan";
import { Card } from "rooms/schema/Card";
import arrUtil from "utils/array.util";
@ -31,6 +31,8 @@ export class PlayerHandler {
public _cardstate: CondType = CondType.NO_COND;
public _cardlinkfrom: PlayerHandler = null;
public _isdied: boolean = false;
_totalcc: number = 0;
private _totalem: number = 0;
@ -42,9 +44,9 @@ export class PlayerHandler {
this.updateHero(true);
};
public clear(){
public clear(cachedel: boolean = false){
this._pets.forEach((item: PetHandler) =>{
this.delPet(item, true);
this.delPet(item, true, cachedel);
});
this._self = null;
this._pets.length = 0;
@ -104,7 +106,7 @@ export class PlayerHandler {
return pr;
};
public delPet(pet: PetHandler, isbatchdel: boolean = false){
public delPet(pet: PetHandler, isbatchdel: boolean = false, cachedel: boolean = false){
if(!pet){
return;
}
@ -116,7 +118,7 @@ export class PlayerHandler {
(idx >= 0) && this._pets.splice(idx, 1);
}
this._owner.onDelPetNotify(pet);
!cachedel && this._owner.onDelPetNotify(pet);
};
public getPet(pet: Pet): PetHandler{
@ -378,8 +380,9 @@ export class PlayerHandler {
this._friend = aplayer;
};
public die(){
this.clear();
public die(needcache: boolean){
this._isdied = true;
this.clear(needcache);
//todo:
};
@ -855,5 +858,9 @@ export class PlayerHandler {
delBuff(buffid: number, buffcount: number, from: PetHandler): number{
return this._self? this._self.delBuff(buffid, buffcount, from): -1;
}
};
public exportRemoveMsg(): PlayerRemoveMsg{
return new PlayerRemoveMsg(this);
};
}

View File

@ -4,6 +4,7 @@ import { Skill } from "./Skill";
import { GameUnitType, SkillEffectType, SkillUserType } from "./SkillConst";
import { SKillEffectData, SkillInfoData, SkillInfoMsg } from "../../../message/SkillInfo";
import { PetInfo } from "message/PetInfo";
import { RemovePetMsg } from "message/RemovePetMsg";
export class SkillParam{
cardid: number;
@ -402,3 +403,15 @@ export class PetUpdateProcess{
this.info = pet.exportInfo();
};
};
export class PlayerRemoveMsg{
id: string;
pets: RemovePetMsg[];
constructor(player: PlayerHandler){
this.id = player.getId();
this.pets = [];
player._pets.forEach((item: PetHandler) =>{
this.pets.push(item.exportRemoveMsg());
});
}
}