重构继承关系

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2023-11-01 02:01:35 +08:00
parent e59c5640d7
commit 6ebed0b45e
43 changed files with 496 additions and 524 deletions

View File

@@ -1,20 +1,15 @@
import { _decorator, sp } from "cc";
import GObject, { GTowards } from "../GObject";
import { JNFrameInfo } from "../../../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
import GFSMBattle from "../fsm/base/GFSMBattle/GFSMBattle";
import { GFSMBattleAmin, GFSMBattleAminEnum } from "../fsm/base/GFSMBattle/GFSMBattleAmin";
import { Vec2 } from "cc";
import { v3 } from "cc";
import { GTactical } from "../../entity/GTactical";
import { JEasing, JTween } from "../../../../../extensions/ngame/assets/ngame/sync/frame/game/tween/JNFrameTween";
import { v2 } from "cc";
import { app } from "../../../App";
import { TableGRoleAttack } from "../../../../resources/config/ts/TableGRoleAttack";
import { GAttack, GAttackBase } from "../attack/GAttack";
import { TableGRole } from "../../../../resources/config/ts/TableGRole";
import { TableGRoleSkill } from "../../../../resources/config/ts/TableGRoleSkill";
import { GSkill, GSkillBase, GSkillState } from "../../skill/GSkill";
import JNSkeleton from "../../../../../extensions/ngame/assets/ngame/sync/frame/game/spine/JNFrameSkeleton";
import { GFSMAnimBase } from "../fsm/GFSMAnimBase";
import GFSMBase from "../fsm/GFSMBase";
import { app } from "../../../App";
const { ccclass, property } = _decorator;
export enum GRoleAnimEvent{
@@ -28,19 +23,13 @@ export default abstract class GRoleBase<T> extends GObject<T>{
spine:JNSkeleton;
//角色
role:TableGRole
//角色技能
skills:GSkillBase[] = [];
//角色类型
type:number;
role:TableGRole;
//状态机
fsm:GFSMBattle;
fsm:GFSMBase;
//动画状态机
fsmAnim:GFSMBattleAmin;
fsmAnim:GFSMAnimBase;
//玩家攻击范围
range:number = 100;
@@ -48,20 +37,6 @@ export default abstract class GRoleBase<T> extends GObject<T>{
//移动速度
moveSpeed:number = 80;
//在阵容中的下标
tacticalIndex:number;
//阵容
_tactical:GTactical;
get tactical(){return this._tactical};
set tactical(value:GTactical){
this.setTowards(value.towards);
this._tactical = value;
}
//阵容位置
_tacticalPos:Vec2;
get tacticalPos(){ return this._tacticalPos}
set tacticalPos(value:Vec2){ this._tacticalPos = value}
//血量
blood:number = 100;
fullBlood:number = 100;
@@ -71,8 +46,6 @@ export default abstract class GRoleBase<T> extends GObject<T>{
get isDie(){ return this._isDie}
set isDie(value:boolean){
this._isDie = value;
//设置死亡状态
this.fsmAnim.isDie = value;
}
//受击回调
@@ -85,7 +58,7 @@ export default abstract class GRoleBase<T> extends GObject<T>{
//添加受击回调
addAttackCallback(fun:Function){this.attackCallbacks.push(fun)};
get():GRoleBase<T>{
get():this{
if(this.isDie) return null;
return this;
}
@@ -99,41 +72,23 @@ export default abstract class GRoleBase<T> extends GObject<T>{
return;
}
// this.spine.debugBones = true;
this.bind(this.role);
//创建角色状态机
this.fsm = this.fsmCreate();
//创建角色动画状态机
this.fsmAnim = this.fsmAnimCreate();
//监听攻击
this.fsmAnim.addEventListener(GRoleAnimEvent.Attack,this.onAttack.bind(this));
//监听死亡击飞
this.fsmAnim.addStartListener(GFSMBattleAminEnum.Fly,this.onFly.bind(this));
}
//设置角色
bind(role:TableGRole){
//初始化
protected init(role:TableGRole){
if(this.spine)
this.spine.skeletonData = app.role.skData[role.id];
this.range = role.roleAttackRange; //设置攻击范围
this.role = role; //设置角色
// 设置技能
this.skills = role.roleSkillIds.map(skillId => {
let info = TableGRoleSkill.getConfig(skillId);
return (new GSkill[info.skillController]()).bind(this,info);
})
}
//创建一个状态机
protected abstract fsmCreate():GFSMBattle;
protected abstract fsmCreate():GFSMBase;
//创建一个动画状态机
protected abstract fsmAnimCreate():GFSMBattleAmin;
protected abstract fsmAnimCreate():GFSMAnimBase;
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T){
@@ -141,9 +96,6 @@ export default abstract class GRoleBase<T> extends GObject<T>{
this.fsm && this.fsm.onUpdate(dt / 1000);
this.fsmAnim && this.fsmAnim.onUpdate(dt / 1000);
//更新技能
this.skills.forEach(skill => skill.onUpdate(dt));
}
//向目标点移动
@@ -188,29 +140,6 @@ export default abstract class GRoleBase<T> extends GObject<T>{
}
}
//攻击
onAttack(){
if(!this.fsm.enemy) return;
//敌人扣血
let info = TableGRoleAttack.getConfig(this.role.id);
(new GAttack[info.attackWay]()).attack(this,info);
this.attackCallbacks.forEach(fun => fun());
}
//释放技能 每一次只能释放一次
onSkill():boolean{
for (const item of this.skills) {
if(item.isRelease()){
//如果可以释放则释放
item.release();
return true;
}
}
return false;
}
//受击
onHit(){
// return;
@@ -236,66 +165,6 @@ export default abstract class GRoleBase<T> extends GObject<T>{
}
}
//击飞
onFly(){
if(this.nId == 1)
console.log("onFly");
let vWorld = this.node.worldPosition;
let vEndWorld = this.getWorldBackLen(v2(1500,500));
this.JTween(vWorld)
.to({x:vEndWorld.x},1000)
.onUpdate(pos => this.node.worldPosition = pos)
.start();
this.JTween(vWorld)
.to({y:vEndWorld.y},1000)
.easing(JEasing.Circular.Out)
.onUpdate(pos => this.node.worldPosition = vWorld)
.start();
}
//恢复阵容朝向
onRecoverTacticalTowards(){
this.setTowards(this.tactical.towards);
}
//过滤敌人
filterEnemy(roles:GRoleBase<{}>[] = []){
return roles.filter(role => role.type != this.type);
}
//判断是否可以释放技能
isReleaseSkill():boolean{
for (const skill of this.skills) {
if(skill.isRelease()){
return true;
}
}
return false;
}
//释放技能
onReleaseSkill():boolean{
for (const skill of this.skills) {
if(skill.isRelease()){
skill.release();
return true;
}
}
return false;
}
//是否正在释放技能
isReleasingSkill():boolean {
for (const skill of this.skills) {
if(skill.state() == GSkillState.Releasing){
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,200 @@
import { _decorator } from "cc";
import GRoleBase, { GRoleAnimEvent } from "./GRoleBase";
import { ProgressBar } from "cc";
import { JNFrameInfo } from "../../../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
import { TableGRole } from "../../../../resources/config/ts/TableGRole";
import { GFSMAnimBase, GFSMBattleAminEnum } from "../fsm/GFSMAnimBase";
import { GFSMDefaultAnim } from "../fsm/Default/GFSMDefaultAnim";
import GFSMDefault from "../fsm/Default/GFSMDefault";
import { JEasing } from "../../../../../extensions/ngame/assets/ngame/sync/frame/game/tween/JNFrameTween";
import { TableGRoleAttack } from "../../../../resources/config/ts/TableGRoleAttack";
import { GAttack } from "../attack/GAttack";
import { v2 } from "cc";
import { GTactical } from "../../entity/GTactical";
import { Vec2 } from "cc";
import { GSkill, GSkillBase, GSkillState } from "../../skill/GSkill";
import { TableGRoleSkill } from "../../../../resources/config/ts/TableGRoleSkill";
const { property,ccclass } = _decorator;
//默认角色类
@ccclass('GRoleDefault')
export default class GRoleDefault extends GRoleBase<{}>{
@property(ProgressBar)
bloodVolume:ProgressBar;
//能量条
@property(ProgressBar)
energyVolume:ProgressBar;
//状态机
fsm:GFSMDefault;
//动画状态机
fsmAnim:GFSMDefaultAnim;
get isDie(){ return this._isDie}
set isDie(value:boolean){
this._isDie = value;
//设置死亡状态
this.fsmAnim.isDie = value;
}
//角色类型
type:number;
//在阵容中的下标
tacticalIndex:number;
//阵容
_tactical:GTactical;
get tactical(){return this._tactical};
set tactical(value:GTactical){
this.setTowards(value.towards);
this._tactical = value;
}
//阵容位置
get tacticalPos(){ return this.tactical.getPosition(this.tacticalIndex)}
//角色技能
skills:GSkillBase[] = [];
onSyncLoad(){
super.onSyncLoad();
//监听攻击
this.fsmAnim.addEventListener(GRoleAnimEvent.Attack,this.onAttack.bind(this));
//监听死亡击飞
this.fsmAnim.addStartListener(GFSMBattleAminEnum.Fly,this.onFly.bind(this));
}
//初始化
onInit(type:number,role:TableGRole,tactical:GTactical,tacticalIndex:number){
super.init(role);
this.type = type;
this.range = role.roleAttackRange; //设置攻击范围
this.role = role; //设置角色
this.tactical = tactical;
this.tacticalIndex = tacticalIndex;
// 设置技能
this.skills = role.roleSkillIds.map(skillId => {
let info = TableGRoleSkill.getConfig(skillId);
return (new GSkill[info.skillController]()).bind(this,info);
})
}
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: {}) {
super.onSyncUpdate(dt,frame,input);
//更新技能
this.skills.forEach(skill => skill.onUpdate(dt));
//更新显示
this.bloodVolume.progress = this.blood / this.fullBlood;
//显示第一个技能进度条
if(this.skills[0]){
this.energyVolume.progress = this.skills[0].getProgress();
}
}
protected fsmCreate(): GFSMDefault {
return new GFSMDefault(this);
}
protected fsmAnimCreate(): GFSMDefaultAnim {
return new GFSMDefaultAnim(this.spine);
}
//攻击
onAttack(){
if(!this.fsm.enemy) return;
//敌人扣血
let info = TableGRoleAttack.getConfig(this.role.id);
(new GAttack[info.attackWay]()).attack(this,info);
this.attackCallbacks.forEach(fun => fun());
}
//击飞
onFly(){
let vWorld = this.node.worldPosition;
let vEndWorld = this.getWorldBackLen(v2(1500,500));
this.JTween(vWorld)
.to({x:vEndWorld.x},1000)
.onUpdate(pos => this.node.worldPosition = pos)
.start();
this.JTween(vWorld)
.to({y:vEndWorld.y},1000)
.easing(JEasing.Circular.Out)
.onUpdate(pos => this.node.worldPosition = vWorld)
.start();
}
//过滤敌人
filterEnemy(roles:GRoleDefault[] = []){
return roles.filter(role => role.type != this.type);
}
//恢复阵容朝向
onRecoverTacticalTowards(){
this.setTowards(this.tactical.towards);
}
//释放技能 每一次只能释放一次
onSkill():boolean{
for (const item of this.skills) {
if(item.isRelease()){
//如果可以释放则释放
item.release();
return true;
}
}
return false;
}
//判断是否可以释放技能
isReleaseSkill():boolean{
for (const skill of this.skills) {
if(skill.isRelease()){
return true;
}
}
return false;
}
//释放技能
onReleaseSkill():boolean{
for (const skill of this.skills) {
if(skill.isRelease()){
skill.release();
return true;
}
}
return false;
}
//是否正在释放技能
isReleasingSkill():boolean {
for (const skill of this.skills) {
if(skill.state() == GSkillState.Releasing){
return true;
}
}
return false;
}
onQueryEunmy():GRoleDefault{
return null;
}
}

View File

@@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "9fc034a7-5c68-4f22-9065-447435329c8a",
"uuid": "27681ee3-9d09-4a06-be5e-71af045319b8",
"files": [],
"subMetas": {},
"userData": {}

View File

@@ -1,12 +0,0 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "34152d1b-ca03-4bb1-a970-692cd8995991",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -1,86 +0,0 @@
import { _decorator } from "cc";
import GRoleBase from "../GRoleBase";
import GFSMPVP from "../../fsm/PVP/GFSMPVP";
import GPVPMode, { GPVPModePlayerEnum } from "../../../modes/GPVPMode";
import { GFSMBattleAmin } from "../../fsm/base/GFSMBattle/GFSMBattleAmin";
import { JNFrameInfo } from "../../../../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
import { ProgressBar } from "cc";
const { ccclass, property } = _decorator;
export interface GDemoMessage{
isAttack?:boolean;
isRun?:boolean;
}
//PVP 角色
@ccclass('GRolePVPEntity')
export default class GRolePVPEntity extends GRoleBase<GDemoMessage>{
//所属阵容
_ones:GPVPModePlayerEnum;
get ones():GPVPModePlayerEnum{
return this._ones;
}
set ones(value:GPVPModePlayerEnum){
this._ones = value;
}
@property(ProgressBar)
bloodVolume:ProgressBar;
//能量条
@property(ProgressBar)
energyVolume:ProgressBar;
onSyncLoad(){
super.onSyncLoad();
}
getClassName():string{return "GDemoMessage"}
onSyncUpdate(dt: number,frame:JNFrameInfo, input?: GDemoMessage) {
super.onSyncUpdate(dt,frame,input);
if(input){
if(Object.prototype.hasOwnProperty.call(input,"isAttack")){
this.fsmAnim.isAttack = input.isAttack;
}
if(Object.prototype.hasOwnProperty.call(input,"isRun")){
this.fsmAnim.isMove = input.isRun;
}
}
//更新显示
this.bloodVolume.progress = this.blood / this.fullBlood;
//显示第一个技能进度条
if(this.skills[0]){
this.energyVolume.progress = this.skills[0].getProgress();
}
}
get mode():GPVPMode{
return super.mode as GPVPMode;
}
set mode(value:GPVPMode){
this._mode = value;
}
protected fsmCreate(): GFSMPVP {
return new GFSMPVP(this);
}
protected fsmAnimCreate(): GFSMBattleAmin {
return new GFSMBattleAmin(this.spine);
}
//添加死亡销毁
onHit(){
super.onHit();
if(this.isDie){
//销毁数据
this.mode.killRole(this);
}
}
}