增加文档

This commit is contained in:
lostluna1
2025-10-17 23:37:16 +08:00
parent f00a65e2f8
commit a9b10b88c0
8 changed files with 450 additions and 165 deletions

View File

@@ -5,81 +5,101 @@
文件用途:
*/
/** 状态机
* @global
*/
class StateMachine {
//状态注册表
StatusRegistry = null;
//状态注册表
StatusRegistry = null;
constructor() {
if (getroottable().rawin("__StateMachine__")) {
// 防止重复实例化
throw "StateMachine 不能重复实例化!";
}
//初始化状态注册表
StatusRegistry = {};
foreach(JobIndex in getconsttable().CHARACTERJOB) {
StatusRegistry[JobIndex] <- {};
}
}
constructor() {
if (getroottable().rawin("__StateMachine__")) {
// 防止重复实例化
throw "StateMachine 不能重复实例化!";
}
//初始化状态注册表
StatusRegistry = {};
foreach (JobIndex in getconsttable().CHARACTERJOB) {
StatusRegistry[JobIndex] <- {};
}
}
// 静态方法:获取唯一实例
function GetInstance() {
if (!getroottable().rawin("__StateMachine__")) {
// 首次调用时创建实例
getroottable()["__StateMachine__"] <- StateMachine();
}
return getroottable()["__StateMachine__"];
}
/**
* 静态方法:获取唯一实例
* @function
* @returns {table}
*/
function GetInstance() {
if (!getroottable().rawin("__StateMachine__")) {
// 首次调用时创建实例
getroottable()["__StateMachine__"] <- StateMachine();
}
return getroottable()["__StateMachine__"];
}
//注册状态
function RegisterState(Job, StateName, StateIndex) {
StatusRegistry[Job][StateIndex] <- {
StateName = StateName,
StateIndex = StateIndex
}
print("注册了状态" + StateName + ",状态索引为" + StateIndex);
}
/**
* 注册状态
* @function
* @param {integer} Job
* @param {any} StateName
* @param {integer} StateIndex
* @returns {void}
*/
function RegisterState(Job, StateName, StateIndex) {
StatusRegistry[Job][StateIndex] <- {
StateName = StateName,
StateIndex = StateIndex
};
print("注册了状态" + StateName + ",状态索引为" + StateIndex);
}
//获取状态信息
function GetStateInfo(Job, State) {
return StatusRegistry[Job][State];
}
/**
* 获取状态信息
* @function
* @param {integer} Job
* @param {integer} State
* @returns {integer}
*/
function GetStateInfo(Job, State) {
return StatusRegistry[Job][State];
}
}
function StateMachine_checkCanChangeState(C_Object, Job, State) {
//获取状态信息
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
//判断是否有 检查能否切换状态函数
local FuncName = "checkCanChangeState_" + StateInfo.StateName;
if (getroottable().rawin(FuncName)) {
return getroottable()[FuncName](CharacterObject(C_Object));
} else {
error("没有找到" + FuncName + "函数");
}
return false;
//获取状态信息
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
//判断是否有 检查能否切换状态函数
local FuncName = "checkCanChangeState_" + StateInfo.StateName;
if (getroottable().rawin(FuncName)) {
return getroottable()[FuncName](CharacterObject(C_Object));
} else {
error("没有找到" + FuncName + "函数");
}
return false;
}
function StateMachine_SetState(C_Object, Job, State) {
//获取状态信息
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
//判断是否有 设置状态函数
local FuncName = "SetState_" + StateInfo.StateName;
if (getroottable().rawin(FuncName)) {
getroottable()[FuncName](CharacterObject(C_Object));
} else {
error("没有找到" + FuncName + "函数");
}
return false;
//获取状态信息
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
//判断是否有 设置状态函数
local FuncName = "SetState_" + StateInfo.StateName;
if (getroottable().rawin(FuncName)) {
getroottable()[FuncName](CharacterObject(C_Object));
} else {
error("没有找到" + FuncName + "函数");
}
return false;
}
function StateMachine_ProcState(C_Object, Job, State, DeltaTime) {
//获取状态信息
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
//判断是否有 设置状态函数
local FuncName = "ProcState_" + StateInfo.StateName;
if (getroottable().rawin(FuncName)) {
getroottable()[FuncName](CharacterObject(C_Object), DeltaTime);
} else {
error("没有找到" + FuncName + "函数");
}
return false;
}
//获取状态信息
local StateInfo = StateMachine.GetInstance().GetStateInfo(Job, State);
//判断是否有 设置状态函数
local FuncName = "ProcState_" + StateInfo.StateName;
if (getroottable().rawin(FuncName)) {
getroottable()[FuncName](CharacterObject(C_Object), DeltaTime);
} else {
error("没有找到" + FuncName + "函数");
}
return false;
}