mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交拖拽阵法
This commit is contained in:
@@ -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 [];
|
||||
|
Reference in New Issue
Block a user