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


 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/50213.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java算法day23

java算法day23 121买卖股票的最佳时机55 跳跃游戏45 跳跃游戏Ⅱ763划分子母区间 121买卖股票的最佳时机 最容易想的应该就是两个for暴力枚举。但是超时 本题用贪心做应该是最快的。 先看清楚题&#xff0c;题目要求在某一天买入&#xff0c;然后在某一天卖出&#xff0c;要求…

MarkTool集合篇

MarkTool目前包含以下几种工具 1、TCP客户端 2、TCP服务端 3、UDP客户端 4、Web客户端 5、Web服务端 6、串口网口 7、PLC 8、获取本机设备 9、Log 10、密钥 11、系统设置 11-1、基本设置 11-2、角色设置 11-3、用户设置 11-4、log记录 开启软件需要找我解密&#…

S7-1200PLC通过111报文和EPOS模式实现位置轴轴控功能(FB284封装)

EASY_SINA_POS的详细使用介绍请参考下面文章链接: S7-1200PLC使用标准报文111和EPOS模式实现V90 PN总线伺服定位(Easy_SINA_Pos)_西门子sinapos-CSDN博客文章浏览阅读132次。文章浏览阅读7k次。先简单说下如何获取FB284,一般有2种方法,Startdrive软件可以操作大部分西门子的…

PostgreSQL使用(四)——数据查询

说明&#xff1a;对于一门SQL语言&#xff0c;数据查询是我们非常常用的&#xff0c;也是SQL语言中非常大的一块。本文介绍PostgreSQL使用中的数据查询&#xff0c;如有一张表&#xff0c;内容如下&#xff1a; 简单查询 --- 1.查询某张表的全部数据 select * from tb_student…

【Qt】QLabel常用属性相关API

QLabel是Qt框架中用于显示文本或图案的小部件。在Qt应用程序中&#xff0c;QLabel是用来呈现静态文本或图像给用户的重要部分 QLabel属性陈列 属性说明textQLabel中的文本内容textFormat 文本的格式 Qt::PlainText 纯文本Qt::RichText 富文本Qt::MarkdownText markdown…

管理和监控 Oracle 数据库中的会话和进程,以及终止特定的会话

select username,count(username) from v$session where username is not null group by username;• 作用: 统计每个用户的当前会话数量。 • 介绍: 从 v$session 视图中选择 username 和 username 的计数&#xff0c;并对不为空的 username 进行分组。 SELECT sid, serial#,…

IntelliJIDEA------简介

IntelliJ IDEA 14是java语言开发的集成环境,IntelliJ在业界被公认为最好的java开发工具之一&#xff0c;尤其在智能代码助手、代码自动提示、重构、J2EE支 持、Ant、JUnit、CVS整合、代码审查、 创新的GUI设计等方面的功能可以说是超常的。 IntelliJ IDEA特色功能 IDEA所提倡的…

【数据结构】排序算法(冒泡排序、插入排序、希尔排序、选择排序、堆排序、计数排序)

生命不可能有两次&#xff0c;但许多人连一次也不善于度过。&#x1f493;&#x1f493;&#x1f493; 目录 ✨说在前面 &#x1f34b;知识点一&#xff1a;排序的概念和应用 • &#x1f330;1.排序及其概念 • &#x1f330;2.排序的应用 • &#x1f330;3.常见的排序算…

php 箭头函数详解

PHP 的箭头函数&#xff08;也称为匿名函数或闭包函数&#xff09;是一种简洁的定义单表达式函数的方法。这种语法是从 PHP 7.4 版本开始引入的&#xff0c;它使得创建简短的一次性使用的函数变得更加方便。 基本语法 箭头函数的基本语法如下&#xff1a; fn($parameters) &…

qt做的分页控件

介绍 qt做的分页控件 如何使用 创建 Pagination必须基于一个QWidget创建&#xff0c;否则会引发错误。 Pagination* pa new Pagination(QWidget*);设置总页数 Pagination需要设置一个总的页数&#xff0c;来初始化页码。 pa->SetTotalItem(count);设置可选的每页数量…

前端养成记-实现一个低配版简单版本的vue3表单自定义设计组件

简介&#xff1a; 通过使用了最新的vue3,vite2,TypeScript等主流技术开发&#xff0c;并配合使用vuedraggable 插件以及antd design vue 组件库实现低配版本的自定义表单设计组件&#xff1b; 项目地址&#xff1a;https://gitee.com/hejunqing/vue3-antdv-generator

PyTorch模型训练步步详解:从零开始构建深度学习流程

P y T o r c h 训练模型流程图 PyTorch训练模型流程图 P y T orc h 训练模型流程图

Python面试宝典第20题:精选问答题

题目1 解释Python中的GIL是什么&#xff0c;它是如何影响多线程程序的&#xff1f; 题目2 Python中的装饰器是什么&#xff0c;如何定义和使用一个装饰器&#xff1f; 题目3 Python中的迭代器和生成器有什么区别&#xff0c;并提供一个使用生成器的例子。 题目4 谈一谈你对Pyth…

非凸T0算法,如何获取超额收益?

什么是非凸 T0 算法&#xff1f; 非凸 T0 算法基于投资者持有的股票持仓&#xff0c;利用机器学习等技术&#xff0c;短周期预测&#xff0c;全自动操作&#xff0c;抓取行情波动价差&#xff0c;增厚产品收益。通过开仓金额限制、持仓时长控制等&#xff0c;把控盈亏风险&…

学习笔记:MySQL数据库操作5

1. 触发器&#xff08;Triggers&#xff09; 触发器是数据库的一种高级功能&#xff0c;它允许在执行特定数据库操作&#xff08;如INSERT、UPDATE、DELETE&#xff09;之前或之后自动执行一段代码。 1.1 创建商品和订单表 商品表&#xff08;goods&#xff09; gid: 商品编号…

会话存储、本地存储,路由导航守卫、web会话跟踪、JWT生成token、axios请求拦截、响应拦截

1、会话存储、本地存储 前端浏览器中存储用户信息&#xff0c;会话存储、本地存储、cookie 会话存储&#xff08;sessionStorage&#xff09;&#xff1a;会话期间存储&#xff0c;关闭浏览器后&#xff0c;数据就会销毁 sessionStorage.setItem("account",resp.d…

反射型与dom型的xss的区别【源码分析】

反射型 XSS 和 DOM 型 XSS 都属于跨站脚本攻击 (XSS) 的类型&#xff0c;它们的共同点是均能通过注入恶意脚本在用户浏览器中执行&#xff0c;不同点是dom型xss不经过服务器&#xff0c;而反射型是经过服务器的。但是&#xff0c;它们在攻击方式、执行过程和防御措施上有所不同…

flask后端+vue前端——后端怎么发文件给前端?

首先&#xff0c;前端axios请求的responseType要设置为blob const service axios.create({baseURL: http://127.0.0.1/api,timeout: 5000});//向后端发送数据&#xff0c;后端根据这个数据data生成文件返回send_coordinate(data){return service.post(/,data,{responseType: …

c++栈笔记

一种常见的数据结构&#xff0c;遵循后进先出&#xff0c;先进后出的原则。地址不连续&#xff0c;栈顶&#xff08;top&#xff09; 1.常见函数 stack<int> s;定义一个参数类型为int 的栈 名为ss.push()向栈中插入元素s.emplace()压栈&#xff0c;无返回值s.pop()删除…

@SpingFrameWork

SpingFrameWork 一、技术体系结构 单一架构&#xff0c;一个大的项目&#xff0c;一个工程&#xff0c;导出war包在一个tomcat上运行&#xff08;主要用spring、springMVC、Mybatis&#xff09;分布式架构&#xff0c;一个项目&#xff0c;但是有多个模块&#xff0c;但是每个…