Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
SurvivalChance.cs
Go to the documentation of this file.
1 using System;
2 using Loot.Api.Attributes;
3 using Loot.Api.Core;
4 using Loot.Api.Delegators;
5 using Loot.Modifiers.Base;
6 using Terraria;
7 using Terraria.DataStructures;
8 
9 namespace Loot.Modifiers.EquipModifiers.Defensive
10 {
12  {
13  public float SurvivalChance; // Chance to survive lethal blow
14  public static readonly float MAX_SURVIVAL_CHANCE = 0.5f;
15 
16  public override void ResetEffects()
17  {
18  SurvivalChance = 0f;
19  }
20 
21  [AutoDelegation("OnPreKill")]
23  private bool SurviveEvent(double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
24  {
25  if (Main.rand.NextFloat() < Math.Min(SurvivalChance, MAX_SURVIVAL_CHANCE))
26  {
27  player.statLife = 1;
28  return false;
29  }
30 
31  return true;
32  }
33  }
34 
35  [UsesEffect(typeof(SurvivalEffect))]
37  {
38  // TODO easier tooltip templating
40  {
41  return base.GetTooltip()
42  .WithPositive($"+{Properties.RoundedPower}% chance to survive lethal blows"
43  + $"{(Main.LocalPlayer.GetModPlayer<ModifierDelegatorPlayer>().GetEffect<SurvivalEffect>().SurvivalChance >= SurvivalEffect.MAX_SURVIVAL_CHANCE ? $" (cap reached: {SurvivalEffect.MAX_SURVIVAL_CHANCE * 100f}%)" : "")}"
44  );
45  }
46 
48  {
49  return base.GetModifierProperties(item)
50  .WithMaxMagnitude(5f)
51  .WithRollChance(0.333f);
52  }
53 
54  public override void UpdateEquip(Item item, Player player)
55  {
56  ModifierDelegatorPlayer.GetPlayer(player).GetEffect<SurvivalEffect>().SurvivalChance += Properties.RoundedPower / 100f;
57  }
58  }
59 }
bool SurviveEvent(double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
The ModifierPropertiesBuilder implements the builder pattern for ModifierProperties It provides a str...
This attribute may be used to skip usage of AttachDelegations and DetachDelegations Which is a cumber...
A ModifierEffect signifies the effect of a modifier on a player It should house the implementation...
Defines a modifier that can roll on an equip item (armor or accessory) These modifiers will have 60% ...
DelegationPrioritization
Specify when you want your delegation to happen in the chain
static ModifierDelegatorPlayer GetPlayer(Player player)
override ModifierProperties.ModifierPropertiesBuilder GetModifierProperties(Item item)
Defines the properties of a modifier
override void UpdateEquip(Item item, Player player)
Defines a tooltip line of a modifier A modifier can have multiple lines
override void ResetEffects()
Automatically called when the ModPlayer does its ResetEffects Also automatically called when the dele...
override ModifierTooltipLine.ModifierTooltipBuilder GetTooltip()
Holds player-entity data and handles it