Beispiel #1
0
    private static IEnumerator _Attack(Offensive offensive)
    {
        if (offensive.Attacker.Weapon.uses <= 0)
        {
            yield break;
        }

        if (GameSettings.DoBattleAnimation)
        {
            yield return(BattleAnimController.WaitForBattleAnimation(offensive));
        }

        if (offensive.Hit)
        {
            offensive.Defender.Damage(offensive.Damage);

            Debug.Log(offensive.Attacker.Unit.name + " attacked " + offensive.Defender.Unit.name + " for " + offensive.Damage + " damage \n" +
                      offensive.Defender.Unit.name + " hp: " + offensive.Defender.CurrentHP + "/" + offensive.Defender.Unit.stats.hp);
        }
        else
        {
            Debug.Log(offensive.Attacker.Unit.name + " missed " + offensive.Defender.Unit.name);
        }

        if (!offensive.Attacker.Weapon.unbreakable)
        {
            offensive.Attacker.Weapon.uses--;
        }

        if (offensive.Defender == offensive.Attacker.LastTarget && offensive.Attacker.LastTarget != null)
        {
            offensive.Attacker.RepeatedTarget++;
        }
        else
        {
            offensive.Attacker.LastTarget     = offensive.Defender;
            offensive.Attacker.RepeatedTarget = 1;
        }

        if (offensive.Attacker.CurrentHP <= 0)
        {
            UnitManager.Kill(offensive.Attacker);
        }
        if (offensive.Defender.CurrentHP <= 0)
        {
            UnitManager.Kill(offensive.Defender);
        }

        offensive.Attacker.AddEXP(
            StatsCalc.EXPGain_Damage(
                offensive.Attacker.Unit.stats.level,
                offensive.Defender.Unit.stats.level,
                offensive.Attacker.RepeatedTarget,
                offensive.Defender == null || offensive.Defender.CurrentHP <= 0,
                false
                )
            );

        while (GameSettings.DoBattleAnimation && BattleAnimController.IsAnimating)
        {
            yield return(null);
        }

        yield return(new WaitForSeconds(0.5f));
    }
Beispiel #2
0
    GameObject[] SetUnits(Fighter attacker, Fighter defender)
    {
        Vector2Int atkPos = attacker.Position(), defPos = defender.Position();

        Unit   _1    = atkPos.x < defPos.x ? attacker.Unit : defender.Unit;
        string path1 = "Assets/Data/Units/BattlePrefabs/" + _1.unitClass + (_1.unitSex != Unit.Sex.NA ? "_" + _1.unitSex : "") + ".prefab";

        Unit   _2    = _1 == attacker.Unit ? defender.Unit : attacker.Unit;
        string path2 = "Assets/Data/Units/BattlePrefabs/" + _2.unitClass + (_2.unitSex != Unit.Sex.NA ? "_" + _2.unitSex : "") + ".prefab";

        GameObject one = Instantiate((GameObject)UnityEditor.AssetDatabase.LoadAssetAtPath(path1, typeof(GameObject)), left);
        GameObject two = Instantiate((GameObject)UnityEditor.AssetDatabase.LoadAssetAtPath(path2, typeof(GameObject)), right);

        one.SetActive(false);
        two.SetActive(false);

        one.transform.localScale = new Vector3(1, 1, 1);
        two.transform.localScale = new Vector3(-1, 1, 1);

        if (one != null)
        {
            BattleAnimController b = one.GetComponentInChildren <BattleAnimController>();
            b.alignment = _1.alignment;
            if (_1 == attacker.Unit)
            {
                b.linked = attacker;
                Attacker = b;
            }
            else
            {
                b.linked = defender;
                Defender = b;
            }
        }
        else
        {
            Debug.LogError(path1 + " not found");
        }
        if (two != null)
        {
            BattleAnimController b = two.GetComponentInChildren <BattleAnimController>();
            b.alignment = _2.alignment;
            if (_2 == attacker.Unit)
            {
                b.linked = attacker;
                Attacker = b;
            }
            else
            {
                b.linked = defender;
                Defender = b;
            }
        }
        else
        {
            Debug.LogError(path2 + " not found");
        }

        return(new GameObject[2] {
            one, two
        });
    }