public bool SetFloorItem(Item Item, int newX, int newY, double newZ)
 {
     this.GetRoom.GetGameMap().RemoveFromMap(Item);
     Item.SetState(newX, newY, newZ, Gamemap.GetAffectedTiles(Item.GetBaseItem().Length, Item.GetBaseItem().Width, newX, newY, Item.Rotation));
     this.UpdateItem(Item);
     this.GetRoom.GetGameMap().AddItemToMap(Item);
     return(true);
 }
Beispiel #2
0
        internal bool SetFloorItem(RoomItem Item, int newX, int newY, Double newZ)
        {
            room.GetGameMap().RemoveFromMap(Item);
            Item.SetState(newX, newY, newZ, Gamemap.GetAffectedTiles(Item.GetBaseItem().Length, Item.GetBaseItem().Width, newX, newY, Item.Rot));

            UpdateItem(Item);
            room.GetGameMap().AddItemToMap(Item);

            return(true);
        }
        public bool SetFloorItem(GameClient Session, Item Item, int newX, int newY, int newRot, bool newItem, bool OnRoller, bool sendMessage)
        {
            bool NeedsReAdd = false;

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

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

            foreach (ThreeDCoord threeDcoord in affectedTiles.Values)
            {
                if (!this.GetRoom.GetGameMap().ValidTile(threeDcoord.X, threeDcoord.Y) || (this.GetRoom.GetGameMap().SquareHasUsers(threeDcoord.X, threeDcoord.Y) && !Item.GetBaseItem().IsSeat&& Item.GetBaseItem().InteractionType != InteractionType.bed) || this.GetRoom.GetGameMap().Model.SqState[threeDcoord.X, threeDcoord.Y] != SquareState.OPEN)
                {
                    if (NeedsReAdd)
                    {
                        this.UpdateItem(Item);
                        this.GetRoom.GetGameMap().AddToMap(Item);
                    }
                    return(false);
                }
            }

            double pZ = (double)this.GetRoom.GetGameMap().Model.SqFloorHeight[newX, newY];

            List <Item> ItemsAffected = new List <Item>();
            List <Item> ItemsComplete = new List <Item>();

            foreach (ThreeDCoord threeDcoord in affectedTiles.Values)
            {
                List <Item> Temp = this.GetRoom.GetGameMap().GetCoordinatedItems(new Point(threeDcoord.X, threeDcoord.Y));
                if (Temp != null)
                {
                    ItemsAffected.AddRange(Temp);
                }
            }
            //ItemsComplete.AddRange(ItemsOnTile);
            ItemsComplete.AddRange(ItemsAffected);


            bool   ConstruitMode   = false;
            bool   ConstruitZMode  = false;
            double ConstruitHeigth = 1.0;
            bool   PileMagic       = false;

            if (Item.GetBaseItem().InteractionType == InteractionType.pilemagic)
            {
                PileMagic = true;
            }

            if (Session != null && Session.GetHabbo() != null && Session.GetHabbo().CurrentRoom != null)
            {
                RoomUser User_room = Session.GetHabbo().CurrentRoom.GetRoomUserManager().GetRoomUserByHabboId(Session.GetHabbo().Id);
                if (User_room != null)
                {
                    ConstruitMode   = User_room.ConstruitMode;
                    ConstruitZMode  = User_room.ConstruitZMode;
                    ConstruitHeigth = User_room.ConstruitHeigth;
                }
            }

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

            if (ConstruitZMode)
            {
                pZ = pZ + ConstruitHeigth;
            }
            else
            {
                foreach (Item roomItem in ItemsComplete)
                {
                    if (roomItem.GetBaseItem().InteractionType == InteractionType.pilemagic)
                    {
                        pZ        = roomItem.GetZ;
                        PileMagic = true;
                        break;
                    }
                    if (roomItem.Id != Item.Id && roomItem.TotalHeight > pZ)
                    {
                        if (ConstruitMode)
                        {
                            pZ = roomItem.GetZ + ConstruitHeigth;
                        }
                        else
                        {
                            pZ = roomItem.TotalHeight;
                        }
                    }
                }
            }

            if (!OnRoller)
            {
                foreach (Item roomItem in ItemsComplete)
                {
                    if (roomItem != null && roomItem.Id != Item.Id && (roomItem.GetBaseItem() != null && (!roomItem.GetBaseItem().Stackable&& !ConstruitMode && !PileMagic && !ConstruitZMode)))
                    {
                        if (NeedsReAdd)
                        {
                            this.UpdateItem(Item);
                            this.GetRoom.GetGameMap().AddToMap(Item);
                        }
                        return(false);
                    }
                }
            }

            if (newRot != 1 && newRot != 2 && newRot != 3 && newRot != 4 && newRot != 5 && newRot != 6 && newRot != 7 && newRot != 8)
            {
                newRot = 0;
            }

            List <RoomUser> userForSquare = new List <RoomUser>();

            foreach (ThreeDCoord threeDcoord in Item.GetAffectedTiles.Values)
            {
                userForSquare.AddRange(this.GetRoom.GetGameMap().GetRoomUsers(new Point(threeDcoord.X, threeDcoord.Y)));
            }

            Item.Rotation = newRot;
            Item.SetState(newX, newY, pZ, affectedTiles);

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

            if (newItem)
            {
                if (this._floorItems.ContainsKey(Item.Id))
                {
                    if (Session != null)
                    {
                        Session.SendNotification(ButterflyEnvironment.GetLanguageManager().TryGetValue("room.itemplaced", Session.Langue));
                    }
                    return(true);
                }
                else
                {
                    if (Item.IsFloorItem && !this._floorItems.ContainsKey(Item.Id))
                    {
                        this._floorItems.TryAdd(Item.Id, Item);
                    }
                    else if (Item.IsWallItem && !this._wallItems.ContainsKey(Item.Id))
                    {
                        this._wallItems.TryAdd(Item.Id, Item);
                    }

                    this.UpdateItem(Item);
                    if (sendMessage)
                    {
                        this.GetRoom.SendPacket(new ObjectAddComposer(Item, this.GetRoom.RoomData.OwnerName, this.GetRoom.RoomData.OwnerId));
                    }
                }
            }
            else
            {
                this.UpdateItem(Item);
                if (!OnRoller && sendMessage)
                {
                    GetRoom.SendPacket(new ObjectUpdateComposer(Item, GetRoom.RoomData.OwnerId));
                }
            }

            this.GetRoom.GetGameMap().AddToMap(Item);


            foreach (ThreeDCoord threeDcoord in Item.GetAffectedTiles.Values)
            {
                userForSquare.AddRange(this.GetRoom.GetGameMap().GetRoomUsers(new Point(threeDcoord.X, threeDcoord.Y)));
            }

            foreach (RoomUser User in userForSquare)
            {
                if (User == null)
                {
                    continue;
                }
                if (User.IsWalking)
                {
                    continue;
                }

                this.GetRoom.GetRoomUserManager().UpdateUserStatus(User, false);
            }

            return(true);
        }
Beispiel #4
0
        internal bool SetFloorItem(GameClient Session, RoomItem Item, int newX, int newY, int newRot, bool newItem, bool OnRoller, bool sendMessage, bool updateRoomUserStatuses)
        {
            bool NeedsReAdd = 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))
            {
                if (NeedsReAdd)
                {
                    AddItem(Item);
                    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))
                {
                    if (NeedsReAdd)
                    {
                        AddItem(Item);
                        room.GetGameMap().AddToMap(Item);
                    }
                    return(false);
                }
            }

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

            if (!OnRoller)
            {
                // Is the item trying to stack on itself!?
                //if (Item.Rot == newRot && Item.GetX == newX && Item.GetY == newY && Item.GetZ != newZ)
                //{
                //    if (NeedsReAdd)
                //        AddItem(Item);
                //    return false;
                //}

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

                foreach (ThreeDCoord Tile in AffectedTiles.Values)
                {
                    if (room.GetGameMap().Model.SqState[Tile.X, Tile.Y] != SquareState.OPEN)
                    {
                        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)
                            {
                                AddItem(Item);
                                room.GetGameMap().AddToMap(Item);
                            }
                            return(false);
                        }
                    }
                }
            }

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

            foreach (ThreeDCoord Tile in AffectedTiles.Values)
            {
                List <RoomItem> 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 (RoomItem I in ItemsComplete)
                {
                    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.Rot != newRot && Item.GetX == newX && Item.GetY == newY)
                {
                    newZ = Item.GetZ;
                }

                // 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.GetX = newX;
            //Item.GetY = newY;
            //Item.GetZ = newZ;


            Item.Rot = 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 (mFloorItems.ContainsKey(Item.Id))
                {
                    if (Session != null)
                    {
                        Session.SendNotif(LanguageLocale.GetValue("room.itemplaced"));
                    }

                    //Remove from map!!!
                    return(true);
                }

                //using (DatabaseClient dbClient = ButterflyEnvironment.GetDatabase().GetClient())
                //{
                //    dbClient.addParameter("extra_data", Item.ExtraData);
                //    dbClient.runFastQuery("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.GetX + "','" + Item.GetY + "','" + Item.GetZ + "','" + Item.Rot + "','')");
                //}
                //if (mRemovedItems.ContainsKey(Item.Id))
                //    mRemovedItems.Remove(Item.Id);
                //if (mAddedItems.ContainsKey(Item.Id))
                //    return false;

                //mAddedItems.Add(Item.Id, Item);

                if (Item.IsFloorItem && !mFloorItems.ContainsKey(Item.Id))
                {
                    mFloorItems.Add(Item.Id, Item);
                }
                else if (Item.IsWallItem && !mWallItems.ContainsKey(Item.Id))
                {
                    mWallItems.Add(Item.Id, Item);
                }

                AddItem(Item);

                if (sendMessage)
                {
                    ServerMessage Message = new ServerMessage(93);
                    Item.Serialize(Message);
                    room.SendMessage(Message);
                }
            }
            else
            {
                //using (DatabaseClient dbClient = ButterflyEnvironment.GetDatabase().GetClient())
                //{
                //    dbClient.runFastQuery("UPDATE room_items SET x = '" + Item.GetX + "', y = '" + Item.GetY + "', z = '" + Item.GetZ + "', rot = '" + Item.Rot + "', wall_pos = '' WHERE id = '" + Item.Id + "' LIMIT 1");
                //}
                UpdateItem(Item);

                if (!OnRoller && sendMessage)
                {
                    ServerMessage Message = new ServerMessage(95);
                    Item.Serialize(Message);
                    room.SendMessage(Message);
                }
            }

            if (!newItem)
            {
                room.GetWiredHandler().RemoveWiredItem(new System.Drawing.Point(oldX, oldY));

                if (WiredHandler.TypeIsWire(Item.GetBaseItem().InteractionType))
                {
                    room.GetWiredHandler().AddWire(Item, new System.Drawing.Point(newX, newY), newRot, Item.GetBaseItem().InteractionType);
                }
            }
            else
            {
                if (WiredHandler.TypeIsWire(Item.GetBaseItem().InteractionType))
                {
                    room.GetWiredHandler().AddWire(Item, Item.Coordinate, newRot, Item.GetBaseItem().InteractionType);
                }
            }

            //GenerateMaps(false);
            room.GetGameMap().AddToMap(Item);

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

            return(true);
        }