mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
update
This commit is contained in:
@@ -26,6 +26,9 @@ export enum GFSMProcessEnum{
|
||||
//状态机基类
|
||||
export default class GFSMBase{
|
||||
|
||||
//是否关闭
|
||||
isClose:boolean = false;
|
||||
|
||||
//状态流程图
|
||||
process:{[key:number]:GFSMProcessInfo} = {};
|
||||
|
||||
@@ -38,14 +41,19 @@ export default class GFSMBase{
|
||||
//状态机刷新
|
||||
onUpdate(dt:number){
|
||||
|
||||
if(this.isClose) return;
|
||||
|
||||
if(!this.start) this.start = 0;
|
||||
if(!this.current) this.current = 0;
|
||||
|
||||
//运行流程
|
||||
this.execute(this.process[this.current],dt);
|
||||
|
||||
}
|
||||
|
||||
close(){
|
||||
this.isClose = true;
|
||||
}
|
||||
|
||||
//执行流程
|
||||
execute(process:GFSMProcessInfo,dt:number){
|
||||
if(!process) return;
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import GRoleUtil from "../../../util/GRoleUtil";
|
||||
import GRoleBase from "../../role/GRoleBase";
|
||||
import GRolePVPEntity from "../../role/PVP/GRolePVPEntity";
|
||||
import GFSMBattle from "../base/GFSMBattle/GFSMBattle";
|
||||
@@ -6,11 +7,13 @@ import GFSMBattle from "../base/GFSMBattle/GFSMBattle";
|
||||
//PVP 状态机
|
||||
export default class GFSMPVP extends GFSMBattle{
|
||||
|
||||
player:GRolePVPEntity;
|
||||
get player(): GRolePVPEntity {
|
||||
return super.player as GRolePVPEntity;
|
||||
}
|
||||
|
||||
constructor(player:GRolePVPEntity){
|
||||
super(player);
|
||||
this.player = player;
|
||||
this._player = GRoleUtil.get(player);
|
||||
}
|
||||
|
||||
//寻敌
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { Vec2 } from "cc";
|
||||
import GRoleBase from "../../../role/GRoleBase";
|
||||
import GFSMBase, { GFSMProcessEnum, GFSMProcessInfo, GFSMProcessMode } from "../../GFSMBase";
|
||||
import GRoleUtil from "../../../../util/GRoleUtil";
|
||||
|
||||
|
||||
//流程枚举
|
||||
@@ -17,7 +18,20 @@ enum ProcessEnum {
|
||||
|
||||
export default abstract class GFSMBattle extends GFSMBase{
|
||||
|
||||
player:GRoleBase<{}>;
|
||||
protected _player:() => GRoleBase<{}>;
|
||||
get player():GRoleBase<{}>{
|
||||
if(this._player)
|
||||
return this._player();
|
||||
return null;
|
||||
}
|
||||
|
||||
//锁定的敌人
|
||||
_enemy:() => GRoleBase<any>;
|
||||
get enemy():GRoleBase<{}>{
|
||||
if(this._enemy)
|
||||
return this._enemy();
|
||||
return null;
|
||||
}
|
||||
|
||||
//流程图
|
||||
process: { [key: number]: GFSMProcessInfo; } = {
|
||||
@@ -39,19 +53,16 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
execute: this.onAttackProcess.bind(this),
|
||||
to:[ProcessEnum.MoveToTactical],//移动回阵型
|
||||
},
|
||||
// [ProcessEnum.MoveToTactical]:{
|
||||
// title:"移动回阵型",
|
||||
// mode:GFSMProcessMode.WaitExecute,
|
||||
// execute: this.onMoveToTacticalProcess.bind(this),
|
||||
// }
|
||||
[ProcessEnum.MoveToTactical]:{
|
||||
title:"移动回阵型",
|
||||
mode:GFSMProcessMode.WaitExecute,
|
||||
execute: this.onMoveToTacticalProcess.bind(this),
|
||||
}
|
||||
}
|
||||
|
||||
//锁定的敌人
|
||||
enemy:GRoleBase<any>;
|
||||
|
||||
constructor(player:GRoleBase<{}>){
|
||||
super();
|
||||
this.player = player;
|
||||
this._player = GRoleUtil.get(player);
|
||||
}
|
||||
|
||||
abstract onSeekEnemy():GRoleBase<any>;
|
||||
@@ -68,7 +79,7 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
return ProcessEnum.MoveToAttackRange;
|
||||
}
|
||||
|
||||
if(this.enemy = this.onSeekEnemy()){
|
||||
if((this._enemy = GRoleUtil.get(this.onSeekEnemy())) && this.enemy){
|
||||
//如果有敌人 直接 攻击
|
||||
return ProcessEnum.MoveToAttackRange;
|
||||
}
|
||||
@@ -122,7 +133,12 @@ export default abstract class GFSMBattle extends GFSMBase{
|
||||
//播放移动
|
||||
this.player.fsmAnim.isMove = false;
|
||||
this.player.fsmAnim.isAttack = true;
|
||||
return GFSMProcessEnum.Wait;
|
||||
//如果有敌人则攻击 没有 则 重置
|
||||
if(this.enemy){
|
||||
return GFSMProcessEnum.Wait;
|
||||
}else{
|
||||
return ProcessEnum.MoveToTactical;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -32,6 +32,8 @@ enum ProcessEnum {
|
||||
Move = 1,
|
||||
//攻击
|
||||
Attack = 2,
|
||||
//死亡
|
||||
Die = 3,
|
||||
}
|
||||
|
||||
//动画状态机基类
|
||||
@@ -43,6 +45,9 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
//是否移动
|
||||
isMove:boolean = false;
|
||||
|
||||
//是否死亡
|
||||
isDie:boolean = false;
|
||||
|
||||
//轨道的索引
|
||||
trackIndex:number;
|
||||
|
||||
@@ -50,6 +55,7 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
spine:sp.Skeleton;
|
||||
|
||||
events:{event:string,fun:Function}[] = [];
|
||||
starts:{name:string,fun:Function}[] = [];
|
||||
|
||||
constructor(spine:sp.Skeleton,trackIndex?:number){
|
||||
super();
|
||||
@@ -57,6 +63,7 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
this.trackIndex = trackIndex || 0;
|
||||
//设置监听
|
||||
this.spine.setEventListener(this.onEventListener.bind(this));
|
||||
this.spine.setStartListener(this.onStartListener.bind(this));
|
||||
}
|
||||
|
||||
//添加事件监听
|
||||
@@ -67,6 +74,14 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
})
|
||||
}
|
||||
|
||||
//监听动画开始播放
|
||||
addStartListener(name:string,fun:Function){
|
||||
this.starts.push({
|
||||
name,
|
||||
fun,
|
||||
})
|
||||
}
|
||||
|
||||
onEventListener(entry: sp.spine.TrackEntry, ev: sp.spine.Event){
|
||||
this.events.forEach(item => {
|
||||
if(item.event == ev.data.name){
|
||||
@@ -75,6 +90,14 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
});
|
||||
}
|
||||
|
||||
onStartListener(entry: sp.spine.TrackEntry){
|
||||
this.starts.forEach(item => {
|
||||
if(entry.animation.name == item.name){
|
||||
item.fun();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 流程图
|
||||
process: { [key: number]: GFSMProcessAnimInfo; } = {
|
||||
[ProcessEnum.Wait]:{
|
||||
@@ -82,10 +105,11 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
isLoop:true,
|
||||
animName:GFSMBattleAminEnum.Wait,
|
||||
mixs:[0.1,0.1],
|
||||
to:[ProcessEnum.Move,ProcessEnum.Attack],
|
||||
to:[ProcessEnum.Move,ProcessEnum.Attack,ProcessEnum.Die],
|
||||
ifTo:[
|
||||
() => this.isMove, //前往移动
|
||||
() => this.isAttack //前往攻击
|
||||
() => this.isAttack, //前往攻击
|
||||
() => this.isDie,
|
||||
],
|
||||
},
|
||||
[ProcessEnum.Move]:{
|
||||
@@ -93,26 +117,36 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
animName:GFSMBattleAminEnum.Walk,
|
||||
isLoop:true,
|
||||
mixs:[0.1,0.1],
|
||||
to:[ProcessEnum.Wait,ProcessEnum.Attack],
|
||||
to:[ProcessEnum.Wait,ProcessEnum.Attack,ProcessEnum.Die],
|
||||
ifTo:[
|
||||
() => !this.isMove, //前往等待
|
||||
() => this.isAttack, //前往攻击
|
||||
() => this.isDie,
|
||||
],
|
||||
},
|
||||
2:{
|
||||
[ProcessEnum.Attack]:{
|
||||
title:"攻击",
|
||||
animName:GFSMBattleAminEnum.Attack,
|
||||
isLoop:true,
|
||||
mixs:[0.1,0.1],
|
||||
to:[ProcessEnum.Wait,ProcessEnum.Move],
|
||||
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],
|
||||
}
|
||||
}
|
||||
|
||||
execute(process:GFSMProcessAnimInfo,dt:number){
|
||||
process.ifTo = process.ifTo || [];
|
||||
process.to = process.to || [];
|
||||
process.mode = GFSMProcessMode.WaitExecute;
|
||||
process.execute = this.tick.bind(this);
|
||||
super.execute(process,dt);
|
||||
@@ -120,7 +154,7 @@ export class GFSMBattleAmin extends GFSMBase{
|
||||
|
||||
//-1 继续播放 0 重新执行流程 * 指定分支
|
||||
tick(dt:number,info:GFSMProcessAnimInfo){
|
||||
|
||||
|
||||
//判断是否会切换动画 (默认不切换)
|
||||
let to = GFSMProcessEnum.Wait;
|
||||
info.ifTo.forEach((run,index) => {
|
||||
|
Reference in New Issue
Block a user