lua 游戏架构 之 游戏 AI (七)ai_dead
定义一个名为`ai_dead`的类,继承自`ai_base`类。这个类用于处理游戏中AI在死亡状态下的行为逻辑。以下是对代码的具体解释:
1. **引入基类**:
- 使用`require`函数引入`ai_base`类,作为基础类。
2. **定义`ai_dead`类**:
- 使用`class`关键字定义了`ai_dead`类,并继承自`BASE`(即`ai_base`)。
3. **构造函数 (`ctor`)**:
- 构造函数接受一个`entity`参数,并设置`_type`属性为`eAType_DEAD`,表示死亡的行为。
4. **`IsValid` 方法**:
- 这个方法用于验证AI是否应该处于死亡状态。它首先调用基类的`IsValid`方法,然后检查实体是否死亡。
5. **`OnEnter` 方法**:
- - 当AI组件进入激活状态时执行。如果基类的`OnEnter`方法返回`true`,则执行以下操作:
- - 重置`_fadeOut`和`_slowMotion`标志。
- - 检查并重置玩家的自动普通攻击状态。
- - 隐藏实体的称号节点。
- - 检查并重置玩家的超级模式状态。
- - 检查并重置骑乘状态。
- - 如果实体不是宠物或技能类型,播放死亡动作列表。
- - 锁定实体动画。
- - 处理同步RPC和发送死亡命令。
- - 处理玩家死亡后的界面逻辑,如复活界面和宠物状态。
- - 清理死亡实体的仇恨列表和战斗时间。
6. **`OnLeave` 方法**: 当AI组件离开激活状态时执行。如果基类的`OnLeave`方法返回`true`,则解锁实体动画。
7. **`OnLogic` 方法**: 逻辑更新方法。如果基类的`OnLogic`方法返回`true`,则根据时间间隔处理死亡逻辑,如淡出效果、实体销毁等。
8. **创建组件函数**: `create_component`函数用于创建`ai_dead`类的新实例,传入一个实体和一个优先级。
代码中的一些关键点:
- - `IsDead()`:检查实体是否死亡。
- - `ShowTitleNode()`:显示或隐藏实体的称号节点。
- - `SuperMode()`:处理玩家的超级模式。
- - `OnRideMode()`:处理玩家的骑乘模式。
- - `PlayActionList()`:播放一系列动作。
- - `LockAni()`:锁定实体的动画。
- - `Show()`:控制实体的显示与隐藏。
- - `Destory()`:销毁实体。
- - `CanRelease()`:检查实体是否可以释放。
`OnEnter` 方法的逻辑流程:
- - 调用基类的`OnEnter`方法,如果返回`true`,则继续。
- - 重置相关动画和攻击状态。
- - 隐藏称号节点。
- - 检查并重置超级模式和骑乘状态。
- - 播放死亡动作列表并锁定动画。
- - 发送死亡同步命令和处理复活界面逻辑。
- - 清理仇恨列表和战斗时间。
`OnLogic` 方法中,根据时间间隔处理死亡后的逻辑,如:
- - 如果实体存活时间超过4秒,并且可以释放,则销毁实体。
- - 如果实体存活时间超过2秒,并且可以释放,则开始淡出效果。
整体而言,`ai_dead`类的目的是在AI实体死亡时,提供一套标准的行为和逻辑处理,确保游戏内死亡状态的表现和交互符合预期。
local require = requirelocal BASE = require("logic/entity/ai/ai_base").ai_base;------------------------------------------------------
ai_dead = class("ai_dead", BASE);
function ai_dead:ctor(entity)self._type = eAType_DEAD;
endfunction ai_dead:IsValid()if not BASE.IsValid(self) then return false; endreturn self._entity:IsDead();
endfunction ai_dead:OnEnter()if BASE.OnEnter(self) thenself._fadeOut = false;self._slowMotion= false;local logic = game_get_logic();if logic thenlocal player = logic:GetPlayer();if player and player:GetHero() thenlocal hero = player:GetHero();if hero thenif hero._autonormalattack thenif hero._guid == self._entity._guid thenhero._preautonormalattack = false;hero._autonormalattack = false;elseif self._entity._selected == self._entity._guid thenhero._preautonormalattack = false;hero._autonormalattack = false;elseif hero._follow thenif hero._follow._guid == self._entity._guid thenhero._preautonormalattack = false;hero._autonormalattack = false;endendendendendendself._entity:ShowTitleNode(false);if self._entity:GetEntityType() == eET_Player then--清神兵状态if self._entity._superMode.valid thenlocal hero = game_get_player_hero()if self._entity:IsPlayer() thenself._entity:SuperMode(false)elseself._entity:OnSuperMode(false)endendif self._entity:IsPlayer() theng_game_context:ResetLeadMode()local animation = g_game_context:GetSelectWeaponMaxAnimation()if animation theng_game_context:OnStuntAnimationChangeHandler(animation,false)endend--清骑乘local world = game_get_world()if world and not world._syncRpc thenif self._entity:IsOnRide() thenself._entity:OnRideMode(false, true)endendif self._entity._DIYSkill thenself._entity._DIYSkill:OnReset();endendif self._entity:GetEntityType() ~= eET_Pet and self._entity:GetEntityType() ~= eET_Skill thenlocal alist = {}table.insert(alist, {actionName = db_common.engine.defaultDeadAction, actloopTimes = 1})table.insert(alist, {actionName = db_common.engine.defaultDeadLoopAction, actloopTimes = -1})self._entity:PlayActionList(alist, 1);endself._entity:LockAni(true);local logic = game_get_logic();if logic thenlocal world = logic:GetWorld();if world thenlocal syncRpc = world._syncRpc;if not syncRpc then-- send cmdlocal entity = self._entity;if entity and entity:GetEntityType() == eET_Monster and entity._spawnID > 0 thenlocal weaponID = g_game_context:IsInSuperMode() and 1 or 0local damageRank = g_game_context:GetMapCopyDamageRank()local args = { spawnPointID = entity._spawnID , pos = entity._curPos, weaponID = weaponID, damageRank = damageRank}sbean.sync_privatemap_kill(args)endlocal hero = game_get_player_hero()if hero thenhero:RemoveSummoned();endendendendif self._entity:GetEntityType() == eET_Player thenif logic thenlocal player = logic:GetPlayer()local hero = nilif player thenhero = player:GetHero()endlocal logic = game_get_logic();local world = logic:GetWorld()local PetCount = player:GetPetCount()for i = 1,tonumber(PetCount) dolocal Pet = player:GetPet(i)Pet:OnDead()endif g_db.db_get_is_open_revive_ui() then if hero._guid == self._entity._guid thenif hero._killerId and hero._killerId < 0 then--天雷复活界面local killerID = math.abs(hero._killerId);local guid = string.split(hero._guid, "|")local playerId = tonumber(guid[2])if killerID == playerId theng_ui_mgr:OpenUI(eUIID_PlayerRevive)g_ui_mgr:RefreshUI(eUIID_PlayerRevive, true)endelseg_logic:OpenReviveUI()end--log("eUIID_PlayerRevive")local MercenaryCount = player:GetMercenaryCount();for i = 1,tonumber(MercenaryCount) dolocal Mercenary = player:GetMercenary(i)Mercenary:OnDead()endendelseif hero._guid == self._entity._guid and (game_get_map_type() == g_ARENA_SOLO or game_get_map_type() == g_TAOIST) theng_game_context:SetAutoFight(false)local MercenaryCount = player:GetMercenaryCount();for i = 1,tonumber(MercenaryCount) dolocal Mercenary = player:GetMercenary(i)if not Mercenary:IsDead() thenlocal camera = logic:GetMainCamera()hero:DetachCamera()Mercenary:AttachCamera(camera);camera:UpdatePos(Mercenary._curPosE);break;endendendendif world and not world._syncRpc thenself._entity:ClsHorseAi();endendendif self._entity._forceAttackTarget thenself._entity._forceAttackTarget = nil;endif self._entity:GetEntityType() == eET_Mercenary thenself._entity._deadTimeLine = g_get_GMTtime(game_get_time())if logic thenlocal player = logic:GetPlayer()local hero = nilif player thenhero = player:GetHero()endlocal logic = game_get_logic();local world = logic:GetWorld()if world._fightmap thenif hero:IsDead() and (game_get_map_type() == g_ARENA_SOLO or game_get_map_type() == g_TAOIST) thenlocal guid1 = string.split(hero._guid, "_")local guid2 = string.split(self._entity._guid, "_") if tonumber(guid1[2]) == tonumber(guid2[3]) thenlocal MercenaryCount = player:GetMercenaryCount();for i = 1,tonumber(MercenaryCount) dolocal Mercenary = player:GetMercenary(i)if not Mercenary:IsDead() thenlocal camera = logic:GetMainCamera()self._entity:DetachCamera()Mercenary:AttachCamera(camera);camera:UpdatePos(Mercenary._curPosE);break;endendendendendendself._entity:ClsEnmities();endif self._entity:GetEntityType() == eET_Player or self._entity:GetEntityType() == eET_Mercenary thenself._entity:ClearFightTime();endif self._entity:GetEntityType() ~= eET_Player and self._entity:GetEntityType() ~= eET_Mercenary then--self._entity:SetHittable(false);endif self._entity:GetEntityType() == eET_Pet thenlocal world = game_get_world();local player = game_get_player()if world and not world._syncRpc thenif self._entity._hoster thenlocal curFightSP = self._entity._hoster:GetFightSp()self._entity._hoster:UpdateFightSpCanYing(curFightSP - 1)local index = player:GetPetIdx(self._entity._guid)if index > 0 thenplayer:RmvPet(index)endendendendreturn true;endreturn false;
endfunction ai_dead:OnLeave()if BASE.OnLeave(self) thenself._entity:LockAni(false);return true;endreturn false;
endfunction ai_dead:OnLogic(dTick)if BASE.OnLogic(self, dTick) thenif dTick > 0 thenif self._timeTick > 4000 thenif self._entity:CanRelease() thenself._entity:Destory()endelseif self._timeTick > 2000 thenif self._entity:CanRelease() thenif not self._fadeOut thenself._fadeOut = true;self._entity:Show(false, true, 2000);endendendif self._entity:GetEntityType() == eET_Pet or self._entity:GetEntityType() == eET_Skill thenif self._entity:CanRelease() thenself._entity:Destory()endendendreturn true;endreturn false;
endfunction create_component(entity, priority)return ai_dead.new(entity, priority);
end
相关文章:

lua 游戏架构 之 游戏 AI (七)ai_dead
定义一个名为ai_dead的类,继承自ai_base类。这个类用于处理游戏中AI在死亡状态下的行为逻辑。以下是对代码的具体解释: 1. **引入基类**: - 使用require函数引入ai_base类,作为基础类。 2. **定义ai_dead类**: …...

前端开发知识(一)-html
1.前端开发需掌握的内容: 2.前端开发的三剑客:html、css、javascript Vue可以简化JavaScpript流程。 Element(饿了么开发的) :前端组件库。 Ngix:前端服务器。 3.前端开发工具:vscode 1)按…...

身份证如何查验真伪?C#身份证二要素、三要素接口集成
身份证不仅是我们的身份证明,更是社会生活中的“通行证”,现在人们的衣食住行都离不开身份证。但对于提供服务的平台而言,如何对用户提供的身份信息进行真伪核验便成为了一大难题。别担心,今天小编为服务平台带来了身份证二要素、…...

C++ | Leetcode C++题解之第290题单词规律
题目: 题解: class Solution { public:bool wordPattern(string pattern, string str) {unordered_map<string, char> str2ch;unordered_map<char, string> ch2str;int m str.length();int i 0;for (auto ch : pattern) {if (i > m) {…...

Pytorch使用教学7-张量的广播
PyTorch中的张量具有和NumPy相同的广播特性,允许不同形状的张量之间进行计算。 广播的实质特性,其实是低维向量映射到高维之后,相同位置再进行相加。我们重点要学会的就是低维向量如何向高维向量进行映射。 相同形状的张量计算 虽然我们觉…...

生成式AI:对话系统(Chat)与自主代理(Agent)的和谐共舞
生成式AI:对话与行动的和谐共舞 我们正站在一个令人激动的时代门槛上——生成式AI技术飞速发展,带来了无限的可能性。一个关键问题浮现:AI的未来是对话系统(Chat)的天下,还是自主代理(Agent&am…...

唯众物联网(IOT)全功能综合实训教学解决方案
一、引言 在信息技术日新月异的今天,物联网(IoT)作为推动数字化转型的关键力量,其触角已延伸至我们生活的方方面面,深刻地重塑了工作模式、生活习惯乃至社会结构的每一个角落。面对这一前所未有的变革浪潮,…...

24证券从业考试报名『个人信息表』填写模板❗
24证券从业考试报名『个人信息表』填写模板❗ 1️⃣居住城市、通讯地址:写自己现居住的地址就可以。 2️⃣学历:需要注意的是学历填写的是考生已经取得的学历,在校大学生已经不具有报名资格,选择大专以上,或者是高中学…...

深度学习系列70:模型部署torchserve
1. 流程说明 ts文件夹下, 从launcher.py进入,执行jar文件。 入口为model_server.py的start()函数。内容包含: 读取args,创建pid文件 找到java,启动model-server.jar程序,同时读取log-config文件ÿ…...

算法日记day 20(中序后序遍历序列构造二叉树|最大、合并、搜索二叉树)
一、中序后序序列构造二叉树 题目: 给定两个整数数组 inorder 和 postorder ,其中 inorder 是二叉树的中序遍历, postorder 是同一棵树的后序遍历,请你构造并返回这颗 二叉树 。 示例 1: 输入:inorder [9,3,15,20,…...

【科研】# Taylor Francis 论文 LaTeX template模版 及 Word模版
【科研写论文】系列 文章目录 【科研写论文】系列前言一、Word 模板(附下载网址):二、LaTeX 版本方法1:直接网页端打开(附网址)方法2:直接下载到本地电脑上编辑下载地址说明及注意事项 前言 给…...

Linux网络配置及常见命令!
vim /etc/sysconfig/network-scripsts/ifcfg-ens33(图形界面配置网络) Xshell rz:上传(从Windows到Linux) sz:下载:(从Linux到Windows)(后接文件手工输入)…...

linux之shell脚本实战
💝💝💝欢迎来到我的博客,很高兴能够在这里和您见面!希望您在这里可以感受到一份轻松愉快的氛围,不仅可以获得有趣的内容和知识,也可以畅所欲言、分享您的想法和见解。 推荐:Linux运维老纪的首页…...

文件上传漏洞(ctfshow web151-161)
Web151 F12修改源代码 exts后面png改为php 这样就可以上传php的文件了 Web152: 考点:后端不能单一校验 就是要传图片格式,抓个包传个png的图片 然后bp抓包修改php后缀解析 然后放包 Web153-web156 在php代码中可以使用“{}”代替“[]” …...

小猪佩奇.js
闲着没事 使用js 画一个小猪佩奇把 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</tit…...

人工智能AI合集:Ollama部署对话语言大模型-网页访问
目录 🍅点击这里查看所有博文 随着人工智能技术的飞速发展,AI已经不再是遥不可及的高科技概念,而是逐渐融入到我们的日常生活中。从智能手机的语音助手到家庭中的智能音箱,再到工业自动化和医疗诊断,AI的应用无处不在…...

CentOS搭建Apache服务器
安装对应的软件包 [roothds ~]# yum install httpd mod_ssl -y 查看防火墙的状态和selinux [roothds ~]# systemctl status firewalld [roothds ~]# cat /etc/selinux/config 若未关闭,则关闭防火墙和selinux [roothds ~]# systemctl stop firewalld [roothds ~]# …...

CDGA|数据治理:安全如何贯穿数据供给、流通、使用全过程
随着信息技术的飞速发展,数据已经成为企业运营、社会管理和经济发展的核心要素。然而,数据在带来巨大价值的同时,也伴随着诸多安全风险。因此,数据治理的重要性日益凸显,它不仅仅是对数据的简单管理,更是确…...

32单片机bootloader程序
一,单片机为什么要使用bootloader 1、使用bootloader的好处 1) 程序隔离:可以同时存在多个程序,只要flash空间够大,或者通过外挂flash,可以实现多个程序共存,在多个程序之间切换使用。 2)方便程…...

MongoDB - 数组更新操作符:$、$[]、$pop、$pull、$push、$each、$sort、$slice、$position
文章目录 1. $1. 更新数组中的值2. 更新数组中的嵌入文档 2. $[]1. 更新数组中的所有元素2. 更新数组中的所有嵌入文档 3. $pop1. 删除数组的第一个元素2. 删除数组的最后一个元素 4. $pull1. 删除所有等于指定值的项2. 删除与指定条件匹配的所有项3. 从文档数组中删除项4. 从嵌…...

多GPU并行处理[任务分配、进程调度、资源管理、负载均衡]
1. 多GPU并行处理设计 设计思路: 实现基于多GPU的并行任务处理,每个GPU运行独立的任务,以加速整体的处理速度。 实现机制: 进程隔离: 利用multiprocessing.Process为每个GPU创建独立的工作进程。 GPU资源限制: 通过设置CUDA_VISIBLE_DEVICES环境变量&…...

项目部署到服务器
(相关资源都给出来了) 1 下载MobaXterm,然后打开 正常连接输入你的服务器IP,用户名可以起名为root 2 将JDK,Tomcat,mysql安装包 布置到服务器中(JDK官网地址:https://www.oracle.com/java/technologies/downloads/#java8 mysql官网地址: …...

Idea2024 创建Meaven项目没有src文件夹
1、直接创建 新建maven项目,发现没有src/main/java 直接新建文件夹:右击项目名->new->Directory 可以看到idea给出了快捷创建文件夹的选项,可以根据需要创建,这里点击src/main/java 回车,可以看到文件夹已经创建…...

LeetCode 2766.重新放置石块:哈希表
【LetMeFly】2766.重新放置石块:哈希表 力扣题目链接:https://leetcode.cn/problems/relocate-marbles/ 给你一个下标从 0 开始的整数数组 nums ,表示一些石块的初始位置。再给你两个长度 相等 下标从 0 开始的整数数组 moveFrom 和 moveTo…...

基于STM32的农业大棚温湿度采集控制系统的设计
目录 1、设计要求 2、系统功能 3、演示视频和实物 4、系统设计框图 5、软件设计流程图 6、原理图 7、主程序 8、总结 🤞大家好,这里是5132单片机毕设设计项目分享,今天给大家分享的是智能教室。 设备的详细功能见网盘中的文章《8、基…...

go语言的命名规则
身为前端为什么去学go语言呢?我认为go在未来可能会给我带来一些收益。自认为收益是去做一件事情不可缺少的因素,就好像是你努力之后得到回报,努力的欲望会越来越强。《Head First Go》这本书里作者有一句话,如果你已经掌握了一门编…...

新增ClamAV病毒扫描功能、支持Java和Go运行环境,1Panel开源面板v1.10.12版本发布
2024年7月19日,现代化、开源的Linux服务器运维管理面板1Panel正式发布了v1.10.12版本。 在这一版本中,1Panel新增了多项实用功能。社区版方面,1Panel新增ClamAV病毒扫描功能、支持Java和Go运行环境,同时1Panel还新增了文件编辑器…...

Windows通过命令查看mac : getmac
要查看本机网卡mac,可以通过ipconfig /all 显示,但输出内容过多 可以通过getmac命令查看 示例 C:\Users\Desktop> getmac物理地址 传输名称暂缺 没有硬件 1C-1B-B5-04-E2-7D \Device\Tcpip_{80096E40-D51D-490C-9AF7-…...

Android笔试面试题AI答之Android系统与综合类(1)
答案仅供参考,来着文心一言、Kimi.ai 目录 1.简述嵌入式实时操作系统,Android 操作系统属于实时操作系统吗?嵌入式实时操作系统简述Android操作系统是否属于实时操作系统 2.简述Android系统的优势和不足?3.简述Android的系统架构 ࿱…...

【Android】数据存储方案——文件存储、SharedPreferences、SQLite数据库用法总结
文章目录 文件存储存储到文件读取文件 SharedPreferences存储存储获取SharedPreferences对象Context 类的 getSharedPreferences() 方法Activity 类的 getPreferences() 方法PreferenceManager 类中的 getDefaultSharedPreferences() 方法 示例 读取记住密码的功能 SQLite数据库…...