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();
    }
Exemple #2
0
    void Update_UI_Unit()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        RaycastHit UnitRayHit;

        //        Debug.DrawRay(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.down * 10, Color.blue, 3);
        if (Physics.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.down * 10, out UnitRayHit, 9))
        {
            //Debug.Log("Unit is not held!");
            if (UnitRayHit.collider.tag.Contains("Faction"))
            {
                UnitAttributes TargetUnit = UnitRayHit.collider.GetComponent <UnitAttributes>();

                if (!Unit_Viewer.activeSelf)
                {
                    //Sets the Unit Display to active if unit is hovered over with mouse
                    Unit_Viewer.SetActive(true);
                    Sprite_Viewer.SetActive(true);
                    Unit_Viewer.GetComponent <Image>().sprite = TargetUnit.transform.GetChild(0).GetComponent <SpriteRenderer>().sprite;
                }


                for (int i = 0; i < Unit_Statistics.Length; i++)
                {
                    //Debug.Log("Updating!");
                    switch (Unit_Statistics[i].name)
                    {
                    case "HP Text":
                        Unit_Statistics[i].GetComponent <Text>().text = Mathf.RoundToInt(TargetUnit.HealthPool / 10).ToString() + "/10";
                        break;

                    case "HP Bar":
                        Unit_Statistics[i].GetComponent <Slider>().value = TargetUnit.HealthPool;
                        break;

                    case "Ammo Text":
                        Unit_Statistics[i].GetComponent <Text>().text = TargetUnit.Ammo.ToString() + "/" + TargetUnit.MaxAmmo.ToString();
                        break;

                    case "Ammo Bar":
                        Unit_Statistics[i].GetComponent <Slider>().value    = TargetUnit.Ammo;
                        Unit_Statistics[i].GetComponent <Slider>().maxValue = TargetUnit.MaxAmmo;
                        break;

                    case "Fuel Text":
                        Unit_Statistics[i].GetComponent <Text>().text = TargetUnit.FuelPool.ToString() + "/" + TargetUnit.MaxFuelPool.ToString();
                        break;

                    case "Fuel Bar":
                        Unit_Statistics[i].GetComponent <Slider>().value    = TargetUnit.FuelPool;
                        Unit_Statistics[i].GetComponent <Slider>().maxValue = TargetUnit.MaxFuelPool;
                        break;

                    case "Attack Meter":
                        Unit_Statistics[i].GetComponent <Slider>().value = TargetUnit.Attack;
                        break;

                    case "Attack Value":
                        Unit_Statistics[i].GetComponent <Text>().text = TargetUnit.Attack.ToString();
                        break;

                    case "Defence Meter":
                        Unit_Statistics[i].GetComponent <Slider>().value = TargetUnit.Defence;
                        break;

                    case "Defence Value":
                        Unit_Statistics[i].GetComponent <Text>().text = TargetUnit.Defence.ToString();
                        break;

                    case "Movement Meter":
                        Unit_Statistics[i].GetComponent <Slider>().value = TargetUnit.Movement;
                        break;

                    case "Movement Value":
                        Unit_Statistics[i].GetComponent <Text>().text = TargetUnit.Movement.ToString();
                        break;

                    default:
                        break;
                    }
                }
                if (Indicator_AttackIcon.activeSelf)
                {
                    Indicator_AttackIcon.SetActive(false);
                }
                if (GameManager.GManager.HeldObject && GameManager.GManager.HeldObject.GetComponent <UnitAttributes>() != null)
                {
                    UnitAttributes SelectedUnit = GameManager.GManager.HeldObject.GetComponent <UnitAttributes>();

                    if (UnitRayHit.collider.tag.Contains("Faction") && UnitRayHit.collider.gameObject != GameManager.GManager.HeldObject)
                    {
                        if (!Indicator_AttackIcon.activeSelf)
                        {
                            Indicator_AttackIcon.SetActive(true);
                        }

                        //int DamageValue = ((SelectedUnit.Attack * SelectedUnit.HealthPool) / SelectedUnit.WeaknessMod) - ((TargetUnit.Defence*TargetUnit.HealthPool)/TargetUnit.WeaknessMod);
                        float effectiveAttack = 0;


                        if (SelectedUnit.UsesAmmo && SelectedUnit.Ammo > 0)
                        {
                            effectiveAttack = SelectedUnit.AmmoAttack * (SelectedUnit.HealthPool / SelectedUnit.WeaknessMod);
                        }
                        else
                        {
                            effectiveAttack = SelectedUnit.Attack * (SelectedUnit.HealthPool / SelectedUnit.WeaknessMod);
                        }

                        float effectiveDefence = TargetUnit.Defence * (TargetUnit.HealthPool / TargetUnit.WeaknessMod);


                        //Uses the unit's damage calculation to display these values
                        int damageDisplay = TargetUnit.DamageReturn(effectiveAttack, effectiveDefence, SelectedUnit);

                        //Sets Text
                        Indicator_AttackValue.GetComponent <Text>().text = damageDisplay.ToString() + "%";

                        if (damageDisplay >= 50)
                        {
                            Indicator_AttackIcon.GetComponent <Image>().color = Color.blue;
                        }
                        else if (damageDisplay < 50 && damageDisplay >= 25)
                        {
                            Indicator_AttackIcon.GetComponent <Image>().color = Color.magenta;
                        }
                        else
                        {
                            Indicator_AttackIcon.GetComponent <Image>().color = Color.red;
                        }
                    }
                }
            }
        }
        else
        {
            if (Unit_Viewer)
            {
                //disables the Unit Display if unit isn't under mouse
                Unit_Viewer.SetActive(false);
                Sprite_Viewer.SetActive(false);
            }
        }
    }