mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
update
This commit is contained in:
@@ -1,6 +1,86 @@
|
||||
|
||||
//流程模式
|
||||
export enum GFSMProcessMode{
|
||||
Execute,//正常运行
|
||||
WaitExecute,//等待执行
|
||||
}
|
||||
|
||||
//流程信息
|
||||
export interface GFSMProcessInfo{
|
||||
//备注
|
||||
title:string;
|
||||
//模式
|
||||
mode?:GFSMProcessMode;
|
||||
//执行方法
|
||||
execute?:() => number;
|
||||
//前往
|
||||
to?:number[];
|
||||
}
|
||||
|
||||
//状态机基类
|
||||
export default abstract class GFSMBase{
|
||||
export default class GFSMBase{
|
||||
|
||||
//状态流程图
|
||||
process:{[key:number]:GFSMProcessInfo} = {};
|
||||
|
||||
//开始流程Id
|
||||
start:number = 0;
|
||||
|
||||
//当前流程
|
||||
current:number = 0;
|
||||
|
||||
//状态机刷新
|
||||
onUpdate(dt:number){
|
||||
|
||||
if(!this.start) this.start = 0;
|
||||
if(!this.current) this.current = 0;
|
||||
|
||||
//运行流程
|
||||
this.execute(this.process[this.current]);
|
||||
|
||||
}
|
||||
|
||||
//执行流程
|
||||
execute(process:GFSMProcessInfo){
|
||||
if(!process) return;
|
||||
|
||||
process.mode = process.mode || GFSMProcessMode.Execute;
|
||||
process.to = process.to || [];
|
||||
|
||||
let next:number;
|
||||
let isReset:boolean = true;
|
||||
|
||||
//执行流程
|
||||
switch(process.mode){
|
||||
case GFSMProcessMode.Execute:
|
||||
//执行方法
|
||||
next = process.to[process.execute()-1];
|
||||
break;
|
||||
case GFSMProcessMode.WaitExecute:
|
||||
//执行等待方法
|
||||
let state = process.execute();
|
||||
//如果 状态 -1 则 不重置 下一次状态从当前开始流程执行
|
||||
if(state == -1){
|
||||
isReset = false;
|
||||
}else{
|
||||
next = state;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(!this.process[next]) next = null;
|
||||
|
||||
if(next){
|
||||
this.current = next;
|
||||
//运行下一个流程
|
||||
this.execute(this.process[next]);
|
||||
}else{
|
||||
if(isReset){
|
||||
//重置
|
||||
this.current = this.start;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
54
JisolGameCocos/assets/script/battle/base/fsm/GFSMBattle.ts
Normal file
54
JisolGameCocos/assets/script/battle/base/fsm/GFSMBattle.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import GRoleBase from "../role/GRoleBase";
|
||||
import GFSMBase, { GFSMProcessInfo } from "./GFSMBase";
|
||||
|
||||
|
||||
export default abstract class GFSMBattle extends GFSMBase{
|
||||
|
||||
//流程图
|
||||
process: { [key: number]: GFSMProcessInfo; } = {
|
||||
0:{
|
||||
title:"寻找敌人",
|
||||
execute: this.onSeekEnemyProcess.bind(this),
|
||||
to:[1]
|
||||
},
|
||||
1:{
|
||||
title:"攻击敌人",
|
||||
execute: this.onAttackProcess.bind(this),
|
||||
}
|
||||
}
|
||||
|
||||
//锁定的敌人
|
||||
enemy:GRoleBase<any>;
|
||||
|
||||
|
||||
abstract onSeekEnemy():GRoleBase<any>;
|
||||
|
||||
//寻敌流程
|
||||
onSeekEnemyProcess():number{
|
||||
|
||||
if(this.enemy){
|
||||
//如果有敌人 直接 攻击
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(this.enemy = this.onSeekEnemy()){
|
||||
//如果有敌人 直接 攻击
|
||||
return 1;
|
||||
}
|
||||
|
||||
//负责继续寻敌
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
abstract onAttack();
|
||||
|
||||
//攻击敌人
|
||||
onAttackProcess(){
|
||||
this.onAttack();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "bf6010d3-4d2e-4ecf-abc4-a4e770ebd5df",
|
||||
"uuid": "ac1a0b3b-e57a-4718-a27f-39b8e072f74e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
@@ -2,7 +2,7 @@
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "03218a59-18c0-42bc-aa22-117d45bc314a",
|
||||
"uuid": "fe4e5e9b-d1dc-4aaf-9fa8-d089fd6ca00a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
25
JisolGameCocos/assets/script/battle/base/fsm/PVP/GFSMPVP.ts
Normal file
25
JisolGameCocos/assets/script/battle/base/fsm/PVP/GFSMPVP.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import GRoleBase from "../../role/GRoleBase";
|
||||
import GRolePVPEntity from "../../role/PVP/GRolePVPEntity";
|
||||
import GFSMBattle from "../GFSMBattle";
|
||||
|
||||
|
||||
//PVP 状态机
|
||||
export default class GFSMPVP extends GFSMBattle{
|
||||
|
||||
player:GRolePVPEntity;
|
||||
|
||||
constructor(player:GRolePVPEntity){
|
||||
super();
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
//寻敌
|
||||
onSeekEnemy(): GRoleBase<any> {
|
||||
return this.player.mode.getEnumy(this.player);
|
||||
}
|
||||
|
||||
//攻击
|
||||
onAttack() {
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "86cd6fa1-1340-4343-8929-7c5363727b1c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
import GFSMBase from "../GFSMBase";
|
||||
|
||||
//角色状态机实现
|
||||
export default class GFSMRoleController extends GFSMBase{
|
||||
|
||||
//状态机更新
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user