Wolftousen
05-10-2010, 03:41 PM
Was looking at this function trying to figure it out and did so with a little help from Kim, but it had a lot of repeated tests and function calls so i compressed it down so it does less work with the same outcomes. It tests for blocking first instead of riposte though, but that shouldn't make any difference.
Here is the diff against 1473 zone/attack.cpp:
C:\Program Files (x86)\GnuWin32\bin>diff c:\Users\Wolftousen\Documents\fdO.txt c:\Users\Wolftousen\workspace\EQEmuServer\zone\att ack.cpp -u
--- c:\Users\Wolftousen\Documents\fdO.txt 2010-05-09 22:52:42.436100000 -0400
+++ c:\Users\Wolftousen\workspace\EQEmuServer\zone\att ack.cpp 2010-05-10 03:41:15.458150000 -0400
@@ -372,185 +372,158 @@
return(tohit_roll <= chancetohit);
}
+/* solar: called when a mob is attacked, does the checks to see if it's a hit
+* and does other mitigation checks. 'this' is the mob being attacked.
+*
+* special return values:
+* -1 - block
+* -2 - parry
+* -3 - riposte
+* -4 - dodge
+*
+*/
bool Mob::AvoidDamage(Mob* other, sint32 &damage)
-{
- /* solar: called when a mob is attacked, does the checks to see if it's a hit
- * and does other mitigation checks. 'this' is the mob being attacked.
- *
- * special return values:
- * -1 - block
- * -2 - parry
- * -3 - riposte
- * -4 - dodge
- *
- */
- float skill;
- float bonus;
- float RollTable[4] = {0,0,0,0};
- float roll;
- Mob *attacker=other;
- Mob *defender=this;
-
- //garunteed hit
- bool ghit = false;
- if((attacker->spellbonuses.MeleeSkillCheck + attacker->itembonuses.MeleeSkillCheck) > 500)
- ghit = true;
-
- //////////////////////////////////////////////////////////
- // make enrage same as riposte
- /////////////////////////////////////////////////////////
- if (IsEnraged() && !other->BehindMob(this, other->GetX(), other->GetY())) {
- damage = -3;
- mlog(COMBAT__DAMAGE, "I am enraged, riposting frontal attack.");
- }
-
- /////////////////////////////////////////////////////////
- // riposte
- /////////////////////////////////////////////////////////
- if (damage > 0 && CanThisClassRiposte() && !other->BehindMob(this, other->GetX(), other->GetY()))
- {
- skill = GetSkill(RIPOSTE);
- if (IsClient()) {
- CastToClient()->CheckIncreaseSkill(RIPOSTE, other, -10);
- }
-
- if (!ghit) { //if they are not using a garunteed hit discipline
- bonus = 2.0 + skill/60.0 + (GetDEX()/200);
- bonus = bonus * (100 + defender->spellbonuses.RiposteChance + defender->itembonuses.RiposteChance) / 100.0f;
- RollTable[0] = bonus;
- }
+{
+ //is there a garunteed hit disc in place?
+ if((other->spellbonuses.MeleeSkillCheck + other->itembonuses.MeleeSkillCheck) > 500)
+ {
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return false;
}
- ///////////////////////////////////////////////////////
- // block
- ///////////////////////////////////////////////////////
-
+ //is attacker behind or in front...
+ bool inFront = !other->BehindMob(this, other->GetX(), other->GetY());
bool bBlockFromRear = false;
- if (this->IsClient()) {
- float aaChance = 0;
-
+ if (this->IsClient())
+ {
// a successful roll on this does not mean a successful block is forthcoming. only that a chance to block
// from a direction other than the rear is granted.
- switch (GetAA(aaHightenedAwareness)) {
- case 1:
- aaChance = 8;
- break;
- case 2:
- aaChance = 16;
- break;
- case 3:
- aaChance = 24;
- break;
- case 4:
- aaChance = 32;
- break;
- case 5:
- aaChance = 40;
- break;
- }
-
- if (aaChance > MakeRandomInt(1, 100))
+ if (GetAA(aaHightenedAwareness) * 8 > MakeRandomInt(1, 100))
+ {
bBlockFromRear = true;
- }
-
- if (damage > 0 && CanThisClassBlock() && (!other->BehindMob(this, other->GetX(), other->GetY()) || bBlockFromRear)) {
- skill = CastToClient()->GetSkill(BLOCKSKILL);
- if (IsClient()) {
- CastToClient()->CheckIncreaseSkill(BLOCKSKILL, other, -10);
- }
-
- if (!ghit) { //if they are not using a garunteed hit discipline
- bonus = 2.0 + skill/35.0 + (GetDEX()/200);
- RollTable[1] = RollTable[0] + bonus;
}
}
- else{
- RollTable[1] = RollTable[0];
+
+ float chance = 0;
+ float roll = MakeRandomFloat(0,100);;
+
+ ///////////////////////////////////////////////////////
+ // block - Monk/Bst only
+ ///////////////////////////////////////////////////////
+
+ if (CanThisClassBlock() && (inFront || bBlockFromRear))
+ {
+ chance = 2.0 + (float)CastToClient()->GetSkill(BLOCKSKILL)/35.0 + ((float)GetDEX()/200.0);
}
-
- if(damage > 0 && GetAA(aaShieldBlock) && (!other->BehindMob(this, other->GetX(), other->GetY()))) {
- bool equiped = CastToClient()->m_inv.GetItem(14);
- if(equiped) {
- uint8 shield = CastToClient()->m_inv.GetItem(14)->GetItem()->ItemType;
-
- if(shield == ItemTypeShield) {
- switch(GetAA(aaShieldBlock)) {
+
+ ///////////////////////////////////////////////////////
+ // shield block - WAR/PAL/SK only
+ ///////////////////////////////////////////////////////
+
+ if(GetAA(aaShieldBlock) > 0)
+ {
+ if(CastToClient()->m_inv.GetItem(14))
+ {
+ if(CastToClient()->m_inv.GetItem(14)->GetItem()->ItemType == ItemTypeShield)
+ {
+ switch(GetAA(aaShieldBlock))
+ {
case 1:
- RollTable[1] = RollTable[0] + 2.50;
- break;
- case 2:
- RollTable[1] = RollTable[0] + 5.00;
- break;
- case 3:
- RollTable[1] = RollTable[0] + 10.00;
+ chance = 2.50;
+ break;
+ case 2:
+ chance = 5.00;
+ break;
+ case 3:
+ chance = 10.00;
break;
}
}
}
}
-
- //////////////////////////////////////////////////////
- // parry
- //////////////////////////////////////////////////////
- if (damage > 0 && CanThisClassParry() && !other->BehindMob(this, other->GetX(), other->GetY()))
- {
- skill = CastToClient()->GetSkill(PARRY);
- if (IsClient()) {
- CastToClient()->CheckIncreaseSkill(PARRY, other, -10);
- }
-
- if (!ghit) { //if they are not using a garunteed hit discipline
- bonus = 2.0 + skill/60.0 + (GetDEX()/200);
- bonus = bonus * (100 + defender->spellbonuses.ParryChance + defender->itembonuses.ParryChance) / 100.0f;
- RollTable[2] = RollTable[1] + bonus;
- }
- }
- else{
- RollTable[2] = RollTable[1];
- }
- ////////////////////////////////////////////////////////
- // dodge
- ////////////////////////////////////////////////////////
- if (damage > 0 && CanThisClassDodge() && !other->BehindMob(this, other->GetX(), other->GetY()))
+ if(roll <= chance)
{
-
- skill = CastToClient()->GetSkill(DODGE);
- if (IsClient()) {
- CastToClient()->CheckIncreaseSkill(DODGE, other, -10);
- }
-
- if (!ghit) { //if they are not using a garunteed hit discipline
- bonus = 2.0 + skill/60.0 + (GetAGI()/200);
- bonus = bonus * (100 + defender->spellbonuses.DodgeChance + defender->itembonuses.DodgeChance) / 100.0f;
- RollTable[3] = RollTable[2] + bonus;
+ if (IsClient() && GetAA(aaShieldBlock) > 0)
+ {
+ CastToClient()->CheckIncreaseSkill(BLOCKSKILL, other, -10);
}
+ damage = -1;
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return true;
}
- else{
- RollTable[3] = RollTable[2];
- }
-
- if(damage > 0){
- roll = MakeRandomFloat(0,100);
- if(roll <= RollTable[0]){
+
+ if(inFront)
+ {
+ //////////////////////////////////////////////////////////
+ // make enrage same as riposte
+ /////////////////////////////////////////////////////////
+ if (IsEnraged())
+ {
damage = -3;
+ mlog(COMBAT__DAMAGE, "I am enraged, riposting frontal attack.");
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return true;
}
- else if(roll <= RollTable[1]){
- damage = -1;
+
+ /////////////////////////////////////////////////////////
+ // riposte
+ /////////////////////////////////////////////////////////
+ if (CanThisClassRiposte())
+ {
+ chance += (2.0 + (float)GetSkill(RIPOSTE)/60.0 + ((float)GetDEX()/200.0)) * ((100 + this->spellbonuses.RiposteChance + this->itembonuses.RiposteChance) / 100.0f);
+
+ if(roll <= chance)
+ {
+ if (IsClient())
+ {
+ CastToClient()->CheckIncreaseSkill(RIPOSTE, other, -10);
+ }
+ damage = -3;
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return true;
+ }
}
- else if(roll <= RollTable[2]){
- damage = -2;
+ //////////////////////////////////////////////////////
+ // parry
+ //////////////////////////////////////////////////////
+ if (CanThisClassParry())
+ {
+ chance += (2.0 + (float)CastToClient()->GetSkill(PARRY)/60.0 + ((float)GetDEX()/200.0)) * ((100 + this->spellbonuses.ParryChance + this->itembonuses.ParryChance) / 100.0f);
+
+ if(roll <= chance)
+ {
+ if (IsClient())
+ {
+ CastToClient()->CheckIncreaseSkill(PARRY, other, -10);
+ }
+ damage = -2;
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return true;
+ }
}
- else if(roll <= RollTable[3]){
- damage = -4;
+
+ ////////////////////////////////////////////////////////
+ // dodge
+ ////////////////////////////////////////////////////////
+ if(CanThisClassDodge())
+ {
+ chance += (2.0 + (float)CastToClient()->GetSkill(DODGE)/60.0 + ((float)GetAGI()/200.0)) * ((100 + this->spellbonuses.DodgeChance + this->itembonuses.DodgeChance) / 100.0f);
+
+ if(roll <= chance)
+ {
+ if (IsClient())
+ {
+ CastToClient()->CheckIncreaseSkill(DODGE, other, -10);
+ }
+ damage = -4;
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return true;
+ }
}
}
-
mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
-
- if (damage < 0)
- return true;
return false;
}
Here is the diff against 1473 zone/attack.cpp:
C:\Program Files (x86)\GnuWin32\bin>diff c:\Users\Wolftousen\Documents\fdO.txt c:\Users\Wolftousen\workspace\EQEmuServer\zone\att ack.cpp -u
--- c:\Users\Wolftousen\Documents\fdO.txt 2010-05-09 22:52:42.436100000 -0400
+++ c:\Users\Wolftousen\workspace\EQEmuServer\zone\att ack.cpp 2010-05-10 03:41:15.458150000 -0400
@@ -372,185 +372,158 @@
return(tohit_roll <= chancetohit);
}
+/* solar: called when a mob is attacked, does the checks to see if it's a hit
+* and does other mitigation checks. 'this' is the mob being attacked.
+*
+* special return values:
+* -1 - block
+* -2 - parry
+* -3 - riposte
+* -4 - dodge
+*
+*/
bool Mob::AvoidDamage(Mob* other, sint32 &damage)
-{
- /* solar: called when a mob is attacked, does the checks to see if it's a hit
- * and does other mitigation checks. 'this' is the mob being attacked.
- *
- * special return values:
- * -1 - block
- * -2 - parry
- * -3 - riposte
- * -4 - dodge
- *
- */
- float skill;
- float bonus;
- float RollTable[4] = {0,0,0,0};
- float roll;
- Mob *attacker=other;
- Mob *defender=this;
-
- //garunteed hit
- bool ghit = false;
- if((attacker->spellbonuses.MeleeSkillCheck + attacker->itembonuses.MeleeSkillCheck) > 500)
- ghit = true;
-
- //////////////////////////////////////////////////////////
- // make enrage same as riposte
- /////////////////////////////////////////////////////////
- if (IsEnraged() && !other->BehindMob(this, other->GetX(), other->GetY())) {
- damage = -3;
- mlog(COMBAT__DAMAGE, "I am enraged, riposting frontal attack.");
- }
-
- /////////////////////////////////////////////////////////
- // riposte
- /////////////////////////////////////////////////////////
- if (damage > 0 && CanThisClassRiposte() && !other->BehindMob(this, other->GetX(), other->GetY()))
- {
- skill = GetSkill(RIPOSTE);
- if (IsClient()) {
- CastToClient()->CheckIncreaseSkill(RIPOSTE, other, -10);
- }
-
- if (!ghit) { //if they are not using a garunteed hit discipline
- bonus = 2.0 + skill/60.0 + (GetDEX()/200);
- bonus = bonus * (100 + defender->spellbonuses.RiposteChance + defender->itembonuses.RiposteChance) / 100.0f;
- RollTable[0] = bonus;
- }
+{
+ //is there a garunteed hit disc in place?
+ if((other->spellbonuses.MeleeSkillCheck + other->itembonuses.MeleeSkillCheck) > 500)
+ {
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return false;
}
- ///////////////////////////////////////////////////////
- // block
- ///////////////////////////////////////////////////////
-
+ //is attacker behind or in front...
+ bool inFront = !other->BehindMob(this, other->GetX(), other->GetY());
bool bBlockFromRear = false;
- if (this->IsClient()) {
- float aaChance = 0;
-
+ if (this->IsClient())
+ {
// a successful roll on this does not mean a successful block is forthcoming. only that a chance to block
// from a direction other than the rear is granted.
- switch (GetAA(aaHightenedAwareness)) {
- case 1:
- aaChance = 8;
- break;
- case 2:
- aaChance = 16;
- break;
- case 3:
- aaChance = 24;
- break;
- case 4:
- aaChance = 32;
- break;
- case 5:
- aaChance = 40;
- break;
- }
-
- if (aaChance > MakeRandomInt(1, 100))
+ if (GetAA(aaHightenedAwareness) * 8 > MakeRandomInt(1, 100))
+ {
bBlockFromRear = true;
- }
-
- if (damage > 0 && CanThisClassBlock() && (!other->BehindMob(this, other->GetX(), other->GetY()) || bBlockFromRear)) {
- skill = CastToClient()->GetSkill(BLOCKSKILL);
- if (IsClient()) {
- CastToClient()->CheckIncreaseSkill(BLOCKSKILL, other, -10);
- }
-
- if (!ghit) { //if they are not using a garunteed hit discipline
- bonus = 2.0 + skill/35.0 + (GetDEX()/200);
- RollTable[1] = RollTable[0] + bonus;
}
}
- else{
- RollTable[1] = RollTable[0];
+
+ float chance = 0;
+ float roll = MakeRandomFloat(0,100);;
+
+ ///////////////////////////////////////////////////////
+ // block - Monk/Bst only
+ ///////////////////////////////////////////////////////
+
+ if (CanThisClassBlock() && (inFront || bBlockFromRear))
+ {
+ chance = 2.0 + (float)CastToClient()->GetSkill(BLOCKSKILL)/35.0 + ((float)GetDEX()/200.0);
}
-
- if(damage > 0 && GetAA(aaShieldBlock) && (!other->BehindMob(this, other->GetX(), other->GetY()))) {
- bool equiped = CastToClient()->m_inv.GetItem(14);
- if(equiped) {
- uint8 shield = CastToClient()->m_inv.GetItem(14)->GetItem()->ItemType;
-
- if(shield == ItemTypeShield) {
- switch(GetAA(aaShieldBlock)) {
+
+ ///////////////////////////////////////////////////////
+ // shield block - WAR/PAL/SK only
+ ///////////////////////////////////////////////////////
+
+ if(GetAA(aaShieldBlock) > 0)
+ {
+ if(CastToClient()->m_inv.GetItem(14))
+ {
+ if(CastToClient()->m_inv.GetItem(14)->GetItem()->ItemType == ItemTypeShield)
+ {
+ switch(GetAA(aaShieldBlock))
+ {
case 1:
- RollTable[1] = RollTable[0] + 2.50;
- break;
- case 2:
- RollTable[1] = RollTable[0] + 5.00;
- break;
- case 3:
- RollTable[1] = RollTable[0] + 10.00;
+ chance = 2.50;
+ break;
+ case 2:
+ chance = 5.00;
+ break;
+ case 3:
+ chance = 10.00;
break;
}
}
}
}
-
- //////////////////////////////////////////////////////
- // parry
- //////////////////////////////////////////////////////
- if (damage > 0 && CanThisClassParry() && !other->BehindMob(this, other->GetX(), other->GetY()))
- {
- skill = CastToClient()->GetSkill(PARRY);
- if (IsClient()) {
- CastToClient()->CheckIncreaseSkill(PARRY, other, -10);
- }
-
- if (!ghit) { //if they are not using a garunteed hit discipline
- bonus = 2.0 + skill/60.0 + (GetDEX()/200);
- bonus = bonus * (100 + defender->spellbonuses.ParryChance + defender->itembonuses.ParryChance) / 100.0f;
- RollTable[2] = RollTable[1] + bonus;
- }
- }
- else{
- RollTable[2] = RollTable[1];
- }
- ////////////////////////////////////////////////////////
- // dodge
- ////////////////////////////////////////////////////////
- if (damage > 0 && CanThisClassDodge() && !other->BehindMob(this, other->GetX(), other->GetY()))
+ if(roll <= chance)
{
-
- skill = CastToClient()->GetSkill(DODGE);
- if (IsClient()) {
- CastToClient()->CheckIncreaseSkill(DODGE, other, -10);
- }
-
- if (!ghit) { //if they are not using a garunteed hit discipline
- bonus = 2.0 + skill/60.0 + (GetAGI()/200);
- bonus = bonus * (100 + defender->spellbonuses.DodgeChance + defender->itembonuses.DodgeChance) / 100.0f;
- RollTable[3] = RollTable[2] + bonus;
+ if (IsClient() && GetAA(aaShieldBlock) > 0)
+ {
+ CastToClient()->CheckIncreaseSkill(BLOCKSKILL, other, -10);
}
+ damage = -1;
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return true;
}
- else{
- RollTable[3] = RollTable[2];
- }
-
- if(damage > 0){
- roll = MakeRandomFloat(0,100);
- if(roll <= RollTable[0]){
+
+ if(inFront)
+ {
+ //////////////////////////////////////////////////////////
+ // make enrage same as riposte
+ /////////////////////////////////////////////////////////
+ if (IsEnraged())
+ {
damage = -3;
+ mlog(COMBAT__DAMAGE, "I am enraged, riposting frontal attack.");
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return true;
}
- else if(roll <= RollTable[1]){
- damage = -1;
+
+ /////////////////////////////////////////////////////////
+ // riposte
+ /////////////////////////////////////////////////////////
+ if (CanThisClassRiposte())
+ {
+ chance += (2.0 + (float)GetSkill(RIPOSTE)/60.0 + ((float)GetDEX()/200.0)) * ((100 + this->spellbonuses.RiposteChance + this->itembonuses.RiposteChance) / 100.0f);
+
+ if(roll <= chance)
+ {
+ if (IsClient())
+ {
+ CastToClient()->CheckIncreaseSkill(RIPOSTE, other, -10);
+ }
+ damage = -3;
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return true;
+ }
}
- else if(roll <= RollTable[2]){
- damage = -2;
+ //////////////////////////////////////////////////////
+ // parry
+ //////////////////////////////////////////////////////
+ if (CanThisClassParry())
+ {
+ chance += (2.0 + (float)CastToClient()->GetSkill(PARRY)/60.0 + ((float)GetDEX()/200.0)) * ((100 + this->spellbonuses.ParryChance + this->itembonuses.ParryChance) / 100.0f);
+
+ if(roll <= chance)
+ {
+ if (IsClient())
+ {
+ CastToClient()->CheckIncreaseSkill(PARRY, other, -10);
+ }
+ damage = -2;
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return true;
+ }
}
- else if(roll <= RollTable[3]){
- damage = -4;
+
+ ////////////////////////////////////////////////////////
+ // dodge
+ ////////////////////////////////////////////////////////
+ if(CanThisClassDodge())
+ {
+ chance += (2.0 + (float)CastToClient()->GetSkill(DODGE)/60.0 + ((float)GetAGI()/200.0)) * ((100 + this->spellbonuses.DodgeChance + this->itembonuses.DodgeChance) / 100.0f);
+
+ if(roll <= chance)
+ {
+ if (IsClient())
+ {
+ CastToClient()->CheckIncreaseSkill(DODGE, other, -10);
+ }
+ damage = -4;
+ mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
+ return true;
+ }
}
}
-
mlog(COMBAT__DAMAGE, "Final damage after all avoidances: %d", damage);
-
- if (damage < 0)
- return true;
return false;
}