Compare commits

...

2 Commits

Author SHA1 Message Date
5dea65e51a Merge branch 'dev' of http://git.legu.cc/qixin/HJ_Server into dev 2023-12-14 20:43:33 +08:00
0304c78991 战斗清理 2023-12-14 20:42:22 +08:00
7 changed files with 142 additions and 35 deletions

View File

@ -7,16 +7,43 @@ import {HeroShared} from '../shared/public/hero';
import {PlayerShared} from '../shared/public/player';
import {HeroFun} from './hero';
import {UserFun} from './user';
import {re} from "mathjs";
import {re, string} from "mathjs";
import {getGud} from './gud';
import {PushGiftFun} from "./pushgift";
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 {
static fightIndex:number = 0;
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 { getSkillConf, randNumber, randomSkill } from "./fightFun";
import { buffDataType, dpsinfoType, joinFightData, modifyHpType, roleDataType } from "./fightType";
import { PassiveSkillBase } from "./passiveSkill/passiveSkillBase";
import { runPassiveSkillBase } from "./passiveSkill/runPassiveSkill";
import { SkillBase } from "./skill/skillBase";
@ -24,6 +25,23 @@ export class Player {
get lockHp() { return false; }
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;
skillLv = 1;
hudunzhi = 0;

View File

@ -20,6 +20,7 @@ import {
import {runPassiveSkillBase} from "./passiveSkill/runPassiveSkill";
import {SkillBase} from "./skill/skillBase";
import { PublicShared } from "../public/public";
import { PassiveSkillBase } from "./passiveSkill/passiveSkillBase";
export class Role {
rid: string;
@ -37,6 +38,23 @@ export class Role {
hudunzhi = 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() {
let heroId = this.roleData.heroId;
let jieji = this.roleData.jieji || 0;
@ -102,6 +120,8 @@ export class Role {
// fromRole行动的角色
// skillConf 使用的技能
// toRole 目标
//上一个指针release
this.curAtkSkill?.release();
this.curAtkSkill = this.runSkillClass();
this.bloodReturn();
this.debug(() => {

View File

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

View File

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

View File

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

View File

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