Difference between revisions of "Combat h.nss"
From Dragon Age Toolset Wiki
Dom Queron (Talk | contribs) m |
Dom Queron (Talk | contribs) (Added Combat_GetFlankingBonus) |
||
Line 5: | Line 5: | ||
=== Notable Functions === | === Notable Functions === | ||
− | |||
Line 76: | Line 75: | ||
} | } | ||
</dascript> | </dascript> | ||
+ | |||
+ | |||
+ | ==== Combat_GetFlankingBonus ==== | ||
+ | |||
+ | This function is invoked during to hit determination and returns the magnitude | ||
+ | of the benefit the attacker may receive due to his facing and location relative to | ||
+ | the target. | ||
+ | |||
+ | <dascript> | ||
+ | // ----------------------------------------------------------------------------- | ||
+ | // Determine the magnitude of positional bonuses for the attacker | ||
+ | // ----------------------------------------------------------------------------- | ||
+ | float Combat_GetFlankingBonus(object oAttacker, object oTarget) | ||
+ | { | ||
+ | |||
+ | if (HasAbility(oTarget, ABILITY_TALENT_SHIELD_TACTICS)) | ||
+ | { | ||
+ | if (IsUsingShield(oTarget)) | ||
+ | return 0.0; | ||
+ | } | ||
+ | |||
+ | if (GetHasEffects(oTarget, EFFECT_TYPE_FLANK_IMMUNITY)) | ||
+ | { | ||
+ | return 0.0; | ||
+ | } | ||
+ | |||
+ | float fAngle = GetAngleBetweenObjects(oTarget, oAttacker); | ||
+ | float fFactor = 0.0; | ||
+ | |||
+ | // ------------------------------------------------------------------------- | ||
+ | // The maximum bonus from position is +15 | ||
+ | // ------------------------------------------------------------------------- | ||
+ | float fMaxModifier = 15.0; | ||
+ | |||
+ | // The attackers ability to flank is stored in a creature property | ||
+ | float fFlankingAngle = GetCreatureProperty(oAttacker, PROPERTY_ATTRIBUTE_FLANKING_ANGLE); | ||
+ | |||
+ | if (fFlankingAngle <= 10.0 ) /*old savegames have this at 10*/ | ||
+ | { | ||
+ | fFlankingAngle = 60.0; // old savegames need this to avoid divby0 later | ||
+ | } | ||
+ | else if (fFlankingAngle>180.0) | ||
+ | { | ||
+ | fFlankingAngle = 180.0; | ||
+ | } | ||
+ | |||
+ | |||
+ | // ------------------------------------------------------------------------- | ||
+ | // Combat movement expands the maximum bonus to +20 | ||
+ | // ------------------------------------------------------------------------- | ||
+ | if (HasAbility(oAttacker, ABILITY_TALENT_COMBAT_MOVEMENT)) | ||
+ | { | ||
+ | fMaxModifier = 20.0; | ||
+ | } | ||
+ | |||
+ | if ( fMaxModifier <= 0.0 ) | ||
+ | { | ||
+ | return 0.0; | ||
+ | } | ||
+ | |||
+ | if ( (fAngle>= (180.0 - fFlankingAngle) && fAngle<=(180.0 + fFlankingAngle ))) | ||
+ | { | ||
+ | // Shield block negates flanking on the left. | ||
+ | |||
+ | int bShieldBlock = HasAbility(oTarget,ABILITY_TALENT_SHIELD_BLOCK); | ||
+ | int bUsingShield = IsUsingShield(oTarget); | ||
+ | |||
+ | if (!bShieldBlock || fAngle < 180.0 || (bShieldBlock && !bUsingShield) ) | ||
+ | { | ||
+ | fFactor = (fFlankingAngle - fabs( 180.0 - fAngle))/fFlankingAngle; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | // Only rogues get the full positional benefits on the battlefield, | ||
+ | // everyone else gets half | ||
+ | float fClassModifier = GetCreatureCoreClass(oAttacker) == CLASS_ROGUE?1.0f:0.5f; | ||
+ | |||
+ | |||
+ | return fFactor * fMaxModifier * fClassModifier; | ||
+ | } | ||
+ | </dascript> | ||
+ | |||
[[Category: Scripts]] | [[Category: Scripts]] |
Revision as of 02:43, 28 October 2009
Overview
Combat_h.nss handles the core rule resolution logic for non-talent combat interaction.
Notable Functions
Combat_CheckBackstab
// ----------------------------------------------------------------------------- // Check if backstab conditions are true // ----------------------------------------------------------------------------- int Combat_CheckBackstab(object oAttacker, object oTarget, object oWeapon, float fFlankingBonus) { // ------------------------------------------------------------------------- // If we we are a rogue // ------------------------------------------------------------------------- if (!HasAbility(oAttacker, ABILITY_TALENT_HIDDEN_ROGUE)) { return FALSE; } // ------------------------------------------------------------------------- // Only humanoid rigs have the backstab anim // ------------------------------------------------------------------------- if (!IsHumanoid(oAttacker)) { return FALSE; } // ------------------------------------------------------------------------- // And target is not immune // ------------------------------------------------------------------------- if (HasAbility(oTarget, ABILITY_TRAIT_CRITICAL_HIT_IMMUNITY)) { return FALSE; } // ------------------------------------------------------------------------- // And attacker does not use double strike mode // ------------------------------------------------------------------------- if (IsModalAbilityActive(oAttacker, ABILITY_TALENT_DUAL_WEAPON_DOUBLE_STRIKE)) { return FALSE; } // ------------------------------------------------------------------------- // We can only backstab if we are flanking. // ------------------------------------------------------------------------- if (fFlankingBonus>0.0) { return TRUE; } else { /* Coup de grace*/ if (HasAbility(oAttacker, ABILITY_TALENT_BACKSTAB)) { if (GetHasEffects(oTarget, EFFECT_TYPE_STUN)) { return TRUE; } else if (GetHasEffects(oTarget, EFFECT_TYPE_PARALYZE)) { return TRUE; } } } return FALSE; }
Combat_GetFlankingBonus
This function is invoked during to hit determination and returns the magnitude of the benefit the attacker may receive due to his facing and location relative to the target.
// ----------------------------------------------------------------------------- // Determine the magnitude of positional bonuses for the attacker // ----------------------------------------------------------------------------- float Combat_GetFlankingBonus(object oAttacker, object oTarget) { if (HasAbility(oTarget, ABILITY_TALENT_SHIELD_TACTICS)) { if (IsUsingShield(oTarget)) return 0.0; } if (GetHasEffects(oTarget, EFFECT_TYPE_FLANK_IMMUNITY)) { return 0.0; } float fAngle = GetAngleBetweenObjects(oTarget, oAttacker); float fFactor = 0.0; // ------------------------------------------------------------------------- // The maximum bonus from position is +15 // ------------------------------------------------------------------------- float fMaxModifier = 15.0; // The attackers ability to flank is stored in a creature property float fFlankingAngle = GetCreatureProperty(oAttacker, PROPERTY_ATTRIBUTE_FLANKING_ANGLE); if (fFlankingAngle <= 10.0 ) /*old savegames have this at 10*/ { fFlankingAngle = 60.0; // old savegames need this to avoid divby0 later } else if (fFlankingAngle>180.0) { fFlankingAngle = 180.0; } // ------------------------------------------------------------------------- // Combat movement expands the maximum bonus to +20 // ------------------------------------------------------------------------- if (HasAbility(oAttacker, ABILITY_TALENT_COMBAT_MOVEMENT)) { fMaxModifier = 20.0; } if ( fMaxModifier <= 0.0 ) { return 0.0; } if ( (fAngle>= (180.0 - fFlankingAngle) && fAngle<=(180.0 + fFlankingAngle ))) { // Shield block negates flanking on the left. int bShieldBlock = HasAbility(oTarget,ABILITY_TALENT_SHIELD_BLOCK); int bUsingShield = IsUsingShield(oTarget); if (!bShieldBlock || fAngle < 180.0 || (bShieldBlock && !bUsingShield) ) { fFactor = (fFlankingAngle - fabs( 180.0 - fAngle))/fFlankingAngle; } } // Only rogues get the full positional benefits on the battlefield, // everyone else gets half float fClassModifier = GetCreatureCoreClass(oAttacker) == CLASS_ROGUE?1.0f:0.5f; return fFactor * fMaxModifier * fClassModifier; }