예제 #1
0
    public void AudienceTargetedSpace(Audience currentAudience, List <GridSpace> damageSpaces, bool middleTileMat = false, UnityAction onEnter = null, UnityAction onExit = null)
    {
        UnityAction onTileClick = delegate
        {
            currentAudience.CheckAbility(this);

            GridManager.DeactivateTiles.Invoke();

            GameToolTipManager.Instance.ShowAttackRange(true);
            ResetDamageNumbers.Invoke();
        };

        UnityAction onTileEnter = delegate
        {
            if (middleTileMat)
            {
                gridButton.material = TileButton.moveHover;
            }

            int audienceDamage = AudienceManager.Instance.GetAudienceDamage(currentAudience.CurrentAudienceType);
            if (audienceDamage > 0 && IsObjectType(ObjectType.Unit))
            {
                GetCharacter().PassDamageNumber(audienceDamage);
            }

            foreach (GridSpace tile in damageSpaces)
            {
                if (!tile.Equals(this))
                {
                    tile.gridButton.UpdateState(ButtonState.AreaOfEffect);

                    int audienceRowDamage = AudienceManager.Instance.GetAudienceDamage(currentAudience.CurrentAudienceType, true);

                    if (audienceRowDamage >= 0 && tile.TryGetCharacter(out GameCharacter unit))
                    {
                        if (currentAudience.CurrentAudienceType == AudienceType.Star && !tile.HasPlayer())
                        {
                            if (unit.GridUnit.WillHitObstacle(out GridObject obstacle, this, 1))
                            {
                                unit.PassDamageNumber(audienceRowDamage + Knockbackable.KnockbackDamage);

                                if (obstacle is GridUnit obstacleUnit)
                                {
                                    obstacleUnit.Character.PassDamageNumber(Knockbackable.KnockbackDamage);
                                }

                                continue;
                            }
                        }

                        unit.PassDamageNumber(audienceRowDamage);
                    }
                }
            }

            if (onEnter != null)
            {
                onEnter.Invoke();
            }
            gridButton.UpdateState(ButtonState.AreaOfEffect);
        };

        UnityAction onTileExit = delegate
        {
            gridButton.UpdateState(ButtonState.Targeted);
            // Debug.Log("Grid Button Exit");

            GridSpace.ResetDamageNumbers.Invoke();

            foreach (GridSpace tile in damageSpaces)
            {
                if (tile != this)
                {
                    tile.gridButton.UpdateState();
                }
            }

            if (onExit != null)
            {
                onExit.Invoke();
            }
        };

        gridButton.UpdateEvents(onTileClick, onTileEnter, onTileExit);
        gridButton.UpdateState(ButtonState.Targeted);
    }