Ejemplo n.º 1
0
        public bool SetFloorItem(GameClient Session, Item Item, int newX, int newY, int newRot, bool newItem, bool OnRoller, bool sendMessage, bool updateRoomUserStatuses = false)
        {
            // Questions -> Skype: keiz.er
            bool NeedsReAdd = false;


            if (newItem)
            {
                if (Item.IsWired)
                {
                    if (Item.GetBaseItem().WiredType == WiredBoxType.EffectRegenerateMaps && _room.GetRoomItemHandler().GetFloor.Where(x => x.GetBaseItem().WiredType == WiredBoxType.EffectRegenerateMaps).Count() > 0)
                    {
                        return(false);
                    }
                }
            }


            List <Item> ItemsOnTile = GetFurniObjects(newX, newY);

            if (Item.GetBaseItem().InteractionType == InteractionType.ROLLER && ItemsOnTile.Where(x => x.GetBaseItem().InteractionType == InteractionType.ROLLER && x.Id != Item.Id).Count() > 0)
            {
                return(false);
            }


            if (!newItem)
            {
                NeedsReAdd = _room.GetGameMap().RemoveFromMap(Item);
            }


            Dictionary <int, ThreeDCoord> AffectedTiles = Gamemap.GetAffectedTiles(Item.GetBaseItem().Length, Item.GetBaseItem().Width, newX, newY, newRot);


            if (!_room.GetGameMap().ValidTile(newX, newY) || _room.GetGameMap().SquareHasUsers(newX, newY) && !Item.GetBaseItem().IsSeat)
            {
                if (NeedsReAdd)
                {
                    _room.GetGameMap().AddToMap(Item);
                }
                return(false);
            }


            foreach (ThreeDCoord Tile in AffectedTiles.Values)
            {
                if (!_room.GetGameMap().ValidTile(Tile.X, Tile.Y) ||
                    (_room.GetGameMap().SquareHasUsers(Tile.X, Tile.Y) && !Item.GetBaseItem().IsSeat))
                {
                    if (NeedsReAdd)
                    {
                        _room.GetGameMap().AddToMap(Item);
                    }
                    return(false);
                }
            }

            Double newZ = _room.GetGameMap().Model.SqFloorHeight[newX, newY];


            if (!OnRoller)
            {
                if (_room.GetGameMap().Model.SqState[newX, newY] != SquareState.OPEN && !Item.GetBaseItem().IsSeat)
                {
                    return(false);
                }


                foreach (ThreeDCoord Tile in AffectedTiles.Values)
                {
                    if (_room.GetGameMap().Model.SqState[Tile.X, Tile.Y] != SquareState.OPEN &&
                        !Item.GetBaseItem().IsSeat)
                    {
                        if (NeedsReAdd)
                        {
                            //AddItem(Item);
                            _room.GetGameMap().AddToMap(Item);
                        }
                        return(false);
                    }
                }

                if (!Item.GetBaseItem().IsSeat&& !Item.IsRoller)
                {
                    foreach (ThreeDCoord Tile in AffectedTiles.Values)
                    {
                        if (_room.GetGameMap().GetRoomUsers(new Point(Tile.X, Tile.Y)).Count > 0)
                        {
                            if (NeedsReAdd)
                            {
                                _room.GetGameMap().AddToMap(Item);
                            }
                            return(false);
                        }
                    }
                }
            }


            // Find affected objects
            var ItemsAffected = new List <Item>();
            var ItemsComplete = new List <Item>();


            foreach (ThreeDCoord Tile in AffectedTiles.Values.ToList())
            {
                List <Item> Temp = GetFurniObjects(Tile.X, Tile.Y);


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



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


            if (!OnRoller)
            {
                foreach (Item I in ItemsComplete.ToList())
                {
                    if (I == null)
                    {
                        continue;
                    }


                    if (I.Id == Item.Id)
                    {
                        continue;
                    }


                    if (I.GetBaseItem() == null)
                    {
                        continue;
                    }
                }
            }

            {
                if (Item.Rotation != newRot && Item.GetX == newX && Item.GetY == newY)
                {
                    newZ = Item.GetZ;
                }

                foreach (Item I in ItemsComplete.ToList())
                {
                    if (I == null)
                    {
                        continue;
                    }
                    if (I.Id == Item.Id)
                    {
                        continue;
                    }


                    if (I.GetBaseItem().InteractionType == InteractionType.STACKTOOL)
                    { // Basically the core of the fix
                        // Questions -> Skype: keiz.er
                        newZ = I.GetZ;
                        break;
                    }


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

            if (newRot != 0 && newRot != 2 && newRot != 4 && newRot != 6 && newRot != 8 && !Item.GetBaseItem().ExtraRot)
            {
                newRot = 0;
            }


            Item.Rotation = newRot;
            int oldX = Item.GetX;
            int oldY = Item.GetY;

            Item.SetState(newX, newY, newZ, AffectedTiles);


            if (!OnRoller && Session != null)
            {
                Item.Interactor.OnPlace(Session, Item);
            }



            if (newItem)
            {
                if (_floorItems.ContainsKey(Item.Id))
                {
                    if (Session != null)
                    {
                        Session.SendNotification(PlusEnvironment.GetGame().GetLanguageLocale().TryGetValue("room_item_placed"));
                    }
                    _room.GetGameMap().RemoveFromMap(Item);
                    return(true);
                }


                if (Item.IsFloorItem && !_floorItems.ContainsKey(Item.Id))
                {
                    _floorItems.TryAdd(Item.Id, Item);
                }
                else if (Item.IsWallItem && !_wallItems.ContainsKey(Item.Id))
                {
                    _wallItems.TryAdd(Item.Id, Item);
                }


                if (sendMessage)
                {
                    _room.SendMessage(new ObjectAddComposer(Item, _room));
                }
            }
            else
            {
                UpdateItem(Item);
                if (!OnRoller && sendMessage)
                {
                    _room.SendMessage(new ObjectUpdateComposer(Item, _room.OwnerId));
                }
            }
            _room.GetGameMap().AddToMap(Item);


            if (Item.GetBaseItem().IsSeat)
            {
                updateRoomUserStatuses = true;
            }


            if (updateRoomUserStatuses)
            {
                _room.GetRoomUserManager().UpdateUserStatusses();
            }


            if (Item.GetBaseItem().InteractionType == InteractionType.TENT || Item.GetBaseItem().InteractionType == InteractionType.TENT_SMALL)
            {
                _room.RemoveTent(Item.Id, Item);
                _room.AddTent(Item.Id);
            }


            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.RunQuery("UPDATE `items` SET `room_id` = '" + _room.RoomId + "', `x` = '" + Item.GetX + "', `y` = '" + Item.GetY + "', `z` = '" + Item.GetZ + "', `rot` = '" + Item.Rotation + "' WHERE `id` = '" + Item.Id + "' LIMIT 1");
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool SetFloorItem(GameClient Session, Item Item, int newX, int newY, int newRot, bool newItem, bool OnRoller, bool sendMessage, bool updateRoomUserStatuses = false, double height = -1)
        {
            bool NeedsReAdd = false;

            if (newItem)
            {
                if (Item.IsWired)
                {
                    if (Item.GetBaseItem().WiredType == WiredBoxType.EffectRegenerateMaps && _room.GetRoomItemHandler().GetFloor.Count(x => x.GetBaseItem().WiredType == WiredBoxType.EffectRegenerateMaps) > 0)
                    {
                        return(false);
                    }
                }
            }

            List <Item> ItemsOnTile = GetFurniObjects(newX, newY);

            if (Item.GetBaseItem().InteractionType == InteractionType.ROLLER && ItemsOnTile.Count(x => x.GetBaseItem().InteractionType == InteractionType.ROLLER && x.Id != Item.Id) > 0)
            {
                return(false);
            }

            if (!newItem)
            {
                NeedsReAdd = _room.GetGameMap().RemoveFromMap(Item);
            }

            Dictionary <int, ThreeDCoord> AffectedTiles = Gamemap.GetAffectedTiles(Item.GetBaseItem().Length, Item.GetBaseItem().Width, newX, newY, newRot);

            if (!_room.GetGameMap().ValidTile(newX, newY) || _room.GetGameMap().SquareHasUsers(newX, newY) && !Item.GetBaseItem().IsSeat)
            {
                if (NeedsReAdd)
                {
                    _room.GetGameMap().AddToMap(Item);
                }
                return(false);
            }

            foreach (ThreeDCoord Tile in AffectedTiles.Values)
            {
                if (!_room.GetGameMap().ValidTile(Tile.X, Tile.Y) ||
                    (_room.GetGameMap().SquareHasUsers(Tile.X, Tile.Y) && !Item.GetBaseItem().IsSeat))
                {
                    if (NeedsReAdd)
                    {
                        _room.GetGameMap().AddToMap(Item);
                    }
                    return(false);
                }
            }

            // Start calculating new Z coordinate
            double newZ = _room.GetGameMap().Model.SqFloorHeight[newX, newY];

            if (height == -1)
            {
                if (!OnRoller)
                {
                    // Make sure this tile is open and there are no users here
                    if (_room.GetGameMap().Model.SqState[newX, newY] != SquareState.Open && !Item.GetBaseItem().IsSeat)
                    {
                        return(false);
                    }

                    foreach (ThreeDCoord Tile in AffectedTiles.Values)
                    {
                        if (_room.GetGameMap().Model.SqState[Tile.X, Tile.Y] != SquareState.Open &&
                            !Item.GetBaseItem().IsSeat)
                        {
                            if (NeedsReAdd)
                            {
                                //AddItem(Item);
                                _room.GetGameMap().AddToMap(Item);
                            }
                            return(false);
                        }
                    }

                    // And that we have no users
                    if (!Item.GetBaseItem().IsSeat&& !Item.IsRoller)
                    {
                        foreach (ThreeDCoord Tile in AffectedTiles.Values)
                        {
                            if (_room.GetGameMap().GetRoomUsers(new Point(Tile.X, Tile.Y)).Count > 0)
                            {
                                if (NeedsReAdd)
                                {
                                    _room.GetGameMap().AddToMap(Item);
                                }
                                return(false);
                            }
                        }
                    }
                }

                // Find affected objects
                var ItemsAffected = new List <Item>();
                var ItemsComplete = new List <Item>();

                foreach (ThreeDCoord Tile in AffectedTiles.Values.ToList())
                {
                    List <Item> Temp = GetFurniObjects(Tile.X, Tile.Y);

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


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

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

                        if (I.Id == Item.Id)
                        {
                            continue;
                        }

                        if (I.GetBaseItem() == null)
                        {
                            continue;
                        }

                        if (!I.GetBaseItem().Stackable)
                        {
                            if (NeedsReAdd)
                            {
                                //AddItem(Item);
                                _room.GetGameMap().AddToMap(Item);
                            }
                            return(false);
                        }
                    }
                }

                //if (!Item.IsRoller)
                {
                    // If this is a rotating action, maintain item at current height
                    if (Item.Rotation != newRot && Item.GetX == newX && Item.GetY == newY)
                    {
                        newZ = Item.GetZ;
                    }

                    // Are there any higher objects in the stack!?
                    foreach (Item i in ItemsComplete.ToList())
                    {
                        if (i == null)
                        {
                            continue;
                        }
                        if (i.Id == Item.Id)
                        {
                            continue;
                        }

                        if (i.GetBaseItem().InteractionType == InteractionType.STACKTOOL)
                        {
                            newZ = i.GetZ;
                            break;
                        }
                        if (i.TotalHeight > newZ)
                        {
                            newZ = i.TotalHeight;
                        }
                    }
                }

                // Verify the rotation is correct
                if (newRot != 0 && newRot != 2 && newRot != 4 && newRot != 6 && newRot != 8 && !Item.GetBaseItem().ExtraRot)
                {
                    newRot = 0;
                }
            }
            else
            {
                newZ = height;
            }

            Item.Rotation = newRot;
            int oldX = Item.GetX;
            int oldY = Item.GetY;

            Item.SetState(newX, newY, newZ, AffectedTiles);

            if (!OnRoller && Session != null)
            {
                Item.Interactor.OnPlace(Session, Item);
            }


            if (newItem)
            {
                if (_floorItems.ContainsKey(Item.Id))
                {
                    if (Session != null)
                    {
                        Session.SendNotification(PlusEnvironment.GetLanguageManager().TryGetValue("room.item.already_placed"));
                    }
                    _room.GetGameMap().RemoveFromMap(Item);
                    return(true);
                }

                if (Item.IsFloorItem && !_floorItems.ContainsKey(Item.Id))
                {
                    _floorItems.TryAdd(Item.Id, Item);
                }
                else if (Item.IsWallItem && !_wallItems.ContainsKey(Item.Id))
                {
                    _wallItems.TryAdd(Item.Id, Item);
                }

                if (sendMessage)
                {
                    _room.SendPacket(new ObjectAddComposer(Item));
                }
            }
            else
            {
                UpdateItem(Item);
                if (!OnRoller && sendMessage)
                {
                    _room.SendPacket(new ObjectUpdateComposer(Item, _room.OwnerId));
                }
            }
            _room.GetGameMap().AddToMap(Item);

            if (Item.GetBaseItem().IsSeat)
            {
                updateRoomUserStatuses = true;
            }

            if (updateRoomUserStatuses)
            {
                _room.GetRoomUserManager().UpdateUserStatusses();
            }

            if (Item.GetBaseItem().InteractionType == InteractionType.TENT || Item.GetBaseItem().InteractionType == InteractionType.TENT_SMALL)
            {
                _room.RemoveTent(Item.Id);
                _room.AddTent(Item.Id);
            }

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.RunQuery("UPDATE `items` SET `room_id` = '" + _room.RoomId + "', `x` = '" + Item.GetX + "', `y` = '" + Item.GetY + "', `z` = '" + Item.GetZ + "', `rot` = '" + Item.Rotation + "' WHERE `id` = '" + Item.Id + "' LIMIT 1");
            }
            return(true);
        }
Ejemplo n.º 3
0
        public bool SetFloorItem(GameClient Session, Item Item, int newX, int newY, int newRot, bool newItem, bool OnRoller, bool sendMessage, bool updateRoomUserStatuses = false, bool ToDB = true, Item SpaceItem = null, double newZ = 1000.0, bool PlacedByRoleplay = false)
        {
            double origZ       = newZ;
            bool   CheckHeight = newZ == 1000.0 ? true : false;
            bool   NeedsReAdd  = false;

            if (newItem && Item.ExtraData == "")
            {
                Item.ExtraData = "0";
            }

            if (newItem)
            {
                if (Item.IsWired)
                {
                    if (Item.GetBaseItem().WiredType == WiredBoxType.EffectRegenerateMaps && _room.GetRoomItemHandler().GetFloor.Where(x => x.GetBaseItem().WiredType == WiredBoxType.EffectRegenerateMaps).Count() > 0)
                    {
                        return(false);
                    }
                }
            }

            List <Item> ItemsOnTile = GetFurniObjects(newX, newY);

            if (Item.GetBaseItem().InteractionType == InteractionType.ROLLER && ItemsOnTile.Where(x => x.GetBaseItem().InteractionType == InteractionType.ROLLER && x.Id != Item.Id).Count() > 0)
            {
                return(false);
            }

            if (!newItem)
            {
                NeedsReAdd = _room.GetGameMap().RemoveFromMap(Item);
            }

            Dictionary <int, ThreeDCoord> AffectedTiles = Gamemap.GetAffectedTiles(Item.GetBaseItem().Length, Item.GetBaseItem().Width, newX, newY, newRot);

            if (!PlacedByRoleplay)
            {
                if (!_room.GetGameMap().ValidTile(newX, newY) || (_room.GetGameMap().SquareHasUsers(newX, newY) && !Item.GetBaseItem().Walkable&& !Item.GetBaseItem().IsSeat))
                {
                    if (NeedsReAdd)
                    {
                        _room.GetGameMap().AddToMap(Item);
                    }
                    return(false);
                }

                foreach (ThreeDCoord Tile in AffectedTiles.Values)
                {
                    if (!_room.GetGameMap().ValidTile(Tile.X, Tile.Y) || (_room.GetGameMap().SquareHasUsers(newX, newY) && !Item.GetBaseItem().Walkable&& !Item.GetBaseItem().IsSeat))
                    {
                        if (NeedsReAdd)
                        {
                            _room.GetGameMap().AddToMap(Item);
                        }
                        return(false);
                    }
                }
            }

            if (SpaceItem != null && Session != null)
            {
                bool CanPlaceHere = true;

                if (AffectedTiles.Values.Select(x => new Point(x.X, x.Y)).Where(x => !SpaceItem.GetAffectedTiles.Contains(x)).ToList().Count > 0)
                {
                    CanPlaceHere = false;
                }

                if (_room.OwnerId == Session.GetHabbo().Id || _room.CheckRights(Session) || Session.GetHabbo().GetPermissions().HasRight("room_item_place_exchange_anywhere"))
                {
                    CanPlaceHere = true;
                }

                if (!CanPlaceHere)
                {
                    return(false);
                }
            }

            // Start calculating new Z coordinate
            newZ = _room.GetGameMap().Model.SqFloorHeight[newX, newY];

            if (Session != null)
            {
                if (Session.GetHabbo().DebugStacking == true)
                {
                    newZ = Session.GetHabbo().StackHeight;
                }
            }

            if (!OnRoller && !PlacedByRoleplay)
            {
                // Make sure this tile is open and there are no users here
                if (_room.GetGameMap().Model.SqState[newX, newY] != SquareState.OPEN && !Item.GetBaseItem().IsSeat&& !Item.GetBaseItem().Walkable)
                {
                    return(false);
                }

                foreach (ThreeDCoord Tile in AffectedTiles.Values)
                {
                    if (_room.GetGameMap().Model.SqState[Tile.X, Tile.Y] != SquareState.OPEN && !Item.GetBaseItem().IsSeat&& !Item.GetBaseItem().Walkable)
                    {
                        if (NeedsReAdd)
                        {
                            _room.GetGameMap().AddToMap(Item);
                        }
                        return(false);
                    }
                }

                // And that we have no users
                if (!Item.GetBaseItem().IsSeat&& !Item.IsRoller && !Item.GetBaseItem().Walkable)
                {
                    foreach (ThreeDCoord Tile in AffectedTiles.Values)
                    {
                        if (_room.GetGameMap().GetRoomUsers(new Point(Tile.X, Tile.Y)).Count > 0)
                        {
                            if (NeedsReAdd)
                            {
                                _room.GetGameMap().AddToMap(Item);
                            }
                            return(false);
                        }
                    }
                }
            }

            // Find affected objects
            var ItemsAffected = new List <Item>();
            var ItemsComplete = new List <Item>();

            foreach (ThreeDCoord Tile in AffectedTiles.Values.ToList())
            {
                List <Item> Temp = GetFurniObjects(Tile.X, Tile.Y);

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


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

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

                    if (I.Id == Item.Id)
                    {
                        continue;
                    }

                    if (I.GetBaseItem() == null)
                    {
                        continue;
                    }

                    if (!I.GetBaseItem().Stackable)
                    {
                        if (NeedsReAdd)
                        {
                            //AddItem(Item);
                            _room.GetGameMap().AddToMap(Item);
                        }
                        return(false);
                    }
                }
            }

            //if (!Item.IsRoller)
            {
                // If this is a rotating action, maintain item at current height
                if (Item.Rotation != newRot && Item.GetX == newX && Item.GetY == newY)
                {
                    if (Session != null)
                    {
                        if (Session.GetHabbo().DebugStacking == true)
                        {
                            newZ = Session.GetHabbo().StackHeight;
                        }
                        else
                        {
                            newZ = Item.GetZ;
                        }
                    }
                    else
                    {
                        newZ = Item.GetZ;
                    }
                }

                Double StackingTile = 0;


                // Are there any higher objects in the stack!?
                foreach (Item I in ItemsComplete.ToList())
                {
                    if (I == null)
                    {
                        continue;
                    }

                    if (I.Id == Item.Id)
                    {
                        continue; // cannot stack on self
                    }
                    if (I.GetBaseItem().InteractionType == InteractionType.STACKTOOL)
                    {
                        StackingTile = I.GetZ;
                    }

                    if (I.TotalHeight > newZ)
                    {
                        if (Session != null)
                        {
                            if (Session.GetHabbo().DebugStacking == true)
                            {
                                newZ = Session.GetHabbo().StackHeight;
                            }
                            else
                            {
                                newZ = StackingTile != 0 ? StackingTile : I.TotalHeight;
                            }
                        }
                        else
                        {
                            newZ = StackingTile != 0 ? StackingTile : I.TotalHeight;
                        }
                    }
                }
            }

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

            Item.Rotation = newRot;
            int oldX = Item.GetX;
            int oldY = Item.GetY;

            if (!CheckHeight)
            {
                newZ = origZ;
            }

            Item.SetState(newX, newY, newZ, AffectedTiles);

            if (!OnRoller && Session != null)
            {
                Item.Interactor.OnPlace(Session, Item);
            }

            if (newItem)
            {
                if (_floorItems.ContainsKey(Item.Id))
                {
                    if (Session != null)
                    {
                        Session.SendNotification(PlusEnvironment.GetGame().GetLanguageLocale().TryGetValue("room_item_placed"));
                    }
                    _room.GetGameMap().RemoveFromMap(Item);
                    return(true);
                }

                if (Item.IsFloorItem && !_floorItems.ContainsKey(Item.Id))
                {
                    _floorItems.TryAdd(Item.Id, Item);
                }
                else if (Item.IsWallItem && !_wallItems.ContainsKey(Item.Id))
                {
                    _wallItems.TryAdd(Item.Id, Item);
                }

                if (sendMessage)
                {
                    _room.SendMessage(new ObjectAddComposer(Item, _room));
                }
            }
            else
            {
                UpdateItem(Item);
                if (!OnRoller && sendMessage)
                {
                    _room.SendMessage(new ObjectUpdateComposer(Item, Item.UserID));
                }
            }
            _room.GetGameMap().AddToMap(Item);

            if (Item.GetBaseItem().IsSeat)
            {
                updateRoomUserStatuses = true;
            }

            if (updateRoomUserStatuses)
            {
                _room.GetRoomUserManager().UpdateUserStatusses();
            }

            if (Item.GetBaseItem().InteractionType == InteractionType.TENT || Item.GetBaseItem().InteractionType == InteractionType.TENT_SMALL)
            {
                _room.RemoveTent(Item.Id, Item);
                _room.AddTent(Item.Id);
            }

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.RunQuery("UPDATE `items` SET `room_id` = '" + _room.RoomId + "', `x` = '" + Item.GetX + "', `y` = '" + Item.GetY + "', `z` = '" + Item.GetZ + "', `rot` = '" + Item.Rotation + "' WHERE `id` = '" + Item.Id + "' LIMIT 1");
            }
            return(true);
        }