Merge branch 'master' of git.kingsome.cn:node/card_svr

This commit is contained in:
zhl 2020-12-07 13:05:58 +08:00
commit 2c3afe6e28
8 changed files with 252 additions and 73 deletions

3
package-lock.json generated
View File

@ -224,7 +224,8 @@
"@types/debug": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
"integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ=="
"integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==",
"dev": true
},
"@types/express": {
"version": "4.17.9",

View File

@ -49,9 +49,11 @@ export class SkillInfoMsg implements IMsg {
data?: any;
errcode: number;
errmsg: string;
type: string = '';
constructor(data?: SkillInfoData) {
this.errcode = 0;
this.data = data;
this.type = 'cast_skill_s2c';
}
}

View File

@ -9,6 +9,7 @@ import {SkillParam, SkillTarget} from "../skill/SkillParam";
import { Room } from "colyseus";
import { Skill } from "../skill/Skill";
import { PetHandler } from "./PetHandler";
import { SkillInfoMsg } from "message/SkillInfo";
export class BattleHandler {
@ -77,7 +78,7 @@ export class BattleHandler {
switch(skill._data.targetid){
case GameUnitType.PLAYER:
players.forEach((item:PlayerHandler)=>{
lst.push(new SkillTarget(param.srcplayer, param.srcpet, skill, item, GameUnitType.PLAYER));
lst.push(new SkillTarget(skill, param.srcplayer, param.srcpet, item, GameUnitType.PLAYER));
});
break;
case GameUnitType.BATTLEUNIT:
@ -85,7 +86,7 @@ export class BattleHandler {
case GameUnitType.PET:
if(skill.isSingleTarget()){
if(param.dstpet && this.petIsValid(param.dstpet, players, skill._data.targetid)){
lst.push(new SkillTarget(param.srcplayer, param.srcpet, skill,
lst.push(new SkillTarget(skill, param.srcplayer, param.srcpet,
param.dstpet, param.dstpet._isHero? GameUnitType.HERO: GameUnitType.PET));
}
}else{
@ -184,9 +185,11 @@ export class BattleHandler {
pt *= obj.dbpt_cnt;
}
let ps = new SkillParam(obj.card, pt, obj.eff_cnt, ph, dstph, dstpt);
let ps = new SkillParam(obj.card, pt, obj.eff_cnt, ph, null, dstph, dstpt);
ph.useCard(ps);
this.onUseCardEnd(obj);
};
/**
@ -231,7 +234,7 @@ export class BattleHandler {
* @param obj 使
*/
public onUseCardEnd(obj:
{srcplayer: Player, card: Card, cardpoint: number, eff_cnt: number, dstplayer: Player, dstpet: Pet}
{srcplayer: Player, card: number, cardpoint: number, dbpt_cnt: number, eff_cnt: number, dstplayer: Player, dstpet: Pet}
){
};
@ -287,4 +290,13 @@ export class BattleHandler {
public onPlayerStealCard(srcplayer: PlayerHandler, dstplayer: PlayerHandler, count: number){
return this._room.drawCardFromPlayer(srcplayer.getId(), dstplayer.getId(), count);
};
public onSkillResult(skillres: SkillTarget[]){
//todo: build skillrest json -> client
let lst: SkillInfoMsg[] = [];
skillres.forEach((item: SkillTarget)=>{
lst.push(item.exportData());
});
this._room.bMsgQueue(lst);
}
}

View File

@ -8,6 +8,7 @@ import SkillMan from "../skill/SkillMan";
import { EnhanceEffectType, PowerValueType } from "../skill/SkillConst";
import { PlayerHandler } from "./PlayerHandler";
import { PetInfoMsg } from "../../../message/PetInfo";
import { SkillParam } from "../skill/SkillParam";
export class PetHandler {
_pet: Pet;
@ -20,7 +21,7 @@ export class PetHandler {
_dieSkills: Skill[] = [];
_halos: Skill[] = [];
_otherhalos: Skill[] = [];
_effhalos: Skill[] = [];
_baseap: number; // 基础
@ -42,22 +43,20 @@ export class PetHandler {
this._idx = index;
};
public setParam(obj:{
id: number, ap?: number, effcnt?: number, exskillid: number[]}
){
this._id = obj.id || 0;
public setParam(id: number, param?: SkillParam, exskillid?: number[]){
this._id = id || 0;
this._cfg = CfgMan.findUnitCfg(this._id);
if(!obj.ap){
if(!param || !param.cardpoint){
this._baseap = this._cfg.powernum;
}else{
this._baseap = obj.ap;
this._baseap = param.cardpoint;
if(this._cfg.powernum_typeid == PowerValueType.RATIO){
this._baseap *= this._cfg.powernum;
}
}
if(obj.effcnt && this._isEnhancePower(this._cfg.edd_effid)){
if(param && param.edd_cnt && this._isEnhancePower(this._cfg.edd_effid)){
this._baseap += CfgMan.calcEnhanceValue(this._cfg.edd_effid, this._cfg.edd_effnum,
obj.effcnt, obj.ap);
param.edd_cnt, this._baseap);
}
this._skills.clear();
@ -65,9 +64,15 @@ export class PetHandler {
this.addSkill(this._cfg.base_skill2id);
this.addSkill(this._cfg.base_skill3id);
obj.exskillid && obj.exskillid.forEach((skillid: number)=>{
exskillid && exskillid.forEach((skillid: number)=>{
this.addSkill(skillid);
});
if(this._halos.length > 0){
this._owner.onHaloChanged(this);
}
this.born(param);
};
private _isEnhancePower(enid: number){
@ -78,7 +83,16 @@ export class PetHandler {
this._halos.push(halo);
};
public addSkill(skillid: number){
public clearEffHalos(){
// this._effhalos.length = 0;
this._exap = 0;
};
public addEffHalo(skill: Skill, ap: number){
this._exap += ap;
};
public addSkill(skillid: number, halocb?: any){
if(skillid > 0){
let obj = this._skills.get(skillid);
if(!obj){
@ -93,17 +107,18 @@ export class PetHandler {
this._dieSkills.push(obj);
}else if(obj.isHaloSkill()){
this._halos.push(obj);
halocb && halocb(this);
}
}
return true;
return obj;
}
}
return false;
return null;
};
public delSkill(skillid:number){
public delSkill(skillid:number, halocb?: any){
if(skillid > 0){
let obj = this._skills.get(skillid);
if(obj){
@ -118,6 +133,7 @@ export class PetHandler {
idx = this._halos.indexOf(obj);
if(idx >= 0){
this._halos.splice(idx, 1);
halocb && halocb(this);
}
}
this._skills.delete(skillid);
@ -162,25 +178,29 @@ export class PetHandler {
return value;
};
public born(param: any){
public born(param: SkillParam){
this._owner && this._owner.onPetBorned(this, param);
};
public die(){
this._dieSkills.forEach((item: Skill)=>{
});
this.clear();
this._owner && this._owner.onPetDied(this);
};
public useSkill(skillid: number){
public clear(){
this._halos.length = 0;
this._owner.onHaloChanged(this);
};
public hasHalo(): boolean{
return this._halos.length > 0;
};
public checkHalo(apet: PetHandler){
this._halos.forEach((item: Skill)=>{
if(item.isEffSelfPet(this, apet)){
this.addEffHalo(item, item.getEffValue()); // 暂时都加战力
}
});
};

View File

@ -4,7 +4,7 @@ import { HeroCfg } from "../../../cfg/parsers/HeroCfg";
import { BattleHandler } from "./BattleHandler";
import CfgMan from "../CfgMan";
import { Pet } from "rooms/schema/Pet";
import { EffectCardType, GameUnitType, TriggerType } from "../skill/SkillConst";
import { EffectCardType, GameUnitType, SkillType, TriggerType } from "../skill/SkillConst";
import { UnitCfg } from "cfg/parsers/UnitCfg";
import { Skill } from "../skill/Skill";
import { SkillParam, SkillTarget } from "../skill/SkillParam";
@ -37,7 +37,8 @@ export class PlayerHandler {
this._self.init(null, this, 0);
this._self._isHero = true;
let lst = this._playercfg.ex_skill? [this._playercfg.ex_skill]: null;
this._self.setParam({id: this._playercfg.herounit_id, exskillid: lst});
let ps = new SkillParam(0, 0, 0, this, this._self, null, null);
this._self.setParam(this._playercfg.herounit_id, ps, lst);
this._unitcfg = this._playercfg && CfgMan.findUnitCfg(this._playercfg.herounit_id);
};
@ -91,18 +92,18 @@ export class PlayerHandler {
let lst = this._pets.reverse();
lst.forEach(element => {
if(expet != element){
dst.push(new SkillTarget(param.srcplayer, param.srcpet, param.skill, element, GameUnitType.PET));
dst.push(new SkillTarget(param.skill, param.srcplayer, param.srcpet, element, GameUnitType.PET));
}
});
(expet != this._self) && dst.push(new SkillTarget(param.srcplayer, param.srcpet, param.skill, this._self, GameUnitType.PET));
(expet != this._self) && dst.push(new SkillTarget(param.skill, param.srcplayer, param.srcpet, this._self, GameUnitType.PET));
break;
case GameUnitType.HERO:
(expet != this._self) && dst.push(new SkillTarget(param.srcplayer, param.srcpet, param.skill, this._self, GameUnitType.PET));
(expet != this._self) && dst.push(new SkillTarget(param.skill, param.srcplayer, param.srcpet, this._self, GameUnitType.PET));
break;
case GameUnitType.PET:
lst.forEach(element => {
if(expet != element){
dst.push(new SkillTarget(param.srcplayer, param.srcpet, param.skill, element, GameUnitType.PET));
dst.push(new SkillTarget(param.skill, param.srcplayer, param.srcpet, element, GameUnitType.PET));
}
});
break;
@ -124,29 +125,47 @@ export class PlayerHandler {
if(!pet){
return false;
}
pet.setParam({id: cfg.stageunit_id, ap:obj.cardpoint, effcnt: obj.edd_cnt, exskillid:
[cfg.quoteskill1id, cfg.quoteskill2id, cfg.quoteskill3id, cfg.quoteskill4id]});
obj.srcpet = pet;
pet.born(obj);
pet.setParam(cfg.stageunit_id, obj,
[cfg.quoteskill1id, cfg.quoteskill2id, cfg.quoteskill3id, cfg.quoteskill4id]);
}else if(cfg.type_id == EffectCardType.MAGIC){
this.useSkill([cfg.quoteskill1id, cfg.quoteskill2id, cfg.quoteskill3id, cfg.quoteskill4id], obj);
this.useSkills([cfg.quoteskill1id, cfg.quoteskill2id, cfg.quoteskill3id, cfg.quoteskill4id], obj);
}
};
public useSkill(skills: number[], obj: SkillParam)
public useSkills(skills: number[], obj: SkillParam)
{
if(!skills){
return;
}
let res : SkillTarget[] = [];
skills.forEach((item: number)=>{
let sk = this.newSkill(item);
let lst = sk.checkTrigger(TriggerType.NO_COND, 0, obj);
res = res.concat(lst);
this.useSkill(item, 1, obj);
});
};
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;
};
public newSkill(skillid: number): Skill{
@ -157,6 +176,19 @@ export class PlayerHandler {
return obj;
};
summonPet(petid: number, count: number = 1, exparam: SkillParam):number{
let n = -1;
for(let i = 0; i < count; i++){
let pet = this.newPet();
if(!pet){
break;
}
n++;
pet.setParam(petid, exparam);
}
return n;
};
public addCard(count: number){
return this._owner.onPlayerAddCard(this, count, 0);
};
@ -182,6 +214,9 @@ export class PlayerHandler {
};
public checkHalo(apet:PetHandler){
this._pets.forEach((obj:PetHandler)=>{
obj.clearEffHalos();
});
this._pets.forEach((obj: PetHandler)=>{
if(obj != apet){
obj.checkHalo(apet);
@ -199,30 +234,48 @@ export class PlayerHandler {
};
public onPetBorned(apet: PetHandler, param: SkillParam){
//todo: build pet init json -> client
this._owner.onAddPetNotify(apet);
// 战吼
let reslst: SkillTarget[] = [];
apet._bornSkills.forEach((item: Skill)=>{
let lst = item.checkTrigger(TriggerType.NO_COND, 0, param);
reslst = reslst.concat(lst);
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);
}
});
});
//todo: build bornskill json -> client
// 光环
this.checkHalo(apet);
//todo: build haloskill json -> client
this._owner.onSkillResult(reslst);
};
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.onSkillResult(reslst);
};
public onSkillEnd(askill: Skill, res: SkillTarget[]){
public onHaloChanged(apet: PetHandler){
this.checkHalo(apet);
};
public isMyPet(apet: PetHandler){

View File

@ -114,6 +114,41 @@ export class Skill {
return this._data.rangeid == SkillRangeUnitType.ALL;
};
isInRange(srcpet: PetHandler, dstpet: PetHandler){
switch(this._data.rangeid){
case SkillRangeUnitType.SELF:
return srcpet == dstpet;
case SkillRangeUnitType.SINGLE:
return false;
case SkillRangeUnitType.OTHER:
return false;
case SkillRangeUnitType.ALL:
return true;
case SkillRangeUnitType.ALL_EXSELF:
return srcpet != dstpet;
default:
return false;
}
};
isEffSelfPet(srcpet: PetHandler, dstpet: PetHandler){
if(this._data.friendlyid != GameCampType.SELF){
return false;
}
let tgok = false;
switch(this._data.targetid){
case GameUnitType.BATTLEUNIT:
tgok = this.isInRange(srcpet, dstpet);
case GameUnitType.HERO:
tgok = dstpet._isHero;
case GameUnitType.PET:
if(!dstpet._isHero){
tgok = this.isInRange(srcpet, dstpet);
}
}
return tgok;
};
getTargets(param: SkillParam): SkillTarget[]{
return this._owner._owner.getSkillTargets(this, param);
};
@ -122,12 +157,12 @@ export class Skill {
return CfgMan.calcEnhanceValue(this._data.edd_effid, this._data.edd_effnum, param.edd_cnt, param.cardpoint);
};
getEffValue(param: SkillParam): number{
getEffValue(ap?: number): number{
return CfgMan.calcEffectValue(this._data.eff_numtypeid,
this._data.num_signid, this._data.eff_num, param.cardpoint);
this._data.num_signid, this._data.eff_num, ap? ap: this._data.eff_num);
};
trigger(param: SkillParam) {
trigger(param: SkillParam, cb?: any) {
//触发buff效果
let res = TriggerManager.onTrigger(this, param);
@ -137,6 +172,8 @@ export class Skill {
this._start = true;
}
cb && cb(this, param, res);
this._cb && this._cb(this, param, res);
this._man && this._man.onSkillTrigger(this, param, res);
@ -151,11 +188,11 @@ export class Skill {
this._startround++;
}
}
cb && (this._cb = cb);
if(this._tgctrl.checkTrigger(tg_type, tg_value, this._owner)){
return this.trigger(tg_target);
this.trigger(tg_target, cb);
return 1;
}else{
return null;
return 0;
}
};
@ -235,8 +272,24 @@ export class Skill {
}
};
summon(efftype: SkillEffectType, effvalue: number, tgt: SkillTarget){
summon(efftype: SkillEffectType, exparam: SkillParam, tgt: SkillTarget){
let ncount = 1 + exparam.edd_cnt;
switch(efftype){
case SkillEffectType.SUMMON_NPC:
let n = tgt.srcplayer.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);
if(res){
tgt.success(efftype, res.length);
}
break;
default:
break;
}
};
addBuff(efftype: SkillEffectType, effvalue: number, tgt: SkillTarget){

View File

@ -2,6 +2,7 @@ import {PlayerHandler} from "../Handler/PlayerHandler";
import {PetHandler} from "../Handler/PetHandler";
import { Skill } from "./Skill";
import { GameUnitType } from "./SkillConst";
import { SKillEffectData, SkillInfoData, SkillInfoMsg } from "message/SkillInfo";
export class SkillParam{
cardid: number;
@ -11,15 +12,17 @@ export class SkillParam{
dstplayer: PlayerHandler;
dstpet: PetHandler;
srcpet: PetHandler = null;
srcpet: PetHandler;
skill: Skill;
constructor(cardid: number, cardpoint: number, effcnt: number, srcplayer: PlayerHandler, dstplayer: PlayerHandler, dstpet: PetHandler){
constructor(cardid: number, cardpoint: number, effcnt: number, srcplayer: PlayerHandler, srcpet: PetHandler,
dstplayer: PlayerHandler, dstpet: PetHandler){
this.cardid = cardid;
this.cardpoint = cardpoint;
this.edd_cnt = effcnt;
this.srcplayer = srcplayer;
this.srcpet = srcpet;
this.dstplayer = dstplayer;
this.dstpet = dstpet;
};
@ -29,11 +32,13 @@ export class SkillResult{
effect_type: number;
effect_res: number;
err: number;
bsuccess: boolean;
constructor(efftype: number, effres: number, err: number = 0) {
constructor(efftype: number, effres: number, issuccess: boolean, err: number = 0) {
this.effect_type = efftype;
this.effect_res = effres;
this.err = err;
this.bsuccess = issuccess;
}
};
@ -46,12 +51,24 @@ export class SkillTarget{
res: SkillResult[];
constructor(splayer: PlayerHandler, spet: PetHandler, skill: Skill, ds: any, dstp: GameUnitType) {
constructor(skill: Skill, splayer?: PlayerHandler, spet?: PetHandler, dstobj?: any, dsttype?: GameUnitType) {
this.srcplayer = splayer;
this.srcpet = spet;
this.srcskill = skill;
this.dst = ds;
this.dsttype = dstp;
this.dst = dstobj;
this.dsttype = dsttype;
};
public LoadParam(sp: SkillParam){
this.srcplayer = sp.srcplayer;
this.srcpet = sp.srcpet;
if(sp.dstpet){
this.dsttype = sp.dstpet._isHero? GameUnitType.HERO: GameUnitType.PET;
this.dst = sp.dstpet;
}else if(sp.dstplayer){
this.dsttype = GameUnitType.PLAYER;
this.dst = sp.dstplayer;
}
};
public checkRes(){
@ -62,11 +79,32 @@ export class SkillTarget{
public success(efftype: number, effres: number){
this.checkRes();
this.res.push(new SkillResult(efftype, effres));
this.res.push(new SkillResult(efftype, effres, true));
};
public fail(efftype: number, err: number){
this.checkRes();
this.res.push(new SkillResult(efftype, 0, err));
this.res.push(new SkillResult(efftype, 0, false, err));
};
public exportData(): SkillInfoMsg{
let msg = new SkillInfoMsg();
msg.data = new SkillInfoData();
let obj = msg.data;
obj.player = this.srcplayer.getId(),
obj.pos = this.srcpet? this.srcpet._idx: 0;
obj.datas = [];
if(!this.res){
msg.errcode = -1;
}else{
this.res.forEach((item: SkillResult) => {
let ed = new SKillEffectData();
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);
});
}
return msg;
}
};

View File

@ -75,7 +75,7 @@ let TriggerManager = {
onTrigger(sender: Skill, param: SkillParam): SkillTarget[] {
let effectid = sender._type;
let env = sender.getEnhanceValue(param);
let effv = sender.getEffValue(param);
let effv = sender.getEffValue(param.cardpoint);
let tgts = sender.getTargets(param);
if(!tgts || !tgts.length){
return null;
@ -103,7 +103,7 @@ let TriggerManager = {
case SkillEffectType.SUMMON_NPC:
case SkillEffectType.SUMMON_SKILL:
tgts.forEach((item)=>{
sender.summon(effectid, effv + env, item);
sender.summon(effectid, param, item);
});
break;
case SkillEffectType.TAUNT: