Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
ModifierPoolMechanism.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using System.Linq;
3 using Loot.Api.Core;
4 using Loot.Api.Loaders;
5 using Terraria.Utilities;
6 
7 namespace Loot.Api.Mechanism
8 {
9  static class ModifierPoolMechanism
10  {
11  private static IEnumerable<ModifierPool> Pools => ContentLoader.ModifierPool.Pools;
12 
13  public static ModifierPool GetPool(ModifierContext context)
14  {
15  if (context.Pool != null) return context.Pool;
16  var set = context.PoolSet ?? Pools.Where(x => x._CanRoll(context));
17  return GetWeightedPool(set);
18  }
19 
20  private static ModifierPool GetWeightedPool(IEnumerable<ModifierPool> set)
21  {
22  var wr = new WeightedRandom<ModifierPool>();
23  foreach (var m in set.Where(x => x.Type > 0))
24  {
25  wr.Add(m, m.RollChance);
26  }
27 
28  var mod = wr.Get();
29  return (ModifierPool)mod?.Clone();
30  }
31  }
32 }
virtual void Clone(ref ModifierPool clone)
Allows modders to do custom cloning Happens after default cloning
Defines a context in which a Modifier might be rolled Which fields are available (not null) depends o...
List< ModifierPool > PoolSet
static ModifierPoolContent ModifierPool
static ModifierPool GetPool(ModifierContext context)
Defines a modifier pool. A modifier pool holds a certain amount of effects in an array It allows to r...
Definition: ModifierPool.cs:37
static ModifierPool GetWeightedPool(IEnumerable< ModifierPool > set)
This class holds all Content holders of this mod You can use this to access content loaded into the m...