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

151 lines
4.5 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
import Common5 from "../../Platform/th/Common5";
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 }]
ZaoCanArr = [
['馒头', '肉包', '烧卖', '红薯'],
['鸡蛋', '茶叶蛋', '玉米', '西兰花'],
['饺子', '韭菜盒子', '鸡蛋饼', '牛排'],
['油条', '麻球', '油饼', '鸡腿'],
['豆浆', '小米粥', '燕麦', '咖啡机'],
]
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start() {
//NPC,头上带气泡
//点击,点击完自动上架早餐
}
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)
npc.getComponent(ZaoCanDianNpc).init(curDirect, position, this.ZaoCanArr[index][0], index, 1)
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
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 (_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) {}
}