xy-server/game/object/MagicWeaponMgr.ts
2025-04-23 09:34:08 +08:00

100 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import GameUtil from "../core/GameUtil";
import SKDataUtil from "../gear/SKDataUtil";
import SKLogger from "../gear/SKLogger";
import {MsgCode} from "../role/EEnum";
import DB from "../utils/DB";
export default class MagicWeaponMgr {
static shared = new MagicWeaponMgr();
dhamaData: any;
magicWeaponObjs: any;
uuidArr: any = [];
constructor() {
this.dhamaData = null;
this.uuidArr = [];
}
launch() {
this.dhamaData = GameUtil.require_ex('../../conf/prop_data/prop_magic_weapon');
let callback = (ret: any, item: any) => {
if (ret == MsgCode.SUCCESS) {
for (let key in item) {
this.uuidArr.push(item[key].EquipID)
}
}
callback = null;
}
DB.equipKey(callback);
this.magicWeaponObjs ={}
SKLogger.debug('法宝模块加载完毕!');
}
getMagicWeaponID() {
let flag = true;
let uuid = "";
let count = 0;
while (flag) {
uuid = SKDataUtil.uuid();
// 判断主键是否存在,不存在则返回
if (this.uuidArr.indexOf(uuid) == -1) {
flag = false;
this.uuidArr.push(uuid);
}
// 连续二十次重复自动根据随机数加字符生成主键
else if(count > 20){
flag = false;
uuid = SKDataUtil.encodeInvite(Math.random())
this.uuidArr.push(uuid);
SKLogger.info(`生成UUID失败本次生成主键${uuid}`);
}
}
return uuid;
}
addMagicWeapon(weapon: any) {
this.magicWeaponObjs[weapon.efId] = weapon;
}
delMagicWeapon(id: any) {
delete this.magicWeaponObjs[id];
}
// 获得法宝属性
getMagicWeaponAttr(magicWeapon: any): any {
let datum = this.dhamaData[magicWeapon.id];
let result: any = {};
result['baseAttr'] = '{}';
if (datum.baseAttr) {
let baseInfo: any = {};
let baseAttr = datum.baseAttr.split(';');
for (const item of baseAttr) {
let itemAttr = item.split(':');
if (itemAttr.length == 2 && GameUtil.attrEquipTypeStr[itemAttr[0]] != null) {
baseInfo[GameUtil.attrEquipTypeStr[itemAttr[0]]] = itemAttr[1];
}
}
result['baseAttr'] = SKDataUtil.toJson(baseInfo, "{}");
}
datum.baseAttr = result['baseAttr'];
datum.efId = this.getMagicWeaponID();
datum.level = 1;
datum.efExp = 0;
return datum;
}
// 添加法宝进数据库
getInsertData(weapon: any, roleid: any): any {
if (!weapon) {
return null;
}
let fieldstr = 'owner_id, ef_id, ef_name, base_attr, ef_type, level, ef_exp, ef_level, number, active_skillid, passive_skillid, ef_index, ef_state, nimbus, icon, ef_score, create_time';
let valuestr = `'${roleid}', '${weapon.efId}', '${weapon.efName}', '${weapon.baseAttr}', ${weapon.efType}, ${weapon.level}, '${weapon.efExp}', ${weapon.efLevel}, ${weapon.number}, ${weapon.activeSkillid}, ${weapon.passiveSkillid}, ${weapon.efIndex}, ${weapon.efState}, ${weapon.nimbus}, ${weapon.icon}, ${weapon.efScore}, NOW()`;
let data: any = {};
data.fieldstr = fieldstr;
data.valuestr = valuestr;
return data;
}
}