public void AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return;
            }
            if (!Owner.TryGetComponent(out StackComponent stack))
            {
                return;
            }

            var location    = eventArgs.ClickLocation.AlignWithClosestGridTile();
            var locationMap = location.ToMap(Owner.EntityManager);

            var desiredTile = (ContentTileDefinition)_tileDefinitionManager[_outputTile];

            if (_mapManager.TryGetGrid(location.GetGridId(Owner.EntityManager), out var mapGrid))
            {
                var tile     = mapGrid.GetTileRef(location);
                var baseTurf = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];

                if (HasBaseTurf(desiredTile, baseTurf.Name) && eventArgs.Target == null && stack.Use(1))
                {
                    PlaceAt(mapGrid, location, desiredTile.TileId);
                }
            }
            else if (HasBaseTurf(desiredTile, "space"))
            {
                mapGrid = _mapManager.CreateGrid(locationMap.MapId);
                mapGrid.WorldPosition = locationMap.Position;
                location = new EntityCoordinates(mapGrid.GridEntityId, Vector2.Zero);
                PlaceAt(mapGrid, location, desiredTile.TileId, mapGrid.TileSize / 2f);
            }
        }
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (eventArgs.Target == null)
            {
                return(false);
            }

            if (!eventArgs.Target.HasComponent <DamageableComponent>())
            {
                return(true);
            }

            if (!EntitySystem.Get <ActionBlockerSystem>().CanInteract(eventArgs.User))
            {
                return(true);
            }

            if (eventArgs.User != eventArgs.Target &&
                !eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return(true);
            }

            if (Owner.TryGetComponent <SharedStackComponent>(out var stack) && !EntitySystem.Get <StackSystem>().Use(Owner.Uid, 1, stack))
            {
                return(true);
            }

            EntitySystem.Get <DamageableSystem>().TryChangeDamage(eventArgs.Target.Uid, Damage, true);

            return(true);
        }
Ejemplo n.º 3
0
        public void AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (eventArgs.Target == null)
            {
                return;
            }

            if (!eventArgs.Target.TryGetComponent(out ISharedBodyManagerComponent body))
            {
                return;
            }

            if (!ActionBlockerSystem.CanInteract(eventArgs.User))
            {
                return;
            }

            if (eventArgs.User != eventArgs.Target &&
                !eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return;
            }

            if (Owner.TryGetComponent(out StackComponent stack) &&
                !stack.Use(1))
            {
                return;
            }

            foreach (var(type, amount) in Heal)
            {
                body.ChangeDamage(type, -amount, true);
            }
        }
Ejemplo n.º 4
0
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (_wirePrototypeID == null)
            {
                return(true);
            }
            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return(true);
            }
            if (!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(Owner.EntityManager), out var grid))
            {
                return(true);
            }
            var snapPos = grid.TileIndicesFor(eventArgs.ClickLocation);

            if (grid.GetTileRef(snapPos).Tile.IsEmpty)
            {
                return(true);
            }
            foreach (var anchored in grid.GetAnchoredEntities(snapPos))
            {
                if (Owner.EntityManager.ComponentManager.TryGetComponent <WireComponent>(anchored, out var wire) && wire.WireType == _blockingWireType)
                {
                    return(true);
                }
            }
            if (Owner.TryGetComponent <StackComponent>(out var stack) && !stack.Use(1))
            {
                return(true);
            }
            Owner.EntityManager.SpawnEntity(_wirePrototypeID, grid.GridTileToLocal(snapPos));
            return(true);
        }
Ejemplo n.º 5
0
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: false, popup: true,
                                               collisionMask: Shared.Physics.CollisionGroup.MobImpassable))
            {
                return(true);
            }

            if (Charges <= 0)
            {
                eventArgs.User.PopupMessage(Loc.GetString("crayon-interact-not-enough-left-text"));
                return(true);
            }

            var entityManager = IoCManager.Resolve <IServerEntityManager>();

            var entity = entityManager.SpawnEntity("CrayonDecal", eventArgs.ClickLocation);

            if (entity.TryGetComponent(out AppearanceComponent? appearance))
            {
                appearance.SetData(CrayonVisuals.State, SelectedState);
                appearance.SetData(CrayonVisuals.Color, _color);
                appearance.SetData(CrayonVisuals.Rotation, eventArgs.User.Transform.LocalRotation);
            }

            if (!string.IsNullOrEmpty(_useSound))
            {
                SoundSystem.Play(Filter.Pvs(Owner), _useSound, Owner, AudioHelpers.WithVariation(0.125f));
            }

            // Decrease "Ammo"
            Charges--;
            Dirty();
            return(true);
        }
        void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return;
            }

            //Make sure we have the attacking entity
            if (eventArgs.Target == null || !Owner.TryGetComponent(out SolutionComponent? solution) || !solution.Injector)
            {
                return;
            }

            var targetEntity = eventArgs.Target;

            //Handle injecting/drawing for solutions
            if (targetEntity.TryGetComponent <SolutionComponent>(out var targetSolution) && targetSolution.Injectable)
            {
                if (_toggleState == InjectorToggleMode.Inject)
                {
                    TryInject(targetSolution, eventArgs.User);
                }
                else if (_toggleState == InjectorToggleMode.Draw)
                {
                    TryDraw(targetSolution, eventArgs.User);
                }
            }
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return(true);
            }

            if (!Owner.TryGetComponent(out StackComponent? stack))
            {
                return(true);
            }

            var mapManager = IoCManager.Resolve <IMapManager>();

            var location    = eventArgs.ClickLocation.AlignWithClosestGridTile();
            var locationMap = location.ToMap(Owner.EntityManager);

            if (locationMap.MapId == MapId.Nullspace)
            {
                return(true);
            }
            mapManager.TryGetGrid(location.GetGridId(Owner.EntityManager), out var mapGrid);

            if (_outputTiles == null)
            {
                return(true);
            }

            foreach (var currentTile in _outputTiles)
            {
                var currentTileDefinition = (ContentTileDefinition)_tileDefinitionManager[currentTile];

                if (mapGrid != null)
                {
                    var tile     = mapGrid.GetTileRef(location);
                    var baseTurf = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];

                    if (HasBaseTurf(currentTileDefinition, baseTurf.Name))
                    {
                        if (!EntitySystem.Get <StackSystem>().Use(Owner.Uid, stack, 1))
                        {
                            continue;
                        }

                        PlaceAt(mapGrid, location, currentTileDefinition.TileId);
                        break;
                    }
                }
                else if (HasBaseTurf(currentTileDefinition, "space"))
                {
                    mapGrid = mapManager.CreateGrid(locationMap.MapId);
                    mapGrid.WorldPosition = locationMap.Position;
                    location = new EntityCoordinates(mapGrid.GridEntityId, Vector2.Zero);
                    PlaceAt(mapGrid, location, _tileDefinitionManager[_outputTiles[0]].TileId, mapGrid.TileSize / 2f);
                    break;
                }
            }

            return(true);
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        public async Task AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return;
            }
            if (!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(Owner.EntityManager), out var grid))
            {
                return;
            }
            var snapPos  = grid.SnapGridCellFor(eventArgs.ClickLocation, SnapGridOffset.Center);
            var snapCell = grid.GetSnapGridCell(snapPos, SnapGridOffset.Center);

            if (grid.GetTileRef(snapPos).Tile.IsEmpty)
            {
                return;
            }
            foreach (var snapComp in snapCell)
            {
                if (snapComp.Owner.TryGetComponent <WireComponent>(out var wire) && wire.WireType == _blockingWireType)
                {
                    return;
                }
            }
            if (Owner.TryGetComponent(out StackComponent stack) && !stack.Use(1))
            {
                return;
            }
            Owner.EntityManager.SpawnEntity(_wirePrototypeID, grid.GridTileToLocal(snapPos));
        }
Ejemplo n.º 9
0
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            var solutionsSys = EntitySystem.Get <SolutionContainerSystem>();

            if (!eventArgs.InRangeUnobstructed() || eventArgs.Target == null)
            {
                return(false);
            }

            if (!_entities.HasComponent <SolutionContainerManagerComponent>(Owner))
            {
                return(false);
            }

            var target = eventArgs.Target !.Value;

            if (!_entities.HasComponent <SolutionContainerManagerComponent>(target))
            {
                return(false);
            }


            if (CanReceive && _entities.TryGetComponent(target, out ReagentTankComponent? tank) &&
                solutionsSys.TryGetRefillableSolution(Owner, out var ownerRefill) &&
                solutionsSys.TryGetDrainableSolution(target, out var targetDrain))
            {
                var transferred = DoTransfer(eventArgs.User, target, targetDrain, Owner, ownerRefill, tank.TransferAmount);
                if (transferred > 0)
                {
                    var toTheBrim = ownerRefill.AvailableVolume == 0;
                    var msg       = toTheBrim
                        ? "comp-solution-transfer-fill-fully"
                        : "comp-solution-transfer-fill-normal";

                    target.PopupMessage(eventArgs.User,
                                        Loc.GetString(msg, ("owner", eventArgs.Target), ("amount", transferred), ("target", Owner)));
                    return(true);
                }
            }

            if (CanSend && solutionsSys.TryGetRefillableSolution(target, out var targetRefill) &&
                solutionsSys.TryGetDrainableSolution(Owner, out var ownerDrain))
            {
                var transferred = DoTransfer(eventArgs.User, Owner, ownerDrain, target, targetRefill, TransferAmount);

                if (transferred > 0)
                {
                    Owner.PopupMessage(eventArgs.User,
                                       Loc.GetString("comp-solution-transfer-transfer-solution",
                                                     ("amount", transferred),
                                                     ("target", target)));

                    return(true);
                }
            }

            return(true);
        }
Ejemplo n.º 10
0
        void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return;
            }

            //Make sure we have the attacking entity
            if (eventArgs.Target == null || !Owner.TryGetComponent(out SolutionContainerComponent? solution))
            {
                return;
            }

            var targetEntity = eventArgs.Target;

            // Handle injecting/drawing for solutions
            if (targetEntity.TryGetComponent <SolutionContainerComponent>(out var targetSolution))
            {
                if (_toggleState == InjectorToggleMode.Inject)
                {
                    if (solution.CanRemoveSolutions && targetSolution.CanAddSolutions)
                    {
                        TryInject(targetSolution, eventArgs.User);
                    }
                    else
                    {
                        eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("You aren't able to transfer to {0:theName}!", targetSolution.Owner));
                    }
                }
                else if (_toggleState == InjectorToggleMode.Draw)
                {
                    if (targetSolution.CanRemoveSolutions && solution.CanAddSolutions)
                    {
                        TryDraw(targetSolution, eventArgs.User);
                    }
                    else
                    {
                        eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("You aren't able to draw from {0:theName}!", targetSolution.Owner));
                    }
                }
            }
            else // Handle injecting into bloodstream
            {
                if (targetEntity.TryGetComponent(out BloodstreamComponent? bloodstream) && _toggleState == InjectorToggleMode.Inject)
                {
                    if (solution.CanRemoveSolutions)
                    {
                        TryInjectIntoBloodstream(bloodstream, eventArgs.User);
                    }
                    else
                    {
                        eventArgs.User.PopupMessage(eventArgs.User, Loc.GetString("You aren't able to inject {0:theName}!", targetEntity));
                    }
                }
            }
        }
Ejemplo n.º 11
0
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (_cuffing)
            {
                return(true);
            }

            if (eventArgs.Target is not {
                Valid : true
            } target ||
                !EntitySystem.Get <ActionBlockerSystem>().CanUse(eventArgs.User) ||
                !_entities.TryGetComponent <CuffableComponent?>(eventArgs.Target.Value, out var cuffed))
            {
                return(false);
            }

            if (eventArgs.Target == eventArgs.User)
            {
                eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-target-self-error"));
                return(true);
            }

            if (Broken)
            {
                eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-cuffs-broken-error"));
                return(true);
            }

            if (!_entities.TryGetComponent <HandsComponent?>(target, out var hands))
            {
                eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-target-has-no-hands-error", ("targetName", eventArgs.Target)));
                return(true);
            }

            if (cuffed.CuffedHandCount >= hands.Count)
            {
                eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-target-has-no-free-hands-error", ("targetName", eventArgs.Target)));
                return(true);
            }

            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true))
            {
                eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-too-far-away-error"));
                return(true);
            }

            eventArgs.User.PopupMessage(Loc.GetString("handcuff-component-start-cuffing-target-message", ("targetName", eventArgs.Target)));
            eventArgs.User.PopupMessage(target, Loc.GetString("handcuff-component-start-cuffing-by-other-message", ("otherName", eventArgs.User)));

            SoundSystem.Play(Filter.Pvs(Owner), StartCuffSound.GetSound(), Owner);

            TryUpdateCuff(eventArgs.User, target, cuffed);
            return(true);
        }
Ejemplo n.º 12
0
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (_cuffing)
            {
                return(true);
            }

            if (eventArgs.Target == null || !ActionBlockerSystem.CanUse(eventArgs.User) || !eventArgs.Target.TryGetComponent <CuffableComponent>(out var cuffed))
            {
                return(false);
            }

            if (eventArgs.Target == eventArgs.User)
            {
                eventArgs.User.PopupMessage(Loc.GetString("You can't cuff yourself!"));
                return(true);
            }

            if (Broken)
            {
                eventArgs.User.PopupMessage(Loc.GetString("The cuffs are broken!"));
                return(true);
            }

            if (!eventArgs.Target.TryGetComponent <HandsComponent>(out var hands))
            {
                eventArgs.User.PopupMessage(Loc.GetString("{0:theName} has no hands!", eventArgs.Target));
                return(true);
            }

            if (cuffed.CuffedHandCount == hands.Count)
            {
                eventArgs.User.PopupMessage(Loc.GetString("{0:theName} has no free hands to handcuff!", eventArgs.Target));
                return(true);
            }

            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true))
            {
                eventArgs.User.PopupMessage(Loc.GetString("You are too far away to use the cuffs!"));
                return(true);
            }

            eventArgs.User.PopupMessage(Loc.GetString("You start cuffing {0:theName}.", eventArgs.Target));
            eventArgs.User.PopupMessage(eventArgs.Target, Loc.GetString("{0:theName} starts cuffing you!", eventArgs.User));

            if (StartCuffSound != null)
            {
                EntitySystem.Get <AudioSystem>().PlayFromEntity(StartCuffSound, Owner);
            }

            TryUpdateCuff(eventArgs.User, eventArgs.Target, cuffed);
            return(true);
        }
Ejemplo n.º 13
0
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed() || eventArgs.Target == null)
            {
                return(false);
            }

            if (!Owner.TryGetComponent(out ISolutionInteractionsComponent? ownerSolution))
            {
                return(false);
            }

            var target = eventArgs.Target;

            if (!target.TryGetComponent(out ISolutionInteractionsComponent? targetSolution))
            {
                return(false);
            }

            if (CanReceive && target.TryGetComponent(out ReagentTankComponent? tank) &&
                ownerSolution.CanRefill && targetSolution.CanDrain)
            {
                var transferred = DoTransfer(targetSolution, ownerSolution, tank.TransferAmount, eventArgs.User);
                if (transferred > 0)
                {
                    var toTheBrim = ownerSolution.RefillSpaceAvailable == 0;
                    var msg       = toTheBrim
                        ? "solution-transfer-component-fill-to-brim-message"
                        : "solution-transfer-component-fill--message";

                    target.PopupMessage(eventArgs.User, Loc.GetString(msg, ("owner", Owner), ("amount", transferred), ("target", target)));
                    return(true);
                }
            }

            if (CanSend && targetSolution.CanRefill && ownerSolution.CanDrain)
            {
                var transferred = DoTransfer(ownerSolution, targetSolution, TransferAmount, eventArgs.User);

                if (transferred > 0)
                {
                    Owner.PopupMessage(eventArgs.User,
                                       Loc.GetString("solution-transfer-component-transfer-success-message",
                                                     ("amount", transferred),
                                                     ("target", target)));

                    return(true);
                }
            }

            return(true);
        }
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed() || eventArgs.Target == null)
            {
                return(false);
            }

            if (!Owner.TryGetComponent(out ISolutionInteractionsComponent? ownerSolution))
            {
                return(false);
            }

            var target = eventArgs.Target;

            if (!target.TryGetComponent(out ISolutionInteractionsComponent? targetSolution))
            {
                return(false);
            }

            if (CanReceive && target.TryGetComponent(out ReagentTankComponent? tank) &&
                ownerSolution.CanRefill && targetSolution.CanDrain)
            {
                var transferred = DoTransfer(targetSolution, ownerSolution, tank.TransferAmount, eventArgs.User);
                if (transferred > 0)
                {
                    var toTheBrim = ownerSolution.RefillSpaceAvailable == 0;
                    var msg       = toTheBrim
                        ? "You fill {0:TheName} to the brim with {1}u from {2:theName}"
                        : "You fill {0:TheName} with {1}u from {2:theName}";

                    target.PopupMessage(eventArgs.User, Loc.GetString(msg, Owner, transferred, target));
                    return(true);
                }
            }

            if (CanSend && targetSolution.CanRefill && ownerSolution.CanDrain)
            {
                var transferred = DoTransfer(ownerSolution, targetSolution, TransferAmount, eventArgs.User);

                if (transferred > 0)
                {
                    Owner.PopupMessage(eventArgs.User, Loc.GetString("You transfer {0}u to {1:theName}.",
                                                                     transferred, target));

                    return(true);
                }
            }

            return(true);
        }
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (eventArgs.Target == null)
            {
                return(false);
            }

            if (!_entMan.TryGetComponent(eventArgs.Target.Value, out DamageableComponent? targetDamage))
            {
                return(true);
            }
            else if (DamageContainerID is not null && !DamageContainerID.Equals(targetDamage.DamageContainerID))
            {
                return(true);
            }

            if (!EntitySystem.Get <ActionBlockerSystem>().CanInteract(eventArgs.User))
            {
                return(true);
            }

            if (eventArgs.User != eventArgs.Target &&
                !eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return(true);
            }

            if (_entMan.TryGetComponent <SharedStackComponent?>(Owner, out var stack) && !EntitySystem.Get <StackSystem>().Use(Owner, 1, stack))
            {
                return(true);
            }

            var healed = EntitySystem.Get <DamageableSystem>().TryChangeDamage(eventArgs.Target.Value, Damage, true);

            if (healed == null)
            {
                return(true);
            }

            if (eventArgs.Target != eventArgs.User)
            {
                EntitySystem.Get <AdminLogSystem>().Add(LogType.Healed, $"{_entMan.ToPrettyString(eventArgs.User):user} healed {_entMan.ToPrettyString(eventArgs.Target.Value):target} for {healed.Total:damage} damage");
            }
            else
            {
                EntitySystem.Get <AdminLogSystem>().Add(LogType.Healed, $"{_entMan.ToPrettyString(eventArgs.User):user} healed themselves for {healed.Total:damage} damage");
            }

            return(true);
        }
        /// <inheritdoc />
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!EntitySystem.Get <ActionBlockerSystem>().CanInteract(eventArgs.User))
            {
                return(false);
            }

            if (_cablePrototypeID == null)
            {
                return(false);
            }

            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return(false);
            }

            if (!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(_entMan), out var grid))
            {
                return(false);
            }

            var snapPos = grid.TileIndicesFor(eventArgs.ClickLocation);
            var tileDef = grid.GetTileRef(snapPos).Tile.GetContentTileDefinition();

            if (!tileDef.IsSubFloor || !tileDef.Sturdy)
            {
                return(false);
            }

            foreach (var anchored in grid.GetAnchoredEntities(snapPos))
            {
                if (_entMan.TryGetComponent <CableComponent>(anchored, out var wire) && wire.CableType == _blockingCableType)
                {
                    return(false);
                }
            }

            if (_entMan.TryGetComponent <StackComponent?>(Owner, out var stack) &&
                !EntitySystem.Get <StackSystem>().Use(Owner, 1, stack))
            {
                return(false);
            }

            _entMan.SpawnEntity(_cablePrototypeID, grid.GridTileToLocal(snapPos));
            return(true);
        }
        public void AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return;
            }
            if (!Owner.TryGetComponent(out StackComponent stack))
            {
                return;
            }

            var attacked = eventArgs.Target;
            var mapGrid  = _mapManager.GetGrid(eventArgs.ClickLocation.GridID);
            var tile     = mapGrid.GetTileRef(eventArgs.ClickLocation);
            var tileDef  = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];

            if (tileDef.IsSubFloor && attacked == null && stack.Use(1))
            {
                var desiredTile = _tileDefinitionManager[_outputTile];
                mapGrid.SetTile(eventArgs.ClickLocation, new Tile(desiredTile.TileId));
                EntitySystem.Get <AudioSystem>().PlayAtCoords("/Audio/Items/genhit.ogg", eventArgs.ClickLocation);
            }
        }
Ejemplo n.º 18
0
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (eventArgs.Target == null)
            {
                return(false);
            }

            if (!eventArgs.Target.TryGetComponent(out IDamageableComponent damageable))
            {
                return(true);
            }

            if (!ActionBlockerSystem.CanInteract(eventArgs.User))
            {
                return(true);
            }

            if (eventArgs.User != eventArgs.Target &&
                !eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return(true);
            }

            if (Owner.TryGetComponent(out StackComponent stack) &&
                !stack.Use(1))
            {
                return(true);
            }

            foreach (var(type, amount) in Heal)
            {
                damageable.ChangeDamage(type, -amount, true);
            }

            return(true);
        }
Ejemplo n.º 19
0
        async Task <bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
        {
            if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: false, popup: true,
                                               collisionMask: Shared.Physics.CollisionGroup.MobImpassable))
            {
                return(true);
            }

            if (Charges <= 0)
            {
                eventArgs.User.PopupMessage(Loc.GetString("crayon-interact-not-enough-left-text"));
                return(true);
            }

            if (!eventArgs.ClickLocation.IsValid(_entMan))
            {
                eventArgs.User.PopupMessage(Loc.GetString("crayon-interact-invalid-location"));
                return(true);
            }

            if (!EntitySystem.Get <DecalSystem>().TryAddDecal(SelectedState, eventArgs.ClickLocation.Offset(new Vector2(-0.5f, -0.5f)), out _, Color.FromName(_color), cleanable: true))
            {
                return(false);
            }

            if (_useSound != null)
            {
                SoundSystem.Play(Filter.Pvs(Owner), _useSound.GetSound(), Owner, AudioHelpers.WithVariation(0.125f));
            }

            // Decrease "Ammo"
            Charges--;
            Dirty();
            EntitySystem.Get <AdminLogSystem>().Add(LogType.CrayonDraw, $"{eventArgs.User:player} drew a {_color:color} {SelectedState}");
            return(true);
        }
Ejemplo n.º 20
0
        private bool IsRCDStillValid(AfterInteractEventArgs eventArgs, IMapGrid mapGrid, TileRef tile, Vector2i snapPos, RcdMode startingMode)
        {
            //Less expensive checks first. Failing those ones, we need to check that the tile isn't obstructed.
            if (_ammo <= 0)
            {
                Owner.PopupMessage(eventArgs.User, Loc.GetString("The RCD is out of ammo!"));
                return(false);
            }

            if (_mode != startingMode)
            {
                return(false);
            }

            var coordinates = mapGrid.ToCoordinates(tile.GridIndices);

            if (coordinates == EntityCoordinates.Invalid || !eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
            {
                return(false);
            }

            switch (_mode)
            {
            //Floor mode just needs the tile to be a space tile (subFloor)
            case RcdMode.Floors:
                if (!tile.Tile.IsEmpty)
                {
                    Owner.PopupMessage(eventArgs.User, Loc.GetString("You can only build a floor on space!"));
                    return(false);
                }

                return(true);

            //We don't want to place a space tile on something that's already a space tile. Let's do the inverse of the last check.
            case RcdMode.Deconstruct:
                if (tile.Tile.IsEmpty)
                {
                    return(false);
                }

                //They tried to decon a turf but the turf is blocked
                if (eventArgs.Target == null && tile.IsBlockedTurf(true))
                {
                    Owner.PopupMessage(eventArgs.User, Loc.GetString("That tile is obstructed!"));
                    return(false);
                }
                //They tried to decon a non-turf but it's not in the whitelist
                if (eventArgs.Target != null && !eventArgs.Target.TryGetComponent(out RCDDeconstructWhitelist rcd_decon))
                {
                    Owner.PopupMessage(eventArgs.User, Loc.GetString("You can't deconstruct that!"));
                    return(false);
                }

                return(true);

            //Walls are a special behaviour, and require us to build a new object with a transform rather than setting a grid tile, thus we early return to avoid the tile set code.
            case RcdMode.Walls:
                if (tile.Tile.IsEmpty)
                {
                    Owner.PopupMessage(eventArgs.User, Loc.GetString("You cannot build a wall on space!"));
                    return(false);
                }

                if (tile.IsBlockedTurf(true))
                {
                    Owner.PopupMessage(eventArgs.User, Loc.GetString("That tile is obstructed!"));
                    return(false);
                }
                return(true);

            case RcdMode.Airlock:
                if (tile.Tile.IsEmpty)
                {
                    Owner.PopupMessage(eventArgs.User, Loc.GetString("Cannot build an airlock on space!"));
                    return(false);
                }
                if (tile.IsBlockedTurf(true))
                {
                    Owner.PopupMessage(eventArgs.User, Loc.GetString("That tile is obstructed!"));
                    return(false);
                }
                return(true);

            default:
                return(false);    //I don't know why this would happen, but sure I guess. Get out of here invalid state!
            }
        }