mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 03:14:47 +00:00
88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
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";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
//PVP 角色
|
|
export enum GPVPModePlayerEnum{
|
|
PLAYER, //玩家
|
|
ENEMY, //敌人
|
|
}
|
|
|
|
//PVP 玩家信息
|
|
export interface GPVPModePlayerInfo{
|
|
//阵法
|
|
tactical: GTactical;
|
|
//宠物列表
|
|
roles: any[];
|
|
}
|
|
|
|
/**
|
|
* PVP 模式
|
|
*/
|
|
@ccclass('GPVPMode')
|
|
export default class GPVPMode extends GBaseMode{
|
|
|
|
@property(Prefab)
|
|
rolePrefab: Prefab = null;
|
|
|
|
//玩家信息
|
|
playerInfo: GPVPModePlayerInfo = { tactical: GTactical.getTactical1(),roles: [{},{},{}] };
|
|
//敌方信息
|
|
enemyInfo: GPVPModePlayerInfo = { tactical: GTactical.getTactical2(true),roles: [{},{},{}] };
|
|
|
|
//玩家宠物
|
|
playerRoles: GRoleEntity[] = [];
|
|
//敌方宠物
|
|
enemyRoles: GRoleEntity[] = [];
|
|
|
|
//玩家位置
|
|
playerPos: Vec2 = new Vec2(-400,0);
|
|
//敌方位置
|
|
enemyPos: Vec2 = new Vec2(400,0);
|
|
|
|
|
|
onSyncInitSuccess(): void {
|
|
|
|
//初始化战斗
|
|
console.log("GPVPMode 模式初始化");
|
|
|
|
//生成玩家
|
|
this.playerInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.PLAYER,index+1))
|
|
this.enemyInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.ENEMY,index+1))
|
|
|
|
}
|
|
|
|
//生成角色
|
|
onGenRole(type: GPVPModePlayerEnum,index:number) {
|
|
|
|
let pos:Vec2 = this.getInfo(type).tactical.getPosition(index);
|
|
if(!pos) return;
|
|
let role = instantiate(this.rolePrefab);
|
|
let entity = role.getComponent(GRoleEntity)
|
|
this.addGObject(entity,this.getInfo(type).tactical.getPosition(index,this.getTacticalPos(type)));
|
|
|
|
}
|
|
|
|
//获取配置
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
|