コード例 #1
0
    public void AttackPhase(GameObject target)
    {
        //Range Check Code

        //Combat Check

        //This Unit's attacking power
        UnitAttributes OffUnitAttributes = this.GetComponent <UnitAttributes>();
        float          OffensiveUnitDef  = OffUnitAttributes.EffectiveDefenceReturn();
        float          OffensiveUnitAtt  = OffUnitAttributes.EffectiveAttackReturn();
        //The target unit's attacking power


        UnitAttributes TarUnitAttributes = target.GetComponent <UnitAttributes>();
        float          DefendingUnitDef  = TarUnitAttributes.EffectiveDefenceReturn();

        if (TarUnitAttributes.isDefending)
        {
            //Calculate Starting Attack (before it takes damage)
            float DefendingUnitAtt = TarUnitAttributes.EffectiveAttackReturn();
            TarUnitAttributes.HealthPool -= TarUnitAttributes.DamageReturn(OffensiveUnitAtt, DefendingUnitDef, OffUnitAttributes);
            OffUnitAttributes.HealthPool -= OffUnitAttributes.DamageReturn(DefendingUnitAtt, OffensiveUnitDef, TarUnitAttributes);
        }
        else
        {
            //Phase 1
            TarUnitAttributes.HealthPool -= TarUnitAttributes.DamageReturn(OffensiveUnitAtt, DefendingUnitDef, OffUnitAttributes);
            //Phase 2
            if (TarUnitAttributes.HealthPool > 0)
            {
                float DefendingUnitAtt = TarUnitAttributes.EffectiveAttackReturn();
                OffUnitAttributes.HealthPool -= OffUnitAttributes.DamageReturn(DefendingUnitAtt, OffensiveUnitDef, TarUnitAttributes);
            }
            else
            {
                Destroy(TarUnitAttributes.gameObject);
            }
        }
        if (OffUnitAttributes.HealthPool <= 0)
        {
            Destroy(OffUnitAttributes.gameObject);
        }
        if (TarUnitAttributes.HealthPool <= 0)
        {
            Destroy(TarUnitAttributes.gameObject);
        }
        EndPhase();
    }