逻辑基本处理完毕

This commit is contained in:
y.x 2020-12-08 18:37:40 +08:00
parent 276ed94c1a
commit 4428dc7c7e
4 changed files with 137 additions and 109 deletions

View File

@ -78,6 +78,24 @@ export class BattleHandler {
}
};
public getFinalTarget(players: PlayerHandler[], apet: PetHandler, ct: GameUnitType,
checktaunt: boolean=false): PetHandler
{
let pet = apet;
let bok = this.petIsValid(pet, players, ct);
if(checktaunt && (!bok || !pet._istaunt)){
for(let i = 0; i < players.length;i++){
let obj = players[i].findTauntPet();
if(obj){
pet = obj;
bok = true;
break;
}
}
}
return bok? pet: null;
};
public getSkillTargets(skill: Skill, param: SkillParam): SkillTarget[]{
let lst: SkillTarget[] = [];
let players = this.getTargetPlayers(skill._data.friendlyid, param.srcplayer, param.dstplayer);
@ -92,32 +110,10 @@ export class BattleHandler {
case GameUnitType.HERO:
case GameUnitType.PET:
if(skill.isSingleTarget()){
let pet = param.dstpet;
let bok = pet && this.petIsValid(pet, players, skill._data.targetid);
if(skill.isHurtPowerSkill()){
let tauntpets: PetHandler[] = [];
if(bok){
let bfind = false;
players.forEach((item:PlayerHandler) =>{
let obj = item.findTauntPet();
if(obj) {
tauntpets.push(obj);
if(obj == pet){
bfind = true;
}
}
});
bok = bfind || tauntpets.length <= 0;
}
if(!bok && tauntpets.length > 0){
pet = tauntpets[0];
bok = true;
}
}
if(bok){
lst.push(new SkillTarget(skill, param.srcplayer, param.srcpet,
pet, pet._isHero? GameUnitType.HERO: GameUnitType.PET));
}
let pet = this.getFinalTarget(players, param.dstpet, skill._data.targetid,
skill.isHurtPowerSkill());
pet && lst.push(new SkillTarget(skill, param.srcplayer, param.srcpet,
pet, pet._isHero? GameUnitType.HERO: GameUnitType.PET));
}else{
if(skill.isAllTarget()){
players.forEach((item: PlayerHandler)=>{
@ -149,34 +145,40 @@ export class BattleHandler {
let lst: PlayerHandler[] = [];
switch(gct){
case GameCampType.SELF:
lst.push(src);
if(src && src.isAlive()){
lst.push(src);
}
break;
case GameCampType.FRIEND:
let obj = this.getFriend(src);
obj && lst.push(obj);
if(obj && obj.isAlive()){
lst.push(obj);
}
break;
case GameCampType.MYTEAM:
if(src){
lst.push(src);
src.isAlive() && lst.push(src);
let obj = this.getFriend(src);
obj && lst.push(obj);
obj && obj.isAlive() && lst.push(obj);
}
break;
case GameCampType.ENEMY:
if(dst && dst._friend != src){
if(dst && dst._friend != src && dst.isAlive()){
lst.push(dst);
}
break;
case GameCampType.ENEMYTEAM:
for(let [key, obj] of this._players){
if(obj != src && obj != src._friend){
if(obj != src && obj != src._friend && obj.isAlive()){
lst.push(obj);
}
}
break;
case GameCampType.ALL:
for(let [key, obj] of this._players){
lst.push(obj);
if(obj && obj.isAlive()){
lst.push(obj);
}
}
break;
default:
@ -338,7 +340,7 @@ export class BattleHandler {
};
public onPlayerAddCardNotify(aplayer: PlayerHandler, count: number, maxcount: number, from?: PlayerHandler){
return this._room.addCard(aplayer.getId(), count, maxcount);
return this._room.addCard(aplayer.getId(), count, maxcount, 1, from? from.getId(): null);
};
public onPlayerStealCardNotify(srcplayer: PlayerHandler, dstplayer: PlayerHandler, count: number){
@ -357,8 +359,7 @@ export class BattleHandler {
};
public onPlayerAddHPNotify(aplayer: PlayerHandler, addhp: number){
//todo:
return addhp;
return this._room.updateHp(aplayer.getId(), addhp);
}
//end------------------------------------------------
}

View File

@ -8,7 +8,7 @@ import SkillMan from "../skill/SkillMan";
import { EnhanceEffectType, PowerValueType, TriggerType } from "../skill/SkillConst";
import { PlayerHandler } from "./PlayerHandler";
import { PetInfoMsg } from "../../../message/PetInfo";
import { SkillParam } from "../skill/SkillParam";
import { SkillParam, SkillTarget } from "../skill/SkillParam";
import { RemovePetMsg } from "../../../message/RemovePetMsg";
export class PetHandler {
@ -46,7 +46,7 @@ export class PetHandler {
this._idx = index;
};
public setParam(id: number, param?: SkillParam, exskillid?: number[]){
public loadData(id: number, param?: SkillParam, exskillid?: number[]){
this._id = id || 0;
this._cfg = CfgMan.findUnitCfg(this._id);
if(!param || !param.cardpoint){
@ -95,13 +95,12 @@ export class PetHandler {
this._exap += ap;
};
public addSkill(skillid: number, halocb?: any){
public addSkill(skillid: number){
if(skillid > 0){
let obj = this._skills.get(skillid);
if(!obj){
obj = SkillMan.getSkill(skillid);
obj = this._owner.newSkill(skillid);
if(obj){
obj.setOwner(this._owner);
this._skills.set(skillid, obj);
this._selfskills.push(skillid);
if(obj.isBornSkill()){
@ -110,7 +109,6 @@ export class PetHandler {
this._dieSkills.push(obj);
}else if(obj.isHaloSkill()){
this._halos.push(obj);
halocb && halocb(this);
}else{
this._waitskills.push(obj);
}
@ -149,6 +147,10 @@ export class PetHandler {
}
};
public useSkill(skillid: number, count: number, obj: SkillParam): SkillTarget[]{
return this._owner.handleSkill(skillid, count, obj, this);
};
public addAP(value: number){
this._exap += value;
if(this._exap < 0){
@ -197,8 +199,10 @@ export class PetHandler {
};
public clear(){
this._halos.length = 0;
this._owner.onHaloChanged(this);
if(this._halos.length > 0){
this._halos.length = 0;
this._owner.onHaloChanged(this);
}
this._waitskills.length = 0;
};
@ -210,6 +214,10 @@ export class PetHandler {
this._istaunt = false;
};
public summonPet(petid: number, count: number = 1, exparam: SkillParam):number{
return this._owner.summonPet(petid, count, exparam);
};
public hasHalo(): boolean{
return this._halos.length > 0;
};

View File

@ -37,10 +37,15 @@ export class PlayerHandler {
this._self._isHero = true;
let lst = this._playercfg.ex_skill? [this._playercfg.ex_skill]: null;
let ps = new SkillParam(0, 0, 0, this, this._self, null, null);
this._self.setParam(this._playercfg.herounit_id, ps, lst);
this._self.loadData(this._playercfg.herounit_id, ps, lst);
this._unitcfg = this._playercfg && CfgMan.findUnitCfg(this._playercfg.herounit_id);
};
public clear(){
this._self = null;
this._pets.length = 0;
};
public getCurrCardCount(){
return this._player.cards.size;
};
@ -125,7 +130,7 @@ export class PlayerHandler {
return false;
}
obj.srcpet = pet;
pet.setParam(cfg.stageunit_id, obj,
pet.loadData(cfg.stageunit_id, obj,
[cfg.quoteskill1id, cfg.quoteskill2id, cfg.quoteskill3id, cfg.quoteskill4id]);
}else if(cfg.type_id == EffectCardType.MAGIC){
this.useSkills([cfg.quoteskill1id, cfg.quoteskill2id, cfg.quoteskill3id, cfg.quoteskill4id], obj);
@ -144,27 +149,7 @@ export class PlayerHandler {
};
public useSkill(skillid: number, count: number, obj: SkillParam): SkillTarget[]{
let cfg = CfgMan.findSkillCfg(skillid);
let lst:SkillTarget[] = [];
if(cfg.skill_typeid == SkillType.MAGIC){
for(let i = 0; i < count; i++){
let sk = this.newSkill(skillid);
sk.checkTrigger(TriggerType.NO_COND, 0, obj,
(sk: Skill, sp: SkillParam, res: SkillTarget[])=>{
if(res){
lst.concat(res);
}else{
lst.push()
}
});
//todo: build json -> client
}
}else {
for(let i = 0; i < count; i++){
this._self.addSkill(skillid, this.onHaloChanged);
}
}
return lst;
return this.handleSkill(skillid, count, obj, this._self);
};
public newSkill(skillid: number): Skill{
@ -175,7 +160,37 @@ export class PlayerHandler {
return obj;
};
summonPet(petid: number, count: number = 1, exparam: SkillParam):number{
public handleSkill(skillid: number, count: number, param: SkillParam, pet: PetHandler):SkillTarget[]{
let cfg = CfgMan.findSkillCfg(skillid);
let lst: Skill[] = [];
if(cfg.skill_typeid == SkillType.MAGIC){
for(let i = 0; i < count; i++){
let sk = this.newSkill(skillid);
lst.push(sk);
}
// this._owner.onSkillResultNotify(lst);
}else {
let bhalo = 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(bhalo){
this.onHaloChanged(pet);
}
}
return this.simpleCheckSkills(lst, pet, param);
};
public summonPet(petid: number, count: number = 1, exparam: SkillParam):number{
let n = -1;
for(let i = 0; i < count; i++){
let pet = this.newPet();
@ -183,17 +198,17 @@ export class PlayerHandler {
break;
}
n++;
pet.setParam(petid, exparam);
pet.loadData(petid, exparam);
}
return n;
};
public addCard(count: number){
return this._owner.onPlayerAddCardNotify(this, count, 0);
public addCard(count: number, from?: PlayerHandler){
return this._owner.onPlayerAddCardNotify(this, count, 0, from);
};
public addCardLimit(maxcount: number){
return this._owner.onPlayerAddCardNotify(this, 0, maxcount);
public addCardLimit(maxcount: number, from?: PlayerHandler){
return this._owner.onPlayerAddCardNotify(this, 0, maxcount, from);
};
public stealCard(dstplayer: PlayerHandler, count: number){
@ -209,6 +224,7 @@ export class PlayerHandler {
};
public checkHalo(apet:PetHandler){
this._self.clearEffHalos();
this._pets.forEach((obj:PetHandler)=>{
obj.clearEffHalos();
});
@ -218,6 +234,10 @@ export class PlayerHandler {
}
apet.checkHalo(obj);
});
if(this._self != apet){
this._self.checkHalo(apet);
apet.checkHalo(this._self);
}
};
public setFriend(aplayer: PlayerHandler){
@ -225,53 +245,26 @@ export class PlayerHandler {
};
public die(){
this.clear();
//todo:
};
public isDead(){
this._player.state == 2;
public isAlive(): boolean{
return this._player.state != 2;
};
public onPetBorned(apet: PetHandler, param: SkillParam){
this._owner.onAddPetNotify(apet);
// 战吼
let reslst: SkillTarget[] = [];
apet._bornSkills.forEach((item: Skill)=>{
item.checkTrigger(TriggerType.NO_COND, 0, param, (skill: Skill, ap: SkillParam, res: SkillTarget[])=>{
if(res){
reslst = reslst.concat(res);
}else{
let st = new SkillTarget(skill);
st.LoadParam(param);
reslst.push(st);
}
});
});
this._owner.onSkillResultNotify(reslst);
this.simpleCheckSkills(apet._bornSkills, apet, param);
};
public onPetDied(apet: PetHandler){
this._owner.onDelPetNotify(apet);
// 遗愿
let ps = new SkillParam(0, 0, 0, this, apet, null, null);
let reslst: SkillTarget[] = [];
apet._dieSkills.forEach((item: Skill)=>{
item.checkTrigger(TriggerType.NO_COND, 0, ps, (skill: Skill, ap: SkillParam, res: SkillTarget[])=>{
if(res){
reslst = reslst.concat(res);
}else{
let st = new SkillTarget(skill);
st.LoadParam(ps);
reslst.push(st);
}
});
});
this._owner.onSkillResultNotify(reslst);
this.simpleCheckSkills(apet._dieSkills, apet);
};
public onHaloChanged(apet: PetHandler){
@ -279,10 +272,16 @@ export class PlayerHandler {
};
public isMyPet(apet: PetHandler){
if(apet == this._self){
return true;
}
return this._pets.includes(apet);
};
public findTauntPet(): PetHandler{
if(this._self && this._self._istaunt){
return this._self;
}
return this._pets.find((item: PetHandler) =>{
return item._istaunt;
})
@ -363,6 +362,26 @@ export class PlayerHandler {
this._owner.onSkillResultNotify(reslst);
};
simpleCheckSkills(skills: Skill[], apet?: PetHandler, param?: SkillParam): SkillTarget[]{
let ps = param? param: new SkillParam(0, 0, 0, this, apet, null, null);
let reslst: SkillTarget[] = [];
skills.forEach((item: Skill)=>{
item.checkTrigger(TriggerType.NO_COND, 0, ps, (skill: Skill, ap: SkillParam, res: SkillTarget[])=>{
if(res){
reslst = reslst.concat(res);
}else{
let st = new SkillTarget(skill);
st.LoadParam(ps);
reslst.push(st);
}
});
});
this._owner.onSkillResultNotify(reslst);
return reslst;
};
resetTotalCard(){
this._totalcc = 0;
}

View File

@ -208,7 +208,7 @@ export class Skill {
switch(efftype){
case SkillEffectType.CARD_ADD:
if(tgt.dsttype == GameUnitType.PLAYER){
let n = tgt.dst.addCard(res);
let n = tgt.dst.addCard(res, tgt.srcplayer);
if(n >= 0){
tgt.success(efftype, n);
}
@ -218,7 +218,7 @@ export class Skill {
break;
case SkillEffectType.CARD_ADD_LIMIT:
if(tgt.dsttype == GameUnitType.PLAYER){
let n = tgt.dst.addCardLimit(res);
let n = tgt.dst.addCardLimit(res, tgt.srcplayer);
if(n >= 0){
tgt.success(efftype, n);
}
@ -282,13 +282,13 @@ export class Skill {
let ncount = 1 + exparam.edd_cnt;
switch(efftype){
case SkillEffectType.SUMMON_NPC:
let n = tgt.srcplayer.summonPet(this._data.quoteunitid, ncount, exparam);
let n = tgt.dst.summonPet(this._data.quoteunitid, ncount, exparam);
if(n >= 0){
tgt.success(efftype, n);
}
break;
case SkillEffectType.SUMMON_SKILL:
let res = tgt.srcplayer.useSkill(this._data.quoteskillid, ncount, exparam);
let res = tgt.dst.useSkill(this._data.quoteskillid, ncount, exparam);
if(res){
tgt.success(efftype, res.length);
}