mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交捕捉
This commit is contained in:
9
JisolGameCocos/assets/script/manager/battle/mode.meta
Normal file
9
JisolGameCocos/assets/script/manager/battle/mode.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "ec650551-a3f2-4b5c-a9bb-a4fd649dbdbd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
import { GOnHookPet } from "../../../../../extensions/ngame/assets/ngame/message/proto";
|
||||
import Singleton from "../../../../../extensions/ngame/assets/ngame/util/Singleton";
|
||||
import { app } from "../../../App";
|
||||
import { PlayerPetOV } from "../../../consts/API";
|
||||
import { GAPI } from "../../../consts/GAPI";
|
||||
import PlayerPetData from "../../../data/PlayerPetData";
|
||||
import { GUI } from "../../../ui/UIConfig";
|
||||
|
||||
export enum GOnHookManagerEvent{
|
||||
//添加死亡野怪
|
||||
ADD_KILL_SREEP = "GOnHookManagerEvent_ADD_KILL_SREEP",
|
||||
//删除死亡野怪
|
||||
DEL_KILL_SREEP = "GOnHookManagerEvent_DEL_KILL_SREEP"
|
||||
}
|
||||
|
||||
//游戏模式 OnHook 管理器
|
||||
export default class GOnHookManager extends Singleton{
|
||||
|
||||
//野怪列表
|
||||
_sreeps:Map<string,GOnHookPet> = new Map();
|
||||
get sreeps(){
|
||||
//如果没有野怪了 则 向服务器生成
|
||||
if(!this._sreeps || !(this._sreeps.size)){
|
||||
//生成
|
||||
this.onSpawnSreeps();
|
||||
return null;
|
||||
}
|
||||
return this._sreeps;
|
||||
}
|
||||
set sreeps(data:Map<string,GOnHookPet>){
|
||||
this._sreeps = data;
|
||||
}
|
||||
|
||||
//已经死亡的野怪列表
|
||||
killSreeps:GOnHookPet[] = [];
|
||||
|
||||
|
||||
//生成野怪
|
||||
onSpawnSreeps(){
|
||||
GAPI.GOnHookSpawnCreeps().then(data => {
|
||||
data.pets.forEach(pet => {
|
||||
this._sreeps.set(pet.key,pet as GOnHookPet);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
//获取下一只野怪
|
||||
getNextCreeps(){
|
||||
if(!this.sreeps) return;
|
||||
let creeps = this.sreeps.get(this.sreeps.keys().next()?.value)
|
||||
return creeps;
|
||||
}
|
||||
|
||||
//野怪死亡
|
||||
onKillSreeps(creeps:GOnHookPet){
|
||||
|
||||
this.sreeps.delete(creeps.key);
|
||||
//记入死亡
|
||||
//判断是否在死亡中如果在则跳出
|
||||
if(this.killSreeps.indexOf(creeps) > -1){
|
||||
return;
|
||||
}
|
||||
this.killSreeps.push(creeps);
|
||||
|
||||
//通知添加死亡野怪
|
||||
app.event.emit(GOnHookManagerEvent.ADD_KILL_SREEP,creeps);
|
||||
|
||||
console.log(`GOnHookManager : ${creeps.key} 宠物死亡 可进行捕捉 出售`);
|
||||
|
||||
}
|
||||
|
||||
//捕捉野怪
|
||||
async onCatchCreeps(creeps:GOnHookPet):Promise<boolean>{
|
||||
|
||||
let index;
|
||||
if((index = this.killSreeps.indexOf(creeps)) < 0){
|
||||
app.layer.Open(GUI.Tips,{text:"不可捕捉该宠物"});
|
||||
return false;
|
||||
}
|
||||
|
||||
//删除
|
||||
this.killSreeps.splice(index,1);
|
||||
|
||||
//通知添加野怪被删除
|
||||
app.event.emit(GOnHookManagerEvent.DEL_KILL_SREEP,creeps);
|
||||
|
||||
let pet:PlayerPetOV = await GAPI.GOnHookCatchCreeps(creeps.key);
|
||||
|
||||
//保存宠物
|
||||
if(pet){
|
||||
PlayerPetData.getIns().addPet(pet);
|
||||
}
|
||||
|
||||
return !!pet;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "3e881d0a-dd68-4ca6-9043-73e2d45318bd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user