Cleaned up a bit of the Derelict Cyborg code.

This commit is contained in:
The Canned One
2024-10-01 10:02:25 +02:00
parent eaa6017ada
commit 834b6ebaaa
7 changed files with 93 additions and 111 deletions

View File

@@ -60,108 +60,108 @@ public sealed class IonStormSystem : EntitySystem
[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))
// 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)
{
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();
if (law.Order < baseOrder)
baseOrder = law.Order;
}
// 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)
{
if (law.Order < baseOrder)
baseOrder = law.Order;
}
_robustRandom.Shuffle(laws.Laws);
// change order based on shuffled position
for (int i = 0; i < laws.Laws.Count; i++)
{
laws.Laws[i].Order = baseOrder + i;
}
}
// 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);
}
// generate a new law...
var newLaw = GenerateLaw();
// 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()
{
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;
_robustRandom.Shuffle(laws.Laws);
// change order based on shuffled position
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].Order = baseOrder + i;
}
}
//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()}");
// 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);
}
// laws unique to this silicon, dont use station laws anymore
EnsureComp<SiliconLawProviderComponent>(ent);
var ev = new IonStormLawsEvent(laws);
RaiseLocalEvent(ent, ref ev);
// generate a new law...
var newLaw = GenerateLaw();
// 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()
{
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;
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();
}
}
// 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);
}
// for your own sake direct your eyes elsewhere

View File

@@ -6,7 +6,7 @@ using Content.Shared.Silicons.Laws;
namespace Content.Server.Silicons.Laws;
/// <summary>
/// This handles running the ion storm event on specific entities when spawned in.
/// This handles running the ion storm event a on specific entity when that entity is spawned in.
/// </summary>
public sealed class StartIonStormedSystem : EntitySystem
{
@@ -31,7 +31,7 @@ public sealed class StartIonStormedSystem : EntitySystem
for (int currentIonStorm = 0; currentIonStorm < component.IonStormAmount; currentIonStorm++)
{
_ionStorm.IonStormTarget(uid, lawBound, xform, target, null, true, true);
_ionStorm.IonStormTarget(uid, lawBound, xform, target, null, true, false);
}
var laws = _siliconLaw.GetLaws(uid, lawBound);

View File

@@ -1,10 +1,8 @@
using Content.Shared.Random;
using Robust.Shared.Prototypes;
namespace Content.Shared.Silicons.Laws.Components;
/// <summary>
/// Runs the IonStormSystem on an entity IonStormAmount times.
/// Applies law altering ion storms on a specific entity IonStormAmount times when the entity is spawned.
/// </summary>
[RegisterComponent]
public sealed partial class StartIonStormedComponent : Component

View File

@@ -0,0 +1 @@
derelict-cyborg-round-end-agent-name = derelict cyborg

View File

@@ -1,4 +0,0 @@
derelict-cyborg-round-end-agent-name = derelict cyborg
derelict-cyborg-role-greeting =
You are a cyborg that has been lost in space for many years that has now drifted close to a space station. You can use your fire extinguisher and GPS to get board the station. Remember to follow your laws.

View File

@@ -332,16 +332,6 @@
- AllAccess #Randomized access would be fun. AllAccess is the best i can think of right now that does make it too hard for it to enter the station or navigate it..
- type: AccessReader
access: [["Command"], ["Research"]]
- type: IntrinsicRadioTransmitter
channels:
- Binary
- Common
- Science
- type: ActiveRadio
channels:
- Binary
- Common
- Science
- type: StartIonStormed
ionStormAmount: 5
- type: IonStormTarget

View File

@@ -564,9 +564,6 @@
- type: AntagSelection
agentName: derelict-cyborg-round-end-agent-name
definitions:
# briefing:
# text: derelict-cyborg-role-greetin
# color: Blue
- spawnerPrototype: SpawnPointGhostDerelictCyborg
min: 1
max: 1