282 lines
8.3 KiB
TypeScript
282 lines
8.3 KiB
TypeScript
|
import DB from "../utils/DB";
|
||
|
import Player from "./Player";
|
||
|
import Scheme from "./Scheme";
|
||
|
import SKDataUtil from "../gear/SKDataUtil";
|
||
|
import SKLogger from "../gear/SKLogger";
|
||
|
import { MsgCode } from "../role/EEnum";
|
||
|
import SKTimeUtil from "../gear/SKTimeUtil";
|
||
|
import Launch from "../core/Launch";
|
||
|
import GameUtil from "../core/GameUtil";
|
||
|
|
||
|
export default class SchemeMgr {
|
||
|
player: Player;
|
||
|
schemeList: any;
|
||
|
static dbTimer: NodeJS.Timeout;
|
||
|
|
||
|
constructor(player: Player) {
|
||
|
this.player = player;
|
||
|
this.schemeList = {};
|
||
|
}
|
||
|
|
||
|
static launch() {
|
||
|
SKLogger.info(`套装管理模块加载完毕!`);
|
||
|
}
|
||
|
|
||
|
initDefault() {
|
||
|
if (SKDataUtil.getLength(this.schemeList) >= 2) {
|
||
|
return;
|
||
|
}
|
||
|
for (var i = 0; i < 2; i++) {
|
||
|
let name = `套装方案 ${i + 1}`
|
||
|
let scheme = new Scheme(this.player, this, name);
|
||
|
scheme.schemeId = GameUtil.nextId().toString();
|
||
|
scheme.initDefaultData();
|
||
|
if (i == 1) {
|
||
|
scheme.status = -1;
|
||
|
}
|
||
|
this.schemeList[scheme.schemeId] = scheme;
|
||
|
}
|
||
|
}
|
||
|
// 从表中读取
|
||
|
readDB() {
|
||
|
let self = this;
|
||
|
DB.getSchemesByRoleId(this.player.roleid, (code: MsgCode, rows: any) => {
|
||
|
if (code == MsgCode.SUCCESS) {
|
||
|
if (rows.length > 0) {
|
||
|
for (let item of rows) {
|
||
|
let scheme = new Scheme(this.player, this, item.schemeName);
|
||
|
scheme.content = SKDataUtil.jsonBy(item.content);
|
||
|
scheme.status = item.status;
|
||
|
scheme.roleId = item.roleId;
|
||
|
scheme.schemeId = item.schemeId;
|
||
|
self.schemeList[scheme.schemeId] = scheme;
|
||
|
if (scheme.status == 1) {
|
||
|
self.player.setActivateSchemeName(item.schemeName);
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
self.initDefault();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
getActivateScheme() {
|
||
|
for (let key in this.schemeList) {
|
||
|
let scheme = this.schemeList[key];
|
||
|
if (scheme && scheme.status == 1) {
|
||
|
return scheme;
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
addScheme(name: any) {
|
||
|
let check = true;
|
||
|
for (let key in this.schemeList) {
|
||
|
if (this.schemeList.hasOwnProperty(key) && this.schemeList[key].schemeName == name) {
|
||
|
check = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (check) {
|
||
|
let scheme = new Scheme(this.player, this, name);
|
||
|
scheme.initDefaultData();
|
||
|
this.schemeList[scheme.schemeId] = scheme;
|
||
|
this.player.send('s2c_scheme_create', {
|
||
|
ecode: MsgCode.SUCCESS,
|
||
|
newSchemeInfo: JSON.stringify(scheme, function (key, val) {
|
||
|
if (key == 'player')
|
||
|
return undefined;
|
||
|
return val;
|
||
|
|
||
|
})
|
||
|
});
|
||
|
} else {
|
||
|
this.player.send('s2c_scheme_create', {
|
||
|
ecode: MsgCode.FAILED,
|
||
|
newSchemeInfo: ''
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
updateScheme(schemeId: any, data: any, type: any) {
|
||
|
if (this.schemeList.hasOwnProperty(schemeId)) {
|
||
|
let scheme = this.schemeList[schemeId];
|
||
|
scheme.updateScheme(type, data);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
deleteScheme(schemeId: any) {
|
||
|
if (this.schemeList.hasOwnProperty(schemeId)) {
|
||
|
delete this.schemeList[schemeId];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
getSchemeNameList() {
|
||
|
let schemeList = [];
|
||
|
for (var key in this.schemeList) {
|
||
|
if (this.schemeList.hasOwnProperty(key)) {
|
||
|
let scheme = { schemeId: key, schemeName: this.schemeList[key].schemeName, status: this.schemeList[key].status }
|
||
|
schemeList.push(scheme);
|
||
|
}
|
||
|
}
|
||
|
this.player.send('s2c_scheme_List', {
|
||
|
schemeList: SKDataUtil.toJson(schemeList,"[]")
|
||
|
})
|
||
|
}
|
||
|
|
||
|
addCustomPoint(data: any) {
|
||
|
if (this.schemeList.hasOwnProperty(data.schemeId)) {
|
||
|
let scheme = this.schemeList[data.schemeId];
|
||
|
if (scheme) {
|
||
|
scheme.addCustomPoint(data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
addXiulianPoint(data: any) {
|
||
|
if (this.schemeList.hasOwnProperty(data.schemeId)) {
|
||
|
let scheme = this.schemeList[data.schemeId];
|
||
|
if (scheme) {
|
||
|
scheme.addXiulianPoint(data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
resetXiulianPoint(data: any) {
|
||
|
if (this.schemeList.hasOwnProperty(data.schemeId)) {
|
||
|
let scheme = this.schemeList[data.schemeId];
|
||
|
if (scheme) {
|
||
|
scheme.resetXiulianPoint(data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
changePartner(data: any) {
|
||
|
if (this.schemeList.hasOwnProperty(data.schemeId)) {
|
||
|
let scheme = this.schemeList[data.schemeId];
|
||
|
if (scheme) {
|
||
|
scheme.changePartner(data);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
getSchemeInfo(schemeId: any) {
|
||
|
if (this.schemeList.hasOwnProperty(schemeId)) {
|
||
|
let scheme = this.schemeList[schemeId];
|
||
|
if (scheme) {
|
||
|
this.player.send('s2c_scheme_info', {
|
||
|
ecode: MsgCode.SUCCESS,
|
||
|
schemeInfo: JSON.stringify(scheme, function (key, val) {
|
||
|
if (key == 'player')
|
||
|
return undefined;
|
||
|
return val;
|
||
|
})
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
updateSchemeEquip(data: any) {
|
||
|
if (this.schemeList.hasOwnProperty(data.schemeId)) {
|
||
|
let scheme = this.schemeList[data.schemeId];
|
||
|
if (scheme) {
|
||
|
scheme.updateEquips(data.equipId, data.type);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
deleteCurEquips(delId: any) {
|
||
|
for (var it in this.schemeList) {
|
||
|
if (this.schemeList.hasOwnProperty(it)) {
|
||
|
let scheme = this.schemeList[it];
|
||
|
scheme.deleteEquips(delId);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
reset(){
|
||
|
for (var it in this.schemeList) {
|
||
|
if (this.schemeList.hasOwnProperty(it)) {
|
||
|
let scheme = this.schemeList[it];
|
||
|
scheme.schemeEquip();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
activateScheme(data: any) {
|
||
|
if (this.schemeList.hasOwnProperty(data.schemeId)) {
|
||
|
for (var it in this.schemeList) {
|
||
|
if (this.schemeList.hasOwnProperty(it)) {
|
||
|
let scheme = this.schemeList[it];
|
||
|
if (scheme.status == 1)
|
||
|
scheme.status = 0;
|
||
|
|
||
|
if (scheme.schemeId == data.schemeId) {
|
||
|
scheme.activateScheme(1);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
changeScheneName(data: any) {
|
||
|
if (this.schemeList.hasOwnProperty(data.schemeId)) {
|
||
|
let scheme = this.schemeList[data.schemeId];
|
||
|
if (scheme) {
|
||
|
scheme.changeSchemeName(data.name);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
useSchene(data: any) {
|
||
|
if (this.schemeList.hasOwnProperty(data.schemeId)) {
|
||
|
let scheme = this.schemeList[data.schemeId];
|
||
|
if (scheme) {
|
||
|
scheme.onUse();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
syncSchemePoint() {
|
||
|
for (var it in this.schemeList) {
|
||
|
if (this.schemeList.hasOwnProperty(it)) {
|
||
|
let scheme = this.schemeList[it];
|
||
|
if (scheme) {
|
||
|
scheme.syncPoint();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
syncSchemeEquips(curEquipsData: any) {
|
||
|
for (let key in this.schemeList) {
|
||
|
let scheme = this.schemeList[key];
|
||
|
if (scheme && scheme.status == 1) {
|
||
|
scheme.syncEquipsData(curEquipsData);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
syncSchemePartner() {
|
||
|
for (let key in this.schemeList) {
|
||
|
let scheme = this.schemeList[key];
|
||
|
if (scheme && scheme.status == 1) {
|
||
|
scheme.syncPartner();
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
saveDB(callback?: (code: number, msg: string) => void) {
|
||
|
DB.saveScheme(this.schemeList, (code: number, msg: string) => {
|
||
|
if (callback) {
|
||
|
callback(code, msg);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|