mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
update
This commit is contained in:
10
JisolGameCocos/assets/script/battle/modes/GLDLEMode.ts
Normal file
10
JisolGameCocos/assets/script/battle/modes/GLDLEMode.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import GBaseMode from "../GBaseMode";
|
||||
|
||||
|
||||
/**
|
||||
* 挂机模式
|
||||
*/
|
||||
export default class GLDLEMode extends GBaseMode<{}>{
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c579d727-c0c2-422f-8571-3375047fd1b8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
142
JisolGameCocos/assets/script/battle/modes/GPVPMode.ts
Normal file
142
JisolGameCocos/assets/script/battle/modes/GPVPMode.ts
Normal file
@@ -0,0 +1,142 @@
|
||||
import { _decorator } from "cc";
|
||||
import GBaseMode from "../GBaseMode";
|
||||
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 GRole, { GRoleUtil } from "../entity/GRole";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
|
||||
|
||||
//PVP 角色
|
||||
export enum GPVPModePlayerEnum{
|
||||
PLAYER, //玩家
|
||||
ENEMY, //敌人
|
||||
}
|
||||
|
||||
//PVP 玩家信息
|
||||
export interface GPVPModePlayerInfo{
|
||||
//阵法
|
||||
tactical: GTactical;
|
||||
//宠物列表
|
||||
roles: GRole[];
|
||||
}
|
||||
|
||||
/**
|
||||
* PVP 模式
|
||||
*/
|
||||
@ccclass('GPVPMode')
|
||||
export default class GPVPMode extends GBaseMode<{}>{
|
||||
|
||||
@property(Prefab)
|
||||
rolePrefab: Prefab = null;
|
||||
|
||||
//玩家信息
|
||||
playerInfo: GPVPModePlayerInfo;
|
||||
//敌方信息
|
||||
enemyInfo: GPVPModePlayerInfo;
|
||||
|
||||
//玩家宠物
|
||||
playerRoles: GRolePVPEntity[] = [];
|
||||
//敌方宠物
|
||||
enemyRoles: GRolePVPEntity[] = [];
|
||||
|
||||
//玩家位置
|
||||
playerPos: Vec2 = new Vec2(-400,0);
|
||||
//敌方位置
|
||||
enemyPos: Vec2 = new Vec2(400,0);
|
||||
|
||||
onLoad(){
|
||||
super.onLoad();
|
||||
}
|
||||
|
||||
|
||||
onSyncInitSuccess(): void {
|
||||
|
||||
//初始化战斗
|
||||
console.log("GPVPMode 模式初始化");
|
||||
|
||||
this.playerInfo = { tactical: GTactical.getTactical(),roles: GRoleUtil.getGRoles([10001,10001,10001,10001,10001]) };
|
||||
this.enemyInfo = { tactical: GTactical.getTactical(true),roles: GRoleUtil.getGRoles([10002,10002,10002,10001,10001]) };
|
||||
|
||||
//生成玩家
|
||||
this.playerInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.PLAYER,index+1,info))
|
||||
this.enemyInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.ENEMY,index+1,info))
|
||||
|
||||
}
|
||||
|
||||
//生成角色
|
||||
onGenRole(type: GPVPModePlayerEnum,index:number,info:GRole) {
|
||||
|
||||
let pos:Vec2 = this.getInfo(type).tactical.getPosition(index);
|
||||
if(!pos) return;
|
||||
let role = instantiate(this.rolePrefab);
|
||||
let entity = role.getComponent(GRolePVPEntity)
|
||||
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);
|
||||
this.getOnesRole(type).push(entity);
|
||||
|
||||
}
|
||||
|
||||
//获取配置
|
||||
getInfo(type: GPVPModePlayerEnum): GPVPModePlayerInfo {
|
||||
if(type == GPVPModePlayerEnum.PLAYER) return this.playerInfo;
|
||||
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[]{
|
||||
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))
|
||||
});
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "31e6d29e-41d4-4d7d-a24a-b37f9c0caabd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user