266 lines
9.4 KiB
JavaScript
266 lines
9.4 KiB
JavaScript
|
import GameModel from "../ts/core/GameModel";
|
||
|
import { EAttrTypeL1, EAttrTypeL2, LongPressSpeedAttr } from "../ts/core/EEnum";
|
||
|
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
|
||
|
|
||
|
let roleTitleUtil = require('../utils/RoleTitlesUtil');
|
||
|
|
||
|
cc.Class({
|
||
|
extends: cc.Component,
|
||
|
|
||
|
properties: {
|
||
|
propertyNode: cc.Node,
|
||
|
addPointNode: cc.Node,
|
||
|
bangName: cc.Label,
|
||
|
|
||
|
SetRoleTitleUI: cc.Prefab,
|
||
|
BangPanel: cc.Prefab,
|
||
|
},
|
||
|
|
||
|
onLoad() {
|
||
|
this.attr1 = {};
|
||
|
this.addpoint = {};
|
||
|
this.addpointT = {};
|
||
|
this.qianneng = 0;
|
||
|
this.hp = 0;
|
||
|
this.mp = 0;
|
||
|
this.maxhp = 1;
|
||
|
this.maxmp = 1;
|
||
|
this.atk = 0;
|
||
|
this.spd = 0;
|
||
|
this.exp = 0;
|
||
|
this.maxexp = 1;
|
||
|
this.loadGameData();
|
||
|
this.currentBtn = null;
|
||
|
this.timecnt = 0;
|
||
|
this.maxtiemcnt = 30;
|
||
|
this.addOrSubNumber = 1;
|
||
|
this.canSendAddPropert = true;
|
||
|
|
||
|
},
|
||
|
|
||
|
loadGameData() {
|
||
|
this.addpoint = SKDataUtil.clone(GameModel.player.gameData.addattr2);
|
||
|
this.attr1 = GameModel.player.gameData.attr1;
|
||
|
for (let key in EAttrTypeL1) {
|
||
|
let value = SKDataUtil.toNumber(key);
|
||
|
if (isNaN(value)) {
|
||
|
continue;
|
||
|
}
|
||
|
this.addpointT[value] = 0;
|
||
|
}
|
||
|
this.qianneng = GameModel.player.gameData.qianneng;
|
||
|
this.showInfo();
|
||
|
this.canSendAddPropert = true
|
||
|
},
|
||
|
|
||
|
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) {
|
||
|
this.addOrSubNumber = LongPressSpeedAttr.OPERAINITNUM;
|
||
|
if (e.type == cc.Node.EventType.TOUCH_START) {
|
||
|
this.maxtiemcnt = LongPressSpeedAttr.MAXTIMECNT;
|
||
|
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 += LongPressSpeedAttr.TIMECNTADD;
|
||
|
if (this.timecnt >= this.maxtiemcnt) {
|
||
|
if (this.maxtiemcnt > LongPressSpeedAttr.MINTIMECNT) {
|
||
|
this.maxtiemcnt -= LongPressSpeedAttr.TIMECNTSUB;
|
||
|
this.maxtiemcnt = Math.max(LongPressSpeedAttr.MINTIMECNT, this.maxtiemcnt)
|
||
|
}
|
||
|
this.timecnt = 0;
|
||
|
if (this.currentBtn.opertype == 0) {
|
||
|
this.propertyAddPoint(this.currentBtn.datainfo);
|
||
|
}
|
||
|
else if (this.currentBtn.opertype == 1) {
|
||
|
this.propertySubPoint(this.currentBtn.datainfo);
|
||
|
}
|
||
|
this.addOrSubNumber += LongPressSpeedAttr.OPERADDNUM;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
showInfo() {
|
||
|
console.log("attr1",this.attr1)
|
||
|
let HP = SKDataUtil.valueForKey(this.attr1, EAttrTypeL1.HP);
|
||
|
if (HP == null) {
|
||
|
HP = `?`;
|
||
|
}
|
||
|
let HP_MAX = SKDataUtil.valueForKey(this.attr1, EAttrTypeL1.HP_MAX);
|
||
|
if (HP_MAX == null) {
|
||
|
HP_MAX = `?`;
|
||
|
}
|
||
|
let BONE = SKDataUtil.valueForKey(this.attr1, EAttrTypeL2.BONE);
|
||
|
if (BONE == null) {
|
||
|
BONE = `?`;
|
||
|
}
|
||
|
let MP = SKDataUtil.valueForKey(this.attr1, EAttrTypeL1.MP);
|
||
|
if (MP == null) {
|
||
|
MP = `?`;
|
||
|
}
|
||
|
let MP_MAX = SKDataUtil.valueForKey(this.attr1, EAttrTypeL1.MP_MAX);
|
||
|
if (MP_MAX == null) {
|
||
|
MP_MAX = `?`;
|
||
|
}
|
||
|
let SPIRIT = SKDataUtil.valueForKey(this.attr1, EAttrTypeL2.SPIRIT);
|
||
|
if (SPIRIT == null) {
|
||
|
SPIRIT = `?`;
|
||
|
}
|
||
|
let ATK = SKDataUtil.valueForKey(this.attr1, EAttrTypeL1.ATK);
|
||
|
if (ATK == null) {
|
||
|
ATK = `?`;
|
||
|
}
|
||
|
let STRENGTH = SKDataUtil.valueForKey(this.attr1, EAttrTypeL2.STRENGTH);
|
||
|
if (STRENGTH == null) {
|
||
|
STRENGTH = `?`;
|
||
|
}
|
||
|
let SPD = SKDataUtil.valueForKey(this.attr1, EAttrTypeL1.SPD);
|
||
|
if (SPD == null) {
|
||
|
SPD = `?`;
|
||
|
}
|
||
|
let DEXTERITY = SKDataUtil.valueForKey(this.attr1, EAttrTypeL2.DEXTERITY);
|
||
|
if (DEXTERITY == null) {
|
||
|
DEXTERITY = `?`;
|
||
|
}
|
||
|
cc.find('jyProgress', this.propertyNode).getComponent(cc.ProgressBar).progress = GameModel.player.gameData.exp / GameModel.player.gameData.maxexp;
|
||
|
cc.find('jyProgress/progress', this.propertyNode).getComponent(cc.Label).string = `${GameModel.player.gameData.exp}/${GameModel.player.gameData.maxexp}`;
|
||
|
cc.find('blood/blood', this.propertyNode).getComponent(cc.Label).string = `${HP}/${HP_MAX}`;
|
||
|
cc.find('blood/gengu', this.propertyNode).getComponent(cc.Label).string = `${BONE}`;
|
||
|
cc.find('blood/genguadd', this.propertyNode).getComponent(cc.Label).string = `(${GameModel.player.gameData.level}+${GameModel.player.gameData.addattr2[EAttrTypeL2.BONE]})`;
|
||
|
cc.find('skill/skill', this.propertyNode).getComponent(cc.Label).string = `${MP}/${MP_MAX}`;
|
||
|
cc.find('skill/lingxing', this.propertyNode).getComponent(cc.Label).string = `${SPIRIT}`;
|
||
|
cc.find('skill/lingxingadd', this.propertyNode).getComponent(cc.Label).string = `(${GameModel.player.gameData.level}+${GameModel.player.gameData.addattr2[EAttrTypeL2.SPIRIT]})`;
|
||
|
cc.find('attack/attack', this.propertyNode).getComponent(cc.Label).string = `${ATK}`;
|
||
|
cc.find('attack/liliang', this.propertyNode).getComponent(cc.Label).string = `${STRENGTH}`;
|
||
|
cc.find('attack/liliangadd', this.propertyNode).getComponent(cc.Label).string = `(${GameModel.player.gameData.level}+${GameModel.player.gameData.addattr2[EAttrTypeL2.STRENGTH]})`;
|
||
|
cc.find('speed/speed', this.propertyNode).getComponent(cc.Label).string = `${SPD}`;
|
||
|
cc.find('speed/minjie', this.propertyNode).getComponent(cc.Label).string = `${DEXTERITY}`;
|
||
|
cc.find('speed/minjieadd', this.propertyNode).getComponent(cc.Label).string = `(${GameModel.player.gameData.level}+${GameModel.player.gameData.addattr2[EAttrTypeL2.DEXTERITY]})`;
|
||
|
cc.find('qianneng/qianneng', this.propertyNode).getComponent(cc.Label).string = GameModel.player.gameData.qianneng;
|
||
|
let roleTitleInfo = roleTitleUtil.getRoleTitle(GameModel.player.titleid, GameModel.player.titleval, GameModel.player.bangname);
|
||
|
if (roleTitleInfo) {
|
||
|
cc.find('chengweiLab', this.propertyNode).getComponent(cc.Label).string = roleTitleInfo.name;
|
||
|
}
|
||
|
cc.find('QixueNode/qixue', this.addPointNode).getComponent(cc.Label).string = `${HP}/${HP_MAX}`;
|
||
|
cc.find('QixueNode/point/point', this.addPointNode).getComponent(cc.Label).string = this.addpoint[EAttrTypeL2.BONE];
|
||
|
cc.find('FaliNode/fali', this.addPointNode).getComponent(cc.Label).string = `${MP}/${MP_MAX}`;
|
||
|
cc.find('FaliNode/point/point', this.addPointNode).getComponent(cc.Label).string = this.addpoint[EAttrTypeL2.SPIRIT];
|
||
|
cc.find('GongjiNode/atk', this.addPointNode).getComponent(cc.Label).string = `${ATK}`;
|
||
|
cc.find('GongjiNode/point/point', this.addPointNode).getComponent(cc.Label).string = this.addpoint[EAttrTypeL2.STRENGTH];
|
||
|
cc.find('SuduNode/spd', this.addPointNode).getComponent(cc.Label).string = `${SPD}`;
|
||
|
cc.find('SuduNode/point/point', this.addPointNode).getComponent(cc.Label).string = this.addpoint[EAttrTypeL2.DEXTERITY];
|
||
|
|
||
|
this.initBtn(cc.find('FaliNode/point/addBtn', this.addPointNode), 101, 0);
|
||
|
this.initBtn(cc.find('FaliNode/point/subBtn', this.addPointNode), 101, 1);
|
||
|
this.initBtn(cc.find('GongjiNode/point/addBtn', this.addPointNode), 102, 0);
|
||
|
this.initBtn(cc.find('GongjiNode/point/subBtn', this.addPointNode), 102, 1);
|
||
|
this.initBtn(cc.find('QixueNode/point/addBtn', this.addPointNode), 100, 0);
|
||
|
this.initBtn(cc.find('QixueNode/point/subBtn', this.addPointNode), 100, 1);
|
||
|
this.initBtn(cc.find('SuduNode/point/addBtn', this.addPointNode), 103, 0);
|
||
|
this.initBtn(cc.find('SuduNode/point/subBtn', this.addPointNode), 103, 1);
|
||
|
|
||
|
cc.find('qianNeng/qianneng', this.addPointNode).getComponent(cc.Label).string = this.qianneng;
|
||
|
this.initPropertBtn();
|
||
|
if (GameModel.player.bangid > 0 && GameModel.player.bangname != null) {
|
||
|
this.bangName.string = GameModel.player.bangname;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
initPropertBtn() {
|
||
|
this.setPropertBtnInfo('QixueNode', EAttrTypeL1.BONE);
|
||
|
this.setPropertBtnInfo('FaliNode', EAttrTypeL1.SPIRIT);
|
||
|
this.setPropertBtnInfo('GongjiNode', EAttrTypeL1.STRENGTH);
|
||
|
this.setPropertBtnInfo('SuduNode', EAttrTypeL1.DEXTERITY);
|
||
|
},
|
||
|
|
||
|
setPropertBtnInfo(name, type) {
|
||
|
if (this.qianneng <= 0) {
|
||
|
cc.find(`${name}/point/addBtn`, this.addPointNode).active = false;
|
||
|
} else {
|
||
|
cc.find(`${name}/point/addBtn`, this.addPointNode).active = true;
|
||
|
}
|
||
|
if (this.addpointT[type] > 0) {
|
||
|
cc.find(`${name}/point/subBtn`, this.addPointNode).active = true;
|
||
|
} else {
|
||
|
cc.find(`${name}/point/subBtn`, this.addPointNode).active = false;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
addPointBtnClicked(e, d) {
|
||
|
this.propertyNode.active = false;
|
||
|
this.addPointNode.active = true;
|
||
|
},
|
||
|
|
||
|
backBtnClicked(e, d) {
|
||
|
this.propertyNode.active = true;
|
||
|
this.addPointNode.active = false;
|
||
|
},
|
||
|
|
||
|
|
||
|
//顯示用戶稱謂設置界面
|
||
|
onRoleTitleClicked(e, d) {
|
||
|
let roleTitlePanel = cc.instantiate(this.SetRoleTitleUI);
|
||
|
roleTitlePanel.name = "SetRoleTitlePanel";
|
||
|
roleTitlePanel.parent = cc.find('Canvas');
|
||
|
},
|
||
|
|
||
|
|
||
|
propertyAddPoint(d) {
|
||
|
if (this.qianneng <= 0) {
|
||
|
this.currentBtn = null;
|
||
|
return;
|
||
|
}
|
||
|
var addNum = parseInt(this.addOrSubNumber)
|
||
|
addNum = addNum > this.qianneng ? this.qianneng : addNum;
|
||
|
this.addpoint[d] += addNum;
|
||
|
this.addpointT[d] += addNum;
|
||
|
this.qianneng -= addNum;
|
||
|
this.showInfo();
|
||
|
},
|
||
|
|
||
|
propertySubPoint(d) {
|
||
|
if (this.addpointT[d] <= 0) {
|
||
|
this.currentBtn = null;
|
||
|
return;
|
||
|
}
|
||
|
var addNum = parseInt(this.addOrSubNumber)
|
||
|
addNum = addNum > this.addpointT[d] ? this.addpointT[d] : addNum;
|
||
|
this.addpoint[d] -= addNum;
|
||
|
this.addpointT[d] -= addNum;
|
||
|
this.qianneng += addNum;
|
||
|
|
||
|
this.showInfo();
|
||
|
},
|
||
|
|
||
|
porpertySure(e, d) {
|
||
|
this.canSendAddPropert = false
|
||
|
GameModel.send('c2s_player_addpoint', {
|
||
|
roleid: GameModel.player.roleid,
|
||
|
addattr: JSON.stringify(this.addpointT)
|
||
|
});
|
||
|
},
|
||
|
|
||
|
|
||
|
bangBtnClicked(e, d) {
|
||
|
// let bang = cc.instantiate(this.BangPanel);
|
||
|
// bang.parent = cc.find('Canvas');
|
||
|
},
|
||
|
});
|