Example #1
0
        public void UpdateActorStatus(RoomActor Actor)
        {
            try
            {
                Vector2 Redirection = mRedirectGrid[Actor.Position.X, Actor.Position.Y];

                if (Redirection != null)
                {
                    Actor.Position = new Vector3(Redirection.X, Redirection.Y, GetUserStepHeight(Redirection));
                }

                RoomTileEffect Effect = mTileEffects[Actor.Position.X, Actor.Position.Y];

                if (Effect == null)
                {
                    return;
                }

                Dictionary<string, string> CurrentStatusses = Actor.UserStatusses;

                if (Effect.Type == RoomTileEffectType.Sit && !CurrentStatusses.ContainsKey("mv"))
                {
                    string OldStatus = (CurrentStatusses.ContainsKey("sit") ? CurrentStatusses["sit"] : string.Empty);
                    string NewStatus = Math.Round(Effect.InteractionHeight, 1).ToString().Replace(',', '.');

                    if (Actor.BodyRotation != Effect.Rotation)
                    {
                        Actor.BodyRotation = Effect.Rotation;
                        Actor.HeadRotation = Effect.Rotation;
                        Actor.UpdateNeeded = true;
                    }

                    if (NewStatus != OldStatus)
                    {
                        Actor.SetStatus("sit", NewStatus);
                        Actor.UpdateNeeded = true;
                    }
                }
                else if (CurrentStatusses.ContainsKey("sit"))
                {
                    Actor.RemoveStatus("sit");
                    Actor.UpdateNeeded = true;
                }

                if (Effect.Type == RoomTileEffectType.Lay && !CurrentStatusses.ContainsKey("mv"))
                {
                    string OldStatus = (CurrentStatusses.ContainsKey("lay") ? CurrentStatusses["lay"] : string.Empty);
                    string NewStatus = Math.Round(Effect.InteractionHeight, 1).ToString().Replace(',', '.');

                    if (Actor.BodyRotation != Effect.Rotation)
                    {
                        Actor.BodyRotation = Effect.Rotation;
                        Actor.HeadRotation = Effect.Rotation;
                        Actor.UpdateNeeded = true;
                    }

                    if (OldStatus != NewStatus)
                    {
                        Actor.SetStatus("lay", NewStatus);
                        Actor.UpdateNeeded = true;
                    }
                }
                else if (CurrentStatusses.ContainsKey("lay"))
                {
                    Actor.RemoveStatus("lay");
                    Actor.UpdateNeeded = true;
                }

                if (Effect.Type == RoomTileEffectType.Effect)
                {
                    if ((Actor.AvatarEffectId != Effect.EffectId || !Actor.AvatarEffectByItem))
                    {
                        Actor.ApplyEffect(Effect.EffectId, true, true);
                    }
                }
                else if (Actor.AvatarEffectByItem)
                {
                    int ClearEffect = 0;

                    if (Actor.Type == RoomActorType.UserCharacter)
                    {
                        Session SessionObject = SessionManager.GetSessionByCharacterId(Actor.ReferenceId);

                        if (SessionObject != null)
                        {
                            ClearEffect = SessionObject.CurrentEffect;
                        }
                    }
                    else
                    {
                        Bot BotObject = (Bot)Actor.ReferenceObject;

                        if (BotObject != null)
                        {
                            ClearEffect = BotObject.Effect;
                        }
                    }

                    Actor.ApplyEffect(ClearEffect, true, true);
                }

                if (Actor.Type == RoomActorType.UserCharacter && Effect.QuestData > 0)
                {
                    Session SessionObject = SessionManager.GetSessionByCharacterId(Actor.ReferenceId);

                    if (SessionObject != null)
                    {
                        QuestManager.ProgressUserQuest(SessionObject, QuestType.EXPLORE_FIND_ITEM, Effect.QuestData);
                    }
                }
            }
            catch (StackOverflowException e)
            {
                string text = System.IO.File.ReadAllText(Environment.CurrentDirectory + "\\error-log.txt");
                Output.WriteLine("Error in Pathfinder: " + e.Message);
                System.IO.StreamWriter file = new System.IO.StreamWriter(Environment.CurrentDirectory + "\\error-log.txt");
                file.WriteLine(text + "Error in Pathfinder: " + e.Message + "\n\n" + e.StackTrace,
                    OutputLevel.Notification + "\n\n");
            }
        }
Example #2
0
        public void ExecuteActions(Item Item, RoomActor Actor)
        {
            try
            {
                Random rnd = new Random();
                foreach (Item ActionItem in mInstance.GetItemsOnPosition(Item.RoomPosition.GetVector2()))
                {
                    if (ActionItem.Definition.Behavior == ItemBehavior.WiredEffect)
                    {
                        ActionItem.DisplayFlags = "1";
                        ActionItem.BroadcastStateUpdate(mInstance);
                        ActionItem.DisplayFlags = "2";
                        ActionItem.RequestUpdate(4);
                        Session Session = null;
                        if (Actor != null)
                        {
                            Session = SessionManager.GetSessionByCharacterId(Actor.ReferenceId);
                        }
                        RoomInstance Instance = mInstance;
                        if (Actor != null)
                        {
                            Instance = RoomManager.GetInstanceByRoomId(Actor.CurrentRoomId);
                        }

                        int time = 0;
                        if (mWired[ActionItem.Id].Time != 0)
                        {
                            time = mWired[ActionItem.Id].Time * 100;
                            time = time % 2;
                            time = time * 10;
                        }

                        switch (WiredTypesUtil.EffectFromInt(ActionItem.Definition.BehaviorData))
                        {
                            #region reset_timer
                            case WiredEffectTypes.reset_timer:
                                // for every item in the room...
                                foreach (Item nItem in Instance.GetFloorItems())
                                {
                                    // if the item is a wired trigger
                                    if (nItem.Definition.Behavior == ItemBehavior.WiredTrigger)
                                    {
                                        //if the item is Trigger: At Set Time
                                        if (nItem.Definition.BehaviorData == 3)
                                        {
                                            //reset the timer
                                            nItem.RequestUpdate(nItem.WiredData.Data2);
                                        }
                                    }
                                }
                                break;
                            #endregion
                            #region give_clothes
                            case WiredEffectTypes.give_clothes:
                                if (Actor != null)
                                {
                                    string figure = Actor.Figure.ToString();
                                    int colorcode = 70;
                                    int Color = mWired[ActionItem.Id].Data2;
                                    if (Color == 1)
                                    {
                                        colorcode = 70;
                                    }
                                    else if (Color == 2)
                                    {
                                        colorcode = 85;
                                    }
                                    else if (Color == 3)
                                    {
                                        colorcode = 82;
                                    }
                                    else if (Color == 4)
                                    {
                                        colorcode = 1321;
                                    }
                                    if (Actor.Gender == Characters.CharacterGender.Male)
                                    {
                                        figure = "sh-290-" + colorcode + ".ch-215-" + colorcode + ".lg-275-" + colorcode + "";
                                    }
                                    else if (Actor.Gender == Characters.CharacterGender.Female)
                                    {
                                        figure = "sh-725-" + colorcode + ".ch-635-" + colorcode + ".lg-700-" + colorcode + "";
                                    }
                                    Instance.BroadcastMessage(UserInfoUpdateComposer.Compose(Actor.Id, FigToUniFig(Actor.Figure) + figure, Session.CharacterInfo.Gender, Actor.Motto, Session.CharacterInfo.Score));
                                    Session.CharacterInfo.NewFigure = FigToUniFig(Actor.Figure) + figure;
                                    Actor.NewFigure = FigToUniFig(Actor.Figure) + figure;
                                }
                                break;
                            #endregion
                            #region give_clothes_back
                            case WiredEffectTypes.give_clothes_back:
                                if (Actor == null)
                                {
                                    continue;
                                }
                                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                                {
                                    DataRow Row2 = MySqlClient.ExecuteQueryRow("SELECT * FROM characters WHERE id = '" + Actor.ReferenceId + "'");
                                    string figure = (string)Row2["figure"];
                                    Instance.BroadcastMessage(UserInfoUpdateComposer.Compose(Actor.Id, figure, Session.CharacterInfo.Gender, Actor.Motto, Session.CharacterInfo.Score));
                                    Session.CharacterInfo.NewFigure = figure;
                                    Actor.NewFigure = figure;
                                }
                                break;
                            #endregion
                            #region show_message
                            case WiredEffectTypes.show_message:
                                if (Actor == null)
                                {
                                    continue;
                                }
                                System.Threading.Thread.Sleep(time);
                                Actor.Whisper(mWired[ActionItem.Id].Data1, 0, true);
                                break;
                            #endregion
                            #region move_rotate
                            case WiredEffectTypes.move_rotate:
                                if (ActionItem.WiredData.Data2 == 0 && ActionItem.WiredData.Data3 == 0)
                                {
                                    continue;
                                }
                                System.Threading.Thread.Sleep(time);
                                String[] ItemsToMove = ActionItem.WiredData.Data1.Split('|');
                                foreach (String toMove in ItemsToMove)
                                {
                                    uint ItemId;
                                    uint.TryParse(toMove, out ItemId);
                                    Item Move = mInstance.GetItem(ItemId);
                                    if (Move == null)
                                    {
                                        continue;
                                    }
                                    Vector2 NewPosition = new Vector2(Move.RoomPosition.X, Move.RoomPosition.Y);
                                    Vector2 OldPosition = new Vector2(Move.RoomPosition.X, Move.RoomPosition.Y);

                                    switch (ActionItem.WiredData.Data2)
                                    {
                                        case 1:
                                            switch (rnd.Next(1, 5))
                                            {
                                                case 1:
                                                    NewPosition = new Vector2(Move.RoomPosition.X - 1, Move.RoomPosition.Y);
                                                    break;
                                                case 2:
                                                    NewPosition = new Vector2(Move.RoomPosition.X + 1, Move.RoomPosition.Y);
                                                    break;

                                                case 3:
                                                    NewPosition = new Vector2(Move.RoomPosition.X, Move.RoomPosition.Y + 1);
                                                    break;

                                                case 4:
                                                    NewPosition = new Vector2(Move.RoomPosition.X, Move.RoomPosition.Y - 1);
                                                    break;
                                            }
                                            break;
                                        case 2:
                                            if (rnd.Next(0, 2) == 1)
                                            {
                                                NewPosition = new Vector2(Move.RoomPosition.X - 1, Move.RoomPosition.Y);
                                            }
                                            else
                                            {
                                                NewPosition = new Vector2(Move.RoomPosition.X + 1, Move.RoomPosition.Y);
                                            }

                                            break;
                                        case 3:
                                            if (rnd.Next(0, 2) == 1)
                                            {
                                                NewPosition = new Vector2(Move.RoomPosition.X, Move.RoomPosition.Y - 1);
                                            }
                                            else
                                            {
                                                NewPosition = new Vector2(Move.RoomPosition.X, Move.RoomPosition.Y + 1);
                                            }

                                            break;
                                        case 4:
                                            NewPosition = new Vector2(Move.RoomPosition.X, Move.RoomPosition.Y - 1);
                                            break;
                                        case 5:
                                            NewPosition = new Vector2(Move.RoomPosition.X + 1, Move.RoomPosition.Y);
                                            break;
                                        case 6:
                                            NewPosition = new Vector2(Move.RoomPosition.X, Move.RoomPosition.Y + 1);
                                            break;
                                        case 7:
                                            NewPosition = new Vector2(Move.RoomPosition.X - 1, Move.RoomPosition.Y);
                                            break;
                                    }

                                    int NewRotation = Move.RoomRotation;

                                    switch (ActionItem.WiredData.Data3)
                                    {
                                        case 1:
                                            NewRotation = NewRotation + 2;
                                            if (NewRotation == 8)
                                            {
                                                NewRotation = 0;
                                            }
                                            break;

                                        case 2:
                                            NewRotation = (NewRotation - 2);
                                            if (NewRotation == -2)
                                            {
                                                NewRotation = 6;
                                            }
                                            break;
                                        case 3:
                                            if (rnd.Next(0, 2) == 1)
                                            {
                                                goto case 1;
                                            }
                                            else
                                            {
                                                goto case 2;
                                            }
                                    }

                                    bool IsRotationOnly = (ActionItem.WiredData.Data2 == 0);
                                    Vector3 FinalizedPosition = mInstance.SetFloorItem(null, Move, NewPosition, NewRotation);
                                    Vector3 FinalizedOld = mInstance.SetFloorItem(null, Move, OldPosition, NewRotation);

                                    if (FinalizedPosition != null)
                                    {
                                        Move.MoveToRoom(null, mInstance.RoomId, FinalizedPosition, NewRotation, "");
                                        RoomManager.MarkWriteback(Move, false);

                                        mInstance.RegenerateRelativeHeightmap();
                                        mInstance.BroadcastMessage(RoomItemUpdatedComposer.Compose(Move));
                                        mInstance.BroadcastMessage(RollerEventComposer.Compose(FinalizedOld, FinalizedPosition, Item.Id, 0, Move.Id));
                                        ItemEventDispatcher.InvokeItemEventHandler(null, Move, mInstance, ItemEventType.Moved, IsRotationOnly ? 1 : 0);

                                    }
                                }
                                break;
                            #endregion
                            #region match_to_sshot
                            case WiredEffectTypes.match_to_sshot:
                                String[] Selected = ActionItem.WiredData.Data5.Split('+');
                                foreach (String FullData in Selected)
                                {
                                    System.Threading.Thread.Sleep(time);
                                    if (!FullData.Contains('#'))
                                    {
                                        continue;
                                    }

                                    String[] Data = FullData.Split('#');
                                    if (Data.Length != 4)
                                    {
                                        continue;
                                    }

                                    uint Id = uint.Parse(Data[0]);
                                    String[] Position = Data[1].Split('|');
                                    int Rotation = int.Parse(Data[2]);
                                    String Flags = Data[3];

                                    int X = int.Parse(Position[0]);
                                    int Y = int.Parse(Position[1]);
                                    uint Z = uint.Parse(Position[2]);

                                    Item AffectedItem = mInstance.GetItem(Id);

                                    if (AffectedItem == null)
                                    {
                                        continue;
                                    }

                                    Boolean IsRotationOnly = (X == AffectedItem.RoomPosition.X && Y == AffectedItem.RoomPosition.Y && Z == AffectedItem.RoomPosition.Z);

                                    Vector2 NewPosition = new Vector2(X, Y);
                                    Vector2 OldPosition = new Vector2(AffectedItem.RoomPosition.X, AffectedItem.RoomPosition.Y);

                                    if (ActionItem.WiredData.Data2 == 1)
                                    {
                                        AffectedItem.Flags = Flags;
                                        AffectedItem.DisplayFlags = Item.Flags;
                                        AffectedItem.BroadcastStateUpdate(mInstance);
                                    }

                                    if (ActionItem.WiredData.Data3 == 0)
                                    {
                                        Rotation = AffectedItem.RoomRotation;
                                    }

                                    if (ActionItem.WiredData.Data4 == 0)
                                    {
                                        NewPosition = AffectedItem.RoomPosition.GetVector2();
                                    }

                                    if (ActionItem.WiredData.Data4 == 1 || ActionItem.WiredData.Data3 == 1)
                                    {
                                        Vector3 FinalizedPosition = mInstance.SetFloorItem(null, AffectedItem, NewPosition, Rotation);
                                        AffectedItem.MoveToRoom(null, mInstance.RoomId, FinalizedPosition, Rotation, "");

                                        RoomManager.MarkWriteback(AffectedItem, false);

                                        mInstance.RegenerateRelativeHeightmap();
                                        mInstance.BroadcastMessage(RoomItemUpdatedComposer.Compose(AffectedItem));

                                        ItemEventDispatcher.InvokeItemEventHandler(null, AffectedItem, mInstance, ItemEventType.Moved, IsRotationOnly ? 1 : 0);
                                    }
                                    else if (ActionItem.WiredData.Data2 == 1)
                                    {
                                        RoomManager.MarkWriteback(AffectedItem, true);
                                    }
                                }
                                break;
                            #endregion
                            #region teleport_to_furni
                            case WiredEffectTypes.teleport_to:
                                if (Actor == null)
                                {
                                    continue;
                                }
                                System.Threading.Thread.Sleep(time);
                                String[] Selected2 = ActionItem.WiredData.Data1.Split('|');
                                String ItemIdS = Actor.FurniOnId.ToString();

                                while (Actor.FurniOnId.ToString() == ItemIdS)
                                {
                                    ItemIdS = Selected2[rnd.Next(0, Selected2.Length)];
                                }

                                uint ItemId2;
                                uint.TryParse(ItemIdS, out ItemId2);
                                Item AffectedItem2 = mInstance.GetItem(ItemId2);
                                if (AffectedItem2 == null)
                                {
                                    continue;
                                }
                                Actor.BlockWalking();
                                int OldEffect = Actor.AvatarEffectId;
                                Actor.ApplyEffect(4);
                                Actor.PositionToSet = AffectedItem2.RoomPosition.GetVector2();
                                Actor.MoveToPos(AffectedItem2.RoomPosition.GetVector2(), true, false, true);
                                Actor.UpdateNeeded = true;
                                Actor.UnblockWalking();
                                System.Threading.Thread.Sleep(1000);
                                Actor.ApplyEffect(OldEffect);
                                break;
                            #endregion
                            #region toggle_furni_state
                            case WiredEffectTypes.toggle_state:
                                String[] Selected3 = ActionItem.WiredData.Data1.Split('|');

                                System.Threading.Thread.Sleep(time);
                                foreach (String ItemIdS2 in Selected3)
                                {
                                    uint ItemId3;
                                    uint.TryParse(ItemIdS2, out ItemId3);
                                    Item AffectedItem3 = mInstance.GetItem(ItemId3);
                                    if (AffectedItem3 == null)
                                    {
                                        continue;
                                    }

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

                                    int NewState = CurrentState + 1;

                                    if (CurrentState < 0 || CurrentState >= (AffectedItem3.Definition.BehaviorData - 1))
                                    {
                                        NewState = 0;
                                    }
                                    if (AffectedItem3.Definition.Behavior == ItemBehavior.Fireworks)
                                    {
                                        int CurrentCharges = 0;
                                        int.TryParse(AffectedItem3.Flags, out CurrentCharges);
                                        if (AffectedItem3.DisplayFlags == "2")
                                        {
                                        }
                                        else if (CurrentCharges > 0)
                                        {
                                            AffectedItem3.DisplayFlags = "2";
                                            AffectedItem3.BroadcastStateUpdate(mInstance);

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

                                            AffectedItem3.RequestUpdate(AffectedItem3.Definition.BehaviorData);
                                        }
                                    }
                                    else if (AffectedItem3.Definition.Behavior == ItemBehavior.HoloDice || AffectedItem3.Definition.Behavior == ItemBehavior.Dice)
                                    {
                                        AffectedItem3.Flags = "-1";
                                        AffectedItem3.DisplayFlags = "-1";

                                        AffectedItem3.BroadcastStateUpdate(mInstance);
                                        AffectedItem3.RequestUpdate(3);
                                    }
                                    else if (AffectedItem3.Definition.Behavior == ItemBehavior.TraxPlayer)
                                    {
                                        if (mInstance.MusicController.IsPlaying)
                                        {
                                            mInstance.MusicController.Stop();
                                            mInstance.MusicController.BroadcastCurrentSongData(mInstance);
                                            AffectedItem3.DisplayFlags = "0";
                                            AffectedItem3.BroadcastStateUpdate(mInstance);
                                        }
                                        else
                                        {
                                            if (mInstance.MusicController.PlaylistSize > 0)
                                            {
                                                mInstance.MusicController.Start();
                                                AffectedItem3.DisplayFlags = "1";
                                                AffectedItem3.BroadcastStateUpdate(mInstance);
                                            }
                                            else
                                            {
                                                AffectedItem3.DisplayFlags = "0";
                                                AffectedItem3.BroadcastStateUpdate(mInstance);
                                            }
                                        }
                                    }
                                    else if (CurrentState != NewState)
                                    {
                                        AffectedItem3.Flags = NewState.ToString();
                                        AffectedItem3.DisplayFlags = AffectedItem3.Flags;

                                        RoomManager.MarkWriteback(AffectedItem3, true);

                                        AffectedItem3.BroadcastStateUpdate(mInstance);
                                    }
                                    Instance.WiredManager.HandleToggleState(Actor, AffectedItem3);
                                }
                                break;
                            #endregion
                        }
                    }
                }
            }
            catch (StackOverflowException e)
            {
                string text = System.IO.File.ReadAllText(Environment.CurrentDirectory + "\\error-log.txt");
                Output.WriteLine("Error in Wired Action: " + e.Message);
                System.IO.StreamWriter file = new System.IO.StreamWriter(Environment.CurrentDirectory + "\\error-log.txt");
                file.WriteLine(text + "Error in Wired Action: " + e.Message + "\n\n" + e.StackTrace,
                    OutputLevel.Notification + "\n\n");
            }
        }