350 lines
13 KiB
JavaScript
350 lines
13 KiB
JavaScript
|
import GameModel from "../ts/core/GameModel";
|
||
|
import {EAttrTypeL1} from "../ts/core/EEnum";
|
||
|
import GameUtil from "../ts/core/GameUtil";
|
||
|
import MsgAlert from "../ts/game/msg/MsgAlert";
|
||
|
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,
|
||
|
|
||
|
operateBtn: [cc.Node],
|
||
|
btnAdjust: cc.Button,
|
||
|
panelReset: cc.Node
|
||
|
},
|
||
|
|
||
|
onLoad() {
|
||
|
},
|
||
|
|
||
|
loadInfo(data) {
|
||
|
|
||
|
this.resetBtnStatus();
|
||
|
|
||
|
this.dpoint = data.content.defense.xiuPoint;
|
||
|
this.dpointBase = SKDataUtil.clone(this.dpoint);
|
||
|
this.attr1 = GameModel.player.gameData.attr1;
|
||
|
this.attr1T = SKDataUtil.clone(this.attr1);
|
||
|
this.xlevel = data.content.defense.xiuLevel;
|
||
|
this.xlevelT = this.xlevel;
|
||
|
|
||
|
this.schemeId = data.schemeId;
|
||
|
this.dpointT = {};
|
||
|
|
||
|
this.showOperBtn = false;
|
||
|
|
||
|
this.setPropertyInfo();
|
||
|
},
|
||
|
|
||
|
setPropertyInfo(){
|
||
|
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.calculateProperty();
|
||
|
this.showDInfo(false);
|
||
|
},
|
||
|
|
||
|
calculateProperty() {
|
||
|
//this.xiuNode.active = false;
|
||
|
//this.sureNode.active = true;
|
||
|
(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));
|
||
|
},
|
||
|
|
||
|
resetBtnStatus(){
|
||
|
this.sureNode.active = false;
|
||
|
this.btnAdjust.node.active = true;
|
||
|
for(var i = 0;i < this.operateBtn.length;i++){
|
||
|
this.operateBtn[i].active = false;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
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.showOperBtn){
|
||
|
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.xlevel;
|
||
|
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.xlevel <= 0) {
|
||
|
// return;
|
||
|
// }
|
||
|
// if (this.dpoint[d] == null) {
|
||
|
// this.dpoint[d] = 0;
|
||
|
// }
|
||
|
// this.dpoint[d]++;
|
||
|
// this.xlevel--;
|
||
|
// if (this.xlevel < 0) {
|
||
|
// this.xlevel = 0;
|
||
|
// }
|
||
|
// this.calculateProperty();
|
||
|
|
||
|
if (this.xlevel <= 0) {
|
||
|
return;
|
||
|
}
|
||
|
if (this.dpointT[d] == null) {
|
||
|
this.dpointT[d] = 0;
|
||
|
//this.dpoint[d] = 0;
|
||
|
}
|
||
|
this.dpointT[d]++;
|
||
|
this.dpoint[d]++;
|
||
|
this.xlevel--;
|
||
|
this.calculateProperty();
|
||
|
},
|
||
|
|
||
|
propertySubPoint(d) {
|
||
|
if (this.dpointT[d] == null || this.dpointT[d] <= 0) {
|
||
|
return;
|
||
|
}
|
||
|
this.xlevel++;
|
||
|
this.dpointT[d]--;
|
||
|
this.dpoint[d]--;
|
||
|
this.calculateProperty();
|
||
|
},
|
||
|
|
||
|
onClickedShowResetUI(e,d){
|
||
|
this.panelReset.active = true;
|
||
|
},
|
||
|
|
||
|
onClickedCancelResetUI(e,d){
|
||
|
this.panelReset.active = false;
|
||
|
},
|
||
|
|
||
|
onClickedPorpertyReset(e, d) {
|
||
|
if (GameModel.player.gameData.money < GameUtil.resetXiulian) {
|
||
|
MsgAlert.addMsg(`銀兩不足,重置需要消耗${GameUtil.resetXiulian}銀兩!`);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
GameModel.player.send('c2s_scheme_resetXiulianPoint', {
|
||
|
roleId: GameModel.player.roleid,
|
||
|
schemeId: this.schemeId
|
||
|
});
|
||
|
|
||
|
this.panelReset.active = false;
|
||
|
|
||
|
},
|
||
|
|
||
|
|
||
|
onResetXiuLianPoint(){
|
||
|
for(var key in this.dpoint){
|
||
|
if(SKDataUtil.hasProperty(this.dpoint,key)){
|
||
|
this.xlevel += this.dpoint[key];
|
||
|
this.dpoint[key] = 0;
|
||
|
}
|
||
|
}
|
||
|
this.xlevelT = this.xlevel;
|
||
|
this.dpointT = {};
|
||
|
this.dpointBase = SKDataUtil.clone(this.dpoint);
|
||
|
this.showDInfo();
|
||
|
},
|
||
|
|
||
|
|
||
|
porpertySure(e, d) {
|
||
|
for (const key in this.dpoint) {
|
||
|
if (SKDataUtil.hasProperty(this.dpoint,key)) {
|
||
|
const num = this.dpoint[key];
|
||
|
if(num < 0){
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
GameModel.send('c2s_scheme_addXiulianPoint', {
|
||
|
roleId: GameModel.player.roleid,
|
||
|
xiulianPoint: JSON.stringify(this.dpoint),
|
||
|
xiulevel: this.xlevel,
|
||
|
schemeId: this.schemeId
|
||
|
});
|
||
|
this.dpointT = {};
|
||
|
this.dpointBase = SKDataUtil.clone(this.dpoint);
|
||
|
this.xlevelT = this.xlevel;
|
||
|
this.showOperBtn = false;
|
||
|
this.sureNode.active = false;
|
||
|
this.btnAdjust.node.active = true;
|
||
|
for(var i = 0;i < this.operateBtn.length;i++){
|
||
|
this.operateBtn[i].active = false;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
onBtnCancelClicked(e,d) {
|
||
|
for(var i = 0;i < this.operateBtn.length;i++){
|
||
|
this.operateBtn[i].active = false;
|
||
|
}
|
||
|
|
||
|
this.xiuNode.active = true;
|
||
|
this.dpoint = SKDataUtil.clone(this.dpointBase);
|
||
|
this.dpointT = {};
|
||
|
this.xlevel = this.xlevelT;
|
||
|
|
||
|
this.showOperBtn = false;
|
||
|
|
||
|
this.setPropertyInfo();
|
||
|
|
||
|
this.sureNode.active = false;
|
||
|
|
||
|
this.btnAdjust.node.active = true;
|
||
|
|
||
|
},
|
||
|
|
||
|
onBtnAdjustClicked(e, d) {
|
||
|
for(var i = 0;i < this.operateBtn.length;i++){
|
||
|
this.operateBtn[i].active = true;
|
||
|
}
|
||
|
|
||
|
|
||
|
this.btnAdjust.node.active = false;
|
||
|
this.sureNode.active = true;
|
||
|
this.showOperBtn = true;
|
||
|
this.setPropertyInfo();
|
||
|
|
||
|
},
|
||
|
});
|