public bool ValidateEntityTarget(EntityUid user, EntityUid target, EntityTargetAction action)
    {
        if (!target.IsValid() || Deleted(target))
        {
            return(false);
        }

        if (action.Whitelist != null && !action.Whitelist.IsValid(target, EntityManager))
        {
            return(false);
        }

        if (action.CheckCanInteract && !_actionBlockerSystem.CanInteract(user, target))
        {
            return(false);
        }

        if (user == target)
        {
            return(action.CanTargetSelf);
        }

        if (!action.CheckCanAccess)
        {
            // even if we don't check for obstructions, we may still need to check the range.
            var xform       = Transform(user);
            var targetXform = Transform(target);

            if (xform.MapID != targetXform.MapID)
            {
                return(false);
            }

            if (action.Range <= 0)
            {
                return(true);
            }

            return((xform.WorldPosition - targetXform.WorldPosition).Length <= action.Range);
        }

        if (_interactionSystem.InRangeUnobstructed(user, target, range: action.Range) &&
            _containerSystem.IsInSameOrParentContainer(user, target))
        {
            return(true);
        }

        return(_interactionSystem.CanAccessViaStorage(user, target));
    }
Exemple #2
0
    private void OnInit(EntityUid uid, SpellbookComponent component, ComponentInit args)
    {
        //Negative charges means the spell can be used without it running out.
        foreach (var(id, charges) in component.WorldSpells)
        {
            var spell = new WorldTargetAction(_prototypeManager.Index <WorldTargetActionPrototype>(id));
            _actionsSystem.SetCharges(spell, charges < 0 ? null : charges);
            component.Spells.Add(spell);
        }

        foreach (var(id, charges) in component.InstantSpells)
        {
            var spell = new InstantAction(_prototypeManager.Index <InstantActionPrototype>(id));
            _actionsSystem.SetCharges(spell, charges < 0 ? null : charges);
            component.Spells.Add(spell);
        }

        foreach (var(id, charges) in component.EntitySpells)
        {
            var spell = new EntityTargetAction(_prototypeManager.Index <EntityTargetActionPrototype>(id));
            _actionsSystem.SetCharges(spell, charges < 0 ? null : charges);
            component.Spells.Add(spell);
        }
    }
Exemple #3
0
 public RequestPerformActionEvent(EntityTargetAction action, EntityUid entityTarget)
 {
     Action       = action;
     EntityTarget = entityTarget;
 }
 public EntityTargetAction(EntityTargetAction toClone)
 {
     CopyFrom(toClone);
 }