Advertisement
Guest User

UPMod Bug Fixes #1,2,3

a guest
Jul 16th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.35 KB | None | 0 0
  1.  [ModifiesType]
  2.     public class mod_Health : Health
  3.     {
  4.         [ModifiesMember("ApplyDamageDirectly")]
  5.         public void mod_ApplyDamageDirectly(float amount, DamagePacket.DamageType damageType, GameObject source, StatusEffect sourceEffect)
  6.         {
  7.             if (this.Dead || this.Unconscious || !this.CanBeTargeted)
  8.             {
  9.                 return;
  10.             }
  11.             Health health = null;
  12.             if (amount < 0f)
  13.             {
  14.                 amount = -amount;
  15.                 Debug.LogWarning("Script Error: DoDamage(float) was passed a negative value. Damage should be positive.", base.gameObject);
  16.             }
  17.             if (source != null)
  18.             {
  19.                 health = source.GetComponent<Health>();
  20.                 CharacterStats component = source.GetComponent<CharacterStats>();
  21.                 if (component != null)
  22.                 {
  23.                     // ORIGINAL:
  24.                     // amount *= component.StatDamageHealMultiplier;
  25.                     // amount *= component.GetDifficultyDamageMultiplier(this);
  26.  
  27.                     // PATCH START:
  28.                     // RELATED BUGS: #2, #3
  29.                     float dmgCoef = component.StatDamageHealMultiplier;
  30.                    
  31.                     if (sourceEffect != null && sourceEffect.IsDOT)
  32.                     {
  33.                         CharacterStats attackersStats = source.GetComponent<CharacterStats>();
  34.                         CharacterStats attackedCharacterStats = this.gameObject.GetComponent<CharacterStats>();
  35.  
  36.                         float elementalDamageCoef = System.Math.Max(1, attackersStats.GetBonusDamagePerType(damageType));
  37.                         float raceSlayerDamageCoef = System.Math.Max(1, attackersStats.GetBonusDamagePerRaceMultiplier(attackedCharacterStats.CharacterRace));
  38.  
  39.                         float spiritSlayerDamageCoef = System.Math.Max(1, attackersStats.GetBonusDamagePerRaceMultiplier(CharacterStats.Race.Spirit));
  40.                         float vesselSlayerDamageCoef = System.Math.Max(1, attackersStats.GetBonusDamagePerRaceMultiplier(CharacterStats.Race.Vessel));                        
  41.  
  42.                         // non raw dots should be affected by elemental talents
  43.                         if (damageType != DamagePacket.DamageType.Raw)
  44.                         {
  45.                             dmgCoef += elementalDamageCoef - 1;
  46.                         }
  47.  
  48.                         // non fixed dots should be affected by racial slayer talents
  49.                         bool isWounding = "WeaponOrShield".Equals(sourceEffect.AbilityType.ToString(), System.StringComparison.OrdinalIgnoreCase);
  50.                         bool isWoundingShot = sourceEffect.Origin != null ? sourceEffect.Origin.name.ToLower().IndexOf("woundingshot") >= 0 : false;
  51.                         bool isEnduringFlames = sourceEffect.Origin != null ? sourceEffect.Origin.name.ToLower().IndexOf("flamesofdevotion") >= 0 : false;
  52.                         bool isFixedDoT = isWounding || isWoundingShot || isEnduringFlames;
  53.  
  54.                         // there are several 'fixed' dots whose damage is a percentage of weapon damage, and thus should not be affected (because these talents have already increased hit damage):
  55.                         // wounding (from tidefall, drawn-in-spring and persistence) - is of [WeaponOrShield] type
  56.                         // wounding shot - is of [Ability] type
  57.                         // enduring flames - is of [Talent] type
  58.  
  59.                         if (!isFixedDoT)
  60.                         {
  61.                             dmgCoef += raceSlayerDamageCoef - 1;
  62.                         }
  63.                     }
  64.  
  65.                     amount *= dmgCoef;
  66.                     amount *= component.GetDifficultyDamageMultiplier(this);
  67.                     // PATCH END
  68.  
  69.                 }
  70.             }
  71.             if (this.m_stats != null)
  72.             {
  73.                 amount = this.m_stats.AdjustDamageByDTDR(amount, damageType, null, source, 0.25f);
  74.             }
  75.  
  76.             float num = 100f;
  77.             if (this.m_stats)
  78.             {
  79.                 num = this.m_stats.Stamina;
  80.             }
  81.             if (this.m_currentStamina >= num)
  82.             {
  83.                 this.m_canRegenTimer = CharacterStats.StaminaRechargeDelay;
  84.             }
  85.             float currentStamina = this.m_currentStamina;
  86.             float currentHealth = this.m_currentHealth;
  87.             if (this.TakesDamage && !Health.NoDamage)
  88.             {
  89.                 if (num > 0f)
  90.                 {
  91.                     this.m_currentStamina -= amount;
  92.                     if (!this.m_isAnimalCompanion)
  93.                     {
  94.                         this.m_currentHealth -= amount;
  95.                     }
  96.                 }
  97.                 else if (!this.m_isAnimalCompanion)
  98.                 {
  99.                     this.m_currentHealth -= amount;
  100.                 }
  101.                 this.TryPlayInjuredSound(currentStamina, currentHealth);
  102.             }
  103.             if (this.Unconscious && !this.Dead)
  104.             {
  105.                 this.AddInjury(damageType);
  106.                 this.HandleUnconscious(source);
  107.             }
  108.             if (this.ShowDead)
  109.             {
  110.                 if (this.CanDie)
  111.                 {
  112.                     this.m_currentHealth = 0f;
  113.                     this.HandleDeath(source);
  114.                     if (health != null && health.OnKill != null)
  115.                     {
  116.                         GameEventArgs gameEventArgs = new GameEventArgs();
  117.                         gameEventArgs.Type = GameEventType.Killed;
  118.                         gameEventArgs.GameObjectData = new GameObject[1];
  119.                         gameEventArgs.GameObjectData[0] = base.gameObject;
  120.                         health.OnKill(source, gameEventArgs);
  121.                     }
  122.                 }
  123.                 else
  124.                 {
  125.                     this.m_currentHealth = 1f;
  126.                 }
  127.             }
  128.             GameEventArgs gameEventArgs2 = new GameEventArgs();
  129.             gameEventArgs2.Type = GameEventType.Damaged;
  130.             gameEventArgs2.FloatData = new float[2];
  131.             gameEventArgs2.FloatData[0] = amount;
  132.             gameEventArgs2.FloatData[1] = currentStamina;
  133.             gameEventArgs2.GameObjectData = new GameObject[1];
  134.             gameEventArgs2.GameObjectData[0] = source;
  135.             gameEventArgs2.GenericData = new object[2];
  136.             gameEventArgs2.GenericData[0] = new DamageInfo(base.gameObject, amount, null)
  137.             {
  138.                 DamageType = damageType
  139.             };
  140.             gameEventArgs2.GenericData[1] = sourceEffect;
  141.             if (this.OnDamaged != null)
  142.             {
  143.                 this.OnDamaged(base.gameObject, gameEventArgs2);
  144.             }
  145.             if (health != null && health.OnDamageDealt != null)
  146.             {
  147.                 health.OnDamageDealt(base.gameObject, gameEventArgs2);
  148.             }
  149.             UIHealthstringManager.Instance.ShowNumber(amount, base.gameObject);
  150.             if (sourceEffect == null || sourceEffect.Params.IsHostile)
  151.             {
  152.                 ScriptEvent component2 = base.GetComponent<ScriptEvent>();
  153.                 if (component2)
  154.                 {
  155.                     component2.ExecuteScript(ScriptEvent.ScriptEvents.OnAttacked);
  156.                     if (this.m_attackedByPlayer)
  157.                     {
  158.                         component2.ExecuteScript(ScriptEvent.ScriptEvents.OnAttackedByParty);
  159.                     }
  160.                 }
  161.             }
  162.  
  163.             // PATCH START:
  164.             // RELATED BUGS: #1
  165.             // TASK: DoT damage should be registered in personal stat tracker (personal records) as well
  166.             if (PartyHelper.IsPartyMember(source))
  167.             {
  168.                 CharacterStats attStats = source.GetComponent<CharacterStats>();
  169.                 PartyMemberAI memberAI = source.GetComponent<PartyMemberAI>();                
  170.  
  171.                 if (memberAI != null)
  172.                 {                    
  173.                     DamageInfo dmgInfo = new DamageInfo(base.gameObject, amount, null);
  174.                     dmgInfo.DamageType = damageType;
  175.                     dmgInfo.FinalAdjustedDamage = amount;
  176.  
  177.                     memberAI.StatsOnHit(attStats.gameObject, new CombatEventArgs(dmgInfo, source, attStats.gameObject));
  178.                 }
  179.             }
  180.             // PATCH END
  181.         }
  182.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement