-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTutorial.cs
235 lines (231 loc) · 11.9 KB
/
Tutorial.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
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
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Google.Protobuf;
using Google.Protobuf.Collections;
using Newtonsoft.Json.Linq;
using POGOLib.Official.Net;
using POGOLib.Official.Util;
using POGOProtos.Data.Player;
using POGOProtos.Enums;
using POGOProtos.Map.Fort;
using POGOProtos.Networking.Requests;
using POGOProtos.Networking.Requests.Messages;
using POGOProtos.Networking.Responses;
using Troschuetz.Random;
namespace Entropy
{
public class Tutorial
{
public static async Task<RepeatedField<TutorialState>> GetTutorialState(Session session)
{
// Form1.Logger.Debug($"Checking tutorial state for {session.Player.Data.Username}.");
// Get player locale based on current location
var request = await session.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.GetPlayer,
RequestMessage = new GetPlayerMessage
{
PlayerLocale = new GetPlayerMessage.Types.PlayerLocale
{
Country = "US",
Language = "en",
Timezone = "America/New_York"
}
}.ToByteString()
});
var response = GetPlayerResponse.Parser.ParseFrom(request);
return response.PlayerData.TutorialState;
}
public static async Task CompleteTutorial(Session session, RepeatedField<TutorialState> tutorialState)
{
var random = new TRandom();
if (!tutorialState.Contains(0))
{
await Task.Delay(random.Next(1000, 5000));
var mtcReq = await session.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.MarkTutorialComplete,
RequestMessage = new MarkTutorialCompleteMessage
{
SendMarketingEmails = false,
SendPushNotifications = false
}.ToByteString()
});
var mtcResp = MarkTutorialCompleteResponse.Parser.ParseFrom(mtcReq);
// Form1.Logger.Debug($"Sending 0 tutorials_completed for {session.Player.Data.Username}.");
}
if (!tutorialState.Contains((TutorialState)1))
{
await Task.Delay(random.Next(5000, 12000));
var caReq = await session.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.SetAvatar,
RequestMessage = new SetAvatarMessage
{
PlayerAvatar = new PlayerAvatar
{
Hair = random.Next(1, 5),
Shirt = random.Next(1, 3),
Pants = random.Next(1, 2),
Shoes = random.Next(1, 6),
Avatar = random.Next(0, 1),
Eyes = random.Next(1, 4),
Backpack = random.Next(1, 5)
}
}.ToByteString()
});
var caResp = SetAvatarResponse.Parser.ParseFrom(caReq);
// Form1.Logger.Debug($"Sending set random player character request for ${session.Player.Data.Username}.");
}
await Task.Delay(random.Next(500, 600));
var gppr = await session.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.GetPlayerProfile,
RequestMessage = new GetPlayerProfileMessage
{
PlayerName = session.Player.Data.Username
}.ToByteString()
});
var gppre = GetPlayerProfileResponse.Parser.ParseFrom(gppr);
// Form1.Logger.Debug($"Fetching player profile for {session.Player.Data.Username}...");
if (!tutorialState.Contains((TutorialState)3))
{
await Task.Delay(random.Next(1000, 1500));
var starters = new[] { PokemonId.Bulbasaur, PokemonId.Charmander, PokemonId.Squirtle };
var starter = starters[random.Next(0, starters.Length)];
var streq = await session.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.EncounterTutorialComplete,
RequestMessage = new EncounterTutorialCompleteMessage
{
PokemonId = starter
}.ToByteString()
});
// Form1.Logger.Debug($"Catching the starter for {session.Player.Data.Username}. (Chose {starter.ToString()})");
var gpr = await session.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.GetPlayer,
RequestMessage = new GetPlayerMessage
{
PlayerLocale = new GetPlayerMessage.Types.PlayerLocale
{
Country = "US",
Language = "en",
Timezone = "America/New_York"
}
}.ToByteString()
});
var gpre = GetPlayerResponse.Parser.ParseFrom(gpr);
}
if (!tutorialState.Contains((TutorialState)4))
{
await Task.Delay(random.Next(5000, 12000));
var ccreq = await session.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.ClaimCodename,
RequestMessage = new ClaimCodenameMessage
{
Codename = session.Player.Data.Username
}.ToByteString()
});
var ccres = ClaimCodenameResponse.Parser.ParseFrom(ccreq);
// Form1.Logger.Debug($"Claimed codename for {session.Player.Data.Username}.");
var gpr = await session.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.GetPlayer,
RequestMessage = new GetPlayerMessage
{
PlayerLocale = new GetPlayerMessage.Types.PlayerLocale
{
Country = "US",
Language = "en",
Timezone = "America/New_York"
}
}.ToByteString()
});
var gpre = GetPlayerResponse.Parser.ParseFrom(gpr);
}
var firstOrDefault = session.Player.Inventory.InventoryItems.Select(i => i.InventoryItemData?.PokemonData).FirstOrDefault(p => p != null && p.PokemonId > 0);
if (firstOrDefault != null)
{
var starterId = firstOrDefault.Id;
if (starterId != null)
{
var budreq = await session.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.SetBuddyPokemon,
RequestMessage = new SetBuddyPokemonMessage
{
PokemonId = starterId
}.ToByteString()
});
var budres = SetBuddyPokemonResponse.Parser.ParseFrom(budreq);
// Form1.Logger.Debug($"Setting buddy pokemon for {session.Player.Data.Username}.");
}
}
// Form1.Logger.Info($"And {session.Player.Data.Username} is done. Waiting a sec to avoid throttle.");
await Task.Delay(random.Next(2000, 4000));
}
public static async Task TutorialPokestopSpin(Session session)
{
var playerLevel = session.Player.Stats.Level;
if (playerLevel > 1)
{
// Form1.Logger.Debug($"No need to spin a PokeStop. {session.Player.Data.Username} is already level {playerLevel}.");
}
else
{
// Form1.Logger.Debug($"Spinning PokeStop for account {session.Player.Data.Username}.");
foreach (var fortData in session.Map.GetFortsSortedByDistance(f => f.Type == FortType.Checkpoint && f.LureInfo != null))
{
session.Player.SetCoordinates(fortData.Latitude, fortData.Longitude);
if (fortData.CooldownCompleteTimestampMs <= TimeUtil.GetCurrentTimestampInMilliseconds())
{
var playerDistance = session.Player.DistanceTo(fortData.Latitude, fortData.Longitude);
if (playerDistance <= session.GlobalSettings.FortSettings.InteractionRangeMeters)
{
var fortSearchResponseBytestring = await session.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.FortSearch,
RequestMessage = new FortSearchMessage
{
FortId = fortData.Id,
FortLatitude = fortData.Latitude,
FortLongitude = fortData.Longitude,
PlayerLatitude = session.Player.Latitude,
PlayerLongitude = session.Player.Longitude
}.ToByteString()
});
var fortSearchResponse = FortSearchResponse.Parser.ParseFrom(fortSearchResponseBytestring);
switch (fortSearchResponse.Result)
{
case FortSearchResponse.Types.Result.NoResultSet:
// Form1.Logger.Debug($"{session.Player.Data.Username}: Unknown error.");
break;
case FortSearchResponse.Types.Result.Success:
// Form1.Logger.Debug($"{session.Player.Data.Username}: Spun pokestop successfully. {session.Player.Data.Username} is now level {session.Player.Stats.Level}.");
break;
case FortSearchResponse.Types.Result.OutOfRange:
// Form1.Logger.Debug($"{session.Player.Data.Username}: Out of range.");
break;
case FortSearchResponse.Types.Result.InCooldownPeriod:
// Form1.Logger.Debug($"{session.Player.Data.Username}: In cooldown.");
break;
case FortSearchResponse.Types.Result.InventoryFull:
// Form1.Logger.Debug($"{session.Player.Data.Username}: Inventory full.");
break;
case FortSearchResponse.Types.Result.ExceededDailyLimit:
// Form1.Logger.Debug($"{session.Player.Data.Username}: Exceeded daily pokestop limit.");
break;
default:
throw new ArgumentOutOfRangeException(nameof(fortSearchResponse));
}
}
}
}
}
}
}
}