Click here to Skip to main content
15,904,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code:
C#
public static class Damage
    {
        public static double RDamage(AIBaseClient target)
        {
            return new double[] { 100, 200, 300 }[SpellManager.R.Level - 1] + (0.75 * Player.Instance.FlatPhysicalDamageMod) + (1.5 * Player.Instance.FlatPhysicalDamageMod) + (0.2 * target.BuffCount("dariushemo"));
        }

        public static double RDamage(AIBaseClient target, int stack)
        {
            if (stack == 5)
            {
                var bonus = 0f;
                if (!Player.HasBuff("DariusNoxonTactictsONH"))
                    bonus = new float[] { 0, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 85, 95, 105, 130, 155, 180, 205, 230 }[Player.Instance.Level];

                return new double[] { 100, 200, 300 }[SpellManager.R.Level - 1] + (0.75 * (Player.Instance.FlatPhysicalDamageMod + bonus)) + (1.5 * Player.Instance.FlatPhysicalDamageMod) + (0.2 * stack);
            }

            return new double[] { 100, 200, 300 }[SpellManager.R.Level - 1] + (0.75 * Player.Instance.FlatPhysicalDamageMod) + (1.5 * Player.Instance.FlatPhysicalDamageMod) + (0.2 * stack);
        }
        public static double PassiveDamage(this AIHeroClient target)
        {
            float damagePerSec = (12 + Player.Instance.Level + 0.3f * Player.Instance.FlatPhysicalDamageMod) / 5;

            return (float)(ObjectManager.Player.CalculateDamage(target, DamageType.Physical, damagePerSec * target.BuffCount("dariushemo") * target.BuffRemainTime("dariushemo")));
        }

        public static float PassiveDamage(this AIHeroClient target, int second)
        {
            float damagePerSec = (12 + Player.Instance.Level + 0.3f * Player.Instance.FlatPhysicalDamageMod) / 5;

            return (float)(ObjectManager.Player.CalculateDamage(target, DamageType.Physical, damagePerSec * target.BuffCount("dariushemo") * target.BuffRemainTime("dariushemo") > second ? second : target.BuffRemainTime("dariushemo")));
        }

        public static float PassiveDamage(this AIHeroClient target, int stack, int second)
        {
            float damage = ((12 + Player.Instance.Level + 0.3f * Player.Instance.FlatPhysicalDamageMod) / 5) * stack * second;

            return (float)(ObjectManager.Player.CalculateDamage(target, DamageType.Physical, damage));
        }
    }

Now when I am using this
C#
if (QTarget.GetResult().IsKillable)
                    return;

and this
C#
if (Damage.RDamage(unit) > Health + Shield + unit.HPRegenRate)
            {
                result.IsKillable = true;

                if (unit.IsValidTarget(SpellManager.R.Range) && unit.PreviousPosition.Distance(Player.Instance.PreviousPosition) > SpellManager.R.Range)
                    result.Range = UltRange.FlashRRange;

                if (unit.IsValidTarget(SpellManager.R.Range))
                    result.Range = UltRange.RRange;
            }

and result in Index was outside the bounds of the array. in c#

Give me some solution how to solve this any alternate way then give me solution

by thienha1

What I have tried:

I tried using try catch but i like find solution for can solve it completely not deal an error
Posted
Updated 23-Aug-19 10:59am
v2
Comments
MadMyche 23-Aug-19 16:28pm    
Which line is throwing that "index out of range"- that is usually the best place to start

We can't tell you - it needs your code running and your data together to find out.
So, it's going to be up to you. Fortunately, you have a tool that will help you to find out and fix it: the debugger.
Google "Visual Studio debugger" and you find find instructions on how to use it - the pout a break pint on the method that the error occurs in, and step through watching what is going on any your array indices.
When you find out which array and which index is the problem, you can start looking back through your code to find out why.

Sorry, but we can;t do anyof that for you - time form you to learn a new and valuable skill: debugging!
 
Share this answer
 
Quote:
How can do bypass this exception?

The only way is to investigate the problem and apply corrections to code.
Quote:
Give me some solution how to solve this any alternate way then give me solution

Those 3 pieces of code are not related together, we know how it work.
Only you can investigate the problem: Use the debugger, when you get the error, inspect variables used where error happen, a variable does not contain what it should.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

Debugging C# Code in Visual Studio - YouTube[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900