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

185 lines
5.7 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 from "../JuQingChat/TaskManager";
2 months ago
import ZaoCanManager from "../Manager/ZaoCanManager";
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;
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
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start() {
2 months ago
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
let mainId = mainTaskInfo.Id
let index = User.getFirstStepIndex()
if (index == 3) { //早餐摊引导
return
}
2 months ago
//刷新早餐种类
this.refreshZaoCan()
EventMgr.onEvent_custom(ryw_Event.levelUpChange, () => {
//人物升级会变更早餐
this.refreshZaoCan()
}, this)
}
refreshZaoCan() {
let config = ZaoCanManager.getManagerConfigDate()
for (let i = 0; i < config.length; i++) {
2 months ago
let name = ZaoCanManager.getCurNameById(i)
2 months ago
this.ZaoCanArr[i] = name
}
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
}
runNpc() {
let npc = cc.instantiate(this.npc_Prefabs[Common5.getRandomNumber(0, this.npc_Prefabs.length - 1)])
this.npc_parent.addChild(npc)
let position = this.getNpcEndPosition()
let curDirect = this.lastDirect == Npc_Direct.LEFT ? Npc_Direct.RIGHT : Npc_Direct.LEFT
let index = Common5.getRandomNumber(0, this.ZaoCanArr.length - 1)
2 months ago
npc.getComponent(ZaoCanDianNpc).init(curDirect, position, this.ZaoCanArr[index], index, 1)
2 months ago
this.lastDirect = curDirect
this.npcNodes.push(npc)
}
getNpcEndPosition() {
let position
for (let i = 0; i < this.npc_Position_States.length; i++) {
let state = this.npc_Position_States[i]
if (!state.isHaveNpc) {
position = this.npc_Positions[i].getPosition()
this.npc_Position_States[i].isHaveNpc = true
break
}
}
return position
}
onTouchZaoCan(event, custom) {
let _npc = this.getNpcByNeedStr(custom)
if (!_npc) { //没有一个npc需要这个早餐直接返回
//所属物品摊位放大缩小
return
}
let _child
let _position
2 months ago
// 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()))
// }
let tanwei = this.node.getChildByName(custom + "摊位")
let children = tanwei.children
for (const child of children) {
if (child.active) {
_child = child
break
2 months ago
}
}
2 months ago
_position = tanwei.convertToNodeSpaceAR(_npc.parent.convertToWorldSpaceAR(_npc.getPosition()))
2 months ago
if (_child) {
cc.tween(_child)
.sequence(
cc.tween().to(0.5, { position: _position }),
cc.tween().call(() => {
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()
}
})
)
.start()
}
}
getNpcByNeedStr(needStr) {
let _npc = null
for (const npc of this.npcNodes) {
if (npc.getComponent(ZaoCanDianNpc).getNeedStr() == needStr) {
_npc = npc
break
}
}
return _npc
}
onTouchYeWu() {
}
onTouchShengJi() {
}
// update (dt) {}
}