Наследование: MiningGameServer.Entities.ServerEntityMoveable
Пример #1
0
        public override void OnBlockPlaced(int x, int y, bool notify, NetworkPlayer placer = null)
        {
            if (placer == null)
                return;

            int realX = x * GameServer.BlockSize;
            int realY = y * GameServer.BlockSize;
            int diffX = (int)(placer.EntityPosition.X - realX);
            int diffY = (int)(placer.EntityPosition.Y - realY);

            if (Math.Abs(diffX) > Math.Abs(diffY))
            {
                if (diffX < 0)
                    GameServer.SetBlockMetaData(x, y, (byte)PistonFlags.Left);
                else
                    GameServer.SetBlockMetaData(x, y, (byte)PistonFlags.Right);
            }
            else
            {
                if (diffY < 0)
                    GameServer.SetBlockMetaData(x, y, (byte)PistonFlags.Up);
                else
                    GameServer.SetBlockMetaData(x, y, (byte)PistonFlags.Down);
            }

            base.OnBlockPlaced(x, y, notify);
        }
        public void HandlePacket(Packet p, NetworkPlayer player)
        {
            byte num = p.ReadByte();
            switch (num)
            {
                case 0:
                    string name = p.ReadString();
                    player.PlayerName = name;
                    Packet255SCConnectionFirmed packet2 = new Packet255SCConnectionFirmed(player.PlayerID);
                    SendPacket(packet2, player.NetConnection);
                    foreach (NetworkPlayer pl in GameServer.NetworkPlayers)
                    {
                        var packet = new Packet0SCPlayerConnect(pl.PlayerName, pl.PlayerID, pl.EntityPosition);
                        SendPacket(packet, player.NetConnection);

                        if (pl == player) continue;

                        packet = new Packet0SCPlayerConnect(player.PlayerName,
                                                            player.PlayerID, player.EntityPosition);
                        SendPacket(packet, pl.NetConnection);
                    }
                    ServerConsole.Log("New player \"" + name + "\" connected.");
                    break;
                //A game event, JC!
                case 1:
                    byte eventID = p.ReadByte();
                    GameServer.HandleGameEvent(eventID, p, player);
                    break;

                case 2:
                    int pX = p.ReadInt();
                    int pY = p.ReadInt();
                    GameServer.SetBlock(pX, pY, 0, true, 0);
                    break;

                case 4:
                    byte flags = p.ReadByte();
                    if (player.MovementFlags != flags)
                    {
                        player.UpdateMask |= (int)PlayerUpdateFlags.Player_Update;
                        player.UpdateMask |= (int)PlayerUpdateFlags.Player_Movement_Flags;
                    }
                    player.MovementFlags = flags;
                    break;

                case 5:
                    flags = p.ReadByte();
                    float angle = p.ReadShort().DToR();
                    if (player.MovementFlags != flags || angle != player.PlayerAimAngle)
                    {
                        player.UpdateMask |= (int)PlayerUpdateFlags.Player_Update;
                        player.UpdateMask |= (int)PlayerUpdateFlags.Player_Movement_Flags;
                    }
                    player.MovementFlags = flags;
                    player.PlayerAimAngle = angle;
                    break;
            }
        }
Пример #3
0
 public override void OnBlockUsed(int x, int y, NetworkPlayer user)
 {
     byte metaData = GameServer.GetBlockAt(x, y).MetaData;
     bool above = GameServer.GetBlockAt(x, y - 1).ID == 4;
     bool open = metaData.BitSet(1);
     bool isRedTeam = metaData.BitSet(0);
     int teamRequired = isRedTeam ? 1 : 0;
     if (user.PlayerTeam != teamRequired) return;
     if (open)
     {
         metaData = metaData.SetBit(1, false);
         GameServer.SetBlockMetaData(x, y, metaData);
         GameServer.SetBlockMetaData(x, y - (above ? 1 : -1), metaData);
         return;
     }
     metaData = metaData.SetBit(1, true);
     GameServer.SetBlockMetaData(x, y, metaData);
     GameServer.SetBlockMetaData(x, y - (above ? 1 : -1), metaData);
 }
Пример #4
0
 public virtual void OnItemUsed(int x, int y, NetworkPlayer user)
 {
     short block = GameServer.GetBlockAt(x, y).ID;
     if (block == 0 && _blockID != 0)
     {
         GameServer.SetBlock(user, x, y, _blockID);
         user.Inventory.RemoveItemsAtSlot(user.Inventory.PlayerInventorySelected, _itemID, 1);
     }
 }
 public void HandleClient(NetworkPlayer player)
 {
 }
        public void Update()
        {
            if (NetServer == null) return;
            NetIncomingMessage msg;
            while ((msg = NetServer.ReadMessage()) != null)
            {
                switch (msg.MessageType)
                {
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.ErrorMessage:
                        break;
                    case NetIncomingMessageType.StatusChanged:
                        NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
                        if (status == NetConnectionStatus.Connected)
                        {
                            //
                            // A new player just connected!
                            //
                            NetworkPlayer player = new NetworkPlayer((byte)++NumNetworkPlayers, msg.SenderConnection, new Vector2(100, 70), "");
                            GameServer.NetworkPlayers.Add(player);
                            HandleClient(player);
                        }

                        if (status == NetConnectionStatus.Disconnected)
                        {
                            NetworkPlayer pl2 = GameServer.NetworkPlayers.Where(pl => pl.NetConnection.RemoteUniqueIdentifier == msg.SenderConnection.RemoteUniqueIdentifier).FirstOrDefault();
                            GameServer.NetworkPlayers.Remove(pl2);
                            Packet1SCGameEvent p2 = new Packet1SCGameEvent(GameServer.GameEvents.Player_Leave, pl2.PlayerID);
                            SendPacket(p2);
                            Packet1SCGameEvent p3 = new Packet1SCGameEvent(GameServer.GameEvents.Player_Chat, (byte)0, false, "Player " + pl2.PlayerName + " has left the game.");
                            SendPacket(p3);

                            ServerConsole.Log("Player " + pl2.PlayerName + " has disconnected.");
                        }

                        break;
                    case NetIncomingMessageType.Data:
                        NetworkPlayer p = GameServer.NetworkPlayers.Where(pl => pl.NetConnection == msg.SenderConnection).FirstOrDefault();
                        HandlePacket(new Packet(msg.m_data), p);
                        break;
                }
                NetServer.Recycle(msg);
            }
        }
Пример #7
0
        public override void OnBlockUsed(int x, int y, NetworkPlayer user)
        {
            byte flags = GameServer.GetBlockAt(x, y).MetaData;

            PistonFlags dir = PistonFlags.Left;
            if ((flags & (int)PistonFlags.Right) != 0) dir = PistonFlags.Right;
            if ((flags & (int)PistonFlags.Up) != 0) dir = PistonFlags.Up;
            if ((flags & (int)PistonFlags.Down) != 0) dir = PistonFlags.Down;

            if ((flags & (int)PistonFlags.Open) != 0)
            {
                flags ^= (int)PistonFlags.Open;
                ClosePiston(x, y, dir);
            }
            else
            {
                if (OpenPiston(x, y, dir))
                    flags |= (int)PistonFlags.Open;
            }
            GameServer.SetBlockMetaData(x, y, flags);
        }
Пример #8
0
        public static void SetBlock(NetworkPlayer placer, int x, int y, short blockID, bool notify = true, byte metaData = 0)
        {
            if (x < WorldSizeX && y < WorldSizeY && blockID >= 0)
            {
                Block block = GetBlockAt(x, y).Block;
                WorldBlocks[x, y].ID = blockID;
                if (blockID != block.GetBlockID())
                    block.OnBlockRemoved(x, y);
                WorldBlocks[x, y].MetaData = metaData;

                if (blockID != 0)
                    Block.GetBlock(blockID).OnBlockPlaced(x, y, notify, placer);

                //Packet1SCGameEvent pack = new Packet1SCGameEvent((byte)GameEvents.Block_Set, x, y, blockID, metaData);
                // Main.serverNetworkManager.SendPacket(pack);
            }
        }
Пример #9
0
        public static void HandleGameEvent(byte eventID, Packet p, NetworkPlayer player)
        {
            switch ((GameEvents)eventID)
            {
                case GameEvents.Player_Drop_Item:
                    ServerItem inHand = player.Inventory.GetPlayerItemInHand();
                    if (inHand == null)
                        break;
                    player.DropItem();
                    break;

                case GameEvents.Player_Use_Item:
                    short x = p.ReadShort();
                    short y = p.ReadShort();
                    ServerItem itemInHand = player.Inventory.GetPlayerItemInHand();
                    if (itemInHand == null) break;
                    itemInHand.OnItemUsed(x, y, player);
                    break;

                case GameEvents.Player_Use_Block:
                    x = p.ReadShort();
                    y = p.ReadShort();
                    Block b = GetBlockAt(x, y).Block;
                    b.OnBlockUsed(x, y, player);
                    break;

                case GameEvents.Player_Pickup_Block:
                    x = p.ReadShort();
                    y = p.ReadShort();
                    if (player.PClass is PlayerClassDestroyer) {
                        if (Math.Abs(player.EntityPosition.X / BlockSize - (float)(x)) < 2 && Math.Abs(player.EntityPosition.Y / BlockSize - (float)(y)) < 2)
                            ((PlayerClassDestroyer)player.PClass).PickupBlock(new Vector2(x, y));
                    }
                    break;

                case GameEvents.Player_Place_Block:
                    if (player.PClass is PlayerClassDestroyer)
                    {
                        ((PlayerClassDestroyer)player.PClass).PlaceBlock();
                    }
                    break;

                case GameEvents.Player_Inventory_Selection_Change:
                    player.SetPlayerEquippedSlot(p.ReadByte());
                    player.SendEquippedItemUpdate();
                    break;

                case GameEvents.Player_Chat:
                    bool teamChat = p.ReadBool();
                    string chatText = p.ReadString();

                    ServerConsole.Log(player.PlayerName + ": " + chatText);

                    Packet1SCGameEvent pack = new Packet1SCGameEvent(GameEvents.Player_Chat, (byte)player.PlayerID, (bool)teamChat, chatText);
                    ServerNetworkManager.SendPacket(pack);
                    break;

                case GameEvents.Player_Change_Name:
                    string newName = p.ReadString();
                    if (newName.Length > 0)
                    {
                        player.PlayerName = newName;
                        pack = new Packet1SCGameEvent(GameEvents.Player_Change_Name, (byte)player.PlayerID, newName);
                        ServerNetworkManager.SendPacket(pack);
                    }
                    break;

                case GameEvents.Player_Choose_Team:
                    int team = p.ReadByte();
                    if (team != 0 && team != 1) return;
                    if (team == player.PlayerTeam) return;
                    player.PlayerTeam = team;
                    GameMode.OnPlayerChooseTeam(player, team);
                    player.HurtPlayer(10000);

                    Packet newP = new Packet1SCGameEvent(GameEvents.Player_Choose_Team, (byte)player.PlayerID, (byte)team);
                    ServerNetworkManager.SendPacket(newP);
                    break;
            }
        }
Пример #10
0
        public static void DropItem(ItemStack stack, Vector2 position, Vector2 velocity = default(Vector2), NetworkPlayer dropper = null)
        {
            short index = GetFreeDroppedItemIndex();
            if (index == -1)
                return;

            if (velocity == default(Vector2))
                velocity = new Vector2(Random.Next(-5, 6), -3);

            var item = new ServerEntityDroppedItem((int)position.X, (int)position.Y, velocity, stack, index) { Dropper = dropper };
            DroppedItems.Add(item);

            Packet8SCItemDropped pack = new Packet8SCItemDropped(position, velocity, index, stack.ItemID);
            ServerNetworkManager.SendPacket(pack);
        }