Ejemplo n.º 1
0
 /// <summary>
 /// Sets the highlight value of the given selection.
 /// </summary>
 /// <param name="highlighted">The highlight value to apply.</param>
 /// <param name="selection">The selection.</param>
 void SetSelectedHighlight(bool highlighted, EffectAvailableSelection selection)
 {
     if (selection.Units != null)
     {
         foreach (Sector sector in selection.Units.Select(u => u.Sector))
         {
             sector.Highlighted = highlighted;
         }
     }
     if (selection.Sectors != null)
     {
         foreach (Sector sector in selection.Sectors)
         {
             sector.Highlighted = highlighted;
         }
     }
     if (selection.Players != null)
     {
         foreach (PlayerUI playerUI in selection.Players.Select(p => p.Gui))
         {
             playerUI.Highlighted = highlighted;
         }
     }
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Processes a mouse click on the card.
    /// </summary>
    void ProcessClick()
    {
        if (!Clickable)
        {
            return;
        }
        // deselect sectors when processing click
        HumanPlayer currentPlayer = Game.Instance.CurrentPlayer as HumanPlayer;

        if (currentPlayer != null)
        {
            currentPlayer.DeselectSector();
        }

        EffectAvailableSelection selection = _effect.AvailableSelection(Game.Instance);

        if (_held)
        {
            // prevent the raycast from hitting the card
            Collider triggerCollider = gameObject.GetComponent <Collider>();
            triggerCollider.enabled = false;
            Ray        ray = _mainCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                // check if a player UI was clicked
                // and if so attempt to apply the effect to the player
                PlayerUI playerUI = hit.collider.transform.parent?.gameObject.GetComponent <PlayerUI>();
                if (playerUI != null && (selection.Players?.Contains(playerUI.Player) ?? false))
                {
                    ConsumeEffect(playerUI.Player.Stats);
                }
                // check if a sector was clicked
                // if so, check if we can apply the effect to the unit,
                // otherwise just apply the effect to the sector
                Sector sector = hit.collider.gameObject.GetComponent <Sector>();
                if (sector != null)
                {
                    if (sector.Unit != null && (selection.Units?.Contains(sector.Unit) ?? false))
                    {
                        ConsumeEffect(sector.Unit.Stats);
                    }
                    else if (selection.Sectors?.Contains(sector) ?? false)
                    {
                        ConsumeEffect(sector.Stats);
                    }
                }
            }
            triggerCollider.enabled = true;
            ClearHighlights();
            CardHeld        = _held = false;
            PositionPercent = PositionPercent;
        }
        else
        {
            // activate highlight for all relevant objects
            SetSelectedHighlight(true, selection);
            SizePercent = 0;
            CardHeld    = _held = true;
        }
    }