SamsaraGame/assets/Script/panel/PalaceFightIcon.js

131 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

2025-04-24 17:03:28 +08:00
import GameModel from "../ts/core/GameModel";
import GameUtil from "../ts/core/GameUtil";
cc.Class({
extends: cc.Component,
properties: {
pfpanel: cc.Prefab,
},
onLoad () {
this.pfdata = null;
},
start () {
this.node.active = false;
},
showPalaceFightIcon () {
this.node.getComponent(cc.Animation).play('huangchengPK');
this.node.active = true;
},
unshowPalaceFightIcon () {
this.node.getComponent(cc.Animation).stop('huangchengPK');
this.node.active = false;
},
clickPalaceFightIcon () {
let npcdata = GameModel.conf_npc['30060'];
let posmsg = npcdata.auto_create.split(';');
GameUtil.myPlayerToDo(posmsg[0], parseInt(posmsg[1])-3, parseInt(posmsg[2])+3, () => { });
},
syncPalaceFightData (data) {
cc.log('syncPalaceFightData', data);
this.pfdata = data;
/* 有人拒絕決鬥 */
if ((data.recipient.state == 2 || data.sponsor.state == 2) && (data.recipient.roleid == GameModel.player.roleid || data.sponsor.roleid == GameModel.player.roleid)) {
this.unshowPalaceFightIcon();
this.deletePalaceFightPanel();
return;
}
/* 決鬥開始 */
if (data.recipient.state == 1 && data.sponsor.state == 1) {
this.unshowPalaceFightIcon();
let palaceFightPanel = cc.find('Canvas/MainUI/PalaceFightPanel');
if (palaceFightPanel) {
palaceFightPanel.getComponent('PalaceFightPanel').setTm(Math.floor(data.tm/1000));
}
else if (this.canShowPalaceFightPanel()) {
GameModel.send('c2s_palace_rolelist', {
roleid: GameModel.player.roleid,
});
}
// this.pfdata = null;
return;
}
if (data.sponsor.state == 1 && data.recipient.state == 0) { // 發起決鬥
if (GameModel.player.roleid == data.sponsor.roleid) {
let pkpanel = cc.find('Canvas/MainUI/PKPanel');
if (pkpanel) {
pkpanel.destroy();
}
}
this.showPalaceFightIcon();
}
},
deletePalaceFightPanel () {
this.pfdata = null;
let pfpanel = cc.find('Canvas/MainUI/PalaceFightPanel');
if (pfpanel) {
pfpanel.destroy();
}
},
hasPalaceFight () {
return (this.pfdata && this.pfdata.recipient.roleid == GameModel.player.roleid);
},
/*
* 能否顯示palaceFightPanel界面
*/
canShowPalaceFightPanel () {
let canshow = (this.pfdata.sponsor.roleid == GameModel.player.roleid || this.pfdata.recipient.roleid == GameModel.player.roleid);
canshow = canshow && (GameModel.player.mapid == 1206 && !GameModel.player.getMainUILogic().isBattle);
if (this.pfdata.sponsor.roleid == GameModel.player.roleid) {
canshow = canshow && (this.pfdata.recipient.state == 1);
}
return canshow;
},
getCurTm () {
if (this.pfdata) {
return Math.floor(this.pfdata.tm/1000);
}
return 0;
},
getIsAllPrepare () {
if (this.pfdata) {
return (this.pfdata.sponsor.state == 1 && this.pfdata.recipient.state == 1);
}
return false;
},
isSponsor () {
return (this.pfdata && this.pfdata.sponsor.roleid == GameModel.player.roleid);
},
/*
* 能否關閉palaceFightPanel界面
*/
canClosePalaceFight () {
if (this.pfdata) {
return (this.pfdata.recipient.state == 0);
}
return true;
},
update (dt) {
if (this.pfdata) {
this.pfdata.tm -= dt*1000;
if (this.pfdata.tm < 0) {
this.pfdata = null;
}
}
},
});