المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : ضيف رنك الوحش في سيرفيرك


محمد ياسر
2019-07-11, 10:03 AM
السلام عليكم ورحمة الله وبركاته
معانا اليوم اضافة رنك الوحش في السيرفير صوره علشان نفهم
عفواً لايمكن عرض الروابط في الإرشيف
اعمل كلاس جديد باسم MsgBossHarmRanking.cs
وحط فيه الاكواد ده
using ProtoBuf;
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Concurrent;
using System.Text;
using VirusX;
using VirusX.Database;
using System.Threading.Tasks;

namespace VirusX.Network.GamePackets
{
public class MsgBossHarmRanking
{
public MsgBossHarmRanking() { }
public MsgBossHarmRankingProto Info;
[ProtoContract]
public class MsgBossHarmRankingProto
{
[ProtoMember(1, IsRequired = true)]
public uint Type;
[ProtoMember(2, IsRequired = true)]
public uint BossUID;
[ProtoMember(3, IsRequired = true)]
public Hunter[] Hunters;
}
[ProtoContract]
public class Hunter
{
[ProtoMember(1, IsRequired = true)]
public uint Rank;
[ProtoMember(2, IsRequired = true)]
public uint ServerID;
[ProtoMember(3, IsRequired = true)]
public uint UID;
[ProtoMember(4, IsRequired = true)]
public string Name;
[ProtoMember(5, IsRequired = true)]
public uint Damage;
}
public bool Read(byte[] packet)
{
using (var memoryStream = new MemoryStream(packet))
{
Info = Serializer.DeserializeWithLengthPrefix<MsgBossHarmRankingProto>(memoryStream, PrefixStyle.Fixed32);
}
return true;
}
public void Ready(VirusX.Client.GameState client)
{
var proto = new MsgBossHarmRankingProto();
proto.BossUID = Info.BossUID;
proto.Type = 1;
/* var scores = client.Map.Entities.Where(i => i.Key == proto.BossUID).FirstOrDefault().Value.MonsterInfo. Score.OrderByDescending(i => i.Value).ToArray();
if (scores.Length != 0)
{
proto.Hunters = new Hunter[scores.Length];
for (int i = 0; i < proto.Hunters.Length; i++)
{
proto.Hunters[i] = new Hunter();
proto.Hunters[i].UID = scores[i].Key.UID;
proto.Hunters[i].Name = scores[i].Key.Name;
proto.Hunters[i].Damage = scores[i].Value;
proto.Hunters[i].ServerID = scores[i].Key.ServerID;
proto.Hunters[i].Rank = (uint)(i + 1);
}
} */
client.Send(Kernel.FinalizeProtoBuf(proto, 1044));
//client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
}
public void Handle(VirusX.Client.GameState client)
{
switch (Info.Type)
{
case 0:
{
var proto = new MsgBossHarmRankingProto();
proto.BossUID = Info.BossUID;
proto.Type = 1;
var scores = client.Map.Entities.Where(i => i.Key == proto.BossUID).FirstOrDefault().Value.MonsterInfo. Score.OrderByDescending(i => i.Value).ToArray();
if (scores.Length != 0)
{
proto.Hunters = new Hunter[scores.Length];
for (int i = 0; i < proto.Hunters.Length; i++)
{
proto.Hunters[i] = new Hunter();
proto.Hunters[i].UID = scores[i].Key.UID;
proto.Hunters[i].Name = scores[i].Key.Name;
proto.Hunters[i].Damage = scores[i].Value;
proto.Hunters[i].ServerID = scores[i].Key.ServerID;
proto.Hunters[i].Rank = (uint)(i + 1);
}
}
client.Send(Kernel.FinalizeProtoBuf(proto, 1044));
break;
}
}
}
}
}

متنساش تغير كلمه VirusX بإسم الكلاس بتاعك
طبعا هايجيب إيرور ف كلمه Score هنقوم رايحين علي MonsterTable.cs و نضيف الكود ده

public Dictionary<Game.Entity, uint> Score = new Dictionary<Game.Entity, uint>();

و بكده الإريور هايروح تمام نضيف بقي الباكت نروح ع الPacketHandler.cs و نضيف ده
#region MsgBossHarmRanking
case 1044:
{
var pkt = new VirusX.Network.GamePackets.MsgBossHarmRanking();
var myPacket = new byte[packet.Length - 8];
for (int i = 0; i < myPacket.Length; i++)
{
myPacket[i] = packet[i];
}
if (pkt.Read(myPacket))
pkt.Handle(client);
break;
}
#endregion

تمام أخر حاجه بقي عشان الرانك يشتغل تمام هنروح ع Monster.cs و نضيف الكود ده
#region Monster Score
if (monster.EntityFlag == EntityFlag.Monster)
{
//if (attacked.Boss > 0)
{
if (monster.MonsterInfo != null)
{
if (monster.MonsterInfo.Score.ContainsKey(client.Enti ty))
monster.MonsterInfo.Score[client.Entity] += obj.Damage;
else monster.MonsterInfo.Score.Add(client.Entity, obj.Damage);

//new VirusX.Network.GamePackets.MsgBossHarmRanking().Re ady(attacker.Owner);
}
}
}
#endregion


الاضافه من الاخ VirusX

MohamedModyAdel
2019-07-11, 11:21 AM
تسلم

karem1q
2023-10-11, 07:35 AM
عاش