Refactor InRangeUnobstructed and add extension methods (#1925)

* Sort out InRangeUnobstructed and add extension methods

* Rename client RangeChecks to RangeExtensions

* Add container extension methods and test

* Add missing component methods

Component to container
Grid coordinates to container
Map coordinates to container
Local player to container

* Actually use the field

* Merge fixes

* Add popup argument to local player extension methods

* Reduce code repetition for client range extensions
This commit is contained in:
DrSmugleaf
2020-08-30 11:37:06 +02:00
committed by GitHub
parent 9ec3ddf368
commit 9d6c394f6b
39 changed files with 1287 additions and 359 deletions

View File

@@ -3,7 +3,6 @@ using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.Components.Power.PowerNetComponents;
using Content.Server.Interfaces;
@@ -12,7 +11,6 @@ using Content.Server.Utility;
using Content.Shared.GameObjects.Components.Power.AME;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components;
using Microsoft.EntityFrameworkCore.Internal;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.GameObjects.Components.UserInterface;
@@ -20,17 +18,12 @@ using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.ViewVariables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Content.Server.GameObjects.Components.Power.AME
@@ -87,20 +80,27 @@ namespace Content.Server.GameObjects.Components.Power.AME
return;
}
var group = GetAMENodeGroup();
if (group == null)
{
return;
}
_jarSlot.ContainedEntity.TryGetComponent<AMEFuelContainerComponent>(out var fuelJar);
if(fuelJar != null && _powerSupplier != null && fuelJar.FuelAmount > InjectionAmount)
{
_powerSupplier.SupplyRate = GetAMENodeGroup().InjectFuel(InjectionAmount);
_powerSupplier.SupplyRate = group.InjectFuel(InjectionAmount);
fuelJar.FuelAmount -= InjectionAmount;
InjectSound();
UpdateUserInterface();
}
_stability = GetAMENodeGroup().GetTotalStability();
_stability = group.GetTotalStability();
UpdateDisplay(_stability);
if(_stability <= 0) { GetAMENodeGroup().ExplodeCores(); }
if(_stability <= 0) { group.ExplodeCores(); }
}
@@ -213,7 +213,7 @@ namespace Content.Server.GameObjects.Components.Power.AME
break;
}
GetAMENodeGroup().UpdateCoreVisuals(InjectionAmount, _injecting);
GetAMENodeGroup()?.UpdateCoreVisuals(InjectionAmount, _injecting);
UpdateUserInterface();
ClickSound();
@@ -272,11 +272,11 @@ namespace Content.Server.GameObjects.Components.Power.AME
private void RefreshParts()
{
GetAMENodeGroup().RefreshAMENodes(this);
GetAMENodeGroup()?.RefreshAMENodes(this);
UpdateUserInterface();
}
private AMENodeGroup GetAMENodeGroup()
private AMENodeGroup? GetAMENodeGroup()
{
Owner.TryGetComponent(out NodeContainerComponent? nodeContainer);
@@ -285,12 +285,12 @@ namespace Content.Server.GameObjects.Components.Power.AME
.OfType<AMENodeGroup>()
.First();
return engineNodeGroup ?? default!;
return engineNodeGroup;
}
private bool IsMasterController()
{
if(GetAMENodeGroup().MasterController == this)
if(GetAMENodeGroup()?.MasterController == this)
{
return true;
}
@@ -301,10 +301,11 @@ namespace Content.Server.GameObjects.Components.Power.AME
private int GetCoreCount()
{
var coreCount = 0;
var group = GetAMENodeGroup();
if(GetAMENodeGroup() != null)
if (group != null)
{
coreCount = GetAMENodeGroup().CoreCount;
coreCount = group.CoreCount;
}
return coreCount;