重构继承关系

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

@ -3,7 +3,6 @@
"__type__": "cc.SceneAsset",
"_name": "Main",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"scene": {
"__id__": 1
@ -148,14 +147,8 @@
"octree": {
"__id__": 10
},
"skin": {
"__id__": 11
},
"lightProbeInfo": {
"__id__": 12
},
"postSettings": {
"__id__": 13
"__id__": 11
},
"bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false
@ -284,12 +277,6 @@
},
"_depth": 8
},
{
"__type__": "cc.SkinInfo",
"_enabled": false,
"_blurRadius": 0.01,
"_sssIntensity": 3
},
{
"__type__": "cc.LightProbeInfo",
"_giScale": 1,
@ -299,11 +286,6 @@
"_showProbe": true,
"_showWireframe": true,
"_showConvex": false,
"_data": null,
"_lightProbeSphereVolume": 1
},
{
"__type__": "cc.PostSettingsInfo",
"_toneMappingType": 0
"_data": null
}
]

View File

@ -1,7 +1,7 @@
[
{
"__type__": "cc.Prefab",
"_name": "GLDLEMode",
"_name": "GOnHookMode",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
@ -13,7 +13,7 @@
},
{
"__type__": "cc.Node",
"_name": "GLDLEMode",
"_name": "GOnHookMode",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,

View File

@ -8,6 +8,6 @@
],
"subMetas": {},
"userData": {
"syncNodeName": "GLDLEMode"
"syncNodeName": "GOnHookMode"
}
}

View File

@ -1,9 +1,8 @@
[
{
"__type__": "cc.Prefab",
"_name": "RolePVPEntity",
"_name": "GRoleDefault",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"data": {
"__id__": 1
@ -13,7 +12,7 @@
},
{
"__type__": "cc.Node",
"_name": "RolePVPEntity",
"_name": "GRoleDefault",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
@ -730,54 +729,27 @@
"b": 255,
"a": 255
},
"_skeletonData": null,
"defaultSkin": "",
"defaultAnimation": "",
"_premultipliedAlpha": true,
"loop": true,
"_timeScale": 1,
"_useTint": false,
"_preCacheMode": 0,
"_cacheMode": 0,
"_defaultCacheMode": 0,
"_sockets": [],
"_useTint": false,
"_debugMesh": false,
"_debugBones": false,
"_debugSlots": false,
"_skeletonData": null,
"_premultipliedAlpha": true,
"defaultSkin": "",
"defaultAnimation": "",
"_enableBatch": false,
"loop": true,
"_sockets": [],
"_debugMesh": false,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "27Fx6O7FRLnbRD+LXrrqfA"
},
{
"__type__": "9fc03SnXGhPIpBlRHQ1MpyK",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 35
},
"spine": {
"__id__": 32
},
"bloodVolume": {
"__id__": 13
},
"energyVolume": {
"__id__": 27
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "89OuR1/75BxLrKGMeVKN5C"
},
{
"__type__": "cc.BoxCollider2D",
"_name": "",
@ -788,7 +760,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 37
"__id__": 35
},
"tag": 0,
"_group": 1,
@ -812,6 +784,32 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "adZ/2FFS1AnqaNLGcoBV8b"
},
{
"__type__": "276817jnQlKBr5eca8EUxm4",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 37
},
"spine": {
"__id__": 32
},
"bloodVolume": {
"__id__": 13
},
"energyVolume": {
"__id__": 27
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "1egRZj86lNFKKDFfl2+ddc"
},
{
"__type__": "cc.PrefabInfo",
"root": {

View File

@ -8,6 +8,6 @@
],
"subMetas": {},
"userData": {
"syncNodeName": "RolePVPEntity"
"syncNodeName": "GRoleDefault"
}
}

View File

@ -5,6 +5,9 @@ import GAttackNormal from "./GAttackNormal";
import GAttackParabolicBangRemote from "./GAttackParabolicBangRemote";
import { UITransform } from "cc";
import GButtleBase from "../bullet/GButtleBase";
import { GFSMAnimBase } from "../fsm/GFSMAnimBase";
import GFSMBase from "../fsm/GFSMBase";
import GRoleDefault from "../role/GRoleDefault";
//攻击子弹类
export class GAttackBullet{
@ -22,7 +25,7 @@ export class GAttackBullet{
//攻击方式基类
export interface GAttackBase{
attack(role:GRoleBase<{}>,info:TableGRoleAttack);
attack(role:GRoleDefault,info:TableGRoleAttack);
}
//攻击方式

View File

@ -1,12 +1,12 @@
import { TableGRoleAttack } from "../../../../resources/config/ts/TableGRoleAttack";
import GRoleBase from "../role/GRoleBase";
import GRoleDefault from "../role/GRoleDefault";
import { GAttackBase } from "./GAttack";
//普通攻击
export default class GAttackNormal implements GAttackBase{
attack(role: GRoleBase<{}>, info: TableGRoleAttack) {
attack(role: GRoleDefault, info: TableGRoleAttack) {
role.fsm.enemy.onHit();
}

View File

@ -12,6 +12,7 @@ import GEffectUtil from "../../effect/GEffectUtil";
import { TableGRoleAttackEffect } from "../../../../resources/config/ts/TableGRoleAttackEffect";
import GDetection from "../common/GDetection";
import { rect } from "cc";
import GRoleDefault from "../role/GRoleDefault";
/**
* 线
@ -19,7 +20,7 @@ import { rect } from "cc";
*/
export default class GAttackParabolicRemote implements GAttackBase{
attack(role: GRoleBase<{}>, info: TableGRoleAttack): void {
attack(role: GRoleDefault, info: TableGRoleAttack): void {
let enemy = role.fsm.enemy;
if(!enemy) return;

View File

@ -55,7 +55,7 @@ export default class GSpine{
//销毁
create.node.destroy();
});
create.setAnimation(0,play);
create.setAnimation(0,play,false);
return create;
}

View File

@ -2,7 +2,7 @@
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "fe4e5e9b-d1dc-4aaf-9fa8-d089fd6ca00a",
"uuid": "e6c9fc58-9fb5-4ae1-96b7-a857014d64c3",
"files": [],
"subMetas": {},
"userData": {

View File

@ -1,7 +1,8 @@
import { Vec2 } from "cc";
import GRoleBase from "../../../role/GRoleBase";
import GFSMBase, { GFSMProcessEnum, GFSMProcessInfo, GFSMProcessMode } from "../../GFSMBase";
import { GRoleUtil } from "../../../../entity/GRole";
import GRoleBase from "../../role/GRoleBase";
import GFSMBase, { GFSMProcessEnum, GFSMProcessInfo, GFSMProcessMode } from "../GFSMBase";
import { GRoleUtil } from "../../../entity/GRole";
import GRoleDefault from "../../role/GRoleDefault";
//流程枚举
@ -18,18 +19,17 @@ enum ProcessEnum {
ReleaseSkills = 4,
}
export default abstract class GFSMBattle extends GFSMBase{
export default class GFSMDefault extends GFSMBase{
protected _player:() => GRoleBase<{}>;
get player():GRoleBase<{}>{
if(this._player)
return this._player();
return null;
_player:() => GRoleDefault;
get player(): GRoleDefault {
return this._player();
}
//锁定的敌人
_enemy:() => GRoleBase<any>;
get enemy():GRoleBase<{}>{
_enemy:() => GRoleDefault;
get enemy():GRoleDefault{
if(this._enemy)
return this._enemy();
return null;
@ -56,9 +56,9 @@ export default abstract class GFSMBattle extends GFSMBase{
to:[ProcessEnum.SeekEnemy,ProcessEnum.ReleaseSkills],//移动回阵型 释放技能
},
[ProcessEnum.MoveToTactical]:{
title:"移动回阵型",
title:"获取初始点",
mode:GFSMProcessMode.WaitExecute,
execute: this.onMoveToTacticalProcess.bind(this),
execute: this.onMoveToInitPosProcess.bind(this),
to:[ProcessEnum.SeekEnemy],//移动回阵型
},
[ProcessEnum.ReleaseSkills]:{
@ -69,12 +69,16 @@ export default abstract class GFSMBattle extends GFSMBase{
}
}
constructor(player:GRoleBase<{}>){
constructor(player:GRoleDefault){
super();
this._player = GRoleUtil.get(player);
}
abstract onSeekEnemy():GRoleBase<any>;
//寻敌
onSeekEnemy(): GRoleDefault {
return this.player.onQueryEunmy();
}
//寻敌流程
onSeekEnemyProcess(dt:number):number{
@ -126,7 +130,7 @@ export default abstract class GFSMBattle extends GFSMBase{
}
//移动回阵型
onMoveToTacticalProcess(dt:number){
onMoveToInitPosProcess(dt:number){
//播放移动
this.player.fsmAnim.isMove = true;

View File

@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "559e87e4-5a3f-4cc2-873d-e0fb5b61375b",
"uuid": "37959c38-50cc-430a-b892-ef0e6df3f15d",
"files": [],
"subMetas": {},
"userData": {}

View File

@ -0,0 +1,82 @@
import { GFSMAnimBase, GFSMProcessAnimInfo } from "../GFSMAnimBase";
//角色动画名称枚举
export enum GFSMBattleAminEnum {
Wait = "std", //等待
Walk = "walk", //移动
Attack = "atk", //攻击
Fly = "jifei", //击飞
}
//流程枚举
enum ProcessEnum {
//等待
Wait = 0,
//移动
Move = 1,
//攻击
Attack = 2,
//死亡
Die = 3,
}
//动画状态机基类
export class GFSMDefaultAnim extends GFSMAnimBase{
//是否攻击
isAttack:boolean = false;
//是否移动
isMove:boolean = false;
//是否死亡
isDie:boolean = false;
// 流程图
process: { [key: number]: GFSMProcessAnimInfo; } = {
[ProcessEnum.Wait]:{
title:"等待",
isLoop:true,
animName:GFSMBattleAminEnum.Wait,
mixs:[0.1,0.1],
to:[ProcessEnum.Move,ProcessEnum.Attack,ProcessEnum.Die],
ifTo:[
() => this.isMove, //前往移动
() => this.isAttack, //前往攻击
() => this.isDie,
],
},
[ProcessEnum.Move]:{
title:"移动",
animName:GFSMBattleAminEnum.Walk,
isLoop:true,
mixs:[0.1,0.1],
to:[ProcessEnum.Wait,ProcessEnum.Attack,ProcessEnum.Die],
ifTo:[
() => !this.isMove, //前往等待
() => this.isAttack, //前往攻击
() => this.isDie,
],
},
[ProcessEnum.Attack]:{
title:"攻击",
animName:GFSMBattleAminEnum.Attack,
isLoop:true,
mixs:[0.1,0.1],
to:[ProcessEnum.Wait,ProcessEnum.Move,ProcessEnum.Die],
ifTo:[
() => !this.isAttack, //前往等待
() => !this.isAttack && this.isMove, //前往移动
() => this.isDie,
],
},
[ProcessEnum.Die]:{
title:"死亡",
animName:GFSMBattleAminEnum.Fly,
isLoop:true,
mixs:[0.1,0.1],
}
}
}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "8c02bc4d-30d6-47fe-82ff-e5496d4dca8f",
"uuid": "1016ec33-b6d2-453d-9ee2-6ab7ba5bfb7a",
"files": [],
"subMetas": {},
"userData": {}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "9fc034a7-5c68-4f22-9065-447435329c8a",
"uuid": "66a8eb65-27e3-4c94-b098-211d582aa677",
"files": [],
"subMetas": {},
"userData": {}

View File

@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "c579d727-c0c2-422f-8571-3375047fd1b8",
"uuid": "bcd244d3-5392-4926-94f1-3cd24ea2d5c2",
"files": [],
"subMetas": {},
"userData": {}

View File

@ -1,8 +1,6 @@
import { sp } from "cc";
import GFSMBase, { GFSMProcessEnum, GFSMProcessInfo, GFSMProcessMode } from "../../GFSMBase";
import GRoleBase from "../../../role/GRoleBase";
import GRolePVPEntity from "../../../role/PVP/GRolePVPEntity";
import GObject from "../../../GObject";
import GFSMBase, { GFSMProcessEnum, GFSMProcessInfo, GFSMProcessMode } from "./GFSMBase";
import GObject from "../GObject";
//角色动画名称枚举
export enum GFSMBattleAminEnum {
@ -26,29 +24,8 @@ export interface GFSMProcessAnimInfo extends GFSMProcessInfo{
ifTo?:(() => boolean)[];
}
//流程枚举
enum ProcessEnum {
//等待
Wait = 0,
//移动
Move = 1,
//攻击
Attack = 2,
//死亡
Die = 3,
}
//动画状态机基类
export class GFSMBattleAmin extends GFSMBase{
//是否攻击
isAttack:boolean = false;
//是否移动
isMove:boolean = false;
//是否死亡
isDie:boolean = false;
export abstract class GFSMAnimBase extends GFSMBase{
//轨道的索引
trackIndex:number;
@ -59,10 +36,10 @@ export class GFSMBattleAmin extends GFSMBase{
events:{event:string,fun:Function}[] = [];
starts:{name:string,fun:Function}[] = [];
constructor(spine:sp.Skeleton,trackIndex?:number){
constructor(spine:sp.Skeleton,trackIndex:number = 0){
super();
this.spine = spine;
this.trackIndex = trackIndex || 0;
this.trackIndex = trackIndex;
//设置监听
this.spine.setEventListener(this.onEventListener.bind(this));
//因为SpineBUG所以不使用Spine监听 采用自己调用
@ -110,50 +87,7 @@ export class GFSMBattleAmin extends GFSMBase{
}
// 流程图
process: { [key: number]: GFSMProcessAnimInfo; } = {
[ProcessEnum.Wait]:{
title:"等待",
isLoop:true,
animName:GFSMBattleAminEnum.Wait,
mixs:[0.1,0.1],
to:[ProcessEnum.Move,ProcessEnum.Attack,ProcessEnum.Die],
ifTo:[
() => this.isMove, //前往移动
() => this.isAttack, //前往攻击
() => this.isDie,
],
},
[ProcessEnum.Move]:{
title:"移动",
animName:GFSMBattleAminEnum.Walk,
isLoop:true,
mixs:[0.1,0.1],
to:[ProcessEnum.Wait,ProcessEnum.Attack,ProcessEnum.Die],
ifTo:[
() => !this.isMove, //前往等待
() => this.isAttack, //前往攻击
() => this.isDie,
],
},
[ProcessEnum.Attack]:{
title:"攻击",
animName:GFSMBattleAminEnum.Attack,
isLoop:true,
mixs:[0.1,0.1],
to:[ProcessEnum.Wait,ProcessEnum.Move,ProcessEnum.Die],
ifTo:[
() => !this.isAttack, //前往等待
() => !this.isAttack && this.isMove, //前往移动
() => this.isDie,
],
},
[ProcessEnum.Die]:{
title:"死亡",
animName:GFSMBattleAminEnum.Fly,
isLoop:true,
mixs:[0.1,0.1],
}
}
process: { [key: number]: GFSMProcessAnimInfo; } = {}
execute(process:GFSMProcessAnimInfo,dt:number){
process.ifTo = process.ifTo || [];
@ -188,8 +122,7 @@ export class GFSMBattleAmin extends GFSMBase{
//播放动画
if(!info.track){
console.log(`播放动画-${this.spine.getComponent(GObject).nId}-`,info);
info.track = this.spine.setAnimation(this.trackIndex,info.animName,info.isLoop);
// this.onStartListener(info.track);
info.track = this.spine.setAnimation(this.trackIndex,info.animName,!!info.isLoop);
}
return to;

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "dda21a8f-93da-4421-a0d9-bda29817a6c9",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -1,25 +0,0 @@
import { GRoleUtil } from "../../../entity/GRole";
import GRoleBase from "../../role/GRoleBase";
import GRolePVPEntity from "../../role/PVP/GRolePVPEntity";
import GFSMBattle from "../base/GFSMBattle/GFSMBattle";
//PVP 状态机
export default class GFSMPVP extends GFSMBattle{
get player(): GRolePVPEntity {
return super.player as GRolePVPEntity;
}
constructor(player:GRolePVPEntity){
super(player);
this._player = GRoleUtil.get(player);
}
//寻敌
onSeekEnemy(): GRoleBase<any> {
return this.player.mode.getEnumy(this.player);
}
}

View File

@ -1,6 +0,0 @@
import { GFSMBattleAmin } from "../base/GFSMBattle/GFSMBattleAmin";
export default class GFSMPVPAnim extends GFSMBattleAmin{
}

View File

@ -1,12 +0,0 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "552fd09c-0320-46c9-ac7a-abe954b75093",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@ -1,12 +0,0 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "05230b14-5c88-45fd-99c6-31b4b0513f45",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

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

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"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);
}
}
}

View File

@ -1,13 +1,15 @@
import { TableGRole } from "../../../resources/config/ts/TableGRole";
import { GFSMAnimBase } from "../base/fsm/GFSMAnimBase";
import GFSMBase from "../base/fsm/GFSMBase";
import GRoleBase from "../base/role/GRoleBase";
//角色工具类
export class GRoleUtil{
//获取存活的玩家 如果不存活则返回 null
static get<T>(player:GRoleBase<T>):() => GRoleBase<T>{
static get<T extends GRoleBase<{}>>(player:T):() => T{
if(!player) return null;
return ():GRoleBase<T> => {
return ():T => {
if(player)
return player.get();
return null;

View File

@ -9,6 +9,9 @@ export class GTactical{
//阵容朝向
towards:GTowards;
//位置偏差
offset:Vec2;
//阵法位置
static pos:Vec2[][] = [
@ -17,9 +20,15 @@ export class GTactical{
[v2(-100,-150),v2(0,-150),v2(100,-150)],
];
constructor(tactical:number[][],towards:GTowards = GTowards.RIGHT){
constructor(tactical:number[][],towards:GTowards = GTowards.RIGHT,offset:Vec2 = Vec2.ZERO){
this.tactical = tactical;
this.towards = towards;
this.offset = offset;
}
setOffset(offset:Vec2):this{
this.offset = offset;
return this;
}
//获取阵法
@ -69,7 +78,7 @@ export class GTactical{
}
//返回阵法位置
getPosition(index:number,father:Vec2 = v2(0,0)){
getPosition(index:number,father:Vec2 = this.offset){
let pos;
if(pos = this.getXY(index)){

View File

@ -1,10 +0,0 @@
import GBaseMode from "../GBaseMode";
/**
*
*/
export default class GLDLEMode extends GBaseMode<{}>{
}

View File

@ -0,0 +1,43 @@
import { TableGRole } from "../../../resources/config/ts/TableGRole";
import GBaseMode from "../GBaseMode";
import { GRoleUtil } from "../entity/GRole";
import { GTactical } from "../entity/GTactical";
//角色
export enum GOnHookModePlayerEnum{
PLAYER, //玩家
ENEMY, //怪物
}
//玩家信息
export interface GOnHookPlayerInfo{
//阵法
tactical: GTactical;
//宠物列表
roles: TableGRole[];
}
/**
*
*/
export default class GOnHookMode extends GBaseMode<{}>{
//玩家信息
playerInfo;
onSyncInitSuccess():void{
//初始化战斗
console.log("GOnHookMode 模式初始化");
this.playerInfo = { tactical: GTactical.getTactical(), roles: GRoleUtil.getGRoles([10001,10001,10001,10001,10003,10003]) };
//生成玩家
// this.playerInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.PLAYER,index+1,info))
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "84547cc9-858f-4ee4-9b65-272fcd80af47",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -4,9 +4,9 @@ import { GTactical } from "../entity/GTactical";
import { Prefab } from "cc";
import { instantiate } from "cc";
import { Vec2 } from "cc";
import GRolePVPEntity from "../base/role/PVP/GRolePVPEntity";
import { GRoleUtil } from "../entity/GRole";
import { TableGRole } from "../../../resources/config/ts/TableGRole";
import GRoleDefault from "../base/role/GRoleDefault";
const { ccclass, property } = _decorator;
//PVP 角色
@ -41,9 +41,9 @@ export default class GPVPMode extends GBaseMode<{}>{
enemyInfo: GPVPModePlayerInfo;
//玩家宠物
playerRoles: GRolePVPEntity[] = [];
playerRoles: GRoleDefault[] = [];
//敌方宠物
enemyRoles: GRolePVPEntity[] = [];
enemyRoles: GRoleDefault[] = [];
//玩家位置
playerPos: Vec2 = new Vec2(-400,0);
@ -65,8 +65,8 @@ export default class GPVPMode extends GBaseMode<{}>{
//初始化战斗
console.log("GPVPMode 模式初始化");
this.playerInfo = { tactical: GTactical.getTactical(), roles: GRoleUtil.getGRoles([10001,10001,10001,10001,10003,10003]) };
this.enemyInfo = { tactical: GTactical.getTactical(true), roles: GRoleUtil.getGRoles([10002,10002,10002,10001,10004,10003]) };
this.playerInfo = { tactical: GTactical.getTactical().setOffset(this.playerPos), roles: GRoleUtil.getGRoles([10001,10001,10001,10001,10003,10003]) };
this.enemyInfo = { tactical: GTactical.getTactical(true).setOffset(this.enemyPos), roles: GRoleUtil.getGRoles([10002,10002,10002,10001,10004,10003]) };
//生成玩家
this.playerInfo.roles.forEach((info,index) => this.onGenRole(GPVPModePlayerEnum.PLAYER,index+1,info))
@ -77,19 +77,20 @@ export default class GPVPMode extends GBaseMode<{}>{
//生成角色
onGenRole(type: GPVPModePlayerEnum,index:number,info:TableGRole) {
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(GRolePVPEntity);
//绑定角色
entity.type = type;
entity.bind(info);
//赋值阵容
entity.ones = type;
entity.tactical = this.getInfo(type).tactical;
entity.tacticalIndex = index;
entity.tacticalPos = this.getInfo(type).tactical.getPosition(index,this.getTacticalPos(type));
this.addGObject(entity,entity.tacticalPos);
let entity = role.getComponent(GRoleDefault);
//初始化
entity.onInit(type,info,tactical,index);
//绑定寻敌
entity.onQueryEunmy = () => {
return this.getEnumy(entity,type);
}
this.addGObject(entity,tactical.getPosition(index));
this.getOnesRole(type).push(entity);
}
@ -100,24 +101,18 @@ export default class GPVPMode extends GBaseMode<{}>{
if(type == GPVPModePlayerEnum.ENEMY) return this.enemyInfo;
}
//获取位置
getTacticalPos(type: GPVPModePlayerEnum):Vec2{
if(type == GPVPModePlayerEnum.PLAYER) return this.playerPos;
if(type == GPVPModePlayerEnum.ENEMY) return this.enemyPos;
}
//获取阵营角色
getOnesRole(type: GPVPModePlayerEnum):GRolePVPEntity[]{
getOnesRole(type: GPVPModePlayerEnum):GRoleDefault[]{
if(type == GPVPModePlayerEnum.PLAYER) return this.playerRoles;
if(type == GPVPModePlayerEnum.ENEMY) return this.enemyRoles;
}
//获取敌人
getEnumy(player:GRolePVPEntity):GRolePVPEntity{
getEnumy(player:GRoleDefault,type:GPVPModePlayerEnum):GRoleDefault{
let enumyOnes = GPVPModePlayerEnum.ENEMY
//如果是ENEMY 则 它的敌人是 PLAYER
if(player.ones == GPVPModePlayerEnum.ENEMY) enumyOnes = GPVPModePlayerEnum.PLAYER
if(type == GPVPModePlayerEnum.ENEMY) enumyOnes = GPVPModePlayerEnum.PLAYER
//获取敌人
let roles = this.getOnesRole(enumyOnes);
@ -126,7 +121,7 @@ export default class GPVPMode extends GBaseMode<{}>{
//获取我在第几排
let playerXY = player.tactical.getXY(player.tacticalIndex);
//通过排数获取最近的敌人
let sort = roles.sort((enumy1,enumy2) => {
let sort = roles.filter(role => !!role.get()).sort((enumy1,enumy2) => {
let enumy1XY = enumy1.tactical.getXY(enumy1.tacticalIndex);
let enumy2XY = enumy2.tactical.getXY(enumy2.tacticalIndex);
return Math.abs((playerXY.y * 1000) - (enumy1XY.y * 1000)) + Math.abs((playerXY.x - enumy1XY.x)) -
@ -135,16 +130,6 @@ export default class GPVPMode extends GBaseMode<{}>{
return sort[0]
}
//销毁角色数据
killRole(role:GRolePVPEntity){
let index = this.playerRoles.indexOf(role);
if(index >= 0)
this.playerRoles.splice(index,1);
index = this.enemyRoles.indexOf(role);
if(index >= 0)
this.enemyRoles.splice(index,1);
}
}

View File

@ -2,6 +2,7 @@ import { TableGRoleSkill } from "../../../resources/config/ts/TableGRoleSkill";
import GRoleBase from "../base/role/GRoleBase";
import GSkillCrazySquirrel from "./RoleSkill/疯狂松鼠/GSkillCrazySquirrel";
import GSkillBulbasaurDoubleHit from "./RoleSkill/妙蛙种子/GSkillBulbasaurDoubleHit";
import GRoleDefault from "../base/role/GRoleDefault";
//技能状态
export enum GSkillState{
@ -14,7 +15,7 @@ export enum GSkillState{
export interface GSkillBase {
//设置
bind(role:GRoleBase<{}>,info:TableGRoleSkill):GSkillBase;
bind(role:GRoleDefault,info:TableGRoleSkill):GSkillBase;
//是否允许释放
isRelease():boolean;

View File

@ -1,5 +1,6 @@
import { TableGRoleSkill } from "../../../resources/config/ts/TableGRoleSkill";
import GRoleBase from "../base/role/GRoleBase";
import GRoleDefault from "../base/role/GRoleDefault";
import { GSkillBase, GSkillState } from "./GSkill";
@ -11,7 +12,7 @@ export default abstract class GSkillAngerBase implements GSkillBase {
//怒气最大值
angerMax:number = 0;
bind(role: GRoleBase<{}>, info: TableGRoleSkill): GSkillBase {
bind(role: GRoleDefault, info: TableGRoleSkill): GSkillBase {
throw new Error("Method not implemented.");
}
isRelease(): boolean {

View File

@ -1,5 +1,6 @@
import { TableGRoleSkill } from "../../../resources/config/ts/TableGRoleSkill";
import GRoleBase from "../base/role/GRoleBase";
import GRoleDefault from "../base/role/GRoleDefault";
import { GSkillBase, GSkillState } from "./GSkill";
@ -11,7 +12,7 @@ export default abstract class GSkillCDBase implements GSkillBase {
//冷却时间
cdTime:number = 0;
bind(role:GRoleBase<{}>,info: TableGRoleSkill):GSkillCDBase {
bind(role:GRoleDefault,info: TableGRoleSkill):GSkillCDBase {
return this;
}

View File

@ -1,13 +1,14 @@
import { TableGRoleSkill } from "../../../../../resources/config/ts/TableGRoleSkill";
import GRoleBase from "../../../base/role/GRoleBase";
import GRoleDefault from "../../../base/role/GRoleDefault";
import GSkillAngerBase from "../../GSkillAngerBase";
export default class GSkillBulbasaurDoubleHit extends GSkillAngerBase{
role:GRoleBase<{}>;
role:GRoleDefault;
info: TableGRoleSkill;
bind(role:GRoleBase<{}>,info: TableGRoleSkill):GSkillBulbasaurDoubleHit {
bind(role:GRoleDefault,info: TableGRoleSkill):GSkillBulbasaurDoubleHit {
//技能冷却
this.role = role;
this.info = info;

View File

@ -9,6 +9,7 @@ import { v3 } from "cc";
import GBaseMode from "../../../GBaseMode";
import GDetection from "../../../base/common/GDetection";
import { rect } from "cc";
import GRoleDefault from "../../../base/role/GRoleDefault";
/**
*
@ -16,10 +17,10 @@ import { rect } from "cc";
*/
export default class GSkillCrazySquirrel extends GSkillCDBase{
role:GRoleBase<{}>;
role:GRoleDefault;
info: TableGRoleSkill;
bind(role:GRoleBase<{}>,info: TableGRoleSkill):GSkillCrazySquirrel {
bind(role:GRoleDefault,info: TableGRoleSkill):GSkillCrazySquirrel {
//技能冷却
this.cdTatal = parseInt(info.skillArgs[0]);
this.role = role;

View File

@ -1,7 +1,5 @@
import { _decorator, Component, Label, Node } from 'cc';
import { app, JNGLayerBase } from '../../App';
import { director } from 'cc';
import GRolePVPEntity from '../../battle/base/role/PVP/GRolePVPEntity';
import { Toggle } from 'cc';
import { JNSyncAction } from '../../../../extensions/ngame/assets/ngame/sync/JNSyncAction';
const { ccclass, property } = _decorator;
@ -19,17 +17,11 @@ export class HomeView extends JNGLayerBase {
//设置移动
setRoleMove(data:Toggle){
console.log("移动",data.isChecked);
director.getScene().getComponentsInChildren(GRolePVPEntity).forEach((role) => {
role.input.isRun = data.isChecked;
})
}
//设置攻击
setRoleAttack(data){
console.log("攻击",data.isChecked);
director.getScene().getComponentsInChildren(GRolePVPEntity).forEach((role) => {
role.input.isAttack = data.isChecked;
})
}
//重置

@ -1 +1 @@
Subproject commit eee2a6129cee115fa9f03d0f0a98a12da1e63741
Subproject commit eeab2126764c9c81a9f33350da181d0846308b72

@ -1 +1 @@
Subproject commit bce1ad3522fb8ed1497eee9e01bba38d53e97279
Subproject commit b6fc50872f5c6f56d7ca908cbf2ba95d32bd6e29