import auto_signView from "../../../ui/uidata/Interface/auto_signView"; import UIBase from "../../../framework/ui/UIBase"; import UIHelp from "../../../framework/ui/UIHelp"; import Utils from "../../../framework/utils/utils"; import EventManager from "../../../framework/event/EventManager"; import {EVENT_TYPE} from "../../../gameLogic/utrl/gameEnum"; import gameEventManager from "../../../gameLogic/utrl/gameEventManager"; import AccountModel from "../../../data/Account/AccountModel"; import UIObtainView from "./UIObtainView"; import rewardDtMgr from "../../../dataManager/rewardDtMgr"; import value = cc.js.value; import itemDtManager from "../../../dataManager/itemDtManager"; import gameData from "../../../gameLogic/utrl/gameData"; import game = cc.game; import UiGuideHand from "../common/uiGuideHand"; import SignUtil from "../../../framework/utils/signUtil"; const {ccclass, menu, property} = cc._decorator; const wp_reward = 48; const role_reward = 51; @ccclass @menu("UI/Interface/UISignView") export default class UISignView extends UIBase { ui: auto_signView = null; protected static prefabUrl = "Interface/signView"; protected static className = "UISignView"; @property(cc.Prefab) guideHandPrefab: cc.Prefab = null; onUILoad() { this.ui = this.node.addComponent(auto_signView); } private times = 0; private timeStamp = 0; private canSign = false; onShow() { this.refresh(); this.guideHandler(); } private guideHandler() { if (!SignUtil.canSign()){ return; } if (AccountModel.getInstance().is_new == 1) { this.scheduleOnce(() => { if (!this.guideHandPrefab) { return; } const node = cc.instantiate(this.guideHandPrefab); node.getComponent(UiGuideHand).init(this.ui[`singleNode${1}`]); this.node.addChild(node); }, 0) } } checkNeedMultiply(id: number) { return id >= 1 && id <= 12; } private refresh() { this.canSign = false; this.times = AccountModel.singleInstance.sign_times; this.timeStamp = AccountModel.singleInstance.sign_timestamp; // 没有时间戳 if (!this.timeStamp) { this.canSign = true; } else if (new Date(this.timeStamp).getDate() != new Date().getDate()) { this.canSign = true; } //签完不要再签了 if (this.times == 7) { this.canSign = false; this.ui.all_comp.active = true; } const doneFrame = this.ui.done.getComponent(cc.Sprite).spriteFrame; for (let i = 1; i <= 7; i++) { this.ui[`singleNode${i}`].getChildByName('comp').active = i < this.times + 1; if (this.ui[`singleNode${i}`].getChildByName('comp').active) { this.ui[`singleNode${i}`].getChildByName(`day${i}`).getComponent(cc.Sprite).spriteFrame = doneFrame; } this.ui[`singleNode${i}`].getChildByName('tip').active = false; this.ui[`singleNode${i}`].getChildByName('receive').active = false; this.ui[`singleNode${i}`].getChildByName('aureole').active = false; } if (this.canSign) { this.ui[`singleNode${this.times + 1}`].getChildByName('tip').active = true; this.ui[`singleNode${this.times + 1}`].getChildByName('receive').active = true; this.ui[`singleNode${this.times + 1}`].getChildByName('aureole').active = true; } } public refreshForAdEveventForQianDaoAdEnd() { this.canSign = false; this.times = AccountModel.singleInstance.sign_times; this.timeStamp = AccountModel.singleInstance.sign_timestamp; // 没有时间戳 if (!this.timeStamp) { this.canSign = true; } else if (new Date(this.timeStamp).getDate() != new Date().getDate()) { this.canSign = true; } //签完不要再签了 if (this.times == 7) { this.canSign = false; this.ui.all_comp.active = true; } const doneFrame = this.ui.done.getComponent(cc.Sprite).spriteFrame; for (let i = 1; i <= 7; i++) { this.ui[`singleNode${i}`].getChildByName('comp').active = i < this.times + 1; if (this.ui[`singleNode${i}`].getChildByName('comp').active) { this.ui[`singleNode${i}`].getChildByName(`day${i}`).getComponent(cc.Sprite).spriteFrame = doneFrame; } this.ui[`singleNode${i}`].getChildByName('tip').active = false; this.ui[`singleNode${i}`].getChildByName('receive').active = false; this.ui[`singleNode${i}`].getChildByName('aureole').active = false; } if (this.canSign) { this.ui[`singleNode${this.times + 1}`].getChildByName('tip').active = true; this.ui[`singleNode${this.times + 1}`].getChildByName('receive').active = true; this.ui[`singleNode${this.times + 1}`].getChildByName('aureole').active = true; } } onHide() { } onStart() { } clickItem(event: any, type: string) { console.log('zh: clickItem 签到clickItem type=',type,'event='+event); const day = parseInt(type); if (this.canSign && day == this.times + 1) { this.doSign(day); } } doSign(day: number) { gameEventManager.emit(EVENT_TYPE.OFF_SIGN_TIP) const list = rewardDtMgr.getInstance().getSignRewardList(); const info = list[this.times + 1]; const itemID = info.itemID; const itemNum = info.itemNum; let itemArr = []; let numArr = []; if (typeof itemID == 'number') { itemArr.push(itemID); numArr.push(itemNum); } else { itemArr = itemID.split(','); numArr = info.itemNum.split(','); } //处理数量 itemArr.forEach((value, index) => { value = parseInt(value); const data = itemDtManager.getDataByID(value); if (this.checkNeedMultiply(value)) { numArr[index] *= data.value; } }) //分给玩家 itemArr.forEach((value, index) => { const data = itemDtManager.getDataByID(value); let damage: number = 0; // (食物1,药品2,子弹3,近战武器4, 远程武器5) switch (data.type) { case 1: gameData.curPowerNum += numArr[index]; break; case 2: break; case 3: gameData.curBulletNum += numArr[index]; break; case 4: for (let i = 0; i < numArr[index]; i++) { damage = itemDtManager.getDataByID(data.id).value; gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, true); } break; case 5: for (let i = 0; i < numArr[index]; i++) { damage = itemDtManager.getDataByID(data.id).value; gameEventManager.emit(EVENT_TYPE.ADD_WEAPONS, data.id, damage, false); } break; } }); let modelIds = []; if (info.modelID != 0) { const fixedRoleIds = AccountModel.singleInstance.fixed_role_ids; fixedRoleIds.push(info.modelID) AccountModel.singleInstance.fixed_role_ids = fixedRoleIds; gameEventManager.emit(EVENT_TYPE.ADD_HERO_BY_ID, info.modelID); modelIds.push(info.modelID); } UIHelp.ShowUI(UIObtainView, null, {ids: itemArr, nums: numArr, modelIds: modelIds, type: 'sign'}); AccountModel.singleInstance.sign_times++; AccountModel.singleInstance.sign_timestamp = Utils.getTimeStamp(true); this.refresh(); } clickClose() { gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, false); this.onClose(); } onClose() { EventManager.emit(EVENT_TYPE.closeSign); UIHelp.CloseUI(UISignView); } }