I am currently working on a server (Patch 5017), and have been doing a lot of research on other sources etc. Every source that I have looked at, they seem to add the list of targets to a dictionary, then using that dictionary, they generate a skill packet. Am I missing something involving garbage collection, or just the performance of buffer.blockcopy, or could you actually do it this way:
I just find it hard to believe nobody else has thought of this (at least thats released a source to the public)
Code:
public class SkillUsePacket
{
private Writer Writer;
private int offset = 20;
private int TargetCount;
public SkillUsePacket(uint AttackerUID)
{
this.Writer = new Writer(628);
this.Writer.Fill((ushort)1105, 2);
this.Writer.Fill(AttackerUID, 4);
}
public ushort AimX { set { Writer.Fill(value, 8); } }
public ushort AimY { set { Writer.Fill(value, 10); } }
public ushort SkillID { set { Writer.Fill(value, 12); } }
public byte SkillLevel { set { Writer.Fill(value, 14); } }
public void AddTarget(uint UniqueID, uint Damage)
{
Writer.Fill(UniqueID, offset);
offset += 4;
Writer.Fill(Damage, offset);
offset += 8;
TargetCount++;
}
public byte[] ToBytes
{
get
{
int Len = 28 + (TargetCount * 12);
Writer.Fill((ushort)Len, 0);
Writer.Fill(TargetCount, 16);
byte[] newData = new byte[Len];
Buffer.BlockCopy(Writer.Bytes, 0, newData, 0, Len);
return newData;
}
}
}