Skip to content
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

Пытаемся сделать систему зависимости #352

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Content.Server/ADT/Addiction/AddictionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Content.Shared.ADT.Addiction.AddictedComponent;
using Content.Server.ADT.Addiction.EntityEffects;
using Content.Shared.Popups;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server.ADT.Addiction;

public sealed partial class AddictionSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;

public override void Update(float frameTime)
{
base.Update(frameTime);
TimeSpan fT = TimeSpan.FromSeconds(frameTime);
var query = EntityQueryEnumerator<AddictedComponent>();
while (query.MoveNext(out var uid, out var comp))
{
UpdateCurrentAddictedTime(comp, fT);
UpdateTypeAddiction(comp);
UpdateAddicted(comp, uid);
}
}
public void UpdateCurrentAddictedTime(AddictedComponent comp, TimeSpan frameTime)
{
if (comp.CurrentAddictedTime >= TimeSpan.Zero + frameTime)
comp.CurrentAddictedTime -= frameTime;
else
comp.CurrentAddictedTime = TimeSpan.Zero;
if (comp.RemaningTime >= TimeSpan.Zero + frameTime)
comp.RemaningTime -= frameTime;
else
comp.RemaningTime = TimeSpan.Zero;
}
public void UpdateTypeAddiction(AddictedComponent comp)
{
if (comp.TypeAddiction > 0 && comp.Addicted && comp.RemaningTime <= TimeSpan.Zero)
{
comp.RemaningTime = comp.ChangeAddictionTypeTime;
comp.TypeAddiction -= 1;
}
}
public void UpdateAddicted(AddictedComponent comp, EntityUid uid)
{
if (comp.CurrentAddictedTime >= comp.RequiredTime)
{
comp.Addicted = true;
_popup.PopupEntity("У вас сформировывается зависимость", uid, uid);
}
}
}
37 changes: 37 additions & 0 deletions Content.Server/ADT/Addiction/EntityEffects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Content.Shared.ADT.Addiction.AddictedComponent;
using Content.Shared.EntityEffects;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;

namespace Content.Server.ADT.Addiction.EntityEffects;
public sealed partial class AddictionEffect : EntityEffect
{
[DataField(required: true)]
public float TimeCoefficient = new(); // Коэфицент домножающий на себя время воздействие этого регаента на организм
[DataField(required: true)]
public float QuantityCoefficient = new(); // Коэфицент домножающий на себя количество усвоенного реагента организмом
[DataField] public TimeSpan DelayTime = TimeSpan.FromSeconds(30); // Время между получением реагента


protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
{
return Loc.GetString("reagent-effect-addiction", ("chance", Probability));
}

public override void Effect(EntityEffectBaseArgs ev)
{
if (ev is not EntityEffectReagentArgs args)
return;
if (ev.EntityManager.TryGetComponent<AddictedComponent>(ev.TargetEntity, out var comp)) // Получили компонент того, на кого действует эффект.
{
if (comp.LastEffect + DelayTime >= IoCManager.Resolve<IGameTiming>().CurTime)
comp.CurrentAddictedTime += (IoCManager.Resolve<IGameTiming>().CurTime - comp.LastEffect) * 2;
else
comp.CurrentAddictedTime += TimeSpan.FromSeconds(1) * TimeCoefficient * 2;
comp.RemaningTime = comp.ChangeAddictionTypeTime;
if (comp.TypeAddiction < 4)
comp.TypeAddiction += 1;
comp.LastEffect = IoCManager.Resolve<IGameTiming>().CurTime;
}
}
}
38 changes: 38 additions & 0 deletions Content.Shared/ADT/Addiction/AddictedComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Content.Shared.ADT.Addiction.AddictedComponent;

/// <summary>
/// Компонент для базовых представителей рас.
/// Используется такие переменные для указания: RequiredTime, ChangeAddictionTypeTime.
/// </summary>
[RegisterComponent]
public sealed partial class AddictedComponent : Component
{
/// <summary>
/// Время проведенное за употреблением - время, когда не употреблял.
/// </summary>
[DataField] public TimeSpan CurrentAddictedTime = TimeSpan.Zero;
/// <summary>
/// Время проведенное за употреблением - время, когда не употреблял.
/// </summary>
[DataField(required: true)] public TimeSpan ChangeAddictionTypeTime;
/// <summary>
/// Время оставшиеся до того, как сменится тип зависимости.
/// </summary>
[DataField] public TimeSpan RemaningTime;
/// <summary>
/// Время необходимое, чтобы стать зависимым.
/// </summary>
[DataField(required: true)] public TimeSpan RequiredTime;
/// <summary>
/// Собсна тип зависимости. 0 - легкая, без побочек, 1 - с небольшими побочками и т п, до 4
/// </summary>
[DataField] public int TypeAddiction = 4;
/// <summary>
/// собсна сообщает нам имеет ли зависимость пациент
/// </summary>
[DataField] public bool Addicted = false;
/// <summary>
/// Собсна время, которое сообщает нам, время последнего воздействия эффекта на челика
/// </summary>
[DataField] public TimeSpan LastEffect = TimeSpan.Zero;
}
6 changes: 6 additions & 0 deletions Resources/Locale/ru-RU/ADT/reagents/addiction.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
addiction-message-1 = Вы чувсвуете привязанность к этому.
addiction-message-2 = Вы чувсвуете себя более спокойно.
addiction-message-3 = Вы чувсвуете себя более расслабленным.
addiction-message-4 = Вы привыкаете к этому.
addiction-message-5 = Вы чувсвуете себя удовлетворенно.
addiction-message-6 = У вас сформировывается зависимость к этому.
5 changes: 4 additions & 1 deletion Resources/Prototypes/Entities/Mobs/Species/human.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
understands:
- GalacticCommon
- SolCommon
- type: Addicted
changeAddictionTypeTime: 50
requiredTime: 50

- type: entity
parent: BaseSpeciesDummy
Expand All @@ -46,4 +49,4 @@
sizeMaps:
32:
sprite: Mobs/Species/Human/displacement.rsi
state: jumpsuit-female
state: jumpsuit-female
17 changes: 17 additions & 0 deletions Resources/Prototypes/Reagents/narcotics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@
plantMetabolism:
- !type:PlantAdjustHealth
amount: -5
#ADT start
metabolisms:
Narcotic:
effects:
- !type:PopupMessage
type: Local
messages:
- addiction-message-1
- addiction-message-2
- addiction-message-3
- addiction-message-4
- addiction-message-5
- addiction-message-6
- !type:AddictionEffect
timeCoefficient: 1
quantityCoefficient: 2
#ADT end

# TODO: Replace these nonstandardized effects with generic brain damage
- type: reagent
Expand Down