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.
415 lines
16 KiB
415 lines
16 KiB
1 week ago
|
import { ryw_Event } from "../../../FrameWork/Event/EventEnum";
|
||
|
import EventMgr from "../../../FrameWork/Event/EventMgr";
|
||
|
import GameReport from "../../../FrameWork/Report/ZyZyReport";
|
||
|
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 UserManager from "../../Manager/UserManager";
|
||
|
import NewGuideScript from "../../NewGuide/NewGuideScript";
|
||
|
import PrefabManage, { GameType } from "../../PrefabManager/PrefabManage";
|
||
|
import GameBase from "../../SCommon/GameBase";
|
||
|
import GetAward from "../../SCommon/GetAward";
|
||
|
import ZhongCanTingManager from "../ZhongCanTing/ZhongCanTingManager";
|
||
|
|
||
|
const { ccclass, property } = cc._decorator;
|
||
|
|
||
|
|
||
|
@ccclass
|
||
|
export default class ZhiShuZaoLin extends GameBase {
|
||
|
|
||
|
@property(cc.Node)
|
||
|
dripPrefab: cc.Node = null; // 水滴预制体
|
||
|
|
||
|
@property(cc.Node)
|
||
|
dripLayer: cc.Node = null; // 水滴层
|
||
|
|
||
|
@property(cc.Node)
|
||
|
gameSettleView: cc.Node = null; // 游戏结算
|
||
|
|
||
|
@property(cc.Node)
|
||
|
backLayer: cc.Node = null; // 返回按钮层
|
||
|
|
||
|
@property(cc.Node)
|
||
|
cloudNode: cc.Node = null; // 云
|
||
|
|
||
|
@property(cc.Node)
|
||
|
saplingNode: cc.Node = null; // 树苗
|
||
|
|
||
|
@property(cc.ProgressBar)
|
||
|
treeProgress: cc.ProgressBar = null;
|
||
|
|
||
|
@property(cc.Label)
|
||
|
nextShouYi: cc.Label = null;
|
||
|
|
||
|
// @property(cc.Label)
|
||
|
// curIncomeLab: cc.Label = null;
|
||
|
|
||
|
// @property(cc.Label)
|
||
|
// endIncomeLab: cc.Label = null;
|
||
|
|
||
|
|
||
|
@property([cc.Node])
|
||
|
rockLeftArr: cc.Node[] = [];
|
||
|
@property([cc.Node])
|
||
|
rockRightArr: cc.Node[] = [];
|
||
|
|
||
|
TreeNeedDripArray = [5, 10, 20, 15, 20, 40, 20, 40, 60, 30, 50, 90, 55, 85, 110, 75, 100, 130, 95, 125, 150, 125, 165, 200]; // 树需要的水滴数量
|
||
|
LevelUnlocktaskIdArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; // 关卡解锁任务id数组
|
||
|
DripMoveSpeed = 1600; // 水滴运动速度
|
||
|
HaveGoodsLevelArray = [2, 3]; // 拥有的道具等级数组
|
||
|
HaveGoodsIdArray = [3095, 3605]; // 拥有的道具id数组
|
||
|
maskGuideNode: cc.Node = null; // 遮罩层
|
||
|
dripArray: cc.Node[] = []; // 水滴数组
|
||
|
dripPool: cc.NodePool = null; // 水滴池
|
||
|
treeLevel: number = 0; // 植树关卡
|
||
|
dripNumber: number = 0; // 水滴数量
|
||
|
goodsIndex: number = 0; // 道具索引
|
||
|
isStopAll: boolean = false; // 是否停止所有
|
||
|
isStopRockMove: boolean = false; // 是否停止岩石运动
|
||
|
canCreateDrip: boolean = true; //是否能够生成水滴
|
||
|
rockIsMoveToRigthArr: boolean[] = [true, true, true]; // 岩石是否向右运动
|
||
|
rockSpeedArr: number[] = [250, 200, 230]; // 岩石运动速度
|
||
|
|
||
|
onLoad() {
|
||
|
super.onLoad();
|
||
|
}
|
||
|
|
||
|
onDestroy(): void {
|
||
|
if (cc.isValid(this.maskGuideNode)) {
|
||
|
this.maskGuideNode.removeFromParent();
|
||
|
this.maskGuideNode.destroy();
|
||
|
}
|
||
|
super.onDestroy();
|
||
|
|
||
|
EventMgr.emitEvent_custom(ryw_Event.RefreshJuQingDuiHua);
|
||
|
}
|
||
|
|
||
|
protected start(): void {
|
||
|
this.dripNumber = 0;
|
||
|
this.isStopAll = false;
|
||
|
this.isStopRockMove = false;
|
||
|
this.dripPrefab.active = false;
|
||
|
this.dripPool = new cc.NodePool();
|
||
|
|
||
|
this.refreshLevelDataView();
|
||
|
|
||
|
EventMgr.onEvent_custom(ryw_Event.NormalTouchEndCheck, (data_) => {
|
||
|
this.normalClickCallback(data_.targetNode);
|
||
|
}, this);
|
||
|
let spine = this.saplingNode.getComponent(sp.Skeleton);
|
||
|
spine.setCompleteListener(() => {
|
||
|
if (spine.animation == '抖动') {
|
||
|
spine.setAnimation(0, '静止', true);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
protected update(dt: number): void {
|
||
|
if (this.isStopAll) {
|
||
|
return;
|
||
|
}
|
||
|
if (dt > 0.5) {
|
||
|
dt = 1 / 60;
|
||
|
}
|
||
|
this.updataRockMove(dt);
|
||
|
this.updataDripMove(dt);
|
||
|
}
|
||
|
|
||
|
// 刷新关卡数据ui
|
||
|
refreshLevelDataView() {
|
||
|
this.treeLevel = User.getTreeLevel();
|
||
|
let levelNode = this.node.getChildByName('牌子').getChildByName('lab');
|
||
|
let goodsNode = this.node.getChildByName('GetPropView').getChildByName('lab');
|
||
|
|
||
|
this.goodsIndex = -1;
|
||
|
for (let i = 0; i < this.HaveGoodsLevelArray.length; i++) {
|
||
|
const level = this.HaveGoodsLevelArray[i];
|
||
|
if (this.treeLevel <= level) {
|
||
|
this.goodsIndex = i;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (this.treeLevel > this.TreeNeedDripArray.length) {
|
||
|
this.treeLevel = this.TreeNeedDripArray.length;
|
||
|
}
|
||
|
|
||
|
levelNode.getComponent(cc.Label).string = `${this.treeLevel}`;
|
||
|
if (this.goodsIndex == -1) {
|
||
|
goodsNode.getComponent(cc.Label).string = `你已经领取完所有道具!`;
|
||
|
} else {
|
||
|
let goods = BagManager.getGoodsProperty(this.HaveGoodsIdArray[this.goodsIndex]);
|
||
|
goodsNode.getComponent(cc.Label).string = `种到第${this.HaveGoodsLevelArray[this.goodsIndex]}颗树可获得《${goods.goodName}》`;
|
||
|
}
|
||
|
|
||
|
// let curIncome = Common5.getNumberChangeHanzi(ZhongCanTingManager.getPerSecondShouYi(), '2');
|
||
|
// let endIncome = Common5.getNumberChangeHanzi(ZhongCanTingManager.getPerSecondShouYi(1), '2');
|
||
|
// this.curIncomeLab.string = `${curIncome}/秒`;
|
||
|
// this.endIncomeLab.string = `${endIncome}/秒`;
|
||
|
|
||
|
let curShouYi = ZhongCanTingManager.getPerSecondShouYi()
|
||
|
let tiShengShouYi = ZhongCanTingManager.getPerSecondShouYi(1)
|
||
|
|
||
|
let str = `过关后每秒收益: ${Common5.getNumberChangeHanzi(curShouYi, '1', 1)}/秒 → ${Common5.getNumberChangeHanzi(tiShengShouYi, '1', 1)}/秒`
|
||
|
this.nextShouYi.string = str
|
||
|
|
||
|
this.updateDripNumberView();
|
||
|
this.updataRockState();
|
||
|
this.checkGameUnlock();
|
||
|
}
|
||
|
|
||
|
// 刷新水滴数量ui
|
||
|
updateDripNumberView() {
|
||
|
const DripNumberMax = this.TreeNeedDripArray[this.treeLevel - 1];
|
||
|
let lab = this.node.getChildByName('DripNumberView').getChildByName('lab');
|
||
|
lab.getComponent(cc.Label).string = `${this.dripNumber}/${DripNumberMax}`;
|
||
|
this.treeProgress.progress = this.dripNumber / DripNumberMax;
|
||
|
}
|
||
|
|
||
|
// 刷新岩石状态
|
||
|
updataRockState() {
|
||
|
for (let i = 0; i < this.rockLeftArr.length; i++) {
|
||
|
let checkRockLeft = this.rockLeftArr[i].getChildByName("石头");
|
||
|
let checkRockRight = this.rockRightArr[i].getChildByName("石头");
|
||
|
checkRockLeft.getComponent(sp.Skeleton).setAnimation(0, '干', true);
|
||
|
checkRockRight.getComponent(sp.Skeleton).setAnimation(0, '干', true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 游戏解锁判定
|
||
|
checkGameUnlock() {
|
||
|
this.backLayer.active = false;
|
||
|
let taskInfo: any = TaskManager.getCurUnLockMainTaskInfo();
|
||
|
console.log(`taskId:${taskInfo.Id}, levelUnlocktaskId:${this.LevelUnlocktaskIdArray[this.treeLevel - 1]}`);
|
||
|
if (this.LevelUnlocktaskIdArray[this.treeLevel - 1] > taskInfo.Id) {
|
||
|
this.backLayer.active = true;
|
||
|
this.backLayer.getChildByName('标题').getComponent(cc.Label).string = `暂未解锁\n需继续游玩剧情解锁!`;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 点击回调事件
|
||
|
normalClickCallback(targetNode: cc.Node) {
|
||
|
if (targetNode.name == 'bg') {
|
||
|
if (this.canCreateDrip && !this.isStopAll) {
|
||
|
this.canCreateDrip = false;
|
||
|
let drip = this.dripPool.get();
|
||
|
if (drip == null) {
|
||
|
drip = cc.instantiate(this.dripPrefab);
|
||
|
}
|
||
|
this.dripLayer.addChild(drip);
|
||
|
this.dripArray.push(drip);
|
||
|
drip.setPosition(0, 350);
|
||
|
drip.active = true;
|
||
|
this.scheduleOnce(() => {
|
||
|
this.canCreateDrip = true;
|
||
|
}, 0);
|
||
|
this.cloudNode.getComponent(sp.Skeleton).setAnimation(0, '云', false);
|
||
|
}
|
||
|
}
|
||
|
//console.log(`this.foodPool:${this.foodPool.size()}`);
|
||
|
}
|
||
|
|
||
|
// 岩石运动
|
||
|
updataRockMove(dt: number = 1 / 60) {
|
||
|
if (!this.isStopRockMove) {
|
||
|
//地刺运动
|
||
|
for (var i = 0; i < 3; i++) {
|
||
|
if (this.rockIsMoveToRigthArr[i]) {
|
||
|
this.rockLeftArr[i].x += dt * this.rockSpeedArr[i]
|
||
|
this.rockRightArr[i].x -= dt * this.rockSpeedArr[i]
|
||
|
if (this.rockLeftArr[i].x >= -280) {
|
||
|
this.rockSpeedArr[i] = Math.floor(Math.random() * 400 + 100)
|
||
|
this.rockIsMoveToRigthArr[i] = false
|
||
|
}
|
||
|
} else {
|
||
|
this.rockLeftArr[i].x -= dt * this.rockSpeedArr[i]
|
||
|
this.rockRightArr[i].x += dt * this.rockSpeedArr[i]
|
||
|
if (this.rockLeftArr[i].x <= -700) {
|
||
|
this.rockSpeedArr[i] = Math.floor(Math.random() * 400 + 100)
|
||
|
this.rockIsMoveToRigthArr[i] = true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 水滴碰撞和移动
|
||
|
updataDripMove(dt: number = 1 / 60) {
|
||
|
for (const drip of this.dripArray) {
|
||
|
drip.y -= dt * this.DripMoveSpeed;
|
||
|
|
||
|
if (drip.y <= -550) {
|
||
|
let index = this.dripArray.indexOf(drip);
|
||
|
this.dripArray.splice(index, 1);
|
||
|
this.dripPool.put(drip);
|
||
|
this.dripNumber++;
|
||
|
this.updateDripNumberView();
|
||
|
this.saplingNode.getComponent(sp.Skeleton).setAnimation(0, '抖动', false);
|
||
|
|
||
|
const DripNumberMax = this.TreeNeedDripArray[this.treeLevel - 1];
|
||
|
if (this.dripNumber >= DripNumberMax) {
|
||
|
this.isStopAll = true;
|
||
|
this.node.getChildByName('大树').active = true;
|
||
|
this.node.getChildByName('树苗').active = false;
|
||
|
this.scheduleOnce(() => {
|
||
|
this.gameSuccess();
|
||
|
}, 0.5)
|
||
|
}
|
||
|
} else {
|
||
|
for (let index = 0; index < this.rockLeftArr.length; index++) {
|
||
|
if (Common5.checkIntersectsBox(drip, this.rockLeftArr[index].getChildByName("langArea"))) {
|
||
|
this.isStopAll = true;
|
||
|
let checkRockLeft = this.rockLeftArr[index].getChildByName("石头");
|
||
|
let checkRockRight = this.rockRightArr[index].getChildByName("石头");
|
||
|
checkRockLeft.getComponent(sp.Skeleton).setAnimation(0, '浸湿', false);
|
||
|
checkRockRight.getComponent(sp.Skeleton).setAnimation(0, '浸湿', false);
|
||
|
this.scheduleOnce(() => {
|
||
|
this.dripPool.put(drip);
|
||
|
}, 0.1);
|
||
|
this.scheduleOnce(() => {
|
||
|
this.gameFail();
|
||
|
}, 1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 游戏成功
|
||
|
gameSuccess() {
|
||
|
this.gameSettleView.active = true;
|
||
|
this.gameSettleView.getChildByName('fail').active = false;
|
||
|
this.gameSettleView.getChildByName('success').active = true;
|
||
|
|
||
|
let treeLevel = User.getTreeLevel();
|
||
|
if (this.treeLevel <= this.TreeNeedDripArray.length) {
|
||
|
if (treeLevel == this.HaveGoodsLevelArray[this.goodsIndex]) {
|
||
|
let goodArray = [{ goodId: this.HaveGoodsIdArray[this.goodsIndex], goodNum: 1 }];
|
||
|
PrefabManage.loadPrefabByType(GameType.GetAward, null, (prefabNode) => {
|
||
|
prefabNode.getComponent(GetAward).initView(goodArray, () => {
|
||
|
UserManager.addProperTiLi(1);
|
||
|
User.setTreeLevel(treeLevel + 1);
|
||
|
|
||
|
let taskInfo: any = TaskManager.getCurUnLockMainTaskInfo();
|
||
|
if (taskInfo.Id == MainTaskIdEnum.MainTask_1504) {
|
||
|
for (const goodId of [3095, 3605]) {
|
||
|
if (BagManager.getBagGoodNums(goodId) == 0) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_1504);
|
||
|
TaskManager.setCurUnLockMainTaskInfo(MainTaskIdEnum.MainTask_1505);
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
} else {
|
||
|
UserManager.addProperTiLi(1);
|
||
|
User.setTreeLevel(treeLevel + 1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// 游戏失败
|
||
|
gameFail() {
|
||
|
this.gameSettleView.active = true;
|
||
|
this.gameSettleView.getChildByName('fail').active = true;
|
||
|
this.gameSettleView.getChildByName('success').active = false;
|
||
|
}
|
||
|
|
||
|
// 引导
|
||
|
guideView(nodeArray) {
|
||
|
if (this.maskGuideNode == null) {
|
||
|
PrefabManage.loadPrefabByType(GameType.GuideMskNode, this.node, (prefab) => {
|
||
|
let guideNodeArray = nodeArray
|
||
|
this.maskGuideNode = prefab
|
||
|
let firstNode = guideNodeArray.shift()
|
||
|
prefab.getComponent(NewGuideScript).setBindNode(firstNode, guideNodeArray)
|
||
|
})
|
||
|
} else {
|
||
|
this.maskGuideNode.active = true
|
||
|
let guideNodeArray = nodeArray
|
||
|
let firstNode = guideNodeArray.shift()
|
||
|
this.maskGuideNode.getComponent(NewGuideScript).setBindNode(firstNode, guideNodeArray)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//再种一棵
|
||
|
onAgain() {
|
||
|
// Common5.playEffect("sound/按键点击");
|
||
|
for (const drip of this.dripArray) {
|
||
|
this.dripPool.put(drip);
|
||
|
}
|
||
|
this.dripArray = [];
|
||
|
|
||
|
this.dripNumber = 0;
|
||
|
this.refreshLevelDataView();
|
||
|
|
||
|
this.gameSettleView.active = false;
|
||
|
cc.tween(this.node.getChildByName('大树'))
|
||
|
.to(0.5, { x: 500 })
|
||
|
.call(() => {
|
||
|
this.saplingNode.getComponent(sp.Skeleton).setAnimation(0, '静止', true);
|
||
|
this.saplingNode.active = true;
|
||
|
this.isStopAll = false;
|
||
|
})
|
||
|
.set({ active: false, x: 0 })
|
||
|
.start();
|
||
|
}
|
||
|
|
||
|
//返回
|
||
|
onBack() {
|
||
|
// Common5.playEffect("sound/按键点击");
|
||
|
this.node.removeFromParent();
|
||
|
this.node.destroy();
|
||
|
|
||
|
EventMgr.emitEvent_custom(ryw_Event.ExitBtnEvent, '');
|
||
|
}
|
||
|
|
||
|
//重新开始
|
||
|
onRestart() {
|
||
|
// Common5.playEffect("sound/按键点击");
|
||
|
for (const drip of this.dripArray) {
|
||
|
this.dripPool.put(drip);
|
||
|
}
|
||
|
this.dripArray = [];
|
||
|
|
||
|
this.dripNumber = 0;
|
||
|
this.refreshLevelDataView();
|
||
|
|
||
|
this.isStopAll = false;
|
||
|
this.gameSettleView.active = false;
|
||
|
}
|
||
|
|
||
|
//复活继续
|
||
|
onContinue() {
|
||
|
// Common5.playEffect("sound/按键点击");
|
||
|
let tab = {
|
||
|
onClose: (finish) => {
|
||
|
if (finish) {
|
||
|
Common5.ReportDY("inLevel", '植树造林-AD-复活继续');
|
||
|
this.reportKey(() => {
|
||
|
GameReport.ADReport('植树造林复活继续', 1);
|
||
|
})
|
||
|
for (const drip of this.dripArray) {
|
||
|
this.dripPool.put(drip);
|
||
|
}
|
||
|
this.dripArray = [];
|
||
|
this.isStopAll = false;
|
||
|
this.gameSettleView.active = false;
|
||
|
this.updataRockState();
|
||
|
}
|
||
|
else {
|
||
|
this.reportKey(() => {
|
||
|
GameReport.ADReport('植树造林复活继续', 0);
|
||
|
})
|
||
|
Common5.showTips_custom("广告未观看完");
|
||
|
}
|
||
|
}, onFailed: () => { }
|
||
|
}
|
||
|
AppPlatform.playVideo_custom(tab);
|
||
|
}
|
||
|
}
|