Advertisement
Guest User

Untitled

a guest
Apr 9th, 2019
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.05 KB | None | 0 0
  1.  
  2. using ProtoBuf;
  3. using System;
  4. using System.Runtime.InteropServices;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Collections.Concurrent;
  9. using System.Text;
  10. using VirusX;
  11. using VirusX.Database;
  12. using System.Threading.Tasks;
  13.  
  14. namespace VirusX.Network.GamePackets
  15. {
  16.     public class MsgBossHarmRanking
  17.     {
  18.         public MsgBossHarmRanking() { }
  19.         public MsgBossHarmRankingProto Info;
  20.         [ProtoContract]
  21.         public class MsgBossHarmRankingProto
  22.         {
  23.             [ProtoMember(1, IsRequired = true)]
  24.             public uint Type;
  25.             [ProtoMember(2, IsRequired = true)]
  26.             public uint BossUID;
  27.             [ProtoMember(3, IsRequired = true)]
  28.             public Hunter[] Hunters;
  29.         }
  30.         [ProtoContract]
  31.         public class Hunter
  32.         {
  33.             [ProtoMember(1, IsRequired = true)]
  34.             public uint Rank;
  35.             [ProtoMember(2, IsRequired = true)]
  36.             public uint ServerID;
  37.             [ProtoMember(3, IsRequired = true)]
  38.             public uint UID;
  39.             [ProtoMember(4, IsRequired = true)]
  40.             public string Name;
  41.             [ProtoMember(5, IsRequired = true)]
  42.             public uint Damage;
  43.         }
  44.         public bool Read(byte[] packet)
  45.         {
  46.             using (var memoryStream = new MemoryStream(packet))
  47.             {
  48.                 Info = Serializer.DeserializeWithLengthPrefix<MsgBossHarmRankingProto>(memoryStream, PrefixStyle.Fixed32);
  49.             }
  50.             return true;
  51.         }
  52.         public void Ready(VirusX.Client.GameState client)
  53.         {
  54.             var proto = new MsgBossHarmRankingProto();
  55.             proto.BossUID = Info.BossUID;
  56.             proto.Type = 1;
  57.             /* var scores = client.Map.Entities.Where(i => i.Key == proto.BossUID).FirstOrDefault().Value.MonsterInfo.Score.OrderByDescending(i => i.Value).ToArray();
  58.              if (scores.Length != 0)
  59.              {
  60.                  proto.Hunters = new Hunter[scores.Length];
  61.                  for (int i = 0; i < proto.Hunters.Length; i++)
  62.                  {
  63.                      proto.Hunters[i] = new Hunter();
  64.                      proto.Hunters[i].UID = scores[i].Key.UID;
  65.                      proto.Hunters[i].Name = scores[i].Key.Name;
  66.                      proto.Hunters[i].Damage = scores[i].Value;
  67.                      proto.Hunters[i].ServerID = scores[i].Key.ServerID;
  68.                      proto.Hunters[i].Rank = (uint)(i + 1);
  69.                  }
  70.              } */
  71.             client.Send(Kernel.FinalizeProtoBuf(proto, 1044));
  72.             //client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
  73.         }
  74.         public void Handle(VirusX.Client.GameState client)
  75.         {
  76.             switch (Info.Type)
  77.             {
  78.                 case 0:
  79.                     {
  80.                         var proto = new MsgBossHarmRankingProto();
  81.                         proto.BossUID = Info.BossUID;
  82.                         proto.Type = 1;
  83.                         var scores = client.Map.Entities.Where(i => i.Key == proto.BossUID).FirstOrDefault().Value.MonsterInfo.Score.OrderByDescending(i => i.Value).ToArray();
  84.                         if (scores.Length != 0)
  85.                         {
  86.                             proto.Hunters = new Hunter[scores.Length];
  87.                             for (int i = 0; i < proto.Hunters.Length; i++)
  88.                             {
  89.                                 proto.Hunters[i] = new Hunter();
  90.                                 proto.Hunters[i].UID = scores[i].Key.UID;
  91.                                 proto.Hunters[i].Name = scores[i].Key.Name;
  92.                                 proto.Hunters[i].Damage = scores[i].Value;
  93.                                 proto.Hunters[i].ServerID = scores[i].Key.ServerID;
  94.                                 proto.Hunters[i].Rank = (uint)(i + 1);
  95.                             }
  96.                         }
  97.                         client.Send(Kernel.FinalizeProtoBuf(proto, 1044));
  98.                         break;
  99.                     }
  100.             }
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement