[ValidatePrototypeId<DatasetPrototype>]
private const string Foods = "IonStormFoods";
- public void IonStormTarget(EntityUid ent, SiliconLawBoundComponent lawBound, TransformComponent xform, IonStormTargetComponent target, EntityUid? chosenStation, bool ignoreStation = false, bool DoNotAdminlog = false)
+ public void IonStormTarget(EntityUid ent, SiliconLawBoundComponent lawBound, TransformComponent xform, IonStormTargetComponent target, EntityUid? chosenStation, bool ignoreStation = false, bool adminlog = true)
{
- // only affect law holders on the station unless ignoreStation is true.
- if (CompOrNull<StationMemberComponent>(xform.GridUid)?.Station != chosenStation && !ignoreStation)
- return;
+ // only affect law holders on the station unless ignoreStation is true.
+ if (CompOrNull<StationMemberComponent>(xform.GridUid)?.Station != chosenStation && !ignoreStation)
+ return;
- if (!_robustRandom.Prob(target.Chance))
- return;
+ if (!_robustRandom.Prob(target.Chance))
+ return;
- var laws = _siliconLaw.GetLaws(ent, lawBound);
- if (laws.Laws.Count == 0)
- return;
+ var laws = _siliconLaw.GetLaws(ent, lawBound);
+ if (laws.Laws.Count == 0)
+ return;
- // try to swap it out with a random lawset
- if (_robustRandom.Prob(target.RandomLawsetChance))
- {
- var lawsets = _proto.Index<WeightedRandomPrototype>(target.RandomLawsets);
- var lawset = lawsets.Pick(_robustRandom);
- laws = _siliconLaw.GetLawset(lawset);
- }
- else
+ // try to swap it out with a random lawset
+ if (_robustRandom.Prob(target.RandomLawsetChance))
+ {
+ var lawsets = _proto.Index<WeightedRandomPrototype>(target.RandomLawsets);
+ var lawset = lawsets.Pick(_robustRandom);
+ laws = _siliconLaw.GetLawset(lawset);
+ }
+ else
+ {
+ // clone it so not modifying stations lawset
+ laws = laws.Clone();
+ }
+
+ // shuffle them all
+ if (_robustRandom.Prob(target.ShuffleChance))
+ {
+ // hopefully work with existing glitched laws if there are multiple ion storms
+ FixedPoint2 baseOrder = FixedPoint2.New(1);
+ foreach (var law in laws.Laws)
{
- // clone it so not modifying stations lawset
- laws = laws.Clone();
+ if (law.Order < baseOrder)
+ baseOrder = law.Order;
}
- // shuffle them all
- if (_robustRandom.Prob(target.ShuffleChance))
+ _robustRandom.Shuffle(laws.Laws);
+
+ // change order based on shuffled position
+ for (int i = 0; i < laws.Laws.Count; i++)
{
- // hopefully work with existing glitched laws if there are multiple ion storms
- FixedPoint2 baseOrder = FixedPoint2.New(1);
- foreach (var law in laws.Laws)
- {
- if (law.Order < baseOrder)
- baseOrder = law.Order;
- }
+ laws.Laws[i].Order = baseOrder + i;
+ }
+ }
- _robustRandom.Shuffle(laws.Laws);
+ // see if we can remove a random law
+ if (laws.Laws.Count > 0 && _robustRandom.Prob(target.RemoveChance))
+ {
+ var i = _robustRandom.Next(laws.Laws.Count);
+ laws.Laws.RemoveAt(i);
+ }
- // change order based on shuffled position
- for (int i = 0; i < laws.Laws.Count; i++)
- {
- laws.Laws[i].Order = baseOrder + i;
- }
- }
+ // generate a new law...
+ var newLaw = GenerateLaw();
- // see if we can remove a random law
- if (laws.Laws.Count > 0 && _robustRandom.Prob(target.RemoveChance))
+ // see if the law we add will replace a random existing law or be a new glitched order one
+ if (laws.Laws.Count > 0 && _robustRandom.Prob(target.ReplaceChance))
+ {
+ var i = _robustRandom.Next(laws.Laws.Count);
+ laws.Laws[i] = new SiliconLaw()
{
- var i = _robustRandom.Next(laws.Laws.Count);
- laws.Laws.RemoveAt(i);
- }
+ LawString = newLaw,
+ Order = laws.Laws[i].Order
+ };
+ }
+ else
+ {
+ laws.Laws.Insert(0, new SiliconLaw
+ {
+ LawString = newLaw,
+ Order = -1,
+ LawIdentifierOverride = Loc.GetString("ion-storm-law-scrambled-number", ("length", _robustRandom.Next(5, 10)))
+ });
+ }
+
+ // sets all unobfuscated laws' indentifier in order from highest to lowest priority
+ // This could technically override the Obfuscation from the code above, but it seems unlikely enough to basically never happen
+ int orderDeduction = -1;
- // generate a new law...
- var newLaw = GenerateLaw();
+ for (int i = 0; i < laws.Laws.Count; i++)
+ {
+ string notNullIdentifier = laws.Laws[i].LawIdentifierOverride ?? (i - orderDeduction).ToString();
- // see if the law we add will replace a random existing law or be a new glitched order one
- if (laws.Laws.Count > 0 && _robustRandom.Prob(target.ReplaceChance))
+ if (notNullIdentifier.Any(char.IsSymbol))
{
- var i = _robustRandom.Next(laws.Laws.Count);
- laws.Laws[i] = new SiliconLaw()
- {
- LawString = newLaw,
- Order = laws.Laws[i].Order
- };
+ orderDeduction += 1;
}
else
{
- laws.Laws.Insert(0, new SiliconLaw
- {
- LawString = newLaw,
- Order = -1,
- LawIdentifierOverride = Loc.GetString("ion-storm-law-scrambled-number", ("length", _robustRandom.Next(5, 10)))
- });
- }
-
- // sets all unobfuscated laws' indentifier in order from highest to lowest priority
- // This could technically override the Obfuscation from the code above, but it seems unlikely enough to basically never happen
- int orderDeduction = -1;
-
- for (int i = 0; i < laws.Laws.Count; i++)
- {
- string notNullIdentifier = laws.Laws[i].LawIdentifierOverride ?? (i - orderDeduction).ToString();
-
- if (notNullIdentifier.Any(char.IsSymbol))
- {
- orderDeduction += 1;
- }
- else
- {
- laws.Laws[i].LawIdentifierOverride = (i - orderDeduction).ToString();
- }
+ laws.Laws[i].LawIdentifierOverride = (i - orderDeduction).ToString();
}
+ }
- //DoNotAdminlog is used to prevent adminlog spam.
- if (!DoNotAdminlog)
- _adminLogger.Add(LogType.Mind, LogImpact.High, $"{ToPrettyString(ent):silicon} had its laws changed by an ion storm to {laws.LoggingString()}");
+ // adminlog is used to prevent adminlog spam.
+ if (adminlog)
+ _adminLogger.Add(LogType.Mind, LogImpact.High, $"{ToPrettyString(ent):silicon} had its laws changed by an ion storm to {laws.LoggingString()}");
- // laws unique to this silicon, dont use station laws anymore
- EnsureComp<SiliconLawProviderComponent>(ent);
- var ev = new IonStormLawsEvent(laws);
- RaiseLocalEvent(ent, ref ev);
+ // laws unique to this silicon, dont use station laws anymore
+ EnsureComp<SiliconLawProviderComponent>(ent);
+ var ev = new IonStormLawsEvent(laws);
+ RaiseLocalEvent(ent, ref ev);
}
// for your own sake direct your eyes elsewhere