Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
 public override void SetRoomInstance(RoomInstance Room, uint ActorId)
 {
     mCurrentInstance = Room;
     mActorId = ActorId;
     mPath = new List<Vector2>();
     mTarget = null;
 }
Ejemplo n.º 4
0
        private static bool HandleExchangeRedemption(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            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;
        }
Ejemplo n.º 5
0
        public override void OnSelfLeaveRoom(RoomInstance Instance)
        {
            if (mSelfActor == null)
            {
                return;
            }

            mSelfActor = null;
        }
Ejemplo n.º 6
0
        public override void OnSelfLeaveRoom(RoomInstance Instance)
        {
            if (mSelfActor == null)
            {
                return;
            }

            //mSelfActor.Chat("*leaves*", false);
            mSelfActor = null;
        }
Ejemplo n.º 7
0
 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;
             }
         }
     }
 }
Ejemplo n.º 8
0
        public override void OnSelfEnterRoom(RoomInstance Instance)
        {
            mSelfActor = Instance.GetActorByReferenceId(mSelfBot.Id, RoomActorType.AiBot);

            if (mSelfActor == null)
            {
                return;
            }

            mCurrentAction = PetBotAction.Idle;
            mActionStartedTimestamp = UnixTimestamp.GetCurrent();
            mGstTimestamp = UnixTimestamp.GetCurrent();

            RespondToEvent("SEE_OWNER");
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        private static bool HandleBottle(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            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;
        }
Ejemplo n.º 12
0
        public override void OnUserChat(RoomInstance Instance, RoomActor Actor, string MessageText, bool Shout)
        {
            string Message = MessageText.ToLower().Trim();
            string PetName = mSelfBot.PetData.Name.ToLower();

            if (mSelfActor == null || mSelfBot.PetData.OwnerId != Actor.ReferenceId || Actor.Type !=
                RoomActorType.UserCharacter || !Message.StartsWith(PetName + " ") || Message.Length <= PetName.Length)
            {
                return;
            }

            if (mSelfBot.PetData.Energy < 20)
            {
                mSelfActor.SetStatus("gst", "hng");
                RespondToEvent("TIRED");
                return;
            }

            if (mSelfBot.PetData.Happiness < 20)
            {
                mSelfActor.SetStatus("gst", "sad");
                RespondToEvent("UNHAPPY");
                return;
            }

            int SkipLength = PetName.Length + 1;
            string Command = MessageText.Substring(SkipLength, MessageText.Length - SkipLength).ToLower().Trim();

            switch (Command)
            {
                case "free":

                    mSelfActor.ClearStatusses();
                    mSelfActor.Chat("All statusses cleared");
                    break;

                default:

                    mSelfActor.SetStatus(Command.ToLower());
                    mSelfActor.Chat("Effect applied: " + Command.ToLower());
                    mSelfActor.UpdateNeeded = true;
                    break;
            }
        }
Ejemplo n.º 13
0
        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;
        }
Ejemplo n.º 14
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;
        }
Ejemplo n.º 15
0
        private static bool HandleRental(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            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, 0);
        }
Ejemplo n.º 16
0
        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;
        }
Ejemplo n.º 17
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));
            }
        }
Ejemplo n.º 18
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;
            }
        }
Ejemplo n.º 19
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;
        }
Ejemplo n.º 20
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;
        }
Ejemplo n.º 21
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;
        }
Ejemplo n.º 22
0
        private static bool HandleTrashcan(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);

                        Session InteractingSession = SessionManager.GetSessionByCharacterId(InteractingActor.ReferenceId);
                        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]);
                        Session InteractingSession = SessionManager.GetSessionByCharacterId(InteractingActor.ReferenceId);

                        SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient();

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

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

                        }
                        InteractingSession.SendData(RoomChatComposer.Compose(InteractingActor.Id, "[Trashcan MSG] Transaction succesful!", 0, ChatType.Whisper));

                        Instance.BroadcastMessage(RoomChatComposer.Compose(InteractingActor.Id, "*Searches the trashcan and finds*", 0, ChatType.Shout));

                        InteractingActor.UnblockWalking();

                        InteractingSession.CharacterInfo.UpdateBank(MySqlClient, -20);
                        int newcoins = InteractingSession.CharacterInfo.CreditsBalance + 20;
                        InteractingSession.SendData(CreditsBalanceComposer.Compose(newcoins));
                        InteractingSession.CharacterInfo.UpdateCreditsBalance(MySqlClient, +20);

                        return true;
                    }
            }

            return true;
        }
Ejemplo n.º 23
0
        private static bool HandleTeleporter(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            RoomActor Actor = null;

            uint LinkedRef = 0;
            uint.TryParse(Item.Flags, out LinkedRef);

            switch (Event)
            {
                case ItemEventType.InstanceLoaded:

                    Item.DisplayFlags = "0";
                    break;

                case ItemEventType.Moved:

                    if (RequestData != 1)
                    {
                        goto case ItemEventType.Removing;
                    }

                    break;

                case ItemEventType.Removing:
                case ItemEventType.Placed:

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

                        if (Event == ItemEventType.Moved)
                        {
                            Item.BroadcastStateUpdate(Instance);
                        }
                    }

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

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

                    Item.TemporaryInteractionReferenceIds.Clear();
                    break;

                case ItemEventType.Interact:

                    if (Session != null)
                    {
                        Actor = Instance.GetActorByReferenceId(Session.CharacterId);
                    }

                    if (Actor == null)
                    {
                        break;
                    }

                    bool IsInFront = (Actor.Position.X == Item.SquareInFront.X && Actor.Position.Y == Item.SquareInFront.Y);
                    bool IsInTele = !IsInFront && (Actor.Position.X == Item.RoomPosition.X &&
                        Actor.Position.Y == Item.RoomPosition.Y);

                    if (!IsInFront && !IsInTele)
                    {
                        Actor.MoveToItemAndInteract(Item, RequestData, Opcode);
                        break;
                    }

                    if (Item.DisplayFlags == "0" && Item.TemporaryInteractionReferenceIds.Count == 0)
                    {
                        Item.TemporaryInteractionReferenceIds.Add(1, Actor.Id);
                        Actor.BlockWalking();

                        using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                        {
                            TeleporterLinkFinder.FillCache(MySqlClient, LinkedRef);
                        }

                        if (IsInTele)
                        {
                            Item.RequestUpdate(1);
                        }
                        else
                        {
                            Item.DisplayFlags = "1";
                            Actor.MoveTo(Item.RoomPosition.GetVector2(), true, true, true);

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

                    break;

                case ItemEventType.UpdateTick:

                    RoomActor OutgoingUser = null;
                    RoomActor IncomingUser = null;

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

                        if (OutgoingUser == null)
                        {
                            Item.TemporaryInteractionReferenceIds.Remove(1);
                        }
                    }

                    if (Item.TemporaryInteractionReferenceIds.ContainsKey(2))
                    {
                        IncomingUser = Instance.GetActor(Item.TemporaryInteractionReferenceIds[2]);

                        if (IncomingUser == null)
                        {
                            Item.TemporaryInteractionReferenceIds.Remove(2);
                        }
                    }

                    string EffectToApply = "0";
                    uint LinkedRoomRefId = TeleporterLinkFinder.GetValue(LinkedRef);
                    RoomInstance LinkedRoomRef = RoomManager.GetInstanceByRoomId(LinkedRoomRefId);

                    if (OutgoingUser != null)
                    {
                        Item TargetItem = null;
                        Session OutgoingSession = SessionManager.GetSessionByCharacterId(OutgoingUser.ReferenceId);

                        if (LinkedRoomRef == null && LinkedRoomRefId > 0)
                        {
                            RoomManager.TryLoadRoomInstance(LinkedRoomRefId);
                            LinkedRoomRef = RoomManager.GetInstanceByRoomId(LinkedRoomRefId);
                        }

                        if (LinkedRoomRef != null)
                        {
                            TargetItem = LinkedRoomRef.GetItem(LinkedRef);
                        }

                        if (OutgoingSession == null || OutgoingUser.Position.X != Item.RoomPosition.X ||
                            OutgoingUser.Position.Y != Item.RoomPosition.Y || (TargetItem != null &&
                            TargetItem.TemporaryInteractionReferenceIds.ContainsKey(2)))
                        {
                            OutgoingUser.UnblockWalking();
                            Item.TemporaryInteractionReferenceIds.Remove(1);
                        }
                        else if (TargetItem != null)
                        {
                            EffectToApply = "2";

                            RoomActor TeleActor = OutgoingUser;

                            if (Instance != LinkedRoomRef)
                            {
                                OutgoingSession.IsTeleporting = true;
                                OutgoingSession.TargetTeleporterId = LinkedRef;

                                RoomHandler.PrepareRoom(OutgoingSession, LinkedRoomRefId, string.Empty, true);

                                TeleActor = null;
                            }

                            if (TeleActor != null)
                            {
                                TeleActor.BlockWalking();

                                TeleActor.Position = new Vector3(TargetItem.RoomPosition.X, TargetItem.RoomPosition.Y, TargetItem.RoomPosition.Z);
                                TeleActor.BodyRotation = TargetItem.RoomRotation;
                                TeleActor.HeadRotation = TeleActor.BodyRotation;
                                TeleActor.UpdateNeeded = true;

                                if (TargetItem.DisplayFlags != "2")
                                {
                                    TargetItem.DisplayFlags = "2";
                                    TargetItem.BroadcastStateUpdate(LinkedRoomRef);
                                    TargetItem.RequestUpdate(3);
                                }

                                TargetItem.TemporaryInteractionReferenceIds.Add(2, TeleActor.Id);
                            }

                            Item.TemporaryInteractionReferenceIds.Remove(1);
                            Item.RequestUpdate(2);
                        }
                        else if (TargetItem == null)
                        {
                            EffectToApply = "1";
                            OutgoingUser.UnblockWalking();

                            if (Item.Definition.SpriteId == 5000)
                            {
                                if (Instance.IsValidStep(OutgoingUser.Position.GetVector2(), Item.SquareBehind, true))
                                {
                                    OutgoingUser.MoveTo(Item.SquareInFront);
                                }
                            }
                            else
                            {
                                if (Instance.IsValidStep(OutgoingUser.Position.GetVector2(), Item.SquareInFront, true))
                                {
                                    OutgoingUser.MoveTo(Item.SquareInFront);
                                }
                            }

                            Item.TemporaryInteractionReferenceIds.Remove(1);
                            Item.RequestUpdate(2);
                        }
                    }

                    if (IncomingUser != null)
                    {
                        if (IncomingUser.Position.X != Item.RoomPosition.X || IncomingUser.Position.Y != IncomingUser.Position.Y)
                        {
                            IncomingUser.UnblockWalking();
                            Item.TemporaryInteractionReferenceIds.Remove(2);
                        }
                        else
                        {
                            EffectToApply = "1";

                            IncomingUser.UnblockWalking();
                            Item.TemporaryInteractionReferenceIds.Remove(2);
                            if (Item.Definition.SpriteId == 5000)
                            {
                                if (Instance.CanInitiateMoveToPosition(Item.SquareBehind))
                                {
                                    IncomingUser.MoveTo(Item.SquareBehind);
                                }
                            }
                            else
                            {
                                if (Instance.CanInitiateMoveToPosition(Item.SquareInFront))
                                {
                                    IncomingUser.MoveTo(Item.SquareInFront);
                                }
                            }

                            Item.RequestUpdate(3);
                        }
                    }

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

                    break;
            }

            return true;
        }
Ejemplo n.º 24
0
 public abstract void SetRoomInstance(RoomInstance Room, uint ActorId);
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
0
        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;
                        }

                        Session InteractingSession = SessionManager.GetSessionByCharacterId(InteractingActor.ReferenceId);

                        #region Cooldown
                        TimeSpan span = DateTime.Now - Session.CharacterInfo.Cooldown;
                        if (span.Seconds < 5)
                        {
                            InteractingSession.SendData(RoomChatComposer.Compose(InteractingActor.Id, "You're cooling down! [" + span.Seconds + "/5]", 0, ChatType.Whisper));
                            return true;
                        }

                        #endregion

                        if (InteractingSession.CharacterInfo.CreditsBalance < 2)
                        {
                            InteractingSession.SendData(RoomChatComposer.Compose(InteractingActor.Id, "You don't have enough money, vending machines cost $10.", 0, ChatType.Whisper));
                            return true;
                        }

                        if (InteractingSession.CharacterInfo.Energy >= 100)
                        {
                            InteractingSession.SendData(RoomChatComposer.Compose(InteractingActor.Id, "You don't need to eat, you have enough energy.", 0, ChatType.Whisper));
                            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;
                        }
                        Session InteractingSession = SessionManager.GetSessionByCharacterId(InteractingActor.ReferenceId);

                        InteractingActor.UnblockWalking();
                        Instance.BroadcastMessage(RoomChatComposer.Compose(InteractingActor.Id, "*Grabs a tasty snack from the vending machine! [-$10 100e]*", 0, ChatType.Shout));
                        SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient();
                        int newcoins = InteractingSession.CharacterInfo.CreditsBalance - 10;
                        InteractingSession.SendData(CreditsBalanceComposer.Compose(newcoins));
                        InteractingSession.CharacterInfo.UpdateCreditsBalance(MySqlClient, -10);
                        InteractingSession.CharacterInfo.Energise(MySqlClient);
                        Session.CharacterInfo.Cooldown = DateTime.Now;

                        return true;
                    }
            }

            return true;
        }
Ejemplo n.º 27
0
        public Vector3 SetRollerFloorItem(Session Session, Item Item, Vector2 Position, int Rotation, RoomInstance Instance)
        {
            bool AlreadyContained = mItems.ContainsKey(Item.Id);
            int TotalLimitCount = AlreadyContained ? mItems.Count - 1 : mItems.Count;
            int SpecificLimitCount = mItemLimitCache.ContainsKey(Item.Definition.Behavior) ? (AlreadyContained ?
                mItemLimitCache[Item.Definition.Behavior] - 1 : mItemLimitCache[Item.Definition.Behavior]) : 0;

            bool IsRotationOnly = (Item.RoomId == RoomId && Item.RoomPosition.X == Position.X &&
                Item.RoomPosition.Y == Position.Y && Rotation != Item.RoomRotation);
            bool Override = false;
            bool validspace = (IsValidPosition(Position) && GetActorsOnPosition(Position).Count < 1);
            bool isroller = false;
            if (!IsValidItemRotation(Rotation))
            {
                return null;
            }
            foreach (Item item in GetItemsOnPosition(Position))
            {
                if (item.Definition.Behavior == ItemBehavior.Roller)
                {
                    isroller = true;
                    Override = false;
                }
                else if (item.Definition.StackingBehavior == ItemStackingBehavior.Ignore)
                {
                    isroller = false;
                    Override = true;
                }
            }
            if (GetItemsOnPosition(Position).Count > 1 && isroller)
            {
                isroller = false;
                Override = false;
            }
            else if (GetItemsOnPosition(Position).Count > 0 && !isroller)
            {
                isroller = false;
                Override = false;
            }
            List<Vector2> AffectedTiles = CalculateAffectedTiles(Item, Position, Rotation);
                double PlacementHeight = GetItemPlacementHeight(Item, AffectedTiles, IsRotationOnly, true);
                if (isroller)
                {
                    PlacementHeight = Item.RoomPosition.Z;
                }
                else if (Override)
                {
                    PlacementHeight = Item.RoomPosition.Z - 0.45;
                }
                else if (!isroller && !Override)
                {
                    PlacementHeight = (PlacementHeight) + (Item.RoomPosition.Z - 0.45);
                }
                if (!validspace)
                {
                    return null;
                }

            lock (mItemSyncRoot)
            {
                if (!mItems.ContainsKey(Item.Id))
                {
                    mItems.Add(Item.Id, Item);
                    IncrecementFurniLimitCache(Item.Definition.Behavior);
                }
            }

            return new Vector3(Position.X, Position.Y, PlacementHeight);
        }
Ejemplo n.º 28
0
 public WiredManager(RoomInstance Instance)
 {
     mInstance = Instance;
     mWired = new Dictionary<uint, WiredData>();
     mRegisteredWalkItems = new Dictionary<uint, uint>();
 }
Ejemplo n.º 29
0
 public void BroadcastStateUpdate(RoomInstance Instance)
 {
     if (mCachedDefinition.Type == ItemType.FloorItem)
     {
         Instance.BroadcastMessage(RoomFloorItemUpdateFlagsComposer.Compose(mId, mDisplayFlags));
     }
     else if (mCachedDefinition.Type == ItemType.WallItem)
     {
         Instance.BroadcastMessage(RoomWallItemMovedComposer.Compose(this));
     }
 }
Ejemplo n.º 30
0
        public void Update(RoomInstance Instance)
        {
            if (mUpdateTicks > 0)
            {
                mUpdateTicks--;
            }

            if (mUpdateNeeded && mUpdateTicks <= 0)
            {
                mUpdateNeeded = false;
                ItemEventDispatcher.InvokeItemEventHandler(null, this, Instance, ItemEventType.UpdateTick);
            }
        }