提交拖拽阵法

This commit is contained in:
PC-20230316NUNE\Administrator
2023-11-16 19:10:19 +08:00
parent 1683ec01a0
commit c4437fef5e
24 changed files with 509 additions and 96 deletions

View File

@@ -44,6 +44,11 @@ export default abstract class GRoleBase<T> extends GObject<T>{
get isDie(){ return this._isDie}
set isDie(value:boolean){
this._isDie = value;
if(this.isDie){
//如果死亡则关闭状态机
//关闭状态机
this.fsm.close();
}
}
//受击回调

View File

@@ -39,6 +39,8 @@ export default class GRoleDefault extends GRoleBase<{}>{
//设置死亡状态
this.fsmAnim.isDie = value;
if(this.isDie){
//关闭状态机
this.fsm.close();
//死亡回调
this.killBack.forEach(fun => fun(this));
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "eacc8f2a-91b5-4bb6-b11b-6f1c688fdcf0",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,11 @@
import { JNGSyncProtoBase } from "../../../../components/JNComponent";
import GRoleBase from "../GRoleBase";
/**
* 扩展类基类 用于代码动态添加 角色脚本的类
*/
export default class GRoleExpandBase<T> extends JNGSyncProtoBase<T>{
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "bba56115-aac1-4e5e-bc8e-087bf92232a3",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "90bf5822-cd37-491b-a89b-182bbcec4c49",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,18 @@
import { _decorator } from "cc";
import GRoleDefault from "../../GRoleDefault";
import GRoleExpandBase from "../GRoleExpandBase";
const { ccclass, property } = _decorator;
/**
* 角色 无限模式 扩展类
*/
@ccclass('GRoleDefault')
export default class GRoleOnHookExpand extends GRoleExpandBase<{}>{
//角色Id
petId:number;
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "edf60f56-5d3e-48d1-90b4-6deef4b5635c",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -16,6 +16,10 @@ import { v3 } from "cc";
import { v2 } from "cc";
import GFSMOnHookMode from "./OnHook/GFSMOnHookMode";
import { TB } from "../../../resources/config/data/schema";
import PlayerTacticalData, { PlayerTacticalEvent } from "../../data/PlayerTacticalData";
import GRoleOnHookExpand from "../base/role/expand/OnHook/GRoleOnHookExpand";
import PlayerPetData from "../../data/PlayerPetData";
import { GUI } from "../../ui/UIConfig";
const { ccclass, property } = _decorator;
//挂机模式状态
@@ -99,6 +103,16 @@ export default class GOnHookMode extends GBaseMode<{}>{
//是否允许攻击
isAllowAttack:boolean = false;
//添加监听事件
addEvent(){
app.event.on(PlayerTacticalEvent.UPDATE_TACTICAL,this.onUpdatePlayerPet,this);
}
//移除监听事件
onDestroy(){
super.onDestroy();
app.event.off(PlayerTacticalEvent.UPDATE_TACTICAL,this.onUpdatePlayerPet,this);
}
onSyncInitSuccess():void{
//初始化战斗
@@ -124,14 +138,45 @@ export default class GOnHookMode extends GBaseMode<{}>{
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.onUpdatePlayerPet();
//添加监听
this.addEvent();
//生成玩家
this.playerInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.PLAYER,index + 1,info))
// this.playerInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.PLAYER,index + 1,info))
// //生成敌人
// this.onResetGenerateEnemy();
}
//更新玩家宠物
onUpdatePlayerPet(){
//获取玩家阵容
let infos = PlayerTacticalData.getIns().getTacticalInfo();
//移除不再阵容中的宠物
let roles = [...this.getOnesRoleAlive(GOnHookModePlayerEnum.PLAYER)]
roles.forEach(role => {
let expand = role.getComponent(GRoleOnHookExpand);
//如果宠物不再阵容中 则 移除宠物
if(infos.indexOf(expand.petId) < 0){
//移除宠物
this.playerRoles.splice(this.playerRoles.indexOf(role),1);
role.isDie = true;
}
})
infos.forEach((petId,index) => {
if(petId){
this.onGenPlayerPet(index+1,petId);
}
})
}
//更新帧
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: {}){
super.onSyncUpdate(dt,frame,input);
this.onUpdateMap(dt);
@@ -170,13 +215,42 @@ export default class GOnHookMode extends GBaseMode<{}>{
}
//生成玩家宠物
onGenPlayerPet(index:number,petId:number){
//如果场上有这个宠物则更新阵法位置
let passRole:GRoleDefault;
this.playerRoles.forEach(role => {
if(role.getComponent(GRoleOnHookExpand).petId == petId)
passRole = role;
})
if(passRole){
//更新宠物阵法位置
passRole.tacticalIndex = index;
return;
}
//获取要生成的宠物
let info = PlayerPetData.getIns().petIdQueryPetInfo(petId);
if(!info){
app.layer.Open(GUI.Tips,{text:"未拥有当前上阵的宠物"});
return;
}
let role = this.onGenRole(GOnHookModePlayerEnum.PLAYER,index,TD.TbGRole.get(info.petTbId));
//向宠物添加 OnHook 扩展
let expand = role.node.addComponent(GRoleOnHookExpand);
expand.petId = petId;
}
//生成宠物
onGenRole(type: GOnHookModePlayerEnum,index:number,info:TB.TbGRole) {
onGenRole(type: GOnHookModePlayerEnum,index:number,info:TB.TbGRole):GRoleDefault {
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);
@@ -190,8 +264,11 @@ export default class GOnHookMode extends GBaseMode<{}>{
entity.addKillBackEvent(this.onRoleKillBack.bind(this))
this.addGObject(entity,tactical.getPosition(index));
this.getOnesRole(type).push(entity);
return entity;
}
//获取配置
@@ -251,6 +328,10 @@ export default class GOnHookMode extends GBaseMode<{}>{
if(role.isValid)
role.node.destroy()
},3000)
//清理
this.onClearCache();
// //如果没有敌人则生成敌人
// if(this.getOnesRole(GOnHookModePlayerEnum.ENEMY).filter(role => !!role.get()).length <= 0){
// //生成敌人
@@ -258,6 +339,25 @@ export default class GOnHookMode extends GBaseMode<{}>{
// }
}
//清理缓存
onClearCache(){
//清理宠物
let roles = [...this.playerRoles];
roles.forEach(role => {
if(!role.get()){
this.playerRoles.splice(this.playerRoles.indexOf(role),1);
}
})
roles = [...this.enemyRoles];
roles.forEach(role => {
if(!role.get()){
this.enemyRoles.splice(this.enemyRoles.indexOf(role),1);
}
})
}
//是否有怪物
isHaveEnemy(){
if(!this.isAllowAttack) return [];