303 lines
10 KiB
TypeScript
303 lines
10 KiB
TypeScript
import Player from "./Player";
|
||
import GameUtil from "../core/GameUtil";
|
||
import SKDataUtil from "../gear/SKDataUtil";
|
||
import { MsgCode } from "../role/EEnum";
|
||
|
||
export default class Scheme {
|
||
schemeItemList: any;
|
||
schemeId: string;
|
||
roleId: any;
|
||
status: number;
|
||
schemeName: any;
|
||
player: Player;
|
||
content: any;
|
||
|
||
constructor(player: any, schemeMgr: any, name: any) {
|
||
this.schemeItemList = {};
|
||
this.schemeId = "0";
|
||
this.roleId = player.roleid;
|
||
this.status = 0; //-1 未开放,0,已开放未激活 1,已激活
|
||
this.schemeName = name;
|
||
this.player = player;
|
||
this.content = {};
|
||
}
|
||
|
||
initDefaultData() {
|
||
let partnerData = SKDataUtil.clone(this.player.partnerMgr.vecChuZhan);
|
||
let xlevel = this.player.xiulevel;
|
||
for (const key in this.player.addattr1) {
|
||
if (this.player.addattr1.hasOwnProperty(key)) {
|
||
xlevel = xlevel - this.player.addattr1[key];
|
||
}
|
||
}
|
||
this.content = {
|
||
curEquips: {},
|
||
attribute: {
|
||
//baseQianNeng:this.player.qianneng,
|
||
qianNeng: this.player.qianneng,//this.player.qianneng,
|
||
addPoint: SKDataUtil.clone(this.player.addattr2)
|
||
},
|
||
defense: {
|
||
//baseXiuLevel:this.player.xiulevel,
|
||
xiuLevel: xlevel,
|
||
xiuPoint: SKDataUtil.clone(this.player.addattr1)
|
||
|
||
},
|
||
partner: partnerData
|
||
};
|
||
}
|
||
|
||
changeSchemeName(data: any) {
|
||
this.schemeName = data;
|
||
this.player.send('s2c_scheme_changeName', {
|
||
ecode: MsgCode.SUCCESS,
|
||
schemeId: this.schemeId.toString(),
|
||
newName: this.schemeName
|
||
});
|
||
if (this.status == 1) {
|
||
this.checkEquipExist();
|
||
this.player.activateScheme();
|
||
}
|
||
}
|
||
|
||
syncPartner() {
|
||
let partnerData = SKDataUtil.clone(this.player.partnerMgr.vecChuZhan);
|
||
this.content.partner = partnerData
|
||
|
||
}
|
||
|
||
syncEquipsData(curEquipsData: boolean) {
|
||
this.content.curEquips = curEquipsData;
|
||
}
|
||
|
||
updateEquips(equipId: any, type: any) {
|
||
let equip = this.player.equipObjs[equipId];
|
||
let fullEquipData = equip.getFullData(this.player.roleid);
|
||
if (fullEquipData.NeedGrade > this.player.level || fullEquipData.NeedRei > this.player.relive) {
|
||
this.player.send('s2c_notice', {
|
||
strRichText: '角色等级不足,尚不能使用!'
|
||
});
|
||
return;//转生或等级不符合
|
||
}
|
||
if (fullEquipData.Shuxingxuqiu) { //属性需求不符合
|
||
for (const key in fullEquipData.Shuxingxuqiu) {
|
||
if (this.player.getAttr1(key) < fullEquipData.Shuxingxuqiu[key]) {
|
||
this.player.send('s2c_notice', {
|
||
strRichText: '角色属性不足,尚不能使用!'
|
||
});
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
if (equip) {
|
||
let result = false;
|
||
let curEquips = this.content.curEquips;
|
||
let unloadEquipId = -1;
|
||
if (curEquips.hasOwnProperty(equip.EIndex)) {
|
||
if (curEquips[equip.EIndex] == equipId) {
|
||
unloadEquipId = equipId;
|
||
delete curEquips[equip.EIndex];
|
||
result = true;
|
||
} else {
|
||
unloadEquipId = curEquips[equip.EIndex];
|
||
if (this.checkEquips(equipId)) {
|
||
curEquips[equip.EIndex] = equipId;
|
||
result = true;
|
||
}
|
||
}
|
||
} else {
|
||
if (this.checkEquips(equipId)) {
|
||
curEquips[equip.EIndex] = equipId;
|
||
result = true;
|
||
}
|
||
}
|
||
if (result) {
|
||
this.player.send('s2c_scheme_updateEquip', {
|
||
ecode: MsgCode.SUCCESS,
|
||
schemeId: this.schemeId.toString(),
|
||
curEquips: SKDataUtil.toJson(curEquips,"{}"),
|
||
type: type,
|
||
unloadEquipId: unloadEquipId.toString(),
|
||
});
|
||
if (this.status == 1) {
|
||
this.checkEquipExist();
|
||
this.player.activateScheme();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
syncPoint() {
|
||
if (this.status == 1) {
|
||
//激活,则同步所有加点数据
|
||
this.content.attribute.qianNeng = this.player.qianneng;
|
||
this.content.attribute.addPoint = SKDataUtil.clone(this.player.addattr2);
|
||
this.content.defense.xiuPoint = SKDataUtil.clone(this.player.addattr1);
|
||
this.content.defense.xiuLevel = this.player.xiulevel;
|
||
for (var key in this.content.defense.xiuPoint) {
|
||
if (this.content.defense.xiuPoint.hasOwnProperty(key)) {
|
||
this.content.defense.xiuLevel -= this.content.defense.xiuPoint[key];
|
||
}
|
||
}
|
||
} else {
|
||
//未激活,如果潜能和修炼点数据总值发生变化,则同步数据
|
||
let curXLevel = this.content.defense.xiuLevel;
|
||
for (var key in this.content.defense.xiuPoint) {
|
||
if (this.content.defense.xiuPoint.hasOwnProperty(key)) {
|
||
curXLevel += this.content.defense.xiuPoint[key];
|
||
}
|
||
}
|
||
let diffXiu = this.player.xiulevel - curXLevel;
|
||
this.content.defense.xiuLevel += (diffXiu >= 0 ? diffXiu : 0);
|
||
|
||
let curQianneng = this.content.attribute.qianNeng;
|
||
for (var key in this.content.attribute.addPoint) {
|
||
if (this.content.attribute.addPoint.hasOwnProperty(key)) {
|
||
curQianneng += this.content.attribute.addPoint[key];
|
||
}
|
||
}
|
||
let diffValue = this.player.getTotalQianneng() - curQianneng;
|
||
this.content.attribute.qianNeng += (diffValue >= 0 ? diffValue : 0);
|
||
}
|
||
}
|
||
|
||
deleteEquips(delId: any) {
|
||
for (var it in this.content.curEquips) {
|
||
if (this.content.curEquips.hasOwnProperty(it)) {
|
||
let equipId = this.content.curEquips[it]
|
||
if (equipId == delId)
|
||
delete this.content.curEquips[it]
|
||
}
|
||
}
|
||
}
|
||
|
||
schemeEquip(data: any){
|
||
for(let scheme in this.content.curEquips){
|
||
let eqiup = this.content.curEquips[scheme];
|
||
if (eqiup) {
|
||
this.updateEquips(eqiup, 1);
|
||
}
|
||
}
|
||
}
|
||
|
||
checkEquips(checkId: any) {
|
||
let result = false;
|
||
for (var it in this.content.curEquips) {
|
||
if (this.content.curEquips.hasOwnProperty(it)) {
|
||
let equipId = this.content.curEquips[it]
|
||
if (equipId == checkId)
|
||
result = true;
|
||
}
|
||
}
|
||
result = this.player.checkSchemeEquip(checkId);
|
||
return result;
|
||
}
|
||
|
||
addCustomPoint(data: any) {
|
||
this.content.attribute.addPoint = SKDataUtil.jsonBy(data.addPoint);
|
||
this.content.attribute.qianNeng = data.qianNeng;
|
||
if (this.status == 1) {
|
||
this.checkEquipExist();
|
||
this.player.activateScheme();
|
||
}
|
||
}
|
||
|
||
addXiulianPoint(data: any) {
|
||
this.content.defense.xiuPoint = SKDataUtil.jsonBy(data.xiulianPoint);
|
||
this.content.defense.xiuLevel = data.xiulevel;
|
||
if (this.status == 1) {
|
||
this.checkEquipExist();
|
||
this.player.activateScheme();
|
||
}
|
||
}
|
||
|
||
resetXiulianPoint(data: any) {
|
||
let strErr = this.player.CostFee(GameUtil.goldKind.Money, 200000);
|
||
if (strErr != "") {
|
||
this.player.send('s2c_scheme_resetXiulianPoint', {
|
||
ecode: MsgCode.FAILED,
|
||
errorMsg: strErr
|
||
})
|
||
return;
|
||
}
|
||
this.content.defense.xiuLevel = this.player.xiulevel;
|
||
for (var key in this.content.defense.xiuPoint) {
|
||
if (this.content.defense.xiuPoint.hasOwnProperty(key)) {
|
||
this.content.defense.xiuPoint[key] = 0;
|
||
}
|
||
}
|
||
if (this.status == 1) {
|
||
this.checkEquipExist();
|
||
this.player.activateScheme();
|
||
}
|
||
|
||
this.player.send('s2c_scheme_resetXiulianPoint', {
|
||
ecode: MsgCode.SUCCESS,
|
||
errorMsg: ''
|
||
})
|
||
}
|
||
|
||
changePartner(data: any) {
|
||
this.content.partner[data.order] = data.partnerId;
|
||
if (this.status == 1) {
|
||
this.checkEquipExist();
|
||
this.player.activateScheme();
|
||
}
|
||
}
|
||
|
||
|
||
checkEquipExist() {
|
||
for (var key in this.content.curEquips) {
|
||
if (this.content.curEquips.hasOwnProperty(key)) {
|
||
if (!this.player.checkEquipExist(this.content.curEquips[key])) {
|
||
delete this.content.curEquips[key];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
activateScheme(status: any) {
|
||
//如果方案里的装备已经不存在,则从方案中删除
|
||
this.checkEquipExist();
|
||
this.status = status;
|
||
if (this.status == 1) {
|
||
let strErr = this.player.CostFee(GameUtil.goldKind.Money, 100000);
|
||
if (strErr != '') {
|
||
this.status = 0;
|
||
return;
|
||
}
|
||
console.log(typeof this.schemeId)
|
||
this.player.send('s2c_scheme_activate', {
|
||
ecode: MsgCode.SUCCESS,
|
||
schemeId: this.schemeId.toString()
|
||
});
|
||
this.player.activateScheme();
|
||
}
|
||
}
|
||
|
||
onUse() {
|
||
let strErr = this.player.CostFee(GameUtil.goldKind.Money, 10000000);
|
||
if (strErr != "") {
|
||
return;
|
||
}
|
||
this.player.send('s2c_scheme_use', {
|
||
ecode: MsgCode.SUCCESS,
|
||
schemeId: this.schemeId.toString()
|
||
});
|
||
this.status = 0;
|
||
}
|
||
|
||
|
||
toObj() {
|
||
let obj: any = {};
|
||
obj.schemeId = this.schemeId == undefined ? "" : this.schemeId.toString();
|
||
obj.roleId = this.roleId;
|
||
obj.status = this.status;
|
||
obj.schemeName = this.schemeName;
|
||
obj.content = SKDataUtil.toJson(this.content,"{}");
|
||
if (obj.status == undefined){
|
||
obj.status = 0;
|
||
}
|
||
return obj;
|
||
}
|
||
} |