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. 从嵌…...
浅谈 React Hooks
React Hooks 是 React 16.8 引入的一组 API,用于在函数组件中使用 state 和其他 React 特性(例如生命周期方法、context 等)。Hooks 通过简洁的函数接口,解决了状态与 UI 的高度解耦,通过函数式编程范式实现更灵活 Rea…...
生成xcframework
打包 XCFramework 的方法 XCFramework 是苹果推出的一种多平台二进制分发格式,可以包含多个架构和平台的代码。打包 XCFramework 通常用于分发库或框架。 使用 Xcode 命令行工具打包 通过 xcodebuild 命令可以打包 XCFramework。确保项目已经配置好需要支持的平台…...
dedecms 织梦自定义表单留言增加ajax验证码功能
增加ajax功能模块,用户不点击提交按钮,只要输入框失去焦点,就会提前提示验证码是否正确。 一,模板上增加验证码 <input name"vdcode"id"vdcode" placeholder"请输入验证码" type"text&quo…...
使用van-uploader 的UI组件,结合vue2如何实现图片上传组件的封装
以下是基于 vant-ui(适配 Vue2 版本 )实现截图中照片上传预览、删除功能,并封装成可复用组件的完整代码,包含样式和逻辑实现,可直接在 Vue2 项目中使用: 1. 封装的图片上传组件 ImageUploader.vue <te…...
【算法训练营Day07】字符串part1
文章目录 反转字符串反转字符串II替换数字 反转字符串 题目链接:344. 反转字符串 双指针法,两个指针的元素直接调转即可 class Solution {public void reverseString(char[] s) {int head 0;int end s.length - 1;while(head < end) {char temp …...
相机Camera日志分析之三十一:高通Camx HAL十种流程基础分析关键字汇总(后续持续更新中)
【关注我,后续持续新增专题博文,谢谢!!!】 上一篇我们讲了:有对最普通的场景进行各个日志注释讲解,但相机场景太多,日志差异也巨大。后面将展示各种场景下的日志。 通过notepad++打开场景下的日志,通过下列分类关键字搜索,即可清晰的分析不同场景的相机运行流程差异…...
Android Bitmap治理全解析:从加载优化到泄漏防控的全生命周期管理
引言 Bitmap(位图)是Android应用内存占用的“头号杀手”。一张1080P(1920x1080)的图片以ARGB_8888格式加载时,内存占用高达8MB(192010804字节)。据统计,超过60%的应用OOM崩溃与Bitm…...
如何理解 IP 数据报中的 TTL?
目录 前言理解 前言 面试灵魂一问:说说对 IP 数据报中 TTL 的理解?我们都知道,IP 数据报由首部和数据两部分组成,首部又分为两部分:固定部分和可变部分,共占 20 字节,而即将讨论的 TTL 就位于首…...
OPenCV CUDA模块图像处理-----对图像执行 均值漂移滤波(Mean Shift Filtering)函数meanShiftFiltering()
操作系统:ubuntu22.04 OpenCV版本:OpenCV4.9 IDE:Visual Studio Code 编程语言:C11 算法描述 在 GPU 上对图像执行 均值漂移滤波(Mean Shift Filtering),用于图像分割或平滑处理。 该函数将输入图像中的…...
JS设计模式(4):观察者模式
JS设计模式(4):观察者模式 一、引入 在开发中,我们经常会遇到这样的场景:一个对象的状态变化需要自动通知其他对象,比如: 电商平台中,商品库存变化时需要通知所有订阅该商品的用户;新闻网站中࿰…...
