import GameModel from "../ts/core/GameModel"; import Report from "../ts/gear_2.3.4/net/Report"; import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil"; import SKTimeUtil from "../ts/gear_2.3.4/util/SKTimeUtil"; import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil"; import GameUtil from "../ts/core/GameUtil"; let CPubFunction = require('./PubFunction'); let CMainPlayerInfo = require('./MainPlayerInfo'); let pTaskConfigMgr = require('./task_config').g_pTaskConfigMgr; let EState = require('./task_config').EState; let EEventType = require('./task_config').EEventType; let ETaskKind = require('./task_config').ETaskKind; let CNpcMgr = require('./NpcMgr'); cc.Class({ extends: cc.Component, properties: { btnTaskTip: cc.Prefab, preTaskTalkFlag: cc.Prefab, }, ctor() { this.nEventType = 0; this.vecTaskTip = []; this.vecGoFlag = []; this.bShow = false; this.m_timer = 0; this.stAuto = { nKind: 0, nTaskID: 0, }; }, start() { cc.find('btnHidenTip', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TaskTip", "SwitchShowOrHiden", 0)); this.SwitchShowOrHiden(); this.ResetTimer(1000); }, SwitchShowOrHiden() { this.bShow = !this.bShow; let stPos = this.bShow ? { nX: 20, nY: 20 } : { nX: 270, nY: 19 }; this.node.setPosition(cc.v2(stPos.nX, stPos.nY)); cc.find('btnHidenTip/picFlag', this.node).angle = this.bShow ? -90 : 90; cc.find('btnOpenTaskUI', this.node).active = this.bShow if (cc.find('btnOpenTaskUI', this.node).active == false){ cc.find('diaozhu3', this.node).active = true }else{ cc.find('diaozhu3', this.node).active = false } }, IniTip() { if (typeof this.vecTaskTip == "undefined") { return; } CPubFunction.FindAndHidenNode(cc.find('Canvas/MainUI'), { nX: 0, nY: -1000 }); SKUIUtil.destroyList(this.vecTaskTip); for (let key in CMainPlayerInfo.vecTaskState) { let stTaskState = CMainPlayerInfo.vecTaskState[key]; if (!stTaskState) { cc.warn(`$警告:任務狀態配置為空${key}!`); continue; } let stTaskConfig = pTaskConfigMgr.GetTaskInfo(stTaskState.nTaskID); if (!stTaskConfig) { cc.warn(`$警告:任務狀態配置為空${key}!`); continue; } for (let nStep in stTaskState.vecStepState) { if (stTaskState.vecStepState[nStep].nState != EState.EDoing) { continue; } let stStepConfig = stTaskConfig.vecEvent[nStep]; if (!stStepConfig) { cc.warn(`$警告:任務步驟配置為空${key}!`); continue; } let stStepState = stTaskState.vecStepState[nStep]; if (!stStepState) { cc.warn(`$警告:任務步驟狀態為空${key}!`); continue; } this.nEventType = stStepConfig.nEventType; let strTip = stStepConfig.strTip; if (stStepState.nEventType == EEventType.PlayerGiveNpcItem) { if (CMainPlayerInfo.GetBagItemCnt(stStepConfig.nItemID) >= stStepConfig.nNum) strTip = stStepConfig.strTip2; } if (stStepState.nEventType == EEventType.PlayerGatherNpc) { strTip += ` ${stStepConfig.vecNpc.length - stStepState.vecRemainNpc.length}/${stStepConfig.vecNpc.length}`; } let stTaskName = stTaskConfig.strTaskName; if (stTaskConfig.nKind == ETaskKind.EDaily) { stTaskName += ` (${CMainPlayerInfo.GetDailyCnt(stTaskConfig.nTaskGrop) + 1}/ ${stTaskConfig.nDailyCnt})`; } this.AddTaskTip(stTaskState.nTaskID, nStep, stTaskName, strTip); // cc.log('----stStepState.nEventType->' + stStepState.nEventType + '----stStepConfig.bAutoTrigle->' + stStepConfig.bAutoTrigle); if (stStepState.nEventType == EEventType.PlayerTalkNpc && stStepConfig.bAutoTrigle == 1) { let vecSpeak = CPubFunction.GetTaskTalkList(stTaskState.nTaskID, nStep); CPubFunction.CreateNpcTalk(vecSpeak, () => { GameModel.send('c2s_task_talk_npc', { nTaskID: stTaskState.nTaskID, nStep: nStep, nNpcConfigID: stStepState.vecRemainNpc[0].nNpcConfigID, nNpcOnlyID: stStepState.vecRemainNpc[0].nNpcOnlyID }); }); } } } this.ResetSize(); this.UpdateNpcTalkFlag(); }, GetCurTipListSize() { let nSize = 0; for (let item of this.vecTaskTip) { nSize += item.height; } return nSize; }, AddTaskTip(nTaskID, nStepIndex, strTaskName, strStepDetail) { console.log(nTaskID, nStepIndex, strTaskName, strStepDetail) let goContent = cc.find('ScrollView/view/content', this.node); let nSize = this.GetCurTipListSize(); let btnTaskTip = CPubFunction.CreateSubNode(goContent, { nX: 127, nY: -nSize }, this.btnTaskTip, 'btnTaskTip'); btnTaskTip.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TaskTip", "OnClickStepTip", { nTaskID: nTaskID, nStep: nStepIndex })); let picTaskTip = cc.find('picTaskTip', btnTaskTip); let goName = cc.find('txTaskName', picTaskTip); cc.find('txTaskName', picTaskTip).getComponent(cc.Label).string = strTaskName; let goDetail = cc.find('txStepDetail', picTaskTip); let comLabelDetail = goDetail.getComponent(cc.Label); comLabelDetail.string = strStepDetail; picTaskTip.height = Math.max(picTaskTip.height, goName.height + goDetail.height + 25); btnTaskTip.height = picTaskTip.height; btnTaskTip.y = -nSize - btnTaskTip.height / 2; picTaskTip.y = btnTaskTip.height / 2; this.vecTaskTip.push(btnTaskTip); this.ResetSize(); }, ResetSize() { let nSize2 = this.GetCurTipListSize(); let nodScrollView = cc.find('ScrollView', this.node); nodScrollView.height = CPubFunction.ChangeNumToRange(nSize2, 20, 350); cc.find('ScrollView/view', this.node).height = CPubFunction.ChangeNumToRange(nSize2, 20, 350); cc.find('ScrollView/view/content', this.node).height = nSize2; let picLine = cc.find('picLine', this.node); picLine.y = 125 - nodScrollView.height; }, ResetTimer(time) { let safe = this; this.m_timer = SKTimeUtil.loop(() => { safe.CheckAndAutoClick(); }, time, this.m_timer); }, CheckAndAutoClick() { if (this.stAuto == null || this.stAuto.nKind == 0) return; if (null == CMainPlayerInfo.IsHasCurTask(this.stAuto.nTaskID)) this.stAuto.nTaskID = CMainPlayerInfo.FindDailyTask(this.stAuto.nKind); if (this.stAuto.nTaskID == 0) return; let nStep = CMainPlayerInfo.GetTaskCurStep(this.stAuto.nTaskID); let stStepConfig = pTaskConfigMgr.GetTaskStepInfo(this.stAuto.nTaskID, nStep); let goWaitUI = cc.find('picPercent', cc.find('Canvas/MainUI')); if (goWaitUI) { return; } let goTalkUI = cc.find('TalkUI', cc.find('Canvas/MainUI')); if (goTalkUI && goTalkUI.y > -1000) { let comTalkUI = goTalkUI.getComponent('Talk'); comTalkUI.NextSpeak(); return; } if (!stStepConfig) { cc.warn(`$警告:對話找不到步驟定義,任務索引:${this.stAuto.nTaskID}`); } else if (stStepConfig.nEventType == EEventType.PlayerGiveNpcItem && CMainPlayerInfo.GetBagItemCnt(stStepConfig.nItemID) < stStepConfig.nNum && cc.find('NpcFunUI', cc.find('Canvas/MainUI'))) { GameModel.send('c2s_buy_from_npc', { nConfigID: stStepConfig.nFromNpc, nItemID: stStepConfig.nItemID, nCnt: stStepConfig.nNum }); CPubFunction.FindAndDeleteNode(cc.find('Canvas/MainUI'), 'NpcFunUI'); return; } this.OnClickStepTip(null, { nTaskID: this.stAuto.nTaskID, nStep: nStep }); }, GetTaskNpcPos(nTaskID, nStep, nConfigID) { let stPos = CNpcMgr.GetNpcPos(nConfigID); if (stPos != null) return stPos; let stStepConfig = pTaskConfigMgr.GetTaskStepInfo(nTaskID, nStep); if (SKDataUtil.hasProperty(stStepConfig, 'vecCreateNpc')) { for (var it in stStepConfig.vecCreateNpc) { if (stStepConfig.vecCreateNpc[it].nNpc == nConfigID) { return stStepConfig.vecCreateNpc[it]; } } } return null; }, OnClickStepTip(e, data) { if (GameModel.player.teamid > 0 && (!GameModel.player.tempLeave && !GameModel.player.isleader)) { return; } let stTaskConfig = pTaskConfigMgr.GetTaskInfo(data.nTaskID); let stStepConfig = stTaskConfig.vecEvent[data.nStep]; if (!stStepConfig) { let info = `$警告:NPC對話步驟配置為空${data.nStep}`; Report.report(info); return; } let stStepState = CMainPlayerInfo.GetTaskStepState(data.nTaskID, data.nStep); if (stTaskConfig.nKind == ETaskKind.EDaily) { this.stAuto.nKind = stTaskConfig.nTaskGrop; this.stAuto.nTaskID = data.nTaskID; } else { this.stAuto.nKind = 0; this.stAuto.nTaskID = 0; } if (stStepConfig.nEventType == EEventType.PlayerTalkNpc) { let stPos = this.GetTaskNpcPos(data.nTaskID, data.nStep, stStepState.vecRemainNpc[0].nConfigID); GameUtil.myPlayerToDo(stPos.nMap, stPos.nX, stPos.nY, () => { let pNpc = CNpcMgr.FindNpcByConfigID(stPos.nNpc); if (pNpc) { pNpc.getComponent('Npc').OnNpcClick(); } }); } if (stStepConfig.nEventType == EEventType.PlayerGatherNpc) { let stPos = this.GetTaskNpcPos(data.nTaskID, data.nStep, stStepState.vecRemainNpc[0].nConfigID); GameUtil.myPlayerToDo(stPos.nMap, stPos.nX, stPos.nY, () => { let node = CNpcMgr.FindNpcByConfigID(stPos.nNpc); if (node) { let npc = node.getComponent('Npc'); if (npc) { npc.OnNpcClick(); } else { cc.log(`無NPC組件`); } } else { cc.log("NPC找不到Node"); } }); } if (stStepConfig.nEventType == EEventType.PlayerDoAction) { GameUtil.myPlayerToDo(stStepConfig.nMap, stStepConfig.nX, stStepConfig.nY, () => { let comRole = CPubFunction.GetRole(); CPubFunction.CreateRoleBroadCast(comRole.node, stStepConfig.strTalk); GameUtil.createWaitTip(CPubFunction.GetDefault(stStepConfig.strAction, ''), 1, () => { GameModel.send('c2s_role_action', { nMapID: stStepConfig.nMap, nX: stStepConfig.nX, nY: stStepConfig.nY }); }); }); } if (stStepConfig.nEventType == EEventType.PlayerArriveArea) { GameUtil.myPlayerToDo(stStepConfig.nMap, stStepConfig.nX, stStepConfig.nY, () => { }); } if (stStepConfig.nEventType == EEventType.PlayerGiveNpcItem) { this.IniTip(); let nCur = CMainPlayerInfo.GetBagItemCnt(stStepConfig.nItemID); let nNpc = nCur >= stStepConfig.nNum ? stStepConfig.nNpcConfigID : stStepConfig.nFromNpc; let stData = CNpcMgr.GetNpcPos(nNpc); if (null == stData) return; GameUtil.myPlayerToDo(stData.nMap, stData.nX, stData.nY, () => { let goNpc = CNpcMgr.FindNpcByConfigID(nNpc); if (goNpc != null) CNpcMgr.FindNpcByConfigID(nNpc).getComponent('Npc').OnNpcClick(); }); } if (stStepConfig.nEventType == EEventType.PlayerKillNpc) { let stPos = this.GetTaskNpcPos(data.nTaskID, data.nStep, stStepState.vecRemainNpc[0].nConfigID); GameUtil.myPlayerToDo(stPos.nMap, stPos.nX, stPos.nY, () => { let goNpc = CNpcMgr.FindNpcByConfigID(stPos.nNpc); if (goNpc) goNpc.getComponent('Npc').OnNpcClick(); }); } }, UpdateNpcTalkFlag() { SKUIUtil.destroyList(this.vecGoFlag); for (let it in CMainPlayerInfo.vecTaskState) { let stTaskState = CMainPlayerInfo.vecTaskState[it]; for (let nStep in stTaskState.vecStepState) { if (stTaskState.vecStepState[nStep].nState != EState.EDoing) continue; if (stTaskState.vecStepState[nStep].nEventType != EEventType.PlayerTalkNpc) continue; let goNpc = CNpcMgr.FindNpcByConfigID(stTaskState.vecStepState[nStep].vecRemainNpc[0].nConfigID); let goFlag = CPubFunction.CreateSubNode(goNpc, { nX: -5, nY: 190 }, this.preTaskTalkFlag, 'preTaskTalkFlag'); goFlag.stopAllActions(); let ani = cc.sequence(cc.scaleTo(0.5, 1, 1), cc.scaleTo(0.5, 1, 0.9)); goFlag.runAction(cc.repeatForever(ani)); this.vecGoFlag.push(goFlag); } } }, onDestroy() { this.m_timer = SKTimeUtil.cancelLoop(this.m_timer); } });