This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2023-10-24 02:32:06 +08:00
parent 77d44ee300
commit 72f3d7e880
26 changed files with 545 additions and 285 deletions

View File

@@ -2,9 +2,9 @@ import { _decorator } from "cc";
import GBaseMode from "../GBaseMode";
import { GTactical } from "../entity/GTactical";
import { Prefab } from "cc";
import GRoleEntity from "../base/role/impl/GRoleEntity";
import { instantiate } from "cc";
import { Vec2 } from "cc";
import GRolePVPEntity from "../base/role/PVP/GRolePVPEntity";
const { ccclass, property } = _decorator;
@@ -38,9 +38,9 @@ export default class GPVPMode extends GBaseMode{
enemyInfo: GPVPModePlayerInfo = { tactical: GTactical.getTactical2(true),roles: [{},{},{}] };
//玩家宠物
playerRoles: GRoleEntity[] = [];
playerRoles: GRolePVPEntity[] = [];
//敌方宠物
enemyRoles: GRoleEntity[] = [];
enemyRoles: GRolePVPEntity[] = [];
//玩家位置
playerPos: Vec2 = new Vec2(-400,0);
@@ -65,8 +65,13 @@ export default class GPVPMode extends GBaseMode{
let pos:Vec2 = this.getInfo(type).tactical.getPosition(index);
if(!pos) return;
let role = instantiate(this.rolePrefab);
let entity = role.getComponent(GRoleEntity)
let entity = role.getComponent(GRolePVPEntity)
//赋值阵容
entity.ones = type;
entity.tactical = this.getInfo(type).tactical;
entity.tacticalIndex = index;
this.addGObject(entity,this.getInfo(type).tactical.getPosition(index,this.getTacticalPos(type)));
this.getOnesRole(type).push(entity);
}
@@ -81,6 +86,39 @@ export default class GPVPMode extends GBaseMode{
if(type == GPVPModePlayerEnum.PLAYER) return this.playerPos;
if(type == GPVPModePlayerEnum.ENEMY) return this.enemyPos;
}
//获取阵营角色
getOnesRole(type: GPVPModePlayerEnum):GRolePVPEntity[]{
if(type == GPVPModePlayerEnum.PLAYER) return this.playerRoles;
if(type == GPVPModePlayerEnum.ENEMY) return this.enemyRoles;
}
//获取敌人
getEnumy(player:GRolePVPEntity):GRolePVPEntity{
let enumyOnes = GPVPModePlayerEnum.ENEMY
//如果是ENEMY 则 它的敌人是 PLAYER
if(player.ones == GPVPModePlayerEnum.ENEMY) enumyOnes = GPVPModePlayerEnum.PLAYER
//获取敌人
let roles = this.getOnesRole(enumyOnes);
//返回敌人
//获取我在第几排
let playerXY = player.tactical.getXY(player.tacticalIndex);
//通过排数获取最近的敌人
let sort = roles.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))
});
console.log(playerXY,sort[0].tactical.getXY(sort[0].tacticalIndex),);
return sort[0]
}
}