예제 #1
0
파일: Item.cs 프로젝트: DaimOwns/ProRP
 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));
     }
 }
예제 #2
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;
        }
예제 #3
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;
        }
예제 #4
0
        private static bool HandleRoller(Session Session, Item Item, RoomInstance Instance, ItemEventType Event, int RequestData, uint Opcode)
        {
            switch (Event)
            {
                case ItemEventType.UpdateTick:

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

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

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

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

                                    if (FinalizedPosition != null)
                                    {
                                        Instance.BroadcastMessage(RollerEventComposer.Compose(oldpos, FinalizedPosition, Item.Id, 0, item.Id));
                                        ItemEventDispatcher.InvokeItemEventHandler(Session, item, Instance, ItemEventType.Moved, 0);
                                        RoomManager.MarkWriteback(item, false);
                                        item.MoveToRoom(null, Instance.RoomId, FinalizedPosition, NewRotation, string.Empty);
                                    }
                                }
                            }
                        }
                    }
                    System.Threading.Thread.Sleep(1000);
                    Instance.RegenerateRelativeHeightmap();

                    goto case ItemEventType.InstanceLoaded;

                case ItemEventType.InstanceLoaded:
                case ItemEventType.Placed:

                    Item.RequestUpdate(18);
                    break;
            }

            return true;
        }
예제 #5
0
 public void BroadcastCurrentSongData(RoomInstance Instance)
 {
     Instance.BroadcastMessage(MusicPlayingComposer.Compose(mSong == null ? 0 : mSong.SongData.Id,
         mSongQueuePosition, 0));
 }
예제 #6
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;
        }