Esempio n. 1
0
    protected IEnumerator Select()
    {
        Region testRegion = new Region () {
            Left = (int)Input.mousePosition.x - DRAG_SIZE,
            Top = Screen.height - (int)Input.mousePosition.y - DRAG_SIZE,
            Width = DRAG_SIZE * 2,
            Height = DRAG_SIZE * 2
        };
        float startTime = DRAG_TIMER;

        while (true) {
            startTime -= Time.deltaTime;
            if (!Input.GetMouseButton(0)) {
                TargetingMode = TargetingMode.ClickTargeting;
                break;
            }
            if (testRegion.ContainsMouse() == null || startTime <= 0) {
                TargetingMode = TargetingMode.DragTargeting;
                break;
            }
            yield return 0;
        }

        bool cancel = false;
        while (
            (Input.GetMouseButton(0) && TargetingMode == TargetingMode.DragTargeting) ||
            (!Input.GetMouseButton(0) && TargetingMode == TargetingMode.ClickTargeting)
        ) {
            if (Input.GetMouseButton(1)) {
                cancel = true;
                break;
            }
            yield return 0;
            if (ActiveCard.TargetingType == TargetingType.All ||
                ClickRaycast.MouseOverThis(LeftSide)
            ) {
                ReticleController.Shown = false;
                Selected.SuspendDrag = false;
            } else {
                ReticleController.Shown = true;
                Selected.SuspendDrag = true;
            }
        }
        if (ClickRaycast.MouseOverThis(LeftSide)) {
            cancel = true;
        }
        foreach (SelectionRegion pickedRegion in Sprites
                 .Where(x => typeof(SelectionRegion).IsAssignableFrom(x.GetType()))
                 .Cast<SelectionRegion>()
                 .Where(x => x.ContainsMouse())
        ) {
            Target.SetTarget(pickedRegion);
            if (
                !cancel &&
                Selected.GetCard().Cost <= Morphid.LocalPlayer.Morphium &&
                ActiveCard.TargetableGuids != null &&
                ((ActiveCard.TargetableGuids.Contains(Target.GUID)) || ActiveCard.TargetingType != TargetingType.Single)
            ) {
                Morphid.PlayLocalCard(Selected.GetCard(), Target.GUID);
                break;
            }
        }
        Selected.SuspendDrag = false;
        ReticleController.Shown = false;
        TargetingMode = TargetingMode.Inactive;
        ActiveCard = null;
        Selected.OnDrop();
        Selected.Enabled = true;
        Selected = null;
    }