-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTravelToPartyZoneTask.cs
More file actions
297 lines (264 loc) · 11.6 KB
/
TravelToPartyZoneTask.cs
File metadata and controls
297 lines (264 loc) · 11.6 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using DreamPoeBot.Common;
using DreamPoeBot.Loki.Bot;
using DreamPoeBot.Loki.Bot.Pathfinding;
using DreamPoeBot.Loki.Common;
using DreamPoeBot.Loki.Game;
using DreamPoeBot.Loki.Game.GameData;
using DreamPoeBot.Loki.Game.Objects;
using FollowBot.Helpers;
using FollowBot.SimpleEXtensions;
using log4net;
namespace FollowBot
{
class TravelToPartyZoneTask : ITask
{
private readonly ILog Log = Logger.GetLoggerInstanceForType();
private bool _enabled = true;
private Stopwatch _portalRequestStopwatch = Stopwatch.StartNew();
private static int _zoneCheckRetry = 0;
public static Stopwatch PortOutStopwatch = new Stopwatch();
public string Name { get { return "TravelToPartyZone"; } }
public string Description { get { return "This task will travel to party grind zone."; } }
public string Author { get { return "NotYourFriend original from Unknown"; } }
public string Version { get { return "0.0.0.1"; } }
public void Start()
{
PortOutStopwatch.Reset();
}
public void Stop()
{
PortOutStopwatch.Reset();
}
public void Tick()
{
}
public async Task<bool> Run()
{
if (!LokiPoe.IsInGame || LokiPoe.Me.IsDead)
{
return false;
}
await Coroutines.CloseBlockingWindows();
var leader = LokiPoe.InstanceInfo.PartyMembers.FirstOrDefault(x => x.MemberStatus == PartyStatus.PartyLeader);
if (leader == null) return false;
var leaderPlayerEntry = leader.PlayerEntry;
if (leaderPlayerEntry == null) return false;
if (leaderPlayerEntry?.IsOnline != true)
{
GlobalLog.Warn($"Leader is not Online, probably loading.");
return false;
}
var leadername = leaderPlayerEntry?.Name;
var leaderArea = leaderPlayerEntry?.Area;
if (string.IsNullOrEmpty(leadername) || leaderArea == null) return false;
if (LokiPoe.InGameState.PartyHud.IsInSameZone(leadername))
{
_zoneCheckRetry = 0;
PortOutStopwatch.Reset();
return false;
}
else
{
//if (LokiPoe.CurrentWorldArea.IsMap || LokiPoe.CurrentWorldArea.Id.Contains("AfflictionTown") || LokiPoe.CurrentWorldArea.Id.Contains("Delve_"))
//{
// if (FollowBotSettings.Instance.DontPortOutofMap) return false;
//}
if (PortOutStopwatch.IsRunning && PortOutStopwatch.ElapsedMilliseconds < (FollowBotSettings.Instance.PortOutThreshold * 1000))
{
}
else
{
_zoneCheckRetry++;
if (_zoneCheckRetry < 3)
{
await Coroutines.LatencyWait();
GlobalLog.Warn($"IsInSameZone returned false for {leadername} retry [{_zoneCheckRetry}/3]");
return true;
}
}
}
//First check the DontPortOutofMap
var curZone = World.CurrentArea;
if (!curZone.IsTown && !curZone.IsHideoutArea && FollowBotSettings.Instance.DontPortOutofMap) return false;
//Then check for Delve portals:
var delveportal = LokiPoe.ObjectManager.GetObjectsByType<AreaTransition>().FirstOrDefault(x => x.Name == "Azurite Mine" && (x.Metadata == "Metadata/MiscellaneousObject/PortalTransition" || x.Metadata == "Metadata/MiscellaneousObjects/PortalTransition"));
if (delveportal != null)
{
Log.DebugFormat("[{0}] Found walkable delve portal.", Name);
if (LokiPoe.Me.Position.Distance(delveportal.Position) > 15)
{
var walkablePosition = ExilePather.FastWalkablePositionFor(delveportal, 13);
// Cast Phase run if we have it.
FollowBot.PhaseRun();
Move.Towards(walkablePosition, "moving to delve portal");
return true;
}
var tele = await Coroutines.InteractWith(delveportal);
if (!tele)
{
Log.DebugFormat("[{0}] delve portal error.", Name);
}
FollowBot.Leader = null;
return true;
}
//Next check for Heist portals:
var heistportal = LokiPoe.ObjectManager.GetObjectByMetadata("Metadata/Terrain/Leagues/Heist/Objects/MissionEntryPortal");
if (heistportal != null && heistportal.Components.TargetableComponent.CanTarget)
{
Log.DebugFormat("[{0}] Found walkable heist portal.", Name);
if (LokiPoe.Me.Position.Distance(heistportal.Position) > 20)
{
var walkablePosition = ExilePather.FastWalkablePositionFor(heistportal, 20);
// Cast Phase run if we have it.
FollowBot.PhaseRun();
Move.Towards(walkablePosition, "moving to heist portal");
return true;
}
var tele = await Coroutines.InteractWith(heistportal);
if (!tele)
{
Log.DebugFormat("[{0}] heist portal error.", Name);
}
FollowBot.Leader = null;
return true;
}
if (leaderArea.IsMap || leaderArea.IsTempleOfAtzoatl || leaderArea.Id.Contains("Expedition"))
{
if (!await TakePortal())
await Coroutines.ReactionWait();
return true;
}
else if (leaderArea.IsLabyrinthArea)
{
if (leaderArea.Name == "Aspirants' Plaza")
{
await PartyHelper.FastGotoPartyZone(leader.PlayerEntry.Name);
return true;
}
if (World.CurrentArea.Name == "Aspirants' Plaza")
{
var trans = LokiPoe.ObjectManager.GetObjectByType<AreaTransition>();
if (trans == null)
{
var loc = ExilePather.FastWalkablePositionFor(new Vector2i(363, 423));
if (loc != Vector2i.Zero)
{
Move.Towards(loc, "Bronze Plaque");
return true;
}
else
{
GlobalLog.Warn($"[TravelToPartyZoneTask] Cant find Bronze Plaque location.");
return false;
}
}
if (LokiPoe.Me.Position.Distance(trans.Position) > 20)
{
var loc = ExilePather.FastWalkablePositionFor(trans.Position, 20);
Move.Towards(loc, $"{trans.Name}");
return true;
}
await PlayerAction.Interact(trans);
return true;
}
else if (World.CurrentArea.IsLabyrinthArea)
{
AreaTransition areatransition = null;
areatransition = LokiPoe.ObjectManager.GetObjectsByType<AreaTransition>().OrderBy(x => x.Distance).FirstOrDefault(x => ExilePather.PathExistsBetween(LokiPoe.Me.Position, ExilePather.FastWalkablePositionFor(x.Position, 20)));
if (areatransition != null)
{
Log.DebugFormat("[{0}] Found walkable Area Transition [{1}].", Name, areatransition.Name);
if (LokiPoe.Me.Position.Distance(areatransition.Position) > 20)
{
var walkablePosition = ExilePather.FastWalkablePositionFor(areatransition, 20);
// Cast Phase run if we have it.
FollowBot.PhaseRun();
Move.Towards(walkablePosition, "moving to area transition");
return true;
}
var trans = await PlayerAction.TakeTransition(areatransition);
if (!trans)
{
Log.DebugFormat("[{0}] Areatransition error.", Name);
}
FollowBot.Leader = null;
return true;
}
}
GlobalLog.Warn($"[TravelToPartyZoneTask] Cant follow the leader in the Labirynt when the lab is already started.");
return false;
}
if (curZone.IsCombatArea && FollowBotSettings.Instance.PortOutThreshold > 0)
{
if (!PortOutStopwatch.IsRunning)
{
GlobalLog.Warn($"[TravelToPartyZoneTask] Party leader is in a diffrerent zone waiting {FollowBotSettings.Instance.PortOutThreshold} seconds to see if it come back.");
PortOutStopwatch.Restart();
await Coroutines.LatencyWait();
return true;
}
if (PortOutStopwatch.IsRunning && PortOutStopwatch.ElapsedMilliseconds >= (FollowBotSettings.Instance.PortOutThreshold * 1000))
{
PortOutStopwatch.Reset();
GlobalLog.Warn($"[TravelToPartyZoneTask] {FollowBotSettings.Instance.PortOutThreshold} seconds elapsed and Party leader is in still a diffrerent zone porting!.");
await PartyHelper.FastGotoPartyZone(leadername);
return true;
}
await Coroutines.LatencyWait();
return true;
}
else
{
await PartyHelper.FastGotoPartyZone(leadername);
await Coroutines.LatencyWait();
}
await Coroutines.LatencyWait();
return true;
}
private async Task<bool> TakePortal()
{
var portal = LokiPoe.ObjectManager.GetObjectsByType<Portal>().FirstOrDefault(x => x.IsTargetable);
if (portal != null)
{
if (portal.Position.Distance(LokiPoe.Me.Position) > 18)
await Move.AtOnce(portal.Position, "Move to portal");
if (await Coroutines.InteractWith<Portal>(portal))
return true;
else
return false;
}
else
{
Log.DebugFormat("[{0}] Failed to find portals.", Name);
return false;
}
}
public async Task<LogicResult> Logic(Logic logic)
{
return LogicResult.Unprovided;
}
public MessageResult Message(Message message)
{
if (message.Id == Events.Messages.AreaChanged)
{
_zoneCheckRetry = 0;
PortOutStopwatch.Reset();
return MessageResult.Processed;
}
if (message.Id == "Enable")
{
_enabled = true;
return MessageResult.Processed;
}
if (message.Id == "Disable")
{
_enabled = false;
return MessageResult.Processed;
}
return MessageResult.Unprocessed;
}
}
}