mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 18:26:23 +00:00
生成野怪逻辑
This commit is contained in:
@@ -276,6 +276,39 @@ export class TbGMap {
|
||||
}
|
||||
|
||||
|
||||
export namespace TB {
|
||||
export class TbGOnHookGlobal {
|
||||
|
||||
constructor(_json_: any) {
|
||||
if (_json_.id === undefined) { throw new Error() }
|
||||
this.id = _json_.id
|
||||
if (_json_.args === undefined) { throw new Error() }
|
||||
this.args = _json_.args
|
||||
if (_json_.tig === undefined) { throw new Error() }
|
||||
this.tig = _json_.tig
|
||||
}
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
readonly id: number
|
||||
/**
|
||||
* 全局表参数
|
||||
*/
|
||||
readonly args: string
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
readonly tig: string
|
||||
|
||||
resolve(tables:Tables)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export class TbGGlobal{
|
||||
@@ -470,6 +503,38 @@ export class TbGMap{
|
||||
|
||||
|
||||
|
||||
export class TbGOnHookGlobal{
|
||||
private _dataMap: Map<number, TB.TbGOnHookGlobal>
|
||||
private _dataList: TB.TbGOnHookGlobal[]
|
||||
constructor(_json_: any) {
|
||||
this._dataMap = new Map<number, TB.TbGOnHookGlobal>()
|
||||
this._dataList = []
|
||||
for(var _json2_ of _json_) {
|
||||
let _v: TB.TbGOnHookGlobal
|
||||
_v = new TB.TbGOnHookGlobal(_json2_)
|
||||
this._dataList.push(_v)
|
||||
this._dataMap.set(_v.id, _v)
|
||||
}
|
||||
}
|
||||
|
||||
getDataMap(): Map<number, TB.TbGOnHookGlobal> { return this._dataMap; }
|
||||
getDataList(): TB.TbGOnHookGlobal[] { return this._dataList; }
|
||||
|
||||
get(key: number): TB.TbGOnHookGlobal | undefined { return this._dataMap.get(key); }
|
||||
|
||||
resolve(tables:Tables)
|
||||
{
|
||||
for(let data of this._dataList)
|
||||
{
|
||||
data.resolve(tables)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
type JsonLoader = (file: string) => any
|
||||
|
||||
export class Tables {
|
||||
@@ -485,6 +550,8 @@ export class Tables {
|
||||
get TbGRoleSkill(): TbGRoleSkill { return this._TbGRoleSkill;}
|
||||
private _TbGMap: TbGMap
|
||||
get TbGMap(): TbGMap { return this._TbGMap;}
|
||||
private _TbGOnHookGlobal: TbGOnHookGlobal
|
||||
get TbGOnHookGlobal(): TbGOnHookGlobal { return this._TbGOnHookGlobal;}
|
||||
|
||||
constructor(loader: JsonLoader) {
|
||||
this._TbGGlobal = new TbGGlobal(loader('tbgglobal'))
|
||||
@@ -493,6 +560,7 @@ export class Tables {
|
||||
this._TbGRoleBattleRes = new TbGRoleBattleRes(loader('tbgrolebattleres'))
|
||||
this._TbGRoleSkill = new TbGRoleSkill(loader('tbgroleskill'))
|
||||
this._TbGMap = new TbGMap(loader('tbgmap'))
|
||||
this._TbGOnHookGlobal = new TbGOnHookGlobal(loader('tbgonhookglobal'))
|
||||
|
||||
this._TbGGlobal.resolve(this)
|
||||
this._TbGRole.resolve(this)
|
||||
@@ -500,5 +568,6 @@ export class Tables {
|
||||
this._TbGRoleBattleRes.resolve(this)
|
||||
this._TbGRoleSkill.resolve(this)
|
||||
this._TbGMap.resolve(this)
|
||||
this._TbGOnHookGlobal.resolve(this)
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"id": 80001,
|
||||
"args": "100",
|
||||
"tig": "预先生成的野外宠物数量"
|
||||
}
|
||||
]
|
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "2.0.1",
|
||||
"importer": "json",
|
||||
"imported": true,
|
||||
"uuid": "0ccb44c9-b7bc-4fc6-b7d2-8a4335f806a5",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -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