Ejemplo n.º 1
0
        internal bool UserGotAuthorization(GameClient session)
        {
            foreach(string subs in clubsAllowed){
                if (session.GetHabbo().GetSubscriptionManager().HasSubscription(subs))
                    return true;
            }

            if (minrank == 0)
                return true;
            else if (minrank > 0)
            {
                if (minrank <= session.GetHabbo().Rank)
                    return true;
            }
            else if (minrank < 0)
            {
                if (minrank == -1)
                {
                    if (session.GetHabbo().CurrentRoom.CheckRights(session, false))
                        return true;
                }
                else if (minrank == -2)
                {
                    if (session.GetHabbo().CurrentRoom.CheckRights(session, true))
                        return true;
                }
            }

            return false;
        }
Ejemplo n.º 2
0
        internal static ServerMessage Compose(GameClient Session, List<Achievement> Achievements)
        {
            ServerMessage Message = new ServerMessage(436); //436
            Message.AppendInt32(Achievements.Count);

            foreach (Achievement Achievement in Achievements)
            {
                UserAchievement UserData = Session.GetHabbo().GetAchievementData(Achievement.GroupName);
                int TargetLevel = (UserData != null ? UserData.Level + 1 : 1);
                int TotalLevels = Achievement.Levels.Count;

                if (TargetLevel > TotalLevels)
                {
                    TargetLevel = TotalLevels;
                }

                AchievementLevel TargetLevelData = Achievement.Levels[TargetLevel];

                Message.AppendUInt(Achievement.Id);                                                           // Unknown (ID?)
                Message.AppendInt32(TargetLevel);                                                   // Target level
                Message.AppendStringWithBreak(Achievement.GroupName + TargetLevel);                 // Target name/desc/badge
                Message.AppendInt32(TargetLevelData.Requirement);                                   // Progress req/target
                Message.AppendInt32(TargetLevelData.RewardPixels);                                   // Pixel reward
                Message.AppendInt32(TargetLevelData.RewardPoints);                                  // Unknown(??)
                Message.AppendInt32(UserData != null ? UserData.Progress : 0);                      // Current progress
                Message.AppendBoolean(UserData != null ? (UserData.Level >= TotalLevels) : false);  // Set 100% completed(??)
                Message.AppendStringWithBreak(Achievement.Category);                                // Category
                Message.AppendInt32(TotalLevels);                                                   // Total amount of levels
            }

            return Message;
        }
Ejemplo n.º 3
0
        internal static void AlertUser(GameClient ModSession, uint UserId, String Message, Boolean Caution)
        {
            GameClient Client = PiciEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);

            if (Client == null || Client.GetHabbo().Id == ModSession.GetHabbo().Id)
            {
                return;
            }

            if (Caution && Client.GetHabbo().Rank >= ModSession.GetHabbo().Rank)
            {
                ModSession.SendNotif(LanguageLocale.GetValue("moderation.caution.missingrank"));
                Caution = false;
            }

            Client.SendNotif(Message, Caution);

            if (Caution)
            {
                using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.runFastQuery("UPDATE user_info SET cautions = cautions + 1 WHERE user_id = " + UserId + "");
                }
            }
        }
Ejemplo n.º 4
0
        private static void AddToPlaylist(GameClient Session, ClientMessage Message)
        {
            Room Instance = Session.GetHabbo().CurrentRoom;

            if (Instance == null || !Instance.CheckRights(Session, true) || !Instance.GotMusicController() ||
                Instance.GetRoomMusicController().PlaylistSize >= Instance.GetRoomMusicController().PlaylistCapacity)
            {
                return;
            }

            UserItem DiskUserItem = Session.GetHabbo().GetInventoryComponent().GetItem(Message.PopWiredUInt());

            if (DiskUserItem == null || DiskUserItem.GetBaseItem().InteractionType != InteractionType.musicdisc)
            {
                return;
            }

            SongItem item = new SongItem(DiskUserItem);

            int NewOrder = Instance.GetRoomMusicController().AddDisk(item);

            if (NewOrder < 0)
            {
                return;
            }

            Session.GetHabbo().GetInventoryComponent().RemoveItem(item.itemID, true);

            Session.SendMessage(JukeboxComposer.Compose(Instance.GetRoomMusicController().PlaylistCapacity,
                Instance.GetRoomMusicController().Playlist.Values.ToList()));
        }
        internal AvatarEffectsInventoryComponent(uint UserId, GameClient pClient, UserData data)
        {
            this.mClient = pClient;
            this.Effects = new ArrayList();
            this.UserId = UserId;
            this.CurrentEffect = -1;
            this.Effects.Clear();

            StringBuilder QueryBuilder = new StringBuilder();
            foreach (AvatarEffect effect in data.effects)
            {
                if (!effect.HasExpired)
                {
                    Effects.Add(effect);
                    EffectCount++;
                }
                else
                    QueryBuilder.Append("DELETE FROM user_effects WHERE user_id = " + UserId + " AND effect_id = " + effect.EffectId + "; ");
            }

            if (QueryBuilder.Length > 0)
            {
                using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                    dbClient.runFastQuery(QueryBuilder.ToString());
            }
        }
Ejemplo n.º 6
0
        internal static void GivePixels(GameClient Client, int amount)
        {
            Double Timestamp = PiciEnvironment.GetUnixTimestamp();

            Client.GetHabbo().LastActivityPointsUpdate = Timestamp;
            Client.GetHabbo().ActivityPoints += amount;
            Client.GetHabbo().UpdateActivityPointsBalance(0);
        }
Ejemplo n.º 7
0
        internal static ChatMessage CreateMessage(string message, GameClient user, Room room)
        {
            uint userID = user.GetHabbo().Id;
            string username = user.GetHabbo().Username;
            uint roomID = room.RoomId;
            string roomName = room.Name;
            bool isPublic = room.IsPublic;
            DateTime timeSpoken = DateTime.Now;

            ChatMessage chatMessage = new ChatMessage(userID, username, roomID, roomName, isPublic, message, timeSpoken);
            return chatMessage;
        }
Ejemplo n.º 8
0
        internal static string GenerateCommandList(GameClient client)
        {
            StringBuilder notif = new StringBuilder();

            foreach (ChatCommand command in commandRegisterInvokeable.Values)
            {
                if (command.UserGotAuthorization(client))
                    notif.Append(command.input + " " + command.prefix + " - " + command.description + "\r");
            }

            return notif.ToString();
        }
Ejemplo n.º 9
0
 internal static InventoryComponent GetInventory(uint UserId, GameClient Client, UserData data)
 {
     return new InventoryComponent(UserId, Client, data);
     //InventoryComponent component;
     //if (storage.TryGetValue(UserId, out component))
     //    return component;
     //else
     //{
     //    InventoryComponent toReturn =
     //    storage.Add(UserId, toReturn);
     //    return toReturn;
     //}
 }
Ejemplo n.º 10
0
        internal override void OnTrigger(GameClient Session, RoomItem Item, int Request, bool UserHasRights)
        {
            if (!UserHasRights)
            {
                return;
            }

            if (Item.ExtraData == "0")
            {
                Item.ExtraData = "1";
                Item.UpdateState(false, true);
                Item.ReqUpdate(4, true);
            }
        }
Ejemplo n.º 11
0
        internal void MoveBall(RoomItem item, GameClient mover, int newX, int newY)
        {
            if (item == null || mover == null)
                return;

            if (!room.GetGameMap().itemCanBePlacedHere(newX, newY))
                return;

            Point oldRoomCoord = item.Coordinate;
            bool itemIsOnGameItem = GameItemOverlaps(item);

            Double NewZ = room.GetGameMap().Model.SqFloorHeight[newX, newY];

            ServerMessage Message = new ServerMessage(95);
            Message.AppendUInt(item.Id);
            Message.AppendInt32(3508);
            Message.AppendInt32(item.Coordinate.X);
            Message.AppendInt32(item.Coordinate.Y);
            Message.AppendInt32(newX);
            Message.AppendInt32(newY);
            Message.AppendInt32(4);
            Message.AppendStringWithBreak(NewZ.ToString());
            Message.AppendStringWithBreak("H11");
            Message.AppendInt32(-1);
            Message.AppendInt32(0);
            room.SendMessage(Message);

            ServerMessage mMessage = new ServerMessage();
            mMessage.Init(230); // Cf
            mMessage.AppendInt32(item.Coordinate.X);
            mMessage.AppendInt32(item.Coordinate.Y);
            mMessage.AppendInt32(newX);
            mMessage.AppendInt32(newY);
            mMessage.AppendInt32(1);
            mMessage.AppendUInt(item.Id);
            mMessage.AppendStringWithBreak(item.GetZ.ToString().Replace(',', '.'));
            mMessage.AppendStringWithBreak(NewZ.ToString().Replace(',', '.'));
            mMessage.AppendInt32(0);
            room.SendMessage(mMessage);

            if (oldRoomCoord.X == newX && oldRoomCoord.Y == newY)
                return;

            room.GetRoomItemHandler().SetFloorItem(mover, item, newX, newY, item.Rot, false, false, false, false);

            if (!itemIsOnGameItem)
                HandleFootballGameItems(new Point(newX, newY), room.GetRoomUserManager().GetRoomUserByHabbo(mover.GetHabbo().Id));
        }
Ejemplo n.º 12
0
        internal override void OnTrigger(GameClient Session, RoomItem Item, int Request, bool UserHasRights)
        {
            if (Session == null)
                return;
            RoomUser interactingUser = Item.GetRoom().GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);

            Point userCoord = interactingUser.Coordinate;
            Point ballCoord = Item.Coordinate;

            int differenceX = userCoord.X - ballCoord.X;
            int differenceY = userCoord.Y - ballCoord.Y;

            if (differenceX <= 1 && differenceX >= -1 && differenceY <= 1 && differenceY >= -1)
            {
                differenceX = differenceX * 2;
                differenceY = differenceY * 2;

                int newX = Item.GetX + differenceX;
                int newY = Item.GetY + differenceY;

                Item.GetRoom().GetSoccer().MoveBall(Item, Session, newX, newY);
                interactingUser.MoveTo(ballCoord);
            }
            else //if (differenceX == 2 || differenceY == 2 || differenceY == - 2 || differenceX == -2)
            {
                Item.interactingBallUser = Session.GetHabbo().Id;

                differenceX = differenceX * (-1);
                differenceY = differenceY * (-1);

                if (differenceX > 1)
                    differenceX = 1;
                else if (differenceX < -1)
                    differenceX = -1;

                if (differenceY > 1)
                    differenceY = 1;
                else if (differenceY < -1)
                    differenceY = -1;

                int newX = Item.GetX + differenceX;
                int newY = Item.GetY + differenceY;

                interactingUser.MoveTo(new Point(newX, newY));
            }
        }
Ejemplo n.º 13
0
        internal ServerMessage Serialize(GameClient Session)
        {
            ServerMessage Message = new ServerMessage(370);
            Message.AppendStringWithBreak(Session.GetHabbo().Id + "");
            Message.AppendStringWithBreak(Session.GetHabbo().Username);
            Message.AppendStringWithBreak(RoomId + "");
            Message.AppendInt32(Category);
            Message.AppendStringWithBreak(Name);
            Message.AppendStringWithBreak(Description);
            Message.AppendStringWithBreak(StartTime);
            Message.AppendInt32(Tags.Count);

            foreach (string Tag in Tags.ToArray())
            {
                Message.AppendStringWithBreak(Tag);
            }
            return Message;
        }
Ejemplo n.º 14
0
        internal static Boolean NeedsUpdate(GameClient Client)
        {
            try
            {
                if (Client.GetHabbo() == null)
                    return false;

                Double PassedMins = (PiciEnvironment.GetUnixTimestamp() - Client.GetHabbo().LastActivityPointsUpdate) / 60;

                if (PassedMins >= RCV_EVERY_MINS)
                    return true;
            }
            catch (Exception e)
            {
                Logging.HandleException(e, "PixelManager.NeedsUpdate");
            }
            return false;
        }
Ejemplo n.º 15
0
        internal static void TryRedeemVoucher(GameClient Session, string Code)
        {
            if (!IsValidCode(Code))
            {
                ServerMessage Error = new ServerMessage(213);
                Error.AppendRawInt32(1);
                Session.SendMessage(Error);
                return;
            }

            int Value = GetVoucherValue(Code);

            TryDeleteVoucher(Code);

            Session.GetHabbo().Credits += Value;
            Session.GetHabbo().UpdateCreditsBalance();

            Session.SendMessage(new ServerMessage(212));
        }
Ejemplo n.º 16
0
        internal static void BanUser(GameClient ModSession, uint UserId, int Length, String Message)
        {
            GameClient Client = PiciEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);

            if (Client == null || Client.GetHabbo().Id == ModSession.GetHabbo().Id)
            {
                return;
            }

            if (Client.GetHabbo().Rank >= ModSession.GetHabbo().Rank)
            {
                ModSession.SendNotif(LanguageLocale.GetValue("moderation.ban.missingrank"));
                return;
            }

            Double dLength = Length;

            PiciEnvironment.GetGame().GetBanManager().BanUser(Client, ModSession.GetHabbo().Username, dLength, Message, false);
        }
Ejemplo n.º 17
0
        internal static void SellItem(GameClient Session, uint ItemId, int SellingPrice)
        {
            UserItem Item = Session.GetHabbo().GetInventoryComponent().GetItem(ItemId);

            if (Item == null || SellingPrice > 10000 || !CanSellItem(Item))
            {
                Session.GetMessageHandler().GetResponse().Init(610);
                Session.GetMessageHandler().GetResponse().AppendBoolean(false);
                Session.GetMessageHandler().GetResponse();
                Session.GetMessageHandler().SendResponse();
                return;
            }

            int Comission = CalculateComissionPrice(SellingPrice);
            int TotalPrice = SellingPrice + Comission;
            int ItemType = 1;

            if (Item.GetBaseItem().Type == 'i')
                ItemType++;

            using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
            {
                if (dbClient.dbType == DatabaseType.MSSQL)
                    dbClient.setQuery("INSERT INTO catalog_marketplace_offers (item_id,user_id,asking_price,total_price,public_name,sprite_id,item_type,timestamp,extra_data,state) VALUES (" + Item.BaseItem + "," + Session.GetHabbo().Id + "," + SellingPrice + "," + TotalPrice + ",@public_name," + Item.GetBaseItem().SpriteId + "," + ItemType + "," + PiciEnvironment.GetUnixTimestamp() + ",@extra_data, '1')");
                else
                    dbClient.setQuery("INSERT INTO catalog_marketplace_offers (item_id,user_id,asking_price,total_price,public_name,sprite_id,item_type,timestamp,extra_data) VALUES (" + Item.BaseItem + "," + Session.GetHabbo().Id + "," + SellingPrice + "," + TotalPrice + ",@public_name," + Item.GetBaseItem().SpriteId + "," + ItemType + "," + PiciEnvironment.GetUnixTimestamp() + ",@extra_data)");
                dbClient.addParameter("public_name", Item.GetBaseItem().PublicName);
                dbClient.addParameter("extra_data", Item.ExtraData);
                dbClient.runQuery();
            }

            Session.GetHabbo().GetInventoryComponent().RemoveItem(ItemId, false);
            Session.GetHabbo().GetInventoryComponent().RunDBUpdate();

            Session.GetMessageHandler().GetResponse().Init(610);
            Session.GetMessageHandler().GetResponse().AppendBoolean(true);
            Session.GetMessageHandler().SendResponse();
        }
Ejemplo n.º 18
0
        internal void ActivateQuest(GameClient Session, ClientMessage Message)
        {
            Quest Quest = GetQuest(Message.PopWiredUInt());

            if (Quest == null)
            {
                return;
            }

            using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
            {
                if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MySQL)
                    dbClient.runFastQuery("REPLACE INTO user_quests VALUES (" + Session.GetHabbo().Id + ", " + Quest.Id + ", 0)");
                else
                    dbClient.runFastQuery("IF NOT EXISTS (SELECT user_id FROM user_quests WHERE user_id = " + Session.GetHabbo().Id + " AND quest_id = " + Quest.Id + ") " +
                                          "INSERT INTO user_quests VALUES (" + Session.GetHabbo().Id + ", " + Quest.Id + ", 0)");
                dbClient.runFastQuery("UPDATE users SET currentquestid = " + Quest.Id + " WHERE id = " + Session.GetHabbo().Id);
            }

            Session.GetHabbo().CurrentQuestId = Quest.Id;
            GetList(Session, null);
            Session.SendMessage(QuestStartedComposer.Compose(Session, Quest));
        }
Ejemplo n.º 19
0
        internal InventoryComponent(uint UserId, GameClient Client, UserData UserData)
        {
            this.mClient = Client;
            this.UserId = UserId;
            this.floorItems = new Hashtable();
            this.wallItems = new Hashtable();
            this.discs = new Hashtable();

            foreach (UserItem item in UserData.inventory)
            {
                if (item.GetBaseItem().InteractionType == InteractionType.musicdisc)
                    discs.Add(item.Id, item);
                if (item.isWallItem)
                    wallItems.Add(item.Id, item);
                else
                    floorItems.Add(item.Id, item);
            }

            this.InventoryPets = new SafeDictionary<UInt32, Pet>(UserData.pets);
            this.mAddedItems = new Hashtable();
            this.mRemovedItems = new ArrayList();
            this.isUpdated = false;
        }
Ejemplo n.º 20
0
        internal void RemoveFurniture(GameClient Session, uint pId)
        {
            RoomItem Item = GetItem(pId);

            if (Item == null)
                return;

            if (Item.GetBaseItem().InteractionType == InteractionType.fbgate)
            {
                room.GetSoccer().UnRegisterGate(Item);
            }

            Item.Interactor.OnRemove(Session, Item);
            RemoveRoomItem(Item);

            if (Item.wiredHandler != null)
            {
                using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    Item.wiredHandler.DeleteFromDatabase(dbClient);
                    Item.wiredHandler.Dispose();
                    room.GetWiredHandler().RemoveFurniture(Item);
                }
                Item.wiredHandler = null;
            }

            if (Item.wiredCondition != null)
            {
                using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    Item.wiredCondition.DeleteFromDatabase(dbClient);
                    Item.wiredCondition.Dispose();
                    room.GetWiredHandler().conditionHandler.ClearTile(Item.Coordinate);
                }
                Item.wiredCondition = null;
            }
        }
Ejemplo n.º 21
0
 internal void Destroy()
 {
     // RequestHandlers.Clear();
     Session = null;
 }
Ejemplo n.º 22
0
 //private delegate void RequestHandler();
 //private Dictionary<uint, RequestHandler> RequestHandlers;
 public GameClientMessageHandler(GameClient Session)
 {
     this.Session = Session;
     //this.RequestHandlers = new Dictionary<uint, RequestHandler>();
     this.Response = new ServerMessage(0);
 }
Ejemplo n.º 23
0
        internal void UpdateFriend(uint userid, GameClient client, bool notification)
        {
            if (friends.ContainsKey(userid))
            {
                friends[userid].UpdateUser(client);

                if (notification)
                {
                    GameClient Userclient = GetClient();
                    if (Userclient != null)
                        Userclient.SendMessage(SerializeUpdate((MessengerBuddy)friends[userid]));
                }
            }
        }
Ejemplo n.º 24
0
 internal static ServerMessage Compose(GameClient Session, Quest Quest)
 {
     ServerMessage Message = new ServerMessage(802);
     QuestListComposer.SerializeQuest(Message, Session, Quest, Quest.Category);
     return Message;
 }
Ejemplo n.º 25
0
        internal void AddUserToRoom(GameClient Session, bool Spectator)
        {
            RoomUser User = new RoomUser(Session.GetHabbo().Id, room.RoomId, primaryPrivateUserID++, room, Spectator);
            User.userID = Session.GetHabbo().Id;

            string username = Session.GetHabbo().Username;
            uint userID = User.userID;

            if (usersByUsername.ContainsKey(username.ToLower()))
                usersByUsername.Remove(username.ToLower());

            if (usersByUserID.ContainsKey(userID))
                usersByUserID.Remove(userID);

            usersByUsername.Add(Session.GetHabbo().Username.ToLower(), User);
            usersByUserID.Add(Session.GetHabbo().Id, User);

            int PersonalID = secondaryPrivateUserID++;
            User.InternalRoomID = PersonalID;
            Session.CurrentRoomUserID = PersonalID;

            Session.GetHabbo().CurrentRoomId = room.RoomId;
            UserList.Add(PersonalID, User);
        }
Ejemplo n.º 26
0
        internal void RemoveUserFromRoom(GameClient Session, Boolean NotifyClient, Boolean NotifyKick)
        {
            try
            {
                if (Session == null)
                    return;

                if (Session.GetHabbo() == null)
                    return;

                Session.GetHabbo().GetAvatarEffectsInventoryComponent().OnRoomExit();

                if (NotifyClient)
                {
                    if (NotifyKick)
                    {
                        Session.GetMessageHandler().GetResponse().Init(33);
                        Session.GetMessageHandler().GetResponse().AppendInt32(4008);
                        Session.GetMessageHandler().SendResponse();
                    }

                    Session.GetMessageHandler().GetResponse().Init(18);
                    Session.GetMessageHandler().SendResponse();
                }

                RoomUser User = GetRoomUserByHabbo(Session.GetHabbo().Id);

                if (User != null)
                {
                    RemoveRoomUser(User);

                    if (Session.GetHabbo() != null)
                    {
                        if (!User.IsSpectator)
                        {
                            if (User.CurrentItemEffect != ItemEffectType.None)
                            {
                                User.GetClient().GetHabbo().GetAvatarEffectsInventoryComponent().CurrentEffect = -1;
                            }
                            //UserMatrix[User.X, User.Y] = false;

                            if (Session.GetHabbo() != null)
                            {
                                if (room.HasActiveTrade(Session.GetHabbo().Id))
                                    room.TryStopTrade(Session.GetHabbo().Id);

                                if (Session.GetHabbo().Username == room.Owner)
                                {
                                    if (room.HasOngoingEvent)
                                    {
                                        room.Event = new RoomEvent(0, null, null, 0, new List<string>());

                                        ServerMessage Message = new ServerMessage(370);
                                        Message.AppendStringWithBreak("-1");
                                        room.SendMessage(Message);

                                        PiciEnvironment.GetGame().GetRoomManager().GetEventManager().QueueRemoveEvent(room.RoomData, room.Event.Category);
                                    }
                                }
                                Session.GetHabbo().CurrentRoomId = 0;

                                if (Session.GetHabbo().GetMessenger() != null)
                                    Session.GetHabbo().GetMessenger().OnStatusChanged(true);
                            }

                            //DateTime Start = DateTime.Now;
                            //using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
                            //{
                            //    //TimeSpan TimeUsed1 = DateTime.Now - Start;
                            //    //Logging.LogThreadException("Time used on sys part 2: " + TimeUsed1.Seconds + "s, " + TimeUsed1.Milliseconds + "ms", "");

                            //    //if (Session.GetHabbo() != null)
                            //    //    dbClient.runFastQuery("UPDATE user_roomvisits SET exit_timestamp = '" + PiciEnvironment.GetUnixTimestamp() + "' WHERE room_id = '" + this.Id + "' AND user_id = '" + Id + "' ORDER BY exit_timestamp DESC LIMIT 1");
                            //    //dbClient.runFastQuery("UPDATE rooms SET users_now = " + UsersNow + " WHERE id = " + Id);
                            //    //dbClient.runFastQuery("REPLACE INTO room_active VALUES (" + RoomId + ", " + UsersNow + ")");
                            //    dbClient.runFastQuery("UPDATE room_active SET active_users = " + UsersNow);
                            //}
                        }
                    }

                    usersByUserID.Remove(User.userID);
                    if (Session.GetHabbo() != null)
                        usersByUsername.Remove(Session.GetHabbo().Username.ToLower());

                    User.Dispose();
                }

            }
            catch (Exception e)
            {
                Logging.LogCriticalException("Error during removing user from room:" + e.ToString());
            }
        }
Ejemplo n.º 27
0
        internal bool SetWallItem(GameClient Session, RoomItem Item)
        {
            if (!Item.IsWallItem || mWallItems.ContainsKey(Item.Id))
                return false;
            if (mFloorItems.ContainsKey(Item.Id))
            {
                Session.SendNotif(LanguageLocale.GetValue("room.itemplaced"));
                return true;
            }
            Item.Interactor.OnPlace(Session, Item);

            if (Item.GetBaseItem().InteractionType == InteractionType.dimmer)
            {
                if (room.MoodlightData == null)
                {
                    room.MoodlightData = new MoodlightData(Item.Id);
                    Item.ExtraData = room.MoodlightData.GenerateExtraData();
                }
            }

            mWallItems.Add(Item.Id, Item);
            AddItem(Item);

            ServerMessage Message = new ServerMessage(83);
            Item.Serialize(Message);
            room.SendMessage(Message);

            return true;
        }
Ejemplo n.º 28
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 = PiciEnvironment.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 = PiciEnvironment.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;
        }
Ejemplo n.º 29
0
 internal bool SetFloorItem(GameClient Session, RoomItem Item, int newX, int newY, int newRot, bool newItem, bool OnRoller, bool sendMessage)
 {
     return SetFloorItem(Session, Item, newX, newY, newRot, newItem, OnRoller, sendMessage, true);
 }
Ejemplo n.º 30
0
        internal List<RoomItem> RemoveAllFurniture(GameClient Session)
        {
            List<RoomItem> ReturnList = new List<RoomItem>();
            foreach (RoomItem Item in mFloorItems.Values.ToArray())
            {
                Item.Interactor.OnRemove(Session, Item);
                ServerMessage Message = new ServerMessage(94);
                Message.AppendRawUInt(Item.Id);
                Message.AppendStringWithBreak("");
                Message.AppendBoolean(false);
                room.SendMessage(Message);

                //mFloorItems.Remove(Item.Id);

                ReturnList.Add(Item);
            }

            foreach (RoomItem Item in mWallItems.Values.ToArray())
            {
                Item.Interactor.OnRemove(Session, Item);
                ServerMessage Message = new ServerMessage(84);
                Message.AppendRawUInt(Item.Id);
                Message.AppendStringWithBreak("");
                Message.AppendBoolean(false);
                room.SendMessage(Message);
                //mWallItems.Remove(Item.Id);

                ReturnList.Add(Item);
            }

            mWallItems.Clear();
            mFloorItems.Clear();

            mRemovedItems.Clear();

            mMovedItems.Clear();
            mAddedItems.Clear();
            mRollers.QueueDelegate(new onCycleDoneDelegate(ClearRollers));

            using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.runFastQuery("DELETE FROM items_rooms WHERE room_id = " + room.RoomId);
            }

            room.GetGameMap().GenerateMaps();
            room.GetRoomUserManager().UpdateUserStatusses();

            if (room.GotWired())
            {
                room.GetWiredHandler().OnPickall();
            }

            return ReturnList;
        }