SamsaraGame/assets/Script/panel/BangXiulian.js
2025-04-24 17:03:28 +08:00

279 lines
12 KiB
JavaScript

import GameModel from "../ts/core/GameModel";
import MsgAlert from "../ts/game/msg/MsgAlert";
import {EAttrTypeL1} from "../ts/core/EEnum";
import GameUtil from "../ts/core/GameUtil";
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
cc.Class({
extends: cc.Component,
properties: {
contentNode: cc.Node,
sureNode: cc.Node,
xiuNode: cc.Node,
leftPointLab: cc.Label,
xiuLevelLab: cc.Label,
panelReset: cc.Node,
},
onLoad() {
},
loadInfo() {
this.xiuNode.active = true;
this.sureNode.active = false;
this.dpoint = SKDataUtil.clone(GameModel.player.gameData.addattr1);
this.dpointBase = SKDataUtil.clone(this.dpoint);
this.attr1 = GameModel.player.gameData.attr1;
this.xlevel = GameModel.player.gameData.xiulevel;
this.leftpoint = this.xlevel;
for (const key in this.dpoint) {
if (SKDataUtil.hasProperty(this.dpoint,key)) {
this.leftpoint -= this.dpoint[key];
}
}
if (this.leftpoint < 0) {
this.leftpoint = 0;
}
this.dpointT = {};
this.dshangxian = this.attr1[EAttrTypeL1.K_SEAL_CONFUSION_SLEEP_FORGET_LIMIT];
this.dfengyin = this.attr1[EAttrTypeL1.K_SEAL];
this.dhunlun = this.attr1[EAttrTypeL1.K_CONFUSION];
this.dhunshui = this.attr1[EAttrTypeL1.K_SLEEP];
this.dyiwang = this.attr1[EAttrTypeL1.K_FORGET];
this.dfeng = this.attr1[EAttrTypeL1.K_WIND];
this.dlei = this.attr1[EAttrTypeL1.K_THUNDER];
this.dshui = this.attr1[EAttrTypeL1.K_WATER];
this.dhuo = this.attr1[EAttrTypeL1.K_FIRE];
this.dguihuo = this.attr1[EAttrTypeL1.K_WILDFIRE];
this.dsanshi = this.attr1[EAttrTypeL1.K_BLOODRETURN];
this.ddu = this.attr1[EAttrTypeL1.K_POISON];
this.pxishou = this.attr1[EAttrTypeL1.PHY_GET];
this.showDInfo();
},
calculateProperty() {
this.xiuNode.active = false;
this.sureNode.active = true;
this.leftpoint = this.xlevel;//PracticeMgr.GetLevelPoint(GameModel.player.relive, this.xlevel);
for (const key in this.dpoint) {
if (SKDataUtil.hasProperty(this.dpoint,key)){
this.leftpoint -= this.dpoint[key];
}
}
if (this.leftpoint < 0) {
this.leftpoint = 0;
}
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_SEAL_CONFUSION_SLEEP_FORGET_LIMIT)) && (this.dshangxian = this.attr1[EAttrTypeL1.K_SEAL_CONFUSION_SLEEP_FORGET_LIMIT] + this.dpointT[EAttrTypeL1.K_SEAL_CONFUSION_SLEEP_FORGET_LIMIT] * 2.5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_SEAL)) && (this.dfengyin = this.attr1[EAttrTypeL1.K_SEAL] + this.dpointT[EAttrTypeL1.K_SEAL] * 5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_CONFUSION)) && (this.dhunlun = this.attr1[EAttrTypeL1.K_CONFUSION] + this.dpointT[EAttrTypeL1.K_CONFUSION] * 5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_SLEEP)) && (this.dhunshui = this.attr1[EAttrTypeL1.K_SLEEP] + this.dpointT[EAttrTypeL1.K_SLEEP] * 5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_FORGET)) && (this.dyiwang = this.attr1[EAttrTypeL1.K_FORGET] + this.dpointT[EAttrTypeL1.K_FORGET] * 5);
if (this.dfengyin > this.dshangxian) {
this.dfengyin = this.dshangxian;
}
if (this.dhunlun > this.dshangxian) {
this.dhunlun = this.dshangxian;
}
if (this.dhunshui > this.dshangxian) {
this.dhunshui = this.dshangxian;
}
if (this.dyiwang > this.dshangxian) {
this.dyiwang = this.dshangxian;
}
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_WIND)) && (this.dfeng = this.attr1[EAttrTypeL1.K_WIND] + this.dpointT[EAttrTypeL1.K_WIND] * 5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_THUNDER)) && (this.dlei = this.attr1[EAttrTypeL1.K_THUNDER] + this.dpointT[EAttrTypeL1.K_THUNDER] * 5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_WATER)) && (this.dshui = this.attr1[EAttrTypeL1.K_WATER] + this.dpointT[EAttrTypeL1.K_WATER] * 5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_FIRE)) && (this.dhuo = this.attr1[EAttrTypeL1.K_FIRE] + this.dpointT[EAttrTypeL1.K_FIRE] * 5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_WILDFIRE)) && (this.dguihuo = this.attr1[EAttrTypeL1.K_WILDFIRE] + this.dpointT[EAttrTypeL1.K_WILDFIRE] * 5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_BLOODRETURN)) && (this.dsanshi = this.attr1[EAttrTypeL1.K_BLOODRETURN] + this.dpointT[EAttrTypeL1.K_BLOODRETURN] * 5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.K_POISON)) && (this.ddu = this.attr1[EAttrTypeL1.K_POISON] + this.dpointT[EAttrTypeL1.K_POISON] * 5);
(this.dpointT.hasOwnProperty(EAttrTypeL1.PHY_GET)) && (this.pxishou = this.attr1[EAttrTypeL1.PHY_GET] + this.dpointT[EAttrTypeL1.PHY_GET] * 4);
this.showDInfo();
},
initBtn(btn, data, type) {
btn.datainfo = data;
btn.opertype = type;
btn.on(cc.Node.EventType.TOUCH_START, this.propertyBtnClick.bind(this));
btn.on(cc.Node.EventType.TOUCH_CANCEL, this.propertyBtnClick.bind(this));
btn.on(cc.Node.EventType.TOUCH_END, this.propertyBtnClick.bind(this));
},
propertyBtnClick(e) {
if (e.type == cc.Node.EventType.TOUCH_START) {
this.maxtiemcnt = 30;
this.timecnt = 0;
this.currentBtn = e.target;
}
else if (e.type == cc.Node.EventType.TOUCH_END || e.type == cc.Node.EventType.TOUCH_CANCEL) {
this.timecnt = this.maxtiemcnt;
this.update();
this.currentBtn = null;
}
},
update() {
if (this.currentBtn == null) {
return;
}
this.timecnt++;
if (this.timecnt >= this.maxtiemcnt) {
if (this.maxtiemcnt > 4) {
this.maxtiemcnt -= 2;
}
this.timecnt = 0;
if (this.currentBtn.opertype == 0) {
this.propertyAddPoint(this.currentBtn.datainfo);
}
else if (this.currentBtn.opertype == 1) {
this.propertySubPoint(this.currentBtn.datainfo);
}
}
},
initKangBtn() {
this.setKangBtnInfo('item', EAttrTypeL1.K_SEAL_CONFUSION_SLEEP_FORGET_LIMIT);
this.setKangBtnInfo('itemfengyin', EAttrTypeL1.K_SEAL);
this.setKangBtnInfo('itemhunluan', EAttrTypeL1.K_CONFUSION);
this.setKangBtnInfo('itemhunshui', EAttrTypeL1.K_SLEEP);
this.setKangBtnInfo('itemyiwang', EAttrTypeL1.K_FORGET);
this.setKangBtnInfo('itemfeng', EAttrTypeL1.K_WIND);
this.setKangBtnInfo('itemlei', EAttrTypeL1.K_THUNDER);
this.setKangBtnInfo('itemshui', EAttrTypeL1.K_WATER);
this.setKangBtnInfo('itemhuo', EAttrTypeL1.K_FIRE);
this.setKangBtnInfo('itemguihuo', EAttrTypeL1.K_WILDFIRE);
this.setKangBtnInfo('itemsanshi', EAttrTypeL1.K_BLOODRETURN);
this.setKangBtnInfo('itemdushang', EAttrTypeL1.K_POISON);
this.setKangBtnInfo('itemwuli', EAttrTypeL1.PHY_GET);
},
setKangBtnInfo(name, type) {
this.initBtn(cc.find(`${name}/point/addBtn`, this.contentNode), type, 0);
this.initBtn(cc.find(`${name}/point/subBtn`, this.contentNode), type, 1);
if (this.leftpoint <= 0) {
cc.find(`${name}/point/addBtn`, this.contentNode).active = false;
} else {
cc.find(`${name}/point/addBtn`, this.contentNode).active = true;
}
if (this.dpointT[type] > 0) {
cc.find(`${name}/point/subBtn`, this.contentNode).active = true;
} else {
cc.find(`${name}/point/subBtn`, this.contentNode).active = false;
}
},
showDInfo() {
this.leftPointLab.string = this.leftpoint;
this.xiuLevelLab.string = '修煉LV.' + this.xlevel;
cc.find('item/point/num', this.contentNode).getComponent(cc.Label).string = this.dshangxian.toFixed(1) + '%';
cc.find('item/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_SEAL_CONFUSION_SLEEP_FORGET_LIMIT] == null ? 0 : this.dpoint[EAttrTypeL1.K_SEAL_CONFUSION_SLEEP_FORGET_LIMIT]);
cc.find('itemfengyin/point/num', this.contentNode).getComponent(cc.Label).string = this.dfengyin.toFixed(1) + '%';
cc.find('itemfengyin/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_SEAL] == null ? 0 : this.dpoint[EAttrTypeL1.K_SEAL]);
cc.find('itemhunluan/point/num', this.contentNode).getComponent(cc.Label).string = this.dhunlun.toFixed(1) + '%';
cc.find('itemhunluan/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_CONFUSION] == null ? 0 : this.dpoint[EAttrTypeL1.K_CONFUSION]);
cc.find('itemhunshui/point/num', this.contentNode).getComponent(cc.Label).string = this.dhunshui.toFixed(1) + '%';
cc.find('itemhunshui/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_SLEEP] == null ? 0 : this.dpoint[EAttrTypeL1.K_SLEEP]);
cc.find('itemyiwang/point/num', this.contentNode).getComponent(cc.Label).string = this.dyiwang.toFixed(1) + '%';
cc.find('itemyiwang/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_FORGET] == null ? 0 : this.dpoint[EAttrTypeL1.K_FORGET]);
cc.find('itemfeng/point/num', this.contentNode).getComponent(cc.Label).string = this.dfeng.toFixed(1) + '%';
cc.find('itemfeng/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_WIND] == null ? 0 : this.dpoint[EAttrTypeL1.K_WIND]);
cc.find('itemlei/point/num', this.contentNode).getComponent(cc.Label).string = this.dlei.toFixed(1) + '%';
cc.find('itemlei/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_THUNDER] == null ? 0 : this.dpoint[EAttrTypeL1.K_THUNDER]);
cc.find('itemshui/point/num', this.contentNode).getComponent(cc.Label).string = this.dshui.toFixed(1) + '%';
cc.find('itemshui/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_WATER] == null ? 0 : this.dpoint[EAttrTypeL1.K_WATER]);
cc.find('itemhuo/point/num', this.contentNode).getComponent(cc.Label).string = this.dhuo.toFixed(1) + '%';
cc.find('itemhuo/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_FIRE] == null ? 0 : this.dpoint[EAttrTypeL1.K_FIRE]);
cc.find('itemguihuo/point/num', this.contentNode).getComponent(cc.Label).string = this.dguihuo.toFixed(1) + '%';
cc.find('itemguihuo/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_WILDFIRE] == null ? 0 : this.dpoint[EAttrTypeL1.K_WILDFIRE]);
cc.find('itemsanshi/point/num', this.contentNode).getComponent(cc.Label).string = this.dsanshi.toFixed(1) + '%';
cc.find('itemsanshi/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_BLOODRETURN] == null ? 0 : this.dpoint[EAttrTypeL1.K_BLOODRETURN]);
cc.find('itemdushang/point/num', this.contentNode).getComponent(cc.Label).string = this.ddu.toFixed(1) + '%';
cc.find('itemdushang/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.K_POISON] == null ? 0 : this.dpoint[EAttrTypeL1.K_POISON]);
cc.find('itemwuli/point/num', this.contentNode).getComponent(cc.Label).string = this.pxishou.toFixed(1) + '%';
cc.find('itemwuli/point/add', this.contentNode).getComponent(cc.Label).string = (this.dpoint[EAttrTypeL1.PHY_GET] == null ? 0 : this.dpoint[EAttrTypeL1.PHY_GET]);
this.initKangBtn();
},
propertyAddPoint(d) {
if (this.leftpoint <= 0) {
return;
}
if (this.dpointT[d] == null) {
this.dpointT[d] = 0;
//this.dpoint[d] = 0;
}
this.dpointT[d]++;
this.dpoint[d]++;
this.calculateProperty();
},
propertySubPoint(d) {
if (this.dpointT[d] == null || this.dpointT[d] <= 0) {
return;
}
this.dpointT[d]--;
this.dpoint[d]--;
this.calculateProperty();
},
onClickedShowResetUI(){
this.panelReset.active = true;
},
onClickedCancelResetUI(){
this.panelReset.active = false;
},
porpertyReset() {
if (GameModel.player.gameData.money < GameUtil.resetXiulian) {
MsgAlert.addMsg(`銀兩不足,重置需要消耗${GameUtil.resetXiulian}銀兩!`);
return;
}
GameModel.send('c2s_xiulian_point', {
roleid: GameModel.player.roleid,
type: 0,
info: '{}'
});
this.panelReset.active = false;
},
porpertyCancel() {
this.dpoint = SKDataUtil.clone(this.dpointBase);
this.dpointT = {};
this.loadInfo();
},
porpertySure() {
for (const key in this.dpointT) {
if (SKDataUtil.hasProperty(this.dpointT,key)) {
const num = this.dpointT[key];
if(num < 0){
return;
}
}
}
GameModel.send('c2s_xiulian_point', {
roleid: GameModel.player.roleid,
type: 1,
info: JSON.stringify(this.dpointT)
});
},
onCloseBtnClicked() {
this.node.active = false;
},
});