Skip to content

Commit

Permalink
little fixes, some loc, summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeZer2 committed Jan 2, 2025
1 parent e1bead3 commit d4cdfcc
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 24 deletions.
15 changes: 8 additions & 7 deletions Content.Server/SS220/Contractor/ContractorPortalServerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

namespace Content.Server.SS220.Contractor;

/// <summary>
/// This handles...
/// </summary>
public sealed class ContractorPortalServerSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
Expand All @@ -21,11 +18,14 @@ public override void Initialize()
SubscribeLocalEvent<ContractorPortalOnTriggerComponent, StartCollideEvent>(OnEnterPortal);
}

/// <summary>
/// This is used for what doing when player enter portal
/// </summary>
private void OnEnterPortal(Entity<ContractorPortalOnTriggerComponent> ent, ref StartCollideEvent args)
{
if (!TryComp<ContractorTargetComponent>(args.OtherEntity, out var targetComponent))
{
_popup.PopupClient("Портал недоступен для вас", args.OtherEntity, PopupType.Medium);
_popup.PopupClient(Loc.GetString("contractor-portal-for-non-target"), args.OtherEntity, PopupType.Medium);
return;
}

Expand Down Expand Up @@ -56,7 +56,7 @@ private void OnEnterPortal(Entity<ContractorPortalOnTriggerComponent> ent, ref S

if (needsPortalEntity != args.OurEntity)
{
_popup.PopupClient("Этот портал предназначен не для этой цели", args.OtherEntity, PopupType.Medium);
_popup.PopupClient(Loc.GetString("contractor-portal-for-another-target"), args.OtherEntity, PopupType.Medium);
return;
}

Expand All @@ -67,9 +67,10 @@ private void OnEnterPortal(Entity<ContractorPortalOnTriggerComponent> ent, ref S
_uiSystem.ServerSendUiMessage(GetEntity(contractorComponent.PdaEntity)!.Value, ContractorPdaKey.Key, new ContractorUpdateStatsMessage());
_uiSystem.ServerSendUiMessage(GetEntity(contractorComponent.PdaEntity)!.Value, ContractorPdaKey.Key, new ContractorCompletedContractMessage());

_contractorServer.GenerateContracts((contractorEntity, contractorComponent));
_contractorServer.GenerateContracts((contractorEntity, contractorComponent)); // generate new contracts

_transformSystem.SetCoordinates(args.OtherEntity, Transform(contractorEntity).Coordinates); // tp target to other map in future
// TODO: create new warp point for another map (tajpan???)
_transformSystem.SetCoordinates(args.OtherEntity, Transform(contractorEntity).Coordinates);

Dirty(contractorPdaEntity, contractorPdaComponent);
Dirty(contractorEntity, contractorComponent);
Expand Down
42 changes: 31 additions & 11 deletions Content.Server/SS220/Contractor/ContractorServerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ public override void Update(float frameTime)
}
}

/// <summary>
/// Generate contracts on server, once time while called CompInit event
/// </summary>
private void OnContractorCompInit(Entity<ContractorComponent> ent, ref ComponentInit ev)
{
GenerateContracts(ent);
}

/// <summary>
/// Handle open portal event
/// </summary>
private void OnOpenPortalEvent(Entity<ContractorComponent> ent, ref OpenPortalContractorEvent args)
{
if (!TryComp<ContractorTargetComponent>(GetEntity(ent.Comp.CurrentContractEntity), out var target))
Expand All @@ -97,6 +103,9 @@ private void OnOpenPortalEvent(Entity<ContractorComponent> ent, ref OpenPortalCo
}

//TODO server and checks
/// <summary>
/// Raised when clicked on position button on pda
/// </summary>
private void OnNewContractAccepted(Entity<ContractorPdaComponent> ent, ref ContractorNewContractAcceptedMessage ev)
{
if (!TryComp<ContractorComponent>(ev.Actor, out var contractorComponent))
Expand All @@ -110,9 +119,7 @@ private void OnNewContractAccepted(Entity<ContractorPdaComponent> ent, ref Contr

EnsureComp<ContractorTargetComponent>(GetEntity(ev.ContractEntity), out var target);

//Only for test
/*
if (target.AmountTc > 8)
if (target.AmountTc > 8 || ev.TcReward > 8)
{
_adminLogger.Add(
LogType.Action,
Expand All @@ -121,7 +128,6 @@ private void OnNewContractAccepted(Entity<ContractorPdaComponent> ent, ref Contr

return;
}
*/

target.PortalPosition = Transform(GetEntity(ev.WarpPointEntity)).Coordinates;
target.AmountTc = ev.TcReward;
Expand All @@ -131,7 +137,7 @@ private void OnNewContractAccepted(Entity<ContractorPdaComponent> ent, ref Contr

contractorComponent.CurrentContractData = ev.ContractData;
contractorComponent.CurrentContractEntity = ev.ContractEntity;
contractorComponent.PdaEntity = ev.Entity;
//contractorComponent.PdaEntity = ev.Entity; //why this shit here?

Dirty(ev.Actor, contractorComponent);

Expand All @@ -145,7 +151,9 @@ private void OnNewContractAccepted(Entity<ContractorPdaComponent> ent, ref Contr
HandleContractAccepted(ev.ContractEntity, ev.Actor);
}

// TODO on server //DONE
/// <summary>
/// Raised when clicked on execute button, then doAfter, then open portal.
/// </summary>
private void OnExecuteContract(Entity<ContractorPdaComponent> ent, ref ContractorExecutionButtonPressedMessage ev)
{
var entity = GetEntity(ent.Comp.CurrentContractEntity);
Expand Down Expand Up @@ -195,6 +203,11 @@ private void OnBuyContractorKit(StoreBuyListingMessage ev)
EnsureComp<ContractorComponent>(ev.Actor);
}

/// <summary>
/// When contractor accepts new contract, remove this contract from other contractors and generate another contract for them
/// </summary>
/// <param name="acceptedPlayer">Target, on what contractor accepted</param>
/// <param name="contractor">Contractor, who accepted</param>
public void HandleContractAccepted(NetEntity acceptedPlayer, EntityUid contractor)
{
var query = EntityQueryEnumerator<ContractorComponent>();
Expand All @@ -210,7 +223,7 @@ public void HandleContractAccepted(NetEntity acceptedPlayer, EntityUid contracto
if (contractorComp.Contracts.Count >= 5)
continue;

var newContract = GenerateContractForContractor(uid);
var newContract = GenerateContractForContractor((uid, contractorComp));

if (newContract != null)
{
Expand All @@ -223,7 +236,12 @@ public void HandleContractAccepted(NetEntity acceptedPlayer, EntityUid contracto
}
}

private (NetEntity Target, ContractorContract Contract)? GenerateContractForContractor(EntityUid contractor)
/// <summary>
/// Generate a new contract or contracts for contractors, if another contractor has accepted their contract
/// </summary>
/// <param name="contractor"></param>
/// <returns></returns>
private (NetEntity Target, ContractorContract Contract)? GenerateContractForContractor(Entity<ContractorComponent> contractor)
{
var playerPool = _playerManager.Sessions
.Where(p => p is { Status: SessionStatus.InGame, AttachedEntity: not null })
Expand All @@ -242,6 +260,9 @@ public void HandleContractAccepted(NetEntity acceptedPlayer, EntityUid contracto
continue;
}

if (contractor.Comp.Contracts.ContainsKey(GetNetEntity(player)))
continue;

if (!_mindSystem.TryGetMind(player, out var mindId, out _))
continue;

Expand Down Expand Up @@ -336,7 +357,7 @@ public void GenerateContracts(Entity<ContractorComponent> ent)
return allLocations;
}

public bool IsCloseWithPosition(NetEntity playerNet)
private bool IsCloseWithPosition(NetEntity playerNet)
{
var player = GetEntity(playerNet);

Expand All @@ -357,10 +378,9 @@ public bool IsCloseWithPosition(NetEntity playerNet)

var targetPortalPosition = targetComponent.PortalPosition.Position;


var isPlayerCloseToPortal = (playerPosition - targetPortalPosition).Length() < 1f;
var isTargetCloseToPortal = (targetPosition - targetPortalPosition).Length() < 1f;

return isPlayerCloseToPortal && isTargetCloseToPortal; //tile distance
return isPlayerCloseToPortal && isTargetCloseToPortal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Content.Shared.SS220.Contractor;

/// <summary>
/// This is used for...
/// This is used for marking a portal.
/// </summary>
[RegisterComponent]
[NetworkedComponent]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Content.Shared.SS220.Contractor;

/// <summary>
/// This is used for...
/// This is used for marking target for contractor.
/// </summary>
[RegisterComponent]
[NetworkedComponent]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Content.Shared.SS220.Contractor;

/// <summary>
/// This is a prototype for...
/// This is a prototype for contractor items in uplink.
/// </summary>
[Serializable, NetSerializable, Prototype("contractorItems")]
public sealed partial class SharedContractorItemPrototype : IPrototype
Expand Down
23 changes: 21 additions & 2 deletions Content.Shared/SS220/Contractor/SharedContractorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ public abstract class SharedContractorSystem : EntitySystem

public override void Initialize()
{
SubscribeLocalEvent<ContractorPdaComponent, ComponentInit>(OnContractorPdaMapInit);
SubscribeLocalEvent<ContractorPdaComponent, ComponentInit>(OnContractorPdaCompInit);
SubscribeLocalEvent<ContractorPdaComponent, BoundUIOpenedEvent>(OnOpenUI);
SubscribeLocalEvent<ContractorPdaComponent, ContractorHubBuyItemMessage>(OnBuyItem);
}

private void OnContractorPdaMapInit(Entity<ContractorPdaComponent> ent, ref ComponentInit args)
/// <summary>
/// On CompInit pda generate available items
/// </summary>
/// <param name="ent">Entity pda</param>
/// <param name="args">Event</param>
private void OnContractorPdaCompInit(Entity<ContractorPdaComponent> ent, ref ComponentInit args)
{
if (ent.Comp.AvailableItems.Count > 0)
return;
Expand All @@ -32,6 +37,10 @@ private void OnContractorPdaMapInit(Entity<ContractorPdaComponent> ent, ref Comp
}
}

/// <summary>
/// Will generate a pda owner once for the person who first opened it
/// </summary>
/// <param name="ent">PDA entity</param>
private void OnOpenUI(Entity<ContractorPdaComponent> ent, ref BoundUIOpenedEvent args)
{
if (ent.Comp.PdaOwner != null)
Expand All @@ -50,6 +59,9 @@ private void OnOpenUI(Entity<ContractorPdaComponent> ent, ref BoundUIOpenedEvent
Dirty(ent);
}

/// <summary>
/// Raise event for buying an item, but only if buyer is pda owner
/// </summary>
private void OnBuyItem(Entity<ContractorPdaComponent> ent, ref ContractorHubBuyItemMessage ev)
{
if (!TryComp<ContractorComponent>(ev.Actor, out var contractorComponent))
Expand All @@ -72,6 +84,10 @@ private void OnBuyItem(Entity<ContractorPdaComponent> ent, ref ContractorHubBuyI
Dirty(ev.Actor, contractorComponent);
}

/// <summary>
/// Used in bound ui on client, to get contracts for pda
/// </summary>
/// <returns>Return dictionary of contracts</returns>
public Dictionary<NetEntity, ContractorContract>? GetContractsForPda(EntityUid contractor, EntityUid pdaEntity)
{
AddContractsToPda(contractor, pdaEntity);
Expand All @@ -91,6 +107,9 @@ private void AddContractsToPda(EntityUid contractor, EntityUid pdaEntity)

}

/// <summary>
/// Event for opening a portal
/// </summary>
[Serializable, NetSerializable]
public sealed partial class OpenPortalContractorEvent : DoAfterEvent
{
Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/ru-RU/ss220/contractor/contractor.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
contractor-uplink-current-reputation = Текущая репутация: {$currentReputation}
contractor-uplink-current-tc = Имеется ТК: {$amountTc}
contractor-uplink-current-contracts-completed = Выполнено контрактов: {$amountContractsCompleted}
contractor-portal-for-non-target = Портал недоступен для вас
contractor-portal-for-another-target = Этот портал предназначен не для этой цели
1 change: 0 additions & 1 deletion Resources/Prototypes/SS220/Antags/contractor_items.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
shape:
- 0,0,2,2
- type: Storage
maxItemSize: Small
grid:
- 0,0,6,4
- type: Sprite
Expand Down

0 comments on commit d4cdfcc

Please sign in to comment.