找回密码
 注册/Sign up
搜索
查看: 7880|回复: 34

几个简易佣兵AI分享

[复制链接]

发表于 2022-4-2 00:04:35 | 显示全部楼层 |阅读模式
本帖最后由 xman 于 2022-4-2 00:07 编辑

基本需求


autoBattle.lua
  1.   local hp = Char.GetData(charIndex,%对象_血%);
  2.   local hpMax = Char.GetData(charIndex,%对象_最大血%);
复制代码

须先理解的部分
1.Const.lua中找到正确对应的技能(粗体)
并且决定技能范围(数字)

2.建议新增专用技能,调整所需mp,方便佣兵使用
以下暂以原始技能作为范例

Const.lua (省略解说版勿用)
  1. CONST.BATTLE_COM_TARGETS = {
  2. NONE = -1,
  3.   SINGLE = {
  4.     SIDE_0 = {
  5.     SIDE_1 = {
  6.   RANGE = {
  7.     SIDE_0 = {
复制代码
我方单体0~9
敌方单体10~19
我方范围20~29
敌方范围30~39
我方全体40
敌方全体41
敌我全体42

一、随机六种超强状态魔法 autoBattle.lua
  1.   elseif ybjn and yb04 and mp >= 280 then
  2.     local StatuschangeData= { 4409,4509,4609,4709,4809,4909 };
复制代码

二、开场即超强恢复魔法(0回合) autoBattle.lua
        其余回合随机施放超补或超恢 (施放者血量50%以下优先超补)
  1.   elseif ybjn and yb06 and mp >= 480then
  2.     local HealRecoveryData  = { {<b>CONST.BATTLE_COM.BATTLE_COM_<i>P_HEAL</i></b>, 6309}, {<b>CONST.BATTLE_COM.BATTLE_COM_<i>P_LP_RECOVERY</i></b>, 6609} };
  3.     if Battle.GetTurn(battleIndex) == 0 then
  4.         HRR = 2;
复制代码
两个超强范围都是我方全体所以40不变
配对改变前、后的部分


三、宠物 敌单体火焰属性魔法强制为敌全体(41) autoBattle.lua
        主人血量50%以下施放攻击无效
  1.   elseif ybjn and ybcw05 and mp2 >= 100 then
  2.     local MagicPhysicsData  = { {<b>CONST.BATTLE_COM.BATTLE_COM_<i>P_MAGIC</i></b>, <b>41</b>, 2109}, {<b>CONST.BATTLE_COM.BATTLE_COM_<i>P_INEFFECTIVE_PHYSICS</i></b>, <b>20+Battle.GetSlot(battleIndex, charIndex)</b>, 5909} };
复制代码
2109原为单体火焰魔法,设定41强制为敌方全体
5909原为单体攻击无效,设定20+ (0~9为我方强力




补充内容 (2022-5-31 20:28):
请跳过这篇看下面置顶

 楼主| 发表于 2022-4-2 00:15:28 | 显示全部楼层
本帖最后由 xman 于 2022-4-2 00:19 编辑

代码被删去重新传完整版


一、随機六種超強狀态魔法 autoBattle.lua
  1.   elseif ybjn and yb04 and mp >= 280 then
  2.                 local StatuschangeData = { 4409,4509,4609,4709,4809,4909 };
  3.                 local StaR = math.random(1, 6);
  4.           Battle.ActionSelect(charIndex, CONST.BATTLE_COM.BATTLE_COM_P_STATUSCHANGE, 41, StatuschangeData[StaR]);
  5.                   elseif ybjn and yb04 and mp < 280 then
  6.           Battle.ActionSelect(charIndex, CONST.BATTLE_COM.BATTLE_COM_ATTACK, 10, -1);
复制代码


二、開場即超強恢複魔法(0回合) autoBattle.lua
        其餘回合随機施放超補或超恢 (施放者血量50%以下優先超補)
  1.   elseif ybjn and yb06 and mp >= 480 then
  2.                 local HealRecoveryData = { {CONST.BATTLE_COM.BATTLE_COM_P_HEAL, 6309}, {CONST.BATTLE_COM.BATTLE_COM_P_LP_RECOVERY, 6609} };
  3.                 if Battle.GetTurn(battleIndex) == 0 then
  4.                         HRR = 2;
  5.                 else
  6.                         HRR = math.random(1, 2);
  7.                         if hp <= hpMax/2 then        HRR = 1;        end
  8.                 end
  9.           Battle.ActionSelect(charIndex, HealRecoveryData[HRR][1], 40, HealRecoveryData[HRR][2]);
  10.                   elseif ybjn and yb06 and mp < 480 then
  11.           Battle.ActionSelect(charIndex, CONST.BATTLE_COM.BATTLE_COM_ATTACK, 10, -1);
复制代码
兩個超強範圍都是我方全體所以40不變
配對改變前、後的部分


三、寵物 敵單體火焰屬性魔法強制爲敵全體(41) autoBattle.lua
        主人血量50%以下施放攻擊無效
  1.   elseif ybjn and ybcw05 and mp2 >= 100 then
  2.                 local MagicPhysicsData = { {CONST.BATTLE_COM.BATTLE_COM_P_MAGIC, 41, 2109}, {CONST.BATTLE_COM.BATTLE_COM_P_INEFFECTIVE_PHYSICS, 20+Battle.GetSlot(battleIndex, charIndex), 5909} };
  3.                 if hp <= hpMax/2 then
  4.                         MPR = 2;
  5.                 else
  6.                         MPR = 1;
  7.                 end
  8.           Battle.ActionSelect(petIndex, MagicPhysicsData[MPR][1], MagicPhysicsData[MPR][2], MagicPhysicsData[MPR][3]);
  9.                   elseif ybjn and ybcw05 and mp2 < 100 then
  10.           Battle.ActionSelect(petIndex, CONST.BATTLE_COM.BATTLE_COM_ATTACK, 10, -1);
复制代码
2109原爲單體火焰魔法,設定41強制爲敵方全體
5909原爲單體攻擊無效,設定20+ (0~9爲我方強力



发表于 2022-4-2 11:11:19 | 显示全部楼层
能否解决人物逃跑假人继续战斗导致的服务器崩溃?

 楼主| 发表于 2022-4-2 13:13:24 | 显示全部楼层
yjrockman 发表于 2022-4-2 11:11
能否解决人物逃跑假人继续战斗导致的服务器崩溃?


加这段进去这边
测试不会崩端了


if Battle.GetPlayer(battleIndex, 0) < 0 then
    Battle.ActionSelect(charIndex, CONST.BATTLE_COM.BATTLE_COM_ESCAPE, -1, -1);
end

  1.   for i = 0, 9 do
  2.     local charIndex = Battle.GetPlayer(battleIndex, i);
  3.     if charIndex >= 0 then
  4.       --if Char.GetData(charIndex, CONST.CHAR_类型) == CONST.对象类型_人 then
  5.       if Char.IsDummy(charIndex) then
  6.         if Battle.GetPlayer(battleIndex, 0) < 0 then
  7.           Battle.ActionSelect(charIndex, CONST.BATTLE_COM.BATTLE_COM_ESCAPE, -1, -1);
  8.         end
复制代码



发表于 2022-4-2 15:57:03 | 显示全部楼层
加载了第二个补血的代码,第一回合可以正常释放超恢,但是第二回合开始人物就不动了,不知道是什么原因

发表于 2022-4-2 20:26:24 | 显示全部楼层
xman 发表于 2022-4-2 13:13
加这段进去这边测试不会崩端了

亲测可用,感谢

 楼主| 发表于 2022-4-3 07:03:26 来自手机 | 显示全部楼层
jzh890505 发表于 2022-4-2 15:57
加载了第二个补血的代码,第一回合可以正常释放超恢,但是第二回合开始人物就不动了,不知道是什么原因 ...

你有在傭兵名字那段增加以下嗎?

local hp = Char.GetData(charIndex,%对象_血%);

local hpMax = Char.GetData(charIndex,%对象_最大血%);

发表于 2022-4-3 11:24:42 | 显示全部楼层
大佬能否发个整合版,十分感谢

发表于 2022-4-3 12:47:10 | 显示全部楼层
xman 发表于 2022-4-3 07:03
你有在傭兵名字那段增加以下嗎?

local hp = Char.GetData(charIndex,%对象_血%);

感谢大佬,确实是这个问题,可以正常运行了

 楼主| 发表于 2022-4-3 17:08:51 | 显示全部楼层
heiseyoumo 发表于 2022-4-3 11:24
大佬能否发个整合版,十分感谢

我个人化幅度有点太多了
打内挂指令召唤佣兵,需要对应道具
佣兵形象、名字、宠物都有改动过
不介意的话可以下载参考

0403.jpg


yb.rar

8.33 KB, 下载次数: 116

您需要登录后才可以回帖 登录 | 注册/Sign up

本版积分规则

手机版|cgmsv引擎论坛

GMT+8, 2026-6-5 10:39 , Processed in 0.039592 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表