public float GetAttackPositionOffset(BattleUnitController targetedUnit)
 {
     var targetBodySizeOffset = 0f;
     if (targetedUnit != null)
     {
         targetBodySizeOffset = targetedUnit.bodySizeOffset;
     }
     return this.attackDistanceOffset + targetBodySizeOffset;
 }
Example #2
0
    // Damages this unit. If it dies, return true. otherwise, returns false
    public bool TakeDamage(int amount, BattleUnitController attacker)
    {
        unit.health = Mathf.Max(0, unit.health - amount);

        // TODO: IMPLEMENT VISUALS
        if (unit.health == 0)
        {
            // TODO: IMPLEMENT ALL KINDS OF DEATH OPTIONS
            // TODO: IMPLEMENT VISUALS
            // TODO: IMPLEMENT UNIT EVENTS LIKE OnDeath and such
            battleController.map.tiles[unit.y][unit.x] = null;

            return(true);
        }

        return(false);
    }
Example #3
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 #4
0
 public int GetHealed(int amount, BattleUnitController healer)
 {
     if (unit.isAlive)
     {
         int h = unit.baseUnit.maxHealth - unit.health;
         if (h < amount)
         {
             unit.health = unit.baseUnit.maxHealth;
             return(h);
         }
         else
         {
             unit.health += amount;
             return(amount);
         }
     }
     else
     {
         Debug.LogError("Unit is dead");
     }
     return(0);
 }
    public virtual IEnumerator PlaySkillSequence(BattleUnitController actor, BattleView battleView, BattleActionResult actionResult)
    {
        Vector3 targetPosition = new Vector3();
        BattleUnitController targetedUnit = null;
        TileController targetedTile = null;

        if (actionResult.targetCharacter != null)
        {
            targetedUnit = battleView.GetBattleUnit(actionResult.targetCharacter);
            targetPosition = targetedUnit.transform.position;
        }
        else
        {
            targetedTile = battleView.GetTileAtMapPosition(actionResult.targetPosition);
            targetPosition = targetedTile.transform.position;
        }

        var actorOrigPosition = actor.transform.position;

        yield return StartCoroutine(actor.MoveToAttackPosition(targetedUnit, targetPosition));

        StartCoroutine(actor.AnimateAttack());

        for (int i = 0; i < actionResult.allSkillEffectResult.Count; ++i)
        {
            var delay = this.GetDelayedKeyFrames(i);
            yield return StartCoroutine(this.WaitForFrames(delay));

            var skillEffectResult = actionResult.allSkillEffectResult[i];

            yield return this.PlayEffects(skillEffectResult.effectsOnTarget, battleView);
        }

        yield return StartCoroutine(actor.ReturnToPosition(actorOrigPosition));

        Destroy(this.gameObject);
    }
 public virtual IEnumerator MoveToAttackPosition(BattleUnitController targetedUnit, Vector3 targetPosition)
 {
     var offset = this.GetAttackPositionOffset(targetedUnit);
     yield return StartCoroutine(this.MoveToPositionWithOffset(targetPosition, this.attackMovementSpeed, offset));
 }
 protected IEnumerator PlayEffectOnTarget(BattleUnitController unit, BattleActionResult.EffectOnTarget effectOnTarget)
 {
     unit.PlayEffect(effectOnTarget.effectPrefabPath);
     var hpPercentage = effectOnTarget.target.HpPercentage;
     yield return StartCoroutine(unit.TakeEffect(effectOnTarget, hpPercentage));
 }