forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
80 changed files
with
491,324 additions
and
266,012 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
112 changes: 112 additions & 0 deletions
112
Content.Client/SS220/PlacerItem/AlignPlacerItemConstruction.cs
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,112 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
|
||
using Content.Client.Gameplay; | ||
using Content.Shared.Hands.Components; | ||
using Content.Shared.Interaction; | ||
using Content.Shared.RCD.Systems; | ||
using Content.Shared.SS220.PlacerItem.Components; | ||
using Content.Shared.SS220.PlacerItem.Systems; | ||
using Robust.Client.Placement; | ||
using Robust.Client.Player; | ||
using Robust.Client.State; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Map.Components; | ||
using System.Numerics; | ||
|
||
namespace Content.Client.SS220.PlacerItem; | ||
|
||
public sealed class AlignPlacerItemConstruction : PlacementMode | ||
{ | ||
[Dependency] private readonly IEntityManager _entityManager = default!; | ||
[Dependency] private readonly IPlayerManager _playerManager = default!; | ||
[Dependency] private readonly IStateManager _stateManager = default!; | ||
[Dependency] private readonly IMapManager _mapManager = default!; | ||
|
||
private readonly RCDSystem _rcdSystem; | ||
private readonly PlacerItemSystem _placerItemSystem; | ||
private readonly SharedTransformSystem _transformSystem; | ||
private readonly SharedMapSystem _mapSystem; | ||
|
||
private const float SearchBoxSize = 2f; | ||
private const float PlaceColorBaseAlpha = 0.5f; | ||
|
||
private EntityCoordinates _unalignedMouseCoords = default; | ||
|
||
public AlignPlacerItemConstruction(PlacementManager pMan) : base(pMan) | ||
{ | ||
IoCManager.InjectDependencies(this); | ||
_rcdSystem = _entityManager.System<RCDSystem>(); | ||
_placerItemSystem = _entityManager.System<PlacerItemSystem>(); | ||
_transformSystem = _entityManager.System<SharedTransformSystem>(); | ||
_mapSystem = _entityManager.System<SharedMapSystem>(); | ||
|
||
ValidPlaceColor = ValidPlaceColor.WithAlpha(PlaceColorBaseAlpha); | ||
} | ||
|
||
public override void AlignPlacementMode(ScreenCoordinates mouseScreen) | ||
{ | ||
_unalignedMouseCoords = ScreenToCursorGrid(mouseScreen); | ||
MouseCoords = _unalignedMouseCoords.AlignWithClosestGridTile(SearchBoxSize, _entityManager, _mapManager); | ||
|
||
var gridId = _transformSystem.GetGrid(MouseCoords); | ||
if (!_entityManager.TryGetComponent<MapGridComponent>(gridId, out var mapGrid)) | ||
return; | ||
|
||
CurrentTile = _mapSystem.GetTileRef(gridId.Value, mapGrid, MouseCoords); | ||
|
||
float tileSize = mapGrid.TileSize; | ||
GridDistancing = tileSize; | ||
|
||
if (pManager.CurrentPermission!.IsTile) | ||
{ | ||
MouseCoords = new EntityCoordinates(MouseCoords.EntityId, new Vector2(CurrentTile.X + tileSize / 2, | ||
CurrentTile.Y + tileSize / 2)); | ||
} | ||
else | ||
{ | ||
MouseCoords = new EntityCoordinates(MouseCoords.EntityId, new Vector2(CurrentTile.X + tileSize / 2 + pManager.PlacementOffset.X, | ||
CurrentTile.Y + tileSize / 2 + pManager.PlacementOffset.Y)); | ||
} | ||
} | ||
|
||
public override bool IsValidPosition(EntityCoordinates position) | ||
{ | ||
var player = _playerManager.LocalSession?.AttachedEntity; | ||
|
||
// If the destination is out of interaction range, set the placer alpha to zero | ||
if (!_entityManager.TryGetComponent<TransformComponent>(player, out var xform)) | ||
return false; | ||
|
||
if (!_transformSystem.InRange(xform.Coordinates, position, SharedInteractionSystem.InteractionRange)) | ||
{ | ||
InvalidPlaceColor = InvalidPlaceColor.WithAlpha(0); | ||
return false; | ||
} | ||
// Otherwise restore the alpha value | ||
else | ||
{ | ||
InvalidPlaceColor = InvalidPlaceColor.WithAlpha(PlaceColorBaseAlpha); | ||
} | ||
|
||
if (!_entityManager.TryGetComponent<HandsComponent>(player, out var hands)) | ||
return false; | ||
|
||
var heldEntity = hands.ActiveHand?.HeldEntity; | ||
|
||
if (!_entityManager.TryGetComponent<PlacerItemComponent>(heldEntity, out var placerItemComp)) | ||
return false; | ||
|
||
if (!_rcdSystem.TryGetMapGridData(position, out var mapGridData)) | ||
return false; | ||
|
||
// Determine if the user is hovering over a target | ||
var currentState = _stateManager.CurrentState; | ||
|
||
if (currentState is not GameplayStateBase screen) | ||
return false; | ||
|
||
var target = screen.GetClickedEntity(_transformSystem.ToMapCoordinates(_unalignedMouseCoords)); | ||
|
||
return _placerItemSystem.IsPlacementOperationStillValid((heldEntity.Value, placerItemComp), mapGridData.Value, target, player.Value); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
Content.Client/SS220/PlacerItem/PlacerItemConstructionGhostSystem.cs
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,72 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
|
||
using Content.Shared.Hands.Components; | ||
using Content.Shared.Interaction; | ||
using Content.Shared.SS220.PlacerItem; | ||
using Content.Shared.SS220.PlacerItem.Components; | ||
using Robust.Client.Placement; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Enums; | ||
|
||
namespace Content.Client.SS220.PlacerItem; | ||
|
||
public sealed class PlacerItemConstructionGhostSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IPlayerManager _playerManager = default!; | ||
[Dependency] private readonly IPlacementManager _placementManager = default!; | ||
|
||
private string _placementMode = typeof(AlignPlacerItemConstruction).Name; | ||
private Direction _placementDirection = default; | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
|
||
var placerEntity = _placementManager.CurrentPermission?.MobUid; | ||
var placerProto = _placementManager.CurrentPermission?.EntityType; | ||
var placerIsPlacerItem = HasComp<PlacerItemComponent>(placerEntity); | ||
|
||
if (_placementManager.Eraser || | ||
(placerEntity != null && !placerIsPlacerItem)) | ||
return; | ||
|
||
var player = _playerManager.LocalSession?.AttachedEntity; | ||
if (!TryComp<HandsComponent>(player, out var hands)) | ||
return; | ||
|
||
var heldEntity = hands.ActiveHand?.HeldEntity; | ||
if (!TryComp<PlacerItemComponent>(heldEntity, out var comp) || !comp.Active) | ||
{ | ||
if (placerIsPlacerItem) | ||
{ | ||
_placementManager.Clear(); | ||
_placementDirection = default; | ||
} | ||
|
||
return; | ||
} | ||
|
||
// Update the direction | ||
if (_placementDirection != _placementManager.Direction) | ||
{ | ||
_placementDirection = _placementManager.Direction; | ||
RaiseNetworkEvent(new PlacerItemUpdateDirectionEvent(GetNetEntity(heldEntity.Value), _placementDirection)); | ||
} | ||
|
||
if (heldEntity == placerEntity && placerProto == comp.SpawnProto.Id) | ||
return; | ||
|
||
var newObjInfo = new PlacementInformation | ||
{ | ||
MobUid = heldEntity.Value, | ||
EntityType = comp.ConstructionGhostProto ?? comp.SpawnProto, | ||
PlacementOption = _placementMode, | ||
Range = (int)Math.Ceiling(SharedInteractionSystem.InteractionRange), | ||
IsTile = false, | ||
UseEditorContext = false, | ||
}; | ||
|
||
_placementManager.Clear(); | ||
_placementManager.BeginPlacing(newObjInfo); | ||
} | ||
} |
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,76 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
using Content.Shared.Projectiles; | ||
using Content.Shared.SS220.Barricade; | ||
using Microsoft.Extensions.DependencyModel; | ||
using Robust.Server.GameObjects; | ||
using Robust.Shared.Random; | ||
using System.Numerics; | ||
|
||
namespace Content.Server.SS220.Barricade; | ||
|
||
public sealed partial class BarricadeSystem : SharedBarricadeSystem | ||
{ | ||
[Dependency] private readonly TransformSystem _transform = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
|
||
protected override bool HitscanTryPassBarricade(Entity<BarricadeComponent> entity, EntityUid source, TransformComponent? sourceXform = null) | ||
{ | ||
if (!Resolve(source, ref sourceXform)) | ||
return false; | ||
|
||
var hitChance = CalculateHitChance(entity, sourceXform.GridUid, sourceXform.LocalPosition, _transform.GetWorldPosition(source)); | ||
var isHit = _random.Prob(hitChance); | ||
|
||
return !isHit; | ||
} | ||
|
||
protected override bool ProjectileTryPassBarricade(Entity<BarricadeComponent> entity, Entity<ProjectileComponent> projEnt) | ||
{ | ||
var (uid, comp) = entity; | ||
var (projUid, projComp) = projEnt; | ||
|
||
var passBarricade = EnsureComp<PassBarricadeComponent>(projUid); | ||
if (passBarricade.CollideBarricades.TryGetValue(uid, out var isPass)) | ||
return isPass; | ||
|
||
var hitChance = CalculateHitChance(entity, projComp.ShootGridUid, projComp.ShootGridPos, projComp.ShootWorldPos); | ||
var isHit = _random.Prob(hitChance); | ||
|
||
passBarricade.CollideBarricades.Add(uid, !isHit); | ||
Dirty(projUid, passBarricade); | ||
|
||
return !isHit; | ||
} | ||
|
||
private float CalculateHitChance(Entity<BarricadeComponent> entity, EntityUid? gridUid = null, Vector2? gridPos = null, Vector2? worldPos = null) | ||
{ | ||
var (uid, comp) = entity; | ||
var xform = Transform(entity); | ||
|
||
float distance; | ||
if (gridUid != null && gridPos != null && xform.ParentUid == gridUid) | ||
{ | ||
var posDiff = xform.LocalPosition - gridPos; | ||
distance = posDiff.Value.Length(); | ||
} | ||
else if (worldPos != null) | ||
{ | ||
var posDiff = _transform.GetWorldPosition(uid) - worldPos; | ||
distance = posDiff.Value.Length(); | ||
} | ||
else | ||
{ | ||
distance = comp.MaxDistance; | ||
} | ||
|
||
var distanceDiff = comp.MaxDistance - comp.MinDistance; | ||
var chanceDiff = comp.MaxHitChance - comp.MinHitChance; | ||
|
||
/// How much the <see cref="BarricadeComponent.MinHitChances"/> will increase. | ||
var increaseChance = Math.Clamp(distance - comp.MinDistance, 0, distanceDiff) / distanceDiff * chanceDiff; | ||
|
||
var hitChance = Math.Clamp(comp.MinHitChance + increaseChance, comp.MinHitChance, comp.MaxHitChance); | ||
|
||
return hitChance; | ||
} | ||
} |
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,9 @@ | ||
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt | ||
namespace Content.Server.SS220.FractWar; | ||
|
||
[RegisterComponent] | ||
public sealed partial class FractWarRuleComponent : Component | ||
{ | ||
[ViewVariables] | ||
public Dictionary<string, float> FractionsWinPoints = []; | ||
} |
Oops, something went wrong.