You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
211 lines
7.6 KiB
211 lines
7.6 KiB
1 week ago
|
// Learn TypeScript:
|
||
|
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
|
||
|
// Learn Attribute:
|
||
|
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
|
||
|
// Learn life-cycle callbacks:
|
||
|
// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
|
||
|
|
||
|
import { ryw_Event } from "../../FrameWork/Event/EventEnum";
|
||
|
import EventMgr from "../../FrameWork/Event/EventMgr";
|
||
|
import User from "../../FrameWork/User/User";
|
||
|
import AppPlatform from "../../FrameWork/Util/AppPlatform";
|
||
|
import Common5 from "../../Platform/th/Common5";
|
||
|
import TaskManager, { MainTaskIdEnum } from "../JuQingChat/TaskManager";
|
||
|
import BagManager from "../Manager/BagManager";
|
||
|
import InterfaceManager from "../Manager/InterfaceManager";
|
||
|
import NewGuideScript from "../NewGuide/NewGuideScript";
|
||
|
import PrefabManage, { GameType } from "../PrefabManager/PrefabManage";
|
||
|
|
||
|
const { ccclass, property } = cc._decorator;
|
||
|
|
||
|
@ccclass
|
||
|
export default class CiShanChouJiang extends cc.Component {
|
||
|
|
||
|
@property(sp.Skeleton)
|
||
|
m_choujiang_ani: sp.Skeleton = null;
|
||
|
|
||
|
@property(cc.Node)
|
||
|
btn_choujiang: cc.Node = null;
|
||
|
@property(cc.Node)
|
||
|
btn_refresh: cc.Node = null;
|
||
|
|
||
|
@property(cc.Label)
|
||
|
label_num: cc.Label = null;
|
||
|
|
||
|
m_num = 0
|
||
|
|
||
|
m_maxNum = 3
|
||
|
|
||
|
m_isRunning = false
|
||
|
|
||
|
m_isRefresh = false
|
||
|
|
||
|
// LIFE-CYCLE CALLBACKS:
|
||
|
|
||
|
// onLoad () {}
|
||
|
|
||
|
start() {
|
||
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
||
|
let mainId = mainTaskInfo.Id
|
||
|
if (mainId == MainTaskIdEnum.MainTask_503) {
|
||
|
this.m_num = 3
|
||
|
User.setCiShanChouJiangNum(this.m_num)
|
||
|
}
|
||
|
this.init()
|
||
|
|
||
|
this.initTime()
|
||
|
this.schedule(() => {
|
||
|
this.initTime()
|
||
|
}, 60)
|
||
|
}
|
||
|
|
||
|
init() {
|
||
|
this.m_num = User.getCiShanChouJiangNum()
|
||
|
if (this.m_num > 0) {
|
||
|
this.btn_choujiang.active = true
|
||
|
this.btn_refresh.active = false
|
||
|
} else {
|
||
|
this.btn_choujiang.active = false
|
||
|
this.btn_refresh.active = true
|
||
|
}
|
||
|
this.label_num.string = `抽奖${this.m_num}/${this.m_maxNum}`
|
||
|
}
|
||
|
|
||
|
initTime() {
|
||
|
let curtime = Date.now()
|
||
|
let _time = User.getCiShanChouJiangTime()
|
||
|
if (_time == 0) {
|
||
|
User.setCiShanChouJiangTime(curtime)
|
||
|
} else {
|
||
|
let cha = (curtime - _time) / (1000 * 60)
|
||
|
if (cha >= 5) {
|
||
|
this.m_num = 3
|
||
|
User.setCiShanChouJiangNum(this.m_num)
|
||
|
this.init()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
startChouJiang() {
|
||
|
if (this.m_isRunning) {
|
||
|
return
|
||
|
}
|
||
|
Common5.playRemoteAudioEffect("action_effect/慈善抽奖", false);
|
||
|
User.setCiShanChouJiangTime(Date.now())
|
||
|
this.m_isRunning = true
|
||
|
this.m_num--
|
||
|
User.setCiShanChouJiangNum(this.m_num)
|
||
|
this.init()
|
||
|
this.m_choujiang_ani.setAnimation(0, "抽奖", false)
|
||
|
this.m_choujiang_ani.setCompleteListener(() => {
|
||
|
this.m_choujiang_ani.setCompleteListener(null)
|
||
|
this.m_choujiang_ani.setAnimation(0, "静止", false)
|
||
|
this.m_isRunning = false
|
||
|
this.checkTaskFinish()
|
||
|
})
|
||
|
}
|
||
|
|
||
|
checkTaskFinish() {
|
||
|
//获得物品..
|
||
|
let goodArray = [{ goodId: Common5.getRandomNum(3301, 3315), goodNum: 1 }]
|
||
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
||
|
let mainId = mainTaskInfo.Id
|
||
|
let configData = TaskManager.getTaskConfigById(mainId)
|
||
|
let GMGoodIdArray = configData.GMGoodIdArray
|
||
|
let taskCaiGouDan = configData.taskCaiGouDan
|
||
|
if (taskCaiGouDan && taskCaiGouDan.length > 0 && (configData.GMGameType.includes('慈善抽奖') || configData.GMGameType == 'CiShanChouJiang')) {
|
||
|
if (this.m_isRefresh) {//当前已经看过广告
|
||
|
for (let i = 0; i < GMGoodIdArray.length; i++) {
|
||
|
if (BagManager.getBagGoodNums(GMGoodIdArray[i]) <= 0) {
|
||
|
goodArray = [{ goodId: GMGoodIdArray[i], goodNum: 1 }]
|
||
|
this.m_isRefresh = false
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
if (goodArray[0].goodId >= 3301 && goodArray[0].goodId <= 3315) {
|
||
|
for (let i = 0; i < taskCaiGouDan.length; i++) {
|
||
|
if (BagManager.getBagGoodNums(taskCaiGouDan[i]) <= 0 && GMGoodIdArray.indexOf(taskCaiGouDan[i]) == -1) {
|
||
|
goodArray = [{ goodId: taskCaiGouDan[i], goodNum: 1 }]
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
for (let i = 0; i < taskCaiGouDan.length; i++) {
|
||
|
if (BagManager.getBagGoodNums(taskCaiGouDan[i]) <= 0 && GMGoodIdArray.indexOf(taskCaiGouDan[i]) == -1) {
|
||
|
goodArray = [{ goodId: taskCaiGouDan[i], goodNum: 1 }]
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
PrefabManage.loadPrefabByType(GameType.GetAward, null, (prefabNode) => {
|
||
|
prefabNode.getComponent('GetAward').initView(goodArray, () => {
|
||
|
if (taskCaiGouDan && taskCaiGouDan.length > 0) {
|
||
|
let isHave = true
|
||
|
for (let i = 0; i < taskCaiGouDan.length; i++) {
|
||
|
if (BagManager.getBagGoodNums(taskCaiGouDan[i]) <= 0) {
|
||
|
isHave = false
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
if (isHave) {
|
||
|
if (mainId == MainTaskIdEnum.MainTask_503) {
|
||
|
TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_503)
|
||
|
TaskManager.setCurUnLockMainTaskInfo(MainTaskIdEnum.MainTask_504)
|
||
|
EventMgr.emitEvent_custom(ryw_Event.refreshNeedLayer)
|
||
|
User.setRoomBtnIndex(2)
|
||
|
} else if (mainId == MainTaskIdEnum.MainTask_404) {
|
||
|
let node = this.node.getChildByName('exitRoom');
|
||
|
this.guideView([node]);
|
||
|
EventMgr.emitEvent_custom(ryw_Event.HandTip)
|
||
|
EventMgr.emitEvent_custom(ryw_Event.updateDaoYe)
|
||
|
}
|
||
|
EventMgr.emitEvent_custom(ryw_Event.refreshButton)
|
||
|
// this.node.removeFromParent()
|
||
|
// this.node.destroy()
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
})
|
||
|
}
|
||
|
|
||
|
onTouchRefresh() {
|
||
|
if (this.m_isRunning) {
|
||
|
return
|
||
|
}
|
||
|
Common5.playEffect("sound/按键点击")
|
||
|
let tab = {
|
||
|
onClose: (finish) => {
|
||
|
if (finish) {
|
||
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
||
|
let mainId = mainTaskInfo.Id
|
||
|
Common5.ReportDY("inLevel", `任务${mainId}-AD-慈善抽奖增加次数`);
|
||
|
|
||
|
this.m_isRefresh = true
|
||
|
this.m_num = 3
|
||
|
User.setCiShanChouJiangNum(this.m_num)
|
||
|
this.init()
|
||
|
}
|
||
|
else {
|
||
|
Common5.showTips_custom("广告未观看完");
|
||
|
}
|
||
|
}, onFailed: () => {
|
||
|
|
||
|
}
|
||
|
}
|
||
|
AppPlatform.playVideo_custom(tab)
|
||
|
}
|
||
|
|
||
|
guideView(nodeArray) {
|
||
|
PrefabManage.loadPrefabByType(GameType.GuideMskNode, this.node, (prefab) => {
|
||
|
let guideNodeArray = nodeArray
|
||
|
let firstNode = guideNodeArray.shift()
|
||
|
prefab.getComponent(NewGuideScript).setBindNode(firstNode, guideNodeArray)
|
||
|
})
|
||
|
}
|
||
|
// update (dt) {
|
||
|
// }
|
||
|
}
|