Skip to content

Commit

Permalink
Merge branch 'master' into billions-must-flip
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyyapril authored Dec 10, 2024
2 parents 68dacad + 48951ff commit 3321e95
Show file tree
Hide file tree
Showing 125 changed files with 2,175 additions and 399 deletions.
5 changes: 5 additions & 0 deletions Content.Client/Damage/DamageOtherOnHitSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Content.Shared.Damage.Systems;

namespace Content.Client.Damage;

public sealed class DamageOtherOnHitSystem : SharedDamageOtherOnHitSystem;
2 changes: 1 addition & 1 deletion Content.Server/Antag/AntagSelectionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected override void Started(EntityUid uid, AntagSelectionComponent component
return;

var players = _playerManager.Sessions
.Where(x => GameTicker.PlayerGameStatuses[x.UserId] == PlayerGameStatus.JoinedGame)
.Where(x => GameTicker.PlayerGameStatuses.TryGetValue(x.UserId, out var status) && status == PlayerGameStatus.JoinedGame)
.ToList();

ChooseAntags((uid, component), players);
Expand Down
19 changes: 0 additions & 19 deletions Content.Server/Damage/Components/DamageOtherOnHitComponent.cs

This file was deleted.

65 changes: 33 additions & 32 deletions Content.Server/Damage/Systems/DamageOtherOnHitSystem.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,66 @@
using Content.Server.Administration.Logs;
using Content.Server.Damage.Components;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.Camera;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Damage.Systems;
using Content.Shared.Database;
using Content.Shared.Effects;
using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.Mobs.Components;
using Content.Shared.Projectiles;
using Content.Shared.Popups;
using Content.Shared.Throwing;
using Content.Shared.Weapons.Melee;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Physics.Components;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Server.Damage.Systems
{
public sealed class DamageOtherOnHitSystem : EntitySystem
public sealed class DamageOtherOnHitSystem : SharedDamageOtherOnHitSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly GunSystem _guns = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly DamageExamineSystem _damageExamine = default!;
[Dependency] private readonly SharedCameraRecoilSystem _sharedCameraRecoil = default!;
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
[Dependency] private readonly ThrownItemSystem _thrownItem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly StaminaSystem _stamina = default!;

public override void Initialize()
{
SubscribeLocalEvent<DamageOtherOnHitComponent, ThrowDoHitEvent>(OnDoHit);
base.Initialize();

SubscribeLocalEvent<StaminaComponent, BeforeThrowEvent>(OnBeforeThrow);
SubscribeLocalEvent<DamageOtherOnHitComponent, DamageExamineEvent>(OnDamageExamine);
}

private void OnDoHit(EntityUid uid, DamageOtherOnHitComponent component, ThrowDoHitEvent args)
private void OnBeforeThrow(EntityUid uid, StaminaComponent component, ref BeforeThrowEvent args)
{
var dmg = _damageable.TryChangeDamage(args.Target, component.Damage, component.IgnoreResistances, origin: args.Component.Thrower);

// Log damage only for mobs. Useful for when people throw spears at each other, but also avoids log-spam when explosions send glass shards flying.
if (dmg != null && HasComp<MobStateComponent>(args.Target))
_adminLogger.Add(LogType.ThrowHit, $"{ToPrettyString(args.Target):target} received {dmg.GetTotal():damage} damage from collision");

if (dmg is { Empty: false })
{
_color.RaiseEffect(Color.Red, new List<EntityUid>() { args.Target }, Filter.Pvs(args.Target, entityManager: EntityManager));
}
if (!TryComp<DamageOtherOnHitComponent>(args.ItemUid, out var damage))
return;

_guns.PlayImpactSound(args.Target, dmg, null, false);
if (TryComp<PhysicsComponent>(uid, out var body) && body.LinearVelocity.LengthSquared() > 0f)
if (component.CritThreshold - component.StaminaDamage <= damage.StaminaCost)
{
var direction = body.LinearVelocity.Normalized();
_sharedCameraRecoil.KickCamera(args.Target, direction);
args.Cancelled = true;
_popup.PopupEntity(Loc.GetString("throw-no-stamina", ("item", args.ItemUid)), uid, uid);
return;
}

// TODO: If more stuff touches this then handle it after.
if (TryComp<PhysicsComponent>(uid, out var physics))
{
_thrownItem.LandComponent(args.Thrown, args.Component, physics, false);
}
_stamina.TakeStaminaDamage(uid, damage.StaminaCost, component, visual: false);
}

private void OnDamageExamine(EntityUid uid, DamageOtherOnHitComponent component, ref DamageExamineEvent args)
{
_damageExamine.AddDamageExamine(args.Message, component.Damage, Loc.GetString("damage-throw"));
_damageExamine.AddDamageExamine(args.Message, GetDamage(uid, component, args.User), Loc.GetString("damage-throw"));

if (component.StaminaCost == 0)
return;

var staminaCostMarkup = FormattedMessage.FromMarkupOrThrow(
Loc.GetString("damage-stamina-cost",
("type", Loc.GetString("damage-throw")), ("cost", component.StaminaCost)));
args.Message.PushNewline();
args.Message.AddMessage(staminaCostMarkup);
}
}
}
20 changes: 14 additions & 6 deletions Content.Server/Flash/FlashSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Content.Shared.Inventory;
using Content.Shared.Physics;
using Content.Shared.Tag;
using Content.Shared.Throwing;
using Content.Shared.Weapons.Melee.Events;
using Robust.Server.Audio;
using Robust.Server.GameObjects;
Expand Down Expand Up @@ -50,6 +51,7 @@ public override void Initialize()
SubscribeLocalEvent<FlashComponent, MeleeHitEvent>(OnFlashMeleeHit);
// ran before toggling light for extra-bright lantern
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnFlashUseInHand, before: new []{ typeof(HandheldLightSystem) });
SubscribeLocalEvent<FlashComponent, ThrowDoHitEvent>(OnFlashThrowHitEvent);
SubscribeLocalEvent<InventoryComponent, FlashAttemptEvent>(OnInventoryFlashAttempt);
SubscribeLocalEvent<FlashImmunityComponent, FlashAttemptEvent>(OnFlashImmunityFlashAttempt);
SubscribeLocalEvent<PermanentBlindnessComponent, FlashAttemptEvent>(OnPermanentBlindnessFlashAttempt);
Expand All @@ -60,10 +62,8 @@ private void OnFlashMeleeHit(EntityUid uid, FlashComponent comp, MeleeHitEvent a
{
if (!args.IsHit ||
!args.HitEntities.Any() ||
!UseFlash(uid, comp, args.User))
{
!UseFlash(uid, comp))
return;
}

args.Handled = true;
foreach (var e in args.HitEntities)
Expand All @@ -74,14 +74,22 @@ private void OnFlashMeleeHit(EntityUid uid, FlashComponent comp, MeleeHitEvent a

private void OnFlashUseInHand(EntityUid uid, FlashComponent comp, UseInHandEvent args)
{
if (args.Handled || !UseFlash(uid, comp, args.User))
if (args.Handled || !UseFlash(uid, comp))
return;

args.Handled = true;
FlashArea(uid, args.User, comp.Range, comp.AoeFlashDuration, comp.SlowTo, true, comp.Probability);
}

private bool UseFlash(EntityUid uid, FlashComponent comp, EntityUid user)
private void OnFlashThrowHitEvent(EntityUid uid, FlashComponent comp, ThrowDoHitEvent args)
{
if (!UseFlash(uid, comp))
return;

FlashArea(uid, args.User, comp.Range, comp.AoeFlashDuration, comp.SlowTo, false, comp.Probability);
}

private bool UseFlash(EntityUid uid, FlashComponent comp)
{
if (comp.Flashing)
return false;
Expand All @@ -99,7 +107,7 @@ private bool UseFlash(EntityUid uid, FlashComponent comp, EntityUid user)
{
_appearance.SetData(uid, FlashVisuals.Burnt, true);
_tag.AddTag(uid, "Trash");
_popup.PopupEntity(Loc.GetString("flash-component-becomes-empty"), user);
_popup.PopupEntity(Loc.GetString("flash-component-becomes-empty"), uid);
}

uid.SpawnTimer(400, () =>
Expand Down
6 changes: 6 additions & 0 deletions Content.Server/Hands/Systems/HandsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ hands.ActiveHandEntity is not { } throwEnt ||

// Let other systems change the thrown entity (useful for virtual items)
// or the throw strength.
var itemEv = new BeforeGettingThrownEvent(throwEnt, direction, throwStrength, player);
RaiseLocalEvent(throwEnt, ref itemEv);

if (itemEv.Cancelled)
return true;

var ev = new BeforeThrowEvent(throwEnt, direction, throwStrength, player);
RaiseLocalEvent(player, ref ev);

Expand Down
20 changes: 20 additions & 0 deletions Content.Server/Projectiles/ProjectileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Damage.Events;
using Content.Server.Administration.Logs;
using Content.Server.Effects;
using Content.Server.Weapons.Ranged.Systems;
Expand All @@ -7,6 +8,7 @@
using Content.Shared.Projectiles;
using Robust.Shared.Physics.Events;
using Robust.Shared.Player;
using Robust.Shared.Utility;

namespace Content.Server.Projectiles;

Expand All @@ -22,6 +24,7 @@ public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ProjectileComponent, StartCollideEvent>(OnStartCollide);
SubscribeLocalEvent<EmbeddableProjectileComponent, DamageExamineEvent>(OnDamageExamine);
}

private void OnStartCollide(EntityUid uid, ProjectileComponent component, ref StartCollideEvent args)
Expand Down Expand Up @@ -77,4 +80,21 @@ private void OnStartCollide(EntityUid uid, ProjectileComponent component, ref St
RaiseNetworkEvent(new ImpactEffectEvent(component.ImpactEffect, GetNetCoordinates(xform.Coordinates)), Filter.Pvs(xform.Coordinates, entityMan: EntityManager));
}
}

private void OnDamageExamine(EntityUid uid, EmbeddableProjectileComponent component, ref DamageExamineEvent args)
{
if (!component.EmbedOnThrow)
return;

if (!args.Message.IsEmpty)
args.Message.PushNewline();

var isHarmful = TryComp<EmbedPassiveDamageComponent>(uid, out var passiveDamage) && passiveDamage.Damage.Any();
var loc = isHarmful
? "damage-examine-embeddable-harmful"
: "damage-examine-embeddable";

var staminaCostMarkup = FormattedMessage.FromMarkupOrThrow(Loc.GetString(loc));
args.Message.AddMessage(staminaCostMarkup);
}
}
2 changes: 1 addition & 1 deletion Content.Server/Weapons/Melee/MeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void OnMeleeExamineDamage(EntityUid uid, MeleeWeaponComponent component,
if (component.HeavyStaminaCost != 0)
{
var staminaCostMarkup = FormattedMessage.FromMarkupOrThrow(
Loc.GetString("damage-melee-heavy-stamina-cost",
Loc.GetString("damage-stamina-cost",
("type", Loc.GetString("damage-melee-heavy")), ("cost", component.HeavyStaminaCost)));
args.Message.PushNewline();
args.Message.AddMessage(staminaCostMarkup);
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Body/Systems/SharedBodySystem.Targeting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private static TargetBodyPart GetRandomPartSpread(IRobustRandom random, ushort t

public TargetBodyPart? GetRandomBodyPart(EntityUid uid, TargetingComponent? target = null)
{
if (!Resolve(uid, ref target))
if (!Resolve(uid, ref target, false))
return null;

var totalWeight = target.TargetOdds.Values.Sum();
Expand Down
55 changes: 55 additions & 0 deletions Content.Shared/Customization/Systems/CharacterRequirements.Misc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Content.Shared.Customization.Systems;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;

namespace Content.Shared.Customization.Systems;

/// <summary>
/// Requires the server to have a specific CVar value.
/// </summary>
[UsedImplicitly, Serializable, NetSerializable,]
public sealed partial class CVarRequirement : CharacterRequirement
{
[DataField("cvar", required: true)]
public string CVar;

[DataField(required: true)]
public string RequiredValue;

public override bool IsValid(
JobPrototype job,
HumanoidCharacterProfile profile,
Dictionary<string, TimeSpan> playTimes,
bool whitelisted,
IPrototype prototype,
IEntityManager entityManager,
IPrototypeManager prototypeManager,
IConfigurationManager configManager,
out string? reason,
int depth = 0
)
{
if (!configManager.IsCVarRegistered(CVar))
{
reason = null;
return true;
}

const string color = "lightblue";
var cvar = configManager.GetCVar(CVar);
var isValid = cvar.ToString()! == RequiredValue;

reason = Loc.GetString(
"character-cvar-requirement",
("inverted", Inverted),
("color", color),
("cvar", CVar),
("value", RequiredValue));

return isValid;
}
}
Loading

0 comments on commit 3321e95

Please sign in to comment.