Example #1
0
    // Apply an effect of an action performed by this unit
    public void ApplyActionEffect(UnitActionEffect effect, BattleUnitController target)
    {
        float temp = 0;

        temp += effect.fixedAmount;

        temp += effect.selfCurrentHealthRatio * GetHealth();
        temp += effect.selfCurrentStaminaRatio * GetStamina();
        temp += effect.selfMaxHealthRatio * GetMaxHealth();
        temp += effect.selfMaxStaminaRatio * GetMaxStamina();
        temp += effect.selfMovementRatio * GetMovements();
        foreach (var stat in effect.selfStatsRatio)
        {
            temp += stat.Value * GetStat(stat.Key);
        }

        temp += effect.targetCurrentHealthRatio * target.GetHealth();
        temp += effect.targetCurrentStaminaRatio * target.GetStamina();
        temp += effect.targetMaxHealthRatio * target.GetMaxHealth();
        temp += effect.targetMaxStaminaRatio * target.GetMaxStamina();
        temp += effect.targetMovementRatio * target.GetMovements();
        foreach (var stat in effect.targetStatsRatio)
        {
            temp += stat.Value * target.GetStat(stat.Key);
        }

        int amount = (int)temp;

        if (amount < 0)
        {
            amount = 0;
        }

        if (effect.type == ActionEffectType.Damage)
        {
            target.TakeDamage(amount, this);
        }
        else if (effect.type == ActionEffectType.Heal)
        {
            target.GetHealed(amount, this);
        }
        else if (effect.type == ActionEffectType.Pushback)
        {
        }
    }
Example #2
0
    public static List <BattleUnit> GetUnitsInLocalAreaForActionEffect(int x, int y, Direction direction, ActionAreaType areaType, UnitActionEffect effect, BattleMap map)
    {
        List <BattleUnit> ret = new List <BattleUnit>();

        List <BattleMapTile> tiles = GetTilesInLocalAreaForActionEffect(x, y, direction, areaType, effect, map);

        foreach (var tile in tiles)
        {
            if (tile.unit != null)
            {
                ret.Add(tile.unit);
            }
        }

        return(ret);
    }
Example #3
0
    // Static logic


    public static List <BattleMapTile> GetTilesInLocalAreaForActionEffect(int x, int y, Direction direction, ActionAreaType areaType, UnitActionEffect effect, BattleMap map)
    {
        List <BattleMapTile> ret = new List <BattleMapTile>();

        // Area mask is always thought of as being rotated towards right
        if (direction == Direction.Right)
        {
            int minx = Mathf.Max(0, x - effect.areaCenterX);
            int maxx = Mathf.Min(map.width - 1, minx + effect.areaWidth - 1);
            int miny = Mathf.Max(0, y - effect.areaCenterY);
            int maxy = Mathf.Min(map.height - 1, miny + effect.areaHeight - 1);

            // We have to use these for calculating the correct index for the masks when the unit is too close to the edge od the map
            int minxh = -Mathf.Min(0, x - effect.areaCenterX);
            int minyh = -Mathf.Min(0, y - effect.areaCenterY);

            for (int i = minx; i <= maxx; ++i)
            {
                for (int j = miny; j <= maxy; ++j)
                {
                    if (effect.areaMask[j - miny + minyh][i - minx + minxh] == true)
                    {
                        ret.Add(map.tiles[j][i]);
                    }
                }
            }
        }
        // This is basically a complete 180 degree turn from the previous one
        else if (direction == Direction.Left)
        {
            int minx = Mathf.Max(0, x - (effect.areaWidth - effect.areaCenterX - 1));
            int maxx = Mathf.Min(map.width - 1, x + effect.areaCenterX);
            int miny = Mathf.Max(0, y - (effect.areaHeight - effect.areaCenterY - 1));
            int maxy = Mathf.Min(map.height - 1, y + effect.areaCenterY);

            // We have to use these for calculating the correct index for the masks when the unit is too close to the edge od the map
            int minxh = -Mathf.Min(0, x - (effect.areaWidth - effect.areaCenterX - 1));
            int minyh = -Mathf.Min(0, y - (effect.areaHeight - effect.areaCenterY - 1));

            for (int i = minx; i <= maxx; ++i)
            {
                for (int j = miny; j <= maxy; ++j)
                {
                    if (effect.areaMask[effect.areaHeight - (j - miny + minyh) - 1][effect.areaWidth - (i - minx + minxh) - 1] == true)
                    {
                        ret.Add(map.tiles[j][i]);
                    }
                }
            }
        }
        // This is a 90 degree rotation of the first one
        else if (direction == Direction.Down)
        {
            int minx = Mathf.Max(0, x - (effect.areaHeight - effect.areaCenterY - 1));
            int maxx = Mathf.Min(map.width - 1, x + effect.areaCenterY);
            int miny = Mathf.Max(0, y - effect.areaCenterX);
            int maxy = Mathf.Min(map.height - 1, miny + effect.areaWidth - 1);

            // We have to use these for calculating the correct index for the masks when the unit is too close to the edge od the map
            int minxh = -Mathf.Min(0, x - (effect.areaHeight - effect.areaCenterY - 1));
            int minyh = -Mathf.Min(0, y - effect.areaCenterX);

            for (int i = minx; i <= maxx; ++i)
            {
                for (int j = miny; j <= maxy; ++j)
                {
                    if (effect.areaMask[effect.areaHeight - (i - minx + minxh) - 1][j - miny + minyh] == true)
                    {
                        ret.Add(map.tiles[j][i]);
                    }
                }
            }
        }
        // This is a 270 degree rotation of the first one
        else if (direction == Direction.Up)
        {
            int minx = Mathf.Max(0, x - effect.areaCenterY);
            int maxx = Mathf.Min(map.width - 1, minx + effect.areaHeight - 1);
            int miny = Mathf.Max(0, y - (effect.areaWidth - effect.areaCenterX - 1));
            int maxy = Mathf.Min(map.height - 1, y + effect.areaCenterX);

            // We have to use these for calculating the correct index for the masks when the unit is too close to the edge od the map
            int minxh = -Mathf.Min(0, x - effect.areaCenterY);
            int minyh = -Mathf.Min(0, y - (effect.areaWidth - effect.areaCenterX - 1));

            for (int i = minx; i <= maxx; ++i)
            {
                for (int j = miny; j <= maxy; ++j)
                {
                    if (effect.areaMask[i - minx + minxh][effect.areaWidth - (j - miny + minyh) - 1] == true)
                    {
                        ret.Add(map.tiles[j][i]);
                    }
                }
            }
        }

        return(ret);
    }