Exemplo n.º 1
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;
        }
Exemplo n.º 2
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.º 3
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;
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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;
                        }

                        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;
        }
Exemplo n.º 7
0
        private static bool HandleATM(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 (InteractingSession.CharacterInfo.Gathering == 1)
                        {
                            InteractingSession.SendData(RoomChatComposer.Compose(InteractingActor.Id, "[ATM] You are already logged in!", 0, ChatType.Whisper));
                            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);

                        Item.TemporaryInteractionReferenceIds.Clear();

                        if (InteractingActor == null)
                        {
                            return true;
                        }
                        SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient();
                        InteractingSession.CharacterInfo.UpdateGathering(1);

                        InteractingSession.SendData(RoomChatComposer.Compose(InteractingActor.Id, "[ATM] Processing transaction please wait...", 0, ChatType.Whisper));
                        int amount = InteractingSession.CharacterInfo.ATMamount;
                        if (amount > InteractingSession.CharacterInfo.Bank)
                        {
                            InteractingSession.SendData(RoomChatComposer.Compose(InteractingActor.Id, "[ATM] You do not have " + amount + " in your bank account", 0, ChatType.Whisper));
                            InteractingActor.UnblockWalking();
                            InteractingSession.CharacterInfo.UpdateGathering(0);
                            return true;
                        }

                        System.Threading.Thread.Sleep(2000);
                        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, "[ATM] Transaction succesful!", 0, ChatType.Whisper));

                        Instance.BroadcastMessage(RoomChatComposer.Compose(InteractingActor.Id, "*Withdraws " + amount + "$ from their account*", 0, ChatType.Shout));

                        InteractingActor.UnblockWalking();
                        InteractingSession.CharacterInfo.UpdateGathering(0);

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

                        return true;
                    }
            }

            return true;
        }
Exemplo n.º 8
0
        public override void PerformUpdate(RoomInstance Instance)
        {
            if (mNextSpeechAttempt <= 0)
            {
                string Message = BotManager.GetRandomSpeechForBotDefinition(mSelfBot.DefinitionId);

                if (Message != null && Message.Length > 0)
                {
                    mSelfActor.Chat(Message);
                }

                mNextSpeechAttempt = RandomGenerator.GetNext(0, 255);
            }
            else
            {
                mNextSpeechAttempt--;
            }
            if (mSelfActor != null)
            {
                if (!mSelfActor.IsMoving && mNextMovementAttempt <= 0)
                {
                    switch (mSelfBot.WalkMode)
                    {
                        default:
                        case BotWalkMode.STAND:

                            break;

                        case BotWalkMode.FREEROAM:

                            Vector2 position = new Vector2(RandomGenerator.GetNext(0, Instance.Model.Heightmap.SizeX - 1),
                                RandomGenerator.GetNext(0, Instance.Model.Heightmap.SizeY - 1));
                            mSelfActor.MoveTo(position);
                            break;

                        case BotWalkMode.SPECIFIED_RANGE:

                            ReadOnlyCollection<Vector2> Possibilites = mSelfBot.PredefinedPositions;
                            mSelfActor.MoveTo(Possibilites[RandomGenerator.GetNext(0, (Possibilites.Count - 1))]);
                            break;
                    }

                    mNextMovementAttempt = RandomGenerator.GetNext(0, 180);
                    mNeedsRotation = true;
                }
                else
                {
                    mNextMovementAttempt--;

                    if (!mSelfActor.IsMoving)
                    {
                        if (mMovingToServePos)
                        {
                            mMovingToServePos = false;
                            mSelfActor.CarryItem(mServingItemId);
                            mSelfActor.MoveTo(mActorServePos);
                        }
                        else if (mServingItemId > 0)
                        {
                            mSelfActor.CarryItem(0);

                            RoomActor TargetActor = Instance.GetActor(mServingActorId);

                            if (TargetActor != null)
                            {
                                TargetActor.CarryItem(mServingItemId);

                                int NewRot = Rotation.Calculate(mActorServePos, TargetActor.Position.GetVector2());

                                mSelfActor.HeadRotation = NewRot;
                                mSelfActor.BodyRotation = NewRot;
                                mNeedsRotation = true;

                                mSelfActor.UpdateNeeded = true;
                            }

                            mServingItemId = 0;
                        }
                        else if (mNeedsRotation && mSelfBot.Rotation >= 0)
                        {
                            mSelfActor.BodyRotation = mSelfBot.Rotation;
                            mSelfActor.HeadRotation = mSelfBot.Rotation;
                            mNeedsRotation = false;
                        }
                    }
                }
            }
        }
Exemplo n.º 9
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:
                    using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                    {
                        DataRow Row1 = MySqlClient.ExecuteQueryRow("SELECT * FROM groups_details WHERE id = '" + Session.CharacterInfo.GroupID + "'");
                        DataRow Row2 = MySqlClient.ExecuteQueryRow("SELECT * FROM characters WHERE id = '" + Session.CharacterInfo.Id + "'");
                        DataRow Row3 = MySqlClient.ExecuteQueryRow("SELECT * FROM jobranks WHERE jobid = '" + Session.CharacterInfo.GroupID + "' AND rankid = '" + Row2["jobrank"] + "'");
                        int room_id = (int)Row1["roomid"];
                        bool isPolice = false;
                        if ((string)Row3["type"] == "police" && Session.CharacterInfo.Working == 1)
                        {
                            isPolice = true;
                        }
                        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.Definition.SpriteId == 2597 && Session.CharacterInfo.Dead == 1 || Session.CharacterInfo.Jailed == 1)
                        {
                            Session.SendData(RoomChatComposer.Compose(Actor.Id, "You are either dead or jailed, You cannot escape!", 0, ChatType.Whisper));
                            return false;
                        }
                        if (!isPolice)
                        {
                            if (Item.Definition.SpriteId == 2600 && Session.CharacterInfo.Working == 0 || Item.Definition.SpriteId == 2600 && room_id == 0 || Item.Definition.SpriteId == 2600 && room_id != Session.CurrentRoomId)
                            {
                                Session.SendData(RoomChatComposer.Compose(Actor.Id, "You either dont work here or you're not working!", 0, ChatType.Whisper));
                                return false;
                            }
                        }

                        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;
        }