483 lines
19 KiB
JavaScript
483 lines
19 KiB
JavaScript
import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil";
|
||
import GameModel from "../ts/core/GameModel";
|
||
import MsgAlert from "../ts/game/msg/MsgAlert";
|
||
import Arena from "../ts/arena/Arena";
|
||
import DebateDao from "../ts/debateDao/DebateDao";
|
||
import FGAlert from "../ts/gear_2.3.4/fgui/FGAlert";
|
||
import visitingPrison from "../ts/visitingPrison";
|
||
import GameUtil from "../ts/core/GameUtil";
|
||
import GuoShop from "../ts/GuoShop";
|
||
import DrawMoney from "../ts/drawMoney";
|
||
import AudioUtil from "../ts/core/AudioUtil";
|
||
|
||
let CPubFunction = require('./PubFunction');
|
||
let pNpcMgr = require('./NpcMgr');
|
||
let CMainPlayerInfo = require('./MainPlayerInfo');
|
||
|
||
cc.Class({
|
||
extends: cc.Component,
|
||
properties: {
|
||
btnNpcFunction: cc.Prefab,
|
||
XianQiUpPanel: cc.Prefab,
|
||
ShenBingUpPanel: cc.Prefab,
|
||
ShenBingCombinePanel: cc.Prefab,
|
||
RelationInputUI: cc.Prefab,
|
||
RelationListUI: cc.Prefab,
|
||
NpcShopUI: cc.Prefab,
|
||
PKPanel: cc.Prefab,
|
||
ColoringRolePanel: cc.Prefab,
|
||
PetFlyPanel: cc.Prefab,
|
||
fontRes: cc.Font
|
||
},
|
||
|
||
|
||
onLoad() {
|
||
this.nOnlyID = 0;
|
||
this.nResID = 0;
|
||
},
|
||
|
||
NpcFunUI_Init(nOnlyID, nConfigID, strName, strDefaultTalk, mapBtnFunction, mapTaskBtn) {
|
||
this.nOnlyID = nOnlyID;
|
||
this.nConfigID = nConfigID;
|
||
AudioUtil.playNpcAudio(this.nConfigID);
|
||
|
||
let stConfigInfo = pNpcMgr.GetNpcConfigInfo(nConfigID);
|
||
cc.find('btnClose', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "NpcFunUI", "Close", 0));
|
||
//形象
|
||
let resid = stConfigInfo.nResID;
|
||
if (resid <= 4038 || resid == 6024 || resid == 6006 || resid == 6026 || resid == 6027 || resid == 6025 || resid == 6029 || resid == 6034 || resid == 6080 || resid == 5054 || resid == 6089 || resid == 6030 || resid == 6081 || resid == 6035 || resid == 6061 || resid == 6078 || resid == 6011 || resid == 6140 || resid == 6141 || resid == 6142) {
|
||
CPubFunction.SetSpineAvatars(cc.find('nodNpc/goSpeaker1', this.node), cc.find('nodNpc/picAvatar', this.node), stConfigInfo.nResID);
|
||
} else {
|
||
CPubFunction.SetDragonBoneAvatars(cc.find('nodNpc/goSpeaker', this.node), cc.find('nodNpc/picAvatar', this.node), stConfigInfo.nResID);
|
||
}
|
||
//CPubFunction.SetDragonBoneAvatar(cc.find('nodNpc/goSpeaker', this.node), cc.find('nodNpc/picAvatar', this.node), stConfigInfo.nResID);
|
||
|
||
cc.find('nodNpc/picName/label', this.node).getComponent(cc.Label).string = strName;
|
||
|
||
//語言框
|
||
let nodContentTalk = cc.find('nodCustomRichText/view/content', this.node);
|
||
let comCusRichText = nodContentTalk.getComponent('CustomRichText');
|
||
comCusRichText.maxWidth = nodContentTalk.width - 6;
|
||
comCusRichText.fontRes = this.fontRes;
|
||
comCusRichText.emojiAtlas = GameModel.chatEmojiAtlas;
|
||
comCusRichText.string = CPubFunction.GetDefault(strDefaultTalk, '');
|
||
|
||
//按鈕框
|
||
let preButton = this.btnNpcFunction;
|
||
let nodContent2 = cc.find('ScrollView/view/content', this.node);
|
||
|
||
let nBtnHight = preButton.data.height;
|
||
let nDis = 2;
|
||
let nIndex = -1;
|
||
|
||
let stStart = { nX: 145, nY: -30 };
|
||
for (let key in mapTaskBtn) {
|
||
nIndex++;
|
||
let goBtn = SKUIUtil.createSubNode(nodContent2, cc.v2(stStart.nX, stStart.nY - nIndex * (nBtnHight + nDis)), preButton, 'Task');
|
||
goBtn.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "NpcFunUI", 'OnNpcFunction', { strTaskName: key, stData: mapTaskBtn[key] }));
|
||
cc.find('Label', goBtn).getComponent(cc.Label).string = key;
|
||
let goTaskTip = cc.find('TaskTip', cc.find('Canvas/MainUI/right'));
|
||
let comTaskTip = goTaskTip.getComponent('TaskTip');
|
||
if (comTaskTip.stAuto.nTaskID == mapTaskBtn[key].nTaskID) {
|
||
this.OnNpcFunction(goBtn.getComponent(cc.Button), { strTaskName: key, stData: mapTaskBtn[key] });
|
||
}
|
||
}
|
||
for (let key in mapBtnFunction) {
|
||
if (key.indexOf('daily') != -1) {
|
||
let vecTmp = key.split(":");
|
||
if (CMainPlayerInfo.IsAlreadyHasThisGropTask(vecTmp[1]))
|
||
continue;
|
||
}
|
||
nIndex++;
|
||
let goBtn = SKUIUtil.createSubNode(nodContent2, cc.v2(stStart.nX, stStart.nY - nIndex * (nBtnHight + nDis)), preButton, key);
|
||
goBtn.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "NpcFunUI", 'OnNpcFunction', key));
|
||
cc.find('Label', goBtn).getComponent(cc.Label).string = mapBtnFunction[key];
|
||
}
|
||
nodContent2.height = Math.max(nodContent2.height, (nIndex + 1) * (nBtnHight + nDis) + 40);
|
||
},
|
||
|
||
|
||
Close() {
|
||
this.node.destroy();
|
||
},
|
||
|
||
OnNpcFunction(stEvent, stParam) {
|
||
let strTmp = stEvent.target.name;
|
||
if (strTmp == 'Task') {
|
||
let nTaskID = stParam.stData.nTaskID;
|
||
let nStep = stParam.stData.nStep;
|
||
let pSelf = this;
|
||
let vecSpeak = stParam.stData.vecTmp;
|
||
CPubFunction.CreateNpcTalk(vecSpeak, () => {
|
||
GameModel.send('c2s_task_talk_npc', { nTaskID: nTaskID, nStep: nStep, nNpcConfigID: pSelf.nConfigID, nNpcOnlyID: pSelf.nOnlyID });
|
||
});
|
||
}
|
||
else if (strTmp == 'Box') {
|
||
strTmp;
|
||
}
|
||
else if (strTmp == 'Teacher') {
|
||
strTmp;
|
||
}
|
||
else if (strTmp == 'Team') {
|
||
strTmp;
|
||
}
|
||
else if (strTmp == 'bpjyr_bang') { //回到幫派
|
||
let comMapLogic = cc.find('Canvas/MapUI').getComponent('GameMapLogic');
|
||
comMapLogic.changeMap(3002);
|
||
}
|
||
else if (strTmp.indexOf('daily') != -1) {
|
||
let vecTmp = strTmp.split(":");
|
||
if (vecTmp.length != 2)
|
||
return;
|
||
|
||
let nTaskGrop = vecTmp[1];
|
||
GameModel.send('c2s_start_grop_task', { nNpcOnlyID: this.nOnlyID, nTaskGrop: nTaskGrop });
|
||
}
|
||
else if (strTmp.indexOf('fuben') != -1) {
|
||
let vecTmp = strTmp.split(":");
|
||
if (vecTmp.length != 2)
|
||
return;
|
||
|
||
GameModel.send('c2s_incept_fuben_task', { nNpcOnlyID: this.nOnlyID, nTaskID: vecTmp[1] });
|
||
}
|
||
// 挑戰
|
||
else if (strTmp == 'tiaozhan') {
|
||
GameModel.send('c2s_challenge_npc', { nOnlyID: this.nOnlyID, nConfigID: this.nConfigID });
|
||
}
|
||
else if (strTmp == 'hdl_xqhc') {
|
||
let xqhc = cc.instantiate(this.XianQiUpPanel);
|
||
xqhc.parent = cc.find('Canvas');
|
||
}
|
||
else if (strTmp == 'hdl_xqsj') {
|
||
let xqsj = cc.instantiate(this.XianQiUpPanel);
|
||
xqsj.parent = cc.find('Canvas');
|
||
}
|
||
else if (strTmp == 'hdl_sbsj') {
|
||
let sbsj = cc.instantiate(this.ShenBingUpPanel);
|
||
sbsj.parent = cc.find('Canvas');
|
||
}
|
||
else if (strTmp == 'hdl_sbhc') {
|
||
let sbhc = cc.instantiate(this.ShenBingCombinePanel);
|
||
sbhc.parent = cc.find('Canvas');
|
||
}
|
||
else if (strTmp == 'shop') {
|
||
let goUI = SKUIUtil.createSubNode(cc.find('Canvas/MainUI'), cc.v2(0, 0), this.NpcShopUI, 'NpcShopUI');
|
||
let comUI = goUI.getComponent('NpcShopUI');
|
||
comUI.nNpcConfigID = this.nConfigID;
|
||
}
|
||
else if (strTmp == 'taskreset') {
|
||
GameModel.send('c2s_task_reset', {});
|
||
}
|
||
else if (strTmp == 'changerace') { //換種族
|
||
cc.loader.loadRes("Prefabs/LoginCreateRole", function (err, prefab) {
|
||
let mainui = cc.find('Canvas');
|
||
let relive = cc.instantiate(prefab);
|
||
relive.parent = mainui;
|
||
relive.name = 'changeracelayer';
|
||
let logic = relive.getComponent('LoginCreateLogic');
|
||
logic.setOpenType(2);
|
||
});
|
||
}
|
||
// 轉生
|
||
else if (strTmp == 'zhuansheng') {
|
||
let strErr = '';
|
||
let vecNeed = [100, 120, 140];
|
||
let level = GameModel.player.level;
|
||
let relive = GameModel.player.relive;
|
||
if (relive >= 3) {
|
||
strErr = `無法再轉生了`;
|
||
}
|
||
else if (level < vecNeed[relive]) {
|
||
strErr = `你的等級不夠,需達到${vecNeed[relive]}級才能轉生`;
|
||
}
|
||
if (strErr.length < 1) {
|
||
cc.loader.loadRes("Prefabs/LoginCreateRole", function (err, prefab) {
|
||
let mainui = cc.find('Canvas');
|
||
let relive = cc.instantiate(prefab);
|
||
relive.parent = mainui;
|
||
relive.name = 'relivelayer';
|
||
let logic = relive.getComponent('LoginCreateLogic');
|
||
logic.setOpenType(1);
|
||
});
|
||
}
|
||
}
|
||
// 飛升
|
||
else if (strTmp == 'fly_up') {
|
||
let strErr = '';
|
||
let level = GameModel.player.level;
|
||
let relive = GameModel.player.relive;
|
||
if (relive > 3) {
|
||
strErr = `您已經飛升成功!`;
|
||
}
|
||
if (relive != 3) {
|
||
strErr = `您需要三轉才能飛升`;
|
||
}
|
||
else if (level < 180) {
|
||
strErr = `您的等級不夠,需達到180級才能飛升`;
|
||
}
|
||
if (strErr.length < 1) {
|
||
GameModel.send('c2s_fly_up', {});
|
||
}
|
||
else {
|
||
CPubFunction.CreateNpcNotice(10094, strErr);
|
||
}
|
||
}
|
||
// 傳送到指定地圖
|
||
else if (strTmp.indexOf('goto') != -1) {
|
||
let vecTmp = strTmp.split(":");
|
||
if (vecTmp.length != 2) {
|
||
return;
|
||
}
|
||
let mapId = parseInt(vecTmp[1]);
|
||
let comMapLogic = cc.find('Canvas/MapUI').getComponent('GameMapLogic');
|
||
comMapLogic.changeMap(mapId);
|
||
}
|
||
// 探監
|
||
else if (strTmp == 'tanjian') {
|
||
let comMapLogic = cc.find('Canvas/MapUI').getComponent('GameMapLogic');
|
||
comMapLogic.changeMap(1201);
|
||
}
|
||
// 傳送至長安
|
||
else if (strTmp == 'join_leave') {
|
||
let comMapLogic = cc.find('Canvas/MapUI').getComponent('GameMapLogic');
|
||
comMapLogic.changeMap(1011);
|
||
}
|
||
// 水陸大會報名
|
||
else if (strTmp == 'sldh') {
|
||
GameModel.send('c2s_shuilu_sign');
|
||
}
|
||
else if (strTmp == 'linghou') {
|
||
GameModel.send('c2s_linghou_fight', {
|
||
mid: this.nOnlyID,
|
||
});
|
||
}
|
||
// "mapButton": "{ \"planwar\":\"幫我寫戰書\", \"receivewar\":\"我要接受對方的挑戰\", \"warrank\":\"決鬥榜\", \"close\":\"打架是不好的行為\" }",
|
||
else if (strTmp == 'planwar') {
|
||
SKUIUtil.createSubNode(cc.find('Canvas/MainUI'), cc.v2(0, 0), this.PKPanel, 'PKPanel');
|
||
}
|
||
else if (strTmp == 'receivewar') {
|
||
let palaceFightIcon = cc.find('Canvas/MainUI/PalaceFightIcon');
|
||
let logic = palaceFightIcon.getComponent('PalaceFightIcon');
|
||
if (logic.hasPalaceFight()) {
|
||
GameModel.send('c2s_palace_rolelist', {
|
||
roleid: GameModel.player.roleid,
|
||
});
|
||
}
|
||
else {
|
||
MsgAlert.addMsg('你沒有被其他人邀請皇城決鬥!');
|
||
}
|
||
|
||
/* if (!palaceFightIcon.active) {
|
||
MsgAlert.addMsg('你沒有要進行的決鬥!');
|
||
}
|
||
else {
|
||
palaceFightIcon.getComponent('PalaceFightIcon').showPalaceFightPanel();
|
||
} */
|
||
}
|
||
else if (strTmp == 'warrank') {
|
||
MsgAlert.addMsg('暫未開放!');
|
||
}
|
||
else if (strTmp == "arena") {
|
||
//GameModel.send("c2s_start_grop_task", { nNpcOnlyID: 10240, nTaskGrop: "16" })
|
||
Arena.Instance.openArenaPanel();
|
||
}
|
||
else if (strTmp == "visitingPrison") {
|
||
visitingPrison.Instance.openVisitingPrisonPanel();
|
||
}
|
||
//我要結拜
|
||
else if (strTmp == 'newBrother') {
|
||
if (!GameModel.player.teamInfo.objlist || !Array.isArray(GameModel.player.teamInfo.objlist)) {
|
||
MsgAlert.addMsg("必須先組隊才能結拜");
|
||
return false;
|
||
}
|
||
SKUIUtil.createSubNode(cc.find('Canvas/MainUI'), cc.v2(0, 0), this.RelationInputUI, 'RelationInputUI');
|
||
}
|
||
//新人加入結拜
|
||
else if (strTmp == 'addBrother') {
|
||
CPubFunction.CreateSubNodeByType(cc.find('Canvas/MainUI'), { nX: 0, nY: 0 }, this.RelationListUI, 'RelationListUI', 1);
|
||
}
|
||
//退出結拜
|
||
else if (strTmp == 'leaveBrother') {
|
||
CPubFunction.CreateSubNodeByType(cc.find('Canvas/MainUI'), { nX: 0, nY: 0 }, this.RelationListUI, 'RelationListUI', 2);
|
||
}
|
||
else if (strTmp == 'rolecolor') { // 染色
|
||
let panel = cc.instantiate(this.ColoringRolePanel);
|
||
panel.parent = cc.find('Canvas/MainUI');
|
||
panel.setPosition(0, 0);
|
||
}
|
||
else if (strTmp == 'flyingup') { // 寵物飛升
|
||
let panel = cc.instantiate(this.PetFlyPanel);
|
||
panel.parent = cc.find('Canvas/MainUI');
|
||
}
|
||
// 證道大會
|
||
else if (strTmp == 'join_say') {
|
||
if (!GameModel.player.teamInfo.objlist || !Array.isArray(GameModel.player.teamInfo.objlist)) {
|
||
MsgAlert.addMsg("必須先組隊才可以參加哦!");
|
||
return false;
|
||
}
|
||
GameModel.send('c2s_join_say', {
|
||
roleId: GameModel.player.roleid,
|
||
});
|
||
}
|
||
// 離開證道大會
|
||
else if (strTmp == "leave_sat") {
|
||
// 判斷是否在隊伍(不在隊伍直接離開)
|
||
if (GameModel.player.teamInfo.objlist || Array.isArray(GameModel.player.teamInfo.objlist)) {
|
||
if (GameModel.player.isleader) {
|
||
FGAlert.show(`確定離開證道大會嗎?離開您的隊伍將失去當前[color=#ed0803]比賽成績[/color]!`, () => {
|
||
FGAlert.hide();
|
||
}, () => {
|
||
FGAlert.hide();
|
||
let params = {
|
||
teamId: GameModel.player.teamid,
|
||
}
|
||
GameModel.send("c2s_leave_sat", params);
|
||
});
|
||
} else {
|
||
MsgAlert.addMsg("只有隊長才開進行此操作!");
|
||
return false;
|
||
}
|
||
} else {
|
||
let params = {
|
||
teamId: 0,
|
||
}
|
||
GameModel.send("c2s_leave_sat", params);
|
||
}
|
||
}
|
||
// 離開水路大會
|
||
else if (strTmp == "leave_sldh") {
|
||
// 判斷是否在隊伍(不在隊伍直接離開)
|
||
if (GameModel.player.teamInfo.objlist || Array.isArray(GameModel.player.teamInfo.objlist)) {
|
||
if (GameModel.player.isleader) {
|
||
FGAlert.show(`確定離開水路大會嗎?離開您的隊伍將失去當前[color=#ed0803]比賽資格[/color]!`, () => {
|
||
FGAlert.hide();
|
||
}, () => {
|
||
FGAlert.hide();
|
||
let params = {
|
||
teamId: GameModel.player.teamid,
|
||
}
|
||
GameModel.send("c2s_leave_sldh", params);
|
||
});
|
||
} else {
|
||
MsgAlert.addMsg("只有隊長才開進行此操作!");
|
||
return false;
|
||
}
|
||
} else {
|
||
let params = {
|
||
teamId: 0,
|
||
}
|
||
GameModel.send("c2s_leave_sldh", params);
|
||
}
|
||
}
|
||
// 請求幫戰
|
||
else if (strTmp == "gang_wars") {
|
||
GameModel.send('c2s_gang_wars', {
|
||
roleId: GameModel.player.roleid,
|
||
});
|
||
}
|
||
// 上陣迎敵
|
||
else if (strTmp == "to_meet_them") {
|
||
GameModel.send('c2s_to_meet_them', {
|
||
roleId: GameModel.player.roleid,
|
||
});
|
||
}
|
||
// 前往比武場
|
||
else if (strTmp == "go_contest") {
|
||
GameModel.send('c2s_go_contest', {
|
||
roleId: GameModel.player.roleid,
|
||
});
|
||
}
|
||
// 返回長安
|
||
else if (strTmp.indexOf('to_map_chang_an') != -1) {
|
||
let vecTmp = strTmp.split(":");
|
||
if (vecTmp.length != 2)
|
||
return;
|
||
GameModel.send('c2s_to_map_chang_an', {
|
||
roleId: GameModel.player.roleid,
|
||
type: parseInt(vecTmp[1])
|
||
});
|
||
}
|
||
// 返回基地
|
||
else if (strTmp.indexOf('go_home') != -1) {
|
||
let vecTmp = strTmp.split(":");
|
||
if (vecTmp.length != 2)
|
||
return;
|
||
GameModel.send('c2s_go_home', {
|
||
roleId: GameModel.player.roleid,
|
||
type: parseInt(vecTmp[1])
|
||
});
|
||
}
|
||
// 比武
|
||
else if (strTmp == "contest") {
|
||
GameModel.send('c2s_contest', {
|
||
roleId: GameModel.player.roleid,
|
||
});
|
||
}
|
||
// 玩法說明
|
||
else if (strTmp.indexOf('explain') != -1) {
|
||
let vecTmp = strTmp.split(":");
|
||
if (vecTmp.length != 2)
|
||
return;
|
||
DebateDao.Instance.openPlayInfo(vecTmp[1]);
|
||
}
|
||
// 開打幫戰塔
|
||
else if (strTmp.indexOf('break') != -1) {
|
||
let vecTmp = strTmp.split(":");
|
||
if (vecTmp.length != 2)
|
||
return;
|
||
var typeId = (vecTmp[1] == 7206 || vecTmp[1] == 7208) ? 3 : 2
|
||
GameModel.send('c2s_ask_fortifications', {
|
||
roleId: GameModel.player.roleid,
|
||
type: typeId,
|
||
serial: parseInt(vecTmp[1]),
|
||
is: 1
|
||
});
|
||
}
|
||
// 蓄力幫戰塔
|
||
else if (strTmp.indexOf('recharge') != -1) {
|
||
if (GameModel.needKeep) return
|
||
let vecTmp = strTmp.split(":");
|
||
if (vecTmp.length != 2)
|
||
return;
|
||
|
||
var typeId = (vecTmp[1] == 7206 || vecTmp[1] == 7208) ? 3 : 2
|
||
|
||
GameModel.send('c2s_ask_fortifications', {
|
||
roleId: GameModel.player.roleid,
|
||
type: typeId,
|
||
serial: parseInt(vecTmp[1]),
|
||
is: 0
|
||
});
|
||
GameModel.towerNpc = GameModel.towerNpcList[vecTmp[1]]
|
||
GameModel.needKeepType = typeId
|
||
GameModel.serial = parseInt(vecTmp[1])
|
||
}
|
||
// 郭老闆兌換
|
||
else if (strTmp.indexOf('guoShopBuy') != -1) {
|
||
GuoShop.Instance.openShopMainPanel()
|
||
}
|
||
// 郭老闆回收
|
||
else if (strTmp.indexOf('guoShopSale') != -1) {
|
||
GuoShop.Instance.openShopMainPanel(1)
|
||
}
|
||
// 提現
|
||
else if (strTmp.indexOf('drawMoney') != -1) {
|
||
DrawMoney.Instance.openDrawPanel();
|
||
}
|
||
// 天梯報名
|
||
else if (strTmp == 'TianTi') {
|
||
if (!GameModel.player.teamInfo.objlist || !Array.isArray(GameModel.player.teamInfo.objlist)) {
|
||
MsgAlert.addMsg("必須先組隊才可以參加天梯巔峰戰!");
|
||
return false;
|
||
}
|
||
GameModel.send('c2s_join_Tianti', {
|
||
roleid: GameModel.player.roleid,
|
||
});
|
||
}
|
||
|
||
this.node.destroy();
|
||
},
|
||
|
||
|
||
});
|