-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Port] Melee Block / Блок В Ближнем Бою (#10)
* add: melee block * add: RU loc * test * fix * test * test
- Loading branch information
Showing
38 changed files
with
252 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
|
@@ -55,6 +55,7 @@ public enum AlertType : byte | |
BorgCrit, | ||
BorgDead, | ||
Offer, | ||
RecentlyBlocked, // WD EDIT | ||
} | ||
|
||
} |
This file contains 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 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 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 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 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,6 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared._White.Blocking; | ||
|
||
[RegisterComponent, NetworkedComponent] | ||
public sealed partial class BlockBlockerComponent : Component; |
This file contains 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,24 @@ | ||
using Content.Shared.Damage; | ||
using Robust.Shared.Audio; | ||
|
||
namespace Content.Shared._White.Blocking; | ||
|
||
[RegisterComponent] | ||
public sealed partial class MeleeBlockComponent : Component | ||
{ | ||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
public TimeSpan Delay = TimeSpan.FromSeconds(3.1); | ||
|
||
[DataField] | ||
public SoundSpecifier BlockSound = new SoundPathSpecifier("/Audio/Weapons/block_metal1.ogg") | ||
{ | ||
Params = AudioParams.Default.WithVariation(0.25f) | ||
}; | ||
} | ||
|
||
public sealed class MeleeBlockAttemptEvent(EntityUid attacker, DamageSpecifier damage) : HandledEntityEventArgs | ||
{ | ||
public EntityUid Attacker = attacker; | ||
|
||
public DamageSpecifier Damage = damage; | ||
} |
This file contains 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,95 @@ | ||
using Content.Shared.Blocking; | ||
using Content.Shared.Damage; | ||
using Content.Shared.Damage.Systems; | ||
using Content.Shared.Examine; | ||
using Content.Shared.Hands.Components; | ||
using Content.Shared.Item.ItemToggle.Components; | ||
using Content.Shared.Popups; | ||
using Content.Shared.StatusEffect; | ||
using Content.Shared.Weapons.Melee; | ||
using Content.Shared.Weapons.Melee.Events; | ||
using Robust.Shared.Audio.Systems; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Shared._White.Blocking; | ||
|
||
public sealed class MeleeBlockSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
[Dependency] private readonly DamageableSystem _damageable = default!; | ||
[Dependency] private readonly SharedAudioSystem _audio = default!; | ||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!; | ||
[Dependency] private readonly StatusEffectsSystem _statusEffect = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<HandsComponent, MeleeBlockAttemptEvent>(OnBlockAttempt, | ||
after: new[] {typeof(BlockingSystem)}); | ||
SubscribeLocalEvent<MeleeWeaponComponent, MeleeHitEvent>(OnHit, | ||
before: new[] {typeof(StaminaSystem), typeof(MeleeThrowOnHitSystem)}); | ||
SubscribeLocalEvent<MeleeBlockComponent, ExaminedEvent>(OnExamine); | ||
} | ||
|
||
private void OnExamine(Entity<MeleeBlockComponent> ent, ref ExaminedEvent args) | ||
{ | ||
args.PushMarkup(Loc.GetString("melee-block-component-delay", ("delay", ent.Comp.Delay.TotalSeconds))); | ||
} | ||
|
||
private void OnHit(Entity<MeleeWeaponComponent> ent, ref MeleeHitEvent args) | ||
{ | ||
if (!_timing.IsFirstTimePredicted) | ||
return; | ||
|
||
if (!ent.Comp.CanBeBlocked || !args.IsHit || args.Handled) | ||
return; | ||
|
||
if (args.Direction != null || args.HitEntities.Count != 1) // Heavy attacks are unblockable | ||
return; | ||
|
||
var hitEntity = args.HitEntities[0]; | ||
|
||
if (hitEntity == args.User) | ||
return; | ||
|
||
var ev = new MeleeBlockAttemptEvent(args.User, args.BaseDamage + args.BonusDamage); | ||
RaiseLocalEvent(hitEntity, ev); | ||
|
||
if (ev.Handled) | ||
args.Handled = true; | ||
} | ||
|
||
private void OnBlockAttempt(Entity<HandsComponent> ent, ref MeleeBlockAttemptEvent args) | ||
{ | ||
if (args.Handled || HasComp<BlockBlockerComponent>(ent)) | ||
return; | ||
|
||
if (!TryComp(ent, out StatusEffectsComponent? statusEffects)) | ||
return; | ||
|
||
var uid = ent.Comp.ActiveHandEntity; | ||
if (!TryComp(uid, out MeleeBlockComponent? block)) | ||
return; | ||
|
||
if (TryComp(uid.Value, out ItemToggleComponent? toggle) && !toggle.Activated) | ||
return; | ||
|
||
_audio.PlayPredicted(block.BlockSound, ent, args.Attacker); | ||
_popupSystem.PopupPredicted(Loc.GetString("melee-block-event-blocked"), ent, args.Attacker); | ||
_damageable.TryChangeDamage(uid.Value, args.Damage); | ||
TryBlockBlocking(ent, block.Delay, true, statusEffects); | ||
args.Handled = true; | ||
} | ||
|
||
public bool TryBlockBlocking(EntityUid uid, TimeSpan time, bool refresh, StatusEffectsComponent? status = null) | ||
{ | ||
if (time <= TimeSpan.Zero) | ||
return false; | ||
|
||
if (!Resolve(uid, ref status, false)) | ||
return false; | ||
|
||
return _statusEffect.TryAddStatusEffect<BlockBlockerComponent>(uid, "RecentlyBlocked", time, refresh); | ||
} | ||
} |
This file contains 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,2 @@ | ||
alerts-blocked-name = Recently blocked | ||
alerts-blocked-desc = I can't block for a while! |
This file contains 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,2 @@ | ||
melee-block-event-blocked = blocked! | ||
melee-block-component-delay = Can block a melee attack every {$delay} seconds. |
This file contains 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,2 @@ | ||
alerts-blocked-name = Атака заблокирована | ||
alerts-blocked-desc = Невозможно блокировать некоторое время. |
This file contains 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,2 @@ | ||
melee-block-event-blocked = заблокировал! | ||
melee-block-component-delay = Может блокировать атаку ближнего боя каждые {$delay} секунд. |
This file contains 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 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 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 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.