Beispiel #1
0
        public void SetEnemyInfo(EnemyInfo enemyInfo)
        {
            BeginInvoke(new Action(() =>
            {
                int healthPercent = 0;

                if (enemyInfo == null)
                {
                    enemyLabel.Text = "-";
                }
                else
                {
                    enemyLabel.Text = "ENEMY";
                    healthPercent   = enemyInfo.Health;
                }

                enemyHealthLabel.Text        = string.Format("Health ({0}%)", healthPercent);
                enemyHealthProgressBar.Value = healthPercent;
            }));
        }
Beispiel #2
0
        public void Update(Script script)
        {
            // Use med kit
            if (script.HealthPercent <= script.MainForm.GetUseMedKidBelowValue())
            {
                script.PressQueue(new DualShockState()
                {
                    L1 = true
                }, "L1");
            }

            // Detect enemy
            EnemyInfo enemy = DetectEnemy(script);

            // Update form
            script.MainForm.SetEnemyInfo(enemy);

            // Found enemy
            if (enemy != null)
            {
                // Store flag in objective manager
                ObjectiveManager.Instance.FoundEnemy = true;

                //Debug.WriteLine("ENEMY HEALTH: {0}", enemy.Health);

                // Store info
                LastFoundEnemyTime = DateTime.Now;
                LastEnemyHealth    = enemy.Health;

                // Lazy initialize enemy health
                if (EnemyHealthHistory == null)
                {
                    EnemyHealthHistory = new List <int>();
                }

                // Add enemy health to history
                EnemyHealthHistory.Add(LastEnemyHealth);

                // Clear buttons
                script.ClearButtons();

                // If target is not locked
                if (!TargetLocked)
                {
                    // Lock target
                    //script.PressQueue(new DualShockState() { R1 = true }, "R1");
                    script.Press(new DualShockState()
                    {
                        R1 = true
                    });
                    TargetLocked         = true;
                    LastTargetLockedTime = DateTime.Now;

                    // Dash once to get closer
                    var dashControl = script.MainForm.GetDashControl();
                    //script.PressQueue(dashControl.State, dashControl.Properties);
                    script.Press(dashControl.State);

                    // Target lock takes priority, attack later
                    return;
                }

                // Attack
                var attackControl = AttackSequenceManager.Instance.GetNextState();
                if (attackControl != null)
                {
                    script.PressQueue(attackControl.State, attackControl.Properties);
                }

                // Check enemy health for progress
                var enemyHealthLimit = 80; // ~80 seconds
                if (EnemyHealthHistory.Count >= enemyHealthLimit)
                {
                    // Search through history
                    bool shouldReset = true;
                    foreach (var h in EnemyHealthHistory)
                    {
                        if (h != EnemyHealthHistory.First())
                        {
                            // Reset enemy health history
                            EnemyHealthHistory = null;
                            // But don't reset state
                            shouldReset = false;
                            break;
                        }
                    }

                    // Reset if enemy does not take any damage for a while
                    if (shouldReset)
                    {
                        // Unlock target
                        script.PressQueue(new DualShockState()
                        {
                            R1 = true
                        }, "R1");
                        TargetLocked = false;

                        // Reset
                        ResetEnemyData();

                        // Walk random direction for a second
                        Random rnd        = new Random();
                        var    directions = new int[] { PlayerMovement.TOP, PlayerMovement.RIGHT, PlayerMovement.BOTTOM, PlayerMovement.LEFT };
                        Walk(script, directions[rnd.Next(directions.Length)], 1000);
                    }
                }
            }
            // Enemy not found
            else
            {
                // Continue only if the last seen enemy is not found for a while
                if ((DateTime.Now - LastFoundEnemyTime).TotalMilliseconds < 1500)
                {
                    return;
                }

                // Reset
                ResetEnemyData();

                // Fight wave recovery
                bool enableFightRecovery  = ObjectiveManager.Instance.FightWaveRecoveryIndex != -1;
                bool fightRecoveryTimeout = (DateTime.Now - ObjectiveManager.Instance.FightWaveStartTime).TotalMilliseconds >= 60000; // ~1 minute
                bool shouldRecoverFight   = enableFightRecovery && fightRecoveryTimeout;

                // Trigger objective when no more enemy
                if (ObjectiveManager.Instance.FoundEnemy || shouldRecoverFight)
                {
                    script.EnableLoop = false;
                    ObjectiveManager.Instance.FoundEnemy   = false;
                    ObjectiveManager.Instance.ShouldUpdate = true;

                    // Reset attack sequence
                    AttackSequenceManager.Instance.Reset();

                    // Go to recovery index if enabled
                    if (shouldRecoverFight)
                    {
                        ObjectiveManager.Instance.GoToFightRecoveryIndex();
                    }
                }
                // Enemy not found yet
                else
                {
                    // Roam the map
                    if ((int)script.WalkDirection != -1)
                    {
                        RoamMap(script);
                    }
                }
            }
        }
Beispiel #3
0
        public EnemyInfo DetectEnemy(Script script)
        {
            // Crop
            var bmp = script.CropFrame(R_EnemyNameArea);
            // Apply filter
            Bitmap filteredBmp = Helper.PosterizeFilter(bmp);

            Color targetGreenBarColor  = GreenBarColor.ToColorOpaque();
            Color targetYellowBarColor = YellowBarColor.ToColorOpaque();
            Color targetRedBarColor    = RedBarColor.ToColorOpaque();
            Color targetHealthColor    = FilteredHealthColor.ToColorOpaque();

            bool foundColorBar = true;

            for (var i = 0; i < ColorBarScanHeight; i++)
            {
                //Debug.WriteLine(newBmp.GetPixel(163, 2 + i));

                // Check if all is the target color
                var checkBarColor = filteredBmp.GetPixel(P_ColorBarStart.X, P_ColorBarStart.Y + i);
                if (checkBarColor != targetGreenBarColor && checkBarColor != targetYellowBarColor && checkBarColor != targetRedBarColor)
                {
                    foundColorBar = false;
                    break;
                }
            }

            if (foundColorBar)
            {
                var enemyInfo = new EnemyInfo();

                // Enemy health is full
                if (filteredBmp.GetPixel(P_EnemyHealthFull.X, P_EnemyHealthFull.Y) == targetHealthColor)
                {
                    enemyInfo.Health = 100;
                }
                // Enemy health not full
                else
                {
                    var width = R_EnemyHealth.Width;
                    // Dots needed to count
                    var dotsNeeded = 3;

                    // Scan enemy health bar from right to left
                    for (var i = width - 1; i > 0; i--)
                    {
                        int  foundRedCount = 0;
                        bool breakOuter    = false;
                        for (var j = 11; j <= 17; j++)
                        {
                            // Found red
                            var checkRedColor = filteredBmp.GetPixel(i, j);
                            if (checkRedColor == targetHealthColor)
                            {
                                foundRedCount++;
                            }

                            // Enough red dots are found
                            if (foundRedCount >= dotsNeeded)
                            {
                                breakOuter       = true;
                                enemyInfo.Health = (int)((i / Convert.ToDouble(width)) * 100);
                                break;
                            }
                        }

                        // Exit if we found the value
                        if (breakOuter)
                        {
                            break;
                        }
                    }
                }

                // Make sure that the health is valid
                if (enemyInfo.Health < 0)
                {
                    return(null);
                }

                // Return enemy info
                return(enemyInfo);
            }

            return(null);
        }