Here is the method:
Code: Select all
// Checks for if a shield block was successful and returns true if so, false if not.
private static bool ShieldBlockChanceCalculation(DaggerfallEntity target, bool shieldStrongSpot)
{
float blockChance = 0f;
int targetAgili = target.Stats.LiveAgility - 50;
int targetSpeed = target.Stats.LiveSpeed - 50;
int targetStren = target.Stats.LiveStrength - 50;
int targetEndur = target.Stats.LiveEndurance - 50; // First bug i'm seeing, sometimes this gets ran 2-3 times in a single attack, this makes sense since a bunch of times this method is called, problem is that the result for the roll is different every run.
int targetWillp = target.Stats.LiveWillpower - 50;
int targetLuck = target.Stats.LiveLuck - 50;
if (shieldStrongSpot)
{
blockChance = 40f; // A base 40% chance of a block added to body parts covered by the shield, might expand on this later.
blockChance += (targetAgili*.3f);
blockChance += (targetSpeed*.3f);
blockChance += (targetStren*.3f);
blockChance += (targetEndur*.2f);
blockChance += (targetWillp*.1f);
blockChance += (targetLuck*.1f);
Mathf.Clamp(blockChance, 7f, 95f);
int blockChanceInt = (int)Mathf.Round(blockChance);
if (Dice100.SuccessRoll(blockChanceInt))
{
Debug.LogFormat("$$$. Shield Blocked A Hard-Point, Chance Was {0}%", blockChanceInt);
return true;
}
else
{
Debug.LogFormat("!!!. Shield FAILED To Block A Hard-Point, Chance Was {0}%", blockChanceInt);
return false;
}
}
else
{
blockChance = (targetAgili*.2f);
blockChance += (targetSpeed*.2f);
blockChance += (targetStren*.2f);
blockChance += (targetEndur*.1f);
blockChance += (targetWillp*.1f);
blockChance += (targetLuck*.1f);
Mathf.Clamp(blockChance, 0f, 35f);
int blockChanceInt = (int)Mathf.Round(blockChance);
if (Dice100.SuccessRoll(blockChanceInt))
{
Debug.LogFormat("$$$. Shield Blocked A Soft-Point, Chance Was {0}%", blockChanceInt);
return true;
}
else
{
Debug.LogFormat("!!!. Shield FAILED To Block A Soft-Point, Chance Was {0}%", blockChanceInt);
return false;
}
}
}
Edit: A "dirty" solution I was maybe making this method Public and adding a variable that increments every-time the method gets called, and if that value is more than the first call, it will return whatever was returned the last time or something, but i'm not sure how that would work, as well as how I would reset this value back every-time an attack did all of its needed calculations. Like I said, there is the potential that this method is ran 1-3 times from one attack, depending on what is the attacker and if their attack does any damage or not.