mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
生成野怪逻辑
This commit is contained in:
@@ -20,6 +20,8 @@ import PlayerTacticalData, { PlayerTacticalEvent } from "../../data/PlayerTactic
|
||||
import GRoleOnHookExpand from "../base/role/expand/OnHook/GRoleOnHookExpand";
|
||||
import PlayerPetData from "../../data/PlayerPetData";
|
||||
import { GUI } from "../../ui/UIConfig";
|
||||
import { GAction } from "../../consts/GAction";
|
||||
import { GActionType } from "../../consts/GActionType";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//挂机模式状态
|
||||
@@ -43,6 +45,16 @@ export interface GOnHookInfo{
|
||||
roles: TB.TbGRole[];
|
||||
}
|
||||
|
||||
//野怪
|
||||
interface GOnHookPet{
|
||||
key:string; //野怪唯一Id
|
||||
petTbId:number; //野怪配置表Id
|
||||
}
|
||||
//野怪列表
|
||||
interface GOnHookPets{
|
||||
pets:GOnHookPet[];
|
||||
}
|
||||
|
||||
/**
|
||||
* 挂机模式 无限出现小怪 (不是联机模式 该模式支持使用本地数据)
|
||||
*/
|
||||
@@ -103,6 +115,21 @@ export default class GOnHookMode extends GBaseMode<{}>{
|
||||
//是否允许攻击
|
||||
isAllowAttack:boolean = false;
|
||||
|
||||
//野怪列表
|
||||
_wildlifes:GOnHookPets;
|
||||
get wildlifes(){
|
||||
//如果没有野怪了 则 向服务器生成
|
||||
if(!this._wildlifes || !(this._wildlifes.pets.length)){
|
||||
//生成
|
||||
this.onSpawnWildlife();
|
||||
return null;
|
||||
}
|
||||
return this._wildlifes;
|
||||
}
|
||||
set wildlifes(data:GOnHookPets){
|
||||
this._wildlifes = data;
|
||||
}
|
||||
|
||||
//添加监听事件
|
||||
addEvent(){
|
||||
app.event.on(PlayerTacticalEvent.UPDATE_TACTICAL,this.onUpdatePlayerPet,this);
|
||||
@@ -135,14 +162,22 @@ export default class GOnHookMode extends GBaseMode<{}>{
|
||||
this.map3.init(app.battleRes.maps[60001][2],1,app.battleRes.maps[60001][1].width * scale,1048 * scale);
|
||||
this.onUpdateMap(0);
|
||||
|
||||
this.playerInfo = { tactical: GTactical.getTactical().setOffset(this.playerPos), roles: GRoleUtil.getGRoles([10004,10004,10004,10004,10003,10003]) };
|
||||
this.enemyInfo = { tactical: GTactical.getTactical(true).setOffset(this.enemyPos), roles: GRoleUtil.getGRoles([10002]) };
|
||||
this.playerInfo = { tactical: GTactical.getTactical().setOffset(this.playerPos), roles: GRoleUtil.getGRoles([]) };
|
||||
this.enemyInfo = { tactical: GTactical.getTactical(true).setOffset(this.enemyPos), roles: GRoleUtil.getGRoles([]) };
|
||||
|
||||
this.onUpdatePlayerPet();
|
||||
|
||||
//添加监听
|
||||
this.addEvent();
|
||||
|
||||
// //模拟请求生成宠物
|
||||
// app.socket.SendBack(GAction.MODE_ON_HOOK_SPAWN_PET,{
|
||||
// type:GActionType.GOnHookPets,
|
||||
// fun:(info:GOnHookPets) => {
|
||||
// console.log("接受到野怪列表",info)
|
||||
// }
|
||||
// })
|
||||
|
||||
//生成玩家
|
||||
// this.playerInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.PLAYER,index + 1,info))
|
||||
|
||||
@@ -151,6 +186,17 @@ export default class GOnHookMode extends GBaseMode<{}>{
|
||||
|
||||
}
|
||||
|
||||
//生成野怪
|
||||
onSpawnWildlife(){
|
||||
//获取服务器野怪
|
||||
app.socket.SendBack(GAction.MODE_ON_HOOK_SPAWN_PET,{
|
||||
type:GActionType.GOnHookPets,
|
||||
fun:(info:GOnHookPets) => {
|
||||
this.wildlifes = info;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//更新玩家宠物
|
||||
onUpdatePlayerPet(){
|
||||
//获取玩家阵容
|
||||
@@ -318,7 +364,12 @@ export default class GOnHookMode extends GBaseMode<{}>{
|
||||
//生成敌人
|
||||
onResetGenerateEnemy(){
|
||||
this.enemyRoles = [];
|
||||
this.enemyInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.ENEMY,index + 1,info))
|
||||
if(!this.wildlifes) return;
|
||||
|
||||
//获取敌人
|
||||
let wildlife = this.wildlifes.pets.shift();
|
||||
this.onGenRole(GOnHookModePlayerEnum.ENEMY,2,GRoleUtil.getGRole(wildlife.petTbId));
|
||||
// this.enemyInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.ENEMY,index + 1,info));
|
||||
}
|
||||
|
||||
//角色死亡回调
|
||||
|
@@ -2,8 +2,15 @@ export enum GAction {
|
||||
|
||||
TOKEN_EXPIRED = 1001, //Token过期
|
||||
|
||||
//聊天
|
||||
/*************** 聊天 **************/
|
||||
CHAT_MESSAGE = 2001, //发送聊天消息
|
||||
CHAT_RECEIVE_MESSAGE = 2002, //接受聊天消息
|
||||
|
||||
|
||||
/*************** 游戏模式 : 无尽模式(OnHook) **************/
|
||||
MODE_ON_HOOK_SPAWN_PET = 3001, //生成宠物
|
||||
MODE_ON_HOOK_CAPTURE_PET = 3002, //捕捉宠物
|
||||
MODE_ON_HOOK_SELL_PET = 3003, //卖出宠物
|
||||
|
||||
|
||||
}
|
@@ -6,4 +6,9 @@ export enum GActionType {
|
||||
|
||||
GUIChatMessage = "GUIChatMessage",//聊天信息
|
||||
|
||||
|
||||
/*************** 游戏模式 : 无尽模式(OnHook) **************/
|
||||
GOnHookPet = "GOnHookPet", //野怪
|
||||
GOnHookPets = "GOnHookPets", //野怪列表
|
||||
|
||||
}
|
@@ -44,11 +44,14 @@ export default class PlayerTacticalData extends BaseData{
|
||||
}
|
||||
|
||||
//更新上阵
|
||||
async UpdateTactical(roles:number[]){
|
||||
async UpdateTactical(roles:number[]):Promise<boolean>{
|
||||
//如果阵法一样则不更新
|
||||
if(this.info.tacticalData == JSON.stringify(roles)) return false;
|
||||
this.info.roles = roles;
|
||||
this.info.tacticalData = JSON.stringify(this.info.roles);
|
||||
//上传到服务器 并且保存
|
||||
this.onSaveTacticalInfo(await API.SetPlayerTactical(this.info));
|
||||
return true;
|
||||
}
|
||||
|
||||
//修改指定位置的上阵 上阵下标,上阵的宠物Id
|
||||
|
@@ -117,6 +117,12 @@ export class PlayerTacticalItem extends Component {
|
||||
fun(this,e);
|
||||
});
|
||||
}
|
||||
|
||||
addMoveEndEvent(fun:Function){
|
||||
this.drag.addMoveEndEvent((e) => {
|
||||
fun(this,e);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
import { PlayerTacticalItem } from './PlayerTacticalItem';
|
||||
import { app } from '../../../App';
|
||||
import { PlayerTacticalEvent } from '../../../data/PlayerTacticalData';
|
||||
import PlayerTacticalData, { PlayerTacticalEvent } from '../../../data/PlayerTacticalData';
|
||||
import JNodeDrag from '../../../../../extensions/ngame/assets/ngame/util/components/JNodeDrag';
|
||||
import { EventTouch } from 'cc';
|
||||
import { UITransform } from 'cc';
|
||||
import { GUI } from '../../UIConfig';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
@@ -23,7 +24,10 @@ export class PlayerTacticalView extends Component {
|
||||
this.items = this.node.getComponentsInChildren(PlayerTacticalItem);
|
||||
this.items.forEach((item,index) => {
|
||||
item.onInit(index); //初始化阵法下标
|
||||
//添加移动事件
|
||||
item.addMoveEvent(this.onMoveItem.bind(this));
|
||||
//添加移动结束事件
|
||||
item.addMoveEndEvent(this.onMoveEndItem.bind(this));
|
||||
});
|
||||
|
||||
this.onUpdateView();
|
||||
@@ -53,6 +57,20 @@ export class PlayerTacticalView extends Component {
|
||||
|
||||
}
|
||||
|
||||
//子节点移动结束
|
||||
async onMoveEndItem(){
|
||||
|
||||
//移动结束则保存阵法
|
||||
let pets:number[] = PlayerTacticalData.getIns().getInitTacticalInfo();
|
||||
this.items.forEach(item => {
|
||||
pets[item.index] = item.petId || 0;
|
||||
})
|
||||
if(await PlayerTacticalData.getIns().UpdateTactical(pets)){
|
||||
app.layer.Open(GUI.Tips,{text:"保存阵法成功"});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
this.offEvent();
|
||||
}
|
||||
|
Reference in New Issue
Block a user