Пример #1
0
        public void StartLoadedScript(GameInterface game)
        {
            if (isRunning)
            {
                throw new InvalidOperationException("Script is already running");
            }
            else
            {
                this.game             = game;
                unstuckDictionary     = new Dictionary <DateTime, WowPoint>();
                isRunning             = true;
                precision2D           = 3f;
                loopPath              = false;
                startFromNearestPoint = false;
                int            tCounter           = 0;
                DoActionType[] predefinedSettings = new[] { DoActionType.SetLoopPath, DoActionType.SetStartFromNearestPoint };
                while (predefinedSettings.Contains(actionsList[tCounter].ActionType))
                {
                    switch (actionsList[tCounter].ActionType)
                    {
                    case DoActionType.SetLoopPath:
                        loopPath = bool.Parse(actionsList[tCounter].Data);
                        break;

                    case DoActionType.SetStartFromNearestPoint:
                        startFromNearestPoint = bool.Parse(actionsList[tCounter].Data);
                        break;
                    }
                    tCounter++;
                }
                this.LogPrint($"<Loop path> is set to {loopPath}");
                this.LogPrint($"<StartFromNearestPoint> is set to {startFromNearestPoint}");
                if (startFromNearestPoint)
                {
                    WoWPlayerMe localPlayer = game.GetGameObjects();
                    if (localPlayer != null)
                    {
                        DoAction nearestPoint = actionsList.Aggregate((minItem, nextItem) => localPlayer.Location.Distance(minItem.WowPoint) < localPlayer.Location.Distance(nextItem.WowPoint) ? minItem : nextItem);
                        counter = actionsList.IndexOf(nearestPoint);
                    }
                    else
                    {
                        counter = 0;
                    }
                }
                else
                {
                    counter = 0;
                }
                (timer = this.CreateTimer(RESOLUTION_INTERVAL, game, DoAction)).Start();
            }
        }
Пример #2
0
        private void DoAction()
        {
            List <WowObject> wowObjects = new List <WowObject>();
            List <WowNpc>    wowNpcs    = new List <WowNpc>();
            WoWPlayerMe      me         = game.GetGameObjects(wowObjects, null, wowNpcs);

            if (me != null)
            {
                DoAction action = actionsList[counter];
                if (action.ActionType != DoActionType.Move)
                {
                    unstuckDictionary.Clear();
                }
                switch (action.ActionType)
                {
                case DoActionType.Move:
                    double distance2D = me.Location.Distance2D(action.WowPoint);
                    double distance3D = me.Location.Distance(action.WowPoint);
                    if (me.IsFlying && (distance3D > precision3D || (distance3D <= precision3D && GetNextAction().ActionType != DoActionType.Move && me.IsMoving)))
                    {
                        UnstuckIfNeeded(me.Location, action.ActionType);
                        this.LogPrint($"Flying to point --> [{action.WowPoint}]; distance: {distance3D}");
                        game.Move3D(action.WowPoint, precision3D, precision3D, 1000, true, GetNextAction().ActionType == DoActionType.Move);
                    }
                    else if (!me.IsFlying && (distance2D > precision2D || (distance2D <= precision2D && GetNextAction().ActionType != DoActionType.Move && me.IsMoving)))
                    {
                        UnstuckIfNeeded(me.Location, action.ActionType);
                        this.LogPrint(string.Format("Moving to point --> [{0}]; my loc: [{3}]; distance2D: {1}; speed: {2}", action.WowPoint, distance2D, me.Speed, me.Location));
                        game.Move2D(action.WowPoint, precision2D, 1000, true, GetNextAction().ActionType == DoActionType.Move);
                    }
                    else
                    {
                        IncreaseCounterAndDoAction();
                    }
                    break;

                case DoActionType.StopProfile:
                    if (loopPath)
                    {
                        IncreaseCounterAndDoAction();
                    }
                    break;

                case DoActionType.RunLua:
                    Thread.Sleep(500);     // player should be stopped before interact
                    game.SendToChat("/run " + string.Concat(action.Data.TakeWhile(l => l != '\r' && l != '\n')));
                    IncreaseCounterAndDoAction();
                    break;

                case DoActionType.SendChat:
                    Thread.Sleep(500);     // player should be stopped before interact
                    game.SendToChat(action.Data);
                    IncreaseCounterAndDoAction();
                    break;

                case DoActionType.SelectGossipOption:
                    Thread.Sleep(1000);     // player should be stopped before interact
                    game.SelectDialogOption(action.Data);
                    IncreaseCounterAndDoAction();
                    break;

                case DoActionType.Interact:
                    WowObject[] objectsWithCorrectName = wowObjects.Where(l => l.Name == action.Data).ToArray();
                    if (objectsWithCorrectName.Length > 0)
                    {
                        WowObject nearestObject = objectsWithCorrectName.Aggregate((minItem, nextItem) => me.Location.Distance(minItem.Location) < me.Location.Distance(nextItem.Location) ? minItem : nextItem);
                        Thread.Sleep(500);     // player should be stopped before interact
                        nearestObject.Interact();
                    }
                    WowNpc[] npcsWithCorrectName = wowNpcs.Where(l => l.Name == action.Data).ToArray();
                    if (npcsWithCorrectName.Length > 0)
                    {
                        WowNpc nearestNpc = npcsWithCorrectName.Aggregate((minItem, nextItem) => me.Location.Distance(minItem.Location) < me.Location.Distance(nextItem.Location) ? minItem : nextItem);
                        Thread.Sleep(500);     // player should be stopped before interact
                        nearestNpc.Interact();
                    }
                    IncreaseCounterAndDoAction();
                    break;

                case DoActionType.Wait:
                    int timeToWait = int.Parse(action.Data);
                    while (timeToWait > 0 && timer.IsRunning)
                    {
                        Thread.Sleep(100);
                        timeToWait -= 100;
                    }
                    IncreaseCounterAndDoAction();
                    break;

                case DoActionType.SetPrecision2D:
                    if (!float.TryParse(action.Data, out precision2D))
                    {
                        precision2D = 3f;
                    }
                    IncreaseCounterAndDoAction();
                    break;

                case DoActionType.SetPrecision3D:
                    if (!float.TryParse(action.Data, out precision3D))
                    {
                        precision3D = 8f;
                    }
                    IncreaseCounterAndDoAction();
                    break;

                case DoActionType.WaitWhile:
                    if (!game.LuaIsTrue(action.Data))
                    {
                        IncreaseCounterAndDoAction();
                    }
                    else if (!string.IsNullOrWhiteSpace(action.AdditionalData) && int.TryParse(action.AdditionalData, out int lag))
                    {
                        Thread.Sleep(lag);
                    }
                    break;

                case DoActionType.SendToChatWhile:
                    string[] p         = action.Data.Split(new[] { "##@##" }, StringSplitOptions.RemoveEmptyEntries);
                    string   _action   = p[0];
                    string   condition = p[1];
                    if (game.LuaIsTrue(condition))
                    {
                        game.SendToChat(_action);
                    }
                    else
                    {
                        IncreaseCounterAndDoAction();
                    }
                    break;

                case DoActionType.StopProfileIf:
                    if (game.LuaIsTrue(action.Data))
                    {
                        counter = actionsList.Count - 1;
                    }
                    IncreaseCounterAndDoAction();
                    break;

                case DoActionType.NotifyUser:
                    this.ShowNotify(action.Data, false, false);
                    IncreaseCounterAndDoAction();
                    break;

                case DoActionType.NotifyUserIf:
                    if (game.LuaIsTrue(action.AdditionalData))
                    {
                        this.ShowNotify(action.Data, false, false);
                    }
                    IncreaseCounterAndDoAction();
                    break;

                default:
                    IncreaseCounterAndDoAction();
                    break;
                }
            }
            else
            {
                this.LogPrint("Local player is null");
            }
        }