mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 11:24:46 +00:00
106 lines
3.0 KiB
TypeScript
106 lines
3.0 KiB
TypeScript
|
import { _decorator } from "cc";
|
||
|
import GBaseMode from "../GBaseMode";
|
||
|
import { TB, TbGEntity } from "../../config/data/schema";
|
||
|
import PlayerTacticalData from "../../data/PlayerTacticalData";
|
||
|
import PlayerPetData from "../../data/PlayerPetData";
|
||
|
import { TD, app } from "../../App";
|
||
|
import { GUI } from "../../ui/UIConfig";
|
||
|
import { GOnHookModePlayerEnum } from "./GOnHookMode";
|
||
|
import GRoleDefault from "../base/role/GRoleDefault";
|
||
|
const { ccclass, property } = _decorator;
|
||
|
|
||
|
|
||
|
//角色
|
||
|
export enum GDungeonModeEnum{
|
||
|
PLAYER, //玩家
|
||
|
ENEMY, //怪物
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 副本(默认) 模式
|
||
|
*/
|
||
|
@ccclass('GDungeonMode')
|
||
|
export default class GDungeonMode extends GBaseMode<{},TbGEntity.TDungeon>{
|
||
|
|
||
|
|
||
|
//生成玩家宠物
|
||
|
onGenPlayerPet(index:number,petId:number){
|
||
|
|
||
|
//获取玩家阵容
|
||
|
let infos = PlayerTacticalData.getIns().getTacticalInfo();
|
||
|
|
||
|
infos.forEach(petId => {
|
||
|
|
||
|
//获取要生成的宠物
|
||
|
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));
|
||
|
|
||
|
})
|
||
|
|
||
|
//如果场上有这个宠物则更新阵法位置
|
||
|
let passRole:GRoleDefault;
|
||
|
this.playerRoles.forEach(role => {
|
||
|
if(role.getComponent(GRoleOnHookPlayerExpand).petId == petId)
|
||
|
passRole = role;
|
||
|
})
|
||
|
if(passRole){
|
||
|
//更新宠物阵法位置
|
||
|
passRole.tacticalIndex = index;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
|
||
|
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(GRoleOnHookPlayerExpand);
|
||
|
expand.petId = petId;
|
||
|
|
||
|
//添加宠物属性
|
||
|
role.onEffectiveValue(GBattleData.getIns().data.getPetAttribute(petId));
|
||
|
|
||
|
}
|
||
|
|
||
|
//生成宠物
|
||
|
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);
|
||
|
|
||
|
//绑定寻敌
|
||
|
entity.onQueryEunmy = () => {
|
||
|
return this.getEnumy(entity,type);
|
||
|
}
|
||
|
|
||
|
//绑定死亡回调
|
||
|
entity.addKillBackEvent(this.onRoleKillBack.bind(this))
|
||
|
//绑定受击回调
|
||
|
entity.addHitCallback(this.onHitBack.bind(this));
|
||
|
|
||
|
this.addGObject(entity,tactical.getPosition(index));
|
||
|
|
||
|
this.getOnesRole(type).push(entity);
|
||
|
|
||
|
return entity;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|