reduce code duplication

This commit is contained in:
UnknownShadow200 2017-04-19 17:22:54 +10:00
parent 2fe118d0ff
commit 670449e4e1
2 changed files with 61 additions and 61 deletions

View File

@ -80,11 +80,7 @@ namespace MCGalaxy {
TabList.Add(dst, p, id);
if (!Server.zombie.Running || !p.Game.Infected) {
string col = GetSupportedCol(dst, p.color);
if (dst.hasExtList) {
dst.SendExtAddEntity2(id, p.SkinName, col + p.truename + possession, p.Model, pos, rot);
} else {
dst.SendSpawn(id, col + p.truename + possession, p.Model, pos, rot);
}
Spawn(dst, id, p.SkinName, col + p.truename + possession, p.Model, p.Pos, p.Rot);
return;
}
@ -93,12 +89,8 @@ namespace MCGalaxy {
name = ZombieGameProps.ZombieName; skinName = name;
}
string model = id == Entities.SelfID ? p.Model : ZombieGameProps.ZombieModel;
if (dst.hasExtList) {
dst.SendExtAddEntity2(id, skinName, Colors.red + name + possession, model, pos, rot);
} else {
dst.SendSpawn(id, Colors.red + name + possession, model, pos, rot);
}
string model = p == dst ? p.Model : ZombieGameProps.ZombieModel;
Spawn(dst, id, skinName, Colors.red + name + possession, model, p.Pos, p.Rot);
}
/// <summary> Spawns this player to all other players, and spawns all others players to this player. </summary>
@ -139,15 +131,26 @@ namespace MCGalaxy {
if (b.DisplayName.CaselessEq("empty")) name = "";
string skin = Chat.Format(b.SkinName, dst, true, true, false);
if (dst.hasExtList) {
dst.SendExtAddEntity2(b.id, skin, name, b.Model, b.Pos, b.Rot);
} else {
dst.SendSpawn(b.id, name, b.Model, b.Pos, b.Rot);
}
Spawn(dst, b.id, skin, name, b.Model, b.Pos, b.Rot);
if (Server.TablistBots)
TabList.Add(dst, b);
}
static void Spawn(Player dst, byte id, string skin, string name,
string model, Position pos, Orientation rot) {
if (dst.hasExtList) {
dst.SendExtAddEntity2(id, skin, name, pos, rot);
} else {
dst.SendSpawn(id, name, pos, rot);
}
if (dst.hasChangeModel) dst.Send(Packet.ChangeModel(id, model, dst.hasCP437));
if (dst.HasCpeExt(CpeExt.EntityProperty)) {
dst.Send(Packet.EntityProperty(id, EntityProp.RotX, rot.RotX));
dst.Send(Packet.EntityProperty(id, EntityProp.RotZ, rot.RotZ));
}
}
internal static void Despawn(Player dst, byte id) {
dst.SendRaw(Opcode.RemoveEntity, id);
if (!Server.TablistGlobal)

View File

@ -333,12 +333,11 @@ namespace MCGalaxy {
/// <summary> Sends a packet indicating an entity was spawned in the current map
/// at the given absolute position + coordinates </summary>
public void SendSpawn(byte id, string name, string model, Position pos, Orientation rot) {
public void SendSpawn(byte id, string name, Position pos, Orientation rot) {
// NOTE: Fix for standard clients
if (id == Entities.SelfID) pos.Y -= 22;
Send(Packet.AddEntity(id, name, pos, rot, hasCP437));
if (hasChangeModel) Send(Packet.ChangeModel(id, model, hasCP437));
}
/// <summary> Sends a packet indicating an absolute position + orientation change for an enity. </summary>
@ -394,18 +393,16 @@ namespace MCGalaxy {
Send(buffer);
}
public void SendExtAddEntity(byte id, string name, string displayName, string model) {
public void SendExtAddEntity(byte id, string name, string displayName) {
Send(Packet.ExtAddEntity(id, name, displayName, hasCP437));
if (hasChangeModel) Send(Packet.ChangeModel(id, model, hasCP437));
}
public void SendExtAddEntity2(byte id, string skinName, string displayName, string model,
public void SendExtAddEntity2(byte id, string skinName, string displayName,
Position pos, Orientation rot) {
// NOTE: Fix for standard clients
if (id == Entities.SelfID) pos.Y -= 22;
Send(Packet.ExtAddEntity2(id, skinName, displayName, pos, rot, hasCP437));
if (hasChangeModel) Send(Packet.ChangeModel(id, model, hasCP437));
}
public void SendExtAddPlayerName(byte id, string listName, string displayName, string grp, byte grpRank) {