战斗清理

This commit is contained in:
ciniao 2023-12-14 20:42:22 +08:00 committed by dy
parent 0b18e39dd7
commit afd0eb93de
7 changed files with 142 additions and 35 deletions

View File

@ -7,15 +7,42 @@ import {HeroShared} from '../shared/public/hero';
import {PlayerShared} from '../shared/public/player'; import {PlayerShared} from '../shared/public/player';
import {HeroFun} from './hero'; import {HeroFun} from './hero';
import {UserFun} from './user'; import {UserFun} from './user';
import {re} from "mathjs"; import {re, string} from "mathjs";
import {getGud} from './gud'; import {getGud} from './gud';
type fightType = 'tanxian' | 'pata' | 'jjc' | 'gbtx' | 'qjzzd' | 'meirishilian' | 'wzrycross'; type fightType = 'tanxian' | 'pata' | 'jjc' | 'gbtx' | 'qjzzd' | 'meirishilian' | 'wzrycross';
let fights:{[key:string]:FightControl} = {
};
function clearFights (){
//定时清理战斗
setInterval(()=>{
let now = Date.now();
for (let key in fights){
if (now - fights[key].startTime > 30000){
console.log("清理战斗",key);
try{
fights[key].release();
}catch(e){
console.error(e);
}
delete fights[key];
}
}
},5000);
}
clearFights();
export class FightFun { export class FightFun {
static fightIndex:number = 0;
static fight(data: joinFightData[], maxRoundNums = 30, fightType: "pvp" | "pve" = 'pvp') { static fight(data: joinFightData[], maxRoundNums = 30, fightType: "pvp" | "pve" = 'pvp') {
return new FightControl(data, maxRoundNums, fightType).getResult(); this.fightIndex++;
fights[this.fightIndex] = new FightControl(data, maxRoundNums, fightType);
return fights[this.fightIndex].getResult();
} }
/**获取玩家数据 */ /**获取玩家数据 */

View File

@ -5,6 +5,7 @@ import * as BuffClass from './fightBuff/buffExtends';
import { FightControl } from "./fightCntrol"; import { FightControl } from "./fightCntrol";
import { getSkillConf, randNumber, randomSkill } from "./fightFun"; import { getSkillConf, randNumber, randomSkill } from "./fightFun";
import { buffDataType, dpsinfoType, joinFightData, modifyHpType, roleDataType } from "./fightType"; import { buffDataType, dpsinfoType, joinFightData, modifyHpType, roleDataType } from "./fightType";
import { PassiveSkillBase } from "./passiveSkill/passiveSkillBase";
import { runPassiveSkillBase } from "./passiveSkill/runPassiveSkill"; import { runPassiveSkillBase } from "./passiveSkill/runPassiveSkill";
import { SkillBase } from "./skill/skillBase"; import { SkillBase } from "./skill/skillBase";
@ -24,6 +25,23 @@ export class Player {
get lockHp() { return false; } get lockHp() { return false; }
get rolePlayer() { return this } get rolePlayer() { return this }
release(){
for(let buffid in this.buffs){
this.buffs[buffid].release();
}
for(let passiveid in this.passiveSkills){
this.passiveSkills[passiveid].release();
}
this.curAtkSkill?.release();
this.curAtkSkill = null;
this.skillTargets = null;
this.lastSkillTargets = null;
this.lastSkillId = null;
this.lastHitMe = null;
this.buffs = null;
this.passiveSkills = null;
}
skillIdx = 0; skillIdx = 0;
skillLv = 1; skillLv = 1;
hudunzhi = 0; hudunzhi = 0;

View File

@ -20,6 +20,7 @@ import {
import {runPassiveSkillBase} from "./passiveSkill/runPassiveSkill"; import {runPassiveSkillBase} from "./passiveSkill/runPassiveSkill";
import {SkillBase} from "./skill/skillBase"; import {SkillBase} from "./skill/skillBase";
import { PublicShared } from "../public/public"; import { PublicShared } from "../public/public";
import { PassiveSkillBase } from "./passiveSkill/passiveSkillBase";
export class Role { export class Role {
rid: string; rid: string;
@ -37,6 +38,23 @@ export class Role {
hudunzhi = 0; hudunzhi = 0;
addpkNum = 0; addpkNum = 0;
release(){
for(let buffid in this.buffs){
this.buffs[buffid].release();
}
for(let passiveid in this.passiveSkills){
this.passiveSkills[passiveid].release();
}
this.curAtkSkill?.release();
this.curAtkSkill = null;
this.skillTargets = null;
this.lastSkillTargets = null;
this.lastSkillId = null;
this._lastHitMe = null;
this.buffs = null;
this.passiveSkills = null;
}
get skillId() { get skillId() {
let heroId = this.roleData.heroId; let heroId = this.roleData.heroId;
let jieji = this.roleData.jieji || 0; let jieji = this.roleData.jieji || 0;
@ -102,6 +120,8 @@ export class Role {
// fromRole行动的角色 // fromRole行动的角色
// skillConf 使用的技能 // skillConf 使用的技能
// toRole 目标 // toRole 目标
//上一个指针release
this.curAtkSkill?.release();
this.curAtkSkill = this.runSkillClass(); this.curAtkSkill = this.runSkillClass();
this.bloodReturn(); this.bloodReturn();
this.debug(() => { this.debug(() => {

View File

@ -17,6 +17,13 @@ export class BuffBase {
this._BuffId = 'BuffId_' + idx; this._BuffId = 'BuffId_' + idx;
this.startRound = this.role.fightControl.roundNums; this.startRound = this.role.fightControl.roundNums;
} }
release(){
this.clear('release');
this.altAttr = null;
this.role = null;
}
start() { start() {
let skillConf = this.data.skillConf; let skillConf = this.data.skillConf;
this.remainingRounds = skillConf.round; this.remainingRounds = skillConf.round;
@ -119,17 +126,19 @@ export class BuffBase {
buffType = Object.keys(this.data.skillConf.xiaoguocanshu).join(','); buffType = Object.keys(this.data.skillConf.xiaoguocanshu).join(',');
} }
// 字符串以逗号分隔转换为数组 // 字符串以逗号分隔转换为数组
let buffTypeArr = buffType.split(',') if(when != "release"){
buffTypeArr.forEach(buffTypeStr => { let buffTypeArr = buffType.split(',')
this.role.fightControl.record({ buffTypeArr.forEach(buffTypeStr => {
act: 'delBuff', this.role.fightControl.record({
fromRole: this.role.rid, act: 'delBuff',
skillId: this.data.buffid, fromRole: this.role.rid,
buffType: buffTypeStr, skillId: this.data.buffid,
buffId: this._BuffId, buffType: buffTypeStr,
why: when buffId: this._BuffId,
}); why: when
}) });
})
}
this.willClear(); this.willClear();
// this.role.fightControl.event.emit('fight_buffClear', this.data); // this.role.fightControl.event.emit('fight_buffClear', this.data);
let buffid = this.data.buffid; let buffid = this.data.buffid;

View File

@ -6,9 +6,10 @@ import { Player } from "./Player";
import { Role } from "./Role"; import { Role } from "./Role";
export class FightControl { export class FightControl {
//所有战斗成员 startTime: number = Date.now();
//所有战斗成员,包含双方的所有“伙伴”
fightRoles: k_v<Role> = {}; fightRoles: k_v<Role> = {};
//所有战斗对象,包含了双方的“伙伴”和“主角”
fightRolesArr: FightObj[] = []; fightRolesArr: FightObj[] = [];
fightOver = false; fightOver = false;
roundNums = 0; roundNums = 0;
@ -18,6 +19,7 @@ export class FightControl {
initial: joinFightData[]; initial: joinFightData[];
winSide: number; winSide: number;
totalDamage = { "0": 0, "1": 0 }; totalDamage = { "0": 0, "1": 0 };
//战斗统计
fightStatistics: { [k: string]: { [k: string]: number; }; } = {}; fightStatistics: { [k: string]: { [k: string]: number; }; } = {};
player_0: FightObj = null; player_0: FightObj = null;
player_1: FightObj = null; player_1: FightObj = null;
@ -29,6 +31,26 @@ export class FightControl {
this.startTurnRound(); this.startTurnRound();
} }
/**
*
*/
release(){
this.fightRolesArr.map( obj =>{
obj?.release();
});
this.fightRoles = null;
this.fightRolesArr = null;
this.recordData = null;
this.event.removeAllListeners();
this.event = null;
this.initial = null;
this.fightStatistics = null;
this.player_0 = null;
this.player_1 = null;
this.recordSkillDps = null;
this.DATA = null;
}
initControl() { initControl() {
// this.event.setMaxListeners(1000); // this.event.setMaxListeners(1000);
} }

View File

@ -103,6 +103,11 @@ export class PassiveSkillBase {
this._passiveId = 'passiveSkill_' + idx; this._passiveId = 'passiveSkill_' + idx;
this.skillConf = this.skillInfo.skillConf; this.skillConf = this.skillInfo.skillConf;
} }
release(){
this.clear('release');
this.skillConf = null;
this._timers = null;
}
start() { start() {
this._initEvent(); this._initEvent();
@ -112,10 +117,10 @@ export class PassiveSkillBase {
_initEvent() { _initEvent() {
let _when = this.skillConf.chkdata.when; let _when = this.skillConf.chkdata.when;
let toRole = this.skillInfo.toRole; let toRole = this.skillInfo.toRole;
if (_when == 'ontime') { // if (_when == 'ontime') {
//定时触发 或者 频率触发 // //定时触发 或者 频率触发
this._whenOntime(); // this._whenOntime();
} else { // } else {
this._checkFunc = (emitData) => { this._checkFunc = (emitData) => {
toRole.debug(() => { toRole.debug(() => {
console.log('### passiveskill checkEmit', 'fightEvent_' + _when, this.skillConf.skillid); console.log('### passiveskill checkEmit', 'fightEvent_' + _when, this.skillConf.skillid);
@ -123,7 +128,7 @@ export class PassiveSkillBase {
this.checkEmit(emitData); this.checkEmit(emitData);
}; };
toRole.fightControl.event.on('fightEvent_' + _when, this._checkFunc.bind(this), this); toRole.fightControl.event.on('fightEvent_' + _when, this._checkFunc.bind(this), this);
} //}
} }
checkEmit(emitData: EmitDataType) { checkEmit(emitData: EmitDataType) {
@ -161,21 +166,22 @@ export class PassiveSkillBase {
this.remainingRounds--; this.remainingRounds--;
} }
_whenOntime() { //不能也不应该有这样的逻辑,这是个回合制游戏!
let time = this.skillConf.chkdata.time; // _whenOntime() {
if (!time) return; // let time = this.skillConf.chkdata.time;
this._timers.push(setTimeout(() => { // if (!time) return;
this.doAtk(); // this._timers.push(setTimeout(() => {
}, time)); // this.doAtk();
} // }, time));
// }
_doNextOntime() { // _doNextOntime() {
let pinlvtime = this.skillConf.chkdata.pinlvtime; // let pinlvtime = this.skillConf.chkdata.pinlvtime;
if (!pinlvtime) return; // if (!pinlvtime) return;
this._timers.push(setTimeout(() => { // this._timers.push(setTimeout(() => {
this.doAtk(); // this.doAtk();
}, pinlvtime)); // }, pinlvtime));
} // }
/** 清除执行次数限制的被动 */ /** 清除执行次数限制的被动 */
_clearOnceSkill() { _clearOnceSkill() {
@ -188,7 +194,7 @@ export class PassiveSkillBase {
doAtk(emitData?: EmitDataType) { doAtk(emitData?: EmitDataType) {
this._triggerCount++; this._triggerCount++;
this._clearOnceSkill(); this._clearOnceSkill();
this._doNextOntime(); //this._doNextOntime();
} }
clear(why: string) { clear(why: string) {

View File

@ -11,6 +11,11 @@ export class SkillBase {
this.checkAtk(); this.checkAtk();
} }
release(){
this.clear();
this.toRole = null;
}
onRoleClear(why?: string) { onRoleClear(why?: string) {
} }