Пример #1
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Class != null)
         {
             hashCode = hashCode * 59 + Class.GetHashCode();
         }
         if (Actions != null)
         {
             hashCode = hashCode * 59 + Actions.GetHashCode();
         }
         if (Blocked != null)
         {
             hashCode = hashCode * 59 + Blocked.GetHashCode();
         }
         if (Buildable != null)
         {
             hashCode = hashCode * 59 + Buildable.GetHashCode();
         }
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (InQueueSince != null)
         {
             hashCode = hashCode * 59 + InQueueSince.GetHashCode();
         }
         if (Params != null)
         {
             hashCode = hashCode * 59 + Params.GetHashCode();
         }
         if (Stuck != null)
         {
             hashCode = hashCode * 59 + Stuck.GetHashCode();
         }
         if (Task != null)
         {
             hashCode = hashCode * 59 + Task.GetHashCode();
         }
         if (Url != null)
         {
             hashCode = hashCode * 59 + Url.GetHashCode();
         }
         if (Why != null)
         {
             hashCode = hashCode * 59 + Why.GetHashCode();
         }
         if (BuildableStartMilliseconds != null)
         {
             hashCode = hashCode * 59 + BuildableStartMilliseconds.GetHashCode();
         }
         return(hashCode);
     }
 }
Пример #2
0
 public void EngineStop()
 {
     PullController.Stop();
     Stuck.Stop();
     Navigator.Stop();
     Navigation = null;
     Navigator  = null;
     _states    = null;
     CombatHandler.CombatStatusChanged -= CombatChanged;
     GC.Collect();
 }
Пример #3
0
    private void Awake()
    {
        rb       = GetComponent <Rigidbody2D>();
        anim     = GetComponent <Animator>();
        sr       = GetComponent <SpriteRenderer>();
        mySource = GetComponent <AudioSource>();

        fsm       = new FSM();
        moveState = new Move(this, WalkSpeed);
        hurtState = new Hurt(this, TimeHurt);
        jumpState = new Jump(this, JumpForce, rb);
        jumpState.SetMaxJumps(JumpCount);
        stuckState = new Stuck(this, TimeStuck, VulnerableArea);
        idleState  = new Idle(this, 3.0f);
        deadState  = new Dead();
    }
Пример #4
0
        internal void FireEvent(Event eventType, JToken eventData)
        {
            switch (eventType)
            {
            case Event.PlayerUpdate:
            {
                CurrentPosition = (long)eventData;
                Update?.Invoke(currentTrack, (long)eventData).GetAwaiter();

                break;
            }

            case Event.TrackEnd:
            {
                End?.Invoke(currentTrack, (string)eventData).GetAwaiter();

                Playing = true;

                break;
            }

            case Event.TrackException:
            {
                Exception?.Invoke(currentTrack, (string)eventData).GetAwaiter();

                Playing = true;

                break;
            }

            case Event.TrackStuck:
            {
                Stuck?.Invoke(currentTrack, (long)eventData).GetAwaiter();

                Playing = true;

                break;
            }

            default:
            {
                Console.WriteLine(new LogMessage(LogSeverity.Debug, "Lavalink", $"Warning: Unknown Event ({eventType.ToString()})"));

                break;
            }
            }
        }
Пример #5
0
    // Use this for initialization
    void Awake()
    {
        gui = GetComponent <PlayerGUI>();

        buttons[0] = b1;
        buttons[1] = b2;
        buttons[2] = b3;
        buttons[3] = b4;

        Debug.Log("Instantiating Hacks");

        PointControl   points  = player.GetComponent <PointControl>();
        PlayerMovement control = player.GetComponent <PlayerMovement>();

        hacks[4] = new flip(points);
        hacks[5] = new freeze(points);
        hacks[6] = new reverse(points);
        hacks[0] = new dropPoint(points);
        hacks[1] = new slowDown(points);
        hacks[2] = new Delay(points);
        hacks[7] = new Kill(points, sb, fire);
        hacks[3] = new Stuck(points);
        reset    = new Reset(control);
    }
Пример #6
0
		internal void EmitPlayerEvent(string json, PlayerEventType type)
		{
			switch (type)
			{
				case PlayerEventType.TrackEndEvent:
					End?.Invoke(this, JsonConvert.DeserializeObject<PlayerEndEventPacket>(json));
					Status = PlayerStatus.ENDED;
					break;
				case PlayerEventType.TrackExceptionEvent:
					Exception?.Invoke(this, JsonConvert.DeserializeObject<PlayerExceptionEventPacket>(json));
					Status = PlayerStatus.ERRORED;
					break;
				case PlayerEventType.TrackStuckEvent:
					Stuck?.Invoke(this, JsonConvert.DeserializeObject<PlayerStuckEventPacket>(json));
					Status = PlayerStatus.STUCK;
					break;
				case PlayerEventType.WebSocketClosedEvent:
					WebSocketClose?.Invoke(this, JsonConvert.DeserializeObject<PlayerCloseEventPacket>(json));
					Status = PlayerStatus.ERRORED;
					break;
				default:
					throw new ArgumentOutOfRangeException(nameof(type), type, null);
			}
		}
Пример #7
0
        /// <summary>
        /// Returns true if QueueBlockedItem instances are equal
        /// </summary>
        /// <param name="other">Instance of QueueBlockedItem to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(QueueBlockedItem other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Class == other.Class ||
                     Class != null &&
                     Class.Equals(other.Class)
                     ) &&
                 (
                     Actions == other.Actions ||
                     Actions != null &&
                     other.Actions != null &&
                     Actions.SequenceEqual(other.Actions)
                 ) &&
                 (
                     Blocked == other.Blocked ||

                     Blocked.Equals(other.Blocked)
                 ) &&
                 (
                     Buildable == other.Buildable ||

                     Buildable.Equals(other.Buildable)
                 ) &&
                 (
                     Id == other.Id ||

                     Id.Equals(other.Id)
                 ) &&
                 (
                     InQueueSince == other.InQueueSince ||

                     InQueueSince.Equals(other.InQueueSince)
                 ) &&
                 (
                     Params == other.Params ||
                     Params != null &&
                     Params.Equals(other.Params)
                 ) &&
                 (
                     Stuck == other.Stuck ||

                     Stuck.Equals(other.Stuck)
                 ) &&
                 (
                     Task == other.Task ||
                     Task != null &&
                     Task.Equals(other.Task)
                 ) &&
                 (
                     Url == other.Url ||
                     Url != null &&
                     Url.Equals(other.Url)
                 ) &&
                 (
                     Why == other.Why ||
                     Why != null &&
                     Why.Equals(other.Why)
                 ) &&
                 (
                     BuildableStartMilliseconds == other.BuildableStartMilliseconds ||

                     BuildableStartMilliseconds.Equals(other.BuildableStartMilliseconds)
                 ));
        }
Пример #8
0
 public void EngineStop()
 {
     Stuck.Stop();
     Navigator.Stop();
 }
Пример #9
0
        public bool EngineStart()
        {
            FindNode.LoadHarvest();
            FlyingSettings.LoadSettings();
            KeyHelper.AddKey("FMount", "None", FlyingSettings.FlyingMountBar, FlyingSettings.FlyingMountKey);
            KeyHelper.AddKey("Lure", "None", FlyingSettings.LureBar, FlyingSettings.LureKey);
            KeyHelper.AddKey("Waterwalk", "None", FlyingSettings.WaterwalkBar, FlyingSettings.WaterwalkKey);
            KeyHelper.AddKey("CombatStart", "None", FlyingSettings.ExtraBar, FlyingSettings.ExtraKey);
            if (!ObjectManager.InGame)
            {
                Logging.Write(LogType.Info, "Enter game before starting the bot");
                return(false);
            }
            if (ObjectManager.MyPlayer.IsGhost)
            {
                Logging.Write(LogType.Info, "Please ress before starting the bot");
                return(false);
            }
            if (CurrentProfile == null)
            {
                Logging.Write(LogType.Info, "Please load a profile");
                return(false);
            }
            if (CurrentProfile.WaypointsNormal.Count < 2)
            {
                Logging.Write(LogType.Info, "Profile should have more than 2 waypoints");
                return(false);
            }
            Navigation = new FlyingNavigation(CurrentProfile.WaypointsNormal, true, FlyingWaypointsType.Normal);
            Navigator  = new FlyingNavigator();
            ToTown.SetToTown(false);
            switch (CurrentMode)
            {
            case Mode.Normal:
                FlyingStates = new List <MainState>
                {
                    new StateMount(),
                    new StateMoving(),
                    new StateGather(),
                    new StateCombat(),
                    new StateRess(),
                    new StateResting(),
                    new StateMailbox(),
                    new StateToTown(),
                    new StateVendor(),
                    new StateFullBags(),
                };
                break;

            case Mode.TestNormal:
                Logging.Write(LogType.Warning,
                              "Starting flying engine in TestNormal mode, next start will be in normal mode");
                FlyingStates = new List <MainState>
                {
                    new StateMount(),
                    new StateMoving(),
                    new StateFullBags(),
                };
                break;

            case Mode.TestToTown:
                Logging.Write(LogType.Warning,
                              "Starting flying engine in TestToTown mode, next start will be in normal mode");
                FlyingStates = new List <MainState>
                {
                    new StateMount(),
                    new StateMoving(),
                    new StateCombat(),
                    new StateMailbox(),
                    new StateToTown(),
                    new StateVendor(),
                    new StateFullBags(),
                };
                ToTown.SetToTown(true);     //Set town mode to true
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            Stuck.Run();
            FlyingBlackList.Load();
            CloseWindows();
            CurrentMode = Mode.Normal;
            _harvest    = 0;
            _kills      = 0;
            _death      = 0;
            _startTime  = DateTime.Now;
            UpdateStats(0, 0, 0);
            return(true);
        }
Пример #10
0
        /// <summary>
        /// Will try and get around obstacles if stuck
        /// </summary>
        protected void AntiStuck(float frameTime)
        {
            // TODO: More work because these are sketchy af
            // TODO: Check if a wall was spawned in front of us and then immediately dump route if it was

            // First check if we're still in a stuck state from last frame
            if (IsStuck && !_tryingAntiStuck)
            {
                switch (_antiStuckMethod)
                {
                case AntiStuckMethod.None:
                    break;

                case AntiStuckMethod.Jiggle:
                    var randomRange = IoCManager.Resolve <IRobustRandom>().Next(0, 359);
                    var angle       = Angle.FromDegrees(randomRange);
                    Owner.TryGetComponent(out AiControllerComponent mover);
                    mover.VelocityDir = angle.ToVec().Normalized;

                    break;

                case AntiStuckMethod.PhaseThrough:
                    if (Owner.TryGetComponent(out CollidableComponent collidableComponent))
                    {
                        // TODO Fix this because they are yeeting themselves when they charge
                        // TODO: If something updates this this will f**k it
                        collidableComponent.CanCollide = false;

                        Timer.Spawn(100, () =>
                        {
                            if (!collidableComponent.CanCollide)
                            {
                                collidableComponent.CanCollide = true;
                            }
                        });
                    }
                    break;

                case AntiStuckMethod.Teleport:
                    Owner.Transform.DetachParent();
                    Owner.Transform.GridPosition = NextGrid;
                    break;

                case AntiStuckMethod.ReRoute:
                    GetRoute();
                    break;

                case AntiStuckMethod.Angle:
                    var random = IoCManager.Resolve <IRobustRandom>();
                    _addedAngle = new Angle(random.Next(-60, 60));
                    IsStuck     = false;
                    Timer.Spawn(100, () =>
                    {
                        _addedAngle = Angle.Zero;
                    });
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }

            _stuckTimerRemaining -= frameTime;

            // Stuck check cooldown
            if (_stuckTimerRemaining > 0.0f)
            {
                return;
            }

            _tryingAntiStuck     = false;
            _stuckTimerRemaining = 0.5f;

            // Are we actually stuck
            if ((_ourLastPosition.Position - Owner.Transform.GridPosition.Position).Length < TileTolerance)
            {
                _antiStuckAttempts++;

                // Maybe it's just 1 tile that's borked so try next 1?
                if (_antiStuckAttempts >= 2 && _antiStuckAttempts < 5 && Route.Count > 1)
                {
                    var nextTile = Route.Dequeue();
                    NextGrid = _mapManager.GetGrid(nextTile.GridIndex).GridTileToLocal(nextTile.GridIndices);
                    return;
                }

                if (_antiStuckAttempts >= 5 || Route.Count == 0)
                {
                    Logger.DebugS("ai", $"{Owner} is stuck at {Owner.Transform.GridPosition}, trying new route");
                    _antiStuckAttempts = 0;
                    IsStuck            = false;
                    _ourLastPosition   = Owner.Transform.GridPosition;
                    GetRoute();
                    return;
                }
                Stuck?.Invoke();
                IsStuck = true;
                return;
            }

            IsStuck = false;

            _ourLastPosition = Owner.Transform.GridPosition;
        }
Пример #11
0
        /// <summary>
        /// Returns true if QueueLeftItem instances are equal
        /// </summary>
        /// <param name="other">Instance of QueueLeftItem to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(QueueLeftItem other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Class == other.Class ||
                     Class != null &&
                     Class.Equals(other.Class)
                     ) &&
                 (
                     Actions == other.Actions ||
                     Actions != null &&
                     Actions.SequenceEqual(other.Actions)
                 ) &&
                 (
                     Blocked == other.Blocked ||
                     Blocked != null &&
                     Blocked.Equals(other.Blocked)
                 ) &&
                 (
                     Buildable == other.Buildable ||
                     Buildable != null &&
                     Buildable.Equals(other.Buildable)
                 ) &&
                 (
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                 ) &&
                 (
                     InQueueSince == other.InQueueSince ||
                     InQueueSince != null &&
                     InQueueSince.Equals(other.InQueueSince)
                 ) &&
                 (
                     Params == other.Params ||
                     Params != null &&
                     Params.Equals(other.Params)
                 ) &&
                 (
                     Stuck == other.Stuck ||
                     Stuck != null &&
                     Stuck.Equals(other.Stuck)
                 ) &&
                 (
                     Task == other.Task ||
                     Task != null &&
                     Task.Equals(other.Task)
                 ) &&
                 (
                     Url == other.Url ||
                     Url != null &&
                     Url.Equals(other.Url)
                 ) &&
                 (
                     Why == other.Why ||
                     Why != null &&
                     Why.Equals(other.Why)
                 ) &&
                 (
                     Cancelled == other.Cancelled ||
                     Cancelled != null &&
                     Cancelled.Equals(other.Cancelled)
                 ) &&
                 (
                     Executable == other.Executable ||
                     Executable != null &&
                     Executable.Equals(other.Executable)
                 ));
        }
Пример #12
0
        public bool EngineStart()
        {
            GrindingSettings.LoadSettings();
            if (!ObjectManager.InGame)
            {
                Logging.Write(LogType.Info, "【地面战斗】先登录游戏");
                return(false);
            }
            if (ObjectManager.MyPlayer.IsDead && ObjectManager.MyPlayer.IsGhost)
            {
                Logging.Write(LogType.Info, "【地面战斗】先复活吧");
                return(false);
            }
            if (CurrentProfile == null)
            {
                Logging.Write(LogType.Info, "【地面战斗】先读取一个Profile文件");
                return(false);
            }
            Navigator  = new GrindingNavigator();
            Navigation = new GrindingNavigation(CurrentProfile);
            GrindingSettings.LoadSettings();
            ToTown.SetToTown(false);
            switch (CurrentMode)
            {
            case Mode.TestToTown:
                Logging.Write(LogType.Warning,
                              "Starting Grinding engine in TestToTown mode, next start will be in normal mode THIS IS TODO");
                //TODO
                break;

            default:
                _states = new List <MainState>
                {
                    new StatePull(),
                    new StateLoot(),
                    new StateMoving(),
                    new StateTrainer(),
                    new StateResting(),
                    new StateResurrect(),
                    new StateCombat(),
                    new StateToTown(),
                    new StateVendor(),
                };
                break;
            }
            Stuck.Run();
            CurrentMode = Mode.Normal;
            CombatHandler.CombatStatusChanged += CombatChanged;
            CloseWindows();
            loots      = 0;
            _kills     = 0;
            _death     = 0;
            _xpInitial = ObjectManager.MyPlayer.Experience;
            _startTime = DateTime.Now;

            /*
             * if (GrindingSettings.ShouldTrain)
             * {
             *  ShouldTrain = GrindingShouldTrain.ShouldTrain();
             * }*/
            PullController.Start();
            return(true);
        }
Пример #13
0
	// Use this for initialization
	void Start () {
        stuck = GetComponent<Stuck>();
        WakeUp(waterDrops[index]);
	}
Пример #14
0
 public override void DoWork()
 {
     Logging.Debug("Approaching: " + _node.Location);
     if (_nodeLoc == _node.Location)
     {
         if (_approachTimes > 6)
         {
             Logging.Write("We tried to approach the same node more than 6 times... does not make sense abort");
             FlyingBlackList.Blacklist(_node, 120, true);
             return;
         }
         _approachTimes++;
     }
     else
     {
         _nodeLoc       = _node.Location;
         _approachTimes = 0;
     }
     if (Gather.GatherNode(_node))
     {
         FlyingEngine.UpdateStats(1, 0, 0);
         if (FlyingSettings.WaitForLoot)
         {
             while (ObjectManager.MyPlayer.LootWinOpen && !TimeOut.IsReady)
             {
                 Thread.Sleep(100);
             }
             Latency.Sleep(1300);
         }
         if (ObjectManager.MyPlayer.IsInFlightForm)
         {
             MoveHelper.Jump();
         }
     }
     else
     {
         if (ObjectManager.ShouldDefend && Mount.IsMounted())
         {
             Logging.Write("ShouldDefend while mounted? Odd");
             FlyingBlackList.Blacklist(_node, 120, true);
         }
     }
     if (!ObjectManager.MyPlayer.InVashjir && ObjectManager.MyPlayer.IsSwimming)
     {
         Logging.Write("We got into the water, blacklisting node");
         FlyingBlackList.AddBadNode(_node);
         KeyHelper.SendKey("Space");
         Thread.Sleep(3000);
         KeyHelper.ReleaseKey("Space");
     }
     if (!ObjectManager.ShouldDefend && !ObjectManager.MyPlayer.IsInCombat)
     {
         LootedBlacklist.Looted(_node);
         if (ObjectManager.MyPlayer.InVashjir)
         {
             KeyHelper.SendKey("Space");
             Thread.Sleep(1000);
             KeyHelper.ReleaseKey("Space");
         }
     }
     if (!Mount.IsMounted())
     {
         CombatHandler.RunningAction();
         CombatHandler.Rest();
     }
     Stuck.Reset();
     if (FlyingEngine.CurrentProfile.NaturalRun)
     {
         FlyingEngine.Navigation.UseNearestWaypoint();
     }
     else
     {
         FlyingEngine.Navigation.UseNearestWaypoint(10);
     }
 }
Пример #15
0
        public RunStatus Execute()
        {
            if (!IsQueuedMovement)
            {
                return(RunStatus.Failure);
            }

            if (CurrentMovement == null)
            {
                CurrentMovement = _internalQueue.Dequeue();
                CurrentMovement.StartPosition   = ZetaDia.Me.Position;
                CurrentMovement.LastStartedTime = DateTime.UtcNow;
                Stuck.Reset();
            }

            _options = CurrentMovement.Options;

            if (CurrentMovement.OnUpdate != null)
            {
                CurrentMovement.OnUpdate.Invoke(CurrentMovement);
            }

            _status.LastStatus          = PlayerMover.NavigateTo(CurrentMovement.Destination, CurrentMovement.Name);
            _status.DistanceToObjective = ZetaDia.Me.Position.Distance(CurrentMovement.Destination);
            _status.ChangeInDistance    = _status.LastPosition.Distance(CurrentMovement.Destination) - _status.DistanceToObjective;
            _status.LastPosition        = ZetaDia.Me.Position;

            CurrentMovement.Status = _status;

            if (CurrentMovement.StopCondition != null &&
                CurrentMovement.StopCondition.Invoke(CurrentMovement))
            {
                FailedHandler("StopWhen");
                return(RunStatus.Failure);
            }

            if (Stuck.IsStuck(_options.ChangeInDistanceLimit, _options.TimeBeforeBlocked))
            {
                FailedHandler("Blocked " + Stuck.LastLogMessage);
                return(RunStatus.Failure);
            }

            if (_status.DistanceToObjective < _options.AcceptableDistance)
            {
                SuccessHandler(string.Format("AcceptableDistance: {0}", _options.AcceptableDistance));
                return(RunStatus.Success);
            }

            if (IsBlacklisted(CurrentMovement))
            {
                FailedHandler("RecentlyFailed");
                return(RunStatus.Success);
            }

            if (_status.DistanceToObjective > _options.MaxDistance)
            {
                FailedHandler(string.Format("MaxDistance: {0}", _options.MaxDistance));
                return(RunStatus.Success);
            }

            switch (_status.LastStatus)
            {
            case MoveResult.ReachedDestination:
                SuccessHandler();
                return(RunStatus.Success);

            case MoveResult.PathGenerationFailed:
            case MoveResult.Moved:
                MovedHandler();
                return(RunStatus.Running);

            case MoveResult.Failed:
                FailedHandler("Navigation");
                return(RunStatus.Failure);

            default:
                return(RunStatus.Success);
            }
        }