Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fract war ebent update v0.7 #2034

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
112 changes: 112 additions & 0 deletions Content.Client/SS220/PlacerItem/AlignPlacerItemConstrucrion.cs
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 AlignPlacerItemConstrucrion : 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 AlignPlacerItemConstrucrion(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);
}
}
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(AlignPlacerItemConstrucrion).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);
}
}
76 changes: 76 additions & 0 deletions Content.Server/SS220/Barricade/BarricadeSystem.cs
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;
}
}
19 changes: 19 additions & 0 deletions Content.Server/SS220/EventCapturePoint/EventCapturePointSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Random;
using Robust.Shared.Timing;

namespace Content.Server.SS220.EventCapturePoint;

Expand All @@ -22,6 +23,7 @@ public sealed class EventCapturePointSystem : EntitySystem
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly IGameTiming _timing = default!;

public override void Initialize()
{
Expand All @@ -36,6 +38,23 @@ public override void Initialize()
SubscribeLocalEvent<EventCapturePointComponent, FlagRemovalFinshedEvent>(OnFlagRemoved);
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<EventCapturePointComponent>();
while (query.MoveNext(out var uid, out var component))
{
if (component.FlagEntity is not { } flagUid ||
!TryComp<EventCapturePointFlagComponent>(flagUid, out var flagComp) ||
flagComp.Fraction is not { } flagFraction)
continue;

if (!component.PointRetentionTime.TryAdd(flagFraction, TimeSpan.Zero))
component.PointRetentionTime[flagFraction] += _timing.TickPeriod;
}
}

#region Listeners
private void OnActivated(Entity<EventCapturePointComponent> entity, ref ActivateInWorldEvent args)
{
Expand Down
7 changes: 7 additions & 0 deletions Content.Server/SS220/FractWar/FractWarRuleComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// © 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
{
}
38 changes: 38 additions & 0 deletions Content.Server/SS220/FractWar/FractWarRuleSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using Content.Shared.GameTicking.Components;
using Content.Shared.SS220.EventCapturePoint;
using System.Linq;

namespace Content.Server.SS220.FractWar;

public sealed partial class FractWarRuleSystem : GameRuleSystem<FractWarRuleComponent>
{
protected override void AppendRoundEndText(EntityUid uid, FractWarRuleComponent component, GameRuleComponent gameRule, ref RoundEndTextAppendEvent args)
{
base.AppendRoundEndText(uid, component, gameRule, ref args);

args.AddLine(Loc.GetString("fractwar-round-end-score-points"));

Dictionary<string, float> fractionsWinPoints = new();
var capturePoints = EntityQueryEnumerator<EventCapturePointComponent>();
while (capturePoints.MoveNext(out _, out var capturePointComponent))
{
foreach (var (fraction, retentionTime) in capturePointComponent.PointRetentionTime)
{
var winPoints = (float)(retentionTime.TotalSeconds / capturePointComponent.RetentionTimeForWP.TotalSeconds) * capturePointComponent.WinPoints;
if (!fractionsWinPoints.TryAdd(fraction, winPoints))
fractionsWinPoints[fraction] += winPoints;
}
}

foreach (var (fraction, winPoints) in fractionsWinPoints)
{
args.AddLine(Loc.GetString("fractwar-round-end-fraction-points", ("fraction", Loc.GetString(fraction)), ("points", (int)winPoints)));
}

//Sort by value
fractionsWinPoints = fractionsWinPoints.OrderByDescending(pair => pair.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
args.AddLine(Loc.GetString("fractwar-round-end-winner", ("fraction", Loc.GetString(fractionsWinPoints.First().Key))));
}
}
5 changes: 5 additions & 0 deletions Content.Server/Spawners/Components/SpawnOnDespawnComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public sealed partial class SpawnOnDespawnComponent : Component
/// </summary>
[DataField(required: true)]
public EntProtoId Prototype = string.Empty;

// SS220 Add inherit rotation begin
[DataField]
public bool InheritRotation = false;
// SS220 Add inherit rotation end
}
16 changes: 15 additions & 1 deletion Content.Server/Spawners/EntitySystems/SpawnOnDespawnSystem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using Content.Server.Spawners.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Spawners;

namespace Content.Server.Spawners.EntitySystems;

public sealed class SpawnOnDespawnSystem : EntitySystem
{
[Dependency] private readonly MapSystem _mapSystem = default!;
[Dependency] private readonly TransformSystem _xform = default!;

public override void Initialize()
{
base.Initialize();
Expand All @@ -18,7 +22,17 @@ private void OnDespawn(EntityUid uid, SpawnOnDespawnComponent comp, ref TimedDes
if (!TryComp(uid, out TransformComponent? xform))
return;

Spawn(comp.Prototype, xform.Coordinates);
// SS220 Add inherit rotation begin
//Spawn(comp.Prototype, xform.Coordinates);

if (comp.InheritRotation)
{
var mapCords = _xform.ToMapCoordinates(GetNetCoordinates(xform.Coordinates));
Spawn(comp.Prototype, mapCords, rotation: xform.LocalRotation);
}
else
Spawn(comp.Prototype, xform.Coordinates);
// SS220 Add inherit rotation end
}

public void SetPrototype(Entity<SpawnOnDespawnComponent> entity, EntProtoId prototype)
Expand Down
Loading
Loading