2023-11-01 19:07:15 +08:00
|
|
|
import { Vec2 } from "cc";
|
2023-11-01 02:01:35 +08:00
|
|
|
import { TableGRole } from "../../../resources/config/ts/TableGRole";
|
|
|
|
import GBaseMode from "../GBaseMode";
|
|
|
|
import { GRoleUtil } from "../entity/GRole";
|
|
|
|
import { GTactical } from "../entity/GTactical";
|
2023-11-01 19:07:15 +08:00
|
|
|
import GRoleDefault from "../base/role/GRoleDefault";
|
|
|
|
import { Prefab } from "cc";
|
|
|
|
import { _decorator } from "cc";
|
|
|
|
import { instantiate } from "cc";
|
|
|
|
import { GPVPModePlayerEnum } from "./GPVPMode";
|
|
|
|
import { JNFrameInfo } from "../../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
|
|
|
|
const { ccclass, property } = _decorator;
|
2023-11-01 02:01:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
//角色
|
|
|
|
export enum GOnHookModePlayerEnum{
|
|
|
|
PLAYER, //玩家
|
|
|
|
ENEMY, //怪物
|
|
|
|
}
|
|
|
|
|
|
|
|
//玩家信息
|
2023-11-01 19:07:15 +08:00
|
|
|
export interface GOnHookInfo{
|
2023-11-01 02:01:35 +08:00
|
|
|
//阵法
|
|
|
|
tactical: GTactical;
|
|
|
|
//宠物列表
|
|
|
|
roles: TableGRole[];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 挂机模式 无限出现小怪
|
|
|
|
*/
|
2023-11-01 19:07:15 +08:00
|
|
|
@ccclass('GOnHookMode')
|
2023-11-01 02:01:35 +08:00
|
|
|
export default class GOnHookMode extends GBaseMode<{}>{
|
|
|
|
|
2023-11-01 19:07:15 +08:00
|
|
|
@property(Prefab)
|
|
|
|
rolePrefab: Prefab = null;
|
|
|
|
|
2023-11-01 02:01:35 +08:00
|
|
|
//玩家信息
|
2023-11-01 19:07:15 +08:00
|
|
|
playerInfo:GOnHookInfo;
|
|
|
|
//宠物信息
|
|
|
|
enemyInfo:GOnHookInfo;
|
|
|
|
|
|
|
|
//玩家宠物位置
|
2023-11-02 01:41:11 +08:00
|
|
|
playerPos: Vec2 = new Vec2(-400,0);
|
2023-11-01 19:07:15 +08:00
|
|
|
//怪物位置
|
2023-11-02 01:41:11 +08:00
|
|
|
enemyPos: Vec2 = new Vec2(400,0);
|
2023-11-01 02:01:35 +08:00
|
|
|
|
2023-11-01 19:07:15 +08:00
|
|
|
//玩家宠物
|
|
|
|
playerRoles: GRoleDefault[] = [];
|
|
|
|
//敌方宠物
|
|
|
|
enemyRoles: GRoleDefault[] = [];
|
2023-11-01 02:01:35 +08:00
|
|
|
|
|
|
|
onSyncInitSuccess():void{
|
|
|
|
|
|
|
|
//初始化战斗
|
|
|
|
console.log("GOnHookMode 模式初始化");
|
|
|
|
|
2023-11-01 19:07:15 +08:00
|
|
|
this.playerInfo = { tactical: GTactical.getTactical().setOffset(this.playerPos), roles: GRoleUtil.getGRoles([10004,10004,10004,10004,10003,10003]) };
|
2023-11-02 01:41:11 +08:00
|
|
|
this.enemyInfo = { tactical: GTactical.getTactical(true).setOffset(this.enemyPos), roles: GRoleUtil.getGRoles([10002]) };
|
2023-11-01 02:01:35 +08:00
|
|
|
|
|
|
|
//生成玩家
|
2023-11-01 19:07:15 +08:00
|
|
|
this.playerInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.PLAYER,index + 1,info))
|
|
|
|
//生成敌人
|
|
|
|
this.onResetGenerateEnemy();
|
2023-11-01 02:01:35 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-11-01 19:07:15 +08:00
|
|
|
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: {}){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//生成宠物
|
|
|
|
onGenRole(type: GOnHookModePlayerEnum,index:number,info:TableGRole) {
|
|
|
|
|
|
|
|
let tactical = this.getInfo(type).tactical;
|
|
|
|
let pos:Vec2 = this.getInfo(type).tactical.getPosition(index);
|
|
|
|
if(!pos) return;
|
|
|
|
let role = instantiate(this.rolePrefab);
|
|
|
|
let entity = role.getComponent(GRoleDefault);
|
|
|
|
//初始化
|
|
|
|
entity.onInit(type,info,tactical,index);
|
|
|
|
|
|
|
|
//绑定寻敌
|
|
|
|
entity.onQueryEunmy = () => {
|
|
|
|
return this.getEnumy(entity,type);
|
|
|
|
}
|
|
|
|
|
|
|
|
//绑定死亡回调
|
|
|
|
entity.addKillBackEvent(this.onRoleKillBack.bind(this))
|
|
|
|
|
|
|
|
this.addGObject(entity,tactical.getPosition(index));
|
|
|
|
this.getOnesRole(type).push(entity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取配置
|
|
|
|
getInfo(type: GOnHookModePlayerEnum): GOnHookInfo {
|
|
|
|
if(type == GOnHookModePlayerEnum.PLAYER) return this.playerInfo;
|
|
|
|
if(type == GOnHookModePlayerEnum.ENEMY) return this.enemyInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取阵营宠物
|
|
|
|
getOnesRole(type: GOnHookModePlayerEnum):GRoleDefault[]{
|
|
|
|
if(type == GOnHookModePlayerEnum.PLAYER) return this.playerRoles;
|
|
|
|
if(type == GOnHookModePlayerEnum.ENEMY) return this.enemyRoles;
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取敌人
|
|
|
|
getEnumy(player:GRoleDefault,type:GOnHookModePlayerEnum):GRoleDefault{
|
|
|
|
|
|
|
|
let enumyOnes = GOnHookModePlayerEnum.ENEMY
|
|
|
|
//如果是ENEMY 则 它的敌人是 PLAYER
|
|
|
|
if(type == GOnHookModePlayerEnum.ENEMY) enumyOnes = GOnHookModePlayerEnum.PLAYER
|
|
|
|
|
|
|
|
//获取敌人
|
|
|
|
let roles = this.getOnesRole(enumyOnes);
|
|
|
|
|
|
|
|
//返回敌人
|
|
|
|
//获取我在第几排
|
|
|
|
let playerXY = player.tactical.getXY(player.tacticalIndex);
|
|
|
|
//通过排数获取最近的敌人
|
|
|
|
let sort = roles.filter(role => !!role.get()).sort((enumy1,enumy2) => {
|
|
|
|
let enumy1XY = enumy1.tactical.getXY(enumy1.tacticalIndex);
|
|
|
|
let enumy2XY = enumy2.tactical.getXY(enumy2.tacticalIndex);
|
|
|
|
return Math.abs((playerXY.y * 1000) - (enumy1XY.y * 1000)) + Math.abs((playerXY.x - enumy1XY.x)) -
|
|
|
|
Math.abs((playerXY.y * 1000) - (enumy2XY.y * 1000)) + Math.abs((playerXY.x - enumy2XY.x))
|
|
|
|
});
|
|
|
|
return sort[0]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//生成敌人
|
|
|
|
onResetGenerateEnemy(){
|
|
|
|
this.enemyRoles = [];
|
2023-11-02 01:41:11 +08:00
|
|
|
this.enemyInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.ENEMY,index + 1,info))
|
2023-11-01 19:07:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//角色死亡回调
|
|
|
|
onRoleKillBack(role:GRoleDefault){
|
|
|
|
//如果没有敌人则生成敌人
|
|
|
|
if(this.getOnesRole(GOnHookModePlayerEnum.ENEMY).filter(role => !!role.get()).length <= 0){
|
|
|
|
//生成敌人
|
|
|
|
this.onResetGenerateEnemy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 02:01:35 +08:00
|
|
|
}
|
|
|
|
|