コード例 #1
0
ファイル: Room.cs プロジェクト: habb0/uberEmu-stabilized
        public bool SetFloorItem(GameClient Session, RoomItem Item, int newX, int newY, int newRot, bool newItem)
        {
            // Find affected tiles
            Dictionary<int, AffectedTile> AffectedTiles = GetAffectedTiles(Item.GetBaseItem().Length, Item.GetBaseItem().Width, newX, newY, newRot);

            // Verify tiles are valid
            if (!ValidTile(newX, newY))
            {
                return false;
            }

            foreach (AffectedTile Tile in AffectedTiles.Values)
            {
                if (!ValidTile(Tile.X, Tile.Y))
                {
                    return false;
                }
            }

            // Start calculating new Z coordinate
            Double newZ = Model.SqFloorHeight[newX, newY];

            // Is the item trying to stack on itself!?
            if (Item.Rot == newRot && Item.X == newX && Item.Y == newY && Item.Z != newZ)
            {
                return false;
            }

            // Make sure this tile is open and there are no users here
            if (Model.SqState[newX, newY] != SquareState.OPEN)
            {
                return false;
            }

            foreach (AffectedTile Tile in AffectedTiles.Values)
            {
                if (Model.SqState[Tile.X, Tile.Y] != SquareState.OPEN)
                {
                    return false;
                }
            }

            // And that we have no users
            if (!Item.GetBaseItem().IsSeat)
            {
                if (SquareHasUsers(newX, newY))
                {
                    return false;
                }

                foreach (AffectedTile Tile in AffectedTiles.Values)
                {
                    if (SquareHasUsers(Tile.X, Tile.Y))
                    {
                        return false;
                    }
                }
            }

            // Find affected objects
            List<RoomItem> ItemsOnTile = GetFurniObjects(newX, newY);
            List<RoomItem> ItemsAffected = new List<RoomItem>();
            List<RoomItem> ItemsComplete = new List<RoomItem>();

            foreach (AffectedTile Tile in AffectedTiles.Values)
            {
                List<RoomItem> Temp = GetFurniObjects(Tile.X, Tile.Y);

                if (Temp != null)
                {
                    ItemsAffected.AddRange(Temp);
                }
            }

            if (ItemsOnTile == null) ItemsOnTile = new List<RoomItem>();

            ItemsComplete.AddRange(ItemsOnTile);
            ItemsComplete.AddRange(ItemsAffected);

            // Check for items in the stack that do not allow stacking on top of them
            foreach (RoomItem I in ItemsComplete)
            {
                if (I.Id == Item.Id)
                {
                    continue;
                }

                if (!I.GetBaseItem().Stackable)
                {
                    return false;
                }
            }

            // If this is a rotating action, maintain item at current height
            if (Item.Rot != newRot && Item.X == newX && Item.Y == newY)
            {
                newZ = Item.Z;
            }

            // Are there any higher objects in the stack!?
            foreach (RoomItem I in ItemsComplete)
            {
                if (I.Id == Item.Id)
                {
                    continue; // cannot stack on self
                }

                if (I.TotalHeight > newZ)
                {
                    newZ = I.TotalHeight;
                }
            }

            // Verify the rotation is correct
            if (newRot != 0 && newRot != 2 && newRot != 4 && newRot != 6 && newRot != 8)
            {
                newRot = 0;
            }

            Item.X = newX;
            Item.Y = newY;
            Item.Z = newZ;
            Item.Rot = newRot;

            Item.Interactor.OnPlace(Session, Item);

            if (newItem)
            {
                using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                {
                    dbClient.AddParamWithValue("extra_data", Item.ExtraData);
                    dbClient.ExecuteQuery("INSERT INTO room_items (id,room_id,base_item,extra_data,x,y,z,rot,wall_pos) VALUES ('" + Item.Id + "','" + RoomId + "','" + Item.BaseItem + "',@extra_data,'" + Item.X + "','" + Item.Y + "','" + Item.Z + "','" + Item.Rot + "','')");
                }

                Items.Add(Item);

                ServerPacket Message = new ServerPacket(93);
                Item.Serialize(Message);
                SendMessage(Message);
            }
            else
            {
                using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                {
                    dbClient.ExecuteQuery("UPDATE room_items SET x = '" + Item.X + "', y = '" + Item.Y + "', z = '" + Item.Z + "', rot = '" + Item.Rot + "', wall_pos = '' WHERE id = '" + Item.Id + "' LIMIT 1");
                }

                ServerPacket Message = new ServerPacket(95);
                Item.Serialize(Message);
                SendMessage(Message);
            }

            GenerateMaps();
            UpdateUserStatusses();

            return true;
        }
コード例 #2
0
ファイル: Room.cs プロジェクト: habb0/uberEmu-stabilized
        public bool SetWallItem(GameClient Session, RoomItem Item)
        {
            Item.Interactor.OnPlace(Session, Item);

            switch (Item.GetBaseItem().InteractionType.ToLower())
            {
                case "dimmer":

                    if (MoodlightData == null)
                    {
                        MoodlightData = new MoodlightData(Item.Id);
                        Item.ExtraData = MoodlightData.GenerateExtraData();
                    }

                    break;
            }

            using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
            {
                dbClient.AddParamWithValue("extra_data", Item.ExtraData);
                dbClient.ExecuteQuery("INSERT INTO room_items (id,room_id,base_item,extra_data,x,y,z,rot,wall_pos) VALUES ('" + Item.Id + "','" + RoomId + "','" + Item.BaseItem + "',@extra_data,'0','0','0','0','" + Item.WallPos + "')");
            }

            Items.Add(Item);

            ServerPacket Message = new ServerPacket(83);
            Item.Serialize(Message);
            SendMessage(Message);

            return true;
        }
コード例 #3
0
ファイル: Room.cs プロジェクト: habb0/uberEmu-stabilized
        public void LoadFurniture()
        {
            this.Items.Clear();

            DataTable Data = null;

            using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
            {
                Data = dbClient.ReadDataTable("SELECT * FROM room_items WHERE room_id = '" + Id + "'");
            }

            if (Data == null)
            {
                return;
            }

            foreach (DataRow Row in Data.Rows)
            {
                RoomItem Item = new RoomItem((uint)Row["id"], RoomId, (uint)Row["base_item"], (string)Row["extra_data"],
                    (int)Row["x"], (int)Row["y"], (Double)Row["z"], (int)Row["rot"], (string)Row["wall_pos"]);

                switch (Item.GetBaseItem().InteractionType.ToLower())
                {
                    case "dimmer":

                        if (MoodlightData == null)
                        {
                            MoodlightData = new MoodlightData(Item.Id);
                        }

                        break;
                }

                this.Items.Add(Item);
            }
        }