-
Notifications
You must be signed in to change notification settings - Fork 450
Undo Accidental Revert Of Rampant Brand Intelligence #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
VMSolidus
merged 3 commits into
Simple-Station:master
from
VMSolidus:Unrevert-Rampant-Brand-Intelligence
Oct 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,179 @@ | ||
| using System.Numerics; | ||
| using Content.Server.Antag.Mimic; | ||
| using Content.Server.GameTicking.Components; | ||
| using Content.Server.Chat.Systems; | ||
| using Content.Server.GameTicking.Rules; | ||
| using Content.Server.GameTicking.Rules.Components; | ||
| using Content.Server.GameTicking.Components; | ||
| using Content.Server.NPC.Systems; | ||
| using Content.Server.Station.Systems; | ||
| using Content.Server.GameTicking; | ||
| using Content.Shared.VendingMachines; | ||
| using Robust.Shared.Map; | ||
| using Robust.Shared.Prototypes; | ||
| using Robust.Shared.Random; | ||
| using Robust.Server.GameObjects; | ||
| using Robust.Shared.Physics.Systems; | ||
| using System.Linq; | ||
| using Robust.Shared.Physics; | ||
| using Content.Shared.Movement.Components; | ||
| using Content.Shared.Damage; | ||
| using Content.Server.NPC.HTN; | ||
| using Content.Server.NPC; | ||
| using Content.Shared.Weapons.Melee; | ||
| using Content.Server.Advertise.EntitySystems; | ||
| using Content.Server.Advertise.Components; | ||
| using Content.Server.Power.Components; | ||
| using Content.Shared.CombatMode; | ||
|
|
||
| namespace Content.Server.Antag; | ||
|
|
||
| public sealed class MobReplacementRuleSystem : GameRuleSystem<MobReplacementRuleComponent> | ||
| { | ||
| [Dependency] private readonly IRobustRandom _random = default!; | ||
| [Dependency] private readonly StationSystem _station = default!; | ||
| [Dependency] private readonly GameTicker _gameTicker = default!; | ||
| [Dependency] private readonly ChatSystem _chat = default!; | ||
| [Dependency] private readonly IPrototypeManager _prototype = default!; | ||
| [Dependency] private readonly IComponentFactory _componentFactory = default!; | ||
| [Dependency] private readonly SharedPhysicsSystem _physics = default!; | ||
| [Dependency] private readonly NpcFactionSystem _npcFaction = default!; | ||
| [Dependency] private readonly NPCSystem _npc = default!; | ||
| [Dependency] private readonly TransformSystem _transform = default!; | ||
| [Dependency] private readonly AdvertiseSystem _advertise = default!; | ||
|
|
||
|
|
||
| protected override void Started(EntityUid uid, MobReplacementRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args) | ||
| { | ||
| base.Started(uid, component, gameRule, args); | ||
|
|
||
| var query = AllEntityQuery<VendingMachineComponent, TransformComponent>(); | ||
| var spawns = new List<(EntityUid Entity, EntityCoordinates Coordinates)>(); | ||
| var stations = _gameTicker.GetSpawnableStations(); | ||
|
|
||
| while (query.MoveNext(out var vendingUid, out _, out var xform)) | ||
| { | ||
| if (!_random.Prob(component.Chance)) | ||
| var ownerStation = _station.GetOwningStation(vendingUid); | ||
|
|
||
| if (ownerStation == null | ||
| || ownerStation != stations[0]) | ||
| continue; | ||
|
|
||
| // Make sure that we aren't running this on something that is already a mimic | ||
| if (HasComp<CombatModeComponent>(vendingUid)) | ||
| continue; | ||
|
|
||
| spawns.Add((vendingUid, xform.Coordinates)); | ||
| } | ||
|
|
||
| foreach (var entity in spawns) | ||
| if (spawns == null) | ||
| { | ||
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //WTF THE STATION DOESN'T EXIST! WE MUST BE IN A TEST! QUICK, PUT A MIMIC AT 0,0!!! | ||
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Spawn(component.Proto, new EntityCoordinates(uid, new Vector2(0, 0))); | ||
| } | ||
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else | ||
| { | ||
| var coordinates = entity.Coordinates; | ||
| Del(entity.Entity); | ||
| // This is intentionally not clamped. If a server host wants to replace every vending machine in the entire station with a mimic, who am I to stop them? | ||
| var k = MathF.MaxMagnitude(component.NumberToReplace, 1); | ||
| while (k > 0 && spawns != null && spawns.Count > 0) | ||
VMSolidus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| if (k > 1) | ||
| { | ||
| var spawnLocation = _random.PickAndTake(spawns); | ||
| BuildAMimicWorkshop(spawnLocation.Entity, component); | ||
| } | ||
| else | ||
| { | ||
| BuildAMimicWorkshop(spawns[0].Entity, component); | ||
| } | ||
VMSolidus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (k == MathF.MaxMagnitude(component.NumberToReplace, 1) | ||
| && component.DoAnnouncement) | ||
| _chat.DispatchStationAnnouncement(stations[0], Loc.GetString("station-event-rampant-intelligence-announcement"), playDefaultSound: true, | ||
| colorOverride: Color.Red, sender: "Central Command"); | ||
VMSolidus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| k--; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// It's like Build a Bear, but MURDER | ||
| /// </summary> | ||
| /// <param name="uid"></param> | ||
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public void BuildAMimicWorkshop(EntityUid uid, MobReplacementRuleComponent component) | ||
| { | ||
| var metaData = MetaData(uid); | ||
| var vendorPrototype = metaData.EntityPrototype; | ||
| var mimicProto = _prototype.Index<EntityPrototype>(component.Proto); | ||
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var vendorComponents = vendorPrototype?.Components.Keys | ||
| .Where(n => n != "Transform" && n != "MetaData") | ||
| .Select(name => (name, _componentFactory.GetRegistration(name).Type)) | ||
| .ToList() ?? new List<(string name, Type type)>(); | ||
|
|
||
| Spawn(component.Proto, coordinates); | ||
| var mimicComponents = mimicProto?.Components.Keys | ||
| .Where(n => n != "Transform" && n != "MetaData") | ||
| .Select(name => (name, _componentFactory.GetRegistration(name).Type)) | ||
| .ToList() ?? new List<(string name, Type type)>(); | ||
|
|
||
| foreach (var name in mimicComponents.Except(vendorComponents)) | ||
| { | ||
| var newComponent = _componentFactory.GetComponent(name.name); | ||
| EntityManager.AddComponent(uid, newComponent); | ||
| } | ||
|
|
||
| var xform = Transform(uid); | ||
| if (xform.Anchored) | ||
| _transform.Unanchor(uid, xform); | ||
|
|
||
| SetupMimicNPC(uid, component); | ||
|
|
||
| if (TryComp<AdvertiseComponent>(uid, out var vendor) | ||
| && component.VendorModify) | ||
| SetupMimicVendor(uid, component, vendor); | ||
| } | ||
| /// <summary> | ||
| /// This handles getting the entity ready to be a hostile NPC | ||
| /// </summary> | ||
| /// <param name="uid"></param> | ||
| /// <param name="component"></param> | ||
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private void SetupMimicNPC(EntityUid uid, MobReplacementRuleComponent component) | ||
| { | ||
| _physics.SetBodyType(uid, BodyType.KinematicController); | ||
| _npcFaction.AddFaction(uid, "SimpleHostile"); | ||
|
|
||
| var melee = EnsureComp<MeleeWeaponComponent>(uid); | ||
| melee.Angle = 0; | ||
| DamageSpecifier dspec = new() | ||
| { | ||
| DamageDict = new() | ||
| { | ||
| { "Blunt", component.MimicMeleeDamage } | ||
VMSolidus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| }; | ||
| melee.Damage = dspec; | ||
|
|
||
| var movementSpeed = EnsureComp<MovementSpeedModifierComponent>(uid); | ||
| (movementSpeed.BaseSprintSpeed, movementSpeed.BaseWalkSpeed) = (component.MimicMoveSpeed, component.MimicMoveSpeed); | ||
VMSolidus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| var htn = EnsureComp<HTNComponent>(uid); | ||
| htn.RootTask = new HTNCompoundTask() { Task = component.MimicAIType }; | ||
| htn.Blackboard.SetValue(NPCBlackboard.NavSmash, component.MimicSmashGlass); | ||
| _npc.WakeNPC(uid, htn); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Handling specific interactions with vending machines | ||
| /// </summary> | ||
| /// <param name="uid"></param> | ||
| /// <param name="mimicComponent"></param> | ||
| /// <param name="vendorComponent"></param> | ||
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private void SetupMimicVendor(EntityUid uid, MobReplacementRuleComponent mimicComponent, AdvertiseComponent vendorComponent) | ||
| { | ||
| vendorComponent.MinimumWait = 5; | ||
| vendorComponent.MaximumWait = 15; | ||
| _advertise.SayAdvertisement(uid, vendorComponent); | ||
|
|
||
| if (TryComp<ApcPowerReceiverComponent>(uid, out var aPC)) | ||
| aPC.NeedsPower = false; | ||
VMSolidus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
VMSolidus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.