Advertisement
XConquer

Activist System by Pezzi

Jan 6th, 2023
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.66 KB | None | 0 0
  1. Creas Nueva Clase Activist
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using COServer.Database;
  8.  
  9. namespace COServer.Game
  10. {
  11. public class Activists
  12. {
  13. public static uint R1Points, R2Points, R3Points, R4Points, R5Points;
  14. public static string R1Name, R2Name, R3Name, R4Name, R5Name;
  15. public static void READ()
  16. {
  17. using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("activists"))
  18. using (var reader = new MySqlReader(cmd))
  19. {
  20. while (reader.Read())
  21. {
  22. R1Points = reader.ReadUInt32("R1Points");
  23. R2Points = reader.ReadUInt32("R2Points");
  24. R3Points = reader.ReadUInt32("R3Points");
  25. R4Points = reader.ReadUInt32("R4Points");
  26. R5Points = reader.ReadUInt32("R5Points");
  27. R1Name = reader.ReadString("R1Name");
  28. R2Name = reader.ReadString("R2Name");
  29. R3Name = reader.ReadString("R3Name");
  30. R4Name = reader.ReadString("R4Name");
  31. R5Name = reader.ReadString("R5Name");
  32. }
  33. }
  34. Console.WriteLine("Systems QuestsServer Players Done!.");
  35. }
  36. public static void RESTART()
  37. {
  38. using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE).Update("activists"))
  39. {
  40. cmd.Set("R1Points", 0).Set("R1Name", "[Empty]")
  41. .Set("R2Points", 0).Set("R2Name", "[Empty]")
  42. .Set("R3Points", 0).Set("R3Name", "[Empty]")
  43. .Set("R4Points", 0).Set("R4Name", "[Empty]")
  44. .Set("R5Points", 0).Set("R5Name", "[Empty]");
  45. cmd.Execute();
  46. }
  47. using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE).Update("entities"))
  48. {
  49. cmd.Set("Activists", 0);
  50. cmd.Execute();
  51. }
  52. Network.GamePackets.Message.WorldMessage("Activists System Restarted.");
  53. }
  54. public static void SAVE()
  55. {
  56. COServer.Database.MySqlCommand cmd = new COServer.Database.MySqlCommand(COServer.Database.MySqlCommandType.UPDATE);
  57. cmd.Update("activists")
  58. .Set("R1Points", R1Points).Set("R1Name", R1Name)
  59. .Set("R2Points", R2Points).Set("R2Name", R2Name)
  60. .Set("R3Points", R3Points).Set("R3Name", R3Name)
  61. .Set("R4Points", R4Points).Set("R4Name", R4Name)
  62. .Set("R5Points", R5Points).Set("R5Name", R5Name);
  63. cmd.Execute();
  64. }
  65. }
  66. }
  67.  
  68.  
  69. ============================================
  70. En PacketHandler.cs
  71.  
  72. Agregamos :
  73.  
  74. #region Activists
  75. public static ConcurrentDictionary<string, byte[]> ActivistsAllowance = new ConcurrentDictionary<string, byte[]>();
  76. public static object ActivistsSyncRoot = new object();
  77. public static void AddActivists(GameClient client)//Caso de error cambias a GameState
  78. {
  79. if (!ActivistsAllowance.ContainsKey(client.Socket.IP))
  80. ActivistsAllowance.Add(client.Socket.IP, new byte[3]);
  81. lock (ActivistsSyncRoot)
  82. {
  83. byte[] data = ActivistsAllowance[client.Socket.IP];
  84. for (int i = 0; i < data.Length; i++)
  85. {
  86. if (data[i] == 0)
  87. {
  88. client.AllowedActivists = true;
  89. client.AllowedActivistsIndex = i;
  90. data[i] = 1;
  91. }
  92. }
  93. }
  94. }
  95. public static void RemoveActivists(GameClient client)
  96. {
  97. if (client.AllowedActivists)
  98. {
  99. lock (ActivistsSyncRoot)
  100. {
  101. byte[] data = ActivistsAllowance[client.Socket.IP];
  102. data[client.AllowedActivistsIndex] = 0;
  103. }
  104. }
  105. }
  106. #endregion
  107.  
  108. Buscamos : void DoLogin(GameClient client) y Agregamos :
  109. AddActivists(client);
  110.  
  111. ==========================================
  112. en GameState // GameClient Agregamos :
  113. public bool AllowedActivists;
  114.  
  115. Buscamos : void Disconnect(bool save = true) y Agregamos :
  116. GeneralData.RemoveActivists(this);//PacketHandler en tu Caso
  117. ==========================================
  118. En World.cs en la Parte de CharactersCallBack Agregamos :
  119. #region Activists
  120. if (DateTime.Now.DayOfWeek != DayOfWeek.Friday)
  121. {
  122. //Check & Set.
  123. uint myPoints = client.Player.Activists;//Player por Entity cualquier cosa..
  124. string myName = client.Player.Name;
  125. //Rank[1]
  126. if (myPoints > Activists.R1Points && myName != Activists.R1Name)
  127. {
  128. if (Activists.R2Points < Activists.R1Points) Activists.R2Name = Activists.R1Name; Activists.R2Points = Activists.R1Points;
  129. Activists.R1Name = myName; Activists.R1Points = myPoints; Activists.SAVE();
  130. }
  131. //Rank[2]
  132. if (myPoints > Activists.R2Points && myName != Activists.R1Name && myName != Activists.R2Name)
  133. {
  134. if (Activists.R3Points < Activists.R2Points) Activists.R3Name = Activists.R2Name; Activists.R3Points = Activists.R2Points;
  135. Activists.R2Name = myName; Activists.R2Points = myPoints; Activists.SAVE();
  136. }
  137. //Rank[3]
  138. if (myPoints > Activists.R3Points && myName != Activists.R1Name && myName != Activists.R2Name && myName != Activists.R3Name)
  139. {
  140. if (Activists.R4Points < Activists.R3Points) Activists.R4Name = Activists.R3Name; Activists.R4Points = Activists.R3Points;
  141. Activists.R3Points = myPoints; Activists.R3Name = myName; Activists.SAVE();
  142. }
  143. //Rank[4]
  144. if (myPoints > Activists.R4Points && myName != Activists.R1Name && myName != Activists.R2Name && myName != Activists.R3Name && myName != Activists.R4Name)
  145. {
  146. if (Activists.R5Points < Activists.R4Points) Activists.R5Name = Activists.R4Name; Activists.R5Points = Activists.R4Points;
  147. Activists.R4Points = myPoints; Activists.R4Name = myName; Activists.SAVE();
  148. }
  149. //Rank[5]
  150. if (myPoints > Activists.R5Points && myName != Activists.R1Name && myName != Activists.R2Name && myName != Activists.R3Name && myName != Activists.R4Name && myName != Activists.R5Name)
  151. {
  152. Activists.R5Points = myPoints; Activists.R5Name = myName; Activists.SAVE();
  153. }
  154. //Update
  155. //1
  156. if (myName == Activists.R1Name && myPoints != Activists.R1Points)
  157. {
  158. Activists.R1Points = myPoints;
  159. }
  160. //2
  161. if (myName == Activists.R2Name && myPoints != Activists.R2Points)
  162. {
  163. Activists.R2Points = myPoints; Activists.SAVE();
  164. }
  165. //3
  166. if (myName == Activists.R3Name && myPoints != Activists.R3Points)
  167. {
  168. Activists.R3Points = myPoints; Activists.SAVE();
  169. }
  170. //4
  171. if (myName == Activists.R4Name && myPoints != Activists.R4Points)
  172. {
  173. Activists.R4Points = myPoints; Activists.SAVE();
  174. }
  175. //5
  176. if (myName == Activists.R5Name && myPoints != Activists.R5Points)
  177. {
  178. Activists.R5Points = myPoints; Activists.SAVE();
  179. }
  180. #region Activists Points
  181. if (client.AllowedActivists)
  182. {
  183. if (Now32 > client.LastActivists.AddMinutes(1))
  184. {
  185. client.Player.Activists += 1;
  186. client.LastActivists = Time32.Now;
  187. }
  188. }
  189. #endregion
  190. }
  191. //1
  192. if (Activists.R2Name == Activists.R1Name) { Activists.R2Name = ""; Activists.R2Points = 0; Activists.SAVE(); }
  193. if (Activists.R3Name == Activists.R1Name) { Activists.R3Name = ""; Activists.R3Points = 0; Activists.SAVE(); }
  194. if (Activists.R4Name == Activists.R1Name) { Activists.R4Name = ""; Activists.R4Points = 0; Activists.SAVE(); }
  195. if (Activists.R5Name == Activists.R1Name) { Activists.R5Name = ""; Activists.R5Points = 0; Activists.SAVE(); }
  196. //2
  197. if (Activists.R3Name == Activists.R2Name) { Activists.R3Name = ""; Activists.R3Points = 0; Activists.SAVE(); }
  198. if (Activists.R4Name == Activists.R2Name) { Activists.R4Name = ""; Activists.R4Points = 0; Activists.SAVE(); }
  199. if (Activists.R5Name == Activists.R2Name) { Activists.R5Name = ""; Activists.R5Points = 0; Activists.SAVE(); }
  200. //3
  201. if (Activists.R4Name == Activists.R3Name) { Activists.R4Name = ""; Activists.R4Points = 0; Activists.SAVE(); }
  202. if (Activists.R5Name == Activists.R3Name) { Activists.R5Name = ""; Activists.R5Points = 0; Activists.SAVE(); }
  203. //4
  204. if (Activists.R5Name == Activists.R4Name) { Activists.R5Name = ""; Activists.R5Points = 0; Activists.SAVE(); }
  205. if (DateTime.Now.DayOfWeek == DayOfWeek.Friday && Now64.Hour == 23 && Now64.Minute == 59 && Now64.Second == 10)
  206. {
  207. #warning IMPORTANTE ACA SE RESETEA !!!
  208. Activists.RESTART();
  209. }
  210. #endregion
  211.  
  212. ==================================================
  213. En Player/Entity.cs Agregamos :
  214. public uint Activists
  215. {
  216. get
  217. {
  218. return _Activists;
  219. }
  220. set
  221. {
  222. if (value <= 0)
  223. value = 0;
  224. _Activists = value;
  225. Database.EntityTable.UpdateActivists(this.Owner);
  226. }
  227. }
  228. ===================================================
  229. En EntityTable Agregamos :
  230. public static void UpdateActivists(Client.GameClient client)
  231. {
  232. UpdateData(client, "Activists", client.Player.Activists);
  233. }
  234.  
  235. Busamos LoadEntity(Client y Agregamos :
  236. client.Player.Activists = reader.ReadUInt32("Activists");
  237. ====================================================
  238. En Npcs.cs al Final o donde quieras agregas el Npc :
  239.  
  240. #region Activists Commander
  241. case 45235:
  242. {
  243. dialog.Avatar(219);
  244. uint myPoints = client.Player.Activists;
  245. string myName = client.Player.Name;
  246. switch (npcRequest.OptionID)
  247. {
  248. case 0:
  249. {
  250. if (DateTime.Now.DayOfWeek == DayOfWeek.Friday && !GuildWar.IsWar)
  251. {
  252. if (myName == Activists.R1Name || myName == Activists.R2Name || myName == Activists.R3Name || myName == Activists.R4Name || myName == Activists.R5Name)
  253. {
  254. dialog.Option("[HOT] Reward.", 4);
  255. dialog.Option("Not~now.", 255);
  256. dialog.Send();
  257. }
  258. else
  259. {
  260. dialog.Text("You're not from our heroes, be much active to get ranked like them");
  261. dialog.Option("I~will.", 255);
  262. dialog.Send();
  263. }
  264. }
  265. else
  266. {
  267. dialog.Text("Hi " + client.Player.Name + ", Commander of the activists here. I can tell you some info if you like. First tell me what you want to know.");
  268. dialog.Option("Who is the first five activists.", 1);
  269. dialog.Option("What about this event.", 2);
  270. dialog.Option("How can I be of 5 activists.", 3);
  271. dialog.Option("Check my points.", 5);
  272. dialog.Option("Bye.", 255);
  273. dialog.Send();
  274. }
  275. break;
  276. }
  277. case 1:
  278. {
  279. dialog.Text("The first five activists Is: \n[1] Is --> (" + Activists.R1Name + ") Points: " + Activists.R1Points + " ,Reward: 100,000,000 CPs\n[2] Is --> (" + Activists.R2Name + ") Points: " + Activists.R2Points + " ,Reward: 90,000,000 CPs.");
  280. dialog.Text("\n[3] Is --> (" + Activists.R3Name + ") Points: " + Activists.R3Points + " ,Reward: 80,000,000 CPs.\n[4] Is --> (" + Activists.R4Name + ") Points: " + Activists.R4Points + " ,Reward: 70,000,000 CPs.\n[5] Is --> (" + Activists.R5Name + ") Points: " + Activists.R5Points + " ,Reward: 60,000,000 CPs.");
  281. dialog.Option("Thanks", 255);
  282. break;
  283. }
  284. case 2:
  285. {
  286. dialog.Text("This event is Consists of 5 ranking, and each rank do choose a player owns much number of activists points.\n");
  287. dialog.Text("Every minute a player gets 1 activists point.\nAll players can get the prize every Friday after GuildWar.");
  288. dialog.Option("Thanks", 255);
  289. break;
  290. }
  291. case 3:
  292. {
  293. dialog.Text("You must be constantly online so you get the maximum number of points to be one of the five ranking.");
  294. dialog.Option("Thanks", 255);
  295. break;
  296. }
  297. case 5:
  298. {
  299. dialog.Text("Hi Mr " + client.Player.Name + ", All of your points is: " + client.Player.Activists + "");
  300. break;
  301. }
  302. case 4:
  303. {
  304. if (myName == Activists.R1Name)
  305. {
  306. dialog.Text("Hi Mr: (" + myName + ") You are rank [1] this week, Your reward is 100,000,000 CPs. Just press claim to get it.");
  307. dialog.Option("Claim.", 6);
  308. dialog.Option("Not~now.", 255);
  309. }
  310. if (myName == Activists.R2Name)
  311. {
  312. dialog.Text("Hi Mr: (" + myName + ") You are rank [2] this week, Your reward is 90,000,000 CPs. Just press claim to get it.");
  313. dialog.Option("Claim.", 6);
  314. dialog.Option("Not~now.", 255);
  315. }
  316. if (myName == Activists.R3Name)
  317. {
  318. dialog.Text("Hi Mr: (" + myName + ") You are rank [3] this week, Your reward is 80,000,000 CPs. Just press claim to get it.");
  319. dialog.Option("Claim.", 6);
  320. dialog.Option("Not~now.", 255);
  321. }
  322. if (myName == Activists.R4Name)
  323. {
  324. dialog.Text("Hi Mr: (" + myName + ") You are rank [4] this week, Your reward is 70,000,000 CPs. Just press claim to get it.");
  325. dialog.Option("Claim.", 6);
  326. dialog.Option("Not~now.", 255);
  327. }
  328. if (myName == Activists.R5Name)
  329. {
  330. dialog.Text("Hi Mr: (" + myName + ") You are rank [5] this week, Your reward is 60,000,000 CPs. Just press claim to get it.");
  331. dialog.Option("Claim.", 6);
  332. dialog.Option("Not~now.", 255);
  333. }
  334. break;
  335. }
  336. case 6:
  337. {
  338. if (myName == Activists.R1Name)
  339. {
  340. Activists.R1Name = "[Its Done.]";
  341. Activists.R1Points = 0;
  342. client.Player.ConquerPoints += 5000;
  343. client.Player.AddTopStatus(Update.Flags.WeeklyPKChampion, DateTime.Now.AddDays(7));
  344. client.Player.AddTopStatus(Update.Flags.MonthlyPKChampion, DateTime.Now.AddDays(7));
  345. Message.WorldMessage("Congratulations " + myName + " He received his prize from Activists Event this weak.");
  346. }
  347. if (myName == Activists.R2Name)
  348. {
  349. Activists.R2Name = "[Its Done.]";
  350. Activists.R2Points = 0;
  351. client.Player.ConquerPoints += 5000;
  352. Message.WorldMessage("Congratulations " + myName + " He received his prize from Activists Event this weak.");
  353. }
  354. if (myName == Activists.R3Name)
  355. {
  356. Activists.R3Name = "[Its Done.]";
  357. Activists.R3Points = 0;
  358. client.Player.ConquerPoints += 5000;
  359. Message.WorldMessage("Congratulations " + myName + " He received his prize from Activists Event this weak.");
  360. }
  361. if (myName == Activists.R4Name)
  362. {
  363. Activists.R4Name = "[Its Done.]";
  364. Activists.R4Points = 0;
  365. client.Player.ConquerPoints += 5000;
  366. Message.WorldMessage("Congratulations " + myName + " He received his prize from Activists Event this weak.");
  367. }
  368. if (myName == Activists.R5Name)
  369. {
  370. Activists.R5Name = "[Its Done.]";
  371. Activists.R5Points = 0;
  372. client.Player.ConquerPoints += 5000;
  373. Message.WorldMessage("Congratulations " + myName + " He received his prize from Activists Event this weak.");
  374. }
  375. break;
  376. }
  377. }
  378. break;
  379. }
  380. #endregion
  381. =========================
  382. En Navicat -> Console Pegas el siguiente code
  383. -- ----------------------------
  384. -- Table structure for activists
  385. -- ----------------------------
  386. DROP TABLE IF EXISTS `activists`;
  387. CREATE TABLE `activists` (
  388. `R1Name` varchar(255) NOT NULL default '',
  389. `R1Points` bigint(16) NOT NULL default '0',
  390. `R2Name` varchar(255) default NULL,
  391. `R2Points` bigint(16) NOT NULL default '0',
  392. `R3Name` varchar(255) default NULL,
  393. `R3Points` bigint(16) NOT NULL default '0',
  394. `R4Name` varchar(255) default NULL,
  395. `R4Points` bigint(16) NOT NULL default '0',
  396. `R5Name` varchar(255) default NULL,
  397. `R5Points` bigint(16) NOT NULL default '0',
  398. PRIMARY KEY (`R1Name`)
  399. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  400.  
  401.  
  402. En entities
  403. activist bigint 255
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement