mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 18:26:23 +00:00
提交挂机
This commit is contained in:
@@ -4,7 +4,7 @@ import ResourceData from "../data/ResourceData";
|
||||
import { GUI } from "../ui/UIConfig";
|
||||
|
||||
//接受到JSON消息
|
||||
export const RData = (data:any,isTips:boolean = true) => {
|
||||
export const RData = (data:any,isTips:boolean = false) => {
|
||||
if(data.data.state == 200){
|
||||
//如果有 Resource 字段 表示要刷新资源
|
||||
if(data.data['resources']){
|
||||
@@ -14,6 +14,10 @@ export const RData = (data:any,isTips:boolean = true) => {
|
||||
PlayerPetData.getIns().onUpdateOV(res.operation,res.pet); //刷新宠物
|
||||
})
|
||||
}
|
||||
//弹出提示
|
||||
if(isTips){
|
||||
app.layer.Open(GUI.Tips,{text:data.data.msg});
|
||||
}
|
||||
return data.data.data;
|
||||
}else{
|
||||
//弹出提示
|
||||
@@ -97,7 +101,7 @@ export const API = {
|
||||
|
||||
/********** 新手引导接口 *****************/
|
||||
SavePlayerInfo : async (playerName:string,novice:boolean = true) => (await app.api.post(`/game/player/info/save`,{playerName,novice})).data as NewsContext, //保存玩家信息
|
||||
SelectNovicePet: async (petId:number) => RData(await app.api.post(`/game/novice/select/${petId}`),true), //选择新手引导宠物
|
||||
SelectNovicePet: async (petId:number) => RData(await app.api.post(`/game/novice/select/${petId}`),false), //选择新手引导宠物
|
||||
|
||||
|
||||
/********** 宠物接口 ******************/
|
||||
|
@@ -19,11 +19,11 @@ export const GAPI = {
|
||||
//切换游戏
|
||||
GOnHookSetMap : async (mapId) => RData(await app.api.post(`/game/mode/onHook/setMapId/${mapId}`)) as ModeOnHookOV,
|
||||
//生成野怪
|
||||
GOnHookSpawnCreeps : async () => RProto(await app.api.get(`/game/mode/onHook/onSpawnCreeps`,{responseType:'arraybuffer'},true),GActionType.GOnHookPets) as GOnHookPets,
|
||||
GOnHookSpawnCreeps : async () => RProto(await app.api.get(`/game/mode/onHook/onSpawnCreeps`,{responseType:'arraybuffer'},false),GActionType.GOnHookPets) as GOnHookPets,
|
||||
//捕捉野怪
|
||||
GOnHookCatchCreeps : async (creepId) => RData(await app.api.post(`/game/mode/onHook/onCatchCreeps/${creepId}`)) as PlayerPetOV,
|
||||
GOnHookCatchCreeps : async (creepId) => RData(await app.api.post(`/game/mode/onHook/onCatchCreeps/${creepId}`),true) as PlayerPetOV,
|
||||
//出售野怪
|
||||
GOnHookSellCreeps : async (creepId) => RData(await app.api.post(`/game/mode/onHook/onSellCreeps/${creepId}`)) as boolean,
|
||||
GOnHookSellCreeps : async (creepId) => RData(await app.api.post(`/game/mode/onHook/onSellCreeps/${creepId}`),true) as boolean,
|
||||
//下一关
|
||||
GOnHookNextLevel : async () => RData(await app.api.post(`/game/mode/onHook/nextLevel`)) as boolean,
|
||||
|
||||
|
@@ -1,8 +1,11 @@
|
||||
import { GOnHookPet } from "../../../../../extensions/ngame/assets/ngame/message/proto";
|
||||
import NGameUtil from "../../../../../extensions/ngame/assets/ngame/util/NGameUtil";
|
||||
import { NSystemEvent } from "../../../../../extensions/ngame/assets/ngame/util/NSystem";
|
||||
import Singleton from "../../../../../extensions/ngame/assets/ngame/util/Singleton";
|
||||
import { app } from "../../../App";
|
||||
import { TD, app } from "../../../App";
|
||||
import GBattleModeManager, { BattleMode } from "../../../battle/GBattleModeManager";
|
||||
import { PlayerPetOV } from "../../../consts/API";
|
||||
import { TB } from "../../../config/data/schema";
|
||||
import { API, PlayerPetOV } from "../../../consts/API";
|
||||
import { GAPI } from "../../../consts/GAPI";
|
||||
import GOnHookData from "../../../data/GOnHookData";
|
||||
import PlayerPetData from "../../../data/PlayerPetData";
|
||||
@@ -16,7 +19,9 @@ export enum GOnHookManagerEvent{
|
||||
//重置数据
|
||||
RESET_DATA = "GOnHookManagerEvent_RESET_DATA",
|
||||
//删除死亡野怪
|
||||
UPDATE_MAP = "GOnHookManagerEvent_UPDATE_MAP"
|
||||
UPDATE_MAP = "GOnHookManagerEvent_UPDATE_MAP",
|
||||
//更新挂机状态
|
||||
UPDATE_ON_HOOK_STATE = "GOnHookManagerEvent_UPDATE_ON_HOOK_STATE"
|
||||
}
|
||||
|
||||
//游戏模式 OnHook 管理器
|
||||
@@ -42,6 +47,71 @@ export default class GOnHookManager extends Singleton{
|
||||
//已经死亡的野怪列表
|
||||
killSreeps:GOnHookPet[] = [];
|
||||
|
||||
//-------------------------- 挂机 ---------------------------------
|
||||
|
||||
//需要捕捉的宠物
|
||||
onHookCatchPets:TB.TbGRole[] = [];
|
||||
//需要主动吞噬的宠物 (主动吞噬其他 0星 宠物 升星)
|
||||
onHookEngulfPets:PlayerPetOV[] = [];
|
||||
|
||||
//是否挂机
|
||||
_isOnHook:boolean = false;
|
||||
get isOnHook(){return this._isOnHook}
|
||||
set isOnHook(value:boolean){
|
||||
this._isOnHook = value;
|
||||
//通知更新挂机状态
|
||||
app.event.emit(GOnHookManagerEvent.UPDATE_ON_HOOK_STATE);
|
||||
}
|
||||
|
||||
init(){
|
||||
app.event.on(NSystemEvent.UPDATE,this.onUpdate,this);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
app.event.off(NSystemEvent.UPDATE,this.onUpdate,this);
|
||||
}
|
||||
|
||||
onUpdate(){
|
||||
this.onUpdateOnHook();
|
||||
}
|
||||
|
||||
//更新挂机
|
||||
onUpdateOnHook = NGameUtil.ThrottleASync((async () => {
|
||||
|
||||
//如果是挂机 则 出售不需要捕捉的宠物
|
||||
if(!this.isOnHook) return;
|
||||
|
||||
//捕捉 和 出售
|
||||
let pet = this.killSreeps[0];
|
||||
if(pet){
|
||||
if(this.onHookCatchPets.indexOf(TD.TbGRole.get(pet.petTbId)) >= 0){
|
||||
//捕捉
|
||||
await this.onCatchCreeps(pet)
|
||||
}else{
|
||||
//出售
|
||||
await this.onSellCreeps(pet)
|
||||
}
|
||||
}
|
||||
|
||||
//自动吞噬
|
||||
for (const item of this.onHookEngulfPets) {
|
||||
|
||||
//获取可吞噬的宠物
|
||||
let engulfs = PlayerPetData.getIns().getData()
|
||||
.filter(value => (value.petStar || 0) == 0 && item.petTbId == value.petTbId && item.petId != value.petId)
|
||||
.map(value => value.petId);
|
||||
|
||||
//吞噬
|
||||
if(engulfs.length){
|
||||
await API.PetUpStar(item.petId,engulfs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}).bind(this))
|
||||
|
||||
//生成野怪
|
||||
onSpawnSreeps(){
|
||||
|
@@ -7,7 +7,7 @@ import { JNGLayerBase } from '../../components/JNComponent';
|
||||
import { app } from '../../App';
|
||||
import { GAction } from '../../consts/GAction';
|
||||
import { GAPI } from '../../consts/GAPI';
|
||||
import GOnHookManager from '../../manager/battle/mode/GOnHookManager';
|
||||
import GOnHookManager, { GOnHookManagerEvent } from '../../manager/battle/mode/GOnHookManager';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('MainView')
|
||||
@@ -15,16 +15,35 @@ export class MainView extends JNGLayerBase {
|
||||
|
||||
@property(Label)
|
||||
playerNameLabel:Label; //玩家名称
|
||||
|
||||
@property(Label)
|
||||
onHookLabel:Label; //挂机文本
|
||||
|
||||
onJNLoad(data?: any): void {
|
||||
|
||||
super.onJNLoad(data);
|
||||
|
||||
//发送消息
|
||||
ChatData.getIns().onSend({
|
||||
message:`${PlayerData.getIns().data.playerId} 加入游戏`
|
||||
});
|
||||
|
||||
this.onUpdateView();
|
||||
|
||||
|
||||
//监听
|
||||
app.event.on(GOnHookManagerEvent.UPDATE_ON_HOOK_STATE,this.onUpdateOnHook,this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
onJNClose(): void {
|
||||
super.onJNClose();
|
||||
//取消监听
|
||||
app.event.on(GOnHookManagerEvent.UPDATE_ON_HOOK_STATE,this.onUpdateOnHook,this);
|
||||
}
|
||||
|
||||
onUpdateOnHook(){
|
||||
this.onHookLabel.string = (GOnHookManager.getIns().isOnHook) ? "挂机中" : "挂机";
|
||||
}
|
||||
|
||||
//更新UI界面
|
||||
|
@@ -2,9 +2,12 @@ import { _decorator, Component, Node } from 'cc';
|
||||
import { JNGLayerBase } from '../../../components/JNComponent';
|
||||
import JNScrollView from '../../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollView';
|
||||
import GOnHookData from '../../../data/GOnHookData';
|
||||
import { TD } from '../../../App';
|
||||
import { app, TD } from '../../../App';
|
||||
import { NodeEventType } from 'cc';
|
||||
import { TablePetIconSelectScroll } from '../../Consts/Pet/table/TablePetIconSelectScroll';
|
||||
import { Label } from 'cc';
|
||||
import GOnHookManager from '../../../manager/battle/mode/GOnHookManager';
|
||||
import { GUI } from '../../UIConfig';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('MainOnHookView')
|
||||
@@ -13,6 +16,10 @@ export class MainOnHookView extends JNGLayerBase {
|
||||
//野怪列表
|
||||
@property(JNScrollView)
|
||||
views:JNScrollView;
|
||||
|
||||
//挂机按钮
|
||||
@property(Label)
|
||||
onHookLabel:Label;
|
||||
|
||||
onJNLoad(){
|
||||
|
||||
@@ -28,11 +35,12 @@ export class MainOnHookView extends JNGLayerBase {
|
||||
onUpdateView(){
|
||||
|
||||
//显示当前地图可出现的所有宠物
|
||||
|
||||
let mapInfo = TD.TbGOnHookMaps.get(GOnHookData.getIns().info.onHookMap);
|
||||
let pets = mapInfo.petIds.map(petId => TD.TbGRole.get(petId));
|
||||
this.views.refreshData(pets);
|
||||
|
||||
this.onHookLabel.string = (!GOnHookManager.getIns().isOnHook) ? "挂机" : "取消挂机"
|
||||
|
||||
}
|
||||
|
||||
//点击Item
|
||||
@@ -43,6 +51,14 @@ export class MainOnHookView extends JNGLayerBase {
|
||||
|
||||
}
|
||||
|
||||
//点击挂机
|
||||
onClickOnHook(){
|
||||
GOnHookManager.getIns().onHookCatchPets = this.views.getItems<TablePetIconSelectScroll>().filter(item => item.select.isSelect).map(item => item.data)
|
||||
GOnHookManager.getIns().isOnHook = !GOnHookManager.getIns().isOnHook;
|
||||
app.layer.Open(GUI.Tips,{text:`${(GOnHookManager.getIns().isOnHook) ? "挂机" : "取消挂机"} 设置成功`})
|
||||
this.close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -91,8 +91,7 @@ export class MainSreepsList extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
if(await GOnHookManager.getIns().onCatchCreeps(item.data))
|
||||
app.layer.Open(GUI.Tips,{text:"捕捉成功!"});
|
||||
await GOnHookManager.getIns().onCatchCreeps(item.data)
|
||||
|
||||
}
|
||||
|
||||
@@ -107,8 +106,7 @@ export class MainSreepsList extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
if(await GOnHookManager.getIns().onSellCreeps(item.data))
|
||||
app.layer.Open(GUI.Tips,{text:"出售成功!"});
|
||||
await GOnHookManager.getIns().onSellCreeps(item.data)
|
||||
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,8 @@ import { app, TD } from '../../App';
|
||||
import { GUI } from '../UIConfig';
|
||||
import { ProgressBar } from 'cc';
|
||||
import JProgressBar from '../../../../extensions/ngame/assets/ngame/util/components/Progress/JProgressBar';
|
||||
import { Toggle } from 'cc';
|
||||
import GOnHookManager from '../../manager/battle/mode/GOnHookManager';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('PetUpStarView')
|
||||
@@ -30,6 +32,9 @@ export class PetUpStarView extends JNLayerBase {
|
||||
@property(JProgressBar)
|
||||
viewPetExpProgress:JProgressBar; //预览宠物经验条
|
||||
|
||||
@property(Toggle)
|
||||
isEngulfToggle:Toggle; //是否主动吞噬 0 星 宠物
|
||||
|
||||
data:PlayerPetOV;
|
||||
|
||||
onJNLoad(data: PlayerPetOV): void {
|
||||
@@ -70,6 +75,9 @@ export class PetUpStarView extends JNLayerBase {
|
||||
|
||||
this.onUpdateSelect();
|
||||
|
||||
//更新吞噬
|
||||
this.isEngulfToggle.isChecked = GOnHookManager.getIns().onHookEngulfPets.indexOf(this.data) >= 0;
|
||||
|
||||
}
|
||||
|
||||
//刷新信息
|
||||
@@ -149,6 +157,7 @@ export class PetUpStarView extends JNLayerBase {
|
||||
|
||||
//点击合成
|
||||
async onClickUp(){
|
||||
|
||||
//获取被合成的Id
|
||||
let pets = this.views.getData<PlayerPetOVSelect>().filter(pet => pet.isSelect).map(pet => pet.petId);
|
||||
|
||||
@@ -158,9 +167,16 @@ export class PetUpStarView extends JNLayerBase {
|
||||
}
|
||||
|
||||
await API.PetUpStar(this.data.petId,pets);
|
||||
app.layer.Open(GUI.Tips,{text:"合成成功"});
|
||||
|
||||
}
|
||||
|
||||
//点击吞噬选择
|
||||
onClickEngulfToggle(){
|
||||
GOnHookManager.getIns().onHookEngulfPets.splice(GOnHookManager.getIns().onHookEngulfPets.indexOf(this.data),1);
|
||||
if(this.isEngulfToggle.isChecked){
|
||||
GOnHookManager.getIns().onHookEngulfPets.push(this.data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -132,8 +132,7 @@ export class IntoBattleView extends JNLayerBase {
|
||||
app.layer.Open(GUI.Tips,{text:"请选择宠物."})
|
||||
return;
|
||||
}
|
||||
if(await API.PetUpLevel(this.pets[this.index].petId))
|
||||
app.layer.Open(GUI.Tips,{text:"升级成功!"})
|
||||
await API.PetUpLevel(this.pets[this.index].petId)
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user