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

[Tweak] Melee / Ближнее Оружие #62

Merged
merged 2 commits into from
Sep 26, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Content.Shared._White.BackStab;
namespace Content.Server._White.Melee.BackStab;

[RegisterComponent]
public sealed partial class BackStabComponent : Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using Content.Server.Popups;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Mobs.Components;
using Content.Shared.Popups;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;

namespace Content.Shared._White.BackStab;
namespace Content.Server._White.Melee.BackStab;

public sealed class BackStabSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly PopupSystem _popup = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -49,10 +48,7 @@ private void HandleHit(Entity<BackStabComponent> ent, ref MeleeHitEvent args)
args.BonusDamage = new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>("Slash"),
damage - args.BaseDamage.GetTotal());

if (!_net.IsServer)
return;

var message = Loc.GetString("backstab-damage-betrayal-dagger", ("damage", damage));
var message = Loc.GetString("melee-backstab-damage", ("damage", damage));
_popup.PopupEntity(message, args.User, args.User, PopupType.MediumCaution);
}
}
13 changes: 13 additions & 0 deletions Content.Server/_White/Melee/Crit/CritComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Content.Server._White.Melee.Crit;

[RegisterComponent]
public sealed partial class CritComponent : Component
{
[DataField]
public float CritChance = 0.2f;

[DataField]
public float CritMultiplier = 2f;

public float? RealChance;
}
50 changes: 50 additions & 0 deletions Content.Server/_White/Melee/Crit/CritSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Content.Server.Popups;
using Content.Shared._White.Blocking;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Popups;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Server._White.Melee.Crit;

public sealed class CritSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly PopupSystem _popup = default!;

public override void Initialize()
{
SubscribeLocalEvent<CritComponent, MeleeHitEvent>(HandleHit, before: new [] {typeof(MeleeBlockSystem)});
}

private void HandleHit(EntityUid uid, CritComponent component, MeleeHitEvent args)
{
if (args.HitEntities.Count == 0 || !IsCriticalHit(component))
return;

var damage = args.BaseDamage.GetTotal() * component.CritMultiplier;

args.BonusDamage = new DamageSpecifier(_prototypeManager.Index<DamageTypePrototype>("Slash"),
damage - args.BaseDamage.GetTotal());

var message = Loc.GetString("melee-crit-damage", ("damage", damage));
_popup.PopupEntity(message, args.User, args.User, PopupType.MediumCaution);
}

private bool IsCriticalHit(CritComponent component)
{
component.RealChance ??= component.CritChance;

var isCritical = _random.NextFloat() <= component.RealChance;

if (isCritical)
component.RealChance = component.CritChance;
else
component.RealChance += component.CritChance;

return isCritical;
}
}
1 change: 0 additions & 1 deletion Resources/Locale/en-US/_white/backstab/backstab.ftl

This file was deleted.

1 change: 1 addition & 0 deletions Resources/Locale/en-US/_white/melee/backstab.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
melee-backstab-damage = A stab in the back: {$damage}!
1 change: 1 addition & 0 deletions Resources/Locale/en-US/_white/melee/crit.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
melee-crit-damage = Critical hit: {$damage}!
1 change: 0 additions & 1 deletion Resources/Locale/ru-RU/_white/backstab/backstab.ftl

This file was deleted.

1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/_white/melee/backstab.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
melee-backstab-damage = Удар в спину: {$damage}!
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/_white/melee/crit.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
melee-crit-damage = Критическое попадание: {$damage}!
Loading