433 lines
16 KiB
TypeScript
433 lines
16 KiB
TypeScript
import SKDataUtil from "../gear/SKDataUtil";
|
||
import SKLogger from "../gear/SKLogger";
|
||
import DB from "../utils/DB";
|
||
import GameUtil from "../core/GameUtil";
|
||
import {EEquipPos, EEquipType, Operate} from "../role/EEnum";
|
||
import EquipMgr from "./EquipMgr";
|
||
import Player from "./Player";
|
||
|
||
export default class Equip {
|
||
owner: Player;
|
||
name: string;
|
||
EquipID: string;
|
||
EquipType: number;
|
||
// 装备评分
|
||
BaseScore: number;
|
||
BaseAttr: any;
|
||
Grade: number;
|
||
EIndex: number;
|
||
Shuxingxuqiu: any;
|
||
Type: any;
|
||
GemCnt: any;
|
||
LianhuaAttr: any;
|
||
pos: any;
|
||
state: any;
|
||
attr1: any;
|
||
gemarr: any;
|
||
refine: any = {};
|
||
recast: any = {};
|
||
|
||
constructor(info: any, owner: Player) {
|
||
this.owner = owner;
|
||
this.name = '';
|
||
this.EquipID = info.EquipID;
|
||
this.EquipType = 0;
|
||
this.BaseAttr = {};
|
||
this.Grade = 0;
|
||
this.EIndex = 0;
|
||
this.Shuxingxuqiu = {};
|
||
this.Type = 0;
|
||
this.GemCnt = 0;
|
||
this.LianhuaAttr = {};
|
||
this.pos = EEquipPos.BAG; // 所在位置 1初始 2身上 3背包 4仓库
|
||
this.state = 1;
|
||
// 属性
|
||
this.attr1 = {};
|
||
GameUtil.clearAllAttr(this.attr1);
|
||
// 行 装备位 0-武器 ... 列 1,2,3,4,5,6,7级宝石
|
||
this.gemarr = [
|
||
[30025, 30026, 30027, 30028, 30029, 30030, 30104], // 红宝石
|
||
[30013, 30014, 30015, 30016, 30017, 30018, 30102], // 绿宝石
|
||
[30019, 30020, 30021, 30022, 30023, 30024, 30103], // 蓝宝石
|
||
[30001, 30002, 30003, 30004, 30005, 30006, 30100], // 紫宝石
|
||
[30007, 30008, 30009, 30010, 30011, 30012, 30101], // 橙宝石
|
||
];
|
||
this.setDB(info);
|
||
}
|
||
|
||
setDB(info: any) {
|
||
if (info == null) {
|
||
return;
|
||
}
|
||
if (info.name) {
|
||
this.name = info.name;
|
||
} else if (info.EName) {
|
||
this.name = info.EName;
|
||
}
|
||
info.EquipType && (this.EquipType = info.EquipType);
|
||
if (info.BaseAttr) {
|
||
this.BaseAttr = SKDataUtil.jsonBy(info.BaseAttr);
|
||
}
|
||
info.Grade && (this.Grade = info.Grade);
|
||
info.EIndex && (this.EIndex = info.EIndex);
|
||
info.Shuxingxuqiu && (this.Shuxingxuqiu = SKDataUtil.jsonBy(info.Shuxingxuqiu));
|
||
info.Type && (this.Type = info.Type);
|
||
info.GemCnt && (this.GemCnt = info.GemCnt);
|
||
info.LianhuaAttr && (this.LianhuaAttr = SKDataUtil.jsonBy(info.LianhuaAttr));
|
||
if (info.refine) {
|
||
this.refine = SKDataUtil.toJson(info.refine, "{}");
|
||
}
|
||
if (info.recast) {
|
||
this.refine = SKDataUtil.toJson(info.recast, "{}");
|
||
}
|
||
info.pos && (this.pos = info.pos);
|
||
this.calculateAttribute();
|
||
}
|
||
|
||
getAttr(attrtype: number): number {
|
||
return this.attr1[attrtype];
|
||
}
|
||
|
||
canUpgrade(): boolean {
|
||
let fulldata: any = this.getFullData();
|
||
if (fulldata.EquipType == EEquipType.XinShou) {
|
||
|
||
} else if (fulldata.EquipType == EEquipType.HIGH) {
|
||
if (fulldata.Grade >= 120) {
|
||
return false;
|
||
}
|
||
} else if (fulldata.EquipType > EEquipType.HIGH) {
|
||
if (!fulldata.NextType || fulldata.NextType == 0) {
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
checkUpgradeBroke(): boolean {
|
||
// 1-2=50%
|
||
// 2-3=25%
|
||
// 3-4=5%
|
||
// 4-5=1%
|
||
if (this.Grade > GameUtil.shenBingBroke.length) {
|
||
return false;
|
||
}
|
||
let r = GameUtil.random(0, 10000);
|
||
let successpre = GameUtil.shenBingBroke[this.Grade - 1];
|
||
if (r < successpre) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// 升阶
|
||
upgrade(data: any): boolean {
|
||
let fulldata: any = this.getFullData();
|
||
let nextGrade = 0;
|
||
let nextType = fulldata.NextType;
|
||
let toType = fulldata.EquipType;
|
||
if (fulldata.EquipType == 0) {
|
||
nextGrade = 2;
|
||
toType = 1;
|
||
} else if (fulldata.EquipType == 1) {
|
||
nextGrade = fulldata.Grade + 1;
|
||
toType = 1;
|
||
} else if (fulldata.EquipType >= 1) {
|
||
if (!fulldata.NextType || fulldata.NextType == 0) {
|
||
return false;
|
||
}
|
||
nextGrade = fulldata.Grade + 1;
|
||
}
|
||
data.resid = nextType;
|
||
let oldGrade = data.grade;
|
||
if (oldGrade == null) {
|
||
oldGrade = 1;
|
||
}
|
||
data.grade = nextGrade;
|
||
data.type = toType;
|
||
data.index = fulldata.EIndex;
|
||
let equipData = EquipMgr.shared.getEquipData(data);
|
||
this.setDB(equipData);
|
||
return true;
|
||
}
|
||
|
||
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;
|
||
}
|
||
value = Math.floor(SKDataUtil.toDecimal2(value * (1 + 0.033 * this.GemCnt)));
|
||
this.attr1[key] += value;
|
||
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;
|
||
}
|
||
value = Math.floor(SKDataUtil.toDecimal2(value * (1 + 0.033 * this.GemCnt)));
|
||
this.attr1[key] += value;
|
||
}
|
||
}
|
||
}
|
||
if (Array.isArray(this.LianhuaAttr)) {
|
||
for (let data of this.LianhuaAttr) {
|
||
for (let key in data) {
|
||
let nkey = parseInt(key);
|
||
let value = parseInt(data[nkey]);
|
||
if (GameUtil.equipTypeNumerical.indexOf(nkey) == -1) {
|
||
value = value / 10;
|
||
}
|
||
this.attr1[key] += value;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
getInlayGemID(): any {
|
||
let result = this.gemarr[this.EIndex - 1][Math.floor(this.GemCnt / 3)];
|
||
return result;
|
||
}
|
||
|
||
getGemList(): any {
|
||
let list: any = {};
|
||
if (this.GemCnt > 21) {
|
||
this.GemCnt = 21;
|
||
}
|
||
let curGemlevel = Math.floor(this.GemCnt / 3);
|
||
for (let index = 0; index < curGemlevel; index++) {
|
||
list[this.gemarr[this.EIndex - 1][index]] = 3;
|
||
}
|
||
let lastNum = this.GemCnt - Math.floor(this.GemCnt / 3) * 3;
|
||
if (lastNum > 0) {
|
||
list[this.gemarr[this.EIndex - 1][curGemlevel]] = lastNum;
|
||
}
|
||
return list;
|
||
}
|
||
|
||
getFullData(roleId?: number): any {
|
||
let equipdata: any = EquipMgr.shared.getEquipData({resid: this.Type, type: this.EquipType});
|
||
if (equipdata == null) {
|
||
SKLogger.warn(`装备[${this.EquipID}:${this.name}]完整信息为空!`);
|
||
return null;
|
||
}
|
||
if (SKDataUtil.isEmptyString(equipdata.EName)) {
|
||
SKLogger.warn(``);
|
||
} else {
|
||
this.name = equipdata.EName;
|
||
}
|
||
let fulldata: any = {};
|
||
fulldata.EquipID = this.EquipID;
|
||
fulldata.EquipType = this.EquipType;
|
||
fulldata.BaseAttr = this.BaseAttr;
|
||
fulldata.EDesc = equipdata.EDesc;
|
||
fulldata.Detail = equipdata.Detail;
|
||
fulldata.Dynamic = equipdata.Dynamic;
|
||
fulldata.Grade = this.Grade;
|
||
fulldata.EIndex = this.EIndex;
|
||
fulldata.JiLv = equipdata.JiLv;
|
||
fulldata.MaxEmbedGemCnt = equipdata.MaxEmbedGemCnt;
|
||
fulldata.MaxEndure = equipdata.MaxEndure;
|
||
fulldata.EName = this.name;
|
||
fulldata.NeedGrade = equipdata.NeedGrade;
|
||
fulldata.NeedRei = equipdata.NeedRei;
|
||
fulldata.NextType = equipdata.NextType;
|
||
fulldata.Overlap = equipdata.Overlap;
|
||
fulldata.Quan = equipdata.Quan;
|
||
fulldata.Race = equipdata.Race;
|
||
fulldata.Rarity = equipdata.Rarity;
|
||
fulldata.RndRange = equipdata.RndRange;
|
||
fulldata.RndWeight = equipdata.RndWeight;
|
||
fulldata.Sex = equipdata.Sex;
|
||
fulldata.Shape = equipdata.Shape;
|
||
fulldata.Shuxingxuqiu = this.Shuxingxuqiu;
|
||
fulldata.Type = this.Type;
|
||
fulldata.GemCnt = this.GemCnt;
|
||
fulldata.LianhuaAttr = this.LianhuaAttr;
|
||
fulldata.OwnerRoleId = equipdata.OwnerRoleId;
|
||
let score = GameUtil.getEquipScore(this.BaseAttr, this.LianhuaAttr, this.EquipType, this.Grade, equipdata.Sex, equipdata.Race, equipdata.BaseScore, this.getGemList());
|
||
this.BaseScore = score;
|
||
fulldata.BaseScore = score;
|
||
return fulldata;
|
||
}
|
||
|
||
toObj() {
|
||
let fulldata = this.getFullData();
|
||
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.EquipID = this.EquipID;
|
||
obj.EquipType = this.EquipType;
|
||
obj.BaseAttr = SKDataUtil.toJson(baseAttr, "{}");
|
||
obj.EDesc = fulldata.EDesc;
|
||
obj.Detail = fulldata.Detail;
|
||
obj.Dynamic = fulldata.Dynamic;
|
||
obj.Grade = this.Grade;
|
||
obj.EIndex = this.EIndex;
|
||
obj.JiLv = fulldata.JiLv;
|
||
obj.MaxEmbedGemCnt = fulldata.MaxEmbedGemCnt;
|
||
obj.MaxEndure = fulldata.MaxEndure;
|
||
obj.EName = fulldata.EName;
|
||
obj.NeedGrade = fulldata.NeedGrade;
|
||
obj.NeedRei = fulldata.NeedRei;
|
||
obj.NextType = fulldata.NextType;
|
||
obj.Overlap = fulldata.Overlap;
|
||
obj.Quan = fulldata.Quan;
|
||
obj.Race = fulldata.Race;
|
||
obj.Rarity = fulldata.Rarity;
|
||
obj.RndRange = fulldata.RndRange;
|
||
obj.RndWeight = fulldata.RndWeight;
|
||
obj.Sex = fulldata.Sex;
|
||
obj.Shape = fulldata.Shape;
|
||
obj.Shuxingxuqiu = SKDataUtil.toJson(this.Shuxingxuqiu, "{}");
|
||
obj.Type = this.Type;
|
||
obj.GemCnt = this.GemCnt;
|
||
obj.LianhuaAttr = SKDataUtil.toJson(this.LianhuaAttr, "{}");
|
||
obj.OwnerRoleId = fulldata.OwnerRoleId;
|
||
obj.refine = SKDataUtil.toJson(this.refine, "{}");
|
||
obj.recast = SKDataUtil.toJson(this.recast, "{}");
|
||
obj.BaseScore = fulldata.BaseScore;
|
||
return obj;
|
||
}
|
||
|
||
getSendInfo(): any {
|
||
let fullEquipData = this.getFullData();
|
||
if (fullEquipData == null) {
|
||
SKLogger.warn(`装备[${this.EquipID}:${this.name}]发送信息为空`);
|
||
return null;
|
||
}
|
||
// 判断当前配饰是否需要鉴定(0 不需要鉴定 1 需要鉴定)
|
||
let flag = 0;
|
||
if (fullEquipData.EquipType == EEquipType.BALDRIC && fullEquipData.BaseAttr.length < 1) {
|
||
flag = 1;
|
||
}
|
||
|
||
let result = {
|
||
EquipID: fullEquipData.EquipID,
|
||
Shape: fullEquipData.Shape,
|
||
EName: fullEquipData.EName,
|
||
EquipType: fullEquipData.EquipType,
|
||
EIndex: fullEquipData.EIndex,
|
||
Grade: fullEquipData.Grade,
|
||
NextType: fullEquipData.NextType,
|
||
Type: fullEquipData.Type,
|
||
GemCnt: fullEquipData.GemCnt,
|
||
flag: flag,
|
||
};
|
||
return result;
|
||
}
|
||
|
||
save() {
|
||
if (this.state == 0) {
|
||
DB.delEquip(this.EquipID, this.owner.roleid, (code: number) => {
|
||
});
|
||
} else {
|
||
let savedata: any = {};
|
||
savedata.name = this.name;
|
||
savedata.EquipType = this.EquipType;
|
||
savedata.BaseAttr = SKDataUtil.toJson(this.BaseAttr, "{}");
|
||
savedata.Grade = this.Grade;
|
||
savedata.EIndex = this.EIndex;
|
||
savedata.Shuxingxuqiu = SKDataUtil.toJson(this.Shuxingxuqiu, "{}");
|
||
savedata.Type = this.Type;
|
||
savedata.GemCnt = this.GemCnt;
|
||
savedata.LianhuaAttr = SKDataUtil.toJson(this.LianhuaAttr, "{}");
|
||
savedata.refine = SKDataUtil.toJson(this.refine, "{}");
|
||
savedata.recast = SKDataUtil.toJson(this.recast, "{}");
|
||
savedata.pos = this.pos;
|
||
savedata.BaseScore = this.BaseScore;
|
||
DB.saveEquipInfo(this.EquipID, this.owner.roleid, savedata, () => {
|
||
});
|
||
}
|
||
}
|
||
|
||
saveSQL(): string {
|
||
if (this.state == 0) {
|
||
return `UPDATE qy_equip SET state = 0, delete_time = NOW() WHERE EquipID='${this.EquipID}' AND RoleID='${this.owner.roleid}';`
|
||
} else {
|
||
let savedata: any = {};
|
||
savedata.name = this.name;
|
||
savedata.EquipType = this.EquipType;
|
||
savedata.BaseAttr = SKDataUtil.toJson(this.BaseAttr, "{}");
|
||
savedata.Grade = this.Grade;
|
||
savedata.EIndex = this.EIndex;
|
||
savedata.Shuxingxuqiu = SKDataUtil.toJson(this.Shuxingxuqiu, "{}");
|
||
savedata.Type = this.Type;
|
||
savedata.GemCnt = this.GemCnt;
|
||
savedata.LianhuaAttr = SKDataUtil.toJson(this.LianhuaAttr, "{}");
|
||
savedata.refine = SKDataUtil.toJson(this.refine, "{}");
|
||
savedata.recast = SKDataUtil.toJson(this.recast, "{}");
|
||
savedata.pos = this.pos;
|
||
//防止装备无评分报错
|
||
if (this.BaseScore == undefined) {
|
||
let score = 0;
|
||
let equipdata: any = EquipMgr.shared.getEquipData({resid: this.Type, type: this.EquipType});
|
||
if (equipdata != null && equipdata != undefined) {
|
||
score = GameUtil.getEquipScore(this.BaseAttr, this.LianhuaAttr, this.EquipType, this.Grade, equipdata.Sex, equipdata.Race, equipdata.BaseScore, this.getGemList());
|
||
}
|
||
this.BaseScore = score;
|
||
}
|
||
savedata.BaseScore = this.BaseScore;
|
||
let numlist = ['pos', 'Grade', 'Type', 'GemCnt', 'EIndex', 'BaseScore'];
|
||
let updatestr = '';
|
||
for (const key in savedata) {
|
||
if (numlist.indexOf(key) == -1) {
|
||
updatestr += `${key} = '${savedata[key]}', `
|
||
} else {
|
||
updatestr += `${key} = ${savedata[key]}, `
|
||
}
|
||
}
|
||
updatestr = updatestr.substr(0, updatestr.length - 2);
|
||
let sql = `UPDATE qy_equip SET ${updatestr} WHERE EquipID = '${this.EquipID}' AND RoleID='${this.owner.roleid}';`;
|
||
return sql;
|
||
}
|
||
}
|
||
|
||
cxfEquip(RoleID: any) {
|
||
let savedata: any = {};
|
||
savedata.equipID = this.EquipID;
|
||
savedata.equipType = this.EquipType;
|
||
savedata.roleID = RoleID;
|
||
savedata.baseAttr = SKDataUtil.toJson(this.BaseAttr, "{}");
|
||
savedata.grade = this.Grade;
|
||
savedata.eIndex = this.EIndex;
|
||
savedata.shuxingxuqiu = SKDataUtil.toJson(this.Shuxingxuqiu, "{}");
|
||
savedata.type = this.Type;
|
||
savedata.gemCnt = this.GemCnt;
|
||
savedata.lianhuaAttr = SKDataUtil.toJson(this.LianhuaAttr, "{}");
|
||
savedata.refine = SKDataUtil.toJson(this.refine, "{}");
|
||
savedata.recast = SKDataUtil.toJson(this.recast, "{}");
|
||
savedata.pos = this.pos;
|
||
savedata.name = this.name;
|
||
//防止装备无评分报错
|
||
if (this.BaseScore == undefined) {
|
||
let equipdata: any = EquipMgr.shared.getEquipData({resid: this.Type, type: this.EquipType});
|
||
let score = GameUtil.getEquipScore(this.BaseAttr, this.LianhuaAttr, this.EquipType, this.Grade, equipdata.Sex, equipdata.Race, equipdata.BaseScore, this.getGemList());
|
||
this.BaseScore = score;
|
||
}
|
||
savedata.baseScore = this.BaseScore;
|
||
return savedata;
|
||
}
|
||
} |