mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 11:24:46 +00:00
193 lines
6.1 KiB
TypeScript
193 lines
6.1 KiB
TypeScript
import { Vec2 } from "cc";
|
|
import { TableGRole } from "../../../resources/config/ts/TableGRole";
|
|
import GBaseMode from "../GBaseMode";
|
|
import { GRoleUtil } from "../entity/GRole";
|
|
import { GTactical } from "../entity/GTactical";
|
|
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";
|
|
import { GMapLoop } from "../base/common/map/GMapLoop";
|
|
import { Node } from "cc";
|
|
import JNFrameTime from "../../../../extensions/ngame/assets/ngame/sync/frame/game/time/JNFrameTime";
|
|
import { TableGMap } from "../../../resources/config/ts/TableGMap";
|
|
import { app } from "../../App";
|
|
import { v3 } from "cc";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
//角色
|
|
export enum GOnHookModePlayerEnum{
|
|
PLAYER, //玩家
|
|
ENEMY, //怪物
|
|
}
|
|
|
|
//玩家信息
|
|
export interface GOnHookInfo{
|
|
//阵法
|
|
tactical: GTactical;
|
|
//宠物列表
|
|
roles: TableGRole[];
|
|
}
|
|
|
|
/**
|
|
* 挂机模式 无限出现小怪
|
|
*/
|
|
@ccclass('GOnHookMode')
|
|
export default class GOnHookMode extends GBaseMode<{}>{
|
|
|
|
@property(Prefab)
|
|
rolePrefab: Prefab = null;
|
|
|
|
//场景地图
|
|
@property(GMapLoop)
|
|
map1:GMapLoop;
|
|
@property(GMapLoop)
|
|
map2:GMapLoop;
|
|
@property(GMapLoop)
|
|
map3:GMapLoop;
|
|
|
|
@property(Node)
|
|
objects: Node = null;
|
|
|
|
get scene():Node{
|
|
return this.objects;
|
|
}
|
|
|
|
//玩家信息
|
|
playerInfo:GOnHookInfo;
|
|
//宠物信息
|
|
enemyInfo:GOnHookInfo;
|
|
|
|
//玩家宠物位置
|
|
playerPos: Vec2 = new Vec2(-400,0);
|
|
//怪物位置
|
|
enemyPos: Vec2 = new Vec2(400,0);
|
|
|
|
//玩家宠物
|
|
playerRoles: GRoleDefault[] = [];
|
|
//敌方宠物
|
|
enemyRoles: GRoleDefault[] = [];
|
|
|
|
offsetX:number = 0;
|
|
|
|
//地图信息
|
|
mapInfo:TableGMap;
|
|
|
|
onSyncInitSuccess():void{
|
|
|
|
//初始化战斗
|
|
console.log("GOnHookMode 模式初始化");
|
|
|
|
//调整相机
|
|
let camreaPos = this.camera.node.worldPosition;
|
|
this.camera.node.worldPosition = v3(0,100,camreaPos.z)
|
|
|
|
//初始化地图
|
|
this.mapInfo = TableGMap.getConfig(60001);
|
|
this.map1.init(app.battleRes.maps[60001][0],1);
|
|
this.map1.UpdateMap(0,this.camera.node.worldPosition.x,this.mapInfo.map1OffsetY);
|
|
this.map2.init(app.battleRes.maps[60001][1],1);
|
|
this.map2.UpdateMap(0,this.camera.node.worldPosition.x,this.mapInfo.map2OffsetY);
|
|
this.map3.init(app.battleRes.maps[60001][2],1,app.battleRes.maps[60001][1].width,app.battleRes.maps[60001][1].height);
|
|
this.map3.UpdateMap(0,this.camera.node.worldPosition.x,this.mapInfo.map3OffsetY);
|
|
|
|
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.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.PLAYER,index + 1,info))
|
|
//生成敌人
|
|
this.onResetGenerateEnemy();
|
|
|
|
}
|
|
|
|
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 = [];
|
|
this.enemyInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.ENEMY,index + 1,info))
|
|
}
|
|
|
|
//角色死亡回调
|
|
onRoleKillBack(role:GRoleDefault){
|
|
//死亡销毁
|
|
JNFrameTime.getInstance().setTimeout(() => {
|
|
if(role.isValid)
|
|
role.node.destroy()
|
|
},3000)
|
|
//如果没有敌人则生成敌人
|
|
if(this.getOnesRole(GOnHookModePlayerEnum.ENEMY).filter(role => !!role.get()).length <= 0){
|
|
//生成敌人
|
|
this.onResetGenerateEnemy();
|
|
}
|
|
}
|
|
|
|
}
|
|
|