Advertisement
lufusol

Restored Content Additional Perks damageManagerProcessor.ws for Witcher 3 4.01

Feb 11th, 2023
1,470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***********************************************************************/
  2. /**     © 2015 CD PROJEKT S.A. All rights reserved.
  3. /**     THE WITCHER® is a trademark of CD PROJEKT S. A.
  4. /**     The Witcher game is based on the prose of Andrzej Sapkowski.
  5. /***********************************************************************/
  6.  
  7.  
  8.  
  9.  
  10.  
  11. class W3DamageManagerProcessor extends CObject
  12. {
  13.    
  14.     private var playerAttacker              : CR4Player;               
  15.     private var playerVictim                : CR4Player;               
  16.     private var action                      : W3DamageAction;
  17.     private var attackAction                : W3Action_Attack;         
  18.     private var weaponId                    : SItemUniqueId;           
  19.     private var actorVictim                 : CActor;                  
  20.     private var actorAttacker               : CActor;                  
  21.     private var dm                          : CDefinitionsManagerAccessor;
  22.     private var attackerMonsterCategory     : EMonsterCategory;
  23.     private var victimMonsterCategory       : EMonsterCategory;
  24.     private var victimCanBeHitByFists       : bool;
  25.    
  26.    
  27.     public function ProcessAction(act : W3DamageAction)
  28.     {
  29.         var wasAlive, validDamage, isFrozen, autoFinishersEnabled : bool;
  30.         var focusDrain : float;
  31.         var npc : CNewNPC;
  32.         var buffs : array<EEffectType>;
  33.         var arrStr : array<string>;
  34.         var aerondight  : W3Effect_Aerondight;
  35.         var trailFxName : name;
  36.        
  37.        
  38.         var swordEntity : CWitcherSword;
  39.         var swordItem : SItemUniqueId;
  40.         var bloodType : EBloodType;
  41.        
  42.            
  43.         wasAlive = act.victim.IsAlive();       
  44.         npc = (CNewNPC)act.victim;
  45.        
  46.        
  47.         InitializeActionVars(act);
  48.        
  49.        
  50.        
  51.         if(playerVictim && attackAction && attackAction.IsActionMelee() && !attackAction.CanBeParried() && attackAction.IsParried())
  52.         {
  53.             action.GetEffectTypes(buffs);
  54.            
  55.             if(!buffs.Contains(EET_Knockdown) && !buffs.Contains(EET_HeavyKnockdown))
  56.             {
  57.                
  58.                 action.SetParryStagger();
  59.                
  60.                
  61.                 action.SetProcessBuffsIfNoDamage(true);
  62.                
  63.                
  64.                 action.AddEffectInfo(EET_LongStagger);
  65.                
  66.                
  67.                 action.SetHitAnimationPlayType(EAHA_ForceNo);
  68.                 action.SetCanPlayHitParticle(false);
  69.                
  70.                
  71.                 action.RemoveBuffsByType(EET_Bleeding);
  72.                
  73.                
  74.                 action.RemoveBuffsByType(EET_Bleeding1);
  75.                 action.RemoveBuffsByType(EET_Bleeding2);
  76.                 action.RemoveBuffsByType(EET_Bleeding3);
  77.                
  78.             }
  79.         }
  80.        
  81.         // BEING DEVASTATING BLOWS ABILITY RESTORATION
  82.         if( playerAttacker && npc && attackAction && playerAttacker.IsHeavyAttack( attackAction.GetAttackName() ) && playerAttacker.GetStat(BCS_Focus) >= 1.0f && GetWitcherPlayer().CanUseSkill(S_Perk_24))
  83.         {
  84.             attackAction.SetUsedZeroStaminaPerk();
  85.             playerAttacker.DrainFocus( 1.0f );
  86.         }
  87.         // END DEVASTATING BLOWS ABILITY RESTORATION
  88.        
  89.         if(actorAttacker && playerVictim && ((W3PlayerWitcher)playerVictim) && GetWitcherPlayer().IsAnyQuenActive())
  90.             FactsAdd("player_had_quen");
  91.        
  92.        
  93.         ProcessPreHitModifications();
  94.  
  95.        
  96.         ProcessActionQuest(act);
  97.        
  98.        
  99.         isFrozen = (actorVictim && actorVictim.HasBuff(EET_Frozen));
  100.        
  101.        
  102.         validDamage = ProcessActionDamage();
  103.        
  104.        
  105.         if(wasAlive && !action.victim.IsAlive())
  106.         {
  107.             arrStr.PushBack(action.victim.GetDisplayName());
  108.             if(npc && npc.WillBeUnconscious())
  109.             {
  110.                 theGame.witcherLog.AddCombatMessage(GetLocStringByKeyExtWithParams("hud_combat_log_unconscious", , , arrStr), NULL, action.victim);
  111.             }
  112.             else if(action.attacker && action.attacker.GetDisplayName() != "")
  113.             {
  114.                 arrStr.PushBack(action.attacker.GetDisplayName());
  115.                 theGame.witcherLog.AddCombatMessage(GetLocStringByKeyExtWithParams("hud_combat_log_killed", , , arrStr), action.attacker, action.victim);
  116.             }
  117.             else
  118.             {
  119.                 theGame.witcherLog.AddCombatMessage(GetLocStringByKeyExtWithParams("hud_combat_log_dies", , , arrStr), NULL, action.victim);
  120.             }
  121.         }
  122.        
  123.         if( wasAlive && action.DealsAnyDamage() )
  124.         {
  125.             ((CActor) action.attacker).SignalGameplayEventParamFloat(  'CausesDamage', MaxF( action.processedDmg.vitalityDamage, action.processedDmg.essenceDamage ) );
  126.         }
  127.        
  128.        
  129.         ProcessActionReaction(isFrozen, wasAlive);
  130.        
  131.        
  132.         if(action.DealsAnyDamage() || action.ProcessBuffsIfNoDamage())
  133.             ProcessActionBuffs();
  134.        
  135.        
  136.         if(theGame.CanLog() && !validDamage && action.GetEffectsCount() == 0)
  137.         {
  138.             LogAssert(false, "W3DamageManagerProcessor.ProcessAction: action deals no damage and gives no buffs - investigate!");
  139.             if ( theGame.CanLog() )
  140.             {
  141.                 LogDMHits("*** Action has no valid damage and no valid buffs - investigate!", action);
  142.             }
  143.         }
  144.        
  145.        
  146.         if( actorAttacker && wasAlive )
  147.             actorAttacker.OnProcessActionPost(action);
  148.  
  149.        
  150.         if(actorVictim == GetWitcherPlayer() && action.DealsAnyDamage() && !action.IsDoTDamage())
  151.         {
  152.             if(actorAttacker && attackAction)
  153.             {
  154.                 if(actorAttacker.IsHeavyAttack( attackAction.GetAttackName() ))
  155.                     focusDrain = CalculateAttributeValue(thePlayer.GetAttributeValue('heavy_attack_focus_drain'));
  156.                 else if(actorAttacker.IsSuperHeavyAttack( attackAction.GetAttackName() ))
  157.                     focusDrain = CalculateAttributeValue(thePlayer.GetAttributeValue('super_heavy_attack_focus_drain'));
  158.                 else
  159.                     focusDrain = CalculateAttributeValue(thePlayer.GetAttributeValue('light_attack_focus_drain'));
  160.             }
  161.             else
  162.             {
  163.                
  164.                 focusDrain = CalculateAttributeValue(thePlayer.GetAttributeValue('light_attack_focus_drain'));
  165.             }
  166.            
  167.            
  168.             if ( GetWitcherPlayer().CanUseSkill(S_Sword_s16) )
  169.                 focusDrain *= 1 - (CalculateAttributeValue( thePlayer.GetSkillAttributeValue(S_Sword_s16, 'focus_drain_reduction', false, true) ) * thePlayer.GetSkillLevel(S_Sword_s16));
  170.                
  171.             thePlayer.DrainFocus(focusDrain);
  172.         }
  173.        
  174.        
  175.         if(actorAttacker == GetWitcherPlayer() && actorVictim && !actorVictim.IsAlive() && (action.IsActionMelee() || action.GetBuffSourceName() == "Kill"))
  176.         {
  177.             autoFinishersEnabled = theGame.GetInGameConfigWrapper().GetVarValue('Gameplay', 'AutomaticFinishersEnabled');
  178.            
  179.            
  180.            
  181.            
  182.             if(!autoFinishersEnabled || !thePlayer.GetFinisherVictim())
  183.             {
  184.                 if(thePlayer.HasAbility('Runeword 10 _Stats', true))
  185.                     GetWitcherPlayer().Runeword10Triggerred();
  186.                 if(thePlayer.HasAbility('Runeword 12 _Stats', true))
  187.                     GetWitcherPlayer().Runeword12Triggerred();
  188.             }
  189.         }
  190.        
  191.        
  192.         if(action.EndsQuen() && actorVictim)
  193.         {
  194.             actorVictim.FinishQuen(false);         
  195.         }
  196.  
  197.        
  198.         if(actorVictim == thePlayer && attackAction && attackAction.IsActionMelee() && (ShouldProcessTutorial('TutorialDodge') || ShouldProcessTutorial('TutorialCounter') || ShouldProcessTutorial('TutorialParry')) )
  199.         {
  200.             if(attackAction.IsCountered())
  201.             {
  202.                 theGame.GetTutorialSystem().IncreaseCounters();
  203.             }
  204.             else if(attackAction.IsParried())
  205.             {
  206.                 theGame.GetTutorialSystem().IncreaseParries();
  207.             }
  208.            
  209.             if(attackAction.CanBeDodged() && !attackAction.WasDodged())
  210.             {
  211.                 GameplayFactsAdd("tut_failed_dodge", 1, 1);
  212.                 GameplayFactsAdd("tut_failed_roll", 1, 1);
  213.             }
  214.         }
  215.        
  216.         if( playerAttacker && npc && action.IsActionMelee() && action.DealtDamage() && IsRequiredAttitudeBetween( playerAttacker, npc, true ))
  217.         {      
  218.             if(!npc.HasTag( 'AerondightIgnore' ))  
  219.             {
  220.                 if( playerAttacker.inv.ItemHasTag( attackAction.GetWeaponId(), 'Aerondight' ) )
  221.                 {
  222.                    
  223.                     aerondight = (W3Effect_Aerondight)playerAttacker.GetBuff( EET_Aerondight );
  224.                     aerondight.IncreaseAerondightCharges( attackAction.GetAttackName() );
  225.                    
  226.                    
  227.                     if( aerondight.GetCurrentCount() == aerondight.GetMaxCount() )
  228.                     {
  229.                         switch( npc.GetBloodType() )
  230.                         {
  231.                             case BT_Red :
  232.                                 trailFxName = 'aerondight_blood_red';
  233.                                 break;
  234.                                
  235.                             case BT_Yellow :
  236.                                 trailFxName = 'aerondight_blood_yellow';
  237.                                 break;
  238.                            
  239.                             case BT_Black :
  240.                                 trailFxName = 'aerondight_blood_black';
  241.                                 break;
  242.                            
  243.                             case BT_Green :
  244.                                 trailFxName = 'aerondight_blood_green';
  245.                                 break;
  246.                         }
  247.                        
  248.                         playerAttacker.inv.GetItemEntityUnsafe( attackAction.GetWeaponId() ).PlayEffect( trailFxName );
  249.                     }
  250.                 }
  251.             }
  252.            
  253.            
  254.             if(!action.WasDodged() && !attackAction.IsParried() && !attackAction.IsCountered())
  255.             {
  256.                 swordItem = GetWitcherPlayer().GetHeldSword();
  257.                 if(swordItem != GetInvalidUniqueId())
  258.                 {
  259.                     swordEntity = (CWitcherSword)thePlayer.GetInventory().GetItemEntityUnsafe( swordItem );
  260.                     if(swordEntity)
  261.                     {
  262.                         bloodType = npc.GetBloodType();
  263.                         if(bloodType == BT_Red || bloodType == BT_Yellow)
  264.                         {
  265.                             swordEntity.PlayEffectSingle('weapon_blood');
  266.                         }
  267.                         else if (bloodType == BT_Black || npc.HasAbility('mon_kikimora_warrior') || npc.HasAbility('mon_kikimora_worker') || npc.HasAbility('mon_black_spider_base') || npc.HasAbility('mon_black_spider_ep2_base') )
  268.                         {
  269.                             swordEntity.PlayEffectSingle('weapon_blood_black');
  270.                         }
  271.                         else if (bloodType == BT_Green)
  272.                         {
  273.                             swordEntity.PlayEffectSingle('weapon_blood_green');
  274.                         }
  275.                     }
  276.                 }
  277.             }
  278.            
  279.         }
  280.     }
  281.    
  282.    
  283.     private final function InitializeActionVars(act : W3DamageAction)
  284.     {
  285.         var tmpName : name;
  286.         var tmpBool : bool;
  287.    
  288.         action              = act;
  289.         playerAttacker      = (CR4Player)action.attacker;
  290.         playerVictim        = (CR4Player)action.victim;
  291.         attackAction        = (W3Action_Attack)action;     
  292.         actorVictim         = (CActor)action.victim;
  293.         actorAttacker       = (CActor)action.attacker;
  294.         dm                  = theGame.GetDefinitionsManager();
  295.        
  296.         if(attackAction)
  297.             weaponId        = attackAction.GetWeaponId();
  298.            
  299.         theGame.GetMonsterParamsForActor(actorVictim, victimMonsterCategory, tmpName, tmpBool, tmpBool, victimCanBeHitByFists);
  300.        
  301.         if(actorAttacker)
  302.             theGame.GetMonsterParamsForActor(actorAttacker, attackerMonsterCategory, tmpName, tmpBool, tmpBool, tmpBool);
  303.     }
  304.    
  305.    
  306.    
  307.    
  308.    
  309.    
  310.     private function ProcessActionQuest(act : W3DamageAction)
  311.     {
  312.         var victimTags, attackerTags : array<name>;
  313.        
  314.         victimTags = action.victim.GetTags();
  315.        
  316.         if(action.attacker)
  317.             attackerTags = action.attacker.GetTags();
  318.        
  319.         AddHitFacts( victimTags, attackerTags, "_weapon_hit" );
  320.        
  321.        
  322.         if ((CGameplayEntity) action.victim) action.victim.OnWeaponHit(act);
  323.     }
  324.    
  325.    
  326.    
  327.    
  328.    
  329.     private function ProcessActionDamage() : bool
  330.     {
  331.         var directDmgIndex, size, i : int;
  332.         var dmgInfos : array< SRawDamage >;
  333.         var immortalityMode : EActorImmortalityMode;
  334.         var dmgValue : float;
  335.         var anyDamageProcessed, fallingRaffard : bool;
  336.         var victimHealthPercBeforeHit, frozenAdditionalDamage : float;     
  337.         var powerMod : SAbilityAttributeValue;
  338.         var witcher : W3PlayerWitcher;
  339.         var canLog : bool;
  340.         var immortalityChannels : array<EActorImmortalityChanel>;
  341.        
  342.         canLog = theGame.CanLog();
  343.        
  344.        
  345.         action.SetAllProcessedDamageAs(0);
  346.         size = action.GetDTs( dmgInfos );
  347.         action.SetDealtFireDamage(false);      
  348.        
  349.        
  350.         if(!actorVictim || (!actorVictim.UsesVitality() && !actorVictim.UsesEssence()) )
  351.         {
  352.            
  353.             for(i=0; i<size; i+=1)
  354.             {
  355.                 if(dmgInfos[i].dmgType == theGame.params.DAMAGE_NAME_FIRE && dmgInfos[i].dmgVal > 0)
  356.                 {
  357.                     action.victim.OnFireHit( (CGameplayEntity)action.causer );
  358.                     break;
  359.                 }
  360.             }
  361.            
  362.             if ( !actorVictim.abilityManager )
  363.                 actorVictim.OnDeath(action);
  364.            
  365.             return false;
  366.         }
  367.        
  368.        
  369.         if(actorVictim.UsesVitality())
  370.             victimHealthPercBeforeHit = actorVictim.GetStatPercents(BCS_Vitality);
  371.         else
  372.             victimHealthPercBeforeHit = actorVictim.GetStatPercents(BCS_Essence);
  373.            
  374.        
  375.         if ( actorVictim && playerAttacker && victimMonsterCategory == MC_Specter && playerAttacker.HasBuff(EET_Mutagen28) && !actorVictim.HasAbility( 'ShadowFormActive' ) )
  376.         {
  377.             actorVictim.BlockAbility('ShadowForm', true);          
  378.             actorVictim.BlockAbility('Flashstep', true);           
  379.             actorVictim.BlockAbility('EssenceRegen', true);
  380.             actorVictim.BlockAbility('Teleport', true);
  381.            
  382.             actorVictim.BlockAbility('Specter', true);         
  383.         }
  384.        
  385.  
  386.    
  387.        
  388.         ProcessDamageIncrease( dmgInfos );
  389.                    
  390.        
  391.         if ( canLog )
  392.         {
  393.             LogBeginning();
  394.         }
  395.            
  396.        
  397.         ProcessCriticalHitCheck();
  398.        
  399.        
  400.         ProcessOnBeforeHitChecks();
  401.        
  402.        
  403.         powerMod = GetAttackersPowerMod();
  404.  
  405.        
  406.         anyDamageProcessed = false;
  407.         directDmgIndex = -1;
  408.         witcher = GetWitcherPlayer();
  409.         size = dmgInfos.Size();        
  410.         for( i = 0; i < size; i += 1 )
  411.         {
  412.            
  413.             if(dmgInfos[i].dmgVal == 0)
  414.                 continue;
  415.            
  416.             if(dmgInfos[i].dmgType == theGame.params.DAMAGE_NAME_DIRECT)
  417.             {
  418.                 directDmgIndex = i;
  419.                 continue;
  420.             }
  421.            
  422.            
  423.             if(dmgInfos[i].dmgType == theGame.params.DAMAGE_NAME_POISON && witcher == actorVictim && witcher.HasBuff(EET_GoldenOriole) && witcher.GetPotionBuffLevel(EET_GoldenOriole) == 3)
  424.             {
  425.                
  426.                 witcher.GainStat(BCS_Vitality, dmgInfos[i].dmgVal);
  427.                
  428.                
  429.                 if ( canLog )
  430.                 {
  431.                     LogDMHits("", action);
  432.                     LogDMHits("*** Player absorbs poison damage from level 3 Golden Oriole potion: " + dmgInfos[i].dmgVal, action);
  433.                 }
  434.                
  435.                
  436.                 dmgInfos[i].dmgVal = 0;
  437.                
  438.                 continue;
  439.             }
  440.            
  441.            
  442.             if ( canLog )
  443.             {
  444.                 LogDMHits("", action);
  445.                 LogDMHits("*** Incoming " + NoTrailZeros(dmgInfos[i].dmgVal) + " " + dmgInfos[i].dmgType + " damage", action);
  446.                 if(action.IsDoTDamage())
  447.                     LogDMHits("DoT's current dt = " + NoTrailZeros(action.GetDoTdt()) + ", estimated dps = " + NoTrailZeros(dmgInfos[i].dmgVal / action.GetDoTdt()), action);
  448.             }
  449.            
  450.            
  451.             anyDamageProcessed = true;
  452.                
  453.            
  454.             dmgValue = MaxF(0, CalculateDamage(dmgInfos[i], powerMod));
  455.        
  456.            
  457.             if( DamageHitsEssence(  dmgInfos[i].dmgType ) )     action.processedDmg.essenceDamage  += dmgValue;
  458.             if( DamageHitsVitality( dmgInfos[i].dmgType ) )     action.processedDmg.vitalityDamage += dmgValue;
  459.             if( DamageHitsMorale(   dmgInfos[i].dmgType ) )     action.processedDmg.moraleDamage   += dmgValue;
  460.             if( DamageHitsStamina(  dmgInfos[i].dmgType ) )     action.processedDmg.staminaDamage  += dmgValue;
  461.         }
  462.        
  463.         if(size == 0 && canLog)
  464.         {
  465.             LogDMHits("*** There is no incoming damage set (probably only buffs).", action);
  466.         }
  467.        
  468.         if ( canLog )
  469.         {
  470.             LogDMHits("", action);
  471.             LogDMHits("Processing block, parry, immortality, signs and other GLOBAL damage reductions...", action);    
  472.         }
  473.        
  474.        
  475.         if(actorVictim)
  476.             actorVictim.ReduceDamage(action);
  477.                
  478.        
  479.         if(directDmgIndex != -1)
  480.         {
  481.             anyDamageProcessed = true;
  482.            
  483.            
  484.             immortalityChannels = actorVictim.GetImmortalityModeChannels(AIM_Invulnerable);
  485.             fallingRaffard = immortalityChannels.Size() == 1 && immortalityChannels.Contains(AIC_WhiteRaffardsPotion) && action.GetBuffSourceName() == "FallingDamage";
  486.            
  487.             if(action.GetIgnoreImmortalityMode() || (!actorVictim.IsImmortal() && !actorVictim.IsInvulnerable() && !actorVictim.IsKnockedUnconscious()) || fallingRaffard)
  488.             {
  489.                 action.processedDmg.vitalityDamage += dmgInfos[directDmgIndex].dmgVal;
  490.                 action.processedDmg.essenceDamage  += dmgInfos[directDmgIndex].dmgVal;
  491.             }
  492.             else if( actorVictim.IsInvulnerable() )
  493.             {
  494.                
  495.             }
  496.             else if( actorVictim.IsImmortal() )
  497.             {
  498.                
  499.                 action.processedDmg.vitalityDamage += MinF(dmgInfos[directDmgIndex].dmgVal, actorVictim.GetStat(BCS_Vitality)-1 );
  500.                 action.processedDmg.essenceDamage  += MinF(dmgInfos[directDmgIndex].dmgVal, actorVictim.GetStat(BCS_Essence)-1 );
  501.             }
  502.         }
  503.        
  504.        
  505.         if( actorVictim.HasAbility( 'OneShotImmune' ) )
  506.         {
  507.             if( action.processedDmg.vitalityDamage >= actorVictim.GetStatMax( BCS_Vitality ) )
  508.             {
  509.                 action.processedDmg.vitalityDamage = actorVictim.GetStatMax( BCS_Vitality ) - 1;
  510.             }
  511.             else if( action.processedDmg.essenceDamage >= actorVictim.GetStatMax( BCS_Essence ) )
  512.             {
  513.                 action.processedDmg.essenceDamage = actorVictim.GetStatMax( BCS_Essence ) - 1;
  514.             }
  515.         }
  516.        
  517.        
  518.         if(action.HasDealtFireDamage())
  519.             action.victim.OnFireHit( (CGameplayEntity)action.causer );
  520.            
  521.        
  522.         ProcessInstantKill();
  523.            
  524.        
  525.         ProcessActionDamage_DealDamage();
  526.        
  527.        
  528.         if(playerAttacker && witcher)
  529.             witcher.SetRecentlyCountered(false);
  530.        
  531.        
  532.         if( attackAction && !attackAction.IsCountered() && playerVictim && attackAction.IsActionMelee())
  533.             theGame.GetGamerProfile().ResetStat(ES_CounterattackChain);
  534.        
  535.        
  536.         ProcessActionDamage_ReduceDurability();
  537.        
  538.        
  539.         if(playerAttacker && actorVictim)
  540.         {
  541.            
  542.             if(playerAttacker.inv.ItemHasAnyActiveOilApplied(weaponId) && (!playerAttacker.CanUseSkill(S_Alchemy_s06) || (playerAttacker.GetSkillLevel(S_Alchemy_s06) < 3)) )
  543.             {          
  544.                 playerAttacker.ReduceAllOilsAmmo( weaponId );
  545.                
  546.                 if(ShouldProcessTutorial('TutorialOilAmmo'))
  547.                 {
  548.                     FactsAdd("tut_used_oil_in_combat");
  549.                 }
  550.             }
  551.            
  552.            
  553.             playerAttacker.inv.ReduceItemRepairObjectBonusCharge(weaponId);
  554.         }
  555.        
  556.        
  557.         if(actorVictim && actorAttacker && !action.GetCannotReturnDamage() )
  558.             ProcessActionReturnedDamage(); 
  559.        
  560.         return anyDamageProcessed;
  561.     }
  562.    
  563.    
  564.     private function ProcessInstantKill()
  565.     {
  566.         var instantKill, focus : float;
  567.  
  568.         if( !actorVictim || !actorAttacker || actorVictim.IsImmuneToInstantKill() )
  569.         {
  570.             return;
  571.         }
  572.        
  573.        
  574.         if( action.WasDodged() || ( attackAction && ( attackAction.IsParried() || attackAction.IsCountered() ) ) )
  575.         {
  576.             return;
  577.         }
  578.        
  579.         if( actorAttacker.HasAbility( 'ForceInstantKill' ) && actorVictim != thePlayer )
  580.         {
  581.             action.SetInstantKill();
  582.         }
  583.        
  584.        
  585.         if( actorAttacker == thePlayer && !action.GetIgnoreInstantKillCooldown() )
  586.         {
  587.             if( !GameTimeDTAtLeastRealSecs( thePlayer.lastInstantKillTime, theGame.GetGameTime(), theGame.params.INSTANT_KILL_INTERNAL_PLAYER_COOLDOWN ) )
  588.             {
  589.                 return;
  590.             }
  591.         }
  592.    
  593.        
  594.         if( !action.GetInstantKill() )
  595.         {
  596.            
  597.             instantKill = CalculateAttributeValue( actorAttacker.GetInventory().GetItemAttributeValue( weaponId, 'instant_kill_chance' ) );
  598.            
  599.            
  600.             if( ( action.IsActionMelee() || action.IsActionRanged() ) && playerAttacker && action.DealsAnyDamage() && thePlayer.CanUseSkill( S_Sword_s03 ) && !playerAttacker.inv.IsItemFists( weaponId ) )
  601.             {
  602.                 focus = thePlayer.GetStat( BCS_Focus );
  603.                
  604.                 if( focus >= 1 )
  605.                 {
  606.                     instantKill += focus * CalculateAttributeValue( thePlayer.GetSkillAttributeValue( S_Sword_s03, 'instant_kill_chance', false, true ) ) * thePlayer.GetSkillLevel( S_Sword_s03 );
  607.                 }
  608.             }
  609.         }
  610.        
  611.        
  612.         if( action.GetInstantKill() || ( RandF() < instantKill ) )
  613.         {
  614.             if( theGame.CanLog() )
  615.             {
  616.                 if( action.GetInstantKill() )
  617.                 {
  618.                     instantKill = 1.f;
  619.                 }
  620.                 LogDMHits( "Instant kill!! (" + NoTrailZeros( instantKill * 100 ) + "% chance", action );
  621.             }
  622.        
  623.             action.processedDmg.vitalityDamage += actorVictim.GetStat( BCS_Vitality );
  624.             action.processedDmg.essenceDamage += actorVictim.GetStat( BCS_Essence );
  625.             action.SetCriticalHit();   
  626.             action.SetInstantKillFloater();        
  627.            
  628.            
  629.             if( playerAttacker )
  630.             {
  631.                 thePlayer.SetLastInstantKillTime( theGame.GetGameTime() );
  632.                 theSound.SoundEvent( 'cmb_play_deadly_hit' );
  633.                 theGame.SetTimeScale( 0.2, theGame.GetTimescaleSource( ETS_InstantKill ), theGame.GetTimescalePriority( ETS_InstantKill ), true, true );
  634.                 thePlayer.AddTimer( 'RemoveInstantKillSloMo', 0.2 );
  635.             }          
  636.         }
  637.     }
  638.    
  639.    
  640.     private function ProcessOnBeforeHitChecks()
  641.     {
  642.         var effectAbilityName, monsterBonusType : name;
  643.         var effectType : EEffectType;
  644.         var null, monsterBonusVal : SAbilityAttributeValue;
  645.         var oilLevel, skillLevel, i : int;
  646.         var baseChance, perOilLevelChance, chance : float;
  647.         var buffs : array<name>;
  648.    
  649.        
  650.         if( playerAttacker && actorVictim && attackAction && attackAction.IsActionMelee() && playerAttacker.CanUseSkill(S_Alchemy_s12) && playerAttacker.inv.ItemHasActiveOilApplied( weaponId, victimMonsterCategory ) )
  651.         {
  652.            
  653.             monsterBonusType = MonsterCategoryToAttackPowerBonus(victimMonsterCategory);
  654.             monsterBonusVal = playerAttacker.inv.GetItemAttributeValue(weaponId, monsterBonusType);
  655.        
  656.             if(monsterBonusVal != null)
  657.             {
  658.                
  659.                 oilLevel = (int)CalculateAttributeValue(playerAttacker.inv.GetItemAttributeValue(weaponId, 'level')) - 1;              
  660.                 skillLevel = playerAttacker.GetSkillLevel(S_Alchemy_s12);
  661.                 baseChance = CalculateAttributeValue(playerAttacker.GetSkillAttributeValue(S_Alchemy_s12, 'skill_chance', false, true));
  662.                 perOilLevelChance = CalculateAttributeValue(playerAttacker.GetSkillAttributeValue(S_Alchemy_s12, 'oil_level_chance', false, true));                    
  663.                 chance = baseChance * skillLevel + perOilLevelChance * oilLevel;
  664.                
  665.                
  666.                 if(RandF() < chance)
  667.                 {
  668.                    
  669.                     dm.GetContainedAbilities(playerAttacker.GetSkillAbilityName(S_Alchemy_s12), buffs);
  670.                     for(i=0; i<buffs.Size(); i+=1)
  671.                     {
  672.                         EffectNameToType(buffs[i], effectType, effectAbilityName);
  673.                         action.AddEffectInfo(effectType, , , effectAbilityName);
  674.                     }
  675.                 }
  676.             }
  677.         }
  678.     }
  679.    
  680.    
  681.     private function ProcessCriticalHitCheck()
  682.     {
  683.         var critChance, critDamageBonus : float;
  684.         var canLog, meleeOrRanged, redWolfSet, isLightAttack, isHeavyAttack, mutation2 : bool;
  685.         var arrStr : array<string>;
  686.         var samum : CBaseGameplayEffect;
  687.         var signPower, min, max : SAbilityAttributeValue;
  688.         var aerondight : W3Effect_Aerondight;
  689.        
  690.         meleeOrRanged = playerAttacker && attackAction && ( attackAction.IsActionMelee() || attackAction.IsActionRanged() );
  691.         redWolfSet = ( W3Petard )action.causer && ( W3PlayerWitcher )actorAttacker && GetWitcherPlayer().IsSetBonusActive( EISB_RedWolf_1 );
  692.         mutation2 = ( W3PlayerWitcher )actorAttacker && GetWitcherPlayer().IsMutationActive(EPMT_Mutation2) && action.IsActionWitcherSign();
  693.        
  694.         if( meleeOrRanged || redWolfSet || mutation2 )
  695.         {
  696.             canLog = theGame.CanLog();
  697.        
  698.            
  699.             if( mutation2 )
  700.             {
  701.                 if( FactsQuerySum('debug_fact_critical_boy') > 0 )
  702.                 {
  703.                     critChance = 1.f;
  704.                 }
  705.                 else
  706.                 {
  707.                     signPower = action.GetPowerStatValue();
  708.                     theGame.GetDefinitionsManager().GetAbilityAttributeValue('Mutation2', 'crit_chance_factor', min, max);
  709.                     critChance = min.valueAdditive + signPower.valueMultiplicative * min.valueMultiplicative;
  710.                 }
  711.             }          
  712.             else
  713.             {
  714.                 if( attackAction )
  715.                 {
  716.                    
  717.                     if( SkillEnumToName(S_Sword_s02) == attackAction.GetAttackTypeName() )
  718.                     {              
  719.                         critChance += CalculateAttributeValue(playerAttacker.GetSkillAttributeValue(S_Sword_s02, theGame.params.CRITICAL_HIT_CHANCE, false, true)) * playerAttacker.GetSkillLevel(S_Sword_s02);
  720.                     }
  721.                    
  722.                    
  723.                     if(GetWitcherPlayer() && GetWitcherPlayer().HasRecentlyCountered() && playerAttacker.CanUseSkill(S_Sword_s11) && playerAttacker.GetSkillLevel(S_Sword_s11) > 2)
  724.                     {
  725.                         critChance += CalculateAttributeValue(playerAttacker.GetSkillAttributeValue(S_Sword_s11, theGame.params.CRITICAL_HIT_CHANCE, false, true));
  726.                     }
  727.                    
  728.                    
  729.                     isLightAttack = playerAttacker.IsLightAttack( attackAction.GetAttackName() );
  730.                     isHeavyAttack = playerAttacker.IsHeavyAttack( attackAction.GetAttackName() );
  731.                     critChance += playerAttacker.GetCriticalHitChance(isLightAttack, isHeavyAttack, actorVictim, victimMonsterCategory, (W3BoltProjectile)action.causer );
  732.                    
  733.                    
  734.                     if(action.GetIsHeadShot())
  735.                     {
  736.                         critChance += theGame.params.HEAD_SHOT_CRIT_CHANCE_BONUS;
  737.                         actorVictim.SignalGameplayEvent( 'Headshot' );
  738.                     }
  739.                    
  740.                    
  741.                     if ( actorVictim && actorVictim.IsAttackerAtBack(playerAttacker) )
  742.                     {
  743.                         critChance += theGame.params.BACK_ATTACK_CRIT_CHANCE_BONUS;
  744.                     }
  745.                        
  746.                    
  747.                     if( action.IsActionMelee() && playerAttacker.inv.ItemHasTag( attackAction.GetWeaponId(), 'Aerondight' ) )
  748.                     {
  749.                         aerondight = (W3Effect_Aerondight)playerAttacker.GetBuff( EET_Aerondight );
  750.                        
  751.                         if( aerondight && aerondight.IsFullyCharged() )
  752.                         {
  753.                            
  754.                             min = playerAttacker.GetAbilityAttributeValue( 'AerondightEffect', 'crit_chance_bonus' );
  755.                             critChance += min.valueAdditive;
  756.                         }
  757.                     }
  758.                 }
  759.                 else
  760.                 {
  761.                    
  762.                     critChance += playerAttacker.GetCriticalHitChance(false, false, actorVictim, victimMonsterCategory, (W3BoltProjectile)action.causer );
  763.                 }
  764.                
  765.                
  766.                 samum = actorVictim.GetBuff(EET_Blindness, 'petard');
  767.                 if(samum && samum.GetBuffLevel() == 3)
  768.                 {
  769.                     critChance += 1.0f;
  770.                 }
  771.             }
  772.            
  773.            
  774.             if ( canLog )
  775.             {
  776.                
  777.                 critDamageBonus = 1 + CalculateAttributeValue(actorAttacker.GetCriticalHitDamageBonus(weaponId, victimMonsterCategory, actorVictim.IsAttackerAtBack(playerAttacker)));
  778.                 critDamageBonus += CalculateAttributeValue(actorAttacker.GetAttributeValue('critical_hit_chance_fast_style'));
  779.                 critDamageBonus = 100 * critDamageBonus;
  780.                
  781.                
  782.                 LogDMHits("", action);             
  783.                 LogDMHits("Trying critical hit (" + NoTrailZeros(critChance*100) + "% chance, dealing " + NoTrailZeros(critDamageBonus) + "% damage)...", action);
  784.             }
  785.            
  786.            
  787.             if(RandF() < critChance)
  788.             {
  789.                
  790.                 action.SetCriticalHit();
  791.                                
  792.                 if ( canLog )
  793.                 {
  794.                     LogDMHits("********************", action);
  795.                     LogDMHits("*** CRITICAL HIT ***", action);
  796.                     LogDMHits("********************", action);             
  797.                 }
  798.                
  799.                 arrStr.PushBack(action.attacker.GetDisplayName());
  800.                 theGame.witcherLog.AddCombatMessage(theGame.witcherLog.COLOR_GOLD_BEGIN + GetLocStringByKeyExtWithParams("hud_combat_log_critical_hit",,,arrStr) + theGame.witcherLog.COLOR_GOLD_END, action.attacker, NULL);
  801.             }
  802.             else if ( canLog )
  803.             {
  804.                 LogDMHits("... nope", action);
  805.             }
  806.         }  
  807.     }
  808.    
  809.    
  810.     private function LogBeginning()
  811.     {
  812.         var logStr : string;
  813.        
  814.         if ( !theGame.CanLog() )
  815.         {
  816.             return;
  817.         }
  818.        
  819.         LogDMHits("-----------------------------------------------------------------------------------", action);      
  820.         logStr = "Beginning hit processing from <<" + action.attacker + ">> to <<" + action.victim + ">> via <<" + action.causer + ">>";
  821.         if(attackAction)
  822.         {
  823.             logStr += " using AttackType <<" + attackAction.GetAttackTypeName() + ">>";    
  824.         }
  825.         logStr += ":";
  826.         LogDMHits(logStr, action);
  827.         LogDMHits("", action);
  828.         LogDMHits("Target stats before damage dealt are:", action);
  829.         if(actorVictim)
  830.         {
  831.             if( actorVictim.UsesVitality() )
  832.                 LogDMHits("Vitality = " + NoTrailZeros(actorVictim.GetStat(BCS_Vitality)), action);
  833.             if( actorVictim.UsesEssence() )
  834.                 LogDMHits("Essence = " + NoTrailZeros(actorVictim.GetStat(BCS_Essence)), action);
  835.             if( actorVictim.GetStatMax(BCS_Stamina) > 0)
  836.                 LogDMHits("Stamina = " + NoTrailZeros(actorVictim.GetStat(BCS_Stamina, true)), action);
  837.             if( actorVictim.GetStatMax(BCS_Morale) > 0)
  838.                 LogDMHits("Morale = " + NoTrailZeros(actorVictim.GetStat(BCS_Morale)), action);
  839.         }
  840.         else
  841.         {
  842.             LogDMHits("Undefined - victim is not a CActor and therefore has no stats", action);
  843.         }
  844.     }
  845.    
  846.    
  847.     private function ProcessDamageIncrease(out dmgInfos : array< SRawDamage >)
  848.     {
  849.         var difficultyDamageMultiplier, rendLoad, rendBonus, overheal, rendRatio, focusCost : float;
  850.         var i, bonusCount : int;
  851.         var frozenBuff : W3Effect_Frozen;
  852.         var frozenDmgInfo : SRawDamage;
  853.         var hadFrostDamage : bool;
  854.         var mpac : CMovingPhysicalAgentComponent;
  855.         var rendBonusPerPoint, staminaRendBonus, perk20Bonus : SAbilityAttributeValue;
  856.         var witcherAttacker : W3PlayerWitcher;
  857.         var damageVal, damageBonus, min, max            : SAbilityAttributeValue;      
  858.         var npcVictim : CNewNPC;
  859.         var sword : SItemUniqueId;
  860.         var actionFreeze : W3DamageAction;
  861.         var aerondight  : W3Effect_Aerondight;
  862.        
  863.        
  864.         var aardDamage : SRawDamage;
  865.         var yrdens : array<W3YrdenEntity>;
  866.         var j, levelDiff : int;
  867.         var aardDamageF : float;
  868.         var spellPower, spellPowerAard, spellPowerYrden : float;
  869.         var spNetflix : SAbilityAttributeValue;
  870.        
  871.        
  872.        
  873.         var entities : array<CGameplayEntity>;
  874.         var skillPassiveMod : float;
  875.        
  876.  
  877.        
  878.        
  879.         if(actorAttacker && !actorAttacker.IgnoresDifficultySettings() && !action.IsDoTDamage())
  880.         {
  881.             difficultyDamageMultiplier = CalculateAttributeValue(actorAttacker.GetAttributeValue(theGame.params.DIFFICULTY_DMG_MULTIPLIER));
  882.             for(i=0; i<dmgInfos.Size(); i+=1)
  883.             {
  884.                 dmgInfos[i].dmgVal = dmgInfos[i].dmgVal * difficultyDamageMultiplier;
  885.             }
  886.         }
  887.            
  888.        
  889.        
  890.        
  891.         if(actorVictim && playerAttacker && !action.IsDoTDamage() && actorVictim.HasBuff(EET_Frozen) && ( (W3AardProjectile)action.causer || (W3AardEntity)action.causer || action.DealsPhysicalOrSilverDamage()) )
  892.         {
  893.            
  894.             action.SetWasFrozen();
  895.            
  896.            
  897.             if( !( ( W3WhiteFrost )action.causer ) )
  898.             {              
  899.                 frozenBuff = (W3Effect_Frozen)actorVictim.GetBuff(EET_Frozen);         
  900.                 frozenDmgInfo.dmgVal = frozenBuff.GetAdditionalDamagePercents() * actorVictim.GetHealth();
  901.             }
  902.            
  903.            
  904.             actorVictim.RemoveAllBuffsOfType(EET_Frozen);
  905.             action.AddEffectInfo(EET_KnockdownTypeApplicator);
  906.            
  907.            
  908.             if( !( ( W3WhiteFrost )action.causer ) )
  909.             {
  910.                 actionFreeze = new W3DamageAction in theGame;
  911.                 actionFreeze.Initialize( actorAttacker, actorVictim, action.causer, action.GetBuffSourceName(), EHRT_None, CPS_Undefined, action.IsActionMelee(), action.IsActionRanged(), action.IsActionWitcherSign(), action.IsActionEnvironment() );
  912.                 actionFreeze.SetCannotReturnDamage( true );
  913.                 actionFreeze.SetCanPlayHitParticle( false );
  914.                 actionFreeze.SetHitAnimationPlayType( EAHA_ForceNo );
  915.                 actionFreeze.SetWasFrozen();       
  916.                 actionFreeze.AddDamage( theGame.params.DAMAGE_NAME_FROST, frozenDmgInfo.dmgVal );
  917.                 theGame.damageMgr.ProcessAction( actionFreeze );
  918.                 delete actionFreeze;
  919.             }
  920.         }
  921.        
  922.        
  923.        
  924.         if(actorVictim && playerAttacker && GetWitcherPlayer().IsSetBonusActive( EISB_Netflix_2 ) && !action.IsDoTDamage() && ( (W3AardProjectile)action.causer || (W3AardEntity)action.causer))
  925.         {  
  926.             yrdens = GetWitcherPlayer().yrdenEntities;
  927.            
  928.             if(yrdens.Size() > 0)
  929.             {
  930.                 spellPowerAard = CalculateAttributeValue(GetWitcherPlayer().GetAttributeValue('spell_power_aard'));
  931.                 spellPowerYrden = CalculateAttributeValue(GetWitcherPlayer().GetAttributeValue('spell_power_yrden'));              
  932.                 spellPower = ClampF(1 + spellPowerAard + spellPowerYrden + CalculateAttributeValue(GetWitcherPlayer().GetPowerStatValue(CPS_SpellPower)), 1, 3);               
  933.            
  934.                 for(i=0; i<yrdens.Size(); i+=1)
  935.                 {
  936.                     for(j=0; j<yrdens[i].validTargetsInArea.Size(); j+=1)
  937.                     {          
  938.                         if(yrdens[i].validTargetsInArea[j] == actorVictim )
  939.                         {
  940.                             levelDiff = playerAttacker.GetLevel() - actorVictim.GetLevel();
  941.                             aardDamage.dmgType = theGame.params.DAMAGE_NAME_DIRECT;
  942.                             if( GetWitcherPlayer().CanUseSkill(S_Magic_s06) )
  943.                                 aardDamageF = (RandRangeF(375.0, 325.0) + (playerAttacker.GetLevel() * 1.8f) + (GetWitcherPlayer().GetSkillLevel(S_Magic_s06) * 100) ) * spellPower;
  944.                             else
  945.                                 aardDamageF = (RandRangeF(375.0, 325.0) + (playerAttacker.GetLevel() * 1.8f) ) * spellPower;
  946.                            
  947.                             if( actorVictim.GetCharacterStats().HasAbilityWithTag('Boss') || (W3MonsterHuntNPC)actorVictim || (levelDiff < 0 && Abs(levelDiff) > theGame.params.LEVEL_DIFF_HIGH))
  948.                             {
  949.                                 aardDamage.dmgVal = aardDamageF * 0.75f;
  950.                             }                  
  951.                             else
  952.                             {
  953.                                 aardDamage.dmgVal = aardDamageF;
  954.                             }
  955.                            
  956.                             spNetflix = action.GetPowerStatValue();
  957.                             aardDamage.dmgVal += 3 * actorVictim.GetHealth() * ( 0.01 + 0.03 * LogF( spNetflix.valueMultiplicative ) );
  958.                             dmgInfos.PushBack(aardDamage);
  959.                         }
  960.                     }
  961.                 }
  962.             }
  963.         }
  964.            
  965.        
  966.         if(actorVictim)
  967.         {
  968.             mpac = (CMovingPhysicalAgentComponent)actorVictim.GetMovingAgentComponent();
  969.                        
  970.             if(mpac && mpac.IsDiving())
  971.             {
  972.                 mpac = (CMovingPhysicalAgentComponent)actorAttacker.GetMovingAgentComponent(); 
  973.                
  974.                 if(mpac && mpac.IsDiving())
  975.                 {
  976.                     action.SetUnderwaterDisplayDamageHack();
  977.                
  978.                     if(playerAttacker && attackAction && attackAction.IsActionRanged())
  979.                     {
  980.                         for(i=0; i<dmgInfos.Size(); i+=1)
  981.                         {
  982.                             if(FactsQuerySum("NewGamePlus"))
  983.                             {
  984.                                 dmgInfos[i].dmgVal *= (1 + theGame.params.UNDERWATER_CROSSBOW_DAMAGE_BONUS_NGP);
  985.                             }
  986.                             else
  987.                             {
  988.                                 dmgInfos[i].dmgVal *= (1 + theGame.params.UNDERWATER_CROSSBOW_DAMAGE_BONUS);
  989.                             }
  990.                         }
  991.                     }
  992.                 }
  993.             }
  994.         }
  995.        
  996.        
  997.         if(playerAttacker && attackAction && SkillNameToEnum(attackAction.GetAttackTypeName()) == S_Sword_s02)
  998.         {
  999.             witcherAttacker = (W3PlayerWitcher)playerAttacker;
  1000.            
  1001.            
  1002.             rendRatio = witcherAttacker.GetSpecialAttackTimeRatio();
  1003.            
  1004.            
  1005.             rendLoad = MinF(rendRatio * playerAttacker.GetStatMax(BCS_Focus), playerAttacker.GetStat(BCS_Focus));
  1006.            
  1007.            
  1008.             if(rendLoad >= 1)
  1009.             {
  1010.                 rendBonusPerPoint = witcherAttacker.GetSkillAttributeValue(S_Sword_s02, 'adrenaline_final_damage_bonus', false, true);
  1011.                 rendBonus = FloorF(rendLoad) * rendBonusPerPoint.valueMultiplicative;
  1012.                
  1013.                 for(i=0; i<dmgInfos.Size(); i+=1)
  1014.                 {
  1015.                     dmgInfos[i].dmgVal *= (1 + rendBonus);
  1016.                 }
  1017.             }
  1018.            
  1019.            
  1020.             staminaRendBonus = witcherAttacker.GetSkillAttributeValue(S_Sword_s02, 'stamina_max_dmg_bonus', false, true);
  1021.            
  1022.             for(i=0; i<dmgInfos.Size(); i+=1)
  1023.             {
  1024.                 dmgInfos[i].dmgVal *= (1 + rendRatio * staminaRendBonus.valueMultiplicative);
  1025.             }
  1026.            
  1027.            
  1028.             thePlayer.SetAttackActionName('');
  1029.         }  
  1030.  
  1031.        
  1032.         if ( actorAttacker != thePlayer && action.IsActionRanged() && (int)CalculateAttributeValue(actorAttacker.GetAttributeValue('level',,true)) > 31)
  1033.         {
  1034.             damageVal = actorAttacker.GetAttributeValue('light_attack_damage_vitality',,true);
  1035.             for(i=0; i<dmgInfos.Size(); i+=1)
  1036.             {
  1037.                 dmgInfos[i].dmgVal = dmgInfos[i].dmgVal + CalculateAttributeValue(damageVal) / 2;
  1038.             }
  1039.         }
  1040.        
  1041.        
  1042.         if ( actorVictim && playerAttacker && attackAction && action.IsActionMelee() && thePlayer.HasAbility('Runeword 4 _Stats', true) && !attackAction.WasDodged() )
  1043.         {
  1044.             overheal = thePlayer.abilityManager.GetOverhealBonus() / thePlayer.GetStatMax(BCS_Vitality);
  1045.        
  1046.             if(overheal > 0.005f)
  1047.             {
  1048.                 for(i=0; i<dmgInfos.Size(); i+=1)
  1049.                 {
  1050.                     dmgInfos[i].dmgVal *= 1.0f + overheal;
  1051.                 }
  1052.            
  1053.                 thePlayer.abilityManager.ResetOverhealBonus();
  1054.                
  1055.                
  1056.                 actorVictim.CreateFXEntityAtPelvis( 'runeword_4', true );              
  1057.             }
  1058.         }
  1059.        
  1060.        
  1061.         if( playerAttacker && actorVictim && attackAction.IsActionMelee() && GetWitcherPlayer().IsSetBonusActive( EISB_Wolf_1 ) )
  1062.         {
  1063.             FindGameplayEntitiesInRange( entities, playerAttacker, 50, 1000, , FLAG_OnlyAliveActors );
  1064.             if( entities.Size() > 0 )
  1065.             {
  1066.                 for( i=0; i<entities.Size(); i+=1 )
  1067.                 {
  1068.                     npcVictim = (CNewNPC) entities[i];
  1069.                     if( npcVictim )
  1070.                     {
  1071.                         if( npcVictim.HasBuff( EET_Bleeding ) )  bonusCount += 1;
  1072.                         if( npcVictim.HasBuff( EET_Bleeding1 ) ) bonusCount += 1;
  1073.                         if( npcVictim.HasBuff( EET_Bleeding2 ) ) bonusCount += 1;
  1074.                         if( npcVictim.HasBuff( EET_Bleeding3 ) ) bonusCount += 1;
  1075.                     }
  1076.                 }
  1077.                
  1078.                 bonusCount *= ((W3PlayerWitcher)playerAttacker).GetSetPartsEquipped( EIST_Wolf );
  1079.                
  1080.                 for( i=0; i<dmgInfos.Size() ; i+=1 )
  1081.                 {
  1082.                     dmgInfos[i].dmgVal *= 1 + bonusCount*0.01;
  1083.                 }
  1084.             }
  1085.         }
  1086.        
  1087.        
  1088.        
  1089.         if( playerAttacker && playerAttacker.IsLightAttack( attackAction.GetAttackName() ) && playerAttacker.HasBuff( EET_LynxSetBonus ) && !attackAction.WasDodged() )
  1090.         {
  1091.             if( !attackAction.IsParried() && !attackAction.IsCountered() )
  1092.             {
  1093.                
  1094.                 damageBonus = playerAttacker.GetAttributeValue( 'lynx_dmg_boost' );
  1095.                
  1096.                 damageBonus.valueAdditive *= ((W3PlayerWitcher)playerAttacker).GetSetPartsEquipped( EIST_Lynx );
  1097.                
  1098.                 for( i=0 ; i<dmgInfos.Size() ; i += 1 )
  1099.                 {
  1100.                     dmgInfos[i].dmgVal *= 1 + damageBonus.valueAdditive;
  1101.                 }
  1102.             }
  1103.         }
  1104.  
  1105.        
  1106.         if( playerAttacker && attackAction.IsActionMelee() && actorVictim.IsAttackerAtBack( playerAttacker ) && !actorVictim.HasAbility( 'CannotBeAttackedFromBehind' ) && ((W3PlayerWitcher)playerAttacker).IsSetBonusActive( EISB_Lynx_2 ) && !attackAction.WasDodged() && ( playerAttacker.inv.IsItemSteelSwordUsableByPlayer( attackAction.GetWeaponId() ) || playerAttacker.inv.IsItemSilverSwordUsableByPlayer( attackAction.GetWeaponId() ) ) )
  1107.         {
  1108.             if( !attackAction.IsParried() && !attackAction.IsCountered() && playerAttacker.GetStat(BCS_Focus) >= 1.0f )
  1109.             {
  1110.                 theGame.GetDefinitionsManager().GetAbilityAttributeValue( GetSetBonusAbility( EISB_Lynx_2 ), 'lynx_2_dmg_boost', min, max );
  1111.                 for( i=0; i<dmgInfos.Size() ; i+=1 )
  1112.                 {
  1113.                     dmgInfos[i].dmgVal *= 1 + min.valueAdditive;
  1114.                 }
  1115.                
  1116.                 if ( !( thePlayer.IsInCombatAction() && ( thePlayer.GetCombatAction() == EBAT_SpecialAttack_Light || thePlayer.GetCombatAction() == EBAT_SpecialAttack_Heavy ) ) )
  1117.                 {
  1118.                     theGame.GetDefinitionsManager().GetAbilityAttributeValue( GetSetBonusAbility( EISB_Lynx_2 ), 'lynx_2_adrenaline_cost', min, max );
  1119.                     focusCost = min.valueAdditive;
  1120.                     if( GetWitcherPlayer().GetStat( BCS_Focus ) >= focusCost )
  1121.                     {              
  1122.                         theGame.GetDefinitionsManager().GetAbilityAttributeValue( GetSetBonusAbility( EISB_Lynx_2 ), 'lynx_2_stun_duration', min, max );
  1123.                         attackAction.AddEffectInfo( EET_Confusion, min.valueAdditive );
  1124.                         playerAttacker.SoundEvent( "ep2_setskill_lynx_activate" );
  1125.                         playerAttacker.DrainFocus( focusCost );
  1126.                     }
  1127.                 }
  1128.             }
  1129.         }
  1130.  
  1131.        
  1132.        
  1133.        
  1134.         if ( playerAttacker && action.IsActionRanged() && ((W3Petard)action.causer) )
  1135.         {
  1136.             skillPassiveMod = CalculateAttributeValue(GetWitcherPlayer().GetAttributeValue('potion_duration'));
  1137.             for( i = 0 ; i < dmgInfos.Size() ; i+=1)
  1138.             {
  1139.                 dmgInfos[i].dmgVal *= ( 1 + skillPassiveMod );
  1140.             }
  1141.            
  1142.            
  1143.             if ( GetWitcherPlayer().CanUseSkill(S_Perk_20) && !action.IsDoTDamage() )
  1144.             {
  1145.                 perk20Bonus = GetWitcherPlayer().GetSkillAttributeValue( S_Perk_20, 'dmg_multiplier', false, false);
  1146.                 for( i = 0 ; i < dmgInfos.Size() ; i+=1)
  1147.                 {
  1148.                     dmgInfos[i].dmgVal *= ( 1 + perk20Bonus.valueMultiplicative );
  1149.                 }
  1150.             }
  1151.            
  1152.         }
  1153.        
  1154.        
  1155.         if( playerAttacker && action.IsActionWitcherSign() && GetWitcherPlayer().IsMutationActive( EPMT_Mutation1 ) )
  1156.         {
  1157.             sword = playerAttacker.inv.GetCurrentlyHeldSword();
  1158.            
  1159.             damageVal.valueBase = 0;
  1160.             damageVal.valueMultiplicative = 0;
  1161.             damageVal.valueAdditive = 0;
  1162.        
  1163.             if( playerAttacker.inv.GetItemCategory(sword) == 'steelsword' )
  1164.             {
  1165.                 damageVal += playerAttacker.inv.GetItemAttributeValue(sword, theGame.params.DAMAGE_NAME_SLASHING);
  1166.             }
  1167.             else if( playerAttacker.inv.GetItemCategory(sword) == 'silversword' )
  1168.             {
  1169.                 damageVal += playerAttacker.inv.GetItemAttributeValue(sword, theGame.params.DAMAGE_NAME_SILVER);
  1170.             }
  1171.             theGame.GetDefinitionsManager().GetAbilityAttributeValue('Mutation1', 'dmg_bonus_factor', min, max);               
  1172.            
  1173.             damageVal.valueBase *= CalculateAttributeValue(min);
  1174.            
  1175.             if( action.IsDoTDamage() )
  1176.             {
  1177.                 damageVal.valueBase *= action.GetDoTdt();
  1178.             }
  1179.            
  1180.             for( i = 0 ; i < dmgInfos.Size() ; i+=1)
  1181.             {
  1182.                 dmgInfos[i].dmgVal += damageVal.valueBase;
  1183.             }
  1184.         }
  1185.        
  1186.        
  1187.         npcVictim = (CNewNPC) actorVictim;
  1188.         if( playerAttacker && npcVictim && attackAction && action.IsActionMelee() && GetWitcherPlayer().IsMutationActive( EPMT_Mutation8 ) && ( victimMonsterCategory != MC_Human || npcVictim.IsImmuneToMutation8Finisher() ) && attackAction.GetWeaponId() == GetWitcherPlayer().GetHeldSword() )
  1189.         {
  1190.             dm.GetAbilityAttributeValue( 'Mutation8', 'dmg_bonus', min, max );
  1191.            
  1192.             for( i = 0 ; i < dmgInfos.Size() ; i+=1)
  1193.             {
  1194.                 dmgInfos[i].dmgVal *= 1 + min.valueMultiplicative;
  1195.             }
  1196.         }
  1197.        
  1198.        
  1199.         if( playerAttacker && actorVictim && attackAction && action.IsActionMelee() && playerAttacker.inv.ItemHasTag( attackAction.GetWeaponId(), 'Aerondight' ) )
  1200.         {  
  1201.             aerondight = (W3Effect_Aerondight)playerAttacker.GetBuff( EET_Aerondight );
  1202.            
  1203.             if( aerondight )
  1204.             {
  1205.                 min = playerAttacker.GetAbilityAttributeValue( 'AerondightEffect', 'dmg_bonus' );
  1206.                 bonusCount = aerondight.GetCurrentCount();
  1207.            
  1208.                 if( bonusCount > 0 )
  1209.                 {
  1210.                     min.valueMultiplicative *= bonusCount;
  1211.                    
  1212.                     for( i = 0 ; i < dmgInfos.Size() ; i += 1 )
  1213.                     {
  1214.                         dmgInfos[i].dmgVal *= 1 + min.valueMultiplicative;
  1215.                     }
  1216.                 }              
  1217.             }
  1218.         }  
  1219.     }
  1220.    
  1221.    
  1222.     private function ProcessActionReturnedDamage()
  1223.     {
  1224.         var witcher             : W3PlayerWitcher;
  1225.         var quen                : W3QuenEntity;
  1226.         var params              : SCustomEffectParams;
  1227.         var processFireShield, canBeParried, canBeDodged, wasParried, wasDodged, returned : bool;
  1228.         var g5Chance            : SAbilityAttributeValue;
  1229.         var dist, checkDist     : float;
  1230.        
  1231.        
  1232.         if((W3PlayerWitcher)playerVictim && !playerAttacker && actorAttacker && !action.IsDoTDamage() && action.IsActionMelee() && (attackerMonsterCategory == MC_Necrophage || attackerMonsterCategory == MC_Vampire) && actorVictim.HasBuff(EET_BlackBlood))
  1233.         {
  1234.             returned = ProcessActionBlackBloodReturnedDamage();    
  1235.         }
  1236.        
  1237.        
  1238.         if(action.IsActionMelee() && actorVictim.HasAbility( 'Thorns' ) )
  1239.         {
  1240.             returned = ProcessActionThornDamage() || returned;
  1241.         }
  1242.        
  1243.         if(actorVictim.HasAbility( 'Glyphword 5 _Stats', true))
  1244.         {          
  1245.             if( GetAttitudeBetween(actorAttacker, actorVictim) == AIA_Hostile)
  1246.             {
  1247.                 if( !action.IsDoTDamage() )
  1248.                 {
  1249.                     g5Chance = actorVictim.GetAttributeValue('glyphword5_chance');
  1250.                    
  1251.                     if(RandF() < g5Chance.valueAdditive)
  1252.                     {
  1253.                         canBeParried = attackAction.CanBeParried();
  1254.                         canBeDodged = attackAction.CanBeDodged();
  1255.                         wasParried = attackAction.IsParried() || attackAction.IsCountered();
  1256.                         wasDodged = attackAction.WasDodged();
  1257.                
  1258.                         if(!action.IsActionMelee() || (!canBeParried && canBeDodged && !wasDodged) || (canBeParried && !wasParried && !canBeDodged) || (canBeParried && canBeDodged && !wasDodged && !wasParried))
  1259.                         {
  1260.                             returned = ProcessActionReflectDamage() || returned;
  1261.                         }
  1262.                     }  
  1263.                 }
  1264.             }          
  1265.            
  1266.         }
  1267.        
  1268.        
  1269.         if(playerVictim && !playerAttacker && actorAttacker && attackAction && attackAction.IsActionMelee() && thePlayer.HasBuff(EET_Mutagen26))
  1270.         {
  1271.             returned = ProcessActionLeshenMutagenDamage() || returned;
  1272.         }
  1273.        
  1274.        
  1275.         if(action.IsActionMelee() && actorVictim.HasAbility( 'FireShield' ) )
  1276.         {
  1277.             witcher = GetWitcherPlayer();          
  1278.             processFireShield = true;          
  1279.             if(playerAttacker == witcher)
  1280.             {
  1281.                 quen = (W3QuenEntity)witcher.GetSignEntity(ST_Quen);
  1282.                 if(quen && quen.IsAnyQuenActive())
  1283.                 {
  1284.                     processFireShield = false;
  1285.                 }
  1286.             }
  1287.            
  1288.             if(processFireShield)
  1289.             {
  1290.                 params.effectType = EET_Burning;
  1291.                 params.creator = actorVictim;
  1292.                 params.sourceName = actorVictim.GetName();
  1293.                
  1294.                 params.effectValue.valueMultiplicative = 0.01;
  1295.                 actorAttacker.AddEffectCustom(params);
  1296.                 returned = true;
  1297.             }
  1298.         }
  1299.        
  1300.        
  1301.         if(actorAttacker.UsesEssence())
  1302.         {
  1303.             returned = ProcessSilverStudsReturnedDamage() || returned;
  1304.         }
  1305.            
  1306.        
  1307.         if( (W3PlayerWitcher)playerVictim && !playerAttacker && actorAttacker && !playerAttacker.IsInFistFightMiniGame() && !action.IsDoTDamage() && action.IsActionMelee() && GetWitcherPlayer().IsMutationActive( EPMT_Mutation4 ) )
  1308.         {
  1309.            
  1310.             dist = VecDistance( actorAttacker.GetWorldPosition(), actorVictim.GetWorldPosition() );
  1311.             checkDist = 3.f;
  1312.             if( actorAttacker.IsHuge() )
  1313.             {
  1314.                 checkDist += 3.f;
  1315.             }
  1316.  
  1317.             if( dist <= checkDist )
  1318.             {
  1319.                 returned = GetWitcherPlayer().ProcessActionMutation4ReturnedDamage( action.processedDmg.vitalityDamage, actorAttacker, EAHA_ForceYes, action ) || returned;
  1320.             }
  1321.         }
  1322.        
  1323.         action.SetWasDamageReturnedToAttacker( returned );
  1324.     }
  1325.    
  1326.    
  1327.     private function ProcessActionLeshenMutagenDamage() : bool
  1328.     {
  1329.         var damageAction : W3DamageAction;
  1330.         var returnedDamage, pts, perc : float;
  1331.         var mutagen : W3Mutagen26_Effect;
  1332.        
  1333.         mutagen = (W3Mutagen26_Effect)playerVictim.GetBuff(EET_Mutagen26);
  1334.         mutagen.GetReturnedDamage(pts, perc);
  1335.        
  1336.         if(pts <= 0 && perc <= 0)
  1337.             return false;
  1338.            
  1339.        
  1340.        
  1341.         returnedDamage = pts + perc * action.processedDmg.vitalityDamage;
  1342.        
  1343.        
  1344.        
  1345.         damageAction = new W3DamageAction in this;     
  1346.         damageAction.Initialize( action.victim, action.attacker, NULL, "Mutagen26", EHRT_None, CPS_AttackPower, true, false, false, false );       
  1347.         damageAction.SetCannotReturnDamage( true );    
  1348.         damageAction.SetHitAnimationPlayType( EAHA_ForceNo );      
  1349.        
  1350.        
  1351.        
  1352.         damageAction.AddDamage(theGame.params.DAMAGE_NAME_DIRECT, returnedDamage);
  1353.        
  1354.        
  1355.         theGame.damageMgr.ProcessAction(damageAction);
  1356.         delete damageAction;
  1357.        
  1358.         return true;
  1359.     }
  1360.    
  1361.    
  1362.     private function ProcessSilverStudsReturnedDamage() : bool
  1363.     {
  1364.         var damageAction : W3DamageAction;
  1365.         var returnedDamage : float;
  1366.        
  1367.         returnedDamage = CalculateAttributeValue(actorVictim.GetAttributeValue('returned_silver_damage'));
  1368.        
  1369.         if(returnedDamage <= 0)
  1370.             return false;
  1371.        
  1372.         damageAction = new W3DamageAction in this;     
  1373.         damageAction.Initialize( action.victim, action.attacker, NULL, "SilverStuds", EHRT_None, CPS_AttackPower, true, false, false, false );     
  1374.         damageAction.SetCannotReturnDamage( true );    
  1375.         damageAction.SetHitAnimationPlayType( EAHA_ForceNo );      
  1376.        
  1377.         damageAction.AddDamage(theGame.params.DAMAGE_NAME_SILVER, returnedDamage);
  1378.        
  1379.         theGame.damageMgr.ProcessAction(damageAction);
  1380.         delete damageAction;
  1381.        
  1382.         return true;
  1383.     }
  1384.    
  1385.    
  1386.     private function ProcessActionBlackBloodReturnedDamage() : bool
  1387.     {
  1388.         var returnedAction : W3DamageAction;
  1389.         var returnVal : SAbilityAttributeValue;
  1390.         var bb : W3Potion_BlackBlood;
  1391.         var potionLevel : int;
  1392.         var returnedDamage : float;
  1393.    
  1394.         if(action.processedDmg.vitalityDamage <= 0)
  1395.             return false;
  1396.        
  1397.         bb = (W3Potion_BlackBlood)actorVictim.GetBuff(EET_BlackBlood);
  1398.         potionLevel = bb.GetBuffLevel();
  1399.        
  1400.        
  1401.         returnedAction = new W3DamageAction in this;       
  1402.         returnedAction.Initialize( action.victim, action.attacker, bb, "BlackBlood", EHRT_None, CPS_AttackPower, true, false, false, false );      
  1403.         returnedAction.SetCannotReturnDamage( true );      
  1404.        
  1405.         returnVal = bb.GetReturnDamageValue();
  1406.        
  1407.         if(potionLevel == 1)
  1408.         {
  1409.             returnedAction.SetHitAnimationPlayType(EAHA_ForceNo);
  1410.         }
  1411.         else
  1412.         {
  1413.             returnedAction.SetHitAnimationPlayType(EAHA_ForceYes);
  1414.             returnedAction.SetHitReactionType(EHRT_Reflect);
  1415.         }
  1416.        
  1417.         returnedDamage = (returnVal.valueBase + action.processedDmg.vitalityDamage) * returnVal.valueMultiplicative + returnVal.valueAdditive;
  1418.         returnedAction.AddDamage(theGame.params.DAMAGE_NAME_DIRECT, returnedDamage);
  1419.        
  1420.         theGame.damageMgr.ProcessAction(returnedAction);
  1421.         delete returnedAction;
  1422.         return true;
  1423.     }
  1424.    
  1425.    
  1426.     private function ProcessActionReflectDamage() : bool
  1427.     {
  1428.         var returnedAction : W3DamageAction;
  1429.         var returnVal, min, max : SAbilityAttributeValue;
  1430.         var potionLevel : int;
  1431.         var returnedDamage : float;
  1432.         var template : CEntityTemplate;
  1433.         var fxEnt : CEntity;
  1434.         var boneIndex: int;
  1435.         var b : bool;
  1436.         var component : CComponent;
  1437.        
  1438.        
  1439.         if(action.processedDmg.vitalityDamage <= 0)
  1440.             return false;
  1441.        
  1442.         returnedDamage = CalculateAttributeValue(actorVictim.GetTotalArmor());
  1443.         theGame.GetDefinitionsManager().GetAbilityAttributeValue('Glyphword 5 _Stats', 'damage_mult', min, max);
  1444.        
  1445.        
  1446.        
  1447.        
  1448.         returnedAction = new W3DamageAction in this;       
  1449.         returnedAction.Initialize( action.victim, action.attacker, NULL, "Glyphword5", EHRT_None, CPS_AttackPower, true, false, false, false );    
  1450.         returnedAction.SetCannotReturnDamage( true );      
  1451.         returnedAction.SetHitAnimationPlayType(EAHA_ForceYes);
  1452.         returnedAction.SetHitReactionType(EHRT_Heavy);
  1453.        
  1454.         returnedAction.AddDamage(theGame.params.DAMAGE_NAME_DIRECT, returnedDamage * min.valueMultiplicative);
  1455.        
  1456.        
  1457.        
  1458.        
  1459.         theGame.damageMgr.ProcessAction(returnedAction);
  1460.         delete returnedAction;
  1461.        
  1462.         template = (CEntityTemplate)LoadResource('glyphword_5');
  1463.        
  1464.        
  1465.        
  1466.        
  1467.        
  1468.        
  1469.         component = action.attacker.GetComponent('torso3effect');
  1470.         if(component)
  1471.             thePlayer.PlayEffect('reflection_damge', component);
  1472.         else
  1473.             thePlayer.PlayEffect('reflection_damge', action.attacker);
  1474.         action.attacker.PlayEffect('yrden_shock');
  1475.        
  1476.         return true;
  1477.     }
  1478.    
  1479.    
  1480.     private function ProcessActionThornDamage() : bool
  1481.     {
  1482.         var damageAction        : W3DamageAction;
  1483.         var damageVal           : SAbilityAttributeValue;
  1484.         var damage              : float;
  1485.         var inv                 : CInventoryComponent;
  1486.         var damageNames         : array < CName >;
  1487.        
  1488.         damageAction    = new W3DamageAction in this;
  1489.        
  1490.         damageAction.Initialize( action.victim, action.attacker, NULL, "Thorns", EHRT_Light, CPS_AttackPower, true, false, false, false );
  1491.        
  1492.         damageAction.SetCannotReturnDamage( true );    
  1493.        
  1494.         damageVal               =  actorVictim.GetAttributeValue( 'light_attack_damage_vitality' );
  1495.        
  1496.        
  1497.        
  1498.        
  1499.        
  1500.         inv = actorAttacker.GetInventory();    
  1501.         inv.GetWeaponDTNames(weaponId, damageNames );
  1502.         damageVal.valueBase  = actorAttacker.GetTotalWeaponDamage(weaponId, damageNames[0], GetInvalidUniqueId() );
  1503.        
  1504.         damageVal.valueBase *= 0.10f;
  1505.        
  1506.         if( damageVal.valueBase == 0 )
  1507.         {
  1508.             damageVal.valueBase = 10;
  1509.         }
  1510.                
  1511.         damage = (damageVal.valueBase + action.processedDmg.vitalityDamage) * damageVal.valueMultiplicative + damageVal.valueAdditive;
  1512.         damageAction.AddDamage(  theGame.params.DAMAGE_NAME_PIERCING, damage );
  1513.        
  1514.         damageAction.SetHitAnimationPlayType( EAHA_ForceYes );
  1515.         theGame.damageMgr.ProcessAction(damageAction);
  1516.         delete damageAction;
  1517.        
  1518.         return true;
  1519.     }
  1520.        
  1521.    
  1522.     private function GetAttackersPowerMod() : SAbilityAttributeValue
  1523.     {      
  1524.         var powerMod, criticalDamageBonus, min, max, critReduction, sp : SAbilityAttributeValue;
  1525.         var mutagen : CBaseGameplayEffect;
  1526.         var totalBonus : float;
  1527.        
  1528.        
  1529.         var inv : CInventoryComponent;
  1530.         var weaponName : name;
  1531.        
  1532.            
  1533.        
  1534.         powerMod = action.GetPowerStatValue();
  1535.         if ( powerMod.valueAdditive == 0 && powerMod.valueBase == 0 && powerMod.valueMultiplicative == 0 && theGame.CanLog() )
  1536.             LogDMHits("Attacker has power stat of 0!", action);
  1537.        
  1538.        
  1539.         if(playerAttacker && attackAction && playerAttacker.IsHeavyAttack(attackAction.GetAttackName()))
  1540.             powerMod.valueMultiplicative -= 0.433;
  1541.        
  1542.        
  1543.         if ( playerAttacker && (W3IgniProjectile)action.causer )
  1544.             powerMod.valueMultiplicative = 1 + (powerMod.valueMultiplicative - 1) * theGame.params.IGNI_SPELL_POWER_MILT;
  1545.        
  1546.        
  1547.         if ( playerAttacker && (W3AardProjectile)action.causer )
  1548.             powerMod.valueMultiplicative = 1;
  1549.        
  1550.        
  1551.        
  1552.         inv = actorAttacker.GetInventory();
  1553.         weaponName = inv.GetItemName( weaponId );
  1554.        
  1555.         if( !playerAttacker && actorVictim && !thePlayer.IsInFistFightMiniGame() && GetAttitudeBetween( thePlayer, actorAttacker ) == AIA_Friendly && !actorAttacker.HasTag( 'keira' ) && !actorAttacker.HasTag( 'Yennefer' )
  1556.             && ( actorAttacker.IsWeaponHeld( 'silversword' ) || actorAttacker.IsWeaponHeld( 'staff2h' ) || weaponName == 'fists_lightning' || weaponName == 'fists_fire' || actorAttacker.HasAbility( 'SkillWitcher' ) || actorAttacker.HasTag( 'regis' )  || actorAttacker.HasBuff(EET_AxiiGuardMe) ) )
  1557.         {
  1558.             if ( powerMod.valueMultiplicative <= 0.1 )
  1559.             {
  1560.                 actorAttacker.AddAbility( 'FCR3HighDamageBoost' );
  1561.                 actorAttacker.AddAbility( 'FCR3LowDamageBoost');
  1562.             }
  1563.             else if ( powerMod.valueMultiplicative <= 0.4 )
  1564.             {
  1565.                 actorAttacker.AddAbility( 'FCR3MedDamageBoost' );
  1566.                 actorAttacker.AddAbility( 'FCR3LowDamageBoost' );
  1567.             }
  1568.             else if ( powerMod.valueMultiplicative <= 0.9 )
  1569.             {
  1570.                 actorAttacker.AddAbility( 'FCR3MedDamageBoost' );
  1571.             }
  1572.             else if ( powerMod.valueMultiplicative <= 1.1 )
  1573.             {
  1574.                 actorAttacker.AddAbility( 'FCR3LowDamageBoost' );
  1575.             }
  1576.         }
  1577.        
  1578.        
  1579.        
  1580.         if(action.IsCriticalHit())
  1581.         {
  1582.            
  1583.             if( playerAttacker && action.IsActionWitcherSign() && GetWitcherPlayer().IsMutationActive(EPMT_Mutation2) )
  1584.             {
  1585.                 sp = action.GetPowerStatValue();
  1586.                
  1587.                 theGame.GetDefinitionsManager().GetAbilityAttributeValue('Mutation2', 'crit_damage_factor', min, max);             
  1588.                 criticalDamageBonus.valueAdditive = sp.valueMultiplicative * min.valueMultiplicative;
  1589.             }
  1590.             else
  1591.             {
  1592.                 criticalDamageBonus = actorAttacker.GetCriticalHitDamageBonus(weaponId, victimMonsterCategory, actorVictim.IsAttackerAtBack(playerAttacker));
  1593.                
  1594.                 criticalDamageBonus += actorAttacker.GetAttributeValue('critical_hit_chance_fast_style');
  1595.                
  1596.                 if(attackAction && playerAttacker)
  1597.                 {
  1598.                     if(playerAttacker.IsHeavyAttack(attackAction.GetAttackName()) && playerAttacker.CanUseSkill(S_Sword_s08))
  1599.                         criticalDamageBonus += playerAttacker.GetSkillAttributeValue(S_Sword_s08, theGame.params.CRITICAL_HIT_DAMAGE_BONUS, false, true) * playerAttacker.GetSkillLevel(S_Sword_s08);
  1600.                     else if (!playerAttacker.IsHeavyAttack(attackAction.GetAttackName()) && playerAttacker.CanUseSkill(S_Sword_s17))
  1601.                         criticalDamageBonus += playerAttacker.GetSkillAttributeValue(S_Sword_s17, theGame.params.CRITICAL_HIT_DAMAGE_BONUS, false, true) * playerAttacker.GetSkillLevel(S_Sword_s17);
  1602.                 }
  1603.             }
  1604.            
  1605.            
  1606.             totalBonus = CalculateAttributeValue(criticalDamageBonus);
  1607.             critReduction = actorVictim.GetAttributeValue(theGame.params.CRITICAL_HIT_REDUCTION);
  1608.             totalBonus = totalBonus * ClampF(1 - critReduction.valueMultiplicative, 0.f, 1.f);
  1609.            
  1610.            
  1611.             powerMod.valueMultiplicative += totalBonus;
  1612.         }
  1613.        
  1614.        
  1615.         if (actorVictim && playerAttacker)
  1616.         {
  1617.             if ( playerAttacker.HasBuff(EET_Mutagen05) && (playerAttacker.GetStat(BCS_Vitality) == playerAttacker.GetStatMax(BCS_Vitality)) )
  1618.             {
  1619.                 mutagen = playerAttacker.GetBuff(EET_Mutagen05);
  1620.                 dm.GetAbilityAttributeValue(mutagen.GetAbilityName(), 'damageIncrease', min, max);
  1621.                 powerMod += GetAttributeRandomizedValue(min, max);
  1622.             }
  1623.         }
  1624.            
  1625.         return powerMod;
  1626.     }
  1627.    
  1628.    
  1629.     private function GetDamageResists(dmgType : name, out resistPts : float, out resistPerc : float)
  1630.     {
  1631.         var armorReduction, armorReductionPerc, skillArmorReduction : SAbilityAttributeValue;
  1632.         var bonusReduct, bonusResist : float;
  1633.         var mutagenBuff : W3Mutagen28_Effect;
  1634.         var appliedOilName, vsMonsterResistReduction : name;
  1635.         var oils : array< W3Effect_Oil >;
  1636.         var i : int;
  1637.        
  1638.        
  1639.         if(attackAction && attackAction.IsActionMelee() && actorAttacker.GetInventory().IsItemFists(weaponId) && !actorVictim.UsesEssence())
  1640.             return;
  1641.            
  1642.        
  1643.         if(actorVictim)
  1644.         {
  1645.            
  1646.             actorVictim.GetResistValue( GetResistForDamage(dmgType, action.IsDoTDamage()), resistPts, resistPerc );
  1647.            
  1648.            
  1649.             if(playerVictim && actorAttacker && playerVictim.CanUseSkill(S_Alchemy_s05))
  1650.             {
  1651.                 GetOilProtectionAgainstMonster(dmgType, bonusResist, bonusReduct);
  1652.                
  1653.                 resistPerc += bonusResist * playerVictim.GetSkillLevel(S_Alchemy_s05);
  1654.             }
  1655.            
  1656.            
  1657.             if(playerVictim && actorAttacker && playerVictim.HasBuff(EET_Mutagen28))
  1658.             {
  1659.                 mutagenBuff = (W3Mutagen28_Effect)playerVictim.GetBuff(EET_Mutagen28);
  1660.                 mutagenBuff.GetProtection(attackerMonsterCategory, dmgType, action.IsDoTDamage(), bonusResist, bonusReduct);
  1661.                 resistPts += bonusReduct;
  1662.                 resistPerc += bonusResist;
  1663.             }
  1664.            
  1665.            
  1666.             if(actorAttacker)
  1667.             {
  1668.                
  1669.                 armorReduction = actorAttacker.GetAttributeValue('armor_reduction');
  1670.                 armorReductionPerc = actorAttacker.GetAttributeValue('armor_reduction_perc');
  1671.                
  1672.                
  1673.                 if(playerAttacker)
  1674.                 {
  1675.                     vsMonsterResistReduction = MonsterCategoryToResistReduction(victimMonsterCategory);
  1676.                     oils = playerAttacker.inv.GetOilsAppliedOnItem( weaponId );
  1677.                    
  1678.                     if( oils.Size() > 0 )
  1679.                     {
  1680.                         for( i=0; i<oils.Size(); i+=1 )
  1681.                         {
  1682.                             appliedOilName = oils[ i ].GetOilItemName();
  1683.                            
  1684.                            
  1685.                             if( oils[ i ].GetAmmoCurrentCount() > 0 && dm.ItemHasAttribute( appliedOilName, true, vsMonsterResistReduction ) )
  1686.                             {
  1687.                                 armorReductionPerc.valueMultiplicative += oils[ i ].GetAmmoPercentage();
  1688.                             }
  1689.                         }
  1690.                     }
  1691.                 }
  1692.                
  1693.                
  1694.                 if(playerAttacker && action.IsActionMelee() && playerAttacker.IsHeavyAttack(attackAction.GetAttackName()) && playerAttacker.CanUseSkill(S_Sword_2))
  1695.                     armorReduction += playerAttacker.GetSkillAttributeValue(S_Sword_2, 'armor_reduction', false, true);
  1696.                
  1697.                
  1698.                 if ( playerAttacker &&
  1699.                      action.IsActionMelee() && playerAttacker.IsHeavyAttack(attackAction.GetAttackName()) &&
  1700.                      ( dmgType == theGame.params.DAMAGE_NAME_PHYSICAL ||
  1701.                        dmgType == theGame.params.DAMAGE_NAME_SLASHING ||
  1702.                        dmgType == theGame.params.DAMAGE_NAME_PIERCING ||
  1703.                        dmgType == theGame.params.DAMAGE_NAME_BLUDGEONING ||
  1704.                        dmgType == theGame.params.DAMAGE_NAME_RENDING ||
  1705.                        dmgType == theGame.params.DAMAGE_NAME_SILVER
  1706.                      ) &&
  1707.                      playerAttacker.CanUseSkill(S_Sword_s06)
  1708.                    )
  1709.                 {
  1710.                    
  1711.                     skillArmorReduction = playerAttacker.GetSkillAttributeValue(S_Sword_s06, 'armor_reduction_perc', false, true);
  1712.                     armorReductionPerc += skillArmorReduction * playerAttacker.GetSkillLevel(S_Sword_s06);             
  1713.                 }
  1714.             }
  1715.         }
  1716.        
  1717.        
  1718.         if(!action.GetIgnoreArmor())
  1719.             resistPts += CalculateAttributeValue( actorVictim.GetTotalArmor() );
  1720.        
  1721.        
  1722.         resistPts = MaxF(0, resistPts - CalculateAttributeValue(armorReduction) );     
  1723.         resistPerc -= CalculateAttributeValue(armorReductionPerc);     
  1724.        
  1725.        
  1726.        
  1727.         resistPerc = MaxF(0, resistPerc);
  1728.     }
  1729.        
  1730.    
  1731.     private function CalculateDamage(dmgInfo : SRawDamage, powerMod : SAbilityAttributeValue) : float
  1732.     {
  1733.         var finalDamage, finalIncomingDamage : float;
  1734.         var resistPoints, resistPercents : float;
  1735.         var ptsString, percString : string;
  1736.         var mutagen : CBaseGameplayEffect;
  1737.         var min, max : SAbilityAttributeValue;
  1738.         var encumbranceBonus : float;
  1739.         var temp : bool;
  1740.         var fistfightDamageMult : float;
  1741.         var burning : W3Effect_Burning;
  1742.        
  1743.        
  1744.         var weaponName      : name;
  1745.         var dmgBonus        : float;
  1746.         var playerStlDmg    : float;
  1747.         var playerSlvDmg    : float;
  1748.         var playerFastSlvDmg: float;
  1749.         var playerSlvCritDmg: float;
  1750.         var multBonus       : float;
  1751.         var dmgLevel        : int;
  1752.         var curStats        : SPlayerOffenseStats;
  1753.         var inv             : CInventoryComponent;
  1754.        
  1755.    
  1756.        
  1757.         GetDamageResists(dmgInfo.dmgType, resistPoints, resistPercents);
  1758.    
  1759.        
  1760.         if( thePlayer.IsFistFightMinigameEnabled() && actorAttacker == thePlayer )
  1761.         {
  1762.             finalDamage = MaxF(0, (dmgInfo.dmgVal));
  1763.         }
  1764.         else
  1765.         {
  1766.            
  1767.             burning = (W3Effect_Burning)action.causer;
  1768.             if( burning && burning.IsSignEffect() )
  1769.             {
  1770.                 if ( powerMod.valueMultiplicative > 2.5f )
  1771.                 {
  1772.                     powerMod.valueMultiplicative = 2.5f + LogF( (powerMod.valueMultiplicative - 2.5f) + 1 );
  1773.                 }
  1774.             }
  1775.            
  1776.             finalDamage = MaxF(0, (dmgInfo.dmgVal + powerMod.valueBase) * powerMod.valueMultiplicative + powerMod.valueAdditive);
  1777.            
  1778.            
  1779.            
  1780.             inv = actorAttacker.GetInventory();
  1781.             weaponName = inv.GetItemName( weaponId );
  1782.             if( thePlayer.IsCiri() )
  1783.             {
  1784.                 dmgLevel = ( actorVictim.GetLevel() -2 ) * 10;
  1785.             }
  1786.             else
  1787.             {
  1788.                 dmgLevel = Min( actorVictim.GetLevel(), GetWitcherPlayer().GetLevel() ) * 40;
  1789.             }
  1790.            
  1791.             if( !playerAttacker && actorVictim && GetAttitudeBetween( thePlayer, actorAttacker ) == AIA_Friendly && !action.IsDoTDamage() && !actorAttacker.HasTag( 'Yennefer' ) && !actorAttacker.HasTag( 'keira' )
  1792.                 && !actorAttacker.HasTag( 'Philippa' ) && ( actorAttacker.IsWeaponHeld( 'silversword' ) || actorAttacker.IsWeaponHeld( 'staff2h' ) || weaponName == 'fists_lightning' || weaponName == 'fists_fire'
  1793.                 || actorAttacker.HasAbility( 'SkillWitcher' ) || actorAttacker.HasTag( 'zoltan' ) || actorAttacker.HasTag( 'hjalmar' ) || actorAttacker.HasTag( 'regis' ) || actorAttacker.HasBuff(EET_AxiiGuardMe) ) && ( finalDamage < dmgLevel || thePlayer.IsCiri() ) )
  1794.             {
  1795.                 dmgBonus += dmgLevel - finalDamage;
  1796.                 finalDamage = MaxF(0, (dmgInfo.dmgVal + powerMod.valueBase + dmgBonus) * powerMod.valueMultiplicative + powerMod.valueAdditive);
  1797.             }
  1798.            
  1799.         }
  1800.            
  1801.         finalIncomingDamage = finalDamage;
  1802.            
  1803.         if(finalDamage > 0.f)
  1804.         {
  1805.            
  1806.             if(!action.IsPointResistIgnored() && !(dmgInfo.dmgType == theGame.params.DAMAGE_NAME_ELEMENTAL || dmgInfo.dmgType == theGame.params.DAMAGE_NAME_FIRE || dmgInfo.dmgType == theGame.params.DAMAGE_NAME_FROST ))
  1807.             {
  1808.                 finalDamage = MaxF(0, finalDamage - resistPoints);
  1809.                
  1810.                 if(finalDamage == 0.f)
  1811.                     action.SetArmorReducedDamageToZero( true );
  1812.             }
  1813.         }
  1814.        
  1815.         if(finalDamage > 0.f)
  1816.         {
  1817.            
  1818.             if (playerVictim == GetWitcherPlayer() && playerVictim.HasBuff(EET_Mutagen02))
  1819.             {
  1820.                 encumbranceBonus = 1 - (GetWitcherPlayer().GetEncumbrance() / GetWitcherPlayer().GetMaxRunEncumbrance(temp));
  1821.                 if (encumbranceBonus < 0)
  1822.                     encumbranceBonus = 0;
  1823.                 mutagen = playerVictim.GetBuff(EET_Mutagen02);
  1824.                 dm.GetAbilityAttributeValue(mutagen.GetAbilityName(), 'resistGainRate', min, max);
  1825.                 encumbranceBonus *= CalculateAttributeValue(GetAttributeRandomizedValue(min, max));
  1826.                 resistPercents += encumbranceBonus;
  1827.             }
  1828.             finalDamage *= 1 - resistPercents;
  1829.         }  
  1830.  
  1831.  
  1832.  
  1833.        
  1834.        
  1835.         if( !playerAttacker && actorVictim && !action.IsDoTDamage() && !thePlayer.IsFistFightMinigameEnabled() && finalDamage <= actorVictim.GetMaxHealth() * 0.01 && (GetAttitudeBetween( thePlayer, actorAttacker ) == AIA_Friendly || actorAttacker.HasBuff(EET_AxiiGuardMe)) )
  1836.         {
  1837.             dmgBonus += dmgLevel - finalDamage;
  1838.             if ( powerMod.valueMultiplicative < 1.0 )
  1839.             {
  1840.                 multBonus = 1.0 - powerMod.valueMultiplicative;
  1841.             }
  1842.             finalDamage = MaxF(actorVictim.GetMaxHealth() * 0.01, (dmgInfo.dmgVal + powerMod.valueBase + dmgBonus) * ( powerMod.valueMultiplicative + multBonus ) + powerMod.valueAdditive);
  1843.            
  1844.             if(!action.IsPointResistIgnored() && !(dmgInfo.dmgType == theGame.params.DAMAGE_NAME_ELEMENTAL || dmgInfo.dmgType == theGame.params.DAMAGE_NAME_FIRE || dmgInfo.dmgType == theGame.params.DAMAGE_NAME_FROST ))
  1845.             {
  1846.                 finalDamage = MaxF(actorVictim.GetMaxHealth() * 0.01, finalDamage - resistPoints);
  1847.                
  1848.                 if(finalDamage == 0.f)
  1849.                     action.SetArmorReducedDamageToZero( true );
  1850.                 else
  1851.                     action.SetArmorReducedDamageToZero( false );
  1852.             }
  1853.            
  1854.             finalDamage *= 1 - resistPercents;
  1855.         }
  1856.        
  1857.        
  1858.         curStats = GetWitcherPlayer().GetOffenseStatsList();
  1859.         playerStlDmg = MaxF(0, curStats.steelStrongDmg - resistPoints);
  1860.         playerStlDmg *= 1 - resistPercents;
  1861.         playerStlDmg /= 6;
  1862.        
  1863.         playerFastSlvDmg = MaxF(0, curStats.silverFastDmg - resistPoints);
  1864.         playerFastSlvDmg *= 1 - resistPercents;
  1865.         playerFastSlvDmg /= 6;
  1866.  
  1867.         playerSlvDmg = MaxF(0, curStats.silverStrongDmg - resistPoints);
  1868.         playerSlvDmg *= 1 - resistPercents;
  1869.         playerSlvDmg /= 6;
  1870.        
  1871.         playerSlvCritDmg = MaxF(0, curStats.silverStrongCritDmg - resistPoints);
  1872.         playerSlvCritDmg *= 1 - resistPercents;
  1873.         playerSlvCritDmg /= 6;
  1874.        
  1875.         if( !playerAttacker && actorVictim && !action.IsDoTDamage() && !thePlayer.IsFistFightMinigameEnabled() && (GetAttitudeBetween( thePlayer, actorAttacker ) == AIA_Friendly || actorAttacker.HasBuff(EET_AxiiGuardMe)) && !thePlayer.IsCiri()  )
  1876.         {
  1877.             if(finalDamage > playerStlDmg && !actorAttacker.HasAbility( 'ForceInstantKill' ))
  1878.             {
  1879.                 if ( actorAttacker.HasTag( 'regis' ) )
  1880.                 {
  1881.                     if ( finalDamage > playerSlvCritDmg * 2 )
  1882.                     {
  1883.                         finalDamage = ClampF( finalDamage, 0, playerSlvCritDmg * 2 );
  1884.                         finalDamage = MaxF(actorVictim.GetMaxHealth() * 0.01, finalDamage);
  1885.                     }
  1886.                     if ( finalDamage < playerSlvCritDmg )
  1887.                     {
  1888.                         finalDamage = ClampF( finalDamage, playerSlvCritDmg, finalDamage );
  1889.                     }
  1890.                 }
  1891.                 else if ( actorAttacker.IsWeaponHeld( 'staff2h' ) || weaponName == 'fists_lightning' || weaponName == 'fists_fire' || action.GetPowerStatType() == CPS_SpellPower )
  1892.                 {
  1893.                     if ( finalDamage > playerSlvDmg * 2 )
  1894.                     {
  1895.                         finalDamage = ClampF( finalDamage, 0, playerSlvDmg );
  1896.                         finalDamage = MaxF(actorVictim.GetMaxHealth() * 0.01, finalDamage);
  1897.                     }
  1898.                    
  1899.                     if ( finalDamage < playerFastSlvDmg && attackAction )
  1900.                     {
  1901.                         finalDamage = ClampF( finalDamage, playerFastSlvDmg, finalDamage );
  1902.                     }
  1903.                 }
  1904.                 else if ( actorAttacker.IsWeaponHeld( 'silversword' ) || actorAttacker.HasAbility( 'SkillWitcher' ) || actorAttacker.HasBuff(EET_AxiiGuardMe) )
  1905.                 {
  1906.                     if ( finalDamage > playerSlvCritDmg )
  1907.                     {
  1908.                         finalDamage = ClampF( finalDamage, 0, playerSlvCritDmg );
  1909.                         finalDamage = MaxF(actorVictim.GetMaxHealth() * 0.01, finalDamage);
  1910.                     }
  1911.                     if ( action.IsActionMelee() )
  1912.                     {
  1913.                        
  1914.                         if ( finalDamage < playerSlvDmg && actorVictim.UsesEssence() )
  1915.                         {
  1916.                             finalDamage = ClampF( finalDamage, playerSlvDmg, finalDamage );
  1917.                         }
  1918.                         else if ( finalDamage < playerStlDmg )
  1919.                         {
  1920.                             finalDamage = ClampF( finalDamage, playerStlDmg, finalDamage );
  1921.                         }
  1922.                     }
  1923.                 }
  1924.                 else
  1925.                 {
  1926.                     finalDamage = ClampF( finalDamage, 0, playerStlDmg );
  1927.                     finalDamage = MaxF(actorVictim.GetMaxHealth() * 0.01, finalDamage);
  1928.                 }
  1929.             }
  1930.        
  1931.            
  1932.             if(thePlayer.GetBossTag() != '' || (W3MonsterHuntNPC)actorVictim || actorVictim.GetCharacterStats().HasAbilityWithTag('Boss') || actorVictim.HasAbility( 'Boss' ) || actorVictim.HasAbility( 'SkillBoss') )
  1933.             {
  1934.                 finalDamage = ClampF(finalDamage, 0, actorVictim.GetMaxHealth() * 0.005);
  1935.             }
  1936.         }
  1937.         if(actorAttacker.HasBuff(EET_AxiiGuardMe))
  1938.         {
  1939.             switch(GetWitcherPlayer().GetSkillLevel(S_Magic_s05))
  1940.             {
  1941.                 case 3:
  1942.                     finalDamage *= 1.6;
  1943.                     break;
  1944.                 case 2:
  1945.                     finalDamage *= 1.4;
  1946.                     break;
  1947.                 case 1:
  1948.                     finalDamage *= 1.2;
  1949.                     break;
  1950.             }
  1951.         }
  1952.        
  1953.    
  1954.        
  1955.         if(dmgInfo.dmgType == theGame.params.DAMAGE_NAME_FIRE && finalDamage > 0)
  1956.             action.SetDealtFireDamage(true);
  1957.            
  1958.         if( playerAttacker && thePlayer.IsWeaponHeld('fist') && !thePlayer.IsInFistFightMiniGame() && action.IsActionMelee() )
  1959.         {
  1960.             if(FactsQuerySum("NewGamePlus") > 0)
  1961.             {fistfightDamageMult = thePlayer.GetLevel()* 0.1;}
  1962.             else
  1963.             {fistfightDamageMult = thePlayer.GetLevel()* 0.05;}
  1964.            
  1965.             finalDamage *= ( 1+fistfightDamageMult );
  1966.         }
  1967.        
  1968.         if(playerAttacker && attackAction && playerAttacker.IsHeavyAttack(attackAction.GetAttackName()))
  1969.             finalDamage *= 1.833;
  1970.            
  1971.        
  1972.         burning = (W3Effect_Burning)action.causer;
  1973.         if(actorVictim && (((W3IgniEntity)action.causer) || ((W3IgniProjectile)action.causer) || ( burning && burning.IsSignEffect())) )
  1974.         {
  1975.             min = actorVictim.GetAttributeValue('igni_damage_amplifier');
  1976.             finalDamage = finalDamage * (1 + min.valueMultiplicative) + min.valueAdditive;
  1977.         }
  1978.        
  1979.        
  1980.        
  1981.        
  1982.         if ( theGame.CanLog() )
  1983.         {
  1984.             LogDMHits("Single hit damage: initial damage = " + NoTrailZeros(dmgInfo.dmgVal), action);
  1985.             LogDMHits("Single hit damage: attack_power = base: " + NoTrailZeros(powerMod.valueBase) + ", mult: " + NoTrailZeros(powerMod.valueMultiplicative) + ", add: " + NoTrailZeros(powerMod.valueAdditive), action );
  1986.             if(action.IsPointResistIgnored())
  1987.                 LogDMHits("Single hit damage: resistance pts and armor = IGNORED", action);
  1988.             else
  1989.                 LogDMHits("Single hit damage: resistance pts and armor = " + NoTrailZeros(resistPoints), action);          
  1990.             LogDMHits("Single hit damage: resistance perc = " + NoTrailZeros(resistPercents * 100), action);
  1991.             LogDMHits("Single hit damage: final damage to sustain = " + NoTrailZeros(finalDamage), action);
  1992.         }
  1993.        
  1994.        
  1995.         if( playerVictim && actorAttacker && FactsQuerySum("NewGamePlus") > 0)
  1996.             finalDamage *= 1.1;
  1997.        
  1998.            
  1999.         return finalDamage;
  2000.     }
  2001.    
  2002.    
  2003.     private function ProcessActionDamage_DealDamage()
  2004.     {
  2005.         var logStr : string;
  2006.         var hpPerc : float;
  2007.         var npcVictim : CNewNPC;
  2008.    
  2009.        
  2010.         if ( theGame.CanLog() )
  2011.         {
  2012.             logStr = "";
  2013.             if(action.processedDmg.vitalityDamage > 0)          logStr += NoTrailZeros(action.processedDmg.vitalityDamage) + " vitality, ";
  2014.             if(action.processedDmg.essenceDamage > 0)           logStr += NoTrailZeros(action.processedDmg.essenceDamage) + " essence, ";
  2015.             if(action.processedDmg.staminaDamage > 0)           logStr += NoTrailZeros(action.processedDmg.staminaDamage) + " stamina, ";
  2016.             if(action.processedDmg.moraleDamage > 0)            logStr += NoTrailZeros(action.processedDmg.moraleDamage) + " morale";
  2017.                
  2018.             if(logStr == "")
  2019.                 logStr = "NONE";
  2020.             LogDMHits("Final damage to sustain is: " + logStr, action);
  2021.         }
  2022.                
  2023.        
  2024.         if(actorVictim)
  2025.         {
  2026.             hpPerc = actorVictim.GetHealthPercents();
  2027.            
  2028.            
  2029.             if(actorVictim.IsAlive())
  2030.             {
  2031.                 npcVictim = (CNewNPC)actorVictim;
  2032.                 if(npcVictim && npcVictim.IsHorse())
  2033.                 {
  2034.                     npcVictim.GetHorseComponent().OnTakeDamage(action);
  2035.                 }
  2036.                 else
  2037.                 {
  2038.                     actorVictim.OnTakeDamage(action);
  2039.                 }
  2040.             }
  2041.            
  2042.             if(!actorVictim.IsAlive() && hpPerc == 1)
  2043.                 action.SetWasKilledBySingleHit();
  2044.         }
  2045.            
  2046.         if ( theGame.CanLog() )
  2047.         {
  2048.             LogDMHits("", action);
  2049.             LogDMHits("Target stats after damage dealt are:", action);
  2050.             if(actorVictim)
  2051.             {
  2052.                 if( actorVictim.UsesVitality())                     LogDMHits("Vitality = " + NoTrailZeros( actorVictim.GetStat(BCS_Vitality)), action);
  2053.                 if( actorVictim.UsesEssence())                      LogDMHits("Essence = "  + NoTrailZeros( actorVictim.GetStat(BCS_Essence)), action);
  2054.                 if( actorVictim.GetStatMax(BCS_Stamina) > 0)        LogDMHits("Stamina = "  + NoTrailZeros( actorVictim.GetStat(BCS_Stamina, true)), action);
  2055.                 if( actorVictim.GetStatMax(BCS_Morale) > 0)         LogDMHits("Morale = "   + NoTrailZeros( actorVictim.GetStat(BCS_Morale)), action);
  2056.             }
  2057.             else
  2058.             {
  2059.                 LogDMHits("Undefined - victim is not a CActor and therefore has no stats", action);
  2060.             }
  2061.         }
  2062.     }
  2063.    
  2064.    
  2065.     private function ProcessActionDamage_ReduceDurability()
  2066.     {      
  2067.         var witcherPlayer : W3PlayerWitcher;
  2068.         var dbg_currDur, dbg_prevDur1, dbg_prevDur2, dbg_prevDur3, dbg_prevDur4, dbg_prevDur : float;
  2069.         var dbg_armor, dbg_pants, dbg_boots, dbg_gloves, reducedItemId, weapon : SItemUniqueId;
  2070.         var slot : EEquipmentSlots;
  2071.         var weapons : array<SItemUniqueId>;
  2072.         var armorStringName : string;
  2073.         var canLog, playerHasSword : bool;
  2074.         var i : int;
  2075.        
  2076.         canLog = theGame.CanLog();
  2077.  
  2078.         witcherPlayer = GetWitcherPlayer();
  2079.    
  2080.        
  2081.         if ( playerAttacker && playerAttacker.inv.IsIdValid( weaponId ) && playerAttacker.inv.HasItemDurability( weaponId ) )
  2082.         {      
  2083.             dbg_prevDur = playerAttacker.inv.GetItemDurability(weaponId);
  2084.                        
  2085.             if ( playerAttacker.inv.ReduceItemDurability(weaponId) && canLog )
  2086.             {
  2087.                 LogDMHits("", action);
  2088.                 LogDMHits("Player's weapon durability changes from " + NoTrailZeros(dbg_prevDur) + " to " + NoTrailZeros(action.attacker.GetInventory().GetItemDurability(weaponId)), action );
  2089.             }
  2090.         }
  2091.        
  2092.         else if(playerVictim && attackAction && attackAction.IsActionMelee() && (attackAction.IsParried() || attackAction.IsCountered()) )
  2093.         {
  2094.             weapons = playerVictim.inv.GetHeldWeapons();
  2095.             playerHasSword = false;
  2096.             for(i=0; i<weapons.Size(); i+=1)
  2097.             {
  2098.                 weapon = weapons[i];
  2099.                 if(playerVictim.inv.IsIdValid(weapon) && (playerVictim.inv.IsItemSteelSwordUsableByPlayer(weapon) || playerVictim.inv.IsItemSilverSwordUsableByPlayer(weapon)) )
  2100.                 {
  2101.                     playerHasSword = true;
  2102.                     break;
  2103.                 }
  2104.             }
  2105.            
  2106.             if(playerHasSword)
  2107.             {
  2108.                 playerVictim.inv.ReduceItemDurability(weapon);
  2109.             }
  2110.         }
  2111.        
  2112.         else if(action.victim == witcherPlayer && (action.IsActionMelee() || action.IsActionRanged()) && action.DealsAnyDamage())
  2113.         {
  2114.            
  2115.             if ( canLog )
  2116.             {
  2117.                 if ( witcherPlayer.GetItemEquippedOnSlot(EES_Armor, dbg_armor) )
  2118.                     dbg_prevDur1 = action.victim.GetInventory().GetItemDurability(dbg_armor);
  2119.                 else
  2120.                     dbg_prevDur1 = 0;
  2121.                    
  2122.                 if ( witcherPlayer.GetItemEquippedOnSlot(EES_Pants, dbg_pants) )
  2123.                     dbg_prevDur2 = action.victim.GetInventory().GetItemDurability(dbg_pants);
  2124.                 else
  2125.                     dbg_prevDur2 = 0;
  2126.                    
  2127.                 if ( witcherPlayer.GetItemEquippedOnSlot(EES_Boots, dbg_boots) )
  2128.                     dbg_prevDur3 = action.victim.GetInventory().GetItemDurability(dbg_boots);
  2129.                 else
  2130.                     dbg_prevDur3 = 0;
  2131.                    
  2132.                 if ( witcherPlayer.GetItemEquippedOnSlot(EES_Gloves, dbg_gloves) )
  2133.                     dbg_prevDur4 = action.victim.GetInventory().GetItemDurability(dbg_gloves);
  2134.                 else
  2135.                     dbg_prevDur4 = 0;
  2136.             }
  2137.            
  2138.             slot = GetWitcherPlayer().ReduceArmorDurability();
  2139.            
  2140.            
  2141.             if( canLog )
  2142.             {
  2143.                 LogDMHits("", action);
  2144.                 if(slot != EES_InvalidSlot)
  2145.                 {      
  2146.                     switch(slot)
  2147.                     {
  2148.                         case EES_Armor :
  2149.                             armorStringName = "chest armor";
  2150.                             reducedItemId = dbg_armor;
  2151.                             dbg_prevDur = dbg_prevDur1;
  2152.                             break;
  2153.                         case EES_Pants :
  2154.                             armorStringName = "pants";
  2155.                             reducedItemId = dbg_pants;
  2156.                             dbg_prevDur = dbg_prevDur2;
  2157.                             break;
  2158.                         case EES_Boots :
  2159.                             armorStringName = "boots";
  2160.                             reducedItemId = dbg_boots;
  2161.                             dbg_prevDur = dbg_prevDur3;
  2162.                             break;
  2163.                         case EES_Gloves :
  2164.                             armorStringName = "gloves";
  2165.                             reducedItemId = dbg_gloves;
  2166.                             dbg_prevDur = dbg_prevDur4;
  2167.                             break;
  2168.                     }
  2169.                    
  2170.                     dbg_currDur = action.victim.GetInventory().GetItemDurability(reducedItemId);
  2171.                     LogDMHits("", action);
  2172.                     LogDMHits("Player's <<" + armorStringName + ">> durability changes from " + NoTrailZeros(dbg_prevDur) + " to " + NoTrailZeros(dbg_currDur), action );
  2173.                 }
  2174.                 else
  2175.                 {
  2176.                     LogDMHits("Tried to reduce player's armor durability but failed", action);
  2177.                 }
  2178.             }
  2179.                
  2180.            
  2181.             if(slot != EES_InvalidSlot)
  2182.                 thePlayer.inv.ReduceItemRepairObjectBonusCharge(reducedItemId);
  2183.         }
  2184.     }  
  2185.    
  2186.    
  2187.    
  2188.    
  2189.    
  2190.    
  2191.     private function ProcessActionReaction(wasFrozen : bool, wasAlive : bool)
  2192.     {
  2193.         var dismemberExplosion          : bool;
  2194.         var damageName                  : name;
  2195.         var damage                      : array<SRawDamage>;
  2196.         var points, percents, hp, dmg   : float;
  2197.         var counterAction               : W3DamageAction;      
  2198.         var moveTargets                 : array<CActor>;
  2199.         var i                           : int;
  2200.         var canPerformFinisher          : bool;
  2201.         var weaponName                  : name;
  2202.         var npcVictim                   : CNewNPC;
  2203.         var toxicCloud                  : W3ToxicCloud;
  2204.         var playsNonAdditiveAnim        : bool;
  2205.         var bleedCustomEffect           : SCustomEffectParams;
  2206.        
  2207.        
  2208.         var min, max                    : SAbilityAttributeValue;
  2209.         var minDmg                      : float;
  2210.        
  2211.        
  2212.         if(!actorVictim)
  2213.             return;
  2214.        
  2215.         npcVictim = (CNewNPC)actorVictim;
  2216.        
  2217.         canPerformFinisher = CanPerformFinisher(actorVictim);
  2218.        
  2219.         if( actorVictim.IsAlive() && !canPerformFinisher )
  2220.         {
  2221.            
  2222.             if(!action.IsDoTDamage() && action.DealtDamage())
  2223.             {
  2224.                 if ( actorAttacker && npcVictim)
  2225.                 {
  2226.                     npcVictim.NoticeActorInGuardArea( actorAttacker );
  2227.                 }
  2228.  
  2229.                
  2230.                 if ( !playerVictim )
  2231.                     actorVictim.RemoveAllBuffsOfType(EET_Confusion);
  2232.                
  2233.                
  2234.                 if(playerAttacker && action.IsActionMelee() && !playerAttacker.GetInventory().IsItemFists(weaponId) && playerAttacker.IsLightAttack(attackAction.GetAttackName()) && playerAttacker.CanUseSkill(S_Sword_s05))
  2235.                 {
  2236.                     bleedCustomEffect.effectType = EET_Bleeding;
  2237.                     bleedCustomEffect.creator = playerAttacker;
  2238.                     bleedCustomEffect.sourceName = SkillEnumToName(S_Sword_s05);
  2239.                    
  2240.                    
  2241.                    
  2242.                     theGame.GetDefinitionsManager().GetAbilityAttributeValue( 'BleedingEffect', 'DirectDamage', min, max );
  2243.                     bleedCustomEffect.effectValue = min;
  2244.                     minDmg = CalculateAttributeValue(playerAttacker.GetSkillAttributeValue(S_Sword_s05, 'dmg_per_sec', false, true)) * playerAttacker.GetSkillLevel(S_Sword_s05);
  2245.                     dmg = bleedCustomEffect.effectValue.valueAdditive + (bleedCustomEffect.effectValue.valueMultiplicative * actorVictim.GetMaxHealth());
  2246.                    
  2247.                     if ( dmg < minDmg )
  2248.                     {
  2249.                         bleedCustomEffect.effectValue.valueAdditive += minDmg - dmg;
  2250.                     }
  2251.                    
  2252.                    
  2253.                    
  2254.                     actorVictim.AddEffectCustom(bleedCustomEffect);
  2255.                 }
  2256.             }
  2257.            
  2258.            
  2259.             if(actorVictim && wasAlive)
  2260.             {
  2261.                 playsNonAdditiveAnim = actorVictim.ReactToBeingHit( action );
  2262.             }              
  2263.         }
  2264.         else
  2265.         {
  2266.            
  2267.             if( !canPerformFinisher && CanDismember( wasFrozen, dismemberExplosion, weaponName ) )
  2268.             {
  2269.                 ProcessDismemberment(wasFrozen, dismemberExplosion);
  2270.                 toxicCloud = (W3ToxicCloud)action.causer;
  2271.                
  2272.                 if(toxicCloud && toxicCloud.HasExplodingTargetDamages())
  2273.                     ProcessToxicCloudDismemberExplosion(toxicCloud.GetExplodingTargetDamages());
  2274.                    
  2275.                
  2276.                 if(IsRequiredAttitudeBetween(thePlayer, action.victim, true))
  2277.                 {
  2278.                     moveTargets = thePlayer.GetMoveTargets();
  2279.                     for ( i = 0; i < moveTargets.Size(); i += 1 )
  2280.                     {
  2281.                         if ( moveTargets[i].IsHuman() )
  2282.                             moveTargets[i].DrainMorale(20.f);
  2283.                     }
  2284.                 }
  2285.             }
  2286.            
  2287.             else if ( canPerformFinisher )
  2288.             {
  2289.                 if ( actorVictim.IsAlive() )
  2290.                     actorVictim.Kill( 'Finisher', false, thePlayer );
  2291.                    
  2292.                 thePlayer.AddTimer( 'DelayedFinisherInputTimer', 0.1f );
  2293.                 thePlayer.SetFinisherVictim( actorVictim );
  2294.                 thePlayer.CleanCombatActionBuffer();
  2295.                 thePlayer.OnBlockAllCombatTickets( true );
  2296.                
  2297.                 if( actorVictim.WillBeUnconscious() )
  2298.                 {
  2299.                     actorVictim.SetBehaviorVariable( 'prepareForUnconsciousFinisher', 1.0f );
  2300.                     actorVictim.ActionRotateToAsync( thePlayer.GetWorldPosition() );
  2301.                 }
  2302.                
  2303.                 moveTargets = thePlayer.GetMoveTargets();
  2304.                
  2305.                 for ( i = 0; i < moveTargets.Size(); i += 1 )
  2306.                 {
  2307.                     if ( actorVictim != moveTargets[i] )
  2308.                         moveTargets[i].SignalGameplayEvent( 'InterruptChargeAttack' );
  2309.                 }  
  2310.                
  2311.                 if  (   theGame.GetInGameConfigWrapper().GetVarValue('Gameplay', 'AutomaticFinishersEnabled' ) == "true"
  2312.                     || ( (W3PlayerWitcher)playerAttacker && GetWitcherPlayer().IsMutationActive( EPMT_Mutation3 ) )
  2313.                     ||  actorVictim.WillBeUnconscious()
  2314.                     )
  2315.                 {
  2316.                     actorVictim.AddAbility( 'ForceFinisher', false );
  2317.                 }
  2318.                
  2319.                 if ( actorVictim.HasTag( 'ForceFinisher' ) )
  2320.                     actorVictim.AddAbility( 'ForceFinisher', false );
  2321.                
  2322.                 actorVictim.SignalGameplayEvent( 'ForceFinisher' );
  2323.             }
  2324.             else if ( weaponName == 'fists' && npcVictim )
  2325.             {
  2326.                 npcVictim.DisableAgony();  
  2327.             }
  2328.            
  2329.             thePlayer.FindMoveTarget();
  2330.         }
  2331.        
  2332.         if( attackAction.IsActionMelee() )
  2333.         {
  2334.             actorAttacker.SignalGameplayEventParamObject( 'HitActionReaction', actorVictim );
  2335.             actorVictim.OnHitActionReaction( actorAttacker, weaponName );
  2336.         }
  2337.        
  2338.        
  2339.         actorVictim.ProcessHitSound(action, playsNonAdditiveAnim || !actorVictim.IsAlive());
  2340.        
  2341.        
  2342.        
  2343.         if(action.IsCriticalHit() && action.DealtDamage() && !actorVictim.IsAlive() && actorAttacker == thePlayer )
  2344.             GCameraShake( 0.5, true, actorAttacker.GetWorldPosition(), 10 );
  2345.        
  2346.        
  2347.         if( attackAction && npcVictim && npcVictim.IsShielded( actorAttacker ) && attackAction.IsParried() && attackAction.GetAttackName() == 'attack_heavy' &&  npcVictim.GetStaminaPercents() <= 0.1 )
  2348.         {
  2349.             npcVictim.ProcessShieldDestruction();
  2350.         }
  2351.        
  2352.        
  2353.         if( actorVictim && action.CanPlayHitParticle() && ( action.DealsAnyDamage() || (attackAction && attackAction.IsParried()) ) )
  2354.             actorVictim.PlayHitEffect(action);
  2355.            
  2356.  
  2357.         if( action.victim.HasAbility('mon_nekker_base') && !actorVictim.CanPlayHitAnim() && !((CBaseGameplayEffect) action.causer) )
  2358.         {
  2359.            
  2360.             actorVictim.PlayEffect(theGame.params.LIGHT_HIT_FX);
  2361.             actorVictim.SoundEvent("cmb_play_hit_light");
  2362.         }
  2363.            
  2364.        
  2365.         if(actorVictim && playerAttacker && action.IsActionMelee() && thePlayer.inv.IsItemFists(weaponId) )
  2366.         {
  2367.             actorVictim.SignalGameplayEvent( 'wasHitByFists' );
  2368.                
  2369.             if(MonsterCategoryIsMonster(victimMonsterCategory))
  2370.             {
  2371.                 if(!victimCanBeHitByFists)
  2372.                 {
  2373.                     playerAttacker.ReactToReflectedAttack(actorVictim);
  2374.                 }
  2375.                 else
  2376.                 {          
  2377.                     actorVictim.GetResistValue(CDS_PhysicalRes, points, percents);
  2378.                
  2379.                     if(percents >= theGame.params.MONSTER_RESIST_THRESHOLD_TO_REFLECT_FISTS)
  2380.                         playerAttacker.ReactToReflectedAttack(actorVictim);
  2381.                 }
  2382.             }          
  2383.         }
  2384.        
  2385.        
  2386.         ProcessSparksFromNoDamage();
  2387.        
  2388.        
  2389.         if(attackAction && attackAction.IsActionMelee() && actorAttacker && playerVictim && attackAction.IsCountered() && playerVictim == GetWitcherPlayer())
  2390.         {
  2391.             GetWitcherPlayer().SetRecentlyCountered(true);
  2392.         }
  2393.        
  2394.        
  2395.        
  2396.        
  2397.         if(attackAction && !action.IsDoTDamage() && (playerAttacker || playerVictim) && (attackAction.IsParried() || attackAction.IsCountered()) )
  2398.         {
  2399.             theGame.VibrateControllerLight();
  2400.         }
  2401.     }
  2402.    
  2403.     private function CanDismember( wasFrozen : bool, out dismemberExplosion : bool, out weaponName : name ) : bool
  2404.     {
  2405.         var dismember           : bool;
  2406.         var dismemberChance     : int;
  2407.         var petard              : W3Petard;
  2408.         var bolt                : W3BoltProjectile;
  2409.         var arrow               : W3ArrowProjectile;
  2410.         var inv                 : CInventoryComponent;
  2411.         var toxicCloud          : W3ToxicCloud;
  2412.         var witcher             : W3PlayerWitcher;
  2413.         var i                   : int;
  2414.         var secondaryWeapon     : bool;
  2415.  
  2416.         petard = (W3Petard)action.causer;
  2417.         bolt = (W3BoltProjectile)action.causer;
  2418.         arrow = (W3ArrowProjectile)action.causer;
  2419.         toxicCloud = (W3ToxicCloud)action.causer;
  2420.        
  2421.         dismemberExplosion = false;
  2422.        
  2423.         if(playerAttacker)
  2424.         {
  2425.             secondaryWeapon = playerAttacker.inv.ItemHasTag( weaponId, 'SecondaryWeapon' ) || playerAttacker.inv.ItemHasTag( weaponId, 'Wooden' );
  2426.         }
  2427.        
  2428.         if( actorVictim.HasAbility( 'DisableDismemberment' ) )
  2429.         {
  2430.             dismember = false;
  2431.         }
  2432.         else if( actorVictim.HasTag( 'DisableDismemberment' ) )
  2433.         {
  2434.             dismember = false;
  2435.         }
  2436.         else if (actorVictim.WillBeUnconscious())
  2437.         {
  2438.             dismember = false;     
  2439.         }
  2440.         else if (playerAttacker && secondaryWeapon )
  2441.         {
  2442.             dismember = false;
  2443.         }
  2444.         else if( arrow && !wasFrozen )
  2445.         {
  2446.             dismember = false;
  2447.         }      
  2448.         else if( actorAttacker.HasAbility( 'ForceDismemberment' ) )
  2449.         {
  2450.             dismember = true;
  2451.             dismemberExplosion = action.HasForceExplosionDismemberment();
  2452.         }
  2453.         else if(wasFrozen)
  2454.         {
  2455.             dismember = true;
  2456.             dismemberExplosion = action.HasForceExplosionDismemberment();
  2457.         }                      
  2458.         else if( (petard && petard.DismembersOnKill()) || (bolt && bolt.DismembersOnKill()) )
  2459.         {
  2460.             dismember = true;
  2461.             dismemberExplosion = action.HasForceExplosionDismemberment();
  2462.         }
  2463.         else if( (W3Effect_YrdenHealthDrain)action.causer )
  2464.         {
  2465.             dismember = true;
  2466.             dismemberExplosion = true;
  2467.         }
  2468.         else if(toxicCloud && toxicCloud.HasExplodingTargetDamages())
  2469.         {
  2470.             dismember = true;
  2471.             dismemberExplosion = true;
  2472.         }
  2473.         else
  2474.         {
  2475.             inv = actorAttacker.GetInventory();
  2476.             weaponName = inv.GetItemName( weaponId );
  2477.            
  2478.             if( attackAction
  2479.                 && !inv.IsItemSteelSwordUsableByPlayer(weaponId)
  2480.                 && !inv.IsItemSilverSwordUsableByPlayer(weaponId)
  2481.                 && weaponName != 'polearm'
  2482.                 && weaponName != 'fists_lightning'
  2483.                 && weaponName != 'fists_fire' )
  2484.             {
  2485.                 dismember = false;
  2486.             }          
  2487.             else if ( action.IsCriticalHit() )
  2488.             {
  2489.                 dismember = true;
  2490.                 dismemberExplosion = action.HasForceExplosionDismemberment();
  2491.             }
  2492.             else if ( action.HasForceExplosionDismemberment() )
  2493.             {
  2494.                 dismember = true;
  2495.                 dismemberExplosion = true;
  2496.             }
  2497.            
  2498.             else if ( weaponName == 'fists_lightning' || weaponName == 'fists_fire' )
  2499.             {
  2500.                 if(RandRange(100) > 75)
  2501.                     dismember = true;
  2502.             }
  2503.            
  2504.             else
  2505.             {
  2506.                
  2507.                 dismemberChance = theGame.params.DISMEMBERMENT_ON_DEATH_CHANCE;
  2508.                
  2509.                
  2510.                 if(playerAttacker && playerAttacker.forceDismember)
  2511.                 {
  2512.                     dismemberChance = thePlayer.forceDismemberChance;
  2513.                     dismemberExplosion = thePlayer.forceDismemberExplosion;
  2514.                 }
  2515.                
  2516.                
  2517.                 if(attackAction)
  2518.                 {
  2519.                     dismemberChance += RoundMath(100 * CalculateAttributeValue(inv.GetItemAttributeValue(weaponId, 'dismember_chance')));
  2520.                     dismemberExplosion = attackAction.HasForceExplosionDismemberment();
  2521.                 }
  2522.                    
  2523.                
  2524.                 witcher = (W3PlayerWitcher)actorAttacker;
  2525.                 if(witcher && witcher.CanUseSkill(S_Perk_03))
  2526.                     dismemberChance += RoundMath(100 * CalculateAttributeValue(witcher.GetSkillAttributeValue(S_Perk_03, 'dismember_chance', false, true)));
  2527.                
  2528.                
  2529.                 if( ( W3PlayerWitcher )playerAttacker && attackAction.IsActionMelee() && GetWitcherPlayer().IsMutationActive(EPMT_Mutation3) ) 
  2530.                 {
  2531.                     if( thePlayer.inv.IsItemSteelSwordUsableByPlayer( weaponId ) || thePlayer.inv.IsItemSilverSwordUsableByPlayer( weaponId ) )
  2532.                     {
  2533.                         dismemberChance = 100;
  2534.                     }
  2535.                 }
  2536.                
  2537.                 dismemberChance = Clamp(dismemberChance, 0, 100);
  2538.                
  2539.                 if (RandRange(100) < dismemberChance)
  2540.                     dismember = true;
  2541.                 else
  2542.                     dismember = false;
  2543.             }
  2544.         }      
  2545.  
  2546.         return dismember;
  2547.     }  
  2548.    
  2549.     private function CanPerformFinisher( actorVictim : CActor ) : bool
  2550.     {
  2551.         var finisherChance          : int;
  2552.         var areEnemiesAttacking     : bool;
  2553.         var i                       : int;
  2554.         var victimToPlayerVector, playerPos : Vector;
  2555.         var item                    : SItemUniqueId;
  2556.         var moveTargets             : array<CActor>;
  2557.         var b                       : bool;
  2558.         var size                    : int;
  2559.         var npc                     : CNewNPC;
  2560.        
  2561.         if ( (W3ReplacerCiri)thePlayer || playerVictim || thePlayer.isInFinisher )
  2562.             return false;
  2563.        
  2564.         if ( actorVictim.IsAlive() && !CanPerformFinisherOnAliveTarget(actorVictim) )
  2565.             return false;
  2566.        
  2567.        
  2568.         if ( actorVictim.WillBeUnconscious() && !theGame.GetDLCManager().IsEP2Available() )
  2569.             return false;
  2570.        
  2571.         moveTargets = thePlayer.GetMoveTargets();  
  2572.         size = moveTargets.Size();
  2573.         playerPos = thePlayer.GetWorldPosition();
  2574.    
  2575.         if ( size > 0 )
  2576.         {
  2577.             areEnemiesAttacking = false;           
  2578.             for(i=0; i<size; i+=1)
  2579.             {
  2580.                 npc = (CNewNPC)moveTargets[i];
  2581.                 if(npc && VecDistanceSquared(playerPos, moveTargets[i].GetWorldPosition()) < 7 && npc.IsAttacking() && npc != actorVictim )
  2582.                 {
  2583.                     areEnemiesAttacking = true;
  2584.                     break;
  2585.                 }
  2586.             }
  2587.         }
  2588.        
  2589.         victimToPlayerVector = actorVictim.GetWorldPosition() - playerPos;
  2590.        
  2591.         if ( actorVictim.IsHuman() )
  2592.         {
  2593.             npc = (CNewNPC)actorVictim;
  2594.             if ( ( size <= 1 && theGame.params.FINISHER_ON_DEATH_CHANCE > 0 ) || ( actorVictim.HasAbility('ForceFinisher') ) || ( GetWitcherPlayer().IsMutationActive(EPMT_Mutation3) ) )
  2595.             {
  2596.                 finisherChance = 100;
  2597.             }
  2598.             else if ( ( actorVictim.HasBuff(EET_Confusion) || actorVictim.HasBuff(EET_AxiiGuardMe) ) )
  2599.             {
  2600.                 finisherChance = 75 + ( - ( npc.currentLevel - thePlayer.GetLevel() ) );
  2601.             }
  2602.             else if ( npc.currentLevel - thePlayer.GetLevel() < -5 )
  2603.             {
  2604.                 finisherChance = theGame.params.FINISHER_ON_DEATH_CHANCE + ( - ( npc.currentLevel - thePlayer.GetLevel() ) );
  2605.             }
  2606.             else
  2607.                 finisherChance = theGame.params.FINISHER_ON_DEATH_CHANCE;
  2608.                
  2609.             finisherChance = Clamp(finisherChance, 0, 100);
  2610.         }
  2611.         else
  2612.             finisherChance = 0;
  2613.            
  2614.         if ( actorVictim.HasTag('ForceFinisher') )
  2615.         {
  2616.             finisherChance = 100;
  2617.             areEnemiesAttacking = false;
  2618.         }
  2619.            
  2620.         item = thePlayer.inv.GetItemFromSlot( 'l_weapon' );
  2621.        
  2622.         if ( thePlayer.forceFinisher )
  2623.         {
  2624.             b = playerAttacker && attackAction && attackAction.IsActionMelee();
  2625.             b = b && ( actorVictim.IsHuman() && !actorVictim.IsWoman() );
  2626.             b = b && !thePlayer.IsInAir();
  2627.             b = b && ( thePlayer.IsWeaponHeld( 'steelsword') || thePlayer.IsWeaponHeld( 'silversword') );
  2628.             b = b && !thePlayer.IsSecondaryWeaponHeld();
  2629.             b = b && !thePlayer.inv.IsIdValid( item );
  2630.             b = b && !actorVictim.IsKnockedUnconscious();
  2631.             b = b && !actorVictim.HasBuff( EET_Knockdown );
  2632.             b = b && !actorVictim.HasBuff( EET_Ragdoll );
  2633.             b = b && !actorVictim.HasBuff( EET_Frozen );
  2634.             b = b && !actorVictim.HasAbility( 'DisableFinishers' );
  2635.             b = b && !thePlayer.IsUsingVehicle();
  2636.             b = b && thePlayer.IsAlive();
  2637.             b = b && !thePlayer.IsCurrentSignChanneled();
  2638.         }
  2639.         else
  2640.         {
  2641.             b = playerAttacker && attackAction && attackAction.IsActionMelee();
  2642.             b = b && ( actorVictim.IsHuman() && !actorVictim.IsWoman() );
  2643.             b = b && RandRange(100) < finisherChance;
  2644.             b = b && !areEnemiesAttacking;
  2645.             b = b && AbsF( victimToPlayerVector.Z ) < 0.4f;
  2646.             b = b && !thePlayer.IsInAir();
  2647.             b = b && ( thePlayer.IsWeaponHeld( 'steelsword') || thePlayer.IsWeaponHeld( 'silversword') );
  2648.             b = b && !thePlayer.IsSecondaryWeaponHeld();
  2649.             b = b && !thePlayer.inv.IsIdValid( item );
  2650.             b = b && !actorVictim.IsKnockedUnconscious();
  2651.             b = b && !actorVictim.HasBuff( EET_Knockdown );
  2652.             b = b && !actorVictim.HasBuff( EET_Ragdoll );
  2653.             b = b && !actorVictim.HasBuff( EET_Frozen );
  2654.             b = b && !actorVictim.HasAbility( 'DisableFinishers' );
  2655.             b = b && actorVictim.GetAttitude( thePlayer ) == AIA_Hostile;
  2656.             b = b && !thePlayer.IsUsingVehicle();
  2657.             b = b && thePlayer.IsAlive();
  2658.             b = b && !thePlayer.IsCurrentSignChanneled();
  2659.             b = b && ( theGame.GetWorld().NavigationCircleTest( actorVictim.GetWorldPosition(), 2.f ) || actorVictim.HasTag('ForceFinisher') ) ;
  2660.            
  2661.         }
  2662.  
  2663.         if ( b  )
  2664.         {
  2665.             if ( !actorVictim.IsAlive() && !actorVictim.WillBeUnconscious() )
  2666.                 actorVictim.AddAbility( 'DisableFinishers', false );
  2667.                
  2668.             return true;
  2669.         }
  2670.        
  2671.         return false;
  2672.     }
  2673.    
  2674.     private function CanPerformFinisherOnAliveTarget( actorVictim : CActor ) : bool
  2675.     {
  2676.         return actorVictim.IsHuman()
  2677.         && ( actorVictim.HasBuff(EET_Confusion) || actorVictim.HasBuff(EET_AxiiGuardMe) )
  2678.         && actorVictim.IsVulnerable()
  2679.         && !actorVictim.HasAbility('DisableFinisher')
  2680.         && !actorVictim.HasAbility('InstantKillImmune');
  2681.     }
  2682.    
  2683.    
  2684.    
  2685.    
  2686.    
  2687.    
  2688.     private function ProcessActionBuffs() : bool
  2689.     {
  2690.         var inv : CInventoryComponent;
  2691.         var ret : bool;
  2692.    
  2693.        
  2694.         if(!action.victim.IsAlive() || action.WasDodged() || (attackAction && attackAction.IsActionMelee() && !attackAction.ApplyBuffsIfParried() && attackAction.CanBeParried() && attackAction.IsParried()) )
  2695.             return true;
  2696.            
  2697.        
  2698.         ApplyQuenBuffChanges();
  2699.    
  2700.        
  2701.         if( actorAttacker == thePlayer && action.IsActionWitcherSign() && action.IsCriticalHit() && GetWitcherPlayer().IsMutationActive( EPMT_Mutation2 ) && action.HasBuff( EET_Burning ) )
  2702.         {
  2703.             action.SetBuffSourceName( 'Mutation2ExplosionValid' );
  2704.         }
  2705.    
  2706.        
  2707.         if(actorVictim && action.GetEffectsCount() > 0)
  2708.             ret = actorVictim.ApplyActionEffects(action);
  2709.         else
  2710.             ret = false;
  2711.            
  2712.        
  2713.         if(actorAttacker && actorVictim)
  2714.         {
  2715.             inv = actorAttacker.GetInventory();
  2716.             actorAttacker.ProcessOnHitEffects(actorVictim, inv.IsItemSilverSwordUsableByPlayer(weaponId), inv.IsItemSteelSwordUsableByPlayer(weaponId), action.IsActionWitcherSign() );
  2717.         }
  2718.        
  2719.         return ret;
  2720.     }
  2721.    
  2722.    
  2723.     private function ApplyQuenBuffChanges()
  2724.     {
  2725.         var npc : CNewNPC;
  2726.         var protection : bool;
  2727.         var witcher : W3PlayerWitcher;
  2728.         var quenEntity : W3QuenEntity;
  2729.         var i : int;
  2730.         var buffs : array<EEffectType>;
  2731.    
  2732.         if(!actorVictim || !actorVictim.HasAlternateQuen())
  2733.             return;
  2734.        
  2735.         npc = (CNewNPC)actorVictim;
  2736.         if(npc)
  2737.         {
  2738.             if(!action.DealsAnyDamage())
  2739.                 protection = true;
  2740.         }
  2741.         else
  2742.         {
  2743.             witcher = (W3PlayerWitcher)actorVictim;
  2744.             if(witcher)
  2745.             {
  2746.                 quenEntity = (W3QuenEntity)witcher.GetCurrentSignEntity();
  2747.                 if(quenEntity.GetBlockedAllDamage())
  2748.                 {
  2749.                     protection = true;
  2750.                 }
  2751.             }
  2752.         }
  2753.        
  2754.         if(!protection)
  2755.             return;
  2756.            
  2757.         action.GetEffectTypes(buffs);
  2758.         for(i=buffs.Size()-1; i>=0; i -=1)
  2759.         {
  2760.             if(buffs[i] == EET_KnockdownTypeApplicator || IsKnockdownEffectType(buffs[i]))
  2761.                 continue;
  2762.                
  2763.             action.RemoveBuff(i);
  2764.         }
  2765.     }
  2766.    
  2767.    
  2768.    
  2769.    
  2770.     private function ProcessDismemberment(wasFrozen : bool, dismemberExplosion : bool )
  2771.     {
  2772.         var hitDirection        : Vector;
  2773.         var usedWound           : name;
  2774.         var npcVictim           : CNewNPC;
  2775.         var wounds              : array< name >;
  2776.         var i                   : int;
  2777.         var petard              : W3Petard;
  2778.         var bolt                : W3BoltProjectile;    
  2779.         var forcedRagdoll       : bool;
  2780.         var isExplosion         : bool;
  2781.         var dismembermentComp   : CDismembermentComponent;
  2782.         var specialWounds       : array< name >;
  2783.         var useHitDirection     : bool;
  2784.         var fxMask              : EDismembermentEffectTypeFlags;
  2785.         var template            : CEntityTemplate;
  2786.         var ent                 : CEntity;
  2787.         var signType            : ESignType;
  2788.        
  2789.         if(!actorVictim)
  2790.             return;
  2791.            
  2792.         dismembermentComp = (CDismembermentComponent)(actorVictim.GetComponentByClassName( 'CDismembermentComponent' ));
  2793.         if(!dismembermentComp)
  2794.             return;
  2795.            
  2796.         if(wasFrozen)
  2797.         {
  2798.             ProcessFrostDismemberment();
  2799.             return;
  2800.         }
  2801.        
  2802.         forcedRagdoll = false;
  2803.        
  2804.        
  2805.         petard = (W3Petard)action.causer;
  2806.         bolt = (W3BoltProjectile)action.causer;
  2807.        
  2808.         if( dismemberExplosion || (attackAction && ( attackAction.GetAttackName() == 'attack_explosion' || attackAction.HasForceExplosionDismemberment() ))
  2809.             || (petard && petard.DismembersOnKill()) || (bolt && bolt.DismembersOnKill()) )
  2810.         {
  2811.             isExplosion = true;
  2812.         }
  2813.         else
  2814.         {
  2815.             isExplosion = false;
  2816.         }
  2817.        
  2818.        
  2819.         if(playerAttacker && thePlayer.forceDismember && IsNameValid(thePlayer.forceDismemberName))
  2820.         {
  2821.             usedWound = thePlayer.forceDismemberName;
  2822.         }
  2823.         else
  2824.         {  
  2825.            
  2826.             if(isExplosion)
  2827.             {
  2828.                 dismembermentComp.GetWoundsNames( wounds, WTF_Explosion ); 
  2829.  
  2830.                
  2831.                 if( action.IsMutation2PotentialKill() )
  2832.                 {
  2833.                    
  2834.                     for( i=wounds.Size()-1; i>=0; i-=1 )
  2835.                     {
  2836.                         if( !StrContains( wounds[ i ], "_ep2" ) )
  2837.                         {
  2838.                             wounds.EraseFast( i );
  2839.                         }
  2840.                     }
  2841.                    
  2842.                     signType = action.GetSignType();
  2843.                     if( signType == ST_Aard )
  2844.                     {
  2845.                         fxMask = DETF_Aaard;
  2846.                     }
  2847.                     else if( signType == ST_Igni )
  2848.                     {
  2849.                         fxMask = DETF_Igni;
  2850.                     }
  2851.                     else if( signType == ST_Yrden )
  2852.                     {
  2853.                         fxMask = DETF_Yrden;
  2854.                     }
  2855.                     else if( signType == ST_Quen )
  2856.                     {
  2857.                         fxMask = DETF_Quen;
  2858.                     }
  2859.                 }
  2860.                 else
  2861.                 {
  2862.                     fxMask = 0;
  2863.                 }
  2864.                
  2865.                 if ( wounds.Size() > 0 )
  2866.                     usedWound = wounds[ RandRange( wounds.Size() ) ];
  2867.                    
  2868.                 if ( usedWound )
  2869.                     StopVO( actorVictim );
  2870.             }
  2871.             else if(attackAction || action.GetBuffSourceName() == "riderHit")
  2872.             {
  2873.                 if  ( attackAction.GetAttackTypeName() == 'sword_s2' || thePlayer.isInFinisher )
  2874.                     useHitDirection = true;
  2875.                
  2876.                 if ( useHitDirection )
  2877.                 {
  2878.                     hitDirection = actorAttacker.GetSwordTipMovementFromAnimation( attackAction.GetAttackAnimName(), attackAction.GetHitTime(), 0.1, attackAction.GetWeaponEntity() );
  2879.                     usedWound = actorVictim.GetNearestWoundForBone( attackAction.GetHitBoneIndex(), hitDirection, WTF_Cut );
  2880.                 }
  2881.                 else
  2882.                 {          
  2883.                    
  2884.                     dismembermentComp.GetWoundsNames( wounds );
  2885.                    
  2886.                    
  2887.                     if(wounds.Size() > 0)
  2888.                     {
  2889.                         dismembermentComp.GetWoundsNames( specialWounds, WTF_Explosion );
  2890.                         for ( i = 0; i < specialWounds.Size(); i += 1 )
  2891.                         {
  2892.                             wounds.Remove( specialWounds[i] );
  2893.                         }
  2894.                        
  2895.                         if(wounds.Size() > 0)
  2896.                         {
  2897.                            
  2898.                             dismembermentComp.GetWoundsNames( specialWounds, WTF_Frost );
  2899.                             for ( i = 0; i < specialWounds.Size(); i += 1 )
  2900.                             {
  2901.                                 wounds.Remove( specialWounds[i] );
  2902.                             }
  2903.                            
  2904.                            
  2905.                             if ( wounds.Size() > 0 )
  2906.                                 usedWound = wounds[ RandRange( wounds.Size() ) ];
  2907.                         }
  2908.                     }
  2909.                 }
  2910.             }
  2911.         }
  2912.        
  2913.         if ( usedWound )
  2914.         {
  2915.             npcVictim = (CNewNPC)action.victim;
  2916.             if(npcVictim)
  2917.                 npcVictim.DisableAgony();          
  2918.            
  2919.             actorVictim.SetDismembermentInfo( usedWound, actorVictim.GetWorldPosition() - actorAttacker.GetWorldPosition(), forcedRagdoll, fxMask );
  2920.             actorVictim.AddTimer( 'DelayedDismemberTimer', 0.05f );
  2921.             actorVictim.SetBehaviorVariable( 'dismemberAnim', 1.0 );
  2922.            
  2923.            
  2924.             if ( usedWound == 'explode_02' || usedWound == 'explode2' || usedWound == 'explode_02_ep2' || usedWound == 'explode2_ep2')
  2925.             {
  2926.                 ProcessDismembermentDeathAnim( usedWound, true, EFDT_LegLeft );
  2927.                 actorVictim.SetKinematic( false );
  2928.                
  2929.             }
  2930.             else
  2931.             {
  2932.                 ProcessDismembermentDeathAnim( usedWound, false );
  2933.             }
  2934.            
  2935.            
  2936.             if( usedWound == 'explode_01_ep2' || usedWound == 'explode1_ep2' || usedWound == 'explode_02_ep2' || usedWound == 'explode2_ep2' )
  2937.             {
  2938.                 template = (CEntityTemplate) LoadResource( "explosion_dismember_force" );
  2939.                 ent = theGame.CreateEntity( template, npcVictim.GetWorldPosition(), , , , true );
  2940.                 ent.DestroyAfter( 5.f );
  2941.             }
  2942.            
  2943.             DropEquipmentFromDismember( usedWound, true, true );
  2944.            
  2945.             if( attackAction && actorAttacker == thePlayer )           
  2946.                 GCameraShake( 0.5, true, actorAttacker.GetWorldPosition(), 10);
  2947.                
  2948.             if(playerAttacker)
  2949.                 theGame.VibrateControllerHard();   
  2950.                
  2951.            
  2952.             if( dismemberExplosion && (W3AardProjectile)action.causer )
  2953.             {
  2954.                 npcVictim.AddTimer( 'AardDismemberForce', 0.00001f );
  2955.             }
  2956.         }
  2957.         else
  2958.         {
  2959.             LogChannel( 'Dismemberment', "ERROR: No wound found to dismember on entity but entity supports dismemberment!!!" );
  2960.         }
  2961.     }
  2962.    
  2963.     function ApplyForce()
  2964.     {
  2965.         var size, i : int;
  2966.         var victim : CNewNPC;
  2967.         var fromPos, toPos : Vector;
  2968.         var comps : array<CComponent>;
  2969.         var impulse : Vector;
  2970.        
  2971.         victim = (CNewNPC)action.victim;
  2972.         toPos = victim.GetWorldPosition();
  2973.         toPos.Z += 1.0f;
  2974.         fromPos = toPos;
  2975.         fromPos.Z -= 2.0f;
  2976.         impulse = VecNormalize( toPos - fromPos.Z ) * 10;
  2977.        
  2978.         comps = victim.GetComponentsByClassName('CComponent');
  2979.         victim.GetVisualDebug().AddArrow( 'applyForce', fromPos, toPos, 1, 0.2f, 0.2f, true, Color( 0,0,255 ), true, 5.0f );
  2980.         size = comps.Size();
  2981.         for( i = 0; i < size; i += 1 )
  2982.         {
  2983.             comps[i].ApplyLocalImpulseToPhysicalObject( impulse );
  2984.         }
  2985.     }
  2986.    
  2987.     private function ProcessFrostDismemberment()
  2988.     {
  2989.         var dismembermentComp   : CDismembermentComponent;
  2990.         var wounds              : array< name >;
  2991.         var wound               : name;
  2992.         var i, fxMask           : int;
  2993.         var npcVictim           : CNewNPC;
  2994.        
  2995.         dismembermentComp = (CDismembermentComponent)(actorVictim.GetComponentByClassName( 'CDismembermentComponent' ));
  2996.         if(!dismembermentComp)
  2997.             return;
  2998.        
  2999.         dismembermentComp.GetWoundsNames( wounds, WTF_Frost );
  3000.        
  3001.        
  3002.        
  3003.         if( theGame.GetDLCManager().IsEP2Enabled() )
  3004.         {
  3005.             fxMask = DETF_Mutation6;
  3006.            
  3007.            
  3008.             for( i=wounds.Size()-1; i>=0; i-=1 )
  3009.             {
  3010.                 if( !StrContains( wounds[ i ], "_ep2" ) )
  3011.                 {
  3012.                     wounds.EraseFast( i );
  3013.                 }
  3014.             }
  3015.         }
  3016.         else
  3017.         {
  3018.             fxMask = 0;
  3019.         }
  3020.        
  3021.         if ( wounds.Size() > 0 )
  3022.         {
  3023.             wound = wounds[ RandRange( wounds.Size() ) ];
  3024.         }
  3025.         else
  3026.         {
  3027.             return;
  3028.         }
  3029.        
  3030.         npcVictim = (CNewNPC)action.victim;
  3031.         if(npcVictim)
  3032.         {
  3033.             npcVictim.DisableAgony();
  3034.             StopVO( npcVictim );
  3035.         }
  3036.        
  3037.         actorVictim.SetDismembermentInfo( wound, actorVictim.GetWorldPosition() - actorAttacker.GetWorldPosition(), true, fxMask );
  3038.         actorVictim.AddTimer( 'DelayedDismemberTimer', 0.05f );
  3039.         if( wound == 'explode_02' || wound == 'explode2' || wound == 'explode_02_ep2' || wound == 'explode2_ep2' )
  3040.         {
  3041.             ProcessDismembermentDeathAnim( wound, true, EFDT_LegLeft );
  3042.             npcVictim.SetKinematic(false);
  3043.         }
  3044.         else
  3045.         {
  3046.             ProcessDismembermentDeathAnim( wound, false );
  3047.         }
  3048.         DropEquipmentFromDismember( wound, true, true );
  3049.        
  3050.         if( attackAction )         
  3051.             GCameraShake( 0.5, true, actorAttacker.GetWorldPosition(), 10);
  3052.            
  3053.         if(playerAttacker)
  3054.             theGame.VibrateControllerHard();   
  3055.     }
  3056.    
  3057.    
  3058.     private function ProcessDismembermentDeathAnim( nearestWound : name, forceDeathType : bool, optional deathType : EFinisherDeathType )
  3059.     {
  3060.         var dropCurveName : name;
  3061.        
  3062.         if ( forceDeathType )
  3063.         {
  3064.             if ( deathType == EFDT_Head )
  3065.                 StopVO( actorVictim );
  3066.                
  3067.             actorVictim.SetBehaviorVariable( 'FinisherDeathType', (int)deathType );
  3068.            
  3069.             return;
  3070.         }
  3071.        
  3072.         dropCurveName = ( (CDismembermentComponent)(actorVictim.GetComponentByClassName( 'CDismembermentComponent' )) ).GetMainCurveName( nearestWound );
  3073.        
  3074.         if ( dropCurveName == 'head' )
  3075.         {
  3076.             actorVictim.SetBehaviorVariable( 'FinisherDeathType', (int)EFDT_Head );
  3077.             StopVO( actorVictim );
  3078.         }
  3079.         else if ( dropCurveName == 'torso_left' || dropCurveName == 'torso_right' || dropCurveName == 'torso' )
  3080.             actorVictim.SetBehaviorVariable( 'FinisherDeathType', (int)EFDT_Torso );
  3081.         else if ( dropCurveName == 'arm_right' )
  3082.             actorVictim.SetBehaviorVariable( 'FinisherDeathType', (int)EFDT_ArmRight );
  3083.         else if ( dropCurveName == 'arm_left' )
  3084.             actorVictim.SetBehaviorVariable( 'FinisherDeathType', (int)EFDT_ArmLeft );
  3085.         else if ( dropCurveName == 'leg_left' )
  3086.             actorVictim.SetBehaviorVariable( 'FinisherDeathType', (int)EFDT_LegLeft );
  3087.         else if ( dropCurveName == 'leg_right' )
  3088.             actorVictim.SetBehaviorVariable( 'FinisherDeathType', (int)EFDT_LegRight );
  3089.         else
  3090.             actorVictim.SetBehaviorVariable( 'FinisherDeathType', (int)EFDT_None );
  3091.     }
  3092.    
  3093.     private function StopVO( actor : CActor )
  3094.     {
  3095.         actor.SoundEvent( "grunt_vo_death_stop", 'head' );
  3096.     }
  3097.  
  3098.     private function DropEquipmentFromDismember( nearestWound : name, optional dropLeft, dropRight : bool )
  3099.     {
  3100.         var dropCurveName : name;
  3101.        
  3102.         if( actorVictim.HasAbility( 'DontDropWeaponsOnDismemberment' ) )
  3103.         {
  3104.             return;
  3105.         }
  3106.        
  3107.         dropCurveName = ( (CDismembermentComponent)(actorVictim.GetComponentByClassName( 'CDismembermentComponent' )) ).GetMainCurveName( nearestWound );
  3108.        
  3109.         if ( ChangeHeldItemAppearance() )
  3110.         {
  3111.             actorVictim.SignalGameplayEvent('DropWeaponsInDeathTask');
  3112.             return;
  3113.         }
  3114.        
  3115.         if ( dropLeft || dropRight )
  3116.         {
  3117.            
  3118.             if ( dropLeft )
  3119.                 actorVictim.DropItemFromSlot( 'l_weapon', true );
  3120.            
  3121.             if ( dropRight )
  3122.                 actorVictim.DropItemFromSlot( 'r_weapon', true );          
  3123.            
  3124.             return;
  3125.         }
  3126.        
  3127.         if ( dropCurveName == 'arm_right' )
  3128.             actorVictim.DropItemFromSlot( 'r_weapon', true );
  3129.         else if ( dropCurveName == 'arm_left' )
  3130.             actorVictim.DropItemFromSlot( 'l_weapon', true );
  3131.         else if ( dropCurveName == 'torso_left' || dropCurveName == 'torso_right' || dropCurveName == 'torso' )
  3132.         {
  3133.             actorVictim.DropItemFromSlot( 'l_weapon', true );
  3134.             actorVictim.DropItemFromSlot( 'r_weapon', true );
  3135.         }          
  3136.         else if ( dropCurveName == 'head' || dropCurveName == 'leg_left' || dropCurveName == 'leg_right' )
  3137.         {
  3138.             if(  RandRange(100) < 50 )
  3139.                 actorVictim.DropItemFromSlot( 'l_weapon', true );
  3140.            
  3141.             if(  RandRange(100) < 50 )
  3142.                 actorVictim.DropItemFromSlot( 'r_weapon', true );
  3143.         }
  3144.     }
  3145.    
  3146.     function ChangeHeldItemAppearance() : bool
  3147.     {
  3148.         var inv : CInventoryComponent;
  3149.         var weapon : SItemUniqueId;
  3150.        
  3151.         inv = actorVictim.GetInventory();
  3152.        
  3153.         weapon = inv.GetItemFromSlot('l_weapon');
  3154.        
  3155.         if ( inv.IsIdValid( weapon ) )
  3156.         {
  3157.             if ( inv.ItemHasTag(weapon,'bow') || inv.ItemHasTag(weapon,'crossbow') )
  3158.                 inv.GetItemEntityUnsafe(weapon).ApplyAppearance("rigid");
  3159.             return true;
  3160.         }
  3161.        
  3162.         weapon = inv.GetItemFromSlot('r_weapon');
  3163.        
  3164.         if ( inv.IsIdValid( weapon ) )
  3165.         {
  3166.             if ( inv.ItemHasTag(weapon,'bow') || inv.ItemHasTag(weapon,'crossbow') )
  3167.                 inv.GetItemEntityUnsafe(weapon).ApplyAppearance("rigid");
  3168.             return true;
  3169.         }
  3170.    
  3171.         return false;
  3172.     }
  3173.    
  3174.    
  3175.     private function GetOilProtectionAgainstMonster(dmgType : name, out resist : float, out reduct : float)
  3176.     {
  3177.         var i : int;
  3178.         var heldWeapons : array< SItemUniqueId >;
  3179.         var weapon : SItemUniqueId;
  3180.        
  3181.         resist = 0;
  3182.         reduct = 0;
  3183.        
  3184.        
  3185.         heldWeapons = thePlayer.inv.GetHeldWeapons();
  3186.        
  3187.        
  3188.         for( i=0; i<heldWeapons.Size(); i+=1 )
  3189.         {
  3190.             if( !thePlayer.inv.IsItemFists( heldWeapons[ i ] ) )
  3191.             {
  3192.                 weapon = heldWeapons[ i ];
  3193.                 break;
  3194.             }
  3195.         }
  3196.        
  3197.        
  3198.         if( !thePlayer.inv.IsIdValid( weapon ) )
  3199.         {
  3200.             return;
  3201.         }
  3202.    
  3203.        
  3204.         if( !thePlayer.inv.ItemHasActiveOilApplied( weapon, attackerMonsterCategory ) )
  3205.         {
  3206.             return;
  3207.         }
  3208.        
  3209.         resist = CalculateAttributeValue( thePlayer.GetSkillAttributeValue( S_Alchemy_s05, 'defence_bonus', false, true ) );       
  3210.     }
  3211.    
  3212.    
  3213.     private function ProcessToxicCloudDismemberExplosion(damages : array<SRawDamage>)
  3214.     {
  3215.         var act : W3DamageAction;
  3216.         var i, j : int;
  3217.         var ents : array<CGameplayEntity>;
  3218.        
  3219.        
  3220.         if(damages.Size() == 0)
  3221.         {
  3222.             LogAssert(false, "W3DamageManagerProcessor.ProcessToxicCloudDismemberExplosion: trying to process but no damages are passed! Aborting!");
  3223.             return;
  3224.         }      
  3225.        
  3226.        
  3227.         FindGameplayEntitiesInSphere(ents, action.victim.GetWorldPosition(), 3, 1000, , FLAG_OnlyAliveActors);
  3228.        
  3229.        
  3230.         for(i=0; i<ents.Size(); i+=1)
  3231.         {
  3232.             act = new W3DamageAction in this;
  3233.             act.Initialize(action.attacker, ents[i], action.causer, 'Dragons_Dream_3', EHRT_Heavy, CPS_Undefined, false, false, false, true);
  3234.            
  3235.             for(j=0; j<damages.Size(); j+=1)
  3236.             {
  3237.                 act.AddDamage(damages[j].dmgType, damages[j].dmgVal);
  3238.             }
  3239.            
  3240.             theGame.damageMgr.ProcessAction(act);
  3241.             delete act;
  3242.         }
  3243.     }
  3244.    
  3245.    
  3246.     private final function ProcessSparksFromNoDamage()
  3247.     {
  3248.         var sparksEntity, weaponEntity : CEntity;
  3249.         var weaponTipPosition : Vector;
  3250.         var weaponSlotMatrix : Matrix;
  3251.        
  3252.        
  3253.         if(!playerAttacker || !attackAction || !attackAction.IsActionMelee() || attackAction.DealsAnyDamage())
  3254.             return;
  3255.        
  3256.        
  3257.         if( ( !attackAction.DidArmorReduceDamageToZero() && !actorVictim.IsVampire() && ( attackAction.IsParried() || attackAction.IsCountered() ) )
  3258.             || ( ( attackAction.IsParried() || attackAction.IsCountered() ) && !actorVictim.IsHuman() && !actorVictim.IsVampire() )
  3259.             || actorVictim.IsCurrentlyDodging() )
  3260.             return;
  3261.        
  3262.        
  3263.         if(actorVictim.HasTag('NoSparksOnArmorDmgReduced'))
  3264.             return;
  3265.        
  3266.        
  3267.         if (!actorVictim.GetGameplayVisibility())
  3268.             return;
  3269.        
  3270.        
  3271.         weaponEntity = playerAttacker.inv.GetItemEntityUnsafe(weaponId);
  3272.         weaponEntity.CalcEntitySlotMatrix( 'blood_fx_point', weaponSlotMatrix );
  3273.         weaponTipPosition = MatrixGetTranslation( weaponSlotMatrix );
  3274.        
  3275.        
  3276.         sparksEntity = theGame.CreateEntity( (CEntityTemplate)LoadResource( 'sword_colision_fx' ), weaponTipPosition );
  3277.         sparksEntity.PlayEffect('sparks');
  3278.     }
  3279.    
  3280.     private function ProcessPreHitModifications()
  3281.     {
  3282.         var fireDamage, totalDmg, maxHealth, currHealth : float;
  3283.         var attribute, min, max : SAbilityAttributeValue;
  3284.         var infusion : ESignType;
  3285.         var hack : array< SIgniEffects >;
  3286.         var dmgValTemp : float;
  3287.         var igni : W3IgniEntity;
  3288.         var quen : W3QuenEntity;
  3289.  
  3290.         if( actorVictim.HasAbility( 'HitWindowOpened' ) && !action.IsDoTDamage() )
  3291.         {
  3292.             if( actorVictim.HasTag( 'fairytale_witch' ) )
  3293.             {
  3294.                
  3295.                
  3296.                
  3297.                
  3298.                
  3299.                
  3300.                     ((CNewNPC)actorVictim).SetBehaviorVariable( 'shouldBreakFlightLoop', 1.0 );
  3301.                
  3302.             }
  3303.             else
  3304.             {
  3305.                 quen = (W3QuenEntity)action.causer;
  3306.            
  3307.                 if( !quen )
  3308.                 {
  3309.                     if( actorVictim.HasTag( 'dettlaff_vampire' ) )
  3310.                     {
  3311.                         actorVictim.StopEffect( 'shadowdash' );
  3312.                     }
  3313.                    
  3314.                     action.ClearDamage();
  3315.                     if( action.IsActionMelee() )
  3316.                     {
  3317.                         actorVictim.PlayEffect( 'special_attack_break' );
  3318.                     }
  3319.                     actorVictim.SetBehaviorVariable( 'repelType', 0 );
  3320.                    
  3321.                     actorVictim.AddEffectDefault( EET_CounterStrikeHit, thePlayer );
  3322.                     action.RemoveBuffsByType( EET_KnockdownTypeApplicator );
  3323.                 }
  3324.             }
  3325.            
  3326.             ((CNewNPC)actorVictim).SetHitWindowOpened( false );
  3327.         }
  3328.        
  3329.        
  3330.        
  3331.         if(playerAttacker && attackAction && attackAction.IsActionMelee() && (W3PlayerWitcher)thePlayer && thePlayer.HasAbility('Runeword 1 _Stats', true))
  3332.         {
  3333.             infusion = GetWitcherPlayer().GetRunewordInfusionType();
  3334.            
  3335.             switch(infusion)
  3336.             {
  3337.                 case ST_Aard:
  3338.                     action.AddEffectInfo(EET_KnockdownTypeApplicator);
  3339.                     action.SetProcessBuffsIfNoDamage(true);
  3340.                     attackAction.SetApplyBuffsIfParried(true);
  3341.                     actorVictim.CreateFXEntityAtPelvis( 'runeword_1_aard', false );
  3342.                     break;
  3343.                 case ST_Axii:
  3344.                     action.AddEffectInfo(EET_Confusion);
  3345.                     action.SetProcessBuffsIfNoDamage(true);
  3346.                     attackAction.SetApplyBuffsIfParried(true);
  3347.                     break;
  3348.                 case ST_Igni:
  3349.                    
  3350.                     totalDmg = action.GetDamageValueTotal();
  3351.                     attribute = thePlayer.GetAttributeValue('runeword1_fire_dmg');
  3352.                     fireDamage = totalDmg * attribute.valueMultiplicative;
  3353.                     action.AddDamage(theGame.params.DAMAGE_NAME_FIRE, fireDamage);
  3354.                    
  3355.                    
  3356.                     action.SetCanPlayHitParticle(false);                   
  3357.                     action.victim.AddTimer('Runeword1DisableFireFX', 1.f);
  3358.                     action.SetHitReactionType(EHRT_Heavy); 
  3359.                     action.victim.PlayEffect('critical_burning');
  3360.                     break;
  3361.                 case ST_Yrden:
  3362.                     attribute = thePlayer.GetAttributeValue('runeword1_yrden_duration');
  3363.                     action.AddEffectInfo(EET_Slowdown, attribute.valueAdditive);
  3364.                     action.SetProcessBuffsIfNoDamage(true);
  3365.                     attackAction.SetApplyBuffsIfParried(true);
  3366.                     break;
  3367.                 default:       
  3368.                     break;
  3369.             }
  3370.         }
  3371.        
  3372.        
  3373.         if( playerAttacker && actorVictim && (W3PlayerWitcher)playerAttacker && GetWitcherPlayer().IsMutationActive( EPMT_Mutation9 ) && (W3BoltProjectile)action.causer )
  3374.         {
  3375.             maxHealth = actorVictim.GetMaxHealth();
  3376.             currHealth = actorVictim.GetHealth();
  3377.            
  3378.            
  3379.             if( AbsF( maxHealth - currHealth ) < 1.f )
  3380.             {
  3381.                 theGame.GetDefinitionsManager().GetAbilityAttributeValue('Mutation9', 'health_reduction', min, max);
  3382.                 actorVictim.ForceSetStat( actorVictim.GetUsedHealthType(), maxHealth * ( 1 - min.valueMultiplicative ) );
  3383.             }
  3384.            
  3385.            
  3386.             action.AddEffectInfo( EET_KnockdownTypeApplicator, 0.1f, , , , 1.f );
  3387.         }
  3388.     }
  3389. }
  3390.  
  3391. exec function ForceDismember( b: bool, optional chance : int, optional n : name, optional e : bool )
  3392. {
  3393.     var temp : CR4Player;
  3394.    
  3395.     temp = thePlayer;
  3396.     temp.forceDismember = b;
  3397.     temp.forceDismemberName = n;
  3398.     temp.forceDismemberChance = chance;
  3399.     temp.forceDismemberExplosion = e;
  3400. }
  3401.  
  3402. exec function ForceFinisher( b: bool, optional n : name, optional rightStance : bool )
  3403. {
  3404.     var temp : CR4Player;
  3405.    
  3406.     temp = thePlayer;
  3407.     temp.forcedStance = rightStance;
  3408.     temp.forceFinisher = b;
  3409.     temp.forceFinisherAnimName = n;
  3410. }
  3411.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement