Exemple #1
0
        private void Update(float frameTime, VaporComponent vapor, Solution contents, TransformComponent xform)
        {
            if (!vapor.Active)
            {
                return;
            }

            var entity = vapor.Owner;

            vapor.ReactTimer += frameTime;

            if (vapor.ReactTimer >= ReactTime && TryComp(xform.GridUid, out IMapGridComponent? gridComp))
            {
                vapor.ReactTimer = 0;

                var tile = gridComp.Grid.GetTileRef(xform.Coordinates.ToVector2i(EntityManager, _mapManager));
                foreach (var reagentQuantity in contents.Contents.ToArray())
                {
                    if (reagentQuantity.Quantity == FixedPoint2.Zero)
                    {
                        continue;
                    }
                    var reagent = _protoManager.Index <ReagentPrototype>(reagentQuantity.ReagentId);
                    _solutionContainerSystem.TryRemoveReagent(vapor.Owner, contents, reagentQuantity.ReagentId,
                                                              reagent.ReactionTile(tile, (reagentQuantity.Quantity / vapor.TransferAmount) * 0.25f));
                }
            }

            if (contents.CurrentVolume == 0)
            {
                // Delete this
                EntityManager.QueueDeleteEntity(entity);
            }
        }
 public void Start(VaporComponent vapor, Vector2 dir, float speed, EntityCoordinates target, float aliveTime)
 {
     vapor.Active    = true;
     vapor.Target    = target;
     vapor.AliveTime = aliveTime;
     // Set Move
     if (EntityManager.TryGetComponent(vapor.Owner, out PhysicsComponent? physics))
     {
         physics.BodyStatus = BodyStatus.InAir;
         physics.ApplyLinearImpulse(dir * speed);
     }
 }
Exemple #3
0
        internal bool TryAddSolution(VaporComponent vapor, Solution solution)
        {
            if (solution.TotalVolume == 0)
            {
                return(false);
            }

            if (!_solutionContainerSystem.TryGetSolution(vapor.Owner, VaporComponent.SolutionName,
                                                         out var vaporSolution))
            {
                return(false);
            }

            return(_solutionContainerSystem.TryAddSolution(vapor.Owner, vaporSolution, solution));
        }
Exemple #4
0
        private void HandleCollide(EntityUid uid, VaporComponent component, StartCollideEvent args)
        {
            if (!ComponentManager.TryGetComponent(uid, out SolutionContainerComponent? contents))
            {
                return;
            }

            contents.Solution.DoEntityReaction(args.OtherFixture.Body.Owner, ReactionMethod.Touch);

            // Check for collision with a impassable object (e.g. wall) and stop
            if ((args.OtherFixture.CollisionLayer & (int)CollisionGroup.Impassable) != 0 && args.OtherFixture.Hard)
            {
                EntityManager.QueueDeleteEntity(uid);
            }
        }
Exemple #5
0
        private void Update(float frameTime, VaporComponent vapor, Solution contents)
        {
            if (!vapor.Active)
            {
                return;
            }

            var entity = vapor.Owner;

            vapor.Timer      += frameTime;
            vapor.ReactTimer += frameTime;

            if (vapor.ReactTimer >= ReactTime && vapor.Owner.Transform.GridID.IsValid())
            {
                vapor.ReactTimer = 0;
                var mapGrid = _mapManager.GetGrid(entity.Transform.GridID);

                var tile = mapGrid.GetTileRef(entity.Transform.Coordinates.ToVector2i(EntityManager, _mapManager));
                foreach (var reagentQuantity in contents.Contents.ToArray())
                {
                    if (reagentQuantity.Quantity == ReagentUnit.Zero)
                    {
                        continue;
                    }
                    var reagent = _protoManager.Index <ReagentPrototype>(reagentQuantity.ReagentId);
                    _solutionContainerSystem.TryRemoveReagent(vapor.Owner.Uid, contents, reagentQuantity.ReagentId,
                                                              reagent.ReactionTile(tile, (reagentQuantity.Quantity / vapor.TransferAmount) * 0.25f));
                }
            }

            // Check if we've reached our target.
            if (!vapor.Reached &&
                vapor.Target.TryDistance(EntityManager, entity.Transform.Coordinates, out var distance) &&
                distance <= 0.5f)
            {
                vapor.Reached = true;
            }

            if (contents.CurrentVolume == 0 || vapor.Timer > vapor.AliveTime)
            {
                // Delete this
                entity.QueueDelete();
            }
        }
Exemple #6
0
        public void Start(VaporComponent vapor, TransformComponent vaporXform, Vector2 dir, float speed, MapCoordinates target, float aliveTime, EntityUid?user = null)
        {
            vapor.Active = true;
            var despawn = EnsureComp <TimedDespawnComponent>(vapor.Owner);

            despawn.Lifetime = aliveTime;

            // Set Move
            if (EntityManager.TryGetComponent(vapor.Owner, out PhysicsComponent? physics))
            {
                physics.LinearDamping  = 0f;
                physics.AngularDamping = 0f;

                _throwing.TryThrow(vapor.Owner, dir * speed, user: user, pushbackRatio: 50f);

                var distance = (target.Position - vaporXform.WorldPosition).Length;
                var time     = (distance / physics.LinearVelocity.Length);
                despawn.Lifetime = MathF.Min(aliveTime, time);
            }
        }
Exemple #7
0
        internal bool TryAddSolution(VaporComponent vapor, Solution solution)
        {
            if (solution.TotalVolume == 0)
            {
                return(false);
            }

            if (!vapor.Owner.TryGetComponent(out SolutionContainerComponent? contents))
            {
                return(false);
            }

            var result = contents.TryAddSolution(solution);

            if (!result)
            {
                return(false);
            }

            return(true);
        }