Example #1
0
        protected override void ReactWithEntity(IEntity entity, double solutionFraction)
        {
            if (SolutionContainerComponent == null)
            {
                return;
            }

            if (!entity.TryGetComponent(out BloodstreamComponent? bloodstream))
            {
                return;
            }

            if (entity.TryGetComponent(out InternalsComponent? internals) &&
                internals.AreInternalsWorking())
            {
                return;
            }

            var cloneSolution    = SolutionContainerComponent.Solution.Clone();
            var transferAmount   = ReagentUnit.Min(cloneSolution.TotalVolume * solutionFraction, bloodstream.EmptyVolume);
            var transferSolution = cloneSolution.SplitSolution(transferAmount);

            foreach (var reagentQuantity in transferSolution.Contents.ToArray())
            {
                if (reagentQuantity.Quantity == ReagentUnit.Zero)
                {
                    continue;
                }
                var reagent = PrototypeManager.Index <ReagentPrototype>(reagentQuantity.ReagentId);
                transferSolution.RemoveReagent(reagentQuantity.ReagentId, reagent.ReactionEntity(entity, ReactionMethod.Ingestion, reagentQuantity.Quantity));
            }

            bloodstream.TryTransferSolution(transferSolution);
        }
        private protected override Entity CreateEntity(string?prototypeName, EntityUid?uid = null)
        {
            var entity = base.CreateEntity(prototypeName, uid);

            if (prototypeName != null)
            {
                var prototype = PrototypeManager.Index <EntityPrototype>(prototypeName);

                // At this point in time, all data configure on the entity *should* be purely from the prototype.
                // As such, we can reset the modified ticks to Zero,
                // which indicates "not different from client's own deserialization".
                // So the initial data for the component or even the creation doesn't have to be sent over the wire.
                foreach (var(netId, component) in ComponentManager.GetNetComponents(entity.Uid))
                {
                    // Make sure to ONLY get components that are defined in the prototype.
                    // Others could be instantiated directly by AddComponent (e.g. ContainerManager).
                    // And those aren't guaranteed to exist on the client, so don't clear them.
                    if (prototype.Components.ContainsKey(component.Name))
                    {
                        ((Component)component).ClearTicks();
                    }
                }
            }

            return(entity);
        }