重构继承关系

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2023-11-01 02:01:35 +08:00
parent e59c5640d7
commit 6ebed0b45e
43 changed files with 496 additions and 524 deletions

View File

@@ -1,10 +0,0 @@
import GBaseMode from "../GBaseMode";
/**
* 挂机模式
*/
export default class GLDLEMode extends GBaseMode<{}>{
}

View File

@@ -0,0 +1,43 @@
import { TableGRole } from "../../../resources/config/ts/TableGRole";
import GBaseMode from "../GBaseMode";
import { GRoleUtil } from "../entity/GRole";
import { GTactical } from "../entity/GTactical";
//角色
export enum GOnHookModePlayerEnum{
PLAYER, //玩家
ENEMY, //怪物
}
//玩家信息
export interface GOnHookPlayerInfo{
//阵法
tactical: GTactical;
//宠物列表
roles: TableGRole[];
}
/**
* 挂机模式 无限出现小怪
*/
export default class GOnHookMode extends GBaseMode<{}>{
//玩家信息
playerInfo;
onSyncInitSuccess():void{
//初始化战斗
console.log("GOnHookMode 模式初始化");
this.playerInfo = { tactical: GTactical.getTactical(), roles: GRoleUtil.getGRoles([10001,10001,10001,10001,10003,10003]) };
//生成玩家
// this.playerInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.PLAYER,index+1,info))
}
}

View File

@@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c579d727-c0c2-422f-8571-3375047fd1b8",
"uuid": "84547cc9-858f-4ee4-9b65-272fcd80af47",
"files": [],
"subMetas": {},
"userData": {}

View File

@@ -4,9 +4,9 @@ import { GTactical } from "../entity/GTactical";
import { Prefab } from "cc";
import { instantiate } from "cc";
import { Vec2 } from "cc";
import GRolePVPEntity from "../base/role/PVP/GRolePVPEntity";
import { GRoleUtil } from "../entity/GRole";
import { TableGRole } from "../../../resources/config/ts/TableGRole";
import GRoleDefault from "../base/role/GRoleDefault";
const { ccclass, property } = _decorator;
//PVP 角色
@@ -41,9 +41,9 @@ export default class GPVPMode extends GBaseMode<{}>{
enemyInfo: GPVPModePlayerInfo;
//玩家宠物
playerRoles: GRolePVPEntity[] = [];
playerRoles: GRoleDefault[] = [];
//敌方宠物
enemyRoles: GRolePVPEntity[] = [];
enemyRoles: GRoleDefault[] = [];
//玩家位置
playerPos: Vec2 = new Vec2(-400,0);
@@ -65,8 +65,8 @@ export default class GPVPMode extends GBaseMode<{}>{
//初始化战斗
console.log("GPVPMode 模式初始化");
this.playerInfo = { tactical: GTactical.getTactical(), roles: GRoleUtil.getGRoles([10001,10001,10001,10001,10003,10003]) };
this.enemyInfo = { tactical: GTactical.getTactical(true), roles: GRoleUtil.getGRoles([10002,10002,10002,10001,10004,10003]) };
this.playerInfo = { tactical: GTactical.getTactical().setOffset(this.playerPos), roles: GRoleUtil.getGRoles([10001,10001,10001,10001,10003,10003]) };
this.enemyInfo = { tactical: GTactical.getTactical(true).setOffset(this.enemyPos), roles: GRoleUtil.getGRoles([10002,10002,10002,10001,10004,10003]) };
//生成玩家
this.playerInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.PLAYER,index+1,info))
@@ -77,19 +77,20 @@ export default class GPVPMode extends GBaseMode<{}>{
//生成角色
onGenRole(type: GPVPModePlayerEnum,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(GRolePVPEntity);
//绑定角色
entity.type = type;
entity.bind(info);
//赋值阵容
entity.ones = type;
entity.tactical = this.getInfo(type).tactical;
entity.tacticalIndex = index;
entity.tacticalPos = this.getInfo(type).tactical.getPosition(index,this.getTacticalPos(type));
this.addGObject(entity,entity.tacticalPos);
let entity = role.getComponent(GRoleDefault);
//初始化
entity.onInit(type,info,tactical,index);
//绑定寻敌
entity.onQueryEunmy = () => {
return this.getEnumy(entity,type);
}
this.addGObject(entity,tactical.getPosition(index));
this.getOnesRole(type).push(entity);
}
@@ -100,24 +101,18 @@ export default class GPVPMode extends GBaseMode<{}>{
if(type == GPVPModePlayerEnum.ENEMY) return this.enemyInfo;
}
//获取位置
getTacticalPos(type: GPVPModePlayerEnum):Vec2{
if(type == GPVPModePlayerEnum.PLAYER) return this.playerPos;
if(type == GPVPModePlayerEnum.ENEMY) return this.enemyPos;
}
//获取阵营角色
getOnesRole(type: GPVPModePlayerEnum):GRolePVPEntity[]{
getOnesRole(type: GPVPModePlayerEnum):GRoleDefault[]{
if(type == GPVPModePlayerEnum.PLAYER) return this.playerRoles;
if(type == GPVPModePlayerEnum.ENEMY) return this.enemyRoles;
}
//获取敌人
getEnumy(player:GRolePVPEntity):GRolePVPEntity{
getEnumy(player:GRoleDefault,type:GPVPModePlayerEnum):GRoleDefault{
let enumyOnes = GPVPModePlayerEnum.ENEMY
//如果是ENEMY 则 它的敌人是 PLAYER
if(player.ones == GPVPModePlayerEnum.ENEMY) enumyOnes = GPVPModePlayerEnum.PLAYER
if(type == GPVPModePlayerEnum.ENEMY) enumyOnes = GPVPModePlayerEnum.PLAYER
//获取敌人
let roles = this.getOnesRole(enumyOnes);
@@ -126,7 +121,7 @@ export default class GPVPMode extends GBaseMode<{}>{
//获取我在第几排
let playerXY = player.tactical.getXY(player.tacticalIndex);
//通过排数获取最近的敌人
let sort = roles.sort((enumy1,enumy2) => {
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)) -
@@ -135,16 +130,6 @@ export default class GPVPMode extends GBaseMode<{}>{
return sort[0]
}
//销毁角色数据
killRole(role:GRolePVPEntity){
let index = this.playerRoles.indexOf(role);
if(index >= 0)
this.playerRoles.splice(index,1);
index = this.enemyRoles.indexOf(role);
if(index >= 0)
this.enemyRoles.splice(index,1);
}
}