找回密码
 立即注册
首页 业界区 科技 使用C#编写WRobot 魔兽世界自动化脚本的指南(循环刷本 ...

使用C#编写WRobot 魔兽世界自动化脚本的指南(循环刷本)

沦嘻亟 2025-6-7 13:29:05
引言

在《魔兽世界》中,自动化脚本可以帮助玩家完成重复性任务,如打怪、拾取物品、售卖物品等。WRobot是一个可用在私服上的自动化工具,支持使用C#编写自定义脚本。
本文将介绍如何使用C#编写一个的WRobot自动化循环刷本脚本。
如果对Wrobot 基础编码不太了解,可以看下我在B站UP的视频(B站:兔兔跳啊跳),顺便求个关注+三连:
魔兽世界Wrobot插件编写教程(C#)
如果想了解战斗脚本的编制,可以看我另个视频(PS: 我在b站传的第一个视频,录的不好,见谅。):
魔兽世界Wrobot辅助脚本制作教学视频
1. 环境准备

在开始编写脚本之前,确保你已经安装了WRobot,并熟悉其基本操作。WRobot提供了一个插件系统,允许用户通过C#编写自定义逻辑。
对应版本:魔兽世界-暗影国度 9.27 + WRobot 2.8.0 (大概在国服开10.0的时,国外有了个9版本的私服,就写了这脚本用来刷G,后来刷了100多w也没啥用,游戏也弃了,回归国服继续肝正式服)
2. 创建插件

WRobot插件是一个实现了wManager.Plugin.IPlugin接口的C#类。以下是一个简单的插件模板:
csharp复制代码
  1. using System;
  2. using System.Threading;
  3. using robotManager.Helpful;
  4. using wManager.Wow.Class;
  5. using wManager.Wow.Helpers;
  6. using wManager.Wow.ObjectManager;
  7. public class MyPlugin : wManager.Plugin.IPlugin
  8. {
  9.     private bool isLaunched;
  10.     public void Initialize()
  11.     {
  12.         isLaunched = true;
  13.         Logging.Write("插件已启动");
  14.         // 在这里添加你的逻辑
  15.         while (isLaunched)
  16.         {
  17.             // 执行任务
  18.             Thread.Sleep(1000);
  19.         }
  20.     }
  21.     public void Dispose()
  22.     {
  23.         isLaunched = false;
  24.         Logging.Write("插件已停止");
  25.     }
  26.     public void Settings()
  27.     {
  28.         // 插件设置
  29.     }
  30. }
复制代码
3. 关键功能实现

在Initialize方法中,你可以编写插件的核心逻辑。以下是一些常见的功能实现:
3.1 移动和导航

使用GoToTask.ToPosition方法可以让角色移动到指定位置:
csharp复制代码
  1. wManager.Wow.Bot.Tasks.GoToTask.ToPosition(new Vector3(-786.707f, 6100.32f, 4.649368f));
复制代码
3.2 与NPC交互

使用GoToTask.ToPositionAndIntecractWithNpc方法可以与指定NPC交互:
csharp复制代码
  1. wManager.Wow.Bot.Tasks.GoToTask.ToPositionAndIntecractWithNpc(new Vector3(-786.707f, 6100.32f, 4.649368f), 89257);
复制代码
 
以下是完整代码:
  1. using System;
  2. using System.Threading;
  3. using robotManager.Helpful;
  4. using robotManager.Products;
  5. using wManager.Wow.Class;
  6. using wManager.Wow.Helpers;
  7. using wManager.Wow.ObjectManager;
  8. using Timer = robotManager.Helpful.Timer;
  9. using System.Collections.Generic;
  10. using System.Configuration;
  11. using System.ComponentModel;
  12. using robotManager;
  13. using System.IO;
  14. using robotManager.FiniteStateMachine;
  15. using wManager.Wow.Bot.States;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using wManager.Wow.Bot.Tasks;
  20. using wManager;
  21. using robotManager.Events;
  22. using System.Collections.Generic;
  23. using System.Linq;
  24. using System.Threading;
  25. using wManager.Wow.Enums;
  26. using System.Windows;
  27. using System.Text.RegularExpressions;
  28. // using 主要从wrobot中获取wManager 和 robotManager 命名空间
  29. // 一些注释代码是做一些备用功能或备忘录用的
  30. public class Mainasl: wManager.Plugin.IPlugin
  31. {
  32.     private bool isLaunched;
  33.     // ContinentId = 1220    1456
  34.     //return Usefuls.ContinentId == 1456;
  35.     private void test()
  36.     {
  37.         robotManager.Helpful.Mouse.ClickLeft();
  38.         //robotManager.Helpful.Keyboard.PressKey(wManager.Wow.Memory.WowMemory.Memory.WindowHandle, System.Windows.Forms.Keys.);
  39.         //rbotManager.Helpful.XmlSerializer.
  40.     }
  41.     public void Initialize()
  42.     {
  43.         var originStr = "";
  44.         var regStr = @"!\w+\s\d+";
  45.         var resultStr = string.Empty;
  46.         MatchCollection matches = Regex.Matches(originStr, regStr);
  47.         foreach(Match match in matches)
  48.         {
  49.             resultStr = match.Value;
  50.         }
  51.         if(!string.IsNullOrWhiteSpace(resultStr))
  52.         {
  53.             // 输入
  54.         }
  55.         robotManager.Events.ProductEvents.OnProductLoaded += ProductEvents_OnProductLoaded;
  56.         robotManager.Products.Products.LoadProducts("");
  57.         isLaunched = true;
  58.         
  59.         if(Usefuls.AreaId != 7334 && Usefuls.ContinentId != 1456)
  60.         {
  61.             Products.ProductStop();
  62.             Logging.Write("非阿苏纳地图或者非艾萨拉之眼地图,停止WR");
  63.         }
  64.         if(Usefuls.AreaId == 7334)
  65.         {
  66.             if(wManager.Wow.Helpers.Bag.GetContainerNumFreeSlots <= 60) //判断包裹剩余格子
  67.             {
  68.                 // 找NPC 清包裹
  69.                 wManager.Wow.Bot.Tasks.GoToTask.ToPositionAndIntecractWithNpc(new Vector3(-786.707 f, 6100.32 f, 4.649368 f), 89257);
  70.                 List < WoWItem > wiList = Bag.GetBagItem();
  71.                 List < string > itemSell = new List < string > ();
  72.                 List < string > itemNoSell = new List < string > ();
  73.                 itemNoSell.Add("炉石");
  74.                 itemNoSell.Add("飞行管理员的哨子");
  75.                 List < WoWItemQuality > itemQuality = new List < WoWItemQuality > ();
  76.                 itemQuality.Add(WoWItemQuality.Artifact);
  77.                 itemQuality.Add(WoWItemQuality.Common);
  78.                 itemQuality.Add(WoWItemQuality.Epic);
  79.                 itemQuality.Add(WoWItemQuality.Heirloom);
  80.                 itemQuality.Add(WoWItemQuality.Legendary);
  81.                 itemQuality.Add(WoWItemQuality.Poor);
  82.                 itemQuality.Add(WoWItemQuality.Rare);
  83.                 itemQuality.Add(WoWItemQuality.Uncommon);
  84.                 for(int i = 0; i < wiList.Count; i++)
  85.                 {
  86.                     itemSell.Add(wiList[i].Name);
  87.                 }
  88.                 Vendor.SellItems(itemSell, itemNoSell, itemQuality);//卖掉所有东西
  89.                 Thread.Sleep(1000 * 3);
  90.             }
  91.             Logging.Write("回到艾萨拉之眼副本门口");
  92.             Lua.LuaDoString("ResetInstances();");
  93.             Logging.Write("重置副本");
  94.             wManager.Wow.Bot.Tasks.GoToTask.ToPosition(new Vector3(-2.174723 f, 5800.943 f, 2.098947 f));
  95.             Logging.Write("进本");
  96.             // 门口模拟按键
  97.             Move.StrafeLeft(Move.MoveAction.PressKey, 100);
  98.             Move.Forward(Move.MoveAction.PressKey, 2000);
  99.         }
  100.         // sell point to 0 - 3
  101.         wManager.Wow.Bot.Tasks.GoToTask.ToPosition(new Vector3(-771.9302 f, 6111.996 f, 51.47897 f));
  102.         wManager.Wow.Bot.Tasks.GoToTask.ToPosition(new Vector3(-606.0879 f, 5991.238 f, 67.36471 f));
  103.         wManager.Wow.Bot.Tasks.GoToTask.ToPosition(new Vector3(-403.6466 f, 5857.353 f, 101.1433 f));
  104.         Thread.Sleep(1000 * 30);
  105.         wManager.Wow.Bot.Tasks.GoToTask.ToPosition(new Vector3(-201.3126 f, 5747.511 f, 135.9531 f));
  106.         //PositionWithoutType = -786.707 ; 6100.32 ; 4.649368 ; "None"
  107.         //PositionRelativeWithoutType = -786.707; 6100.32; 4.649368; "None"
  108.         if(Usefuls.ContinentId == 1220 && wManager.Wow.Helpers.Bag.GetContainerNumFreeSlots <= 2)
  109.         {
  110.             wManager.Wow.Bot.Tasks.GoToTask.ToPositionAndIntecractWithNpc(new Vector3(-786.707 f, 6100.32 f, 4.649368 f), 89257);
  111.             List < WoWItem > wiList = Bag.GetBagItem();
  112.             List < string > itemSell = new List < string > ();
  113.             List < string > itemNoSell = new List < string > ();
  114.             itemNoSell.Add("炉石");
  115.             itemNoSell.Add("飞行管理员的哨子");
  116.             List < WoWItemQuality > itemQuality = new List < WoWItemQuality > ();
  117.             itemQuality.Add(WoWItemQuality.Artifact);
  118.             itemQuality.Add(WoWItemQuality.Common);
  119.             itemQuality.Add(WoWItemQuality.Epic);
  120.             itemQuality.Add(WoWItemQuality.Heirloom);
  121.             itemQuality.Add(WoWItemQuality.Legendary);
  122.             itemQuality.Add(WoWItemQuality.Poor);
  123.             itemQuality.Add(WoWItemQuality.Rare);
  124.             itemQuality.Add(WoWItemQuality.Uncommon);
  125.             for(int i = 0; i < wiList.Count; i++)
  126.             {
  127.                 itemSell.Add(wiList[i].Name);
  128.             }
  129.             Vendor.SellItems(itemSell, itemNoSell, itemQuality);
  130.         }
  131.         //  回到坐标  -2.174723 ; 5800.943 ; 2.098947
  132.         wManager.Wow.Bot.Tasks.GoToTask.ToPosition(new Vector3(-2.174723 f, 5800.943 f, 2.098947 f));
  133.         Logging.Write("111" + Lua.LuaDoString < string > ("GetDungeonDifficulty();"));
  134.         Lua.LuaDoString("SetDungeonDifficulty(2);");
  135.         Move.Forward(Move.MoveAction.PressKey, 3000);
  136.         Move.StrafeLeft(Move.MoveAction.PressKey, 100);
  137.         Write("初始化...");
  138.         // 以下配置是可以在Wrobot工具中配置,也可以在这里写代码直接配置好
  139.         wManagerSetting.CurrentSetting.CloseAfterXMin = 60 * 3; // XX分钟后停止WR
  140.         wManagerSetting.CurrentSetting.LootMobs = true; //拾取
  141.         //被GM传送关闭游戏
  142.         wManagerSetting.CurrentSetting.CloseIfPlayerTeleported = false;
  143.         //目标周围怪物数量
  144.         wManagerSetting.CurrentSetting.MaxUnitsNear = 99;
  145.         //可攻击灰名怪
  146.         wManagerSetting.CurrentSetting.CanAttackUnitsAlreadyInFight = true;
  147.         //可攻击精英怪
  148.         wManagerSetting.CurrentSetting.AttackElite = true;
  149.         //主动攻击敌对玩家
  150.         wManagerSetting.CurrentSetting.AttackBeforeBeingAttacked = false;
  151.         //寻怪搜索范围
  152.         wManagerSetting.CurrentSetting.SearchRadius = 25;
  153.         //避免在玩家附近拾取
  154.         wManagerSetting.CurrentSetting.HarvestAvoidPlayersRadius = 0;
  155.         //远距离拾取41
  156.         wManagerSetting.CurrentSetting.HarvestDuringLongMove = true;
  157.         wManagerSetting.CurrentSetting.Repair = false; // 修理
  158.         wManagerSetting.CurrentSetting.Selling = false; // 售卖
  159.         wManagerSetting.CurrentSetting.HarvestHerbs = false; // 采集
  160.         //wManagerSetting.CurrentSetting.acc
  161.         wManager.wManagerSetting.CurrentSetting.LootChests = true; //拾取
  162.         wManager.wManagerSetting.CurrentSetting.LootChests = true;
  163.         Logging.Stop();
  164.         robotManager.Helpful.Logging.Stop();
  165.         wManagerSetting.CurrentSetting.UseFlyingMount = true;
  166.         wManagerSetting.CurrentSetting.FlyAboveGroundHeight = 60;
  167.         wManagerGlobalSetting.CurrentSetting.Save();
  168.         while(true)
  169.         {
  170.             isLaunched = true;
  171.             GO();
  172.             
  173.             robotManager.Events.LoggingEvents.OnAddLog += delegate(Logging.Log log)
  174.             {
  175.                 if(!log.Text.Contains("[ToTown] Unable to reach the vendor, blacklist it 120 minutes (you can disable this NPC in NPC DB tab 'Tools').")) return;
  176.                 foreach(var n in NpcDB.ListNpc)
  177.                 {
  178.                     n.BlackList(-1);
  179.                 }
  180.             };
  181.             robotManager.Events.LoggingEvents.OnAddLog += (robotManager.Helpful.Logging.Log log) =>
  182.             {
  183.                 log.Text = string.Empty;
  184.             };
  185.             while(Products.IsStarted)
  186.             {
  187.                 try
  188.                 {
  189.                     try
  190.                     {
  191.                         if(Usefuls.ContinentId == 1220) // 固定在这地图不动了
  192.                         {
  193.                             Move.Forward(Move.MoveAction.PressKey, 300); // 运行过程中会有问题,导致角色不动了,用个纠错移动来继续执行脚本。大概率是wow服务端问题
  194.                             Logging.Write("纠错移动");
  195.                         }
  196.                     }
  197.                     catch(Exception)
  198.                     {}
  199.                     Thread.Sleep(1000 * 60 * 2);
  200.                 }
  201.                 catch(Exception)
  202.                 {}
  203.             }
  204.         }
  205.     }
  206.     private void ProductEvents_OnProductLoaded(string str)
  207.         {
  208.             throw new NotImplementedException();
  209.         }
  210.         // 其实判断装备好坏是个很难的问题,涉及到很多代码,不想写了,毕竟刷本是用来刷G的
  211.         //private void EventsLuaWithArgs_OnEventsLuaWithArgs(string eventName, List<string> args)
  212.         //{
  213.         //    if (eventName == "CHAT_MSG_LOOT") // 监听物品拾取事件
  214.         //    {
  215.         //        string lootMessage = args.FirstOrDefault();
  216.         //        if (lootMessage != null)
  217.         //        {
  218.         //            // 解析物品链接
  219.         //            string itemLink = Lua.LuaDoString<string>(lootMessage);
  220.         //            if (!string.IsNullOrEmpty(itemLink))
  221.         //            {
  222.         //                // 判断拾取的物品是否为装备
  223.         //                if (ItemsManager.GetItemType(itemLink) == WoWItemType.Armor ||
  224.         //                    ItemsManager.GetItemType(itemLink) == WoWItemType.Weapon)
  225.         //                {
  226.         //                    // 比较装备,判断是否更好
  227.         //                    if (IsBetterEquipment(itemLink))
  228.         //                    {
  229.         //                        // 装备物品
  230.         //                        EquipItem(itemLink);
  231.         //                    }
  232.         //                }
  233.         //            }
  234.         //        }
  235.         //    }
  236.         //}
  237.     public static bool IsWorldFrame()
  238.         {
  239.             string cmd = "return WorldFrame:IsVisible();";
  240.             Logging.Write(Lua.LuaDoString < string > (cmd));
  241.             return Lua.LuaDoString < bool > (cmd);
  242.             Lua.LuaDoString("WorldFrame:Click()");
  243.             Lua.LuaDoString("print('[WorldFrame错误点击]');");
  244.             Logging.Write("[WorldFrame错误点击]");
  245.         }
  246.         //private bool IsBetterEquipment(string itemLink)
  247.         //{
  248.         //    // 获取角色当前装备的同一部位的物品
  249.         //    WoWItem equippedItem = ObjectManager.Me.Inventory.GetItemBySlot(itemLink.GetInventorySlot());
  250.         //    // 比较物品的属性来判断是否更好
  251.         //    if (equippedItem != null)
  252.         //    {
  253.         //        WoWItem newItem = new WoWItem(itemLink);
  254.         //        newItem.GetItemInfo.
  255.         //        return newItem.GetTotalStatValue() > equippedItem.GetTotalStatValue();
  256.         //    }
  257.         //    return true; // 如果当前部位没有装备,直接判断为更好
  258.         //}
  259.         //private void EquipItem(string itemLink)
  260.         //{
  261.         //    Lua.LuaDoString("UseContainerItem(" + itemLink.GetBagIndex() + ", " + itemLink.GetBagSlot() + ")");
  262.         //}
  263.    
  264.     private static void EventsLuaWithArgs_OnEventsLuaWithArgs(LuaEventsId id, List < string > args)
  265.     {
  266.         throw new NotImplementedException();
  267.     }
  268.     public void GO()
  269.     {
  270.         Products.ProductStop();
  271.         Products.ProductStart();
  272.         //Move.Forward(Move.MoveAction.PressKey, 5000);  //
  273.     }
  274.     public void Write(string text)
  275.     {
  276.         Logging.Write(text);
  277.         Lua.LuaDoString("print('" + text + "');");
  278.     }
  279.     public void Dispose()
  280.     {
  281.         isLaunched = false;
  282.     }
  283.     public void Settings()
  284.     {}
  285. }
复制代码
 

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册