Skip to content

Commit

Permalink
more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Acensti committed Jul 7, 2024
1 parent 86529f9 commit f96c8c9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 182 deletions.
114 changes: 7 additions & 107 deletions Content.Shared/Buckle/SharedBuckleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private void InitializeBuckle()
SubscribeLocalEvent<BuckleComponent, ThrowPushbackAttemptEvent>(OnBuckleThrowPushbackAttempt);
SubscribeLocalEvent<BuckleComponent, UpdateCanMoveEvent>(OnBuckleUpdateCanMove);
}

public bool ToggleBuckle(EntityUid buckleUid, EntityUid userUid, EntityUid strapUid, BuckleComponent? buckleComp = null, StrapComponent? strapComp = null)
{
if (!Resolve(buckleUid, ref buckleComp, false) || !Resolve(strapUid, ref strapComp, false))
Expand All @@ -89,64 +90,41 @@ public bool ToggleBuckle(EntityUid buckleUid, EntityUid userUid, EntityUid strap
else
return TryBuckle(buckleUid, userUid, strapUid, buckleComp, strapComp);
}
public bool IsBuckled(EntityUid uid, BuckleComponent? buckleComp = null)

public bool IsBuckled(EntityUid uid, BuckleComponent? buckleComp = null)
{

if (!Resolve(uid, ref buckleComp, false))

return false;


return buckleComp.Buckled;

}
public void StrapSetEnabled(EntityUid uid, bool enabled)

public void StrapSetEnabled(EntityUid uid, bool enabled)
{

if (TryComp<StrapComponent>(uid, out var strap))

{

strap.Enabled = enabled;

Dirty(uid, strap);

}

}


private void OnStrapStartup(EntityUid uid, StrapComponent component, ComponentStartup args)

{

UpdateStrapVisuals(uid, component);


var buckleQuery = GetEntityQuery<BuckleComponent>();

var xform = Transform(uid);

var buckleEntities = GetEntitiesInRange(uid, component.MaxBuckleDistance);


foreach (var entity in buckleEntities)

{

if (buckleQuery.TryGetComponent(entity, out var buckle) && !buckle.Buckled)

{

TryBuckle(entity, entity, uid, buckle, component);

}

}

}

public IEnumerable<EntityUid> GetEntitiesInRange(EntityUid uid, float range, TransformComponent? xform = null)
{
if (!Resolve(uid, ref xform))
Expand All @@ -171,46 +149,29 @@ public IEnumerable<EntityUid> GetEntitiesInRange(EntityUid uid, float range, Tra
}
}
}
private void OnStrapShutdown(EntityUid uid, StrapComponent component, ComponentShutdown args)

private void OnStrapShutdown(EntityUid uid, StrapComponent component, ComponentShutdown args)
{

// Unbuckle all entities from this strap

foreach (var buckledEntity in component.BuckledEntities.ToList())

{

TryUnbuckle(buckledEntity, buckledEntity, true);

}


// Clear the buckled entities list

component.BuckledEntities.Clear();

component.OccupiedSize = 0;


// Update the strap's visual state

UpdateStrapVisuals(uid, component);

}


private void UpdateStrapVisuals(EntityUid uid, StrapComponent? strap = null)

{

if (!Resolve(uid, ref strap))

return;


Appearance.SetData(uid, StrapVisuals.State, strap.BuckledEntities.Count > 0);

}

private void OnBuckleStartup(EntityUid uid, BuckleComponent component, ComponentStartup args)
Expand Down Expand Up @@ -304,150 +265,91 @@ private void UpdateBuckleStatus(EntityUid uid, BuckleComponent component)
}

public bool TryBuckle(EntityUid buckleUid, EntityUid userUid, EntityUid strapUid, BuckleComponent? buckleComp = null, StrapComponent? strapComp = null)

{

if (!Resolve(buckleUid, ref buckleComp, false) || !Resolve(strapUid, ref strapComp, false))

return false;


if (buckleComp.Buckled || !CanBuckle(buckleUid, userUid, strapUid, out strapComp, buckleComp))

return false;


buckleComp.Buckled = true;

buckleComp.BuckledTo = strapUid;

buckleComp.BuckleTime = _gameTiming.CurTime;


strapComp.BuckledEntities.Add(buckleUid);

strapComp.OccupiedSize += buckleComp.Size;


ReAttach(buckleUid, strapUid, buckleComp, strapComp);


_audio.PlayPredicted(strapComp.BuckleSound, strapUid, userUid);

_alerts.ShowAlert(buckleUid, strapComp.BuckledAlertType);


var ev = new BuckleChangeEvent(strapUid, buckleUid, true);

RaiseLocalEvent(buckleUid, ref ev);

RaiseLocalEvent(strapUid, ref ev);


return true;

}
public bool TryUnbuckle(EntityUid buckleUid, EntityUid userUid, bool force, BuckleComponent? buckleComp = null, StrapComponent? strapComp = null)

public bool TryUnbuckle(EntityUid buckleUid, EntityUid userUid, bool force, BuckleComponent? buckleComp = null, StrapComponent? strapComp = null)
{

if (!Resolve(buckleUid, ref buckleComp, false) || !buckleComp.Buckled || buckleComp.BuckledTo == null || !Resolve(buckleComp.BuckledTo.Value, ref strapComp, false))

return false;


if (!force && _gameTiming.CurTime < buckleComp.BuckleTime + buckleComp.Delay)

return false;


buckleComp.Buckled = false;

buckleComp.BuckledTo = null!;


if (_mobState.IsIncapacitated(buckleUid))

_standing.Down(buckleUid);


if (strapComp.BuckledEntities.Remove(buckleUid))

{

strapComp.OccupiedSize -= buckleComp.Size;

Dirty(buckleComp.BuckledTo.Value, strapComp);

}


_joints.RefreshRelay(buckleUid);

Appearance.SetData(buckleComp.BuckledTo.Value, StrapVisuals.State, strapComp.BuckledEntities.Count != 0);


if (!TerminatingOrDeleted(buckleComp.BuckledTo.Value))

_audio.PlayPredicted(strapComp.UnbuckleSound, buckleComp.BuckledTo.Value, userUid);


var ev = new BuckleChangeEvent(buckleComp.BuckledTo.Value, buckleUid, false);

RaiseLocalEvent(buckleUid, ref ev);

RaiseLocalEvent(buckleComp.BuckledTo.Value, ref ev);


return true;

}


private bool CanBuckle(EntityUid buckleUid, EntityUid userUid, EntityUid strapUid, [NotNullWhen(true)] out StrapComponent? strapComp, BuckleComponent? buckleComp = null)

{

strapComp = null;


if (!Resolve(buckleUid, ref buckleComp, false) || !Resolve(strapUid, ref strapComp, false))

return false;


if (userUid == strapUid)

return false;


if (!ActionBlocker.CanInteract(userUid, strapUid))

return false;


if (!IsEntityAllowed(buckleUid, strapComp))

return false;


if (!_interaction.InRangeUnobstructed(buckleUid, strapUid, buckleComp.Range))

return false;


if (strapComp.OccupiedSize + buckleComp.Size > strapComp.Size)

return false;


if (!strapComp.Enabled)

return false;


return true;

}

private bool IsEntityAllowed(EntityUid buckleUid, StrapComponent strapComp)
Expand Down Expand Up @@ -487,11 +389,9 @@ private void ReAttach(EntityUid buckleUid, EntityUid strapUid, BuckleComponent?
break;
}
}
public enum StrapVisuals

public enum StrapVisuals
{

State

}
}
3 changes: 3 additions & 0 deletions Content.Shared/Vehicles/Components/RiddenVehicleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ public sealed partial class RiddenVehicleComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
[DataField("speed")]
public float Speed = 5f;
[DataField("canMove")]

public bool CanMove = true;
}
}
22 changes: 0 additions & 22 deletions Content.Shared/Vehicles/Components/VehicleComponent.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Content.Shared/Vehicles/RiddenVehicleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Content.Shared.Interaction;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Movement.Systems; // Added this line
using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
using Content.Shared.Vehicle;
using Robust.Shared.GameObjects;
Expand Down
40 changes: 6 additions & 34 deletions Resources/Prototypes/Entities/Vehicles/vehicles.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,24 @@
- type: entity
id: VehicleCar
name: Car
description: A simple car for transportation.
components:
- type: Sprite
sprite: Vehicles/car.rsi
- type: Physics
- type: MovementSpeedModifier
baseWalkSpeed: 3.0
baseSprintSpeed: 6.0
- type: Vehicle
maxOccupants: 4
maxDrivers: 1
- type: Damageable
damageContainer: Vehicle
- type: Destructible
thresholds:
- trigger: !type:DamageTrigger
damage: 100
behaviors:
- !type:DoActsBehavior
acts: ["Destruction"]
- type: ContainerContainer
containers:
vehicle_storage: !type:Container

- type: entity
id: VehicleSecway
name: Secway
description: A simple personal transportation device.
components:
- type: Sprite
sprite: Objects/Vehicles/secway.rsi
state: secway
state: vehicle
- type: Physics
bodyType: Dynamic
- type: Vehicle
maxOccupants: 1
maxDrivers: 1
- type: RiddenVehicle
speed: 2.0
- type: Buckle
range: 1.0
delay: 0.5
- type: Strap
position: Stand
buckleOffset: "0,0"
size: 100
- type: Pullable
- type: Interactable
- type: UseDelay
delay: 0.5
- type: Item
size: Large
- type: RiddenVehicle
maxRiders: 1
Loading

0 comments on commit f96c8c9

Please sign in to comment.