Make masks & some helmets block eating/drinkling (#5656)

This commit is contained in:
Leon Friedrich
2021-12-03 03:51:05 +13:00
committed by GitHub
parent 44871eb95e
commit a9c3153a55
8 changed files with 143 additions and 4 deletions

View File

@@ -25,6 +25,10 @@ using Robust.Shared.Player;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.Utility;
using Content.Server.Inventory.Components;
using Content.Shared.Inventory;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Tag;
namespace Content.Server.Nutrition.EntitySystems
{
@@ -135,6 +139,14 @@ namespace Content.Server.Nutrition.EntitySystems
!_bodySystem.TryGetComponentsOnMechanisms<StomachComponent>(userUid, out var stomachs, body))
return false;
if (IsMouthBlocked(userUid, out var blocker))
{
var name = EntityManager.GetComponent<MetaDataComponent>(blocker.Value).EntityName;
_popupSystem.PopupEntity(Loc.GetString("food-system-remove-mask", ("entity", name)),
userUid, Filter.Entities(userUid));
return true;
}
var usedUtensils = new List<UtensilComponent>();
if (!TryGetRequiredUtensils(userUid, component, out var utensils))
@@ -252,6 +264,14 @@ namespace Content.Server.Nutrition.EntitySystems
return true;
}
if (IsMouthBlocked(targetUid, out var blocker))
{
var name = EntityManager.GetComponent<MetaDataComponent>(blocker.Value).EntityName;
_popupSystem.PopupEntity(Loc.GetString("food-system-remove-mask", ("entity", name)),
userUid, Filter.Entities(userUid));
return true;
}
if (!TryGetRequiredUtensils(userUid, food, out var utensils))
return true;
@@ -344,6 +364,9 @@ namespace Content.Server.Nutrition.EntitySystems
if (!Resolve(uid, ref food) || !Resolve(target, ref body, false))
return;
if (IsMouthBlocked(target, out _))
return;
if (!_solutionContainerSystem.TryGetSolution(uid, food.SolutionName, out var foodSolution))
return;
@@ -367,7 +390,9 @@ namespace Content.Server.Nutrition.EntitySystems
_logSystem.Add(LogType.ForceFeed, $"{edible} was thrown into the mouth of {targetEntity}");
else
_logSystem.Add(LogType.ForceFeed, $"{userEntity} threw {edible} into the mouth of {targetEntity}");
_popupSystem.PopupEntity(Loc.GetString(food.EatMessage), target, Filter.Entities(target));
var filter = (user == null) ? Filter.Entities(target) : Filter.Entities(target, user.Value);
_popupSystem.PopupEntity(Loc.GetString(food.EatMessage), target, filter);
foodSolution.DoEntityReaction(uid, ReactionMethod.Ingestion);
_stomachSystem.TryTransferSolution(firstStomach.Value.Comp.OwnerUid, foodSolution, firstStomach.Value.Comp);
@@ -421,6 +446,39 @@ namespace Content.Server.Nutrition.EntitySystems
{
args.Food.InUse = false;
}
/// <summary>
/// Is an entity's mouth accessible, or is it blocked by something like a mask? Does not actually check if
/// the user has a mouth. Body system when?
/// </summary>
public bool IsMouthBlocked(EntityUid uid, [NotNullWhen(true)] out EntityUid? blockingEntity,
InventoryComponent? inventory = null)
{
blockingEntity = null;
if (!Resolve(uid, ref inventory, false))
return false;
// check masks
if (inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.MASK, out ItemComponent? mask))
{
// For now, lets just assume that any masks always covers the mouth
// TODO MASKS if the ability is added to raise/lower masks, this needs to be updated.
blockingEntity = mask.OwnerUid;
return true;
}
// check helmets. Note that not all helmets cover the face.
if (inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.HEAD, out ItemComponent? head) &&
EntityManager.TryGetComponent(head.OwnerUid, out TagComponent tag) &&
tag.HasTag("ConcealsFace"))
{
blockingEntity = head.OwnerUid;
return true;
}
return false;
}
}
public sealed class ForceFeedEvent : EntityEventArgs