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.
484 lines
19 KiB
484 lines
19 KiB
// 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 Common5 from "../../Platform/th/Common5";
|
|
import TaskManager, { MainTaskIdEnum } from "../JuQingChat/TaskManager";
|
|
import JieDaoManager from "../Manager/JieDaoManager";
|
|
import UserManager from "../Manager/UserManager";
|
|
import ZaoCanManager from "../Manager/ZaoCanManager";
|
|
import PrefabManage, { GameType } from "../PrefabManager/PrefabManage";
|
|
import ZaoCanDianNpc from "./ZaoCanDianNpc";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
export enum Npc_Direct {
|
|
LEFT,
|
|
RIGHT,
|
|
}
|
|
|
|
type Npc_Position_State = {
|
|
isHaveNpc: boolean
|
|
}
|
|
|
|
@ccclass
|
|
export default class ZaoCanDian extends cc.Component {
|
|
|
|
@property([cc.Prefab])
|
|
npc_Prefabs: cc.Prefab[] = [];
|
|
|
|
@property([cc.Node])
|
|
npc_Positions: cc.Node[] = [];
|
|
|
|
@property(cc.Node)
|
|
npc_parent: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
npc_free_parent: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
fly_zaocan_parent: cc.Node = null;
|
|
|
|
@property(sp.Skeleton)
|
|
car: sp.Skeleton = null;
|
|
|
|
@property(sp.Skeleton)
|
|
tiehe: sp.Skeleton = null;
|
|
|
|
@property(cc.Sprite)
|
|
m_bg: cc.Sprite = null;
|
|
|
|
npcNodes: cc.Node[] = [];
|
|
lastDirect: Npc_Direct = Npc_Direct.RIGHT;
|
|
|
|
npc_Position_States: Npc_Position_State[] = [{ isHaveNpc: false }, { isHaveNpc: false }, { isHaveNpc: false }]
|
|
|
|
ZaoCanArr = []
|
|
|
|
//摊位动画状态
|
|
TanWeiSpineState = [false, false, false, false, false]
|
|
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {}
|
|
|
|
start() {
|
|
this.updateMainTask()
|
|
EventMgr.onEvent_custom(ryw_Event.updateMainTask, () => {
|
|
this.updateMainTask()
|
|
}, this)
|
|
|
|
//刷新早餐种类
|
|
this.refreshZaoCan()
|
|
EventMgr.onEvent_custom(ryw_Event.refreshZaoCan, () => {
|
|
//解锁会变更早餐
|
|
this.refreshZaoCan()
|
|
}, this)
|
|
|
|
//刷新街道
|
|
this.RefreshJieDao()
|
|
EventMgr.onEvent_custom(ryw_Event.RefreshJieDao, () => {
|
|
//解锁会变更早餐
|
|
this.RefreshJieDao()
|
|
}, this)
|
|
|
|
// 自动营业
|
|
EventMgr.onEvent_custom(ryw_Event.autoTimeEvent, () => {
|
|
this.autoTimeEvent()
|
|
}, this)
|
|
}
|
|
|
|
RefreshJieDao() {
|
|
Common5.getSpriteFrameFromBundle("ZaoCanDian", `res/图片${JieDaoManager.getJieDaoInUse() + 1}`, this.m_bg)
|
|
}
|
|
|
|
refreshZaoCan() {
|
|
//刷新当前摊位的早餐样式
|
|
//摊位节点名字
|
|
let names = ['馒头', '鸡蛋', '饺子', '油条', '豆浆']
|
|
//制作动画名
|
|
let animation_names1 = ['蒸', '煮', '', '', '']
|
|
//余几个的动画名
|
|
let animation_names2 = ['', '', '静止', '静止放', '']
|
|
for (let i = 0; i < 5; i++) {
|
|
let name = ZaoCanManager.getCurNameByType(i)
|
|
this.ZaoCanArr[i] = name
|
|
|
|
let tanwei = this.node.getChildByName("桌子").getChildByName(names[i] + "摊位")
|
|
let shengyuNum = 0
|
|
for (const child of this.fly_zaocan_parent.getChildByName(names[i] + "摊位").children) {
|
|
if (child.active) {
|
|
shengyuNum++
|
|
}
|
|
}
|
|
if (i <= 3) {
|
|
if (shengyuNum == 3) {
|
|
this.setTanWeiSpine(i, `${animation_names2[i]}${name}`, 3)
|
|
} else {
|
|
if (i == 2) {//饺子煎锅是直接补满,没有单独补的动画...
|
|
if (shengyuNum != 0) {
|
|
this.setTanWeiSpine(i, `${animation_names2[i]}${name}`, 3)
|
|
}
|
|
} else {
|
|
this.setTanWeiSpine(i, `${animation_names2[i]}${name}余${shengyuNum}`, shengyuNum)
|
|
}
|
|
|
|
}
|
|
} else {
|
|
//豆浆特殊,只有1个
|
|
let tanweiSpine = tanwei.getComponent(sp.Skeleton)
|
|
tanweiSpine.setAnimation(0, name, false)
|
|
}
|
|
}
|
|
|
|
for (let i = this.npcNodes.length - 1; i >= 0; i--) {
|
|
this.npcNodes[i].removeFromParent()
|
|
this.npcNodes[i].destroy()
|
|
this.npc_Position_States[i].isHaveNpc = false
|
|
}
|
|
this.npcNodes = []
|
|
|
|
// this.runNpc()
|
|
this.unschedule(this.npcUpdate)
|
|
this.schedule(this.npcUpdate, 1)
|
|
}
|
|
|
|
npcUpdate() {
|
|
this.runNpc()
|
|
}
|
|
|
|
runNpc() {
|
|
let stateIndex = this.getNpcEndIndex()
|
|
if (stateIndex != null && stateIndex != undefined) {
|
|
let npc = cc.instantiate(this.npc_Prefabs[Common5.getRandomNumber(0, this.npc_Prefabs.length - 1)])
|
|
this.npc_parent.addChild(npc)
|
|
let curDirect = this.lastDirect == Npc_Direct.LEFT ? Npc_Direct.RIGHT : Npc_Direct.LEFT
|
|
let index = Common5.getRandomNumber(0, this.ZaoCanArr.length - 1)
|
|
npc.getComponent(ZaoCanDianNpc).init(curDirect, this.npc_Positions[stateIndex].getPosition(), this.ZaoCanArr[index], stateIndex, 1)
|
|
// npc.getComponent(ZaoCanDianNpc).init(curDirect, this.npc_Positions[stateIndex].getPosition(), "油条", stateIndex, 1)
|
|
this.lastDirect = curDirect
|
|
this.npcNodes.push(npc)
|
|
} else {
|
|
// //逛街
|
|
// let npc = cc.instantiate(this.npc_Prefabs[Common5.getRandomNumber(0, this.npc_Prefabs.length - 1)])
|
|
// this.npc_free_parent.addChild(npc)
|
|
// let curDirect = this.lastDirect == Npc_Direct.LEFT ? Npc_Direct.RIGHT : Npc_Direct.LEFT
|
|
// npc.getComponent(ZaoCanDianNpc).init(curDirect, null, '', -1, 0)
|
|
// this.lastDirect = curDirect
|
|
}
|
|
|
|
}
|
|
|
|
getNpcEndIndex() {
|
|
let index
|
|
for (let i = 0; i < this.npc_Position_States.length; i++) {
|
|
let state = this.npc_Position_States[i]
|
|
if (!state.isHaveNpc) {
|
|
index = i
|
|
this.npc_Position_States[i].isHaveNpc = true
|
|
break
|
|
}
|
|
}
|
|
return index
|
|
}
|
|
|
|
onTouchZaoCan(event, custom) {
|
|
custom = Number(custom) //对应ZaoCanManager的zaocanConfig下标
|
|
//摊位动画正在运行直接返回
|
|
if (this.TanWeiSpineState[custom]) {
|
|
return
|
|
}
|
|
let zaoCanStr = ZaoCanManager.getCurNameByType(custom)
|
|
let _npc = this.getNpcByNeedStr(zaoCanStr)
|
|
|
|
//摊位节点名字
|
|
let names = ['馒头', '鸡蛋', '饺子', '油条', '豆浆']
|
|
//制作动画名
|
|
let animation_names1 = ['蒸', '煮', '', '', '']
|
|
//余几个的动画名
|
|
let animation_names2 = ['', '', '静止', '静止放', '']
|
|
let tanwei = this.node.getChildByName("桌子").getChildByName(names[custom] + "摊位")
|
|
|
|
let shengyuNum = 0
|
|
let _child
|
|
let children = this.fly_zaocan_parent.getChildByName(names[custom] + "摊位").children
|
|
for (let i = children.length - 1; i >= 0; i--) {
|
|
let child = children[i]
|
|
if (child.active) {
|
|
if (!_child) {
|
|
_child = child
|
|
}
|
|
shengyuNum++
|
|
}
|
|
}
|
|
|
|
if (!_npc) { //没有一个npc需要这个早餐
|
|
//补货,少几个补几个
|
|
if (custom <= 3) {//豆浆桶不需要补货
|
|
if (shengyuNum < 3) {
|
|
if (shengyuNum == 0) {
|
|
//手动补货,补全
|
|
this.setTanWeiSpine(custom, `${animation_names1[custom]}${zaoCanStr}`, 3)
|
|
} else {
|
|
if (custom == 2) {//饺子煎锅是直接补满,没有单独补的动画...
|
|
this.setTanWeiSpine(custom, `${animation_names1[custom]}${zaoCanStr}`, 3)
|
|
} else {
|
|
this.setTanWeiSpine(custom, `${animation_names1[custom]}${zaoCanStr}余${shengyuNum}`, 3)
|
|
}
|
|
}
|
|
} else {
|
|
//所属物品摊位放大缩小
|
|
cc.tween(tanwei)
|
|
.sequence(
|
|
cc.tween().set({ scale: 1 }),
|
|
cc.tween().to(0.1, { scale: 1.1 }),
|
|
cc.tween().to(0.1, { scale: 1 })
|
|
)
|
|
.start()
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
let com = _npc.getComponent(ZaoCanDianNpc)
|
|
let _position = this.fly_zaocan_parent.convertToNodeSpaceAR(com.getZaoCanWorldPosition())
|
|
if (custom <= 3) {
|
|
if (shengyuNum == 0) {
|
|
//手动补货,补全
|
|
this.setTanWeiSpine(custom, `${animation_names1[custom]}${zaoCanStr}`, 3)
|
|
return
|
|
} if (shengyuNum == 1) {
|
|
//自动补货,补全
|
|
this.setTanWeiSpine(custom, `${animation_names1[custom]}${zaoCanStr}`, 3)
|
|
} else {
|
|
this.setTanWeiSpine(custom, `${animation_names2[custom]}${zaoCanStr}余${shengyuNum - 1}`, shengyuNum - 1)
|
|
}
|
|
|
|
//先减需要的量
|
|
let needNum = com.getNeedNum() - 1
|
|
com.setNeedNum(needNum)
|
|
|
|
if (_child) {
|
|
let child = cc.instantiate(_child)
|
|
child.setScale(1.3)
|
|
this.fly_zaocan_parent.addChild(child)
|
|
let startPosition = this.fly_zaocan_parent.convertToNodeSpaceAR(_child.parent.convertToWorldSpaceAR(_child.getPosition()))
|
|
child.setPosition(startPosition)
|
|
child.active = true
|
|
Common5.getSpriteFrameFromBundle("ZaoCanDian", "res/icon/" + zaoCanStr, child.getComponent(cc.Sprite))
|
|
let time = _position.sub(startPosition).mag() / 1500
|
|
let middlePos = startPosition.add(_position).div(2)
|
|
let c1 = cc.v2(startPosition.x, middlePos.y)
|
|
let c2 = cc.v2(middlePos.x, _position.y)
|
|
cc.tween(child)
|
|
.sequence(
|
|
cc.tween().bezierTo(time, c1, c2, _position),
|
|
// cc.tween().to(time, { position: _position }),
|
|
cc.tween().call(() => {
|
|
UserManager.addMoney(ZaoCanManager.getDanJia(), child)
|
|
let com = _npc.getComponent(ZaoCanDianNpc)
|
|
com.setNeedNumLabel()
|
|
if (com.getNeedNum() == 0) {
|
|
this.npc_Position_States[com.getStateIndex()].isHaveNpc = false
|
|
com.getZaoCanAfter()
|
|
for (let j = this.npcNodes.length - 1; j >= 0; j--) {
|
|
if (this.npcNodes[j] === com.node) {
|
|
this.npcNodes.splice(j, 1)
|
|
}
|
|
}
|
|
}
|
|
child.removeFromParent()
|
|
child.destroy()
|
|
})
|
|
)
|
|
.start()
|
|
}
|
|
} else {
|
|
//先减需要的量
|
|
let com = _npc.getComponent(ZaoCanDianNpc)
|
|
let needNum = com.getNeedNum() - 1
|
|
com.setNeedNum(needNum)
|
|
|
|
//豆浆特殊
|
|
let tanweiSpine = tanwei.getComponent(sp.Skeleton)
|
|
this.TanWeiSpineState[custom] = true
|
|
tanweiSpine.setAnimation(0, `装${zaoCanStr}`, false)
|
|
tanweiSpine.setCompleteListener(() => {
|
|
tanweiSpine.setCompleteListener(null)
|
|
this.TanWeiSpineState[custom] = false
|
|
let _child = this.fly_zaocan_parent.getChildByName(names[custom] + "摊位").children[0]
|
|
let child = cc.instantiate(_child)
|
|
child.setScale(1.3)
|
|
this.fly_zaocan_parent.addChild(child)
|
|
let startPosition = this.fly_zaocan_parent.convertToNodeSpaceAR(_child.parent.convertToWorldSpaceAR(_child.getPosition()))
|
|
child.setPosition(startPosition)
|
|
child.active = true
|
|
Common5.getSpriteFrameFromBundle("ZaoCanDian", "res/icon/" + zaoCanStr, child.getComponent(cc.Sprite))
|
|
let time = _position.sub(startPosition).mag() / 1500
|
|
let middlePos = startPosition.add(_position).div(2)
|
|
let c1 = cc.v2(startPosition.x, middlePos.y)
|
|
let c2 = cc.v2(middlePos.x, _position.y)
|
|
cc.tween(child)
|
|
.sequence(
|
|
cc.tween().bezierTo(time, c1, c2, _position),
|
|
// cc.tween().to(time, { position: _position }),
|
|
cc.tween().call(() => {
|
|
UserManager.addMoney(ZaoCanManager.getDanJia(), child)
|
|
let com = _npc.getComponent(ZaoCanDianNpc)
|
|
com.setNeedNumLabel()
|
|
if (com.getNeedNum() == 0) {
|
|
this.npc_Position_States[com.getStateIndex()].isHaveNpc = false
|
|
com.getZaoCanAfter()
|
|
for (let j = this.npcNodes.length - 1; j >= 0; j--) {
|
|
if (this.npcNodes[j] === com.node) {
|
|
this.npcNodes.splice(j, 1)
|
|
}
|
|
}
|
|
}
|
|
child.removeFromParent()
|
|
child.destroy()
|
|
})
|
|
)
|
|
.start()
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
getNpcByNeedStr(needStr) {
|
|
let _npc = null
|
|
for (const npc of this.npcNodes) {
|
|
if (npc.getComponent(ZaoCanDianNpc).getNeedStr() == needStr && npc.getComponent(ZaoCanDianNpc).getNeedNum() > 0) {
|
|
_npc = npc
|
|
break
|
|
}
|
|
}
|
|
return _npc
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param tanweiIndex 摊位下标
|
|
* @param animation 动画名
|
|
* @param showNum 需要显示几个早餐
|
|
* @param loop 循环播放
|
|
*/
|
|
setTanWeiSpine(tanweiIndex, animation, showNum, loop = false) {
|
|
if (!showNum) {
|
|
return
|
|
}
|
|
|
|
// 制作音效
|
|
if (showNum == 3) {
|
|
let effecturl = ZaoCanManager.getEffectUrlByType(tanweiIndex)
|
|
Common5.playEffectCustom('ZaoCanDian', effecturl)
|
|
}
|
|
let names = ['馒头', '鸡蛋', '饺子', '油条', '豆浆']
|
|
let tanwei = this.node.getChildByName("桌子").getChildByName(names[tanweiIndex] + "摊位")
|
|
let tanweiSpine = tanwei.getComponent(sp.Skeleton)
|
|
this.TanWeiSpineState[tanweiIndex] = true
|
|
tanweiSpine.setCompleteListener(() => {
|
|
tanweiSpine.setCompleteListener(null)
|
|
this.TanWeiSpineState[tanweiIndex] = false
|
|
if (tanweiIndex == 0) {
|
|
Common5.playEffectCustom('ZaoCanDian', 'sound/蒸笼/出锅')
|
|
}
|
|
this.scheduleOnce(() => {
|
|
Common5.playEffectCustom('ZaoCanDian', 'sound/通用/制作完成')
|
|
})
|
|
for (let i = 3; i > 0; i--) {
|
|
if (showNum >= i) {
|
|
console.log("显示===", i)
|
|
this.fly_zaocan_parent.getChildByName(names[tanweiIndex] + "摊位").getChildByName(`${i}`).active = true
|
|
} else {
|
|
this.fly_zaocan_parent.getChildByName(names[tanweiIndex] + "摊位").getChildByName(`${i}`).active = false
|
|
}
|
|
}
|
|
})
|
|
tanweiSpine.setAnimation(0, animation, loop)
|
|
}
|
|
|
|
onTouchYeWu() {
|
|
|
|
}
|
|
|
|
onTouchShengJi() {
|
|
|
|
}
|
|
|
|
onTouchCar() {
|
|
this.car.setAnimation(0, "开走", false)
|
|
this.car.setCompleteListener(() => {
|
|
this.car.setCompleteListener(null)
|
|
cc.tween(this.car.node)
|
|
.by(0.2, { position: cc.v3(-100, 0, 0) })
|
|
.start()
|
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.Id
|
|
if (mainId == MainTaskIdEnum.MainTask_303 || mainId == MainTaskIdEnum.MainTask_401 || mainId == MainTaskIdEnum.MainTask_402) {
|
|
PrefabManage.loadPrefabByType(GameType.Room2)
|
|
} else if (mainId == MainTaskIdEnum.MainTask_501) {
|
|
PrefabManage.loadPrefabByType(GameType.DH_1)
|
|
} else if (mainId == MainTaskIdEnum.MainTask_503) {
|
|
PrefabManage.loadPrefabByType(GameType.DH_5)
|
|
} else if (mainId == MainTaskIdEnum.MainTask_602) {
|
|
PrefabManage.loadPrefabByType(GameType.GameStory4)
|
|
} else if (mainId == MainTaskIdEnum.MainTask_605 || mainId == MainTaskIdEnum.MainTask_606) {
|
|
PrefabManage.loadPrefabByType(GameType.DH_3)
|
|
} else if (mainId == MainTaskIdEnum.MainTask_701 || mainId == MainTaskIdEnum.MainTask_702) {
|
|
PrefabManage.loadPrefabByType(GameType.DH_4)
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
updateMainTask() {
|
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.Id
|
|
let config = TaskManager.getTaskConfigById(mainId)
|
|
let index = User.getFirstStepIndex()
|
|
// if (index == 3) { //早餐摊引导
|
|
|
|
// return
|
|
// }
|
|
if (config && config.wanFaRuKouTip && config.wanFaRuKouTip.includes('rk_chuZuChe')) {
|
|
this.car.node.active = true
|
|
this.car.setAnimation(0, "空车", false)
|
|
this.car.node.setPosition(cc.v3(0, this.car.node.position.y, 0))
|
|
} else {
|
|
this.car.node.active = false
|
|
}
|
|
}
|
|
|
|
onTouchTieHe() {
|
|
this.tiehe.setAnimation(0, "抖动", false)
|
|
let level = User.getMyLevel()
|
|
let money = 2 * Math.pow(1.025, (level - 1))
|
|
UserManager.addMoney(money, this.tiehe.node)
|
|
}
|
|
|
|
autoTimeEvent() {
|
|
let names = ['馒头', '鸡蛋', '饺子', '油条', '豆浆']
|
|
let autoClickTime = User.getAutoClickTime()
|
|
if (autoClickTime <= 0) {
|
|
|
|
} else {
|
|
for (let i = 0; i < 5; i++) {
|
|
let zaoCanStr = ZaoCanManager.getCurNameByType(i)
|
|
let _npc = this.getNpcByNeedStr(zaoCanStr)
|
|
if (_npc) {
|
|
this.onTouchZaoCan(this.node.getChildByName("桌子").getChildByName(names[i] + "摊位").getChildByName("touch"), i)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// update (dt) {}
|
|
}
|
|
|