Merge branch 'master' into 20-06-24-movement-prediction
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
@@ -13,7 +14,7 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
public abstract class BaseCharger : Component
|
||||
{
|
||||
|
||||
public IEntity HeldItem { get; protected set; }
|
||||
protected IEntity _heldItem;
|
||||
protected ContainerSlot _container;
|
||||
protected PowerDeviceComponent _powerDevice;
|
||||
public CellChargerStatus Status => _status;
|
||||
@@ -58,37 +59,28 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will remove the item directly into the user's hand rather than the floor
|
||||
/// This will remove the item directly into the user's hand / floor
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
public void RemoveItemToHand(IEntity user)
|
||||
public void RemoveItem(IEntity user)
|
||||
{
|
||||
var heldItem = _container.ContainedEntity;
|
||||
if (heldItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
RemoveItem();
|
||||
|
||||
if (user.TryGetComponent(out HandsComponent handsComponent) &&
|
||||
heldItem.TryGetComponent(out ItemComponent itemComponent))
|
||||
_container.Remove(heldItem);
|
||||
if (user.TryGetComponent(out HandsComponent handsComponent))
|
||||
{
|
||||
handsComponent.PutInHand(itemComponent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will put the charger's item on the floor if available
|
||||
/// </summary>
|
||||
public void RemoveItem()
|
||||
{
|
||||
if (_container.ContainedEntity == null)
|
||||
{
|
||||
return;
|
||||
handsComponent.PutInHandOrDrop(heldItem.GetComponent<ItemComponent>());
|
||||
}
|
||||
|
||||
_container.Remove(HeldItem);
|
||||
HeldItem = null;
|
||||
if (heldItem.TryGetComponent(out ServerBatteryBarrelComponent batteryBarrelComponent))
|
||||
{
|
||||
batteryBarrelComponent.UpdateAppearance();
|
||||
}
|
||||
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
@@ -135,8 +127,6 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
}
|
||||
|
||||
_appearanceComponent?.SetData(CellVisual.Occupied, _container.ContainedEntity != null);
|
||||
|
||||
_status = status;
|
||||
}
|
||||
|
||||
public void OnUpdate(float frameTime)
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
@@ -53,7 +54,7 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
RemoveItemToHand(eventArgs.User);
|
||||
RemoveItem(eventArgs.User);
|
||||
}
|
||||
|
||||
[Verb]
|
||||
@@ -61,6 +62,12 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
{
|
||||
protected override void GetData(IEntity user, PowerCellChargerComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.TryGetComponent(out HandsComponent handsComponent))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
@@ -99,6 +106,12 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
{
|
||||
protected override void GetData(IEntity user, PowerCellChargerComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
if (component._container.ContainedEntity == null)
|
||||
{
|
||||
data.Text = "Eject";
|
||||
@@ -111,7 +124,7 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
|
||||
protected override void Activate(IEntity user, PowerCellChargerComponent component)
|
||||
{
|
||||
component.RemoveItem();
|
||||
component.RemoveItem(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,9 +135,8 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HeldItem = entity;
|
||||
if (!_container.Insert(HeldItem))
|
||||
|
||||
if (!_container.Insert(entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -157,7 +169,7 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
{
|
||||
// Two numbers: One for how much power actually goes into the device (chargeAmount) and
|
||||
// chargeLoss which is how much is drawn from the powernet
|
||||
_container.ContainedEntity.TryGetComponent(out PowerCellComponent cellComponent);
|
||||
var cellComponent = _container.ContainedEntity.GetComponent<PowerCellComponent>();
|
||||
var chargeLoss = cellComponent.RequestCharge(frameTime) * _transferRatio;
|
||||
_powerDevice.Load = chargeLoss;
|
||||
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan;
|
||||
using Content.Server.GameObjects.Components.Weapon.Ranged.Barrels;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
{
|
||||
@@ -26,8 +22,8 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
{
|
||||
public override string Name => "WeaponCapacitorCharger";
|
||||
public override double CellChargePercent => _container.ContainedEntity != null ?
|
||||
_container.ContainedEntity.GetComponent<HitscanWeaponCapacitorComponent>().Charge /
|
||||
_container.ContainedEntity.GetComponent<HitscanWeaponCapacitorComponent>().Capacity * 100 : 0.0f;
|
||||
_container.ContainedEntity.GetComponent<ServerBatteryBarrelComponent>().PowerCell.Charge /
|
||||
_container.ContainedEntity.GetComponent<ServerBatteryBarrelComponent>().PowerCell.Capacity * 100 : 0.0f;
|
||||
|
||||
bool IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
@@ -43,7 +39,7 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
RemoveItemToHand(eventArgs.User);
|
||||
RemoveItem(eventArgs.User);
|
||||
}
|
||||
|
||||
[Verb]
|
||||
@@ -51,6 +47,12 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
{
|
||||
protected override void GetData(IEntity user, WeaponCapacitorChargerComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.TryGetComponent(out HandsComponent handsComponent))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
@@ -94,6 +96,12 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
{
|
||||
protected override void GetData(IEntity user, WeaponCapacitorChargerComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
if (component._container.ContainedEntity == null)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Disabled;
|
||||
@@ -106,21 +114,19 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
|
||||
protected override void Activate(IEntity user, WeaponCapacitorChargerComponent component)
|
||||
{
|
||||
component.RemoveItem();
|
||||
component.RemoveItem(user);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryInsertItem(IEntity entity)
|
||||
{
|
||||
if (!entity.HasComponent<HitscanWeaponCapacitorComponent>() ||
|
||||
if (!entity.HasComponent<ServerBatteryBarrelComponent>() ||
|
||||
_container.ContainedEntity != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HeldItem = entity;
|
||||
|
||||
if (!_container.Insert(HeldItem))
|
||||
if (!_container.Insert(entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -140,8 +146,8 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
return CellChargerStatus.Empty;
|
||||
}
|
||||
|
||||
if (_container.ContainedEntity.TryGetComponent(out HitscanWeaponCapacitorComponent component) &&
|
||||
Math.Abs(component.Capacity - component.Charge) < 0.01)
|
||||
if (_container.ContainedEntity.TryGetComponent(out ServerBatteryBarrelComponent component) &&
|
||||
Math.Abs(component.PowerCell.Capacity - component.PowerCell.Charge) < 0.01)
|
||||
{
|
||||
return CellChargerStatus.Charged;
|
||||
}
|
||||
@@ -153,8 +159,8 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
{
|
||||
// Two numbers: One for how much power actually goes into the device (chargeAmount) and
|
||||
// chargeLoss which is how much is drawn from the powernet
|
||||
_container.ContainedEntity.TryGetComponent(out HitscanWeaponCapacitorComponent weaponCapacitorComponent);
|
||||
var chargeLoss = weaponCapacitorComponent.RequestCharge(frameTime) * _transferRatio;
|
||||
var powerCell = _container.ContainedEntity.GetComponent<ServerBatteryBarrelComponent>().PowerCell;
|
||||
var chargeLoss = powerCell.RequestCharge(frameTime) * _transferRatio;
|
||||
_powerDevice.Load = chargeLoss;
|
||||
|
||||
if (!_powerDevice.Powered)
|
||||
@@ -165,14 +171,13 @@ namespace Content.Server.GameObjects.Components.Power.Chargers
|
||||
|
||||
var chargeAmount = chargeLoss * _transferEfficiency;
|
||||
|
||||
weaponCapacitorComponent.AddCharge(chargeAmount);
|
||||
powerCell.AddCharge(chargeAmount);
|
||||
// Just so the sprite won't be set to 99.99999% visibility
|
||||
if (weaponCapacitorComponent.Capacity - weaponCapacitorComponent.Charge < 0.01)
|
||||
if (powerCell.Capacity - powerCell.Charge < 0.01)
|
||||
{
|
||||
weaponCapacitorComponent.Charge = weaponCapacitorComponent.Capacity;
|
||||
powerCell.Charge = powerCell.Capacity;
|
||||
}
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
Reference in New Issue
Block a user