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

1525 lines
43 KiB
JavaScript

import MyModel from "../ts/core/MyModel";
import LocalUtil from "../ts/core/LocalUtil";
import GameModel from "../ts/core/GameModel";
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
import SKHotUpdate from "../ts/gear_2.3.4/util/SKHotUpdate";
import FGAlert from "../ts/gear_2.3.4/fgui/FGAlert";
import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil";
import SKLogger from "../ts/gear_2.3.4/util/SKLoader";
import {
ELivingType
} from "../ts/core/EEnum";
import ItemUtil from "../ts/core/ItemUtil";
import RecastAlert from "../ts/game/baldric/RecastAlert";
import RecastPanel from "../ts/game/baldric/RecastPanel";
import JSUtil from "../ts/core/JSUtil";
import FGUtil from "../ts/gear_2.3.4/fgui/FGUtil";
import Arena from "../ts/arena/Arena";
import Contact from "../ts/contact/Contact";
import TeamPanel from "../ts/team/TeamPanel";
import RechargeReward from "../ts/rechargeReward/RechargeReward";
import Question from "../ts/question/Question";
import TurnTable from "../ts/turnTable/TurnTable";
import Guide from "../ts/guide/Guide";
import BtlInfo from "../ts/btlInfo/BtlInfo";
import Transformation from "../ts/transformation/Transformation";
import Welfare from "../ts/welfare/Welfare";
import DecisiveBattle from "../ts/decisiveBattle/DecisiveBattle";
import DebateDao from "../ts/debateDao/DebateDao";
import Gang from "../ts/gang/Gang";
import Bag from "../ts/bag/Bag";
import Appearance from "../ts/appearance/Appearance";
import visitingPrison from "../ts/visitingPrison";
import FactionTalent from "../ts/FactionTalent";
import EquipRefine from "../ts/EquipRefine"
import DailyActivity from "../ts/DailyActivity"
import Set from "../ts/set";
import Shop from "../ts/Shop";
import GangWar from "../ts/GangWar";
import MsgAlert from "../ts/game/msg/MsgAlert";
import GameMap from "../ts/GameMap";
import PetRefine from "../ts/petRefine";
import Debris from "../ts/debris"
import GuoShop from "../ts/GuoShop"
import DrawMoney from "../ts/drawMoney";
import DailyActivityData from "../ts/DailyActivityData";
// import ChatPanel from "../ts/ChatPanel";
import zhenFa from "../ts/zhenFa/zhenfa"
import myXinwu from "../ts/zhenFa/myXinwu"
import tuJian from "../ts/zhenFa/activeZhenFa"
import equip_list from "../ts/zhenFa/equip_list"
import active_panel from "../ts/zhenFa/active_panel"
import BabyMgrPannel from "../ts/nurture/BabyMgrPannel";
import TianTiPanel from "../ts/TianTiPanel/TianTiPanel";
import TianTiPiPei from "../ts/TianTiPanel/TianTiPiPei";
let GameDefine = require('./GameDefine');
let CMainPlayerInfo = require('./MainPlayerInfo');
let CNpcMgr = require('./NpcMgr');
let CPubFunction = require('./PubFunction');
let pScreenNoticeMgr = require('./ScreenNotice');
cc.Class({
extends: cc.Component,
properties: {
mapLayer: cc.Node,
mainMapPre: cc.Prefab,
mainUI: cc.Node,
battleStagePre: cc.Prefab,
battleUIPre: cc.Prefab,
rolepre: cc.Prefab,
petSelectedPre: cc.Prefab,
autoNode: cc.Node,
autoSearchNodes: [cc.Node],
autoPatrolNode: cc.Node,
autoPatrolNodes: [cc.Node],
YinYaoXiangPanel: cc.Prefab,
EquipItemDetail: cc.Prefab,
SchemeEquipItemDetail: cc.Prefab,
SummonDetail: cc.Prefab,
BagItemDetail: cc.Prefab,
GoodsItemDetail: cc.Prefab,
},
onLoad() {
cc.log("GameLogic")
pScreenNoticeMgr.Reset();
this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegan.bind(this));
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoved.bind(this));
this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnded.bind(this));
this.mapLogic = this.mapLayer.getComponent('GameMapLogic');
this.uiLogic = this.mainUI.getComponent('MainUI');
this.playerObjs = {};
this.startAutoSearchAni();
this.startAutoPatrolAni();
this.mainMap = cc.instantiate(this.mainMapPre);
this.mainMap.parent = this.node;
this.mainMap.active = false;
this.autoNode.active = false;
this.autoPatrolNode.active = false;
GameModel.send('c2s_get_bagitem', {
roleid: GameModel.player.roleid
});
GameModel.send('c2s_equip_list', {
roleid: GameModel.player.roleid
});
GameModel.send('c2s_whitelist_interface', {
roleid: GameModel.player.roleid
});
DailyActivityData.init();
this.role_need_sync = {};
let test = cc.find("test", this.node);
if (test) {
test.active = GameModel.debug;
}
SKHotUpdate.changeBlock = (info) => {
FGAlert.shared.title.text = info;
};
SKHotUpdate.progressBlock = (info) => {
FGAlert.shared.title.text = info;
FGAlert.shared.progressBar.value = SKHotUpdate.shared.percent;
};
SKHotUpdate.hasNewBlock = () => {
FGAlert.show(`檢查到新版本${SKHotUpdate.shared.remoteVesion},是否進行更新?`, () => {
FGAlert.hide();
}, () => {
FGAlert.showProgress();
SKHotUpdate.shared.startUpdate();
});
};
SKHotUpdate.delayCheck();
this.addTypeScript();
// 加載字體
cc.loader.loadRes("fonts/Hanyi_xiaodishujian", cc.Font, (err, res) => {
GameModel.fontRes = res;
fgui.registerFont("汉仪小棣书简", res);
})
},
start() {
GameModel.autoWorldVoice = cc.sys.localStorage.getItem('auto_play_world');
if (!GameModel.autoWorldVoic) {
GameModel.autoWorldVoice = 0;
cc.sys.localStorage.setItem('auto_play_world', 0);
}
},
/**
* 添加腳本單例
*/
addTypeScript() {
// 添加隊伍腳本
if (TeamPanel.Instance) {
TeamPanel.Instance = null
}
this.node.addComponent(TeamPanel);
// 添加競技場腳本
if (Arena.Instance) {
Arena.Instance = null
}
this.node.addComponent(Arena);
// 添加充值獎勵腳本
if (RechargeReward.Instance) {
RechargeReward.Instance = null
}
this.node.addComponent(RechargeReward);
// 添加社交腳本
if (Contact.Instance) {
Contact.Instance = null
}
this.node.addComponent(Contact);
// 添加文曲星腳本
if (Question.Instance) {
Question.Instance = null
}
this.node.addComponent(Question);
// 添加轉盤腳本
if (TurnTable.Instance) {
TurnTable.Instance = null
}
this.node.addComponent(TurnTable);
// 添加攻略引導腳本
if (Guide.Instance) {
Guide.Instance = null
}
this.node.addComponent(Guide);
// 添加戰鬥指令腳本
if (BtlInfo.Instance) {
BtlInfo.Instance = null
}
this.node.addComponent(BtlInfo);
// 添加變身卡腳本
if (Transformation.Instance) {
Transformation.Instance = null
}
this.node.addComponent(Transformation);
// 添加信物腳本
if (myXinwu.Instance) {
myXinwu.Instance = null
}
this.node.addComponent(myXinwu);
// 添加信物腳本
if (zhenFa.Instance) {
zhenFa.Instance = null
}
this.node.addComponent(zhenFa);
// 添加圖鑑腳本
if (tuJian.Instance) {
tuJian.Instance = null
}
this.node.addComponent(tuJian);
// 添加圖鑑腳本
if (equip_list.Instance) {
equip_list.Instance = null
}
this.node.addComponent(equip_list);
//天梯面板腳本
if (TianTiPanel.Instance) {
TianTiPanel.Instance = null
}
this.node.addComponent(TianTiPanel);
//天梯匹配面板腳本
if (TianTiPiPei.Instance) {
TianTiPiPei.Instance = null
}
this.node.addComponent(TianTiPiPei);
// 添加激活面板腳本
if (active_panel.Instance) {
active_panel.Instance = null
}
this.node.addComponent(active_panel);
GameModel.send("c2s_five_phases", {
roleid: GameModel.player.roleid,
type: 1
})
// 添加福利腳本
if (Welfare.Instance) {
Welfare.Instance = null
}
this.node.addComponent(Welfare);
// 添加決戰腳本
if (DecisiveBattle.Instance) {
DecisiveBattle.Instance = null
}
this.node.addComponent(DecisiveBattle);
// 添加證道腳本
if (DebateDao.Instance) {
DebateDao.Instance = null
}
this.node.addComponent(DebateDao);
if (GameModel.player.mapid == 4004)
GameModel.send("c2s_say_team_info", {
teamId: GameModel.player.teamid,
})
// 添加幫派腳本
if (Gang.Instance) {
Gang.Instance = null
}
this.node.addComponent(Gang);
// 添加背包腳本
if (Bag.Instance) {
Bag.Instance = null
}
this.node.addComponent(Bag);
// 添加外觀腳本
if (Appearance.Instance) {
Appearance.Instance = null
}
this.node.addComponent(Appearance);
GameModel.send("c2s_has_seffect", {
roleid: GameModel.player.roleid
})
// 添加探監腳本
if (visitingPrison.Instance) {
visitingPrison.Instance = null
}
this.node.addComponent(visitingPrison);
if (FactionTalent.Instance) {
FactionTalent.Instance = null
}
this.node.addComponent(FactionTalent);
if (EquipRefine.Instance) {
EquipRefine.Instance = null
}
this.node.addComponent(EquipRefine);
if (DailyActivity.Instance) {
DailyActivity.Instance = null
}
this.node.addComponent(DailyActivity);
if (Set.Instance) {
Set.Instance = null
}
this.node.addComponent(Set);
if (Shop.Instance) {
Shop.Instance = null
}
this.node.addComponent(Shop);
if (GangWar.Instance) {
GangWar.Instance = null
}
this.node.addComponent(GangWar);
if (GameMap.Instance) {
GameMap.Instance = null
}
this.node.addComponent(GameMap);
if (PetRefine.Instance) {
PetRefine.Instance = null
}
this.node.addComponent(PetRefine);
if (Debris.Instance) {
Debris.Instance = null
}
this.node.addComponent(Debris);
if (GuoShop.Instance) {
GuoShop.Instance = null
}
this.node.addComponent(GuoShop);
if (DrawMoney.Instance) {
DrawMoney.Instance = null
}
this.node.addComponent(DrawMoney);
// if (ChatPanel.Instance) {
// ChatPanel.Instance = null
// }
// this.node.addComponent(ChatPanel);
},
setAllPlayerActive() {
for (let key in this.playerObjs) {
if (SKDataUtil.hasProperty(this.playerObjs, key)) {
let role = this.playerObjs[key].getComponent('role');
if (role) {
role.resetHidden();
}
}
}
},
loadComplete() {
let params = {
accountid: GameModel.player.accountid,
roleId: GameModel.player.roleid
};
GameModel.send("c2s_enter_game", params);
GameModel.send('c2s_title_info', {}); //請求用戶所有的稱謂數據
},
GetMainPlayerID() {
return this.mapLogic.myRole.netInfo.onlyid;
},
GetPlayerObjs(onlyid) {
return this.playerObjs[onlyid];
},
clearPlayer(onlyid) {
this.playerObjs[onlyid].getComponent('role').clear();
this.playerObjs[onlyid].parent = null;
this.playerObjs[onlyid].destroy();
delete this.playerObjs[onlyid];
},
clearPlayerObjs() {
for (const key in this.playerObjs) {
if (SKDataUtil.hasProperty(this.playerObjs, key)) {
this.clearPlayer(key);
}
}
this.playerObjs = {};
},
synPlayerPos(data) {
let curRole = null;
if (data.onlyid == GameModel.player.onlyid) {
curRole = this.mapLogic.roleNode;
}
if (curRole == null) {
curRole = this.playerObjs[data.onlyid];
}
if (curRole != null) {
let plogic = curRole.getComponent('role');
plogic.actlist = [];
curRole.stopAllActions();
plogic.setObjPos(data.x, data.y);
}
},
resetSelfPlayerTitle() {
this.mapLogic.myRole.resetRoleTitle();
},
/*
* 按幀數同步玩家數據
*/
synPlayerByFrame(data) {
for (let item of data) {
if (item.npcconfig) {
if (item.npcconfig == 70005 || item.npcconfig >= 810016 && item.npcconfig <= 810021)
continue;
}
this.role_need_sync[item.onlyid] = item;
}
},
synPlayerInfo(info) {
if (info.onlyid == GameModel.player.onlyid && (GameModel.player.teamid == 0 || (GameModel.player
.teamid > 0 && (GameModel.player.isleader || GameModel.player.tempLeave)))) {
if (info.name != this.mapLogic.myRole.netInfo.name || info.titleid != this.mapLogic.myRole.netInfo
.titleid || info.titleval != this.mapLogic.myRole.netInfo.titleval) {
this.mapLogic.myRole.setInfo(info);
this.mapLogic.myRole.resetRoleTitle();
}
if (this.mainUI.getChildByName('RolePanel')) {
this.mainUI.getChildByName('RolePanel').getComponent('RolePanel').resetRoleName(info.name);
}
return;
}
if (GameModel.player.mapid != info.mapid) {
return;
}
if (info.livingtype == ELivingType.PLAYER) {
let curRole = null;
if (info.onlyid == GameModel.player.onlyid) {
curRole = this.mapLogic.roleNode;
}
if (!curRole) {
curRole = this.playerObjs[info.onlyid];
}
if (!curRole) {
curRole = cc.instantiate(this.rolepre); //cc.instantiate(this.mapLogic.roleNode);
curRole.parent = this.mapLayer;
curRole.zIndex = 3;
curRole.livingtype = info.livingtype;
let comRole = curRole.getComponent('role');
comRole.setObjPos(info.x, info.y);
comRole.setInfo(info);
comRole.onlyid = info.onlyid;
this.playerObjs[info.onlyid] = curRole;
this.mapLogic.setTeamPath();
} else {
let plogic = curRole.getComponent('role');
if (plogic.tResid != info.changeid) {
if (info.changeid > 0) {
plogic.resetResid(info.changeid)
}
if (info.changeid == 0) {
plogic.clearChange(info.changeid)
}
}
let wingId = SKDataUtil.findByDict(GameModel.game_conf.wing, "resid", info.wingId, "id", 0);
plogic.changeWing(wingId);
if (!plogic.isShane && info.shane > 0 && info.mapid != 1201) {
plogic.isShane = true;
plogic.resetRoleTitle();
}
if (plogic.isShane && (info.shane <= 0 || info.mapid == 1201)) {
plogic.isShane = false;
plogic.resetRoleTitle();
}
if (!plogic.checkInTeam() || info.pause == 1) {
let result = this.mapLogic.searchMovePath(plogic.netInfo.x, plogic.netInfo.y, info.x, info
.y);
plogic.actlist = [];
curRole.stopAllActions();
if (result.length > 0) {
for (const act of result) {
plogic.actlist.push({
type: 2,
info: act
});
}
plogic.living_state = 0;
}
plogic.objUpdate();
}
}
if (curRole) {
let plogic = curRole.getComponent('role');
plogic.netInfo.teamid = info.teamid;
plogic.netInfo.isleader = info.isleader;
if (info.name != plogic.netInfo.name || info.titleid != plogic.netInfo.titleid || info
.titleval != plogic.netInfo.titleval) {
plogic.netInfo.titleid = info.titleid;
plogic.netInfo.titleval = info.titleval;
plogic.netInfo.titletype = info.titletype;
plogic.netInfo.bangname = info.bangname;
//plogic.resetName(info.name);
plogic.resetRoleTitle();
}
if (info.teamid > 0 && info.isleader) {
plogic.addHeadStatus(info.teamcnt >= 5 ? 'zudui2' : 'zudui');
} else {
plogic.delHeadStatus('zudui');
plogic.delHeadStatus('zudui2');
}
if (info.battleid > 0) {
plogic.addHeadStatus('zhandou');
} else {
plogic.delHeadStatus('zhandou');
}
}
}
if (info.livingtype == ELivingType.NPC) {
let newp = CPubFunction.CreateNpc(info.onlyid, info.resid, info.name, 0, 0, {
nX: info.x,
nY: info.y
}, this.mapLayer);
newp.parent = this.mapLayer;
newp.zIndex = 3;
newp.livingtype = info.livingtype;
newp.onlyid = info.onlyid;
newp.resid = info.resid;
let nDir = CNpcMgr.GetNpcDefaultDir(info.npcconfig);
info.dir = nDir;
let comNpc = newp.getComponent('Npc');
comNpc.setInfo(info);
CNpcMgr.AddNpcObj(info.onlyid, newp);
let stConfig = CNpcMgr.mapNpcConfig[info.npcconfig];
if (stConfig) {
comNpc.Npc_Init(stConfig.stTalk, stConfig.mapButton);
} else {
cc.log(`任務沒有找到:${info}`);
}
}
},
synPlayerStop(data) {
let plogic = this.playerObjs[data.onlyid].getComponent('role');
plogic.setObjPos(data.x, data.y);
plogic.playStop();
},
synPlayerExit(data) {
if (this.role_need_sync[data.onlyid]) {
delete this.role_need_sync[data.onlyid];
}
if (this.playerObjs[data.onlyid] != null) {
// this.playerObjs[data.onlyid].destroy();
// delete this.playerObjs[data.onlyid];
this.clearPlayer(data.onlyid);
}
if (CNpcMgr.mapNpcObj[data.onlyid] != null) {
CNpcMgr.DestroyNpc(data.onlyid);
}
},
synPlayerData(data) {
GameModel.player.setUserInfo(data);
let wingId = SKDataUtil.findByDict(GameModel.game_conf.wing, "resid", data.wingId, "id", 0);
if (wingId) {
this.mapLogic.myRole.changeWing(wingId);
}
if (this.mainUI.getChildByName('RolePanel')) {
this.mainUI.getChildByName('RolePanel').getComponent('RolePanel').loadGameData();
}
this.uiLogic.setRoleLevel(data.level);
this.uiLogic.setExp(data.exp, data.maxexp);
// let bangPanel = this.node.getChildByName('BangPanel');
// if (bangPanel) {
// let banglogic = bangPanel.getComponent('BangPanel');
// if (banglogic.xiulianNode.active == true) {
// banglogic.xiulianNode.getComponent('BangXiulian').loadInfo();
// }
// if (banglogic.upgradeNode.active == true) {
// banglogic.upgradeNode.getComponent('BangUpgrade').loadInfo();
// }
// }
if (Gang.Instance.practicePanel)
Gang.Instance.initPracticeData();
if (Gang.Instance.practiceUpGradePanel)
Gang.Instance.refreshUpPracticeGrade();
let bagLayer = this.mainUI.getChildByName('BagPanel');
if (bagLayer) {
bagLayer.getComponent('BagPanel').setSchemeName();
}
if (data.changeid > 0) {
if (this.uiLogic)
this.uiLogic.showTransformationBuff();
} else {
if (this.uiLogic)
this.uiLogic.hideTransformationBuff();
}
},
synChatInfo(info) {
if (info.teamData.length > 0) {
info.msg =
`[${info.teamData[0].type}@${info.teamData[0].teamId}@9](${info.teamData[0].num}/5)${info.teamData[0].content}[join@${info.teamData[0].teamId}@10]`
}
let voice_index = 0;
if (info.voice.length > 0) {
voice_index = GameModel.voiceMgr.addVoice(info.voice);
info.voice = voice_index;
} else {
info.voice = -1;
}
if (this.mapLogic.mapId == 4004 && info.scale == 3) {
if (GameModel.player.teamid != info.teamid)
return
}
this.uiLogic.chatLogic.addListInfo(info);
if (this.node.getChildByName('ChatPanel')) {
this.node.getChildByName('ChatPanel').getComponent('ChatPanel').addListInfo(info);
}
if (info.msg.length > 0) {
if (info.scale == 1) {
let stage = cc.find('Canvas/BattleLayer/BattleStage');
if (stage) {
stage.getComponent('BattleStage').objTalk(info);
}
} else if (info.scale == 3) {
let node = cc.find('Canvas/PalaceNotice');
if (node) {
let logic = node.getComponent('PalaceNotice');
if (logic) {
// logic.addStrToList(info.msg);
}
}
}
}
},
/**
* 同步系統通知消息
*/
synChatSystemMessage(info) {
if (!info) return;
console.log("準備添加系統信息", info);
// this.uiLogic.chatLogic.addListInfo(info);
// if (this.node.getChildByName('ChatPanel')) {
// this.node.getChildByName('ChatPanel').getComponent('ChatPanel').addListInfo(info);
// }
},
syncChatGoodsInfo(data) {
let info = JSON.parse(data.info);
// cc.log(info);
if (data.type == 1) {
if (info.EIndex < 7) {
let EquipItemDetail = cc.instantiate(this.EquipItemDetail);
EquipItemDetail.parent = cc.find('Canvas');
if (EquipItemDetail != null) {
EquipItemDetail.getComponent('EquipItemDetail').loadInfo(info, true);
}
} else {
ItemUtil.showMenu = false;
ItemUtil.showAccessDetail(info, false, false);
}
} else if (data.type == 2) {
let BagItemDetail = cc.instantiate(this.BagItemDetail);
if (BtlInfo.Instance && BtlInfo.Instance.btlInfoPanel && BtlInfo.Instance.btlInfoPanel.node) {
BagItemDetail.x = BtlInfo.Instance.btlInfoPanel.node.width / 2
BagItemDetail.y = -BtlInfo.Instance.btlInfoPanel.node.height / 2
BagItemDetail.parent = BtlInfo.Instance.btlInfoPanel.node
} else
BagItemDetail.parent = cc.find('Canvas');
info = ItemUtil.getItemData(info.id);
if (BagItemDetail != null) {
BagItemDetail.getComponent('BagItemDetail').loadInfo(info);
}
} else if (data.type == 3) {
// let petInfo = GameModel.player.petInfo;
// let pinfo = petInfo.list[2];
let SummonDetail = cc.instantiate(this.SummonDetail);
if (BtlInfo.Instance && BtlInfo.Instance.btlInfoPanel && BtlInfo.Instance.btlInfoPanel.node) {
SummonDetail.x = BtlInfo.Instance.btlInfoPanel.node.width / 2
SummonDetail.y = -BtlInfo.Instance.btlInfoPanel.node.height / 2
SummonDetail.parent = BtlInfo.Instance.btlInfoPanel.node
} else
SummonDetail.parent = cc.find('Canvas');
if (SummonDetail != null) {
SummonDetail.getComponent('SummonDetail').loadInfo(info);
}
} else if (data.type == 4) {
} else if (data.type == 5) {
let iinfo;
let tempList = SKDataUtil.clone(GameDefine.RoleTitleList);
for (let i = 0; i < tempList.length; i++) {
if (info.id == tempList[i].id) {
iinfo = tempList[i];
break;
}
}
iinfo.type = 5;
let itemDetail = cc.instantiate(this.GoodsItemDetail);
if (itemDetail != null) {
itemDetail.parent = cc.find('Canvas');
itemDetail.getComponent('GoodsItemDetail').loadInfo(iinfo);
}
} else if (data.type == 6) {
let stTaskConfig = JSUtil.getTaskConfigMgr().GetTaskInfo(info.id);
cc.log(stTaskConfig);
stTaskConfig.type = 6;
let itemDetail = cc.instantiate(this.GoodsItemDetail);
if (itemDetail != null) {
itemDetail.parent = cc.find('Canvas');
itemDetail.getComponent('GoodsItemDetail').loadInfo(stTaskConfig);
}
} else if (data.type == 9) {
let teamInfoPanel = FGUtil.create("main_ui", "team_memeber_info_panel");
FGUtil.root().addChild(teamInfoPanel);
FGUtil.getComponent(teamInfoPanel, "mask").onClick(() => {
FGUtil.dispose(teamInfoPanel);
})
var joinBtn = FGUtil.getButton(teamInfoPanel, "alert/join");
joinBtn.clearClick();
joinBtn.onClick(() => {
GameModel.send('c2s_requst_team', {
roleid: GameModel.player.roleid,
teamid: info.teamid
});
}, this)
FGUtil.getTextField(teamInfoPanel, "alert/n10").text = info.type + "(" + info.datum.length + "/5)";
for (let i in info.datum) {
FGUtil.getLoader(teamInfoPanel, `alert/m${i}/ava`).texture = GameModel.getRoleHead(info.datum[i]
.resid)
FGUtil.getLoader(teamInfoPanel, `alert/m${i}/n3`).url =
`ui://main_ui/icon_race${info.datum[i].race}`
FGUtil.getTextField(teamInfoPanel, `alert/m${i}/name`).text = info.datum[i].name
FGUtil.getTextField(teamInfoPanel, `alert/m${i}/n4`).text = info.datum[i].relive + "轉" + info
.datum[i].level + "級"
}
}
},
synGetFriendList(list) {
let friendsLayer = this.mainUI.getChildByName('FriendPanel');
if (this.mainUI.getChildByName('FriendAddLayer')) {
this.mainUI.getChildByName('FriendAddLayer').destroy();
}
if (friendsLayer != null) {
friendsLayer.getComponent('FriendPanel').loadFriendListInfo(list);
}
let pkPanel = this.mainUI.getChildByName('PKPanel');
if (pkPanel) {
pkPanel.getComponent('PKPanel').showScrollList(list);
}
},
synFriendChatInfo(info) {
GameModel.player.addFriendChatInfo(info);
},
synFriendAddTip() {
this.uiLogic.friendAddTip();
},
synSearchFriendList(list) {
let addLayer = this.mainUI.getChildByName('FriendAddLayer');
if (addLayer != null) {
addLayer.getComponent('FriendAddLayer').showFriendList(list);
}
let pkPanel = this.mainUI.getChildByName('PKPanel');
if (pkPanel) {
pkPanel.getComponent('PKPanel').showSearch(list);
}
},
// 同步背包數量
synbackpackNum(data) {
console.log("開啟背包格子", data)
if (!data.num || data.num <= 50)
return
GameModel.player.bagKindNum = data.num;
let bagLayer = this.mainUI.getChildByName('BagPanel');
if (bagLayer != null) {
bagLayer.getComponent('BagPanel').loadBagList();
}
},
// 同步背包數據
synBagItemList(data) {
let iteminfo = SKDataUtil.jsonBy(data.info);
if (iteminfo == null || iteminfo.length == 0) return
let list = [];
for (const itemid in iteminfo) {
if (SKDataUtil.hasProperty(iteminfo, itemid)) {
list.push({
itemid: itemid,
count: iteminfo[itemid]
});
}
}
GameModel.player.itemList = iteminfo;
CMainPlayerInfo.vecBagItem = list;
// TODO數據刷新即可 視圖暫時不刷新
//if (true ){
// return
//}
let bagLayer = this.mainUI.getChildByName('BagPanel');
if (bagLayer != null) {
bagLayer.getComponent('BagPanel').loadBagList();
}
Bag.Instance.refreshBagPanel();
let schemePanel = cc.find('Canvas/MainUI/SchemePanel');
if (schemePanel) {
let equipsNode = schemePanel.getChildByName('schemeNode').getChildByName('EquipsNode');
let equipsLogic = equipsNode.getComponent('SchemeEquipsPanel');
if (equipsLogic) {
equipsLogic.loadBagList();
}
}
let nodPartnerUI = this.mainUI.getChildByName('PartnerUI');
if (nodPartnerUI != null) {
nodPartnerUI.getComponent('PartnerUI').OnReceiveBagItem();
}
let nodComposUI = this.mainUI.getChildByName('ComposUI');
if (nodComposUI != null) {
nodComposUI.getComponent('ComposUI').OnReceiveBagItem();
}
let MainUI = cc.find('Canvas/MainUI');
let petLayer = MainUI.getChildByName('PetPanel');
if (petLayer != null) {
petLayer.getComponent('PetPanel').refreshInfoNum();
}
if (Transformation.Instance) {
if (Transformation.Instance.practicePanel && Transformation.Instance.practicePanel.node) {
Transformation.Instance.refreshItemCount();
}
}
let workshop = this.node.getChildByName('WorkShopPanel');
if (workshop) {
workshop.getComponent('WorkShopPanel').refreshNeedLabel();
}
BabyMgrPannel.shared.resetBabyGoodsList()
},
synEquipList(data) {
if (!data) {
GameModel.equipData = null;
} else {
let temp = SKDataUtil.jsonBy(data.list);
GameModel.equipData = temp;
if (temp.use) {
let hasWing = false;
for (let key in temp.use) {
let equip = temp.info[temp.use[key]];
if (equip) {
if (equip.EIndex == 6) {
hasWing = true;
let wingId = SKDataUtil.findByDict(GameModel.game_conf.wing, "resid", equip.Shape,
"id", 0);
if (this.mapLogic && this.mapLogic.myRole) {
this.mapLogic.myRole.changeWing(wingId);
}
}
}
}
if (!hasWing) {
if (this.mapLogic && this.mapLogic.myRole) {
this.mapLogic.myRole.changeWing(0);
}
}
}
}
let bagLayer = this.mainUI.getChildByName('BagPanel');
if (bagLayer) {
bagLayer.getComponent('BagPanel').loadBagList();
}
Bag.Instance.refreshBagPanel();
let shenbingup = this.node.getChildByName('ShenBingUpPanel');
if (shenbingup) {
shenbingup.getComponent('ShenBingUpPanel').loadEquipList();
}
let xianqi = this.node.getChildByName('XianQiPanel');
if (xianqi) {
if (xianqi.getComponent('XianQiPanel').upgradeNode.active) {
xianqi.getComponent('XianQiPanel').upgradeNode.getComponent('XianQiUpPanel').loadEquipList();
}
}
},
synEquipInfo(data) {
let info = SKDataUtil.jsonBy(data.equip);
// cc.log(info);
if (GameModel.equipData && GameModel.equipData.info) {
GameModel.equipData.info[info.EquipID] = info;
} else {
return;
}
if (ItemUtil.isBaldric(info.EIndex)) {
if (ItemUtil.isShowDetail()) {
ItemUtil.showAccessDetail(info, false);
}
if (RecastAlert.shared.isShow()) {
RecastAlert.shared.refresh(info);
}
return;
}
Bag.Instance.refreshEquipItenDetail(info);
let detailNode = this.node.getChildByName('EquipItemDetail');
if (detailNode != null && detailNode.getComponent('EquipItemDetail').iteminfo.EquipID == info.EquipID) {
detailNode.getComponent('EquipItemDetail').loadInfo(info);
}
let schemeDetailNode = this.node.getChildByName('SchemeEquipItemDetail');
if (schemeDetailNode != null && schemeDetailNode.getComponent('SchemeEquipItemDetail').iteminfo
.EquipID == info.EquipID) {
schemeDetailNode.getComponent('SchemeEquipItemDetail').loadInfo(info);
}
let workshop = this.node.getChildByName('WorkShopPanel');
if (workshop) {
workshop.getComponent('WorkShopPanel').reloadListData(info);
}
let wingUpdate = this.node.getChildByName('WingUpdatePanel');
if (wingUpdate) {
wingUpdate.getComponent('WingUpdatePanel').reloadListData(info);
}
let shenbingCombine = this.node.getChildByName('ShenBingCombinePanel');
if (shenbingCombine) {
shenbingCombine.getComponent('ShenBingCombinePanel').finishedCombine(info);
}
let shenbingup = this.node.getChildByName('ShenBingUpPanel');
if (shenbingup) {
shenbingup.getComponent('ShenBingUpPanel').reloadListData(info);
}
let xianqi = this.node.getChildByName('XianQiPanel');
if (xianqi) {
if (xianqi.getComponent('XianQiPanel').upgradeNode.active) {
xianqi.getComponent('XianQiPanel').upgradeNode.getComponent('XianQiUpPanel').loadEquipList();
}
if (xianqi.getComponent('XianQiPanel').combineNode.active) {
xianqi.getComponent('XianQiPanel').combineNode.getComponent('XianQiCombinePanel')
.finishedCombine(info);
}
}
},
// 鑑定佩飾
authenticate(data) {
var node = this.node.getChildByName('accessory_main_third');
if (node == null) return;
node.getComponent("Appraisal").appraisalSuccess(data)
},
synNextEquip(data) {
let info = JSON.parse(data.equip);
if (!info || info == null) {
return;
}
let workshop = this.node.getChildByName('WorkShopPanel');
if (workshop != null) {
workshop.getComponent('WorkShopPanel').nextEquipInfo = info;
workshop.getComponent('WorkShopPanel').showInfo();
}
let shenbingup = this.node.getChildByName('ShenBingUpPanel');
if (shenbingup != null) {
shenbingup.getComponent('ShenBingUpPanel').showNextEquipInfo(info);
}
let xianqi = this.node.getChildByName('XianQiPanel');
if (xianqi != null) {
if (xianqi.getComponent('XianQiPanel').upgradeNode.active) {
xianqi.getComponent('XianQiPanel').upgradeNode.getComponent('XianQiUpPanel').showNextEquipInfo(
info);
}
}
},
synEquipProperty(data) {
let workshop = this.node.getChildByName('WorkShopPanel');
if (workshop) {
workshop.getComponent('WorkShopPanel').newScore = data.score
workshop.getComponent('WorkShopPanel').showNewProperty(data.property);
}
let wingUpdate = this.node.getChildByName('WingUpdatePanel');
if (wingUpdate) {
wingUpdate.getComponent('WingUpdatePanel').showNewProperty(data.property);
}
if (RecastPanel.shared.isShow()) {
RecastPanel.shared.sync(data.property);
}
if (RecastAlert.shared.isShow()) {
RecastAlert.shared.refreshRight(data.property);
}
},
synEquipPropertyScore(data) {
let workshop = this.node.getChildByName('WorkShopPanel');
if (workshop) {
workshop.getComponent('WorkShopPanel').oldScore = data
workshop.getComponent('WorkShopPanel').newScore = 0;
workshop.getComponent('WorkShopPanel').refreshOldScore()
}
},
synChangeWeapon(weapon) {
GameModel.player.weapon = weapon;
this.mapLogic.myRole.changeWeapon(GameModel.player.weapon);
},
synXianQiList(data) {
let xianqi = this.node.getChildByName('XianQiPanel');
if (xianqi != null) {
xianqi.getChildByName('combine').getComponent('XianQiCombinePanel').loadTypeList(data);
}
},
// 打開倉庫時獲取數據
synLockerItemList(data) {
console.log(data)
let lockerLayer = this.node.getChildByName('LockerPanel');
if (lockerLayer) {
let baginfo = JSON.parse(data.bag);
let lockerinfo = JSON.parse(data.locker);
let equipinfo = JSON.parse(data.equip);
lockerLayer.getComponent('LockerPanel').loadInfo(baginfo, lockerinfo, equipinfo);
// lockerLayer.getComponent('LockerPanel').loadBagList(baginfo);
// lockerLayer.getComponent('LockerPanel').loadLockerList(lockerinfo);
}
},
synIncenseState(data) {
if (data.ltime > 0) {
if (this.node.getChildByName('YinYaoXiangPanel')) {
this.node.getChildByName('YinYaoXiangPanel').destroy();
}
let yinyao = cc.instantiate(this.YinYaoXiangPanel);
yinyao.name = 'YinYaoXiangPanel';
yinyao.parent = this.node;
let yinyaologic = yinyao.getComponent('YinYaoXiangPanel');
yinyaologic.setTime(data.ltime);
} else {
if (this.node.getChildByName('YinYaoXiangPanel')) {
this.node.getChildByName('YinYaoXiangPanel').getComponent('YinYaoXiangPanel').closePanel();
}
if (this.autoPatrolNode.active) {
this.autoPatrolNode.active = false;
this.mapLogic.myRole.playStop();
}
}
},
synBangList(list) {
let bangLayer = this.node.getChildByName('BangPanel');
if (bangLayer != null) {
bangLayer.getComponent('BangPanel').showAddlayer();
bangLayer.getComponent('BangPanel').showBangList(list);
}
},
closeBangList() {
let bangLayer = this.node.getChildByName('BangPanel');
if (bangLayer != null) {
bangLayer.destroy();
}
},
clearSelfRoleTitleInfo() {
// GameModel.player.bangdata = null;
GameModel.player.bangid = 0;
// GameModel.player.titleid = 0;
// GameModel.player.bangname = '';
// this.resetSelfPlayerTitle();
},
synBangInfo(data) {
GameModel.player.bangdata = data;
GameModel.player.bangid = data.info.bangid;
GameModel.player.bangname = data.info.name;
let bangLayer = this.node.getChildByName('BangPanel');
if (bangLayer != null) {
bangLayer.getComponent('BangPanel').showBangLayer();
bangLayer.getComponent('BangPanel').showBangInfo(data);
}
},
synBangRequest(data) {
let bangLayer = this.node.getChildByName('BangPanel');
if (bangLayer != null) {
bangLayer.getComponent('BangPanel').requestNode.getComponent('BangList').showRequestList(data
.requestlist);
}
},
choosePet() {
let choose = cc.instantiate(this.petSelectedPre);
choose.parent = this.node;
GameModel.send('c2s_creat_equip', {
type: 0,
roleid: GameModel.player.roleid,
index: 1,
is: 0
});
GameModel.send('c2s_creat_equip', {
type: 0,
roleid: GameModel.player.roleid,
index: 2,
is: 0
});
GameModel.send('c2s_creat_equip', {
type: 0,
roleid: GameModel.player.roleid,
index: 3,
is: 0
});
GameModel.send('c2s_creat_equip', {
type: 0,
roleid: GameModel.player.roleid,
index: 4,
is: 0
});
GameModel.send('c2s_creat_equip', {
type: 0,
roleid: GameModel.player.roleid,
index: 5,
is: 0
});
},
synPetInfo(data) {
if (!data) {
cc.log(`寶寶數據錯誤!`);
return;
}
cc.log(data);
GameModel.player.petInfo = data;
MyModel.shared.petList = data;
if (data.list.length < 1) {
SKLogger(`$警告:召喚獸列表為空!`);
return;
}
let curInfo = null;
if (data.curid == 0) {
curInfo = data.list[0];
} else {
for (let index = 0; index < data.list.length; index++) {
if (data.list[index].petid == data.curid) {
curInfo = data.list[index];
break;
}
}
if (!curInfo) {
curInfo = data.list[0];
}
}
this.uiLogic.setPetHeadIcon(curInfo.resid);
this.uiLogic.setPetLevel(curInfo.level);
let petLayer = this.mainUI.getChildByName('PetPanel');
if (petLayer) {
petLayer.getComponent('PetPanel').loadPetList();
}
},
synPetSupportPanel() {
let petLayer = this.mainUI.getChildByName('PetPanel');
if (petLayer) {
petLayer.getComponent('PetPanel').loadPetSupportList();
}
},
synChangePet(data) {
GameModel.player.petInfo.curid = data.curid;
let petLayer = this.mainUI.getChildByName('PetPanel');
if (petLayer != null) {
petLayer.getComponent('PetPanel').loadPetList();
}
// 重置寵物自動技能
LocalUtil.set('battle_p_skill', 0);
let petlist = GameModel.player.petInfo.list;
for (let index = 0; index < petlist.length; index++) {
if (petlist[index].petid == data.curid) {
this.uiLogic.setPetHeadIcon(petlist[index].resid);
this.uiLogic.setPetLevel(petlist[index].level);
break;
}
}
},
synDelPet(data) {
GameModel.player.petInfo.curid = data.curid;
let delpos = -1;
for (let index = 0; index < GameModel.player.petInfo.list.length; index++) {
if (GameModel.player.petInfo.list[index].petid == data.delid) {
delpos = index;
}
}
if (delpos != -1) {
GameModel.player.petInfo.list.splice(delpos, 1);
}
let petLayer = this.mainUI.getChildByName('PetPanel');
if (petLayer != null) {
petLayer.getComponent('PetPanel').loadPetList();
}
let curInfo = {};
for (let index = 0; index < GameModel.player.petInfo.list.length; index++) {
if (GameModel.player.petInfo.list[index].petid == data.curid) {
curInfo = GameModel.player.petInfo.list[index];
break;
}
}
this.uiLogic.setPetHeadIcon(curInfo.resid);
this.uiLogic.setPetLevel(curInfo.level);
},
synUpdatePet(data) {
let petinfo = data.info;
if (!GameModel.player || !GameModel.player.petInfo || !GameModel.player.petInfo.list) {
cc.warn(`$警告:同步召喚獸數據異常!`);
return;
}
for (let index = 0; index < GameModel.player.petInfo.list.length; index++) {
if (GameModel.player.petInfo.list[index].petid == petinfo.petid) {
GameModel.player.petInfo.list[index] = petinfo;
break;
}
}
let MainUI = cc.find('Canvas/MainUI');
let petLayer = MainUI.getChildByName('PetPanel');
if (petLayer != null) {
petLayer.getComponent('PetPanel').reloadInfo(petinfo, true);
}
if (GameModel.player.petInfo.curid == petinfo.petid) {
this.uiLogic.setPetHeadIcon(petinfo.resid);
this.uiLogic.setPetLevel(petinfo.level);
}
// console.log("dianshu1::::====",petinfo.resid)
// console.log("dianshu2::::====",petinfo.petid)
let petFlyPanel = MainUI.getChildByName('PetFlyPanel');
if (petFlyPanel) {
petFlyPanel.getComponent('PetFlyPanel').refrush();
}
},
updatePetSSkill(petid, skillid) {
for (let index = 0; index < GameModel.player.petInfo.list.length; index++) {
let petdata = GameModel.player.petInfo.list[index];
if (petdata.petid == petid) {
petdata.shenskill = skillid;
break;
}
}
let petPanel = cc.find('PetPanel', this.mainUI);
if (petPanel) {
let petlogic = petPanel.getComponent('PetPanel');
petlogic.changeShenSkill(petid, skillid);
}
let petSSkillPanel = cc.find('PetPanel/PetShenSkill', this.mainUI);
if (petSSkillPanel != null) {
let logic = petSSkillPanel.getComponent('PetShenSkill');
logic.destroySelf();
}
},
OnClickEarth() {
let comTaskTip = cc.find('TaskTip', cc.find('Canvas/MainUI/right')).getComponent('TaskTip');
if (comTaskTip) {
comTaskTip.stAuto.nKind = 0;
comTaskTip.stAuto.nTaskID = 0;
}
},
touchBegan(event) {
if (GameModel.player.getLogic().isBing) {
MsgAlert.addMsg("冰凍中,不可進行操作")
return
}
if (GameModel.player.teamid > 0 && !GameModel.player.isleader && !GameModel.player.tempLeave) {
return;
}
this.OnClickEarth();
let touchPos = event.getLocation();
if (this.node.getChildByName('ChatPanel') != null) {
this.node.getChildByName('ChatPanel').getComponent('ChatPanel').hideEmoji();
}
if (GameModel.player.prisonTime == 0) {
for (let key in CNpcMgr.mapNpcObj) {
if (SKDataUtil.hasProperty(CNpcMgr.mapNpcObj, key)) {
let npc = CNpcMgr.mapNpcObj[key];
let valid = SKUIUtil.isValid(npc);
if (valid) {
let btn = npc.getChildByName('Button');
if (btn) {
let temp = btn.getBoundingBoxToWorld().contains(touchPos);
if (temp) {
npc.getComponent('Npc').OnNpcClick();
return;
}
}
}
}
}
if (!GameModel.hideNotTeam) {
for (const key in this.playerObjs) {
if (SKDataUtil.hasProperty(this.playerObjs, key)) {
const p = this.playerObjs[key];
if (p.getChildByName('Button').getBoundingBoxToWorld().contains(touchPos)) {
p.getComponent('role').OnClick();
return;
}
}
}
}
}
let drawPos = this.mapLayer.convertToNodeSpaceAR(touchPos);
this.mapLogic.touchPos(drawPos);
},
touchMoved(event) {
},
touchEnded(event) {
},
startAutoSearchAni() {
for (let index = 0; index < this.autoSearchNodes.length; index++) {
const n = this.autoSearchNodes[index];
n.stopAllActions();
let ani = cc.sequence(cc.scaleTo(0.35, 1.5), cc.scaleTo(0.35, 1), cc.delayTime(1.8));
n.runAction(cc.sequence(cc.delayTime(index * 0.4), cc.callFunc(() => {
n.runAction(cc.repeatForever(ani));
})));
}
},
startAutoPatrolAni() {
for (let index = 0; index < this.autoPatrolNodes.length; index++) {
const n = this.autoPatrolNodes[index];
n.stopAllActions();
let ani = cc.sequence(cc.scaleTo(0.35, 1.5), cc.scaleTo(0.35, 1), cc.delayTime(1.8));
n.runAction(cc.sequence(cc.delayTime(index * 0.4), cc.callFunc(() => {
n.runAction(cc.repeatForever(ani));
})));
}
},
showMainMap() {
if (!SKUIUtil.isValid(this.mainMap)) {
let info = `$警告:主地圖節點無效`;
cc.warn(info);
return;
}
this.mainMap.active = true;
this.mainMap.getComponent('MainMapLogic').init();
},
showSmallMap() {
console.log(GameModel.conf_map[GameModel.player.mapid])
if (GameModel.conf_map[GameModel.player.mapid].bmap == 0) {
return;
}
if (!SKUIUtil.isValid(this.mainMap)) {
cc.warn(`$警告:顯示小地圖節點無效${GameModel.player.mapid}`);
return;
}
this.mainMap.active = true;
let mainmapLogic = this.mainMap.getComponent('MainMapLogic');
mainmapLogic.init();
mainmapLogic.showAboveNode(GameModel.player.mapid);
mainmapLogic.mainLayer.active = false;
},
// 進入戰鬥
enterBattle(teamA, teamB) {
if (this.autoPatrolNode.active) {
this.autoPatrolNode.active = false;
}
this.mapLogic.myRole.playStop();
// clean battle layer
let battlelayer = cc.find('Canvas/BattleLayer');
battlelayer.destroyAllChildren();
let battlestage = cc.instantiate(this.battleStagePre);
battlestage.parent = battlelayer;
battlestage.name = 'BattleStage';
let battlelogic = battlestage.getComponent('BattleStage');
// check battle ui
let battleui = cc.find('Canvas/BattleUILayer/BattleUI');
if (battleui == null) {
let parent = cc.find('Canvas/BattleUILayer');
battleui = cc.instantiate(this.battleUIPre);
battleui.parent = parent;
}
let battleuilogic = battleui.getComponent('BattleUI');
battleuilogic.initPetPanel(teamA.list);
this.uiLogic.isBattle = true;
GameModel.notice.removeMsg();
battlelogic.onBattle();
battlelogic.setTeam(teamA.list, 1);
battlelogic.setTeam(teamB.list, 2);
},
exitBattle(data) {
let battlelayer = cc.find('Canvas/BattleLayer');
let battlestage = battlelayer.getChildByName('BattleStage');
if (battlestage) {
// let deps = cc.loader.getDependsRecursively('Prefabs/Battle/BattleStage');
// cc.loader.release(deps);
let logic = battlestage.getComponent('BattleStage');
logic.clear();
battlestage.destroy();
}
battlelayer.destroyAllChildren();
this.uiLogic.showBattleEnd(data.result > 0);
},
update() {
let count = 0;
for (let key in this.role_need_sync) {
if (SKDataUtil.hasProperty(this.role_need_sync, key)) {
this.synPlayerInfo(this.role_need_sync[key]);
delete this.role_need_sync[key];
++count;
}
if (count == 1) {
break;
}
}
},
// 同步騎乘
syncRide(data) {
let curRole = null;
if (data.onlyId == GameModel.player.onlyid) {
curRole = this.mapLogic.roleNode;
}
if (curRole == null) {
curRole = this.playerObjs[data.onlyId];
}
if (curRole != null) {
let role = curRole.getComponent('role');
if (role != null) {
role.horseList.syncRide(data.horseIndex);
}
}
},
// 同步下騎
syncGetDown(data) {
let curRole = null;
if (data.onlyId == GameModel.player.onlyid) {
curRole = this.mapLogic.roleNode;
}
if (curRole == null) {
curRole = this.playerObjs[data.onlyId];
}
if (curRole != null) {
let role = curRole.getComponent('role');
if (role) {
role.horseList.syncGetDown();
}
}
},
// 同步轉職
syncRace(data) {
let curRole = null;
if (data.onlyId == GameModel.player.onlyid) {
curRole = this.mapLogic.roleNode;
}
if (curRole == null) {
curRole = this.playerObjs[data.info.onlyid];
}
if (curRole != null) {
let role = curRole.getComponent('role');
if (role != null) {
role.setInfo(data.info);
}
}
},
showTransInfo(data) {
if (this.uiLogic)
this.uiLogic.showTransformationInfo(data);
}
});