示例#1
0
        public static void HandlePacket(byte packetID, Packet p)
        {
            switch (packetID)
            {
                case 0:
                    string pName = p.ReadString();
                    byte id = p.ReadByte();

                    int posX = p.ReadInt();
                    int posY = p.ReadInt();
                    if (OtherPlayers.Where(pl => pl.PlayerID == id).Count() > 0) return;
                    if (ThePlayer.PlayerEntity.PlayerID != id)
                    {
                        ConsoleManager.Log("New player: " + pName + " id: " + id + " x: " + posX + " y: " + posY);
                        OtherPlayers.Add(new PlayerEntity(new Vector2(posX, posY), id, pName));
                    }
                    else
                    {
                        ThePlayer.PlayerEntity.EntityPosition = new Vector2(posX, posY);
                    }
                    break;
                case 1:
                    HandleGameEvent(p.ReadByte(), p);
                    break;

                case 2:
                    byte type = p.ReadByte();
                    byte ID = p.ReadByte();
                    short X = p.ReadShort();
                    short Y = p.ReadShort();
                    short angle = p.ReadShort();
                    byte strength = p.ReadByte();
                    byte owner = p.ReadByte();
                    GameProjectiles.Add(new ProjectileArrow(new Vector2(X, Y), angle, owner, strength) { ProjectileID = ID });
                    break;

                case 3:
                    byte toRemove = p.ReadByte();
                    EntityProjectile proj = null;
                    foreach (EntityProjectile projectile in GameProjectiles)
                    {
                        if (projectile.ProjectileID == toRemove)
                        {
                            proj = projectile;
                            break;
                        }
                    }
                    if (proj != null) GameProjectiles.Remove(proj);
                    break;

                case 6:
                    byte playerID = p.ReadByte();
                    PlayerEntity player = PlayerOfID(playerID);
                    if (player == null) break;
                    player.OnAttack();
                    break;

                case 7:
                    playerID = p.ReadByte();
                    byte itemID = p.ReadByte();
                    player = PlayerOfID(playerID);
                    if (player == null) break;
                    player.EquippedItem = Item.GetItem(itemID);

                    break;

                case 8:
                    Vector2 pos = p.ReadVectorS();
                    Vector2 velocity = p.ReadVectorS();
                    short droppedID = p.ReadShort();
                    itemID = p.ReadByte();
                    EntityDroppedItem item = DroppedItemOfID(droppedID);
                    if (item != null)
                        break;

                    item = new EntityDroppedItem(pos, velocity, itemID, droppedID);
                    DroppedItems.Add(item);
                    break;

                case 9:
                    droppedID = p.ReadShort();
                    byte pickerUpper = p.ReadByte();
                    player = PlayerOfID(pickerUpper);
                    item = DroppedItemOfID(droppedID);
                    if (item == null || player == null) break;
                    item.MovingTowards = player;
                    item.DroppedItemID = -1;
                    item.Incomplete = false;
                    break;

                case 10:
                    droppedID = p.ReadShort();
                    item = DroppedItemOfID(droppedID);
                    if (item != null)
                        DroppedItems.Remove(item);
                    break;

                case 12:
                    droppedID = p.ReadShort();
                    pickerUpper = p.ReadByte();
                    player = PlayerOfID(pickerUpper);
                    item = DroppedItemOfID(droppedID);
                    if (item == null || player == null) break;
                    item.MovingTowards = player;
                    item.Incomplete = true;
                    break;

                case 14:
                    string eventName = p.ReadString();
                    GameMode.OnGameModeEvent(eventName, p);
                    break;

                case 200:
                    PlayerUpdating(p);
                    break;

                case 255:
                    id = p.ReadByte();
                    ConsoleManager.Log("My id is " + id);
                    ThePlayer.PlayerEntity = new PlayerEntity(new Vector2(0, 0), id, ConsoleManager.GetVariableValue("player_name"));
                    break;
            }
        }