207 lines
6.2 KiB
TypeScript
207 lines
6.2 KiB
TypeScript
import SKDataUtil from "../gear/SKDataUtil";
|
||
import DB from "../utils/DB";
|
||
import GameUtil from "../core/GameUtil";
|
||
import {EEquipPos} from "../role/EEnum";
|
||
import Player from "./Player";
|
||
|
||
|
||
export default class MagicWeapon {
|
||
owner: Player;
|
||
// 法宝编号
|
||
efId: string;
|
||
// 法宝名称
|
||
efName: string;
|
||
// 法宝五行(1 金 2 木 3 水 4 火 5土 )
|
||
efType: number;
|
||
// 法宝等级(1:一阶、2:二阶、3阶)
|
||
efLevel: number;
|
||
// 法宝等级
|
||
level: number;
|
||
// 法宝经验
|
||
efExp: number;
|
||
// 法宝属性加成
|
||
baseAttr: any;
|
||
// 法宝编号
|
||
number: number;
|
||
// 主动技能
|
||
activeSkillid: any;
|
||
// 被动技能
|
||
passiveSkillid: any;
|
||
// 法宝穿戴位置
|
||
efIndex: number;
|
||
// 装备存放位置(1未知,2正在使用,3背包,4仓库)
|
||
efPos: any;
|
||
// 0 为已经删除
|
||
efState: any;
|
||
// 评分
|
||
efScore: any;
|
||
// 灵气
|
||
nimbus: number;
|
||
// 外观
|
||
icon: number;
|
||
|
||
attr1: any;
|
||
|
||
constructor(info: any, owner: Player) {
|
||
this.owner = owner;
|
||
this.efId = info.efId;
|
||
this.efExp = info.efExp;
|
||
this.efName = info.efName;
|
||
this.efType = info.efType;
|
||
this.efLevel = info.efLevel;
|
||
this.level = info.level;
|
||
this.number = info.number;
|
||
this.activeSkillid = info.activeSkillid;
|
||
this.passiveSkillid = info.passiveSkillid;
|
||
this.efIndex = info.efIndex;
|
||
this.efPos = EEquipPos.BAG;
|
||
this.efState = 1;
|
||
this.efScore = info.efScore;
|
||
this.nimbus = info.nimbus;
|
||
this.icon = info.icon;
|
||
this.baseAttr = info.baseAttr;
|
||
// 属性
|
||
this.attr1 = {};
|
||
GameUtil.clearAllAttr(this.attr1);
|
||
this.setDB(info);
|
||
}
|
||
|
||
setDB(info: any) {
|
||
if (info == null) {
|
||
return;
|
||
}
|
||
|
||
if (info.baseAttr) {
|
||
this.baseAttr = SKDataUtil.jsonBy(info.baseAttr);
|
||
}
|
||
|
||
info.efId && (this.efId = info.efId);
|
||
info.efName && (this.efName = info.efName);
|
||
info.efType && (this.efType = info.efType);
|
||
info.level && (this.level = info.level);
|
||
info.efExp && (this.efExp = info.efExp);
|
||
info.efLevel && (this.efLevel = info.efLevel);
|
||
info.number && (this.number = info.number);
|
||
info.activeSkillid && (this.activeSkillid = info.activeSkillid);
|
||
info.passiveSkillid && (this.passiveSkillid = info.passiveSkillid);
|
||
info.efIndex && (this.efIndex = info.efIndex);
|
||
info.efState && (this.efState = info.efState);
|
||
info.nimbus && (this.nimbus = info.nimbus);
|
||
info.icon && (this.icon = info.icon);
|
||
info.efPos && (this.efPos = info.efPos);
|
||
info.efScore && (this.efScore = info.efScore);
|
||
this.calculateAttribute();
|
||
}
|
||
|
||
getAttr(attrtype: number): number {
|
||
return this.attr1[attrtype];
|
||
}
|
||
|
||
// 计算法宝属性
|
||
calculateAttribute() {
|
||
GameUtil.clearAllAttr(this.attr1);
|
||
if (SKDataUtil.isArray(this.baseAttr)) {
|
||
for (let item of this.baseAttr) {
|
||
for (let key in item) {
|
||
let nkey = parseInt(key);
|
||
let value = parseInt(item[nkey]);
|
||
if (GameUtil.equipTypeNumerical.indexOf(nkey) == -1) {
|
||
value = value / 10;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
} else {
|
||
for (let key in this.baseAttr) {
|
||
if (this.baseAttr.hasOwnProperty(key)) {
|
||
let nkey = parseInt(key);
|
||
let value = parseInt(this.baseAttr[nkey]);
|
||
if (GameUtil.equipTypeNumerical.indexOf(nkey) == -1) {
|
||
value = value / 10;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
toObj() {
|
||
let baseAttr: any;
|
||
if (SKDataUtil.isArray(this.baseAttr)) {
|
||
baseAttr = this.baseAttr;
|
||
} else {
|
||
baseAttr = {};
|
||
for (let key in this.baseAttr) {
|
||
let value = this.attr1[key];
|
||
baseAttr[key] = value;
|
||
let nkey = parseInt(key);
|
||
if (GameUtil.equipTypeNumerical.indexOf(nkey) == -1) {
|
||
baseAttr[key] *= 10;
|
||
}
|
||
}
|
||
}
|
||
let obj: any = {};
|
||
obj.efId = this.efId;
|
||
obj.baseAttr = SKDataUtil.toJson(baseAttr, "{}");
|
||
obj.efName = this.efName;
|
||
obj.efType = this.efType;
|
||
obj.level = this.level;
|
||
obj.efExp = this.efExp;
|
||
obj.efLevel = this.efLevel;
|
||
obj.number = this.number;
|
||
obj.activeSkillid = this.activeSkillid;
|
||
obj.passiveSkillid = this.passiveSkillid;
|
||
obj.efIndex = this.efIndex;
|
||
obj.efState = this.efState;
|
||
obj.nimbus = this.nimbus;
|
||
obj.icon = this.icon;
|
||
obj.efPos = this.efPos;
|
||
obj.efScore = this.efScore;
|
||
return obj;
|
||
}
|
||
|
||
getSendInfo(): any {
|
||
let result = {
|
||
efId: this.efId,
|
||
icon: this.icon,
|
||
efName: this.efName,
|
||
efType: this.efType,
|
||
efExp: this.efExp,
|
||
level: this.level,
|
||
efIndex: this.efIndex,
|
||
efLevel: this.efLevel
|
||
};
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
save() {
|
||
if (this.efState == 0) {
|
||
DB.delEquip(this.efId, this.owner.roleid, (code: number) => {
|
||
});
|
||
} else {
|
||
let savedata: any = {};
|
||
savedata.ef_name = this.efName;
|
||
savedata.ef_type = this.efType;
|
||
savedata.base_attr = SKDataUtil.toJson(this.baseAttr, "{}");
|
||
savedata.ef_exp = this.efExp;
|
||
savedata.level = this.level;
|
||
savedata.ef_level = this.efLevel;
|
||
savedata.number = this.number;
|
||
savedata.active_skillid = this.activeSkillid;
|
||
savedata.passive_skillid = this.passiveSkillid;
|
||
savedata.ef_index = this.efIndex;
|
||
savedata.ef_state = this.efState;
|
||
savedata.nimbus = this.nimbus;
|
||
savedata.icon = this.icon;
|
||
savedata.ef_pos = this.efPos;
|
||
savedata.ef_score = this.efScore;
|
||
|
||
// DB.saveDhamaInfo(this.efId, this.owner.roleid, savedata, () => {
|
||
// });
|
||
}
|
||
}
|
||
|
||
} |