Exemplo n.º 1
0
        private static bool HandleFixedSwitchSwitch(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
                case ItemEventType.Interact:

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

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

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

                    foreach (uint RefId in Item.TemporaryInteractionReferenceIds.Values)
                    {
                        RoomActor InteractingActor = Instance.GetActor(RefId);
                    }

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

                    if (CurrentState >= (Item.Definition.BehaviorData - 1))
                    {
                        CurrentState = 0;
                        Item.Flags = CurrentState.ToString();
                        Item.DisplayFlags = CurrentState.ToString();
                    }
                    else
                    {
                        int NewState = CurrentState + 1;
                        Item.Flags = NewState.ToString();
                        Item.DisplayFlags = NewState.ToString();
                    }
                    RoomManager.MarkWriteback(Item, true);

                    Item.BroadcastStateUpdate(Instance);
                    Instance.WiredManager.HandleToggleState(Actor, Item);

                    Instance.RegenerateRelativeHeightmap();
                    break;
            }

            return true;
        }
Exemplo n.º 2
0
        private static bool HandleAlert(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            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;
        }
Exemplo n.º 3
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/Reality"));
            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));
            }
        }
Exemplo n.º 4
0
        private static bool HandleGenericSwitch(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            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;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        private static bool HandleLoveShuffler(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
                case ItemEventType.Placed:
                case ItemEventType.Removing:

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

                case ItemEventType.Interact:

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

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

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

                    break;

                case ItemEventType.UpdateTick:

                    if (Item.Flags == "0")
                    {
                        Item.Flags = RandomGenerator.GetNext(1, 4).ToString();
                        Item.DisplayFlags = Item.Flags;

                        Item.BroadcastStateUpdate(Instance);
                    }

                    RoomManager.MarkWriteback(Item, true);

                    break;
            }

            return true;
        }
Exemplo n.º 8
0
        private static bool HandleWired(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
                case ItemEventType.Interact:
                    if (!Instance.CheckUserRights(Session))
                    {
                        break;
                    }
                    {
                        switch (Item.Definition.Behavior)
                        {
                            case ItemBehavior.WiredTrigger:
                                Session.SendData(WiredFurniTriggerComposer.Compose(Item, Instance));
                                break;

                            case ItemBehavior.WiredEffect:
                                Session.SendData(WiredFurniActionComposer.Compose(Item, Instance));
                                break;

                            case ItemBehavior.WiredCondition:
                                Session.SendData(WiredFurniConditionComposer.Compose());
                                break;
                        }
                    }
                    break;
                case ItemEventType.Placed:
                case ItemEventType.InstanceLoaded:
                    Item.WiredData = Instance.WiredManager.LoadWired(Item.Id, Item.Definition.BehaviorData);
                    if (WiredTypesUtil.TriggerFromInt(Item.Definition.BehaviorData) == WiredTriggerTypes.periodically)
                    {
                        Item.RequestUpdate(Item.WiredData.Data2);
                    }
                    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;
        }
Exemplo n.º 9
0
        private static bool HandleScoreboard(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            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, Opcode);
                        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;
        }