-
Notifications
You must be signed in to change notification settings - Fork 244
[ADD] Аллергии #2571
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
Open
Rorkh
wants to merge
16
commits into
AdventureTimeSS14:master
Choose a base branch
from
Rorkh:allergies-feature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+951
−12
Open
[ADD] Аллергии #2571
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
809d3dd
[ADD] Система аллергий
Rorkh fde50c2
[TWEAK] Трейт и конфигурация в компоненте
Rorkh 5c720d4
[TWEAK] YAML fix
Rorkh 09b25fc
[TWEAK] Swab popups
Rorkh 8d95223
[FIX] Clanker driven development
Rorkh 45fb046
Merge branch 'master' into allergies-feature
Rorkh bcb05c5
[ADD] Allergic stack and reactions
Rorkh 2d8fc6e
[FIX] Fixes and etc etc...
Rorkh c3a9801
[TWEAK] Снятие симптомов аллергии, баланс
Rorkh ef57367
Merge branch 'master' into allergies-feature
Rorkh a04c639
[FIX] Allergic reactions sort
Rorkh 0d9654a
[TWEAK] Документация, clanker-driven
Rorkh e8a204f
Merge branch 'allergies-feature' of https://github.com/Rorkh/space_st…
Rorkh b6a6edc
Update medicine.yml
Rorkh 0abf96b
Merge branch 'master' into allergies-feature
Schrodinger71 99856fa
Merge branch 'master' into allergies-feature
Darkiich 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
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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| using System.Linq; | ||
| using Content.Server.Body.Systems; | ||
| using Content.Shared.ADT.Body.Allergies; | ||
| using Content.Shared.Chemistry.Reagent; | ||
| using Content.Shared.Damage; | ||
| using Content.Shared.Damage.Prototypes; | ||
| using Content.Shared.EntityEffects.Effects; | ||
| using Robust.Shared.Prototypes; | ||
| using Robust.Shared.Random; | ||
|
|
||
| namespace Content.Server.ADT.Body; | ||
|
|
||
| public sealed class AllergicSystem : EntitySystem | ||
| { | ||
| [Dependency] private readonly IRobustRandom _random = default!; | ||
|
|
||
| [Dependency] private readonly IPrototypeManager _proto = default!; | ||
|
|
||
| private ProtoId<DamageGroupPrototype> _allergyDamageGroup = "Poison"; | ||
|
|
||
| private DamageTypePrototype? _allergyDamageTypeProto; | ||
|
|
||
| public override void Initialize() | ||
| { | ||
| base.Initialize(); | ||
|
|
||
| SubscribeLocalEvent<AllergicComponent, ComponentInit>(OnInit); | ||
| SubscribeLocalEvent<AllergicComponent, GetReagentEffectsEvent>(OnGetReagentEffects); | ||
|
|
||
| _allergyDamageTypeProto = _proto.Index<DamageTypePrototype>(_allergyDamageGroup); | ||
| } | ||
|
|
||
| private List<ProtoId<ReagentPrototype>> GetRandomAllergies(int min, int max) | ||
| { | ||
| int reagentsCount = _proto.Count<ReagentPrototype>(); | ||
|
|
||
| if (reagentsCount == 0) | ||
| return new(); | ||
|
|
||
| int safeMin = Math.Clamp(min, 0, reagentsCount); | ||
| int safeMax = Math.Clamp(max, safeMin, reagentsCount); | ||
| int allergiesCount = _random.Next(safeMin, safeMax + 1); | ||
|
|
||
| var picked = new HashSet<int>(); | ||
| while (picked.Count < allergiesCount) | ||
| { | ||
| picked.Add(_random.Next(reagentsCount)); | ||
| } | ||
|
|
||
| int index = 0; | ||
| List<ProtoId<ReagentPrototype>> allergies = new(); | ||
|
|
||
| foreach (var proto in _proto.EnumeratePrototypes<ReagentPrototype>()) | ||
| { | ||
| if (picked.Contains(index)) | ||
| allergies.Add(proto.ID); | ||
| index++; | ||
| } | ||
|
|
||
| return allergies; | ||
| } | ||
|
|
||
| public void OnInit(EntityUid uid, AllergicComponent component, ComponentInit args) | ||
| { | ||
| component.Triggers = GetRandomAllergies(component.Min, component.Max); | ||
| } | ||
|
|
||
| public void OnGetReagentEffects(EntityUid uid, AllergicComponent component, ref GetReagentEffectsEvent ev) | ||
| { | ||
| if (!component.Triggers.Contains(ev.Reagent.Prototype)) | ||
| return; | ||
|
|
||
| var damageSpecifier = new DamageSpecifier(_allergyDamageTypeProto!, 0.5); | ||
| var damageEffect = new HealthChange | ||
| { | ||
| Damage = damageSpecifier | ||
| }; | ||
|
|
||
| ev.Effects = ev.Effects.Append(damageEffect).ToArray(); | ||
| } | ||
| } |
172 changes: 172 additions & 0 deletions
172
Content.Server/ADT/Medical/EntitySystems/DiseaseDiagnoserSystem.cs
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 |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| using System.Linq; | ||
| using System.Text; | ||
| using Content.Server.Botany; | ||
| using Content.Server.Power.EntitySystems; | ||
| using Content.Shared.ADT.Medical; | ||
| using Content.Shared.Chemistry.Reagent; | ||
| using Content.Shared.Interaction; | ||
| using Content.Shared.Paper; | ||
| using Content.Shared.Popups; | ||
| using Content.Shared.Power; | ||
| using Robust.Shared.Audio.Systems; | ||
| using Robust.Shared.Containers; | ||
| using Robust.Shared.Prototypes; | ||
| using Robust.Shared.Timing; | ||
|
|
||
| namespace Content.Server.ADT.Medical.EntitySystems; | ||
|
|
||
| public sealed class DiseaseDiagnoserSystem : EntitySystem | ||
| { | ||
| [Dependency] private readonly IGameTiming _timing = default!; | ||
| [Dependency] private readonly SharedAppearanceSystem _appearance = default!; | ||
| [Dependency] private readonly SharedAudioSystem _audio = default!; | ||
| [Dependency] private readonly SharedContainerSystem _container = default!; | ||
| [Dependency] private readonly SharedPopupSystem _popup = default!; | ||
| [Dependency] private readonly PaperSystem _paperSystem = default!; | ||
| [Dependency] private readonly IPrototypeManager _proto = default!; | ||
|
|
||
| public override void Initialize() | ||
| { | ||
| base.Initialize(); | ||
|
|
||
| SubscribeLocalEvent<DiseaseDiagnoserComponent, ActivateInWorldEvent>(OnActivateInWorld); | ||
| SubscribeLocalEvent<DiseaseDiagnoserComponent, ContainerIsRemovingAttemptEvent>(OnRemoveAttempt); | ||
| SubscribeLocalEvent<DiseaseDiagnoserComponent, PowerChangedEvent>(OnPowerChanged); | ||
| } | ||
|
|
||
| #region Events | ||
|
|
||
| private void OnActivateInWorld(Entity<DiseaseDiagnoserComponent> entity, ref ActivateInWorldEvent args) | ||
| { | ||
| if (args.Handled || !args.Complex) | ||
| return; | ||
|
|
||
| TryStart(entity, args.User); | ||
| args.Handled = true; | ||
| } | ||
|
|
||
| private void OnRemoveAttempt(Entity<DiseaseDiagnoserComponent> ent, ref ContainerIsRemovingAttemptEvent args) | ||
| { | ||
| if (args.Container.ID == ent.Comp.ContainerId && ent.Comp.Working) | ||
| args.Cancel(); | ||
| } | ||
|
|
||
| private void OnPowerChanged(Entity<DiseaseDiagnoserComponent> ent, ref PowerChangedEvent args) | ||
| { | ||
| if (!args.Powered) | ||
| Stop(ent); | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| #region Lifecycle | ||
|
|
||
| public void TryStart(Entity<DiseaseDiagnoserComponent> entity, EntityUid? user) | ||
| { | ||
| var (uid, comp) = entity; | ||
| if (comp.Working) | ||
| return; | ||
|
|
||
| if (!HasPower(entity)) | ||
| { | ||
| if (user != null) | ||
| _popup.PopupClient(Loc.GetString("solution-container-mixer-no-power"), entity, user.Value); | ||
| return; | ||
| } | ||
|
|
||
| if (!_container.TryGetContainer(uid, comp.ContainerId, out var container) || container.Count == 0) | ||
| { | ||
| if (user != null) | ||
| _popup.PopupClient(Loc.GetString("solution-container-mixer-popup-nothing-to-mix"), entity, user.Value); | ||
| return; | ||
| } | ||
|
|
||
| comp.Working = true; | ||
| comp.WorkingSoundEntity = _audio.PlayPvs(comp.WorkingSound, entity, comp.WorkingSound?.Params.WithLoop(true)); | ||
| comp.WorkTimeEnd = _timing.CurTime + comp.WorkDuration; | ||
| _appearance.SetData(entity, DiseaseDiagnoserVisuals.Printing, true); | ||
| Dirty(uid, comp); | ||
| } | ||
|
|
||
| public void Stop(Entity<DiseaseDiagnoserComponent> entity) | ||
| { | ||
| var (uid, comp) = entity; | ||
| if (!comp.Working) | ||
| return; | ||
| _audio.Stop(comp.WorkingSoundEntity); | ||
| _appearance.SetData(entity, DiseaseDiagnoserVisuals.Printing, false); | ||
| comp.Working = false; | ||
| comp.WorkingSoundEntity = null; | ||
| Dirty(uid, comp); | ||
| } | ||
|
|
||
| public string GetReport(BotanySwabComponent swabComponent) | ||
| { | ||
| StringBuilder builder = new(); | ||
|
|
||
| if (swabComponent.AllergicTriggers == null || swabComponent.AllergicTriggers.Count() == 0) | ||
| builder.Append(Loc.GetString("paper-allergy-prefix", ("allergies", Loc.GetString("paper-allergy-no")))); | ||
| else | ||
| { | ||
| List<string> localizedNames = new(); | ||
| foreach (ProtoId<ReagentPrototype> trigger in swabComponent.AllergicTriggers) | ||
| { | ||
| localizedNames.Add(_proto.Index<ReagentPrototype>(trigger).LocalizedName.ToLower()); | ||
| } | ||
|
|
||
| builder.Append(Loc.GetString("paper-allergy-prefix", ("allergies", String.Join(", ", localizedNames)))); | ||
| } | ||
|
|
||
| return builder.ToString(); | ||
| } | ||
|
|
||
| public void Finish(Entity<DiseaseDiagnoserComponent> entity) | ||
| { | ||
| var (uid, comp) = entity; | ||
| if (!comp.Working) | ||
| return; | ||
| Stop(entity); | ||
|
|
||
| if (!TryComp<DiseaseDiagnoserComponent>(entity, out var reactionMixer) | ||
| || !_container.TryGetContainer(uid, comp.ContainerId, out var container)) | ||
| return; | ||
|
|
||
| if (container.ContainedEntities.Count == 0) | ||
| return; | ||
|
|
||
| var swabEnt = container.ContainedEntities.First(); | ||
| if (!TryComp<BotanySwabComponent>(swabEnt, out var swabComponent)) | ||
| return; | ||
|
|
||
| var printed = Spawn("DiagnosisReportPaper", Transform(uid).Coordinates); | ||
|
|
||
| if (TryComp<PaperComponent>(printed, out var paper)) | ||
| { | ||
| _paperSystem.SetContent((printed, paper), GetReport(swabComponent)); | ||
| } | ||
| } | ||
|
|
||
| public override void Update(float frameTime) | ||
| { | ||
| base.Update(frameTime); | ||
|
|
||
| var query = EntityQueryEnumerator<DiseaseDiagnoserComponent>(); | ||
| while (query.MoveNext(out var uid, out var comp)) | ||
| { | ||
| if (!comp.Working) | ||
| continue; | ||
|
|
||
| if (_timing.CurTime < comp.WorkTimeEnd) | ||
| continue; | ||
|
|
||
| Finish((uid, comp)); | ||
| } | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| public bool HasPower(Entity<DiseaseDiagnoserComponent> entity) | ||
| { | ||
| return this.IsPowered(entity, EntityManager); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.