forked from DrewKestell/BloogBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestState.cs
73 lines (62 loc) · 2.8 KB
/
RestState.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using BloogBot;
using BloogBot.AI;
using BloogBot.AI.SharedStates;
using BloogBot.Game;
using BloogBot.Game.Objects;
using System.Collections.Generic;
using System.Linq;
namespace ArmsWarriorBot
{
class RestState : IBotState
{
const int stackCount = 5;
readonly Stack<IBotState> botStates;
readonly IDependencyContainer container;
readonly LocalPlayer player;
readonly WoWItem foodItem;
public RestState(Stack<IBotState> botStates, IDependencyContainer container)
{
this.botStates = botStates;
this.container = container;
player = ObjectManager.Player;
foodItem = Inventory.GetAllItems()
.FirstOrDefault(i => i.Info.Name == container.BotSettings.Food);
}
public void Update()
{
if (player.HealthPercent >= 95 ||
player.HealthPercent >= 80 && !player.IsEating ||
ObjectManager.Player.IsInCombat ||
ObjectManager.Units.Any(u => u.TargetGuid == ObjectManager.Player.Guid))
{
Wait.RemoveAll();
player.Stand();
botStates.Pop();
var foodCount = foodItem == null ? 0 : Inventory.GetItemCount(foodItem.ItemId);
if (!InCombat && foodCount == 0 && !container.RunningErrands)
{
var foodToBuy = 28 - (foodCount / stackCount);
var itemsToBuy = new Dictionary<string, int>
{
{ container.BotSettings.Food, foodToBuy }
};
var currentHotspot = container.GetCurrentHotspot();
if (currentHotspot.TravelPath != null)
{
botStates.Push(new TravelState(botStates, container, currentHotspot.TravelPath.Waypoints, 0));
botStates.Push(new MoveToPositionState(botStates, container, currentHotspot.TravelPath.Waypoints[0]));
}
botStates.Push(new BuyItemsState(botStates, currentHotspot.Innkeeper.Name, itemsToBuy));
botStates.Push(new SellItemsState(botStates, container, currentHotspot.Innkeeper.Name));
botStates.Push(new MoveToPositionState(botStates, container, currentHotspot.Innkeeper.Position));
container.CheckForTravelPath(botStates, true, false);
container.RunningErrands = true;
}
return;
}
if (foodItem != null && !ObjectManager.Player.IsEating && Wait.For("EatDelay", 500, true))
foodItem.Use();
}
bool InCombat => ObjectManager.Aggressors.Count() > 0;
}
}