2025-04-24 17:03:28 +08:00

334 lines
13 KiB
JavaScript

import GameModel from "../ts/core/GameModel";
import ItemUtil from "../ts/core/ItemUtil";
import AudioUtil from "../ts/core/AudioUtil";
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil";
import GameUtil from "../ts/core/GameUtil";
import MsgAlert from "../ts/game/msg/MsgAlert";
let CPubFunction = require('./PubFunction');
let CNpcMgr = require('./NpcMgr');
cc.Class({
extends: cc.Component,
properties: {
ActiveDetailUI: cc.Prefab,
},
onLoad() {
this.vecPrize =
[
{ 90002: 0, 900002: 0, 10404: 1 }, // 幫派任務獎勵
{ 90002: 0, 900002: 0, 10404: 1 }, // 師門任務獎勵
{ 90004: 0 }, // 五環任務獎勵
{ 90002: 0, 900002: 0, 10404: 1 }, // 鍾馗抓鬼獎勵
{ 90002: 0, 900002: 0, 10404: 1 }, // 天庭降妖獎勵
{ 10301: 1, 10302: 1, 10303: 0 }, // 寶圖任務獎勵
{ 90002: 0, 900002: 0, 10102: 1, 10103: 1 }, // 大雁塔獎勵
{ 90002: 0, 900002: 0, 10120: 1, 10404: 1 }, // 尋芳獎勵
{ 90002: 0, 900002: 0, 10120: 1, 10103: 1 }, // 地宮獎勵
{ 90002: 0, 900002: 0, 10404: 1, 10301: 1, 10302: 1, 10303: 0 }, // 野外封妖獎勵
{ 90002: 0, 900002: 0, 10404: 1, 50004: 1 }, //三界妖王獎勵
{ 90002: 0, 900002: 0, 50004: 1 }, // 地煞星獎勵
{ 90002: 0, 900002: 0, 10301: 1, 10302: 1, 10303: 0, 50004: 1, 90004: 1 }, // 鎮壓心魔獎勵
{ 90002: 0, 900002: 0, 10404: 1, 10301: 1, 10302: 1, 10303: 0, 67292: 1 }, // 魔王窟獎勵
{ 90002: 0, 900002: 0, 10404: 1 }, // 修羅出沒獎勵
{ 90002: 0, 900002: 0, 10301: 1, 10302: 1, 10303: 0, 50004: 1, 90004: 1 }, // 八卦降魔獎勵
{ 90002: 0, 10204: 0, 10401: 0 }, // 競技場獎勵
//{ 90002: 0, 10204: 0, 10401: 0 }, // 天元盛典獎勵
{ 90002: 0, 900002: 0, 67292: 1,90004: 0 ,50033: 0}, //天星獎勵
{ 90002: 0,900002: 0 }, //文曲星
{ 90002: 0, 90088: 0, 900002: 0, 67293: 0}, //證道大會
{ 90002: 0, 900002: 0, 50023: 0, 67293: 0} //海盜入侵
];
this.vecBtnEvent = [];
this.vecBtnPrize = [0, 0, 0, 0, 0, 0];
this.mapDailyStart = {};
this.mapFuBenCnt = {};
},
start() {
let node = cc.find('btnClose', this.node);
if (SKUIUtil.isValid(node)) {
node.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "DailyUI", "Close", 0));
} else {
cc.warn(`$警告:活動面板btnClose節點無效`);
}
let goContent = cc.find(`ScrollView/view/content`, this.node);
for (let i = 0; i <= 20; i++) {
this.vecBtnEvent.push(goContent.children[i]);
let iconNode = cc.find("nodItemInfo/Icon", this.vecBtnEvent[i]);
if (iconNode) {
let sprite = iconNode.getComponent(cc.Sprite);
if (sprite) {
let conf = GameUtil.getDailyData(i + 1);
if (conf) {
sprite.spriteFrame = ItemUtil.getItemIcon(conf.icon);
}
}
}
let node = this.vecBtnEvent[i];
if (SKUIUtil.isValid(node)) {
let button = node.getComponent(cc.Button);
if (button) {
button.clickEvents.push(CPubFunction.CreateEventHandler(this.node, "DailyUI", "OnDailyEvent", i));
}
}
}
for (let i = 0; i <= 20; i++) {
if (i == 11||i == 17||i == 18) continue;
cc.find(`btnGo`, this.vecBtnEvent[i]).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "DailyUI", "OnGo", i));
}
// cc.find(`btnGo`, this.vecBtnEvent[12]).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "DailyUI", "OnGo", 12));
// cc.find(`btnGo`, this.vecBtnEvent[13]).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "DailyUI", "OnGo", 13));
// cc.find(`btnGo`, this.vecBtnEvent[14]).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "DailyUI", "OnGo", 14));
// cc.find(`btnGo`, this.vecBtnEvent[15]).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "DailyUI", "OnGo", 15));
let nodPrize = cc.find('nodPrize', this.node);
for (let i = 0; i < 6; i++) {
this.vecBtnPrize[i] = nodPrize.children[i];
this.vecBtnPrize[i].getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "DailyUI", "TakeActivePrize", i));
}
GameModel.send('c2s_ask_daily_info', {});
this.SetMoneyInfo();
},
TakeActivePrize(stEvetn, nIndex) {
if (stEvetn.target.children[3].active == true)
return;
if (CPubFunction.GetMapSum(this.mapActiveScore) < (nIndex + 1) * 20)
return;
GameModel.send('c2s_take_active_prize', { nIndex: nIndex });
},
OnReceiveDailyInfo(strJson) {
let stData = SKDataUtil.jsonBy(strJson);
console.log(stData)
this.mapActiveScore = stData.mapActiveScore;
// 活躍度進度條
cc.find('nodPrize/nodExp/picText/picBar', this.node).width = Math.min(CPubFunction.GetMapSum(this.mapActiveScore) / 140, 1) * 680;
// 每日活躍度足夠後的6個獎勵內容是否領取的對勾
for (let i = 0; i < 6; i++) {
let item = this.vecBtnPrize[i];
if (item && item.children && item.children.length >= 3) {
let node = item.children[3];
if (node) {
node.active = parseInt(stData.szBeenTake[i]);
} else {
cc.warn(`$警告:每日限購節點無效!`);
}
} else {
cc.warn(`$警告:每日限購節點無效!`);
}
}
// 每日活躍度足夠後的6個獎勵內容
for (let i = 0; i < 6; i++) {
let vecTmp = stData.szActivePrize[i].split(",");
this.SetPrizesInfo(this.vecBtnPrize[i], parseInt(vecTmp[0]), parseInt(vecTmp[1]));
}
this.mapDailyStart = stData.mapDailyStart;
this.mapDailyCnt = stData.mapDailyCnt;
this.mapFuBenCnt = stData.mapFuBenCnt;
let vecKind = [{ group: 2, cnt: 20, active: 20 }, { group: 3, cnt: 20, active: 20 }, { group: 5, cnt: 5, active: 5 }, { group: 6, cnt: 120, active: 60 }, { group: 7, cnt: 20, active: 20 }, { group: 4, cnt: 15, active: 15 }, { group: 17, cnt: 20, active: 15 }];
for (let nIndex = 0; nIndex <= 5; nIndex++) {
let stDaily = vecKind[nIndex];
let nCurCnt = CPubFunction.GetDefault(this.mapDailyCnt[stDaily.group], 0);
let countNode = cc.find("labCnt", this.vecBtnEvent[nIndex]);
if (SKUIUtil.isValid(countNode)) {
let countLabel = countNode.getComponent(cc.Label);
if (countLabel) {
countLabel.string = `日次數:${nCurCnt}/${stDaily.cnt}`;
}
}
let nCurActive = CPubFunction.GetDefault(this.mapActiveScore[stDaily.group], 0);
let activeNode = cc.find(`labActive`, this.vecBtnEvent[nIndex]);
if (SKUIUtil.isValid(activeNode)) {
let activeLabel = activeNode.getComponent(cc.Label);
if (activeLabel) {
activeLabel.string = `活躍度:${Math.floor(nCurActive)}/${stDaily.active}`;
}
}
}
let vecFuBen = [{ taskid: 1001, active: 21 }, { taskid: 1002, active: 14 }, { taskid: 1004, active: 12 }];
for (let nIndex2 = 0; nIndex2 <= 2; nIndex2++) {
let nBtnIndex = 6 + nIndex2;
let stFuBen = vecFuBen[nIndex2];
let nCurActive = 0;
if (nBtnIndex == 8) //地宮
{
let nCur = this.IsAllReadyInceptFuBenTask(1004) + this.IsAllReadyInceptFuBenTask(1005) + this.IsAllReadyInceptFuBenTask(1006);
cc.find(`labCnt`, this.vecBtnEvent[nBtnIndex]).getComponent(cc.Label).string = `日次數:${nCur}/3`;
nCurActive = CPubFunction.GetDefault(this.mapActiveScore[1004], 0) + CPubFunction.GetDefault(this.mapActiveScore[1005], 0) + CPubFunction.GetDefault(this.mapActiveScore[1006], 0);
} else {
cc.find(`labCnt`, this.vecBtnEvent[nBtnIndex]).getComponent(cc.Label).string = `日次數:${this.IsAllReadyInceptFuBenTask(stFuBen.taskid)}/1`;
nCurActive = CPubFunction.GetDefault(this.mapActiveScore[stFuBen.taskid], 0);
}
cc.find(`labActive`, this.vecBtnEvent[nBtnIndex]).getComponent(cc.Label).string = `活躍度:${nCurActive}/${stFuBen.active}`;
}
// 新增競技場活躍度顯示
let arena = { group: 16, cnt: 10, active: 20 }
let nCurCnt = CPubFunction.GetDefault(this.mapDailyCnt[arena.group], 0);
let countNode = cc.find("labCnt", this.vecBtnEvent[16]);
if (SKUIUtil.isValid(countNode)) {
let countLabel = countNode.getComponent(cc.Label);
if (countLabel) {
countLabel.string = `日次數:${nCurCnt}/${arena.cnt}`;
}
}
let nCurActive = CPubFunction.GetDefault(this.mapActiveScore[arena.group], 0);
let activeNode = cc.find(`labActive`, this.vecBtnEvent[16]);
if (SKUIUtil.isValid(activeNode)) {
let activeLabel = activeNode.getComponent(cc.Label);
if (activeLabel) {
activeLabel.string = `活躍度:${Math.floor(nCurActive)}/${arena.active}`;
}
}
},
IsAllReadyInceptDailyTask(nTeam) {
return SKDataUtil.hasProperty(this.mapDailyStart, nTeam);
},
IsAllReadyInceptFuBenTask(nTask) {
if (SKDataUtil.hasProperty(this.mapFuBenCnt, nTask))
return 1;
return 0;
},
SetPrizesInfo(goItem, nItem, nNum) {
let stConfigInfo = ItemUtil.getItemData(nItem);
cc.find('Icon', goItem).getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIcon(stConfigInfo.icon);
cc.find('txLap', goItem).getComponent(cc.Label).string = SKDataUtil.transform(nNum);
},
SetMoneyInfo() {
// cc.find('layMoney/yinliang/ui_common_icon_yinliang/yinliangLabel', this.node).getComponent(cc.Label).string = GameModel.player.gameData.money;
// cc.find('layMoney/xianyu/ui_common_icon_xianyu/xianyuLabel', this.node).getComponent(cc.Label).string = GameModel.player.gameData.jade;
let topnode = cc.find('topInfo', this.node);
let toplogic = topnode.getComponent('TopInfo');
toplogic.updateGameMoney();
},
CloseAndClickNpc(nNpc) {
let stPos = CNpcMgr.GetNpcPos(nNpc);
GameUtil.myPlayerToDo(stPos.nMap, stPos.nX, stPos.nY, () => {
let temp = CNpcMgr.FindNpcByConfigID(nNpc);
if (temp) {
let npc = temp.getComponent("Npc");
npc.OnNpcClick();
}
});
},
OnDailyEvent(e, i) {
CPubFunction.FindAndDeleteNode(this.node, "ActiveDetailUI");
let goActiveDetailUI = SKUIUtil.createSubNode(this.node, cc.v2(-200, 215), this.ActiveDetailUI, 'ActiveDetailUI');
let conf = GameUtil.getDailyData(i + 1);
if (conf == null) {
return;
}
let desc = conf.desc;
desc = desc.replace(/\\n/g, "\n");
let title = conf.name;
let prize = SKDataUtil.getItemByList(this.vecPrize, i);
let detail = goActiveDetailUI.getComponent('ActiveDetailUI');
if (detail) {
detail.loadInfo(title, desc, prize);
}
},
OnGo(e, d) {
if (d == 0) //幫派任務
{
if (GameModel.player.bangid != 0)
this.CloseAndClickNpc(10054);
else
MsgAlert.addMsg("請先加入幫派")
}
if (d == 1) //師門任務
{
if (GameModel.player.race == 1)
this.CloseAndClickNpc(30062);
if (GameModel.player.race == 2)
this.CloseAndClickNpc(10118);
if (GameModel.player.race == 3)
this.CloseAndClickNpc(30063);
if (GameModel.player.race == 4)
this.CloseAndClickNpc(30065);
if (GameModel.player.race == 5)
this.CloseAndClickNpc(70006);
}
if (d == 2) // 五環
{
this.CloseAndClickNpc(10080);
}
if (d == 3) //鍾馗抓鬼
{
this.CloseAndClickNpc(10112);
}
if (d == 4) //天庭降妖
{
this.CloseAndClickNpc(10221);
}
if (d == 5) //寶圖
{
this.CloseAndClickNpc(10013);
}
if (d == 6) //大雁塔
{
this.CloseAndClickNpc(10062);
}
if (d == 7) //尋芳
{
this.CloseAndClickNpc(10058);
}
if (d == 8) //地宮
{
this.CloseAndClickNpc(10051);
}
if (d == 9) //野外封妖
{
d;
}
if (d == 10) //三界妖王
{
d;
}
if (d == 12) {
this.CloseAndClickNpc(70004);
}
if (d == 13) {
this.CloseAndClickNpc(80015);
}
if (d == 14) {
this.CloseAndClickNpc(30138);
}
if (d == 15) {
this.CloseAndClickNpc(70003);
}
if (d == 16) {
this.CloseAndClickNpc(10240);
}
if (d == 19) {
this.CloseAndClickNpc(60005);
}
},
Close() {
AudioUtil.playCloseAudio();
this.node.destroy();
},
});