· 6 years ago · Dec 31, 2019, 12:32 PM
1using FriendlyBot.API.Accounts;
2using FriendlyBot.API.Attributes;
3using FriendlyBot.API.PluginsInterfaces;
4using FriendlyBot.SimpleAPI;
5using FriendlyBot.SimpleAPI.API.Actions;
6using FriendlyBot.SimpleAPI.API.Map;
7using FriendlyBot.SimpleAPI.API.Others;
8using Newtonsoft.Json;
9using System.Collections.Generic;
10using System.IO;
11using System.Linq;
12
13[assembly: Plugin(typeof(Job.JobPlugin), FriendlyBot.API.Enums.PluginType.DofusBotPlugin, "JobPlugin", "Plugin de récolte pour tous les métiers", "TheFrenchCoder")]
14
15namespace Job
16{
17 public class JobPlugin : IUnloadable
18 {
19 private IDofusAccount _dofusAccount;
20
21 private bool _working = false;
22
23 Dictionary<string, string> _dictionary = new Dictionary<string, string>();
24 // _dictionary.Add("product_id", 12);
25
26 private List<int> _ressourcesToGather = new List<int> { 38, 43, 45, 39, 42, 44, 111, 47, 46, 260, 261, 134, 296, 84 }; // 84 C'est les puits le reste paysan
27 private Enums.CardinalDirection _dir;
28
29 private MapAPI MapAPI => _dofusAccount.DofusBotManager.GetPlugin<MapAPI>();
30 private ActionAPI ActionAPI => _dofusAccount.DofusBotManager.GetPlugin<ActionAPI>();
31 private CommandAPI CommandAPI => _dofusAccount.DofusBotManager.GetPlugin<CommandAPI>();
32
33 public JobPlugin(IDofusAccount dofusAccount)
34 {
35 _dofusAccount = dofusAccount;
36 _dofusAccount.DofusBotManager.Logger.Add("Hello " + _dofusAccount.MainCharacter, FriendlyBot.API.Enums.LogType.Normal);
37
38 ActionAPI.FillQueue += OnFillQueue;
39 CommandAPI.OnCmd += OnCmd;
40
41
42
43 //Comment lire les fichiers de dofus :
44 if (!System.IO.Directory.Exists("Dev"))
45 System.IO.Directory.CreateDirectory("Dev");
46 var allInteractivesDatas = _dofusAccount.FriendlyAccount.FriendlyBotManager.D2o.GetDatas<FriendlyBot.API.DofusDatas.Interactive>();
47 /*string data = "";
48 string target = "Dev/ids.txt";
49 foreach (var interactiveData in allInteractivesDatas)
50 {
51 var interactiveText = $"{interactiveData.Id} : {_dofusAccount.FriendlyAccount.FriendlyBotManager.I18n.GetText(interactiveData.NameId)}";
52 data += interactiveText + "\n";
53 _dofusAccount.DofusBotManager.Logger.Add(interactiveText, FriendlyBot.API.Enums.LogType.Critical);
54 }
55
56 System.IO.File.WriteAllText(target, data);
57 */
58 }
59
60 private void OnCmd(string cmd, string[] args)
61 {
62 // TEST DES COORDONEES xD
63 CommandAPI.PrintHelp("\nMap ID Actuel " + MapAPI.Map.Id, "JobPlugin");
64
65 //D2o = donné de jeux, a chaque fois que tu as NameId, DescriptionId ou des truc du genre, tu peux récupéré le nom, la description, etc avec les I18n
66
67
68
69 if (cmd.ToLower() == "job")
70 {
71 if (args.Count() == 0)
72 {
73 //a la place de MapPosition, tu peux mettre tout ce qui se trouve là
74 var laJeRecupToutLesMonstresDuJeu = _dofusAccount.FriendlyAccount.FriendlyBotManager.D2o.GetDatas<FriendlyBot.API.DofusDatas.Monster>();
75 var theMonster = laJeRecupToutLesMonstresDuJeu.First();
76 //pour voir si t'as compris, récupère moi le nomdu monstre :p
77 var monsterName = _dofusAccount.FriendlyAccount.FriendlyBotManager.I18n.GetText(theMonster.NameId); // xD
78 CommandAPI.PrintHelp("\n" + monsterName, "test");
79
80 var result = _dofusAccount.FriendlyAccount.FriendlyBotManager.D2o.GetData<FriendlyBot.API.DofusDatas.MapPosition>(MapAPI.Map.Id);
81 var nomDeLaZoneJimagine = _dofusAccount.FriendlyAccount.FriendlyBotManager.I18n.GetText(result.NameId);
82 CommandAPI.PrintHelp("\nMap ID Actuel " + MapAPI.Map.Id + "\n" + nomDeLaZoneJimagine + "\n" + result.PosX + ";" + result.PosY, "JobPlugin");
83 //PrintPluginHelp();
84 }
85
86 if (args.Count() == 1)
87 {
88 switch (args[0])
89 {
90 case "help":
91 PrintPluginHelp();
92 break;
93 case "start":
94 CommandAPI.PrintHelp("\nLe bot commence le ramassage de ressources", "JobPlugin");
95 _working = true;
96 break;
97 case "stop":
98 CommandAPI.PrintHelp("\nLe bot arrête le ramassage de ressources", "JobPlugin");
99 _working = false;
100 break;
101 }
102
103 }
104 else if (args.Count() > 1)
105 {
106 PrintPluginHelp();
107 }
108 }
109 /*
110 if (cmd.ToLower() == "set")
111 {
112 if (args.Count() == 1)
113 {
114 switch (args[0])
115 {
116 case "n":
117 _dir = Enums.CardinalDirection.North;
118 break;
119 case "w":
120 _dir = Enums.CardinalDirection.West;
121 break;
122 case "s":
123 _dir = Enums.CardinalDirection.South;
124 break;
125 case "e":
126 _dir = Enums.CardinalDirection.East;
127 break;
128 default:
129 CommandAPI.PrintHelp("Please Use .set [N, W, S, E] as lowercase.", "FirstDofusBotSample");
130 break;
131 }
132 if (_dir != Enums.CardinalDirection.Unknown)
133 {
134 ActionAPI.AddWorldAction(() => MapAPI.MoveMap(_dir));
135 }
136 //With the next version of the API
137 //ActionAPI.RefreshQueue();
138 }
139 }*/
140 }
141
142 private void OnFillQueue()
143 {
144 if (!_working)
145 return;
146
147 foreach (var item in MapAPI.UsableElements)
148 {
149 //_dofusAccount.DofusBotManager.Logger.Add($"{item.ElementTypeId} : {_dofusAccount.FriendlyAccount.FriendlyBotManager.I18n.GetText(item.InteractiveData.NameId)}", FriendlyBot.API.Enums.LogType.Critical);
150 //mauvaise nouvelle, j'ai oublié de remettre la property InteractiveData dans SimpleAPI
151
152 if (item.CanUse() && _ressourcesToGather.Contains(item.ElementTypeId))
153 {
154 ActionAPI.AddMapAction(() => item.Use());
155 }
156 }
157
158 //ActionAPI.AddWorldAction(() => MapAPI.MoveMap(FriendlyBot.SimpleAPI.Enums.CardinalDirection.North));
159
160 }
161
162 private void PrintPluginHelp()
163 {
164 CommandAPI.PrintHelp(
165 "\n" +
166 "Prefix : '.job' \n" +
167 "Start the collect of ressources: '$prefix start' \n" +
168 "Stop the collect of ressources: '$prefix stop' \n",
169 "JobPlugin"
170 );
171
172 }
173
174 public void Unload()
175 {
176 ActionAPI.FillQueue -= OnFillQueue;
177 CommandAPI.OnCmd -= OnCmd;
178 _dofusAccount.DofusBotManager.Logger.Add("Bye " + _dofusAccount.MainCharacter, FriendlyBot.API.Enums.LogType.Normal);
179 _dofusAccount = null;
180 }
181
182 public void LoadJson()
183 {
184 using (StreamReader r = new StreamReader("Plugins/Config/JobPlugin.json"))
185 {
186 string json = r.ReadToEnd();
187 List<Path> path = JsonConvert.DeserializeObject<List<Path>>(json);
188 Path path2 = JsonConvert.DeserializeObject<Path>(json);
189 }
190 }
191
192
193 // Permet de récupérer des informations à propos des différents packets échangés
194 [Packet(typeof(FriendlyBot.API.DofusMessages.connection.IHelloConnectMessage))] // Afin de déterminer lequel utiliser, activer le plugin 'Sniffer' avant l'action.
195 void OnHelloConnectMessage(FriendlyBot.API.DofusMessages.connection.IHelloConnectMessage message, FriendlyBot.API.MessageEvent messageEvent)
196 {
197 string output = "From '" + messageEvent.Source + "' to '" + messageEvent.Target + "\n" +
198 "Key '" + message.Key + "' | ProtocolId '" + message.ProtocolId + "\n";
199 System.IO.File.WriteAllText("Dev/connection.IHelloConnectMessage.txt", output);
200
201 LoadJson();
202 }
203 }
204
205 public class Path
206 {
207 /*public Path(string _name, string _location)
208 {
209 public string name { get; set; }
210 public string location { get; set; }
211 }*/
212
213 private string _json;
214 private string _data;
215
216
217 /*public getData()
218 {
219 return JsonConvert.DeserializeObject<Path>(File.ReadAllText("Plugins/Config/JobPlugin.json"));
220
221 //return 1;
222 // Account account = JsonConvert.DeserializeObject<Account>(json);
223 // use https://www.newtonsoft.com/json/help/html/DeserializeObject.htm
224 }*/
225
226 public void LoadJson()
227 {
228 using (StreamReader r = new StreamReader("Plugins/Config/JobPlugin.json"))
229 {
230 string json = r.ReadToEnd();
231 List<Path> path = JsonConvert.DeserializeObject<List<Path>>(json);
232 Path path2 = JsonConvert.DeserializeObject<Path>(json);
233 }
234 }
235
236 }
237
238}