Beispiel #1
0
        public override void OnUserChat(RoomInstance Instance, RoomActor Actor, string MessageText, bool Shout)
        {
            if (mSelfActor == null || Actor.Type == RoomActorType.AiBot || mServingItemId > 0 ||
                (Distance.Calculate(Actor.Position.GetVector2(), mSelfActor.Position.GetVector2()) > mSelfBot.ResponseDistance))
            {
                return;
            }

            BotResponse Response = mSelfBot.GetResponseForMessage(MessageText);

            if (Response != null)
            {
                mSelfActor.Chat(Response.GetResponse(), false);

                if (Response.ResponseServeId > 0)
                {
                    mMovingToServePos = true;
                    mServingItemId = Response.ResponseServeId;
                    mServingActorId = Actor.Id;
                    mActorServePos = new Vector2(mSelfActor.Position.X, mSelfActor.Position.Y);

                    mSelfActor.MoveTo(mSelfBot.ServePosition);

                    if (mNextMovementAttempt < 50)
                    {
                        mNextMovementAttempt = 50;
                    }
                }

                if (mNextSpeechAttempt < 50)
                {
                    mNextSpeechAttempt += 10;
                }
            }
        }
Beispiel #2
0
        private static void IgnoreUser(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            uint UserId = CharacterResolverCache.GetUidFromName(Message.PopString());

            if (UserId == 0)
            {
                return;
            }

            Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);

            if (TargetSession != null)
            {
                if (TargetSession.HasRight("cannot_ignore"))
                {
                    Session.SendData(NotificationMessageComposer.Compose("You can not ignore this user."));
                    return;
                }

                Session.IgnoreCache.MarkUserIgnored(TargetSession.CharacterId);
                Session.SendData(RoomIgnoreResultComposer.Compose(1));
            }
        }
Beispiel #3
0
        public InfobusQuestion(RoomInstance Instance, string Question, List<string> Answers)
        {
            mInstance = Instance;
            mQuestionText = Question;
            mAnswers = new Dictionary<int, string>();
            mResponses = new Dictionary<uint, int>();
            mTimestampStarted = UnixTimestamp.GetCurrent();
            mCompleted = false;
            mSyncRoot = new object();

            int i = 1;

            foreach (string Answer in Answers)
            {
                mAnswers.Add(i++, Answer);
            }

            foreach (RoomActor Actor in Instance.Actors)
            {
                if (Actor.Type != RoomActorType.UserCharacter)
                {
                    continue;
                }

                mResponses.Add(Actor.Id, -1);
            }

            mWorkerThread = new Thread(new ThreadStart(ExecuteWorkerThread));
            mWorkerThread.Name = "TempInfobusWorker" + Instance.RoomId;
            mWorkerThread.Priority = ThreadPriority.Lowest;
            mWorkerThread.Start();

            BroadcastDataToParticipants(InfobusQuestionStartComposer.Compose(mQuestionText, mAnswers));
        }
Beispiel #4
0
 public override void SetRoomInstance(RoomInstance Room, uint ActorId)
 {
     mCurrentInstance = Room;
     mActorId = ActorId;
     mPath = new List<Vector2>();
     mTarget = null;
 }
Beispiel #5
0
        private static void AddToStaffPicked(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Session.HasRight("hotel_admin"))
            {
                return;
            }

            if (!Navigator.StaffPickedContainsRoom(Instance.RoomId))
            {
                Navigator.AddRoomToStaffPicked(Instance.RoomId);
                Session.SendData(NotificationMessageComposer.Compose("This room has been added to the staff picked rooms successfully."));

                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    Session TargetSession = SessionManager.GetSessionByCharacterId(Instance.Info.OwnerId);

                    if (TargetSession != null)
                    {
                        AchievementManager.ProgressUserAchievement(MySqlClient, TargetSession, "ACH_Spr", 1);
                    }

                    // todo: need a way to save achievement progress in the database so it can be applied on user login
                    //       right now it's impossible to progress an user's achievement if they're not logged in
                }
            }
            else
            {
                Navigator.RemoveRoomFromStaffPicked(Instance.RoomId);
                Session.SendData(NotificationMessageComposer.Compose("This room has been removed from the staff picked rooms successfully."));
            }
        }
Beispiel #6
0
        private static void ActivateGeneric(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null) // warning: rights need to be checked in the event handler; we do not check here
            {
                return;
            }

            Item Item = Instance.GetItem(Message.PopWiredUInt32());

            if (Item == null || Item.Definition.Behavior == ItemBehavior.StaticItem)
            {
                return;
            }

            int RequestData = Message.PopWiredInt32();

            ItemEventDispatcher.InvokeItemEventHandler(Session, Item, Instance, ItemEventType.Interact, RequestData, Message.Id);
            QuestManager.ProgressUserQuest(Session, QuestType.EXPLORE_FIND_ITEM, Item.DefinitionId);

            if (Item.Definition.Behavior == ItemBehavior.Switchable)
            {
                QuestManager.ProgressUserQuest(Session, QuestType.FURNI_SWITCH);
            }
        }
Beispiel #7
0
        private static void AnswerDoorbell(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session))
            {
                return;
            }

            string Name   = Message.PopString();
            bool   Accept = (Message.ReadBytes(1)[0] == 65);

            Session TargetSession = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(Name));

            if (TargetSession == null || TargetSession.AbsoluteRoomId != Instance.RoomId || TargetSession.RoomAuthed)
            {
                return;
            }

            if (Accept)
            {
                TargetSession.RoomAuthed = true;
                TargetSession.SendData(RoomDoorbellAcceptedComposer.Compose());
                return;
            }

            TargetSession.SendData(RoomDoorbellNoResponseComposer.Compose());
            RoomManager.RemoveUserFromRoom(TargetSession, false);
        }
Beispiel #8
0
        private static bool HandleExchangeRedemption(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
                case ItemEventType.Interact:

                    int ItemValue = 0;
                    int.TryParse(Item.Flags, out ItemValue);

                    using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                    {
                        if (ItemValue != 0)
                        {
                            Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, ItemValue);
                            Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance));
                        }

                        Item.RemovePermanently(MySqlClient);
                    }

                    Instance.TakeItem(Item.Id);
                    Instance.RegenerateRelativeHeightmap();
                    break;
            }

            return true;
        }
Beispiel #9
0
        public override void OnSelfLeaveRoom(RoomInstance Instance)
        {
            if (mSelfActor == null)
            {
                return;
            }

            mSelfActor = null;
        }
Beispiel #10
0
        private static void SaveSticky(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            Item Item = Instance.GetItem(Message.PopWiredUInt32());

            if (Item == null || Item.Definition.Behavior != ItemBehavior.StickyNote)
            {
                return;
            }

            StickieEditingRights Rights = Instance.GetStickieEditingRights(Session, Item);

            if (Rights == StickieEditingRights.ReadOnly)
            {
                return;
            }

            string RawData = Message.PopString();

            string[] Bits = RawData.Split(' ');

            if (Bits.Length < 2)
            {
                return;
            }

            string Color = Bits[0].ToUpper().Trim();
            string Text  = UserInputFilter.FilterString(RawData.Substring(Color.Length + 1, RawData.Length - (Color.Length + 1))).Trim();

            if (Color != "FFFF33" && Color != "FF9CFF" && Color != "9CCEFF" && Color != "9CFF9C" || Text.Length > 391)
            {
                return;
            }

            Item.Flags        = RawData;
            Item.DisplayFlags = Color;

            if (Rights == StickieEditingRights.GuestEdit)
            {
                Item.Flags += "\n-----\n" + Session.CharacterInfo.Username + "\n" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
            }

            Instance.RevokeTemporaryStickieRights(Item.Id);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Item.SynchronizeDatabase(MySqlClient, true);
            }

            Instance.BroadcastMessage(RoomWallItemMovedComposer.Compose(Item));
        }
        public static ServerMessage Compose(Item Item, RoomInstance Instance)
        {
            // com.sulake.habbo.communication.messages.incoming.userdefinedroomevents.WiredFurniActionEvent;
            ServerMessage Message = new ServerMessage(OpcodesOut.WIRED_FURNI_ACTION);

            Message.AppendInt32(0);
            Message.AppendInt32(5);  // Furni limit

            if (Item.WiredData.Data1.Contains ("|")) {
                String[] Selected = Item.WiredData.Data1.Split('|');

             	Message.AppendInt32(Selected.Length-1); // Selected Furni Count
                foreach(String selected in Selected) {
                    if(selected == "") {
                        continue;
                    }
                    int result;
                    Int32.TryParse(selected, out result);
                    Message.AppendInt32(result);
                }
            } else {
                Message.AppendUInt32(0);
            }

            Message.AppendUInt32(Item.Definition.SpriteId);
            Message.AppendUInt32(Item.Id);

            Message.AppendStringWithBreak(Item.WiredData.Data1);

            WiredEffectTypes Type = WiredTypesUtil.EffectFromInt(Item.Definition.BehaviorData);

            if(WiredEffectTypes.match_to_sshot == Type || WiredEffectTypes.move_rotate == Type) {
                Message.AppendUInt32(3);  // Data Count
            }

            Message.AppendInt32(Item.WiredData.Data2);
            Message.AppendInt32(Item.WiredData.Data3);

            if(WiredEffectTypes.match_to_sshot == Type || WiredEffectTypes.move_rotate == Type) {
                Message.AppendInt32(Item.WiredData.Data4);
                Message.AppendUInt32(0);
            }

            Message.AppendInt32(Item.Definition.BehaviorData);

            Message.AppendInt32(Item.WiredData.Time); // TIME

            List<Item> Items = Instance.WiredManager.ActionRequiresActor(Item.Definition.BehaviorData, Item.RoomPosition.GetVector2());

            Message.AppendInt32(Items.Count);
            foreach (Item Blocked in Items) {
                Message.AppendUInt32(Blocked.Definition.SpriteId);
            }

            return Message;
        }
Beispiel #12
0
        private static void WiredSave(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }
            Instance.WiredManager.HandleSave(Session, Message);
        }
Beispiel #13
0
        private static void UserChat(Session Session, ClientMessage Message)
        {
            if (Session.CharacterInfo.IsMuted)
            {
                return;
            }

            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor == null)
            {
                return;
            }

            bool   Shout       = (Message.Id == OpcodesIn.ROOM_CHAT_SHOUT);
            string MessageText = UserInputFilter.FilterString(Message.PopString());

            if (MessageText.Length == 0)
            {
                return;
            }

            if (MessageText.Length > 100)
            {
                MessageText = MessageText.Substring(0, 100);
            }

            MessageText = Wordfilter.Filter(MessageText);

            if (MessageText.StartsWith(":") && (ChatCommands.HandleCommand(Session, MessageText) ||
                                                Session.HasRight("moderation_tool")))
            {
                return;
            }

            if (Instance.WiredManager.HandleChat(MessageText, Actor))
            {
                Actor.Whisper(MessageText, 0);
                return;
            }

            Actor.Chat(MessageText, Shout, Session.HasRight("mute"));

            if (Instance.HumanActorCount > 1)
            {
                QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_CHAT);
            }
        }
Beispiel #14
0
        private static void KickBot(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            Instance.KickBot(Message.PopWiredUInt32());
        }
Beispiel #15
0
        private static void ContinueLoadingAfterDoorbell(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Message.PopWiredUInt32());

            if (Instance == null)
            {
                return;
            }

            EnterRoom(Session, Instance);
        }
Beispiel #16
0
        private static void ApplyDecoration(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            Item Item = Session.InventoryCache.GetItem(Message.PopWiredUInt32());

            if (Item == null)
            {
                return;
            }

            string DecorationKey = string.Empty;

            switch (Item.Definition.Behavior)
            {
            case ItemBehavior.Floor:

                QuestManager.ProgressUserQuest(Session, QuestType.FURNI_DECORATION_FLOOR);
                DecorationKey = "floor";
                break;

            case ItemBehavior.Wallpaper:

                QuestManager.ProgressUserQuest(Session, QuestType.FURNI_DECORATION_WALL);
                DecorationKey = "wallpaper";
                break;

            case ItemBehavior.Landscape:

                DecorationKey = "landscape";
                break;
            }

            if (DecorationKey.Length == 0)
            {
                return;
            }

            Session.InventoryCache.RemoveItem(Item.Id);

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Item.RemovePermanently(MySqlClient);
                Instance.Info.ApplyDecoration(MySqlClient, DecorationKey, Item.Flags);
            }

            Instance.BroadcastMessage(RoomDecorationComposer.Compose(DecorationKey, Item.Flags));
            Session.SendData(InventoryItemRemovedComposer.Compose(Item.Id));
        }
Beispiel #17
0
        private static void StopEvent(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            Instance.StopEvent();
        }
Beispiel #18
0
        private static void GetEditInfo(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            Session.SendData(RoomEditInfoComposer.Compose(Instance));
        }
Beispiel #19
0
        private static void DeleteRoom(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            Instance.DeleteRoom(Session);
            //Navigator.GetUserRooms(Session, null); todo: fix. do not uncomment, shit will break in this implementation.
        }
Beispiel #20
0
        private static void RateRoom(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || Instance.CheckUserRights(Session, true) || Session.RatedRoomsCache.HasRatedRoom(Instance.RoomId))
            {
                return;
            }

            Instance.Info.IncreaseScore();
            Session.SendData(RoomRatingInfoComposer.Compose(Instance.Info.Score));
        }
Beispiel #21
0
        private static void GetRoomObjects(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.AbsoluteRoomId);

            if (Instance == null || Session.RoomJoined || !Session.RoomAuthed) // if instance not found, or user already joined us, OR if the user isn't authed in the first place, let's gtfo
            {
                return;
            }

            Instance.SendObjects(Session);

            if (!Instance.AddUserToRoom(Session))
            {
                RoomManager.RemoveUserFromRoom(Session);
                return;
            }

            Session.RoomAuthed = true;
            Session.RoomJoined = true;

            ModerationLogs.LogRoomEntry(Session.CharacterId, Instance.RoomId);
            MessengerHandler.MarkUpdateNeeded(Session, 0, false);

            Session.SendData(RoomWallsStatusComposer.Compose(Instance.Info.HideWalls, Instance.Info.WallThickness, Instance.Info.FloorThickness));
            Session.SendData(RoomInfoRightsComposer.Compose(Instance.Info.Type == RoomType.Flat, Instance.RoomId,
                                                            (Instance.Info.Type == RoomType.Flat && Instance.CheckUserRights(Session, true)), Instance.Info.PubInternalName));

            /*if (Instance.Info.Type == RoomType.Flat)
             * {
             *  Session.SendData(RoomInfoComposer.Compose(Instance.Info, true));
             * }*/

            if (Session.CharacterInfo.IsMuted)
            {
                Session.SendData(RoomMutedComposer.Compose((int)Session.CharacterInfo.MutedSecondsLeft));
            }

            if (Instance.Info.OwnerId != Session.CharacterId)
            {
                QuestManager.ProgressUserQuest(Session, QuestType.SOCIAL_VISIT);
            }

            if (Session.QuestCache.CurrentQuestId > 0)
            {
                Quest Quest = QuestManager.GetQuest(Session.QuestCache.CurrentQuestId);

                if (Quest != null)
                {
                    Session.SendData(QuestStartedComposer.Compose(Session, Quest));
                }
            }
        }
 public static void InvokeItemEventHandler(Session Session, Item Item, RoomInstance Instance, ItemEventType Type, int RequestData = 0, uint Opcode = 0, bool checkrights = true)
 {
     if (mEventHandlers.ContainsKey(Item.Definition.Behavior))
     {
         foreach (ItemEventHandler EventHandler in mEventHandlers[Item.Definition.Behavior])
         {
             if (!EventHandler.Invoke(Session, Item, Instance, Type, RequestData, Opcode))
             {
                 return;
             }
         }
     }
 }
Beispiel #23
0
        private static void UserWhisper(Session Session, ClientMessage Message)
        {
            if (Session.CharacterInfo.IsMuted)
            {
                return;
            }

            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor == null)
            {
                return;
            }

            string MessageText = UserInputFilter.FilterString(Message.PopString().Trim());

            if (MessageText.Length == 0)
            {
                return;
            }

            if (MessageText.Length > 100)
            {
                MessageText = MessageText.Substring(0, 100);
            }

            string[] Bits = MessageText.Split(' ');

            if (Bits.Length < 2)
            {
                return;
            }

            string UserBit = Bits[0];

            MessageText = MessageText.Substring(UserBit.Length + 1);

            uint UserId = CharacterResolverCache.GetUidFromName(UserBit);

            if (UserId > 0)
            {
                Actor.Whisper(MessageText, UserId);
            }
        }
Beispiel #24
0
        private static void UpdateMoodlight(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            Item Item = Instance.MoodlightItem;

            if (Item == null)
            {
                return;
            }

            MoodlightData   Data     = MoodlightData.GenerateFromFlags(Item.Flags);
            int             PresetId = Message.PopWiredInt32();
            MoodlightPreset Preset   = null;

            if (Data.Presets.ContainsKey(PresetId))
            {
                Preset = Data.Presets[PresetId];
            }

            if (Preset == null)
            {
                return;
            }

            Preset.BackgroundOnly = !Message.PopWiredBoolean();
            Preset.ColorCode      = UserInputFilter.FilterString(Message.PopString().Trim());
            Preset.ColorIntensity = Message.PopWiredInt32();

            if (!MoodlightData.IsValidColor(Preset.ColorCode))
            {
                return;
            }

            Item.Flags        = Data.ToItemFlagData();
            Item.DisplayFlags = Data.ToDisplayData();

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Item.SynchronizeDatabase(MySqlClient, true);
            }

            Item.BroadcastStateUpdate(Instance);
        }
Beispiel #25
0
        private static void PlacePet(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || (!Instance.CheckUserRights(Session, true) && !Instance.Info.AllowPets))
            {
                return;
            }

            Pet Pet = Session.PetInventoryCache.GetPet(Message.PopWiredUInt32());

            if (Pet == null)
            {
                return;
            }

            Vector2 DesiredPosition = new Vector2(Message.PopWiredInt32(), Message.PopWiredInt32());

            if (!Instance.IsValidPosition(DesiredPosition))
            {
                return;
            }

            Bot BotDefinition = BotManager.GetHandlerDefinitionForPetType(Pet.Type);

            if (BotDefinition == null)
            {
                Session.SendData(NotificationMessageComposer.Compose("This pet cannot be placed right now. Please try again later."));
                return;
            }

            if (!Instance.CanPlacePet(Instance.CheckUserRights(Session, true)))
            {
                Session.SendData(RoomItemPlacementErrorComposer.Compose(RoomItemPlacementErrorCode.PetLimitReached));
                return;
            }

            Vector3 Position = new Vector3(DesiredPosition.X, DesiredPosition.Y, Instance.GetUserStepHeight(DesiredPosition));

            Pet.MoveToRoom(Instance.RoomId, Position);
            Instance.AddBotToRoom(BotManager.CreateNewInstance(BotDefinition, Instance.RoomId, Position, Pet));

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Pet.SynchronizeDatabase(MySqlClient);
            }

            Session.SendData(InventoryPetRemovedComposer.Compose(Pet.Id));
        }
Beispiel #26
0
        private static void SyncSoundManager(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            if (Instance != null && Instance.MusicController.IsPlaying)
            {
                Session.SendData(MusicPlayingComposer.Compose(Instance.MusicController.CurrentSong.SongData.Id,
                                                              Instance.MusicController.SongQueuePosition, Instance.MusicController.SongSyncTimestamp));
            }
        }
Beispiel #27
0
        private static void GiveRights(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            uint UserId = Message.PopWiredUInt32();

            if (Instance.GiveUserRights(UserId))
            {
                Session.SendData(RoomRightsGivenConfirmationComposer.Compose(Instance.RoomId, UserId, CharacterResolverCache.GetNameFromUid(UserId)));
            }
        }
Beispiel #28
0
 public static void InvokeItemEventHandler(Session Session, Item Item, RoomInstance Instance, ItemEventType Type, int RequestData = 0)
 {
     lock (mSyncRoot)
     {
         if (mEventHandlers.ContainsKey(Item.Definition.Behavior))
         {
             foreach (ItemEventHandler EventHandler in mEventHandlers[Item.Definition.Behavior])
             {
                 if (!EventHandler.Invoke(Session, Item, Instance, Type, RequestData))
                 {
                     return;
                 }
             }
         }
     }
 }
Beispiel #29
0
        private static void SetHome(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                Session.CharacterInfo.SetHomeRoom(MySqlClient, Instance.RoomId);
            }

            Session.SendData(UserHomeRoomComposer.Compose(Session.CharacterInfo.HomeRoom));
        }
Beispiel #30
0
        private static void TakeAllRights(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            foreach (uint UserId in Instance.UsersWithRights)
            {
                if (Instance.TakeUserRights(UserId))
                {
                    Session.SendData(RoomRightsRemovedConfirmationComposer.Compose(Instance.RoomId, UserId));
                }
            }
        }
Beispiel #31
0
        private static void GetGroupBadges(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.AbsoluteRoomId);

            if (Instance == null)
            {
                return;
            }

            ServerMessage xMessage = new ServerMessage(OpcodesOut.ROOM_GROUP_BADGES);

            // count
            // foreach => group id
            //         => string/wb badge code
            xMessage.AppendStringWithBreak("Ib[ZCs58116s04078s04072s52074889902cf4440630470f222ad5c6489d7");
            Session.SendData(xMessage);
        }
Beispiel #32
0
        private static void UnignoreUser(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            uint UserId = CharacterResolverCache.GetUidFromName(Message.PopString());

            if (UserId > 0)
            {
                Session.IgnoreCache.MarkUserUnignored(UserId);
                Session.SendData(RoomIgnoreResultComposer.Compose(3));
            }
        }
Beispiel #33
0
        private static void SetIcon(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            int Junk       = Message.PopWiredInt32();
            int Background = Message.PopWiredInt32();

            if (Background < 1 || Background > 24)
            {
                Background = 1;
            }

            int Foreground = Message.PopWiredInt32();

            if (Foreground < 0 || Foreground > 11)
            {
                Foreground = 0;
            }

            int ObjectCount = Message.PopWiredInt32();

            Dictionary <int, int> Objects = new Dictionary <int, int>();

            for (int i = 0; (i < ObjectCount && i < 10); i++)
            {
                int Position = Message.PopWiredInt32();
                int Item     = Message.PopWiredInt32();

                if (Position < 0 || Position > 10 || Item < 1 || Item > 27 || Objects.ContainsKey(Position))
                {
                    continue;
                }

                Objects.Add(Position, Item);
            }

            Instance.Info.UpdateIcon(Background, Foreground, Objects);
            Session.SendData(RoomUpdatedNotification3Composer.Compose(Instance.RoomId));
            Instance.BroadcastMessage(RoomUpdatedNotification2Composer.Compose(Instance.RoomId));
        }
Beispiel #34
0
        private static void OpenSticky(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            Item Item = Instance.GetItem(Message.PopWiredUInt32());

            if (Item == null || Item.Definition.Behavior != ItemBehavior.StickyNote)
            {
                return;
            }

            Session.SendData(StickyDataComposer.Compose(Item));
        }
Beispiel #35
0
        public RoomActor(uint Id, RoomActorType Type, uint ReferenceId, object ReferenceObject, Vector3 Position, int Rotation, RoomInstance Instance)
        {
            mId               = Id;
            mType             = Type;
            mReferenceId      = ReferenceId;
            mReferenceObject  = ReferenceObject;
            mPosition         = Position;
            mBodyRotation     = Rotation;
            mHeadRotation     = Rotation;
            mUpdateNeeded     = true;
            mStatusses        = new Dictionary <string, string>();
            mInstance         = Instance;
            mEnableClipping   = true;
            mMovementSyncRoot = new object();

            mPathfinder = PathfinderManager.CreatePathfinderInstance();
            mPathfinder.SetRoomInstance(mInstance, Id);
        }
Beispiel #36
0
        public RoomActor(uint Id, RoomActorType Type, uint ReferenceId, object ReferenceObject, Vector3 Position, int Rotation, RoomInstance Instance)
        {
            mId = Id;
            mType = Type;
            mReferenceId = ReferenceId;
            mReferenceObject = ReferenceObject;
            mPosition = Position;
            mBodyRotation = Rotation;
            mHeadRotation = Rotation;
            mUpdateNeeded = true;
            mStatusses = new Dictionary<string, string>();
            mInstance = Instance;
            mEnableClipping = true;
            mMovementSyncRoot = new object();

            mPathfinder = PathfinderManager.CreatePathfinderInstance();
            mPathfinder.SetRoomInstance(mInstance, Id);
        }
Beispiel #37
0
        private static void UserExit(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor == null)
            {
                return;
            }

            Actor.LeaveRoom();
        }
Beispiel #38
0
        private static void GetMoodlightInfo(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null || !Instance.CheckUserRights(Session, true))
            {
                return;
            }

            Item Item = Instance.MoodlightItem;

            if (Item == null)
            {
                return;
            }

            Session.SendData(MoodlightDataComposer.Compose(MoodlightData.GenerateFromFlags(Item.Flags)));
        }
Beispiel #39
0
        private static void TypingStateChanged(Session Session, ClientMessage Message)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId);

            if (Instance == null)
            {
                return;
            }

            RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

            if (Actor == null)
            {
                return;
            }

            Actor.SetTypingState((Message.Id == OpcodesIn.ROOM_CHAT_START_TYPING));
        }
Beispiel #40
0
        private static bool HandleBottle(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
                case ItemEventType.Placed:
                case ItemEventType.Removing:

                    if (Item.Flags != "0")
                    {
                        Item.Flags = "0";
                        Item.DisplayFlags = "0";

                        RoomManager.MarkWriteback(Item, true);
                    }

                    break;

                case ItemEventType.Interact:

                    if (Item.Flags != "-1")
                    {
                        Item.Flags = "-1";
                        Item.DisplayFlags = "-1";

                        Item.BroadcastStateUpdate(Instance);
                        Item.RequestUpdate(4);
                    }

                    break;

                case ItemEventType.UpdateTick:

                    Item.Flags = RandomGenerator.GetNext(0, 7).ToString();
                    Item.DisplayFlags = Item.Flags;

                    Item.BroadcastStateUpdate(Instance);

                    RoomManager.MarkWriteback(Item, true);

                    break;
            }

            return true;
        }
Beispiel #41
0
        private static bool HandleWired(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event) {
            case ItemEventType.Interact:
                switch (Item.Definition.Behavior) {
                case ItemBehavior.WiredTrigger:
                    Session.SendData (WiredFurniTriggerComposer.Compose (Item, Instance));
                    break;

                case ItemBehavior.WiredEffect:
                    Session.SendData (WiredFurniActionComposer.Compose (Item, Instance));
                    break;
                }
                break;
            case ItemEventType.Placed:
                Item.WiredData = Instance.WiredManager.LoadWired (Item.Id, Item.Definition.BehaviorData);
                break;
            case ItemEventType.Removing:
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) {
                    Instance.WiredManager.RemoveWired (Item.Id, MySqlClient);
                }

                Instance.WiredManager.DeRegisterWalkItem(Item.Id);
                break;
            case ItemEventType.UpdateTick:
                if (Item.Definition.Behavior == ItemBehavior.WiredTrigger) {
                    switch (WiredTypesUtil.TriggerFromInt (Item.Definition.BehaviorData)) {
                    case WiredTriggerTypes.periodically:
                        Instance.WiredManager.ExecuteActions (Item, null);
                        Item.RequestUpdate (Item.WiredData.Data2);
                        break;
                    case WiredTriggerTypes.at_given_time:
                        Instance.WiredManager.ExecuteActions (Item, null);
                        break;
                    }
                    return true;
                }
                Item.BroadcastStateUpdate (Instance);
                break;
            }
            return true;
        }
        private static bool HandleAlert(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
                case ItemEventType.InstanceLoaded:
                case ItemEventType.Placed:
                case ItemEventType.Removing:

                    Item.Flags = "0";
                    Item.DisplayFlags = "0";
                    break;

                case ItemEventType.Interact:

                    if (!Instance.CheckUserRights(Session) || Item.Flags == "1")
                    {
                        break;
                    }

                    Item.Flags = "1";
                    Item.DisplayFlags = "1";

                    Item.RequestUpdate(4);
                    Item.BroadcastStateUpdate(Instance);
                    break;

                case ItemEventType.UpdateTick:

                    if (Item.Flags != "1")
                    {
                        break;
                    }

                    Item.Flags = "0";
                    Item.DisplayFlags = "0";

                    Item.BroadcastStateUpdate(Instance);
                    break;
            }

            return true;
        }
Beispiel #43
0
        private static bool HandleRental(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
                case ItemEventType.Placed:
                case ItemEventType.InstanceLoaded:

                    if (Item.PendingExpiration)
                    {
                        int DesiredTicks = (int)((double)(Math.Ceiling(Item.ExpireTimeLeft * 2)));

                        if (DesiredTicks <= 0)
                        {
                            goto case ItemEventType.UpdateTick;
                        }

                        Item.RequestUpdate(DesiredTicks);
                        return true;
                    }

                    break;

                case ItemEventType.UpdateTick:

                    if (Item.PendingExpiration)
                    {
                        using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                        {
                            Item.RemovePermanently(MySqlClient);
                            Instance.TakeItem(Item.Id);
                            Instance.RegenerateRelativeHeightmap();
                        }

                        return true;
                    }

                    break;
            }

            return HandleGenericSwitch(Session, Item, Instance, Event, RequestData);
        }
Beispiel #44
0
        private static bool HandleRoller(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
                case ItemEventType.UpdateTick:

                    List<RoomActor> ActorsToMove = Instance.GetActorsOnPosition(Item.RoomPosition.GetVector2());
                    List<Item> ItemsToMove = new List<Item>();

                    if (ActorsToMove != null)
                    {
                        foreach (RoomActor Actor in ActorsToMove)
                        {
                            if (Actor.IsMoving)
                            {
                                continue;
                            }

                            if (Instance.IsValidStep(Actor.Position.GetVector2(), Item.SquareInFront, true))
                            {
                                Actor.PositionToSet = Item.SquareInFront;
                                Instance.BroadcastMessage(RollerEventComposer.Compose(Actor.Position, new Vector3(
                                    Actor.PositionToSet.X, Actor.PositionToSet.Y,
                                    Instance.GetUserStepHeight(Actor.PositionToSet)), Item.Id, Actor.Id, 0));
                            }
                        }
                    }

                    goto case ItemEventType.InstanceLoaded;

                case ItemEventType.InstanceLoaded:
                case ItemEventType.Placed:

                    Item.RequestUpdate(4);
                    break;
            }

            return true;
        }
        public static ServerMessage Compose(RoomInfo Info, RoomInstance Instance)
        {
            ReadOnlyCollection<string> Tags = Info.Tags;
            RoomEvent Event = (Instance == null ? null : Instance.Event);

            ServerMessage Message = new ServerMessage(OpcodesOut.MODERATION_ROOM_INFO);
            Message.AppendUInt32(Info.Id);
            Message.AppendInt32(Info.CurrentUsers);
            Message.AppendBoolean(Instance == null ? false : (Instance.GetActorByReferenceId(Info.OwnerId) != null));
            Message.AppendUInt32(Info.OwnerId);
            Message.AppendStringWithBreak(Info.OwnerName);
            Message.AppendUInt32(Info.Id);
            Message.AppendStringWithBreak(Info.Name);
            Message.AppendStringWithBreak(Info.Description);
            Message.AppendInt32(Tags.Count);

            foreach (string Tag in Tags)
            {
                Message.AppendStringWithBreak(Tag);
            }

            Message.AppendBoolean(Event != null);

            if (Event != null)
            {
                List<string> EventTags = Event.Tags;

                Message.AppendStringWithBreak(Event.Name);
                Message.AppendStringWithBreak(Event.Description);
                Message.AppendInt32(EventTags.Count);

                foreach (string Tag in EventTags)
                {
                    Message.AppendStringWithBreak(Tag);
                }
            }

            return Message;
        }
Beispiel #46
0
        public override void OnSelfEnterRoom(RoomInstance Instance)
        {
            mSelfActor = Instance.GetActorByReferenceId(mSelfBot.Id, RoomActorType.AiBot);

            if (mSelfActor == null)
            {
                return;
            }

            mNeedsRotation = false;
            mNextSpeechAttempt = RandomGenerator.GetNext(20, 255);
            mNextMovementAttempt = RandomGenerator.GetNext(20, 255);
            mServingItemId = 0;
            mServingActorId = 0;
            mMovingToServePos = false;
            mActorServePos = null;

            if (mSelfBot.Rotation >= 0)
            {
                mSelfActor.BodyRotation = mSelfBot.Rotation;
                mSelfActor.HeadRotation = mSelfBot.Rotation;
            }
        }
Beispiel #47
0
        private static bool HandleSwitch(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            if (Event != ItemEventType.Interact) {
                return true;
            }
            RoomActor actor = Instance.GetActor (Session.CharacterId);
            if (actor == null) {
                return true;
            }

            foreach (Item item in Instance.GetFloorItems()) {
                if (item.Definition.Behavior != ItemBehavior.WiredTrigger || WiredTypesUtil.TriggerFromInt (item.Definition.BehaviorData) != WiredTriggerTypes.state_changed) {
                    continue;
                }

                String[] Selected = item.WiredData.Data1.Split ('|');

                if (Selected.Contains (Item.Id.ToString ())) {
                    Instance.WiredManager.ExecuteActions (item, actor);
                }
            }
            return true;
        }
Beispiel #48
0
        public static void EnterRoom(Session Session, RoomInstance Instance)
        {
            if (!Session.RoomAuthed || Session.RoomJoined || Session.AbsoluteRoomId != Instance.RoomId)
            {
                return;
            }

            Session.SendData(RoomUrlComposer.Compose("http://www.meth0d.org/snowlight"));
            Session.SendData(RoomEntryModelComposer.Compose(Instance.Model.Id, Instance.Info.Id));

            if (Instance.Info.Type == RoomType.Flat)
            {
                Dictionary<string, string> Decorations = Instance.Info.Decorations;

                foreach (KeyValuePair<string, string> Decoration in Decorations)
                {
                    Session.SendData(RoomDecorationComposer.Compose(Decoration.Key, Decoration.Value));
                }

                Session.SendData(RoomRatingInfoComposer.Compose((Session.RatedRoomsCache.HasRatedRoom(Instance.RoomId) || Instance.CheckUserRights(Session, true)) ? Instance.Info.Score : -1));
                Session.SendData(RoomEventInfoComposer.Compose(Instance.Event));
            }
        }
        public static ServerMessage Compose(Item Item, RoomInstance Instance)
        {
            // com.sulake.habbo.communication.messages.incoming.userdefinedroomevents.WiredFurniTriggerEvent;
            ServerMessage Message = new ServerMessage (650);
            Message.AppendInt32 (0);
            Message.AppendInt32 (5);

            if (Item.WiredData.Data1.Contains ("|")) {
                String[] Selected = Item.WiredData.Data1.Split ('|');
                Message.AppendInt32 (Selected.Length-1);
                foreach (String selected in Selected) {
                    if(selected == "") {
                        continue;
                    }
                    int result;
                    Int32.TryParse (selected, out result);
                    Message.AppendInt32 (result);
                }
            } else {
                Message.AppendInt32 (0);
            }

            Message.AppendUInt32 (Item.Definition.SpriteId);
            Message.AppendInt32 ((int)Item.Id);
            Message.AppendStringWithBreak (Item.WiredData.Data1);
            Message.AppendInt32 (1);
            Message.AppendInt32 (Item.WiredData.Data2);
            Message.AppendInt32 (0);
            Message.AppendInt32 (Item.Definition.BehaviorData);
            List<Item> Items = Instance.WiredManager.TriggerRequiresActor (Item.Definition.BehaviorData, Item.RoomPosition.GetVector2 ());
            Message.AppendInt32 (Items.Count); // Contains Event that needs a User, but there is a trigger, that isn't triggered by a User
            foreach (Item Blocked in Items) {
                Message.AppendUInt32 (Blocked.Definition.SpriteId);
            }
            return Message;
        }
Beispiel #50
0
        private static bool HandleGenericSwitch(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
                case ItemEventType.Interact:

                    if (!Instance.CheckUserRights(Session))
                    {
                        return true;
                    }

                    int CurrentState = 0;
                    int.TryParse(Item.Flags, out CurrentState);

                    int NewState = CurrentState + 1;

                    if (CurrentState < 0 || CurrentState >= (Item.Definition.BehaviorData - 1))
                    {
                        NewState = 0;
                    }

                    if (CurrentState != NewState)
                    {
                        Item.Flags = NewState.ToString();
                        Item.DisplayFlags = Item.Flags;

                        RoomManager.MarkWriteback(Item, true);

                        Item.BroadcastStateUpdate(Instance);
                    }

                    break;
            }

            return true;
        }
Beispiel #51
0
        private static bool HandleFixedGateSwitch(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
                case ItemEventType.Interact:

                    if (!Instance.CheckUserRights(Session))
                    {
                        return true;
                    }

                    List<Vector2> GateTiles = Instance.CalculateAffectedTiles(Item, Item.RoomPosition.GetVector2(), Item.RoomRotation);

                    foreach (Vector2 Tile in GateTiles)
                    {
                        if (Instance.GetActorsOnPosition(Tile).Count > 0)
                        {
                            return true;
                        }
                    }

                    int CurrentState = 0;
                    int.TryParse(Item.Flags, out CurrentState);

                    Item.Flags = (CurrentState == 0 ? 1 : 0).ToString();
                    Item.DisplayFlags = Item.Flags;

                    RoomManager.MarkWriteback(Item, true);

                    Item.BroadcastStateUpdate(Instance);
                    Instance.RegenerateRelativeHeightmap();
                    break;
            }

            return true;
        }
Beispiel #52
0
        public static ServerMessage Compose(RoomInstance Instance)
        {
            ServerMessage Message = new ServerMessage(OpcodesOut.ROOM_EDIT_INFO);
            Message.AppendUInt32(Instance.Info.Id);
            Message.AppendStringWithBreak(Instance.Info.Name);
            Message.AppendStringWithBreak(Instance.Info.Description);
            Message.AppendInt32((int)Instance.Info.AccessType);
            Message.AppendInt32(Instance.Info.CategoryId);
            Message.AppendInt32(Instance.Info.MaxUsers);
            Message.AppendInt32(Instance.Model.MaxUsers);
            Message.AppendInt32(Instance.Info.Tags.Count);

            foreach (string Tag in Instance.Info.Tags)
            {
                Message.AppendStringWithBreak(Tag);
            }

            Message.AppendInt32(Instance.UsersWithRights.Count);

            foreach (uint User in Instance.UsersWithRights)
            {
                Message.AppendUInt32(User);
                Message.AppendStringWithBreak(CharacterResolverCache.GetNameFromUid(User));
            }

            // GQjl~rkfasfs!qwHHQFQFHHHIHIHHH

            Message.AppendInt32(Instance.UsersWithRights.Count);
            Message.AppendBoolean(Instance.Info.AllowPets);
            Message.AppendBoolean(Instance.Info.AllowPetEating);
            Message.AppendBoolean(Instance.Info.DisableRoomBlocking);
            Message.AppendBoolean(Instance.Info.HideWalls);
            Message.AppendInt32(Instance.Info.WallThickness);
            Message.AppendInt32(Instance.Info.FloorThickness);
            return Message;
        }
Beispiel #53
0
        private static bool HandleStepSwitch(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
                case ItemEventType.InstanceLoaded:
                case ItemEventType.Moved:
                case ItemEventType.Placed:

                    Item.RequestUpdate(1);
                    break;

                case ItemEventType.UpdateTick:

                    string Flags = "0";

                    if (Instance.GetActorsOnPosition(Item.RoomPosition.GetVector2()).Count > 0)
                    {
                        Flags = "1";
                    }

                    if (Item.DisplayFlags != Flags)
                    {
                        Item.DisplayFlags = Flags;
                        Item.BroadcastStateUpdate(Instance);
                    }

                    Item.RequestUpdate(1);
                    break;
            }

            return true;
        }
Beispiel #54
0
        private static bool HandleScoreboard(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            switch (Event)
            {
                case ItemEventType.Interact:

                    if (!Instance.CheckUserRights(Session))
                    {
                        break;
                    }

                    RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

                    if (Actor == null)
                    {
                        break;
                    }

                    if (!Distance.TilesTouching(Actor.Position.GetVector2(), Item.RoomPosition.GetVector2()))
                    {
                        Actor.MoveToItemAndInteract(Item, RequestData);
                        break;
                    }

                    int Val = 0;
                    int.TryParse(Item.DisplayFlags, out Val);

                    if (RequestData == 1)
                    {
                        Val--;

                        if (Val < 0)
                        {
                            Val = 99;
                        }
                    }
                    else if (RequestData == 2)
                    {
                        Val++;

                        if (Val > 99)
                        {
                            Val = 0;
                        }
                    }
                    else
                    {
                        Val = (Val == -1 ? 0 : -1);
                    }

                    Item.DisplayFlags = Val.ToString();
                    Item.BroadcastStateUpdate(Instance);
                    break;
            }

            return true;
        }
Beispiel #55
0
        private static bool HandleOneWayGate(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
                case ItemEventType.InstanceLoaded:
                case ItemEventType.Moved:
                case ItemEventType.Placed:

                    if (Item.DisplayFlags != "0")
                    {
                        Item.DisplayFlags = "0";
                        Item.BroadcastStateUpdate(Instance);
                    }

                    foreach (uint ActorId in Item.TemporaryInteractionReferenceIds.Values)
                    {
                        RoomActor ActorToUnlock = Instance.GetActor(ActorId);

                        if (ActorToUnlock != null)
                        {
                            ActorToUnlock.UnblockWalking();
                        }
                    }

                    Item.TemporaryInteractionReferenceIds.Clear();
                    break;

                case ItemEventType.Interact:

                    RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

                    if (Actor == null)
                    {
                        break;
                    }

                    if (Actor.Position.X != Item.SquareInFront.X || Actor.Position.Y != Item.SquareInFront.Y)
                    {
                        Actor.MoveToItemAndInteract(Item, RequestData, Opcode);
                        break;
                    }

                    if (Item.TemporaryInteractionReferenceIds.Count == 0 && Instance.IsValidStep(Item.RoomPosition.GetVector2(),
                        Item.SquareBehind, true) && Item.DisplayFlags == "0")
                    {
                        Actor.BlockWalking();
                        Actor.MoveTo(Item.RoomPosition.GetVector2(), true, true, true);
                        Item.TemporaryInteractionReferenceIds.Add(1, Actor.Id);
                        Item.RequestUpdate(1);
                    }

                    break;

                case ItemEventType.UpdateTick:

                    RoomActor UpdateActor = null;

                    if (Item.TemporaryInteractionReferenceIds.ContainsKey(1))
                    {
                        UpdateActor = Instance.GetActor(Item.TemporaryInteractionReferenceIds[1]);
                    }

                    if (UpdateActor == null || !Instance.IsValidStep(Item.RoomPosition.GetVector2(), Item.SquareBehind, true)
                        || ((UpdateActor.Position.X != Item.RoomPosition.X || UpdateActor.Position.Y !=
                        Item.RoomPosition.Y) && (UpdateActor.Position.X != Item.SquareInFront.X ||
                        UpdateActor.Position.Y != Item.SquareInFront.Y)))
                    {
                        if (Item.DisplayFlags != "0")
                        {
                            Item.DisplayFlags = "0";
                            Item.BroadcastStateUpdate(Instance);
                        }

                        if (Item.TemporaryInteractionReferenceIds.Count > 0)
                        {
                            Item.TemporaryInteractionReferenceIds.Clear();
                        }

                        if (UpdateActor != null)
                        {
                            UpdateActor.UnblockWalking();
                        }

                        break;
                    }

                    Item.DisplayFlags = "1";
                    Item.BroadcastStateUpdate(Instance);

                    UpdateActor.MoveTo(Item.SquareBehind, true, true, true);

                    Item.RequestUpdate(2);
                    break;
            }

            return true;
        }
Beispiel #56
0
        public static RoomActor TryCreateActor(uint Id, RoomActorType Type, uint ReferenceId, object ReferenceObject, Vector3 Position, int Rotation, RoomInstance Instance)
        {
            if (ReferenceObject == null)
            {
                return null;
            }

            return new RoomActor(Id, Type, ReferenceId, ReferenceObject, Position, Rotation, Instance);
        }
        private static bool HandleDispenser(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
                case ItemEventType.Moved:
                    {
                        RoomActor InteractingActor = (Item.TemporaryInteractionReferenceIds.ContainsKey(0) ?
                            Instance.GetActor(Item.TemporaryInteractionReferenceIds[0]) : null);

                        if (InteractingActor != null)
                        {
                            InteractingActor.UnblockWalking();
                        }

                        goto case ItemEventType.InstanceLoaded;
                    }
                case ItemEventType.InstanceLoaded:
                    {
                        if (Item.DisplayFlags != "0")
                        {
                            Item.DisplayFlags = "0";
                            Item.BroadcastStateUpdate(Instance);
                        }

                        return true;
                    }
                case ItemEventType.Interact:
                    {
                        RoomActor InteractingActor = Instance.GetActorByReferenceId(Session.CharacterId);

                        if (InteractingActor == null)
                        {
                            return true;
                        }

                        if (InteractingActor.Position.X != Item.SquareInFront.X || InteractingActor.Position.Y !=
                            Item.SquareInFront.Y)
                        {
                            InteractingActor.MoveToItemAndInteract(Item, RequestData, Opcode);
                            return true;
                        }

                        if (Item.TemporaryInteractionReferenceIds.Count == 0)
                        {
                            Item.TemporaryInteractionReferenceIds.Add(0, InteractingActor.Id);

                            InteractingActor.BlockWalking();
                            InteractingActor.PositionToSet = Item.SquareInFront;

                            int NewRot = Rotation.Calculate(InteractingActor.Position.GetVector2(),
                                Item.RoomPosition.GetVector2());

                            if (InteractingActor.BodyRotation != NewRot)
                            {
                                InteractingActor.BodyRotation = NewRot;
                                InteractingActor.HeadRotation = NewRot;
                                InteractingActor.UpdateNeeded = true;
                            }

                            Item.DisplayFlags = "1";
                            Item.BroadcastStateUpdate(Instance);

                            Item.RequestUpdate(2);
                        }

                        return true;
                    }

                case ItemEventType.UpdateTick:
                    {
                        if (Item.DisplayFlags != "0")
                        {
                            Item.DisplayFlags = "0";
                            Item.BroadcastStateUpdate(Instance);
                        }

                        if (Item.TemporaryInteractionReferenceIds.Count < 1)
                        {
                            return true;
                        }

                        RoomActor InteractingActor = Instance.GetActor(Item.TemporaryInteractionReferenceIds[0]);
                        Item.TemporaryInteractionReferenceIds.Clear();

                        if (InteractingActor == null)
                        {
                            return true;
                        }

                        InteractingActor.CarryItem(DrinkSetManager.GetRandomDrinkForSet(Item.Definition.BehaviorData));

                        int NewRot = Rotation.Calculate(InteractingActor.Position.GetVector2(),
                            Item.RoomPosition.GetVector2());

                        if (InteractingActor.BodyRotation != NewRot)
                        {
                            InteractingActor.BodyRotation = NewRot;
                            InteractingActor.HeadRotation = NewRot;
                            InteractingActor.UpdateNeeded = true;
                        }

                        InteractingActor.UnblockWalking();
                        return true;
                    }
            }

            return true;
        }
Beispiel #58
0
        private static bool HandleRoller(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
                case ItemEventType.UpdateTick:

                    List<RoomActor> ActorsToMove = Instance.GetActorsOnPosition(Item.RoomPosition.GetVector2());
                    List<Item> ItemsToMove = new List<Item>();
                    ItemsToMove.AddRange(Instance.GetItemsOnPosition(Item.RoomPosition.GetVector2()));

                    if (ActorsToMove != null)
                    {
                        foreach (RoomActor Actor in ActorsToMove)
                        {
                            if (Actor.IsMoving)
                            {
                                continue;
                            }

                            if (Instance.IsValidStep(Actor.Position.GetVector2(), Item.SquareInFront, true))
                            {
                                Actor.PositionToSet = Item.SquareInFront;
                                Instance.BroadcastMessage(RollerEventComposer.Compose(Actor.Position, new Vector3(
                                    Actor.PositionToSet.X, Actor.PositionToSet.Y,
                                    Instance.GetUserStepHeight(Actor.PositionToSet)), Item.Id, Actor.Id, 0));
                            }
                        }
                    }
                    if (ItemsToMove.Count != 0)
                    {
                        foreach (Item item in ItemsToMove)
                        {
                            if (item == Item)
                            {
                                continue;
                            }

                            if (Item.RoomPosition.X == item.RoomPosition.X && Item.RoomPosition.Y == item.RoomPosition.Y)
                            {
                                Vector2 NewPosition = new Vector2(Item.SquareInFront.X, Item.SquareInFront.Y);
                                int NewRotation = item.RoomRotation;
                                Vector3 FinalizedPosition = Instance.SetFloorItem(Session, item, NewPosition, NewRotation);
                                Vector3 oldpos = item.RoomPosition;

                                if (FinalizedPosition != null)
                                {
                                    item.MoveToRoom(null, Instance.RoomId, FinalizedPosition, NewRotation, string.Empty);
                                    RoomManager.MarkWriteback(item, false);

                                    Instance.RegenerateRelativeHeightmap();
                                    Instance.BroadcastMessage(RoomItemUpdatedComposer.Compose(item));

                                    ItemEventDispatcher.InvokeItemEventHandler(Session, item, Instance, ItemEventType.Moved, 0);
                                    Instance.BroadcastMessage(RollerEventComposer.Compose(oldpos, FinalizedPosition, Item.Id, 0, item.Id));
                                }
                            }
                        }
                    }

                    goto case ItemEventType.InstanceLoaded;

                case ItemEventType.InstanceLoaded:
                case ItemEventType.Placed:

                    Item.RequestUpdate(4);
                    break;
                    }

            return true;
        }
Beispiel #59
0
        private static bool HandleFireworks(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData)
        {
            int CurrentCharges = 0;
            int.TryParse(Item.Flags, out CurrentCharges);

            switch (Event)
            {
                case ItemEventType.InstanceLoaded:
                case ItemEventType.Placed:
                case ItemEventType.Moved:
                case ItemEventType.UpdateTick:

                    string DesiredDisplayFlags = "0";

                    if (CurrentCharges > 0)
                    {
                        DesiredDisplayFlags = "1";
                    }

                    if (Item.DisplayFlags != DesiredDisplayFlags)
                    {
                        Item.DisplayFlags = DesiredDisplayFlags;
                        Item.BroadcastStateUpdate(Instance);
                    }

                    break;

                case ItemEventType.Interact:

                    RoomActor Actor = Instance.GetActorByReferenceId(Session.CharacterId);

                    if (Actor == null)
                    {
                        return true;
                    }

                    if (Distance.Calculate(Actor.Position.GetVector2(), Item.RoomPosition.GetVector2()) > 1)
                    {
                        Actor.MoveToItemAndInteract(Item, RequestData, Item.SquareBehind);
                        return true;
                    }

                    switch (RequestData)
                    {
                        // Purchase charges
                        case 2:

                            if (Session.CharacterInfo.CreditsBalance < CHARGE_COSTS_CREDITS)
                            {
                                return true;
                            }

                            if (Session.CharacterInfo.ActivityPointsBalance < CHARGE_COSTS_PIXELS)
                            {
                                return true;
                            }

                            bool Update = (CurrentCharges <= 0);
                            CurrentCharges += CHARGE_AMOUNT;

                            Item.Flags = CurrentCharges.ToString();

                            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                            {
                                if (CHARGE_COSTS_CREDITS > 0)
                                {
                                    Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, -CHARGE_COSTS_CREDITS);
                                    Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance));
                                }

                                if (CHARGE_COSTS_PIXELS > 0)
                                {
                                    Session.CharacterInfo.UpdateActivityPointsBalance(MySqlClient, -CHARGE_COSTS_PIXELS);
                                    Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance,
                                        -CHARGE_COSTS_PIXELS));
                                }

                                Item.SynchronizeDatabase(MySqlClient, true);
                            }

                            Session.SendData(FireworksChargeInfoComposer.Compose(Item.Id, CurrentCharges, CHARGE_COSTS_CREDITS,
                                CHARGE_COSTS_PIXELS, CHARGE_AMOUNT));

                            if (Update)
                            {
                                Item.DisplayFlags = "1";
                                Item.BroadcastStateUpdate(Instance);
                            }

                            break;

                        case 1:

                            Session.SendData(FireworksChargeInfoComposer.Compose(Item.Id, CurrentCharges, CHARGE_COSTS_CREDITS,
                                CHARGE_COSTS_PIXELS, CHARGE_AMOUNT));
                            break;

                        default:
                        case 0:

                            if (Item.DisplayFlags == "2")
                            {
                                return true;
                            }

                            if (CurrentCharges > 0)
                            {
                                Item.DisplayFlags = "2";
                                Item.BroadcastStateUpdate(Instance);

                                Item.Flags = (--CurrentCharges).ToString();
                                RoomManager.MarkWriteback(Item, true);

                                Item.RequestUpdate(Item.Definition.BehaviorData);
                            }
                            else
                            {
                                goto case 1;
                            }

                            break;
                    }

                    break;
            }

            return true;
        }
Beispiel #60
0
        private static bool HandleJukebox(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
                case ItemEventType.Placed:
                case ItemEventType.InstanceLoaded:

                    Instance.MusicController.Reset();
                    Instance.MusicController.LinkRoomOutputItem(Item);

                    List<Item> Disks = new List<Item>();

                    using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                    {
                        Disks = LoadPlaylist(MySqlClient, Item.Id);
                    }

                    foreach (Item Disk in Disks)
                    {
                        Instance.MusicController.AddDisk(Disk);
                    }

                    if (Item.DisplayFlags == "1")
                    {
                        if (Instance.MusicController.PlaylistSize > 0)
                        {
                            Instance.MusicController.Start();
                        }
                        else
                        {
                            Item.DisplayFlags = "0";
                            Item.BroadcastStateUpdate(Instance);
                        }
                    }

                    break;

                case ItemEventType.Removing:

                    if (Instance.MusicController.IsPlaying)
                    {
                        Instance.MusicController.Stop();
                        Instance.MusicController.BroadcastCurrentSongData(Instance);
                    }

                    Instance.MusicController.Reset();
                    break;

                case ItemEventType.Interact:

                    if (!Instance.CheckUserRights(Session, true))
                    {
                        return true;
                    }

                    switch (RequestData)
                    {
                        case -1: // Open interface

                            break;

                        default: // it loves sending random numbers. as you do.

                            if (Item.DisplayFlags == "1")
                            {
                                Item.DisplayFlags = "0";
                                Instance.MusicController.Stop();
                            }
                            else
                            {
                                if (Instance.MusicController.PlaylistSize < 1)
                                {
                                    break;
                                }

                                Item.DisplayFlags = "1";
                                Instance.MusicController.Start();
                            }

                            Item.BroadcastStateUpdate(Instance);
                            RoomManager.MarkWriteback(Item, true);

                            Instance.MusicController.BroadcastCurrentSongData(Instance);
                            break;
                    }

                    break;
            }

            return true;
        }