技能结果优化处理

This commit is contained in:
yuexin 2020-12-28 12:13:19 +08:00
parent 4bca5751a5
commit 69e211ba60
2 changed files with 82 additions and 32 deletions

View File

@ -624,25 +624,46 @@ export class BattleHandler {
} }
let checklst: PlayerHandler[] = []; let checklst: PlayerHandler[] = [];
let lst: SkillInfoMsg[] = []; let lst: SkillInfoMsg[] = [];
let difflst: SkillTarget[] = []; let resmap: Map<string, SkillTarget[]> = new Map;
let lastkey = '';
let cnt = 0;
skillres.forEach((item: SkillTarget)=>{ skillres.forEach((item: SkillTarget)=>{
lst.push(item.exportData()); let key = item.srcskillid + '|' + item.srcplayer.getId();
if(!difflst.includes(item)){ if(item.srcpet){
difflst.push(item); key += '|' + item.srcpet._idx;
}
key += '' + cnt;
if(lastkey != key && lastkey != ''){
cnt++;
}
lastkey = key;
let tmplst = resmap.get(key);
if(!tmplst){
tmplst = [item];
resmap.set(key, tmplst);
}else{
tmplst.push(item);
} }
}); });
let skid = ''; let skid = '';
let tm = 0; let tm = 0;
difflst.forEach((item: SkillTarget) =>{ resmap.forEach((item: SkillTarget[]) =>{
tm += item.getLastTime(); let st = item[0];
skid += item.srcskillid + '|'; lst.push(st.exportMsg(item));
if(item.isHurtSkill() && item.targetIsPet()){ tm += st.getLastTime();
let ph = item.targetPlayer(); skid += st.srcskillid + '|';
if(!checklst.includes(ph)){
checklst.push(ph); st.isHurtSkill() && item.forEach((v: SkillTarget)=>{
if(v.targetIsPet()){
let ph = v.targetPlayer();
if(!checklst.includes(ph)){
checklst.push(ph);
}
} }
} })
}); });
if(this.isUsingCard()){ if(this.isUsingCard()){

View File

@ -71,7 +71,7 @@ export class SkillTarget{
lasttime: number; lasttime: number;
bresok: boolean = false; bresok: boolean = false;
res: SkillResult[]; res: SkillResult;
constructor(skill: Skill, splayer?: PlayerHandler, spet?: PetHandler, dstobj?: any, dsttype?: GameUnitType) { constructor(skill: Skill, splayer?: PlayerHandler, spet?: PetHandler, dstobj?: any, dsttype?: GameUnitType) {
this.srcplayer = splayer; this.srcplayer = splayer;
@ -120,20 +120,18 @@ export class SkillTarget{
}; };
public checkRes(){ public checkRes(){
if(!this.res){
this.res = [];
}
}; };
public success(efftype: number, effres: number){ public success(efftype: number, effres: number){
this.checkRes(); this.checkRes();
this.res.push(new SkillResult(efftype, effres, true)); this.res = new SkillResult(efftype, effres, true);
this.bresok = true; this.bresok = true;
}; };
public fail(efftype: number, err: number){ public fail(efftype: number, err: number){
this.checkRes(); this.checkRes();
this.res.push(new SkillResult(efftype, 0, false, err)); this.res = new SkillResult(efftype, 0, false, err);
}; };
public getLastTime(){ public getLastTime(){
@ -151,21 +149,52 @@ export class SkillTarget{
if(!this.res){ if(!this.res){
msg.errcode = -1; msg.errcode = -1;
}else{ }else{
this.res.forEach((item: SkillResult) => { let ed = new SKillEffectData();
let ed = new SKillEffectData(); if(this.dsttype == GameUnitType.PLAYER){
if(this.dsttype == GameUnitType.PLAYER){ ed.pos = 0;
ed.pos = 0; ed.player = (this.dst as PlayerHandler).getId();
ed.player = (this.dst as PlayerHandler).getId(); }else {
}else { ed.pos = (this.dst as PetHandler)._idx;
ed.pos = (this.dst as PetHandler)._idx; ed.player = (this.dst as PetHandler)._owner.getId();
ed.player = (this.dst as PetHandler)._owner.getId(); }
} ed.effect_id = this.res.effect_type;
ed.effect_id = item.effect_type; ed.val = this.res.bsuccess? this.res.effect_res: this.res.err;
ed.val = item.bsuccess? item.effect_res: item.err; ed.result = this.res.bsuccess? 0: -1;
ed.result = item.bsuccess? 0: -1; obj.datas.push(ed);
obj.datas.push(ed);
});
} }
return msg; return msg;
};
public exportMsg(lst: SkillTarget[]): SkillInfoMsg{
if(!lst || lst.length == 0){
return null;
}
let st = lst[0];
let msg = new SkillInfoMsg();
msg.data = new SkillInfoData();
let obj = msg.data;
obj.skill_id = st.srcskillid;
obj.player = st.srcplayer.getId(),
obj.pos = st.srcpet? st.srcpet._idx: 0;
obj.datas = [];
lst.forEach((item: SkillTarget) => {
if(item.res){
let ed = new SKillEffectData();
if(item.dsttype == GameUnitType.PLAYER){
ed.pos = 0;
ed.player = (item.dst as PlayerHandler).getId();
}else {
ed.pos = (item.dst as PetHandler)._idx;
ed.player = (item.dst as PetHandler)._owner.getId();
}
let res = item.res;
ed.effect_id = res.effect_type;
ed.val = res.bsuccess? res.effect_res: res.err;
ed.result = res.bsuccess? 0: -1;
obj.datas.push(ed);
}
});
return msg;
} }
}; };