Пример #1
0
    /// <summary>
    /// Sets end point of targeted ability's effect. Uses IMapClickable interface to allow the map or
    /// various characters to be targeted.
    /// </summary>
    /// <param name="target"></param>
    public virtual bool SetTarget(IMapClickable target)
    {
        bool successfulTarget = false;

        switch (target)
        {
        case MapLogic ml:
            if (CanHitGround)
            {
                TargetCharacter  = null;
                TargetLocation   = GetGlobalMousePosition();
                successfulTarget = true;
            }
            break;

        case Character c:
            if (CanHitCharacter)
            {
                TargetCharacter  = c;
                successfulTarget = true;
            }
            break;

        default:
            GD.Print($"Something went wrong clicking on {target}");
            break;
        }

        return(successfulTarget);
    }
Пример #2
0
    public override bool SetTarget(IMapClickable target)
    {
        var baseReturn = base.SetTarget(target);

        if (TargetCharacter != null)
        {
            TargetLocation = TargetCharacter.Position;
        }

        return(baseReturn);
    }
Пример #3
0
    private void HandleNonTargetInput()
    {
        if (inputDelayActive)
        {
            return;
        }

        var       mouseLocation = GetGlobalMousePosition();
        ClickInfo clickInfo     = new ClickInfo();

        if (Input.IsActionJustPressed("left_click"))         //Initial click
        {
            mousePressOrigin = mouseLocation;
        }

        if (Input.IsActionPressed("left_click") && !isMouseDragging)
        {
            if (mouseLocation.x > mousePressOrigin.x + mouseClickMoveTolerance ||
                mouseLocation.x < mousePressOrigin.x - mouseClickMoveTolerance ||
                mouseLocation.y > mousePressOrigin.y + mouseClickMoveTolerance ||
                mouseLocation.y < mousePressOrigin.y - mouseClickMoveTolerance)
            {
                isMouseDragging = true;
            }
        }

        if (isMouseDragging)
        {
            HandleMouseDrag();
        }

        if (Input.IsActionJustReleased("left_click") && !isMouseDragging)         //Mouse up, normal click
        {
            IMapClickable clickTarget = GetMostClickableAt(mouseLocation);

            clickInfo.ButtonNumber = 1;
            clickInfo.ModifyHeld   = (Input.IsActionPressed("modify"));

            if (clickTarget != null)
            {
                clickTarget.ClickAction(clickInfo, mouseLocation);
            }
        }
        else if (Input.IsActionJustReleased("left_click") && isMouseDragging)
        {
            isMouseDragging = false;
        }
    }
Пример #4
0
    /// <summary>
    /// Handles instances where multiple items found on click event.
    /// Players are immediately returned. If no players are found, the first found
    /// monster is returned. If no monsters and map logic was found, it's returned.
    /// Otherwise, null is returned.
    /// </summary>
    /// <param name="found">Array of items from intersect pt</param>
    /// <returns>"Most clickable" based on given rules as it's type</returns>
    public IMapClickable GetMostClickable(Array found)
    {
        if (found.Count == 0)
        {
            return(null);
        }

        IMapClickable mostClickable = null;

        foreach (Dictionary item in found)
        {
            if (item.Contains("collider"))
            {
                switch (item["collider"])
                {
                case PlayerCharacter pc:
                    return(pc);

                case MonsterCharacter mc:
                    if (mostClickable == null || mostClickable.GetType() != typeof(MonsterCharacter))
                    {
                        mostClickable = mc;
                    }
                    break;

                case MapLogic ml:
                    if (mostClickable == null)
                    {
                        mostClickable = ml;
                    }
                    break;

                default:
                    break;
                }
            }
        }

        return(mostClickable);
    }