private void TryDraw(SolutionContainerComponent targetSolution, IEntity user) { if (!Owner.TryGetComponent(out SolutionContainerComponent? solution) || solution.EmptyVolume == 0) { return; } // Get transfer amount. May be smaller than _transferAmount if not enough room var realTransferAmount = ReagentUnit.Min(_transferAmount, targetSolution.CurrentVolume); if (realTransferAmount <= 0) { Owner.PopupMessage(user, Loc.GetString("{0:theName} is empty!", targetSolution.Owner)); return; } // Move units from attackSolution to targetSolution var removedSolution = targetSolution.SplitSolution(realTransferAmount); if (!solution.TryAddSolution(removedSolution)) { return; } Owner.PopupMessage(user, Loc.GetString("Drew {0}u from {1:theName}", removedSolution.TotalVolume, targetSolution.Owner)); Dirty(); }
public override bool TryUseFood(IEntity user, IEntity target, UtensilComponent utensilUsed = null) { if (user == null) { return(false); } var trueTarget = target ?? user; if (!trueTarget.TryGetComponent(out IBody body) || !body.TryGetMechanismBehaviors <StomachBehavior>(out var stomachs)) { return(false); } if (!user.InRangeUnobstructed(trueTarget, popup: true)) { return(false); } var transferAmount = ReagentUnit.Min(_transferAmount, _contents.CurrentVolume); var split = _contents.SplitSolution(transferAmount); var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split)); if (firstStomach == null) { _contents.TryAddSolution(split); trueTarget.PopupMessage(user, Loc.GetString("You can't eat any more!")); return(false); } // TODO: Account for partial transfer. foreach (var(reagentId, quantity) in split.Contents) { if (!_prototypeManager.TryIndex(reagentId, out ReagentPrototype reagent)) { continue; } split.RemoveReagent(reagentId, reagent.ReactionEntity(trueTarget, ReactionMethod.Ingestion, quantity)); } firstStomach.TryTransferSolution(split); if (_useSound != null) { _entitySystem.GetEntitySystem <AudioSystem>() .PlayFromEntity(_useSound, trueTarget, AudioParams.Default.WithVolume(-1f)); } trueTarget.PopupMessage(user, Loc.GetString("You swallow the pill.")); Owner.Delete(); return(true); }
public override bool TryUseFood(IEntity?user, IEntity?target, UtensilComponent?utensilUsed = null) { if (user == null) { return(false); } var trueTarget = target ?? user; if (!trueTarget.TryGetComponent(out IBody? body) || !body.TryGetMechanismBehaviors <StomachBehavior>(out var stomachs)) { return(false); } if (!user.InRangeUnobstructed(trueTarget, popup: true)) { return(false); } var transferAmount = ReagentUnit.Min(TransferAmount, _contents.CurrentVolume); var split = _contents.SplitSolution(transferAmount); var firstStomach = stomachs.FirstOrDefault(stomach => stomach.CanTransferSolution(split)); if (firstStomach == null) { _contents.TryAddSolution(split); trueTarget.PopupMessage(user, Loc.GetString("You can't eat any more!")); return(false); } // TODO: Account for partial transfer. split.DoEntityReaction(trueTarget, ReactionMethod.Ingestion); firstStomach.TryTransferSolution(split); if (UseSound != null) { SoundSystem.Play(Filter.Pvs(trueTarget), UseSound, trueTarget, AudioParams.Default.WithVolume(-1f)); } trueTarget.PopupMessage(user, Loc.GetString("You swallow the pill.")); Owner.Delete(); return(true); }
public override bool TryUseFood(IEntity user, IEntity target, UtensilComponent utensilUsed = null) { if (user == null) { return(false); } var trueTarget = target ?? user; if (!trueTarget.TryGetComponent(out StomachComponent stomach)) { return(false); } if (!user.InRangeUnobstructed(trueTarget, popup: true)) { return(false); } var transferAmount = ReagentUnit.Min(_transferAmount, _contents.CurrentVolume); var split = _contents.SplitSolution(transferAmount); if (!stomach.TryTransferSolution(split)) { _contents.TryAddSolution(split); trueTarget.PopupMessage(user, Loc.GetString("You can't eat any more!")); return(false); } if (_useSound != null) { _entitySystem.GetEntitySystem <AudioSystem>() .PlayFromEntity(_useSound, trueTarget, AudioParams.Default.WithVolume(-1f)); } trueTarget.PopupMessage(user, Loc.GetString("You swallow the pill.")); Owner.Delete(); return(true); }