技能结果优化处理

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 lst: SkillInfoMsg[] = [];
let difflst: SkillTarget[] = [];
let resmap: Map<string, SkillTarget[]> = new Map;
let lastkey = '';
let cnt = 0;
skillres.forEach((item: SkillTarget)=>{
lst.push(item.exportData());
if(!difflst.includes(item)){
difflst.push(item);
let key = item.srcskillid + '|' + item.srcplayer.getId();
if(item.srcpet){
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 tm = 0;
difflst.forEach((item: SkillTarget) =>{
tm += item.getLastTime();
skid += item.srcskillid + '|';
resmap.forEach((item: SkillTarget[]) =>{
let st = item[0];
lst.push(st.exportMsg(item));
if(item.isHurtSkill() && item.targetIsPet()){
let ph = item.targetPlayer();
if(!checklst.includes(ph)){
checklst.push(ph);
tm += st.getLastTime();
skid += st.srcskillid + '|';
st.isHurtSkill() && item.forEach((v: SkillTarget)=>{
if(v.targetIsPet()){
let ph = v.targetPlayer();
if(!checklst.includes(ph)){
checklst.push(ph);
}
}
}
})
});
if(this.isUsingCard()){

View File

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