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.
303 lines
10 KiB
303 lines
10 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 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(sp.Skeleton)
|
|
car: sp.Skeleton = 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() {
|
|
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
|
|
} else {
|
|
this.car.node.active = false
|
|
}
|
|
//刷新早餐种类
|
|
this.refreshZaoCan()
|
|
EventMgr.onEvent_custom(ryw_Event.refreshZaoCan, () => {
|
|
//解锁会变更早餐
|
|
this.refreshZaoCan()
|
|
}, this)
|
|
}
|
|
|
|
refreshZaoCan() {
|
|
//刷新当前摊位的早餐样式
|
|
let names = ['馒头', '鸡蛋', '饺子', '油条', '豆浆']
|
|
for (let i = 0; i < 5; i++) {
|
|
let name = ZaoCanManager.getCurNameByType(i)
|
|
this.ZaoCanArr[i] = name
|
|
|
|
let tanwei = this.node.getChildByName(names[i] + "摊位")
|
|
let shengyuNum = 0
|
|
for (const child of tanwei.getChildByName("touch").children) {
|
|
if (child.active) {
|
|
shengyuNum++
|
|
}
|
|
}
|
|
if (i == 3) {
|
|
if (shengyuNum == 3) {
|
|
this.setTanWeiSpine(i, `静止放${name}`, 3)
|
|
} else {
|
|
this.setTanWeiSpine(i, `静止放${name}余${shengyuNum}`, shengyuNum)
|
|
}
|
|
}
|
|
}
|
|
|
|
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()
|
|
}
|
|
|
|
runNpc() {
|
|
let npc = cc.instantiate(this.npc_Prefabs[Common5.getRandomNumber(0, this.npc_Prefabs.length - 1)])
|
|
this.npc_parent.addChild(npc)
|
|
let stateIndex = this.getNpcEndIndex()
|
|
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, position, this.ZaoCanArr[index], index, 1)
|
|
npc.getComponent(ZaoCanDianNpc).init(curDirect, this.npc_Positions[stateIndex].getPosition(), "油条", stateIndex, 1)
|
|
this.lastDirect = curDirect
|
|
this.npcNodes.push(npc)
|
|
}
|
|
|
|
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 target = event.target
|
|
let zaoCanStr = ZaoCanManager.getCurNameByType(custom)
|
|
let _npc = this.getNpcByNeedStr(zaoCanStr)
|
|
let children = target.children
|
|
let names = ['馒头', '鸡蛋', '饺子', '油条', '豆浆']
|
|
let tanwei = this.node.getChildByName(names[custom] + "摊位")
|
|
|
|
let shengyuNum = 0
|
|
let _child
|
|
for (const child of children) {
|
|
if (child.active) {
|
|
if (!_child) {
|
|
_child = child
|
|
}
|
|
shengyuNum++
|
|
}
|
|
}
|
|
if (!_npc) { //没有一个npc需要这个早餐
|
|
//补货,少几个补几个
|
|
if (shengyuNum < 3) {
|
|
if (shengyuNum == 0) {
|
|
//手动补货,补全
|
|
this.setTanWeiSpine(custom, zaoCanStr, 3)
|
|
} else {
|
|
this.setTanWeiSpine(custom, `${zaoCanStr}余${shengyuNum}`, 3)
|
|
}
|
|
} else {
|
|
//所属物品摊位放大缩小
|
|
}
|
|
return
|
|
}
|
|
let _position
|
|
// if (custom == "馒头") {
|
|
// let tanwei = this.node.getChildByName("馒头摊位")
|
|
// let children = tanwei.children
|
|
// for (const child of children) {
|
|
// if (child.active) {
|
|
// _child = child
|
|
// break
|
|
// }
|
|
// }
|
|
// _position = tanwei.convertToNodeSpaceAR(_npc.parent.convertToWorldSpaceAR(_npc.getPosition()))
|
|
// } else if (custom == "鸡蛋") {
|
|
// let tanwei = this.node.getChildByName("鸡蛋摊位")
|
|
// let children = tanwei.children
|
|
// for (const child of children) {
|
|
// if (child.active) {
|
|
// _child = child
|
|
// break
|
|
// }
|
|
// }
|
|
// _position = tanwei.convertToNodeSpaceAR(_npc.parent.convertToWorldSpaceAR(_npc.getPosition()))
|
|
// }
|
|
|
|
if (shengyuNum == 0) {
|
|
//手动补货,补全
|
|
this.setTanWeiSpine(custom, zaoCanStr, 3)
|
|
return
|
|
} if (shengyuNum == 1) {
|
|
//自动补货,补全
|
|
this.setTanWeiSpine(custom, zaoCanStr, 3)
|
|
} else {
|
|
this.setTanWeiSpine(custom, `静止放${zaoCanStr}余${shengyuNum - 1}`, shengyuNum - 1)
|
|
}
|
|
_position = target.convertToNodeSpaceAR(_npc.parent.convertToWorldSpaceAR(_npc.getPosition()))
|
|
|
|
let oldPosition = _child.getPosition()
|
|
if (_child) {
|
|
cc.tween(_child)
|
|
.sequence(
|
|
cc.tween().to(0.5, { position: _position }),
|
|
cc.tween().call(() => {
|
|
_child.active = false
|
|
_child.setPosition(oldPosition)
|
|
let com = _npc.getComponent(ZaoCanDianNpc)
|
|
let needNum = com.getNeedNum() - 1
|
|
com.setNeedNum(needNum)
|
|
if (needNum == 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)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
)
|
|
.start()
|
|
}
|
|
}
|
|
|
|
getNpcByNeedStr(needStr) {
|
|
let _npc = null
|
|
for (const npc of this.npcNodes) {
|
|
if (npc.getComponent(ZaoCanDianNpc).getNeedStr() == needStr) {
|
|
_npc = npc
|
|
break
|
|
}
|
|
}
|
|
return _npc
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param tanweiIndex 摊位下标
|
|
* @param animation 动画名
|
|
* @param showNum 需要显示几个早餐
|
|
* @param loop 循环播放
|
|
*/
|
|
setTanWeiSpine(tanweiIndex, animation, showNum, loop = false) {
|
|
if (!showNum) {
|
|
return
|
|
}
|
|
let names = ['馒头', '鸡蛋', '饺子', '油条', '豆浆']
|
|
let tanwei = this.node.getChildByName(names[tanweiIndex] + "摊位")
|
|
let tanweiSpine = tanwei.getComponent(sp.Skeleton)
|
|
this.TanWeiSpineState[tanweiIndex] = true
|
|
tanweiSpine.setAnimation(0, animation, loop)
|
|
tanweiSpine.setCompleteListener(() => {
|
|
this.TanWeiSpineState[tanweiIndex] = false
|
|
for (let i = 3; i > 0; i--) {
|
|
if (showNum >= i) {
|
|
tanwei.getChildByName("touch").getChildByName(`${i}`).active = true
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
onTouchYeWu() {
|
|
|
|
}
|
|
|
|
onTouchShengJi() {
|
|
|
|
}
|
|
|
|
onTouchCar() {
|
|
this.car.setAnimation(0, "开走", false)
|
|
this.car.setCompleteListener(() => {
|
|
this.car.setCompleteListener(null)
|
|
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_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)
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
// update (dt) {}
|
|
}
|
|
|