diff --git a/src/rooms/logic/Handler/BattleHandler.ts b/src/rooms/logic/Handler/BattleHandler.ts index a38ec81..6f92691 100644 --- a/src/rooms/logic/Handler/BattleHandler.ts +++ b/src/rooms/logic/Handler/BattleHandler.ts @@ -194,9 +194,9 @@ export class BattleHandler { */ public useCard(obj: {srcplayer: Player, card: number, cardpoint: number, dbpt_cnt: number, eff_cnt: number, dstplayer: Player, dstpet: Pet}) - { + :number{ if(!obj || !obj.card){ - return false; + return 0; } let ph = this.getPlayer(obj.srcplayer); @@ -206,7 +206,7 @@ export class BattleHandler { let dstpt = dstph? dstph.getPet(obj.dstpet): null; if(!ph){ - return false; + return 0; } let pt = obj.cardpoint; @@ -221,6 +221,8 @@ export class BattleHandler { ph.useCard(ps); this.onUseCardEnd(ps); + + return 0; }; /** @@ -332,11 +334,15 @@ export class BattleHandler { // --------------------调用外部接口函数-------------------------- public onAddPetNotify(apet: PetHandler){ - return this._room.bAddPet(apet.exportData()); + return this._room.bAddPet(apet.exportInfoMsg()); }; public onDelPetNotify(apet: PetHandler){ - return this._room.bRemovePet(apet.exportRemoveData()); + return this._room.bRemovePet(apet.exportRemoveMsg()); + }; + + public onUpdatePetNotify(apet: PetHandler){ + return this._room.updatePet([apet.exportInfo()]) }; public onPlayerAddCardNotify(aplayer: PlayerHandler, count: number, maxcount: number, from?: PlayerHandler){ diff --git a/src/rooms/logic/Handler/PetHandler.ts b/src/rooms/logic/Handler/PetHandler.ts index 39d437d..eaaba77 100644 --- a/src/rooms/logic/Handler/PetHandler.ts +++ b/src/rooms/logic/Handler/PetHandler.ts @@ -7,9 +7,10 @@ import SkillMan from "../skill/SkillMan"; import { EnhanceEffectType, PowerValueType, TriggerType } from "../skill/SkillConst"; import { PlayerHandler } from "./PlayerHandler"; -import { PetInfoMsg } from "../../../message/PetInfo"; +import { PetInfo, PetInfoMsg } from "../../../message/PetInfo"; import { SkillParam, SkillTarget } from "../skill/SkillParam"; import { RemovePetMsg } from "../../../message/RemovePetMsg"; +import { SKillEffectData } from "message/SkillInfo"; export class PetHandler { _pet: Pet; @@ -28,7 +29,7 @@ export class PetHandler { _baseap: number; // 基础 - _exap: number = 0; // 额外 + // _exap: number = 0; // 额外 _exredhurt: number = 0; // 减伤 @@ -87,12 +88,22 @@ export class PetHandler { }; public clearEffHalos(){ - // this._effhalos.length = 0; - this._exap = 0; + this._effhalos.length = 0; + // this._exap = 0; }; - public addEffHalo(skill: Skill, ap: number){ - this._exap += ap; + public addEffHalo(skill: Skill){ + this._effhalos.push(skill); + // this._exap += ap; + }; + + public getEffHaloV(): number{ + let n = 0; + this._effhalos.forEach((item: Skill) => { + n += item.getHaloValue(); + }); + return n; + // return this._exap; }; public addSkill(skillid: number){ @@ -151,41 +162,64 @@ export class PetHandler { return this._owner.handleSkill(skillid, count, obj, this); }; - public addAP(value: number){ - this._exap += value; - if(this._exap < 0){ - this._baseap += this._exap; - this._exap = 0; + public subAP(value: number):number { + // this._exap += value; + // if(this._exap < 0){ + // this._baseap += this._exap; + // this._exap = 0; + // } + if(value <= 0){ + return 0; } + let n = -value; + for(let i = 0; i < this._effhalos.length;i++){ + let dv = this._effhalos[i].addHaloValue(n); + n -= dv; + if(n >= 0){ + break; + } + } + if(n < 0){ + this._baseap += n; + } + this.dataChanged(); if(this._baseap < 0){ this.die(); } return value; }; - public addBaseAP(value: number){ + public addBaseAP(value: number): number{ + if(value == 0){ + return 0; + } this._baseap += value; + this.dataChanged(); if(this._baseap < 0){ this.die(); } return value; }; - public addExAP(value: number){ - return this.addAP(value); + public addExAP(value: number, skill: Skill){ + // return this.addAP(value); }; public totalAP(){ - return this._baseap + this._exap; + return this._baseap + this.getEffHaloV(); }; - public beHurt(value: number){ - let res = value * this._exredhurt; - return this.addAP(-res); + public beHurt(value: number): number{ + let res = value - value * this._exredhurt; + if(res < 0){ + return 0; + } + return this.subAP(res); }; public addReduceHurt(value: number){ this._exredhurt += value; + (value != 0) && this.dataChanged(); return value; }; @@ -225,7 +259,7 @@ export class PetHandler { public checkHalo(apet: PetHandler){ this._halos.forEach((item: Skill)=>{ if(item.isEffSelfPet(this, apet)){ - this.addEffHalo(item, item.getEffValue()); // 暂时都加战力 + this.addEffHalo(item); // 暂时都加战力 } }); }; @@ -236,12 +270,12 @@ export class PetHandler { }); }; - public exportData(): PetInfoMsg{ + public exportInfoMsg(): PetInfoMsg{ let obj = new PetInfoMsg({ id: this._id, isHero: this._isHero, ap: this._baseap, - extAp: this._exap, + extAp: this.getEffHaloV(), pos: this._idx, player: this._owner.getId(), harmReduce: this._exredhurt, @@ -251,11 +285,29 @@ export class PetHandler { return obj; }; - public exportRemoveData(): RemovePetMsg{ + public exportRemoveMsg(): RemovePetMsg{ return new RemovePetMsg({ id: this._id, player: this._owner.getId(), pos: this._idx }) }; + + public exportInfo(): PetInfo{ + let obj = new PetInfo(); + obj.id = this._id, + obj.isHero = this._isHero, + obj.ap = this._baseap, + obj.extAp = this.getEffHaloV(), + obj.pos = this._idx, + obj.player = this._owner.getId(), + obj.harmReduce = this._exredhurt, + obj.skills = this._selfskills, + obj.extSkills = this._exskills; + return obj; + }; + + public dataChanged(){ + this._owner && this._owner.onPetChanged(this); + } } diff --git a/src/rooms/logic/Handler/PlayerHandler.ts b/src/rooms/logic/Handler/PlayerHandler.ts index 17f0134..48ba329 100644 --- a/src/rooms/logic/Handler/PlayerHandler.ts +++ b/src/rooms/logic/Handler/PlayerHandler.ts @@ -81,6 +81,11 @@ export class PlayerHandler { return pr; }; + public delPet(ph: PetHandler){ + let idx = this._pets.indexOf(ph); + (idx >= 0) && this._pets.splice(idx, 1); + }; + public getPet(pet: Pet){ return this._pets.find((item:PetHandler)=>{ return item._pet == pet; @@ -171,21 +176,29 @@ export class PlayerHandler { // this._owner.onSkillResultNotify(lst); }else { let bhalo = false; + let bchged = false; for(let i = 0; i < count; i++){ let obj = pet.addSkill(skillid); - if(obj.isBornSkill()){ - lst.push(obj); - }else if(obj.isDieSkill()){ - - }else if(obj.isHaloSkill()){ - bhalo = true; - }else{ - lst.push(obj); + if(obj){ + bchged = true; + if(obj.isBornSkill()){ + lst.push(obj); + }else if(obj.isDieSkill()){ + //nothing to do + }else if(obj.isHaloSkill()){ + //only handle halo, not handle skill + bhalo = true; + }else{ + lst.push(obj); + } } } if(bhalo){ this.onHaloChanged(pet); } + if(bchged){ + pet.dataChanged(); + } } return this.simpleCheckSkills(lst, pet, param); }; @@ -223,23 +236,6 @@ export class PlayerHandler { return this._player.hp; }; - public checkHalo(apet:PetHandler){ - this._self.clearEffHalos(); - this._pets.forEach((obj:PetHandler)=>{ - obj.clearEffHalos(); - }); - this._pets.forEach((obj: PetHandler)=>{ - if(obj != apet){ - obj.checkHalo(apet); - } - apet.checkHalo(obj); - }); - if(this._self != apet){ - this._self.checkHalo(apet); - apet.checkHalo(this._self); - } - }; - public setFriend(aplayer: PlayerHandler){ this._friend = aplayer; }; @@ -265,10 +261,29 @@ export class PlayerHandler { // 遗愿 this.simpleCheckSkills(apet._dieSkills, apet); + + this.delPet(apet); + }; + + public onPetChanged(apet: PetHandler){ + this._owner.onUpdatePetNotify(apet); }; public onHaloChanged(apet: PetHandler){ - this.checkHalo(apet); + this._self.clearEffHalos(); + this._pets.forEach((obj:PetHandler)=>{ + obj.clearEffHalos(); + }); + this._pets.forEach((obj: PetHandler)=>{ + if(obj != apet){ + obj.checkHalo(apet); + } + apet.checkHalo(obj); + }); + if(this._self != apet){ + this._self.checkHalo(apet); + apet.checkHalo(this._self); + } }; public isMyPet(apet: PetHandler){ diff --git a/src/rooms/logic/skill/Skill.ts b/src/rooms/logic/skill/Skill.ts index c658a6a..26ad6d2 100644 --- a/src/rooms/logic/skill/Skill.ts +++ b/src/rooms/logic/skill/Skill.ts @@ -23,7 +23,7 @@ export class Skill { _start: boolean; _cb: any; - ap: number = 0; + halo_v: number = -1; rd: number = 0; // LIFE-CYCLE CALLBACKS: @@ -135,6 +135,7 @@ export class Skill { } }; + // 是否能影响自己 isEffSelfPet(srcpet: PetHandler, dstpet: PetHandler){ if(this._data.friendlyid != GameCampType.SELF){ return false; @@ -166,6 +167,33 @@ export class Skill { this._data.num_signid, this._data.eff_num, ap? ap: this._data.eff_num); }; + getHaloValue(ap?: number): number{ + if(!this.isHaloSkill()){ + return 0; + } + if(this.halo_v < 0){ + this.halo_v = this.getEffValue(ap); + } + return this.halo_v; + }; + + addHaloValue(v: number): number{ + if(this.halo_v < 0){ + this.halo_v = this.getEffValue(); + } + if(this.halo_v > 0){ + let tmp = this.halo_v; + this.halo_v += v; + if(this.halo_v < 0){ + this.halo_v = 0; + return -tmp; + }else{ + return v; + } + } + return 0; + }; + trigger(param: SkillParam, cb?: any) { //触发buff效果 let res = TriggerManager.onTrigger(this, param); @@ -249,7 +277,7 @@ export class Skill { case SkillEffectType.POWER_ENHANCE: case SkillEffectType.POWEREX_ENHANCE: if(tgt.dsttype != GameUnitType.NONE && tgt.dsttype != GameUnitType.PLAYER){ - let n = efftype == SkillEffectType.POWER_ENHANCE? tgt.dst.addBaseAP(effvalue): tgt.dst.addExAP(effvalue); + let n = efftype == SkillEffectType.POWER_ENHANCE? tgt.dst.addBaseAP(effvalue): tgt.dst.addExAP(effvalue, this); tgt.success(efftype, n); }else{ tgt.fail(efftype, -1);