1 using System.Collections.Generic;
10 namespace Loot.Modifiers.WeaponModifiers
17 private static readonly (
int type,
int time,
float chance)[] BuffPairs =
19 (BuffID.Confused, 100, 1f),
20 (BuffID.CursedInferno, 100, 1f),
21 (BuffID.Frostburn, 100, 1f),
22 (BuffID.OnFire, 100, 1f),
23 (BuffID.Poisoned, 100, 1f),
24 (BuffID.Ichor, 100, 1f),
27 private readonly
int _len = BuffPairs.GetLength(0);
29 public int GetRolledIndex() => _index;
30 private int _index = -1;
32 public override void NetReceive(Item item, BinaryReader reader)
34 base.NetReceive(item, reader);
35 _index = reader.ReadInt32();
36 _timeScaleFactor = reader.ReadSingle();
39 public override void NetSend(Item item, BinaryWriter writer)
41 base.NetSend(item, writer);
43 writer.Write(_timeScaleFactor);
46 public override void Save(Item item, TagCompound tag)
49 tag.Add(
"_index", _index);
50 tag.Add(
"_timeScaleFactor", _timeScaleFactor);
53 public override void Load(Item item, TagCompound tag)
56 _index = tag.GetAsInt(
"_index");
58 if (tag.ContainsKey(
"_timeScaleFactor"))
60 _timeScaleFactor = tag.GetAsShort(
"_timeScaleFactor");
61 if (_timeScaleFactor <= 0f) RollTimeScaleFactor();
65 RollTimeScaleFactor();
71 _timeScaleFactor = (0.5f + Main.rand.NextFloat() * (0.25f)) + Properties.Power / 100f;
76 base.Roll(ctx, rolledModifiers);
80 var similarModsBuffTypes = rolledModifiers.Where(x => x is
RandomDebuff).Cast<RandomDebuff>().Select(x => x.BuffType);
81 var rollableBuffTypes = BuffPairs.Select(x => x.type).Except(similarModsBuffTypes);
82 int randBuffIndex = Main.rand.Next(rollableBuffTypes.Count());
83 _index = BuffPairs.ToList().FindIndex(x => x.type == rollableBuffTypes.ElementAt(randBuffIndex));
84 RollTimeScaleFactor();
90 return base.PostRoll(ctx, rolledModifiers)
94 .All(x => x?.GetRolledIndex() != _index);
97 private float _timeScaleFactor = 1f;
98 public override int BuffType => BuffPairs[_index].type;
99 public override int BuffTime => (int) (BuffPairs[_index].time * _timeScaleFactor);
100 public override float BuffInflictionChance => BuffPairs[_index].chance;
Defines a context in which a Modifier might be rolled Which fields are available (not null) depends o...
override void NetSend(Item item, BinaryWriter writer)
override void NetReceive(Item item, BinaryReader reader)
override void Roll(ModifierContext ctx, IEnumerable< Modifier > rolledModifiers)
Allows modders to do something when the modifier is rolled in the given context The passed rolledModi...
void RollTimeScaleFactor()
override bool PostRoll(ModifierContext ctx, IEnumerable< Modifier > rolledModifiers)
Returns if the modifier will actually be added after it is rolled. This is called after Roll is calle...
Defines a modifier that can inflict a debuff, applicable for weapons
override void Load(Item item, TagCompound tag)
Allows modder to do custom loading here Use the given TC to pull data you saved using Save(Item...
override void Save(Item item, TagCompound tag)
Allows modder to do custom saving here Use the given TC to put data you want to save, which can be loaded using Load(Item,TagCompound)