咸鱼的反击
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.

485 lines
19 KiB

2 months 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
2 months ago
import { ryw_Event } from "../../FrameWork/Event/EventEnum";
import EventMgr from "../../FrameWork/Event/EventMgr";
2 months ago
import User from "../../FrameWork/User/User";
2 months ago
import Common5 from "../../Platform/th/Common5";
2 months ago
import TaskManager, { MainTaskIdEnum } from "../JuQingChat/TaskManager";
2 months ago
import JieDaoManager from "../Manager/JieDaoManager";
2 months ago
import UserManager from "../Manager/UserManager";
2 months ago
import ZaoCanManager from "../Manager/ZaoCanManager";
2 months ago
import PrefabManage, { GameType } from "../PrefabManager/PrefabManage";
2 months ago
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;
2 months ago
@property(cc.Node)
npc_free_parent: cc.Node = null;
@property(cc.Node)
fly_zaocan_parent: cc.Node = null;
2 months ago
@property(sp.Skeleton)
car: sp.Skeleton = null;
2 months ago
@property(sp.Skeleton)
tiehe: sp.Skeleton = null;
2 months ago
@property(cc.Sprite)
m_bg: cc.Sprite = null;
2 months ago
npcNodes: cc.Node[] = [];
lastDirect: Npc_Direct = Npc_Direct.RIGHT;
npc_Position_States: Npc_Position_State[] = [{ isHaveNpc: false }, { isHaveNpc: false }, { isHaveNpc: false }]
2 months ago
ZaoCanArr = []
2 months ago
2 months ago
//摊位动画状态
TanWeiSpineState = [false, false, false, false, false]
2 months ago
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start() {
2 months ago
this.updateMainTask()
EventMgr.onEvent_custom(ryw_Event.updateMainTask, () => {
this.updateMainTask()
}, this)
2 months ago
2 months ago
//刷新早餐种类
this.refreshZaoCan()
2 months ago
EventMgr.onEvent_custom(ryw_Event.refreshZaoCan, () => {
//解锁会变更早餐
2 months ago
this.refreshZaoCan()
}, this)
2 months ago
//刷新街道
this.RefreshJieDao()
EventMgr.onEvent_custom(ryw_Event.RefreshJieDao, () => {
//解锁会变更早餐
this.RefreshJieDao()
}, this)
2 months ago
// 自动营业
EventMgr.onEvent_custom(ryw_Event.autoTimeEvent, () => {
this.autoTimeEvent()
}, this)
2 months ago
}
RefreshJieDao() {
Common5.getSpriteFrameFromBundle("ZaoCanDian", `res/图片${JieDaoManager.getJieDaoInUse() + 1}`, this.m_bg)
2 months ago
}
refreshZaoCan() {
2 months ago
//刷新当前摊位的早餐样式
2 months ago
//摊位节点名字
2 months ago
let names = ['馒头', '鸡蛋', '饺子', '油条', '豆浆']
2 months ago
//制作动画名
2 months ago
let animation_names1 = ['蒸', '煮', '', '', '']
2 months ago
//余几个的动画名
2 months ago
let animation_names2 = ['', '', '静止', '静止放', '']
2 months ago
for (let i = 0; i < 5; i++) {
let name = ZaoCanManager.getCurNameByType(i)
2 months ago
this.ZaoCanArr[i] = name
2 months ago
2 months ago
let tanwei = this.node.getChildByName("桌子").getChildByName(names[i] + "摊位")
2 months ago
let shengyuNum = 0
2 months ago
for (const child of this.fly_zaocan_parent.getChildByName(names[i] + "摊位").children) {
2 months ago
if (child.active) {
shengyuNum++
}
}
2 months ago
if (i <= 3) {
2 months ago
if (shengyuNum == 3) {
2 months ago
this.setTanWeiSpine(i, `${animation_names2[i]}${name}`, 3)
2 months ago
} else {
2 months ago
if (i == 2) {//饺子煎锅是直接补满,没有单独补的动画...
if (shengyuNum != 0) {
this.setTanWeiSpine(i, `${animation_names2[i]}${name}`, 3)
}
} else {
this.setTanWeiSpine(i, `${animation_names2[i]}${name}${shengyuNum}`, shengyuNum)
}
2 months ago
}
2 months ago
} else {
//豆浆特殊,只有1个
let tanweiSpine = tanwei.getComponent(sp.Skeleton)
tanweiSpine.setAnimation(0, name, false)
2 months ago
}
2 months ago
}
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 = []
2 months ago
2 months ago
// this.runNpc()
2 months ago
this.unschedule(this.npcUpdate)
this.schedule(this.npcUpdate, 1)
}
npcUpdate() {
this.runNpc()
2 months ago
}
runNpc() {
2 months ago
let stateIndex = this.getNpcEndIndex()
2 months ago
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
}
2 months ago
}
2 months ago
getNpcEndIndex() {
let index
2 months ago
for (let i = 0; i < this.npc_Position_States.length; i++) {
let state = this.npc_Position_States[i]
if (!state.isHaveNpc) {
2 months ago
index = i
2 months ago
this.npc_Position_States[i].isHaveNpc = true
break
}
}
2 months ago
return index
2 months ago
}
onTouchZaoCan(event, custom) {
2 months ago
custom = Number(custom) //对应ZaoCanManager的zaocanConfig下标
//摊位动画正在运行直接返回
if (this.TanWeiSpineState[custom]) {
2 months ago
return
}
2 months ago
let zaoCanStr = ZaoCanManager.getCurNameByType(custom)
2 months ago
let _npc = this.getNpcByNeedStr(zaoCanStr)
2 months ago
2 months ago
//摊位节点名字
let names = ['馒头', '鸡蛋', '饺子', '油条', '豆浆']
2 months ago
//制作动画名
2 months ago
let animation_names1 = ['蒸', '煮', '', '', '']
2 months ago
//余几个的动画名
2 months ago
let animation_names2 = ['', '', '静止', '静止放', '']
let tanwei = this.node.getChildByName("桌子").getChildByName(names[custom] + "摊位")
2 months ago
let shengyuNum = 0
2 months ago
let _child
2 months ago
let children = this.fly_zaocan_parent.getChildByName(names[custom] + "摊位").children
for (let i = children.length - 1; i >= 0; i--) {
let child = children[i]
2 months ago
if (child.active) {
if (!_child) {
_child = child
}
shengyuNum++
}
}
2 months ago
2 months ago
if (!_npc) { //没有一个npc需要这个早餐
//补货,少几个补几个
2 months ago
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)
}
}
2 months ago
} else {
2 months ago
//所属物品摊位放大缩小
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()
2 months ago
}
2 months ago
}
return
}
2 months ago
2 months ago
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()
}
2 months ago
} else {
2 months ago
//先减需要的量
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)
}
2 months ago
}
}
2 months ago
child.removeFromParent()
child.destroy()
})
)
.start()
})
2 months ago
}
2 months ago
2 months ago
}
getNpcByNeedStr(needStr) {
let _npc = null
for (const npc of this.npcNodes) {
2 months ago
if (npc.getComponent(ZaoCanDianNpc).getNeedStr() == needStr && npc.getComponent(ZaoCanDianNpc).getNeedNum() > 0) {
2 months ago
_npc = npc
break
}
}
return _npc
}
2 months ago
/**
*
* @param tanweiIndex
* @param animation
* @param showNum
* @param loop
*/
setTanWeiSpine(tanweiIndex, animation, showNum, loop = false) {
if (!showNum) {
return
}
2 months ago
// 制作音效
if (showNum == 3) {
let effecturl = ZaoCanManager.getEffectUrlByType(tanweiIndex)
Common5.playEffectCustom('ZaoCanDian', effecturl)
}
2 months ago
let names = ['馒头', '鸡蛋', '饺子', '油条', '豆浆']
2 months ago
let tanwei = this.node.getChildByName("桌子").getChildByName(names[tanweiIndex] + "摊位")
2 months ago
let tanweiSpine = tanwei.getComponent(sp.Skeleton)
this.TanWeiSpineState[tanweiIndex] = true
tanweiSpine.setCompleteListener(() => {
2 months ago
tanweiSpine.setCompleteListener(null)
2 months ago
this.TanWeiSpineState[tanweiIndex] = false
2 months ago
if (tanweiIndex == 0) {
Common5.playEffectCustom('ZaoCanDian', 'sound/蒸笼/出锅')
}
this.scheduleOnce(() => {
Common5.playEffectCustom('ZaoCanDian', 'sound/通用/制作完成')
})
2 months ago
for (let i = 3; i > 0; i--) {
if (showNum >= i) {
2 months ago
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
2 months ago
}
}
})
2 months ago
tanweiSpine.setAnimation(0, animation, loop)
2 months ago
}
2 months ago
onTouchYeWu() {
}
onTouchShengJi() {
}
2 months ago
onTouchCar() {
this.car.setAnimation(0, "开走", false)
this.car.setCompleteListener(() => {
this.car.setCompleteListener(null)
2 months ago
cc.tween(this.car.node)
.by(0.2, { position: cc.v3(-100, 0, 0) })
.start()
2 months ago
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
let mainId = mainTaskInfo.Id
2 months ago
if (mainId == MainTaskIdEnum.MainTask_303 || mainId == MainTaskIdEnum.MainTask_401 || mainId == MainTaskIdEnum.MainTask_402) {
PrefabManage.loadPrefabByType(GameType.Room2)
2 months ago
} else if (mainId == MainTaskIdEnum.MainTask_501) {
PrefabManage.loadPrefabByType(GameType.DH_1)
2 months ago
} else if (mainId == MainTaskIdEnum.MainTask_503) {
2 months ago
PrefabManage.loadPrefabByType(GameType.DH_5)
2 months ago
} else if (mainId == MainTaskIdEnum.MainTask_602) {
PrefabManage.loadPrefabByType(GameType.GameStory4)
2 months ago
} 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)
}
})
}
2 months ago
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
2 months ago
this.car.setAnimation(0, "空车", false)
2 months ago
this.car.node.setPosition(cc.v3(0, this.car.node.position.y, 0))
} else {
this.car.node.active = false
}
}
2 months ago
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)
}
}
}
}
2 months ago
// update (dt) {}
}