Skip to content
Open
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
@@ -0,0 +1,9 @@
using Content.Shared.Animals.Systems;

namespace Content.Client.Animals.Systems;

// This is just an empty class so that the matching code in SharedPrizeballLayingSystem can run on the client.
public sealed class PrizeballLayingSystem : SharedPrizeballLayingSystem
{

}
26 changes: 26 additions & 0 deletions Content.Server/_Hardlight/EntityEffects/Effects/Redeem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Content.Shared.EntityEffects;
using Content.Shared.Animals.Components; // HL: Moved the LewdEggLayingComponent to Shared

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for HL comments in HL namespace

using Content.Server.Animals.Systems;
using Robust.Shared.Prototypes;

namespace Content.Server.EntityEffects.Effects
{
/// <summary>
/// Attempts to find a prizeball laying component and triggers its effects
/// </summary>
public sealed partial class Redeem : EntityEffect
{
public override void Effect(EntityEffectBaseArgs args)
{
var entman = args.EntityManager;
if (entman.TryGetComponent(args.TargetEntity, out PrizeballLayingComponent? egglaying))
{
float amt = (args is EntityEffectReagentArgs reagentArgs) ? (float) reagentArgs.Quantity : 1.0f;
entman.System<PrizeballLayingSystem>().Redeem(args.TargetEntity, amt, egglaying);
}
}

protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
=> Loc.GetString("reagent-effect-guidebook-redeem", ("chance", Probability));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
using Content.Shared.Actions;
using Content.Shared.DoAfter;
using Content.Shared.IdentityManagement;
using Content.Shared.Movement.Systems;
using Content.Shared.Storage;
using Content.Shared.Traits.Events;
using Content.Server.Popups;
using Robust.Server.Audio;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Content.Shared.Animals.Systems;
using Content.Shared.Animals.Components;

namespace Content.Server.Animals.Systems;

/// <summary>
/// Gives the ability to lay pballs/other things;
/// produces endlessly if the owner does not have a HungerComponent.
/// </summary>
public sealed class PrizeballLayingSystem : SharedPrizeballLayingSystem // We've changed the base to SharedPrizeballLayingSystem so we can run the Verb drawing on the client.
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<PrizeballLayingComponent, ComponentShutdown>(OnHostShutdown);
SubscribeLocalEvent<PrizeballLayingComponent, PrizeballLayingActionEvent>(OnPballLayingAction);
SubscribeLocalEvent<PrizeballLayingComponent, PrizeballLayingDoAfterEvent>(OnPballLayingDoAfter);
SubscribeLocalEvent<PrizeballLayingComponent, PrizeballLayingInsideDoAfterEvent>(OnPballLayingInsideDoAfter);
SubscribeLocalEvent<PrizeballLayingComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
}

private void OnHostShutdown(EntityUid user, PrizeballLayingComponent pballLaying, ComponentShutdown args)
{
_actions.RemoveAction(user, pballLaying.Action);
}

protected override void AttemptLayInside(Entity<PrizeballLayingComponent> user, EntityUid target)
{
var doargs = new DoAfterArgs(EntityManager, user.Owner, user.Comp.PballLayDelay, new PrizeballLayingInsideDoAfterEvent(), user.Owner, target)
{
BreakOnMove = true,
BlockDuplicate = true,
BreakOnDamage = true,
CancelDuplicate = true,
};

_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-inside-start", ("entity", Identity.Entity(user.Owner, EntityManager)), ("target", Identity.Entity(target, EntityManager))), user);
_doAfter.TryStartDoAfter(doargs);
}

private void OnRefreshMovespeed(EntityUid user, PrizeballLayingComponent pballLaying, RefreshMovementSpeedModifiersEvent args)
{
if (pballLaying.isHeavyOfPballs())
{
args.ModifySpeed(pballLaying.PballSlowMult, pballLaying.PballSlowMult);
}
}

private void OnPballLayingAction(EntityUid user, PrizeballLayingComponent pballLaying, PrizeballLayingActionEvent args)
{
if (!pballLaying.hasPballs())
{
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-no-pballs"), user, user);
return;
}

var doAfter = new DoAfterArgs(EntityManager, user, pballLaying.PballLayDelay, new PrizeballLayingDoAfterEvent(), user)
{
BreakOnMove = true,
BlockDuplicate = true,
BreakOnDamage = true,
CancelDuplicate = true,
};

_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-user-start"), user, user);
_doAfter.TryStartDoAfter(doAfter);
}

public void Redeem(EntityUid user, float amount, PrizeballLayingComponent? pballLaying = null)
{
if (!Resolve(user, ref pballLaying) || pballLaying.Temporary)
return;

amount *= pballLaying.ProductionMult;

bool hasPballsBefore = pballLaying.hasPballs();
bool isHeavyBefore = pballLaying.isHeavyOfPballs();
bool isFullBefore = pballLaying.isFullOfPballs();

AddPballs(user, pballLaying, amount);

if(pballLaying.hasPballs() && !hasPballsBefore)
{
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-firstpball"), user, user);
_actions.AddAction(user, ref pballLaying.Action, pballLaying.ActionPrototype);
}
else if(pballLaying.isHeavyOfPballs() && !isHeavyBefore)
{
_movementSpeedModifier.RefreshMovementSpeedModifiers(user);
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-heavypballs"), user, user);
}
else if(pballLaying.isFullOfPballs() && !isFullBefore)
{
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-fullpballs"), user, user);
}
else if(pballLaying.doFlavor())
{
_popup.PopupEntity(Loc.GetString(_random.Pick(pballLaying.FlavorMessages)), user, user);
}
}

private void OnPballLayingInsideDoAfter(EntityUid user, PrizeballLayingComponent myPballs, PrizeballLayingInsideDoAfterEvent args)
{
if (args.Cancelled || args.Handled || args.Target == null)
return;

args.Handled = true;

if (myPballs.Deleted || !myPballs.hasPballs())
{
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-nopballs"), user, user);
return;
}
var target = args.Target.Value;

_audio.PlayPvs(myPballs.PballLaySound, user);

if (!TryComp<PrizeballLayingComponent>(target, out var theirPballs))
{
theirPballs = (PrizeballLayingComponent)Factory.GetComponent(Factory.GetComponentName<PrizeballLayingComponent>());
EntityManager.AddComponent(target, theirPballs);
theirPballs.makeTempFrom(myPballs);
_actions.AddAction(target, ref theirPballs.Action, theirPballs.ActionPrototype);
}

/// HL: Moved the AddPballs to a helper function so we can share the pballs count in the component to the client
AddPballs(user, myPballs, -1.0f);
AddPballs(target, theirPballs, 1.0f);

_movementSpeedModifier.RefreshMovementSpeedModifiers(user);
_movementSpeedModifier.RefreshMovementSpeedModifiers(target);

if(myPballs.hasPballs())
{
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-inside-give-more", ("entity", Identity.Entity(target, EntityManager))), user, user);
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-inside-receive-more", ("entity", Identity.Entity(user, EntityManager))), target, target);
args.Repeat = true;
}
else
{
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-inside-give-done", ("entity", Identity.Entity(target, EntityManager))), user, user);
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-inside-receive-done", ("entity", Identity.Entity(user, EntityManager))), target, target);

if(myPballs.Temporary)
RemComp<PrizeballLayingComponent>(user);
else
_actions.RemoveAction(user, myPballs.Action);
}
}

private void OnPballLayingDoAfter(EntityUid user, PrizeballLayingComponent pballLaying, PrizeballLayingDoAfterEvent args)
{
if (args.Cancelled || args.Handled)
return;

args.Handled = true;

if (pballLaying.Deleted || !pballLaying.hasPballs())
{
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-nopballs"), user, user);
return;
}

foreach (var ent in EntitySpawnCollection.GetSpawns(pballLaying.EggSpawn, _random))
{
Spawn(ent, Transform(user).Coordinates);
}

_audio.PlayPvs(pballLaying.PballLaySound, user);

AddPballs(user, pballLaying, -1.0f);
_movementSpeedModifier.RefreshMovementSpeedModifiers(user);

if(pballLaying.hasPballs())
{
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-user-more"), user, user);
args.Repeat = true;
}
else
{
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-user-done"), user, user);

if(pballLaying.Temporary)
EntityManager.RemoveComponent<PrizeballLayingComponent>(user);
else
_actions.RemoveAction(user, pballLaying.Action);
}
_popup.PopupEntity(Loc.GetString("action-popup-lay-pball-others", ("entity", user)), user, Filter.PvsExcept(user), true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using Content.Shared.Storage;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Content.Shared.Animals.Systems;

namespace Content.Shared.Animals.Components; // Moved this to Shared so the client can use it for verb drawing.

/// <summary>
/// This component handles prizeball laying for the prizeball layer trait
/// </summary>

[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(fieldDeltas: true)]
public sealed partial class PrizeballLayingComponent : Component
{
[DataField]
public EntProtoId ActionPrototype = "ActionLayPrizeball";

[DataField]
public EntityUid? Action;

/// <summary>
/// Messages while producing prizeballs
/// </summary>
[DataField]
public IReadOnlyList<string> FlavorMessages = new[]
{
"action-popup-lay-pball-flavor-1",
"action-popup-lay-pball-flavor-2",
"action-popup-lay-pball-flavor-3",
"action-popup-lay-pball-flavor-4"
};

/// <summary>
/// The item that gets laid/spawned, retrieved from animal prototype.
/// </summary>
[DataField(required: true)]
public List<EntitySpawnEntry> EggSpawn = new();

/// <summary>
/// The sound played when prizeball pops out
/// </summary>
[DataField]
public SoundSpecifier PballLaySound = new SoundPathSpecifier("/Audio/Machines/machine_vend.ogg");

/// <summary>
/// How many prizeballs produced per unit of cum
/// </summary>
[DataField]
public float ProductionMult = 0.2f;

/// <summary>
/// How many prizeballs between each flavor text
/// </summary>
[DataField]
public float FlavorFreq = 6.0f;

/// <summary>
/// The number of pballs when movespeed is slowed
/// </summary>
[DataField]
public float PballSlowThreshold = 10;

/// <summary>
/// The max number of prizeballs you can hold
/// </summary>
[DataField]
public float MaxPballs = 24;

/// <summary>
/// How much the user is slowed by prizeballs
/// </summary>
[DataField]
public float PballSlowMult = 0.5f;

/// <summary>
/// How long it takes for the prizeball to come out
/// </summary>
[DataField]
public float PballLayDelay = 5.0f;

/// <summary>
/// The number of prizeballs in your belly
/// </summary>
[DataField, AutoNetworkedField]
public float pballs = 0;

/// <summary>
/// The number of prizeballs produced since last flavor text
/// </summary>
public float pballsFlavorAccum = 0;

/// <summary>
/// The number of prizeballs produced since last flavor text
/// </summary>
public bool Temporary = false;
public bool hasPballs()
{
return pballs >= 1.0f;
}
public bool isHeavyOfPballs()
{
return pballs >= PballSlowThreshold;
}
public bool isFullOfPballs()
{
return pballs >= MaxPballs;
}
public bool doFlavor()
{
if(pballsFlavorAccum >= FlavorFreq)
{
pballsFlavorAccum -= FlavorFreq;
return true;
}
return false;
}
public void makeTempFrom(PrizeballLayingComponent other)
{
FlavorMessages = other.FlavorMessages;
EggSpawn = other.EggSpawn;
PballLaySound = other.PballLaySound;
PballSlowThreshold = other.PballSlowThreshold;
MaxPballs = other.MaxPballs;
PballSlowMult = other.PballSlowMult;
PballLayDelay = other.PballLayDelay;
Temporary = true;
}
}
Loading
Loading