123 lines
3.3 KiB
TypeScript
Raw Normal View History

2023-12-10 00:58:43 +08:00
import { Vec2 } from "cc";
2023-12-08 21:26:47 +08:00
import GDefaultMode from "./default/GDefaultMode";
2023-12-10 00:58:43 +08:00
import { TB } from "../../../resources/config/data/schema";
import GRoleDefault from "../base/role/GRoleDefault";
2023-12-11 10:42:36 +08:00
import { _decorator } from "cc";
2023-12-12 18:54:31 +08:00
import GBaseMode from "../GBaseMode";
import { Prefab } from "cc";
import { instantiate } from "cc";
import GRoleCGCrystal from "../base/role/CampGuardian/GRoleCGCrystal";
import { TD } from "../../App";
import { GTowards } from "../base/GObject";
import GRoleBase from "../base/role/GRoleBase";
2023-12-13 10:51:31 +08:00
import { GTactical } from "../entity/GTactical";
import JNFrameTime from "../../../../extensions/ngame/assets/ngame/sync/frame/game/time/JNFrameTime";
2023-12-11 10:42:36 +08:00
const { ccclass, property } = _decorator;
2023-12-08 21:26:47 +08:00
2023-12-12 18:54:31 +08:00
//阵营守护 角色
export enum GCampGuardianEnum{
PLAYER, //玩家
ENEMY, //敌人
}
2023-12-08 21:26:47 +08:00
//阵营守护
//玩家派兵攻击对方阵营 游戏参考
2023-12-11 10:42:36 +08:00
@ccclass('GCampGuardianMode')
2023-12-12 18:54:31 +08:00
export default class GCampGuardianMode extends GBaseMode<{},{}>{
2023-12-08 21:26:47 +08:00
2023-12-10 00:58:43 +08:00
//玩家水晶位置
2023-12-12 18:54:31 +08:00
playerPos: Vec2 = new Vec2(-600,0);
2023-12-11 10:42:36 +08:00
//敌方水晶位置
2023-12-12 18:54:31 +08:00
enemyPos: Vec2 = new Vec2(600,0);
//我方水晶
//敌方水晶
//水晶预制体
@property(Prefab)
crystalPrefab: Prefab;
//角色预制体
@property(Prefab)
petPrefab: Prefab;
2023-12-08 21:26:47 +08:00
2023-12-12 18:54:31 +08:00
//玩家宠物
playerRoles: GRoleBase<{}>[] = [];
//敌方宠物
enemyRoles: GRoleBase<{}>[] = [];
2023-12-10 00:58:43 +08:00
onSyncInitSuccess(){
2023-12-12 18:54:31 +08:00
//生成水晶
this.onGenCrystal(GCampGuardianEnum.PLAYER);
this.onGenCrystal(GCampGuardianEnum.ENEMY);
2023-12-10 00:58:43 +08:00
2023-12-13 10:51:31 +08:00
//定时器生成
JNFrameTime.getInstance().setInterval(() => {
// this.onGenRole(GCampGuardianEnum.PLAYER,TD.TbGRole.get());
},1000)
2023-12-10 00:58:43 +08:00
}
2023-12-12 18:54:31 +08:00
//生成水晶
onGenCrystal(type:GCampGuardianEnum){
let crystalNode = instantiate(this.crystalPrefab);
let crystal = crystalNode.getComponent(GRoleCGCrystal);
crystal.init(TD.TbGRole.get(10005));
switch(type){
case GCampGuardianEnum.PLAYER:
this.addGObject(crystal,this.playerPos)
break;
case GCampGuardianEnum.ENEMY:
crystal.setTowards(GTowards.LEFT)
this.addGObject(crystal,this.enemyPos)
break;
}
}
2023-12-11 10:42:36 +08:00
2023-12-13 10:51:31 +08:00
//生成宠物
onGenRole(type:GCampGuardianEnum,info:TB.TbGRole):GRoleDefault {
2023-12-10 00:58:43 +08:00
2023-12-13 10:51:31 +08:00
let tactical = GTactical.getTactical();
let pos:Vec2;
switch(type){
case GCampGuardianEnum.PLAYER:
pos = tactical.getPosXYPosition(1,1,this.playerPos);
break;
case GCampGuardianEnum.ENEMY:
pos = tactical.getPosXYPosition(1,1,this.enemyPos);
break;
}
2023-12-10 00:58:43 +08:00
2023-12-13 10:51:31 +08:00
if(!pos) return;
let role = instantiate(this.petPrefab);
2023-12-10 00:58:43 +08:00
2023-12-13 10:51:31 +08:00
let entity = role.getComponent(GRoleDefault);
//初始化
entity.onInit(type,info,tactical,tactical.getPosXY(1,1));
2023-12-10 00:58:43 +08:00
2023-12-13 10:51:31 +08:00
// //绑定寻敌
// entity.onQueryEunmy = () => {
// return this.getEnumy(entity,type);
// }
2023-12-10 00:58:43 +08:00
2023-12-13 10:51:31 +08:00
// //绑定死亡回调
// entity.addKillBackEvent(this.onRoleKillBack.bind(this))
// //绑定受击回调
// entity.addHitCallback(this.onHitBack.bind(this));
2023-12-10 00:58:43 +08:00
2023-12-13 10:51:31 +08:00
this.addGObject(entity,pos);
return entity;
2023-12-10 00:58:43 +08:00
2023-12-13 10:51:31 +08:00
}
2023-12-08 21:26:47 +08:00
}