首页 > 其他分享 >lua 游戏架构 之 游戏 AI (八)ai_tbl 行为和优先级

lua 游戏架构 之 游戏 AI (八)ai_tbl 行为和优先级

时间:2024-07-26 17:54:51浏览次数:18  
标签:eAI priority 游戏 script AI eAType Priority lua ai

定义一系列的AI行为类型和它们的优先级,以及一个映射表`ai_tbl`来关联每种AI行为类型与对应的脚本文件和优先级。以下是对代码的详细解释:

lua 游戏架构 之 游戏 AI (一)ai_base-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/heyuchang666/article/details/140624481?spm=1001.2014.3001.5501lua 游戏架构 之 游戏 AI (二)ai_base_move_base-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/heyuchang666/article/details/140624583?spm=1001.2014.3001.5501

lua 游戏架构 之 游戏 AI (三)ai_attack-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/heyuchang666/article/details/140625113?spm=1001.2014.3001.5501

定义AI行为类型
代码中首先定义了一系列的AI行为类型,使用枚举的方式表示不同的AI行为。例如:

  • - `eAType_BASE` 表示基础AI行为,数值为0。
  • - `eAType_IDLE` 表示空闲状态,数值为5。
  • - `eAType_ATTACK` 表示攻击行为,数值为50。
  • - `eAType_DEAD` 表示死亡状态,数值为130。

这些类型用于区分不同的AI行为模式,每个类型都有一个唯一的数值标识。

定义优先级
接着定义了两个优先级常量:

  • - `eAI_Priority_Low` 表示低优先级,数值为0。
  • - `eAI_Priority_High` 表示高优先级,数值为1。

优先级用于控制AI行为的执行顺序,高优先级的行为会优先执行。

AI行为映射表 `ai_tbl`

  • `ai_tbl` 是一个Lua表,用于映射AI行为类型到具体的脚本文件和它们的优先级。表中的每个元素是一个表,包含`script`和`priority`两个字段:
  • - `script` 字段是一个字符串,表示实现该AI行为的脚本文件名。
  • - `priority` 字段是一个数值,表示该AI行为的优先级。

例如:

[ eAType_BASE ] = { script = "ai_base", priority = eAI_Priority_High },
[ eAType_IDLE ] = { script = "ai_idle", priority = eAI_Priority_High },
[ eAType_ATTACK ] = { script = "ai_attack", priority = eAI_Priority_Low },

这意味着当AI需要执行基础行为时,会加载`ai_base`脚本,并且由于其高优先级,它会优先于其他低优先级的行为执行。类似地,`eAType_IDLE` 表示空闲状态,也会加载`ai_idle` 脚本,并具有高优先级。而`eAType_ATTACK` 表示攻击行为,会加载`ai_attack` 脚本,但具有低优先级。

总结
这段代码为游戏的AI系统提供了一个灵活的框架,根据不同的AI行为分配不同的处理脚本和优先级。通过这种方式,可以轻松地管理和扩展AI的行为逻辑,同时保持代码的组织性和可维护性。

----------------------------------------------------------------
eAType_BASE							=   0;
eAType_IDLE							=   5;
eAType_IDLE_NPC						=  10;
eAType_IDLE_STAND					=  11;
eAType_IDLE_JUST_STAND				=  12;
eAType_GUARD						=  13;
eAType_AUTO_NORMALATTACK			=  14;
eAType_AUTOFIGHT_FIND_WAY			=  15;
eAType_AUTOFIGHT_SKILL				=  16;
eAType_AUTOFIGHT_STUNT_SKILL		=  17;
eAType_AUTOFIGHT_MISSION_SKILL		=  18;
eAType_AUTOFIGHT_CAST_FIND_TARGET	=  19
eAType_MERCENARY_AUTO_FIND_TARGET	=  20;
eAType_MOVE							=  21;
eAType_SKILLENTITY_MOVE				=  22;
eAType_NETWORK_SKILLENTITY_MOVE		=  23;
eAType_AUTO_MOVE					=  30;
eAType_NETWORK_MOVE					=  31;
eAType_FOLLOW						=  40;
eAType_FOLLOW_ARENA					=  41;
eAType_ATTACK						=  50;
eAType_NETWORK_ATTACK				=  51;
eAType_Blink						=  55;
eAType_MANUAL_ATTACK				=  60;
eAType_FIND_TARGET					=  70;
eAType_AUTOFIGHT_FIND_TARGET		=  71;
eAType_ARENA_MERCENARY_FIND_TARGET	=  72;
eAType_AUTO_SKILL					=  80;
eAType_MANUAL_SKILL					=  90;
eAType_FORCE_FOLLOW					= 100;
eAType_FEAR							= 105;
eAType_SPA							= 110;
--eAType_RUSH						= 119;
eAType_SHIFT						= 131;
eAType_RETREAT						= 121;
eAType_DEAD							= 130;
eAType_DEAD_MERCENARY				= 135;
eAType_DEAD_REVIVE					= 140;
eAType_NETWORK_CACHE				= 190;
eAType_AUTOFIGHT_MERCENARY_SKILL	= 199;
eAType_AUTO_SUPERMODE 				= 200;
eAType_AUTOFIGHT_TRIGGER_SKILL		= 201;
eAType_PRECOMMOND					= 300;
eAType_AUTOFIGHT_RETURN				= 310;
eAType_PET_CHECK_ALIVE				= 500;
eAType_DAMAGE_CAR					= 501;
eAType_CHECK_WATER                  = 502;

------------------------------------------------------
eAI_Priority_Low	= 0;
eAI_Priority_High	= 1;

------------------------------------------------------
ai_tbl =
{
	[eAType_BASE]						= { script = "ai_base",							priority = eAI_Priority_High },
	[eAType_GUARD]						= { script = "ai_guard",						priority = eAI_Priority_Low },
	[eAType_IDLE_STAND]					= { script = "ai_idle_stand",					priority = eAI_Priority_High },
	[eAType_IDLE_JUST_STAND]			= { script = "ai_idle_just_stand",				priority = eAI_Priority_High },
	[eAType_IDLE]						= { script = "ai_idle",							priority = eAI_Priority_High },
	[eAType_MOVE]						= { script = "ai_move",							priority = eAI_Priority_High },
	[eAType_AUTO_MOVE]					= { script = "ai_auto_move",					priority = eAI_Priority_High },
	[eAType_FOLLOW]						= { script = "ai_follow",						priority = eAI_Priority_Low },
	[eAType_FOLLOW_ARENA]				= { script = "ai_follow_arena",					priority = eAI_Priority_Low },
	[eAType_MERCENARY_AUTO_FIND_TARGET]	= { script = "ai_mercenary_auto_find_target",	priority = eAI_Priority_Low },
	[eAType_Blink]						= { script = "ai_blink",						priority = eAI_Priority_Low },
	[eAType_ATTACK]						= { script = "ai_attack",						priority = eAI_Priority_Low },
	[eAType_NETWORK_ATTACK]				= { script = "ai_network_attack",				priority = eAI_Priority_Low },
	[eAType_MANUAL_ATTACK]				= { script = "ai_manual_attack",				priority = eAI_Priority_Low },
	[eAType_FIND_TARGET]				= { script = "ai_find_target",					priority = eAI_Priority_Low },
	[eAType_ARENA_MERCENARY_FIND_TARGET]= { script = "ai_arena_mercenary_find_target",	priority = eAI_Priority_Low },
	[eAType_AUTO_SKILL]					= { script = "ai_auto_skill",					priority = eAI_Priority_Low },
	[eAType_AUTOFIGHT_SKILL]			= { script = "ai_autofight_special_skill",		priority = eAI_Priority_Low },
	[eAType_AUTOFIGHT_TRIGGER_SKILL]	= { script = "ai_autofight_trigger_skill",		priority = eAI_Priority_Low },
	[eAType_AUTOFIGHT_STUNT_SKILL]		= { script = "ai_autofight_stunt_skill",		priority = eAI_Priority_Low },
	[eAType_MANUAL_SKILL]				= { script = "ai_manual_skill",					priority = eAI_Priority_Low },
	[eAType_FORCE_FOLLOW]				= { script = "ai_force_follow",					priority = eAI_Priority_Low },
	[eAType_FEAR]						= { script = "ai_fear",							priority = eAI_Priority_Low },
	[eAType_SPA]						= { script = "ai_spa",							priority = eAI_Priority_Low },
	[eAType_SHIFT]						= { script = "ai_shift",						priority = eAI_Priority_Low },
	[eAType_RETREAT]					= { script = "ai_retreat",						priority = eAI_Priority_Low },
	[eAType_DEAD]						= { script = "ai_dead",							priority = eAI_Priority_High },
	[eAType_DEAD_MERCENARY]				= { script = "ai_dead_mercenary",				priority = eAI_Priority_High },
	[eAType_DEAD_REVIVE]				= { script = "ai_dead_revive",					priority = eAI_Priority_High },
	[eAType_NETWORK_MOVE]				= { script = "ai_network_auto_move",			priority = eAI_Priority_High },
	[eAType_NETWORK_CACHE]				= { script = "ai_network_cache",				priority = eAI_Priority_High },
	[eAType_PET_CHECK_ALIVE]			= { script = "ai_pet_check_alive",				priority = eAI_Priority_Low },
	[eAType_IDLE_NPC]					= { script = "ai_idle_npc",						priority = eAI_Priority_High },
	[eAType_AUTOFIGHT_MERCENARY_SKILL]	= { script = "ai_autofight_mercenary_skill",	priority = eAI_Priority_Low },
	[eAType_AUTOFIGHT_FIND_TARGET]		= { script = "ai_autofight_find_target",		priority = eAI_Priority_Low },
	[eAType_AUTOFIGHT_FIND_WAY]			= { script = "ai_autofight_find_way",			priority = eAI_Priority_Low },
	[eAType_PRECOMMOND]					= { script = "ai_precommond",					priority = eAI_Priority_Low },
	[eAType_AUTO_NORMALATTACK]			= { script = "ai_auto_normalattack",			priority = eAI_Priority_Low },
	[eAType_AUTOFIGHT_RETURN]			= { script = "ai_autofight_return",				priority = eAI_Priority_Low },
	[eAType_SKILLENTITY_MOVE]			= { script = "ai_skillentity_move",				priority = eAI_Priority_Low },
	[eAType_NETWORK_SKILLENTITY_MOVE]	= { script = "ai_network_skillentity_move",		priority = eAI_Priority_Low },
	[eAType_AUTOFIGHT_MISSION_SKILL]	= { script = "ai_autofight_mission_skill",		priority = eAI_Priority_Low },
	[eAType_AUTOFIGHT_CAST_FIND_TARGET]	= { script = "ai_autofight_cast_find_target",	priority = eAI_Priority_Low },
	[eAType_DAMAGE_CAR]					= { script = "ai_damage_car",					priority = eAI_Priority_Low },
	[eAType_AUTO_SUPERMODE]				= { script = "ai_auto_supermode",				priority = eAI_Priority_Low },
    [eAType_CHECK_WATER]				= { script = "ai_check_water",				    priority = eAI_Priority_Low },
};


 

标签:eAI,priority,游戏,script,AI,eAType,Priority,lua,ai
From: https://blog.csdn.net/heyuchang666/article/details/140712839

相关文章

  • lua 游戏架构 之 游戏 AI (九)ai_mgr Ai管理
    定义`ai_mgr`的类,用于管理游戏中实体的AI组件。先定义AI行为枚举和优先级: lua游戏架构之游戏AI(八)ai_tbl行为和优先级-CSDN博客https://blog.csdn.net/heyuchang666/article/details/140712839?spm=1001.2014.3001.5501lua游戏架构之游戏AI(一)ai_base-CSDN博客htt......
  • 灭火器检测算法:防患未然,精准高效,AI智能守护加油站消防安全
    随着科技的飞速发展和安全意识的不断提升,加油站作为易燃易爆场所,其消防安全管理显得尤为重要。其中,消防灭火器的有效部署和及时维护是保障加油站安全的关键环节。近年来,AI技术在消防安全领域的应用日益广泛,特别是加油站消防灭火器检测AI算法的研发与应用,为加油站的消防安全管理提......
  • 超火爆AI工具——Vozo:一键重写视频脚本、重新配音!
    最近有一款短视频工具——VozoAI非常火热,上线即登ProductHunt榜首,且已蝉联3天。它的全名是VozoRewrite&Redub,Rewrite意味着重新编写,Redub代表重新配音,它能够根据提示词,重新生成视频脚本并能够通过克隆原说话人声音,为视频生成新的配音,外加同步口型!今天就带大家一起来了解......
  • LayaAir3.x 物理2D碰撞事件
    const{regClass,property}=Laya;@regClass()exportclassPlayerBulletextendsLaya.Script{declareowner:Laya.Sprite;private_body:Laya.RigidBody;onAwake():void{this._body=this.owner.getComponent(Laya.RigidBody);......
  • 【P3150 pb的游戏(1)】
    pb的游戏(1)题目背景有一天pb和zs玩游戏你需要帮zs求出每局的胜败情况。题目描述游戏规则是这样的:先手对给出的数进行分割,分割成两个正整数,之后接着后手选择留下两个数中的其中一个。两人轮流操作,直到一方无法操作,另一方胜利。现在要你求出......
  • OpenAI深夜发布 SearchGPT:进军大模型搜索领域,挑战谷歌与 Perplexity!
    近期,AI领域竞争愈发激烈,不仅大模型发布频繁,还不断带来新的产品体验。刚刚,OpenAI正式发布了其大模型搜索产品SearchGPT。链接:https://chatgpt.com/searchSamAltman在X上表示:“我们认为搜索功能还有改进的空间。我们推出了一个名为SearchGPT的新原型产品。我......
  • Spring Boot 对接文心一言,实现ai抠图实例
    上篇文章:SpringBoot对接文心一言讲述了在springboot项目中如何集成文心一言。现在我们来做个实例,实现AI抠图。文心一言的抠图功能通常需要通过调用文心一言的API来实现。在SpringBoot项目中,你可以通过RestTemplate或者WebClient来发起HTTP请求调用文心一言的API。实......
  • Python,Pyinstaller打包含taichi模块的程序
    Python版本3.9、taichi版本1.7.1,pyinstaller版本6.9.0问题描述:正常Pyinstaller打包后报错[Taichi]version1.7.1,llvm15.0.1,commit0f143b2f,win,python3.9.19[Taichi]Startingonarch=x64Traceback(mostrecentcalllast):File"taichi\lang\_wrap_inspec......
  • Python从零开始制做文字游戏(荒岛求生)
    文章目录前言开发游戏《荒岛求生》游戏大纲背景内容通关条件游戏过程探索荒岛购买物资休息总结代码开发定义变量当前代码引入背景故事当前代码循环问题解决:函数当前代码制作延时当前代码制作a函数(探索荒岛阶段)展示数......
  • 【提交ACM出版 | EI&Scopus检索稳定 | 高录用】2024年数字经济,区块链与人工智能国际学
    2024年数字经济,区块链与人工智能国际学术会议(DEBAI2024)为第五届大数据与社会科学国际学术会议(ICBDSS2024)的分会,将于2024年8月23-25日在中国-广州隆重举行。为了让更多的学者有机会参与会议分享交流经验。本次会议主要围绕“数字经济,区块链与人工智能等研究领域展开讨论......