MsgBossHarmRanking.cs


SUBMITTED BY: moudixblack

DATE: Aug. 3, 2017, 11:24 p.m.

FORMAT: C#

SIZE: 3.1 kB

HITS: 371

  1. using ProtoBuf;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Collections.Concurrent;
  8. using System.Text;
  9. using LordsRoad;
  10. using LordsRoad.Database;
  11. using System.Threading.Tasks;
  12. namespace LordsRoad.Network.GamePackets
  13. {
  14. public class MsgBossHarmRanking
  15. {
  16. public MsgBossHarmRanking() { }
  17. public MsgBossHarmRankingProto Info;
  18. [ProtoContract]
  19. public class MsgBossHarmRankingProto
  20. {
  21. [ProtoMember(1, IsRequired = true)]
  22. public uint Type;
  23. [ProtoMember(2, IsRequired = true)]
  24. public uint BossUID;
  25. [ProtoMember(3, IsRequired = true)]
  26. public Hunter[] Hunters;
  27. }
  28. [ProtoContract]
  29. public class Hunter
  30. {
  31. [ProtoMember(1, IsRequired = true)]
  32. public uint Rank;
  33. [ProtoMember(2, IsRequired = true)]
  34. public uint ServerID;
  35. [ProtoMember(3, IsRequired = true)]
  36. public uint UID;
  37. [ProtoMember(4, IsRequired = true)]
  38. public string Name;
  39. [ProtoMember(5, IsRequired = true)]
  40. public uint Damage;
  41. }
  42. public bool Read(byte[] packet)
  43. {
  44. using (var memoryStream = new MemoryStream(packet))
  45. {
  46. Info = Serializer.DeserializeWithLengthPrefix<MsgBossHarmRankingProto>(memoryStream, PrefixStyle.Fixed32);
  47. }
  48. return true;
  49. }
  50. public void Handle(Client.GameClient client)
  51. {
  52. switch (Info.Type)
  53. {
  54. case 0:
  55. {
  56. var proto = new MsgBossHarmRankingProto();
  57. proto.BossUID = Info.BossUID;
  58. proto.Type = 1;
  59. var scores = client.Map.Entities.Where(i => i.Key == proto.BossUID).FirstOrDefault().Value.MonsterInfo.Score.OrderByDescending(i => i.Value).ToArray();
  60. if (scores.Length != 0)
  61. {
  62. proto.Hunters = new Hunter[scores.Length];
  63. for (int i = 0; i < proto.Hunters.Length; i++)
  64. {
  65. proto.Hunters[i] = new Hunter();
  66. proto.Hunters[i].UID = scores[i].Key.UID;
  67. proto.Hunters[i].Name = scores[i].Key.Name;
  68. proto.Hunters[i].Damage = scores[i].Value;
  69. proto.Hunters[i].ServerID = scores[i].Key.ServerID;
  70. proto.Hunters[i].Rank = (uint)(i + 1);
  71. }
  72. }
  73. client.Send(Kernel.FinalizeProtoBuf(proto, 1044));
  74. break;
  75. }
  76. }
  77. }
  78. }
  79. }

comments powered by Disqus