160 lines
4.2 KiB
TypeScript
160 lines
4.2 KiB
TypeScript
import { UnitCfg } from "cfg/parsers/UnitCfg";
|
|
import { Pet } from "../../schema/Pet";
|
|
import CfgMan from "../CfgMan";
|
|
|
|
import {Skill} from "../skill/Skill";
|
|
import SkillMan from "../skill/SkillMan";
|
|
|
|
import { EnhanceEffectType, PowerValueType } from "../skill/SkillConst";
|
|
import { PlayerHandler } from "./PlayerHandler";
|
|
|
|
export class PetHandler {
|
|
_pet: Pet;
|
|
_owner: PlayerHandler;
|
|
_id: number;
|
|
_cfg: UnitCfg;
|
|
_skills: Map<number, Skill> = new Map();
|
|
|
|
_bornSkills: Skill[];
|
|
_dieSkills: Skill[];
|
|
_halos: Skill[];
|
|
|
|
_baseap: number; // 基础
|
|
|
|
_haloap: number = 0; // 光环
|
|
|
|
_exredhurt: number;
|
|
|
|
_isHero: boolean = false;
|
|
|
|
public init(apet: Pet, owner: PlayerHandler){
|
|
this._pet = apet;
|
|
this._owner = owner;
|
|
};
|
|
|
|
public setParam(obj:{
|
|
id: number, ap?: number, effcnt?: number, exskillid: number[]}
|
|
){
|
|
this._id = obj.id || 0;
|
|
this._cfg = CfgMan.findUnitCfg(this._id);
|
|
if(!obj.ap){
|
|
this._baseap = this._cfg.powernum;
|
|
}else{
|
|
this._baseap = obj.ap;
|
|
if(this._cfg.powernum_typeid == PowerValueType.RATIO){
|
|
this._baseap *= this._cfg.powernum;
|
|
}
|
|
}
|
|
if(obj.effcnt && this._isEnhancePower(this._cfg.edd_effid)){
|
|
this._baseap += CfgMan.calcEnhanceValue({eT: this._cfg.edd_effid, eV:this._cfg.edd_effnum,
|
|
eR: obj.effcnt, aP: obj.ap});
|
|
}
|
|
this._skills.clear();
|
|
|
|
this.addSkill(this._cfg.base_skill1id);
|
|
this.addSkill(this._cfg.base_skill2id);
|
|
this.addSkill(this._cfg.base_skill3id);
|
|
|
|
obj.exskillid && obj.exskillid.forEach((skillid: number)=>{
|
|
this.addSkill(skillid, true);
|
|
});
|
|
};
|
|
|
|
private _isEnhancePower(enid: number){
|
|
return enid == EnhanceEffectType.EN_POWER_BYCFG || enid == EnhanceEffectType.EN_POWER_BYAP;
|
|
};
|
|
|
|
public addHalo(halo: Skill){
|
|
this._halos.push(halo);
|
|
};
|
|
|
|
public addSkill(skillid: number, isExSkill?: boolean){
|
|
if(skillid > 0){
|
|
let obj = this._skills.get(skillid);
|
|
if(!obj){
|
|
obj = SkillMan.getSkill(skillid);
|
|
if(obj){
|
|
obj.setOwner(this);
|
|
this._skills.set(skillid, obj);
|
|
if(isExSkill){
|
|
obj.isExSkill = true;
|
|
}
|
|
if(obj.isBornSkill()){
|
|
this._bornSkills.push(obj);
|
|
}else if(obj.isDieSkill()){
|
|
this._dieSkills.push(obj);
|
|
}else if(obj.isHaloSkill()){
|
|
this._halos.push(obj);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
public delSkill(skillid:number){
|
|
if(skillid > 0){
|
|
let obj = this._skills.get(skillid);
|
|
if(obj){
|
|
let idx = this._bornSkills.indexOf(obj);
|
|
if(idx >= 0){
|
|
this._bornSkills.splice(idx, 1);
|
|
}
|
|
idx = this._dieSkills.indexOf(obj);
|
|
if(idx >= 0){
|
|
this._dieSkills.splice(idx, 1);
|
|
}
|
|
idx = this._halos.indexOf(obj);
|
|
if(idx >= 0){
|
|
this._halos.splice(idx, 1);
|
|
}
|
|
}
|
|
this._skills.delete(skillid);
|
|
}
|
|
};
|
|
|
|
public addAP(value: number){
|
|
this._haloap += value;
|
|
if(this._haloap < 0){
|
|
this._baseap += this._haloap;
|
|
this._haloap = 0;
|
|
}
|
|
if(this._baseap < 0){
|
|
this.die();
|
|
}
|
|
};
|
|
|
|
public totalAP(){
|
|
return this._baseap + this._haloap;
|
|
};
|
|
|
|
public beHurt(value: number){
|
|
this.addAP(-value);
|
|
};
|
|
|
|
public born(param: any){
|
|
this._owner && this._owner.onPetBorned(this, param);
|
|
};
|
|
|
|
public die(){
|
|
this._dieSkills.forEach((item: Skill)=>{
|
|
|
|
});
|
|
|
|
this._owner && this._owner.onPetDied(this);
|
|
};
|
|
|
|
public attack(skill: Skill){
|
|
|
|
};
|
|
|
|
public checkHalo(apet: PetHandler){
|
|
this._halos.forEach((item: Skill)=>{
|
|
|
|
});
|
|
};
|
|
}
|