Example #1
0
    public IEnumerator Blink(Color32 color, StartUnit unit, float time_until)
    {
        //Debug.Log("Blinking?");
        Anima2D.SpriteMeshInstance[] Unit_Meshes = unit.gameObject.GetComponentsInChildren <Anima2D.SpriteMeshInstance>();

        Color32 prev_color = Unit_Meshes[0].color;

        while (time_until >= Time.time)
        {
            for (int i = 0; i < Unit_Meshes.Length; i++)
            {
                Unit_Meshes[i].color = color;
                //Debug.Log("Color_Changed");
            }

            yield return(new WaitForSeconds(0.2f));

            for (int i = 0; i < Unit_Meshes.Length; i++)
            {
                Unit_Meshes[i].color = prev_color;
                //Debug.Log("Color_Changed");
            }

            yield return(new WaitForSeconds(0.2f));
        }

        for (int i = 0; i < Unit_Meshes.Length; i++)
        {
            Unit_Meshes[i].color = color_should_be;
            //Debug.Log("Color_Changed");
        }
    }
Example #2
0
    public virtual void TakeDamage(StartUnit attacked_unit, float damage)
    {
        attacked_unit.current_health -= damage;
        attacked_unit.health_bar.GetComponent <Image>().fillAmount = attacked_unit.current_health / attacked_unit.health;
        //Debug.Log("Made it");
        float healthpercent = attacked_unit.current_health / attacked_unit.health; //    120/180 = .667

        float attack_deduction = 1 - healthpercent;                                //   1 - .667 = .333
        float reduction        = attack_deduction / 2;
        float new_attack       = attacked_unit.attack * reduction;                 //   72 * .333 = 23.76

        attacked_unit.current_attack = attacked_unit.attack - new_attack;          // 72 - 23.76 = 48

        if (attacked_unit.current_health <= (attacked_unit.health * 0.4f))
        {
            attacked_unit.gameObject.GetComponent <Animator>().SetBool("Injured", true);
            attacked_unit.Injured = true;
            StartCoroutine(attacked_unit.Injured_Blinking());
        }

        //float attack_deduction = attacked_unit.current_attack * (current_attack - attacked_unit.current_health / attacked_unit.health);
        //if (attack_deduction > attacked_unit.basedmg)
        //    attacked_unit.current_attack = attack_deduction;
        //else
        //{
        //    if (attack_deduction <= basedmg)
        //    {
        //        attacked_unit.current_attack = basedmg;
        //    }
        //}
    }
 public override void Debuf(StartUnit unit)
 {
     //Debug.Log(unit.unit_name + " lost its buff of +15 defense");
     unit.defense          -= 15;
     unit.fortress_def_buff = false;
     unit.Shield_Bubble.SetActive(false);
     //deactivate buff ui element here
     unit.gameObject.GetComponentInChildren <Buff_UI_Manager>().update_current_buffs(unit);
 }
Example #4
0
 private void Hide_Prev_UI()
 {
     if (_Grid.Get_Cell_Index(prev_coords).unitOnTile != null)
     {
         StartUnit _tileUnit    = _Grid.Get_Cell_Index(prev_coords).unitOnTile;
         BattleUI  _tileUnit_UI = _tileUnit.Unit_Stats_Panel.GetComponent <BattleUI>();
         _tileUnit_UI.Hide();
     }
 }
 public override void Buff(StartUnit unit)
 {
     //Debug.Log(unit.unit_name + " was buffed with +15 defense");
     unit.defense          += 15;
     unit.fortress_def_buff = true;
     unit.Shield_Bubble.SetActive(true);
     //activate buff ui element here
     unit.gameObject.GetComponentInChildren <Buff_UI_Manager>().update_current_buffs(unit);
 }
Example #6
0
    public override void TakeDamage(StartUnit attacked_unit, float damage)
    {
        attacked_unit.current_health -= damage;
        attacked_unit.health_bar.GetComponent <Image>().fillAmount = attacked_unit.current_health / attacked_unit.health; // fix?

        float attack_deduction = attacked_unit.current_attack * (current_attack - attacked_unit.current_health / attacked_unit.health);
        float attack_increase  = current_attack - attack_deduction;

        current_attack += attack_increase;
    }
Example #7
0
 public virtual void Buff(StartUnit unit)
 {
     //if (unit.current_attack != unit.attack)
     //{
     //    unit.current_attack += 1;
     //}
     //else
     //{
     //    unit.attack += 1;
     //    unit.current_attack += 1;
     //}
     unit.current_attack += 1;
 }
Example #8
0
    public void populate_current_buffs(StartUnit Unit_To_Buff)
    {
        ListItems = new ArrayList();
        //is unit currently selected

        if (Unit_To_Buff.fortress_def_buff)
        {
            ListItems.Add(new Buff_UI_Item(IconImages[0], "Fortress Buff"));
        }
        if (Unit_To_Buff.attack_buff)
        {
            ListItems.Add(new Buff_UI_Item(IconImages[1], "Attack Buff"));
        }
        if (Unit_To_Buff.health_buff)
        {
            ListItems.Add(new Buff_UI_Item(IconImages[2], "Health Buff"));
        }
        if (Unit_To_Buff.crit_buff)
        {
            ListItems.Add(new Buff_UI_Item(IconImages[3], "Crit Buff"));
        }
        if (Unit_To_Buff.move_buff)
        {
            ListItems.Add(new Buff_UI_Item(IconImages[4], "Move Buff"));
        }


        float num_of_items        = ListItems.Count;
        float curr_num_counter    = 0;
        float desired_width_ratio = 0.2f;

        foreach (Buff_UI_Item buff_item in ListItems)
        {
            GameObject  newBuffItem = Instantiate(BuffItemPrefab) as GameObject;
            Buff_UI_Obj controller  = newBuffItem.GetComponent <Buff_UI_Obj>();
            controller.Icon_Obj.GetComponent <Image>().sprite = buff_item.Icon;
            controller.Buff_ID = buff_item.Buff_ID;
            newBuffItem.transform.SetParent(UI_ListPanel.transform);
            newBuffItem.transform.localScale = Vector3.one;
            float max_x_anchor = 0 + ((curr_num_counter + 1) * desired_width_ratio);
            float min_x_anchor = 0 + (curr_num_counter * desired_width_ratio);
            newBuffItem.GetComponent <RectTransform>().anchorMax = new Vector2(max_x_anchor, 1);
            newBuffItem.GetComponent <RectTransform>().anchorMin = new Vector2(min_x_anchor, 0);
            newBuffItem.GetComponent <RectTransform>().sizeDelta = UI_ListPanel.GetComponent <RectTransform>().rect.size;
            newBuffItem.GetComponent <RectTransform>().offsetMax = new Vector2(0, 0);
            newBuffItem.GetComponent <RectTransform>().offsetMin = new Vector2(0, 0);
            curr_num_counter += 1;
        }
    }
Example #9
0
 public void Assign_Position(Vector3 _new_position, HexagonCoord _new_coord)
 {
     gameObject.transform.position = _new_position;
     prev_coords = coords;
     coords      = _new_coord;
     Hide_Prev_UI();
     if (editor.allow_cursor_control == true)
     {
         StartUnit _tileUnit    = _Grid.Get_Cell_Index(coords).unitOnTile;
         BattleUI  _tileUnit_UI = _tileUnit.Unit_Stats_Panel.GetComponent <BattleUI>();
         editor.Assign_Stats_Var(_tileUnit_UI, _tileUnit);
         _tileUnit_UI.Show();
     }
     else
     {
         Hide_Prev_UI();
     }
     Order_Cursor(_Grid.GetCell(transform.position).coords, _Grid.sprites_per_tile);
 }
Example #10
0
    public IEnumerator Retaliate_Anim(StartUnit retaliated_upon_unit)
    {
        if (Attacking_Lines_List.Length > 0)
        {
            int Chosen_Voice_Line_Index = Random.Range(0, Attacking_Lines_List.Length);
            Attacking_Lines_List[Chosen_Voice_Line_Index].Play();
        }
        anim.SetBool("Attacking", true);
        yield return(new WaitForSeconds(0.2f));

        //attackSound.Play();
        //Camera.main.gameObject.GetComponent<CameraBounder>().Shake_Camera(2f, 20f);
        yield return(new WaitForSeconds(0.8f));

        anim.SetBool("Attacking", false);
        //yield return new WaitForSeconds(0.5f);
        Camera.main.gameObject.GetComponent <CameraBounder>().Lerp_Reset_Zoom();
        yield return(new WaitForSeconds(0.1f));

        retaliated_upon_unit.currently_attacking = false;
    }
 void ResetStats()
 {
     if (PrevUnit != null)
     {
         if (grassDebuff)
         {
             if (!this.GetComponent <HexagonCell>().occupied)
             {
                 if (PrevUnit.current_mobility + 1 >= mobility)
                 {
                     PrevUnit.current_mobility = mobility;
                 }
                 else
                 {
                     PrevUnit.current_mobility = PrevUnit.current_mobility + 1;
                 }
                 PrevUnit = null;
             }
         }
         if (waterDebuff)
         {
             if (!this.GetComponent <HexagonCell>().occupied)
             {
                 if (PrevUnit.current_mobility + 2 >= mobility)
                 {
                     PrevUnit.current_mobility = mobility;
                 }
                 else
                 {
                     PrevUnit.current_mobility = PrevUnit.current_mobility + 2;
                 }
                 PrevUnit = null;
             }
         }
     }
 }
Example #12
0
    public override void TakeDamage(StartUnit attacked_unit, float damage)
    {
        attacked_unit.current_health -= damage - defense;
        attacked_unit.health_bar.GetComponent <Image>().fillAmount = attacked_unit.current_health / attacked_unit.health; // fix?

        float healthpercent    = attacked_unit.current_health / attacked_unit.health;                                     //    120/180 = .667
        float attack_deduction = 1 - healthpercent;                                                                       //   1 - .667 = .333
        float new_attack       = attacked_unit.attack * attack_deduction;                                                 //   72 * .333 = 23.76

        attacked_unit.current_attack = attacked_unit.attack - new_attack;                                                 // 72 - 23.76 = 48
        if (!attacked_unit.slowed)
        {
            if (attacked_unit.current_mobility - 1 <= 0)
            {
                attacked_unit.current_mobility = 1;
            }
            else
            {
                attacked_unit.current_mobility -= 1;
            }
            attacked_unit.slowed          = true;
            attacked_unit.slowing_counter = 2;
        }
    }
Example #13
0
    public IEnumerator WeatherBasicAttack(Grid hexGrid, HexagonCell unitCell)
    {
        end_attack_without_retaliate = true;
        attacked_unit_has_died       = false;

        string name = unitCell.unitOnTile.unit_name;


        //add a call to a retaliate function on the other unit
        List <HexagonCell> targetable = new List <HexagonCell>();

        //Debug.Log(unitCell.unitOnTile.unit_name + " atttacking: ");
        foreach (HexagonCell cell in hexGrid.cells)
        {
            if (unitCell.coords.FindDistanceTo(cell.coords) <= attackRange &&
                unitCell.coords.FindDistanceTo(cell.coords) > 0 &&
                cell.occupied &&
                !cell.unitOnTile.dead &&
                tag != cell.unitOnTile.tag)
            {
                targetable.Add(cell);
            }
        }
        if (targetable.Count >= 1)
        {
            editor.cursor.Assign_Position(this.transform.position, hexGrid.GetCell(this.transform.position).coords);
            Vector3 _new_Camera_Pos = new Vector3(this.transform.position.x, this.transform.position.y, editor.Main_Cam.transform.position.z);
            editor.Main_Cam.transform.position = Vector3.Lerp(editor.Main_Cam.transform.position, _new_Camera_Pos, 1f);

            //StartCoroutine(this.Blink(Color.green, this, Time.time + 0.8f));
            yield return(new WaitForSeconds(0.3f));

            int selectedTarget = ChosenEnemy(targetable);
            //int rand_index = Random.Range(0, targetable.Count);



            float crit_chance = Random.value;
            float miss_chance = Random.value;
            float damage      = current_attack - targetable[selectedTarget].unitOnTile.defense;
            Debug.Log("Damage: " + damage);
            int  dmg_txt       = (int)damage;
            bool crit_happened = false;


            editor.printState();
            if (targetable[selectedTarget].unitOnTile.FloatingTextPrefab)
            {
                //Debug.Log("fadef");
                if (miss_chance <= miss)
                {
                    damage = 0;
                }
                else
                {
                    if (crit_chance <= crit && miss_chance > miss)
                    {
                        int rand = Random.Range(0, 2);
                        if (rand == 0)
                        {
                            GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().PlayOneFromList(GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().critSounds);
                        }
                        damage        = current_attack * crit_multiplier;
                        crit_happened = true;
                    }
                }
                dmg_txt = (int)damage;
            }

            StartUnit attacked_unit = targetable[selectedTarget].unitOnTile;
            Unit_Getting_Attacked = targetable[selectedTarget].unitOnTile.gameObject;
            //Weather_Effect_Object.gameObject.SetActive(true);
            //Weather_Effect_Object.GetComponent<WeatherMan_Effects>().move_target_to(attacked_unit.gameObject);
            //Weather_Effect_Object.GetComponent<WeatherMan_Effects>().play_effect();
            //Debug.Log("----- Weather Effect Called");
            HexagonCell  attacked_cell = targetable[selectedTarget];
            HexagonCoord current       = unitCell.coords;

            if (attacked_cell.gameObject.transform.position.x > transform.position.x) //unit is to the right
            {
                if (!direction)                                                       //facing left, so needs to face right
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = true;
                }
            }
            else //unit is to the left
            {
                if (direction)
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = false;
                }
            }

            if (attacked_unit.FloatingTextPrefab)
            {
                GameObject damagetext = Instantiate(attacked_unit.FloatingTextPrefab, attacked_unit.transform.position, Quaternion.identity, attacked_unit.transform);
                if (damage == 0)
                {
                    damagetext.GetComponent <TextMesh>().text          = "MISS";
                    damagetext.GetComponent <TextMesh>().color         = Color.white;
                    damagetext.GetComponent <TextMesh>().characterSize = 0.06f;
                }


                if (damage != 0)
                {
                    damagetext.GetComponent <TextMesh>().text = dmg_txt.ToString();
                    if (crit_happened)
                    {
                        damagetext.GetComponent <TextMesh>().color         = Color.red;
                        damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * ((float)dmg_txt / 75f));
                    }
                    else
                    {
                        damagetext.GetComponent <TextMesh>().color         = Color.yellow;
                        damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * ((float)dmg_txt / 75f));
                    }
                }

                if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
                {
                    damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                             damagetext.transform.localScale.z);

                    //damagetext.GetComponent<TextMesh>().color = Color.green;
                    //Debug.Log("BackWards Text");
                }
                else
                {
                    if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                    {
                        damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                 damagetext.transform.localScale.z);
                    }
                }
            }
            Debug.Log(name + " attacked " + attacked_unit.unit_name + " for " + damage);
            TakeDamage(attacked_unit, damage);

            if (specialAttackCounter <= 0)
            {
                WeatherVane(editor.hexGrid.GetCell(attacked_unit.transform.position));
            }


            //Debug.Log("he dead");
            if (targetable[selectedTarget].unitOnTile.current_health <= 0)
            {
                GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().PlayOneFromList(GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().killSounds);

                if (targetable[selectedTarget].unitOnTile.tag == "TeamBuff") // was a buffmonster
                {
                    GameObject buffItem = Instantiate(FloatingBuffPrefab, transform.position, Quaternion.identity, transform);
                    int        randBuff = Random.Range(0, 4);
                    //give correct buff accordingly
                    Debug.Log("acquiring buff");
                    if (randBuff == 0) // movement buff
                    {
                        buffItem.GetComponent <SpriteRenderer>().sprite = mobilityBuff;
                        Debug.Log(name + " got a movement buff");
                        current_mobility += 1;
                        move_buff         = true;
                        if (current_health != health)
                        {
                            current_health += 10;
                        }
                    }
                    else if (randBuff == 1) // crit buff
                    {
                        buffItem.GetComponent <SpriteRenderer>().sprite = critBuff;
                        Debug.Log(name + " got a crit buff");
                        crit     += 0.20f;
                        crit_buff = true;
                        if (current_health != health)
                        {
                            current_health += 10;
                        }
                    }
                    else if (randBuff == 2) // attack buff
                    {
                        Debug.Log(name + " got an attack buff");
                        buffItem.GetComponent <SpriteRenderer>().sprite = attackBuff;
                        attack         += 25;
                        current_attack += 25;
                        attack_buff     = true;
                        if (current_health != health)
                        {
                            current_health += 10;
                        }
                    }
                    else // health buff
                    {
                        Debug.Log(name + " got a health buff");
                        buffItem.GetComponent <SpriteRenderer>().sprite = healthBuff;
                        health         += 100;
                        current_health += 100;

                        health_buff = true;
                    }

                    if (current_health > (health * 0.4f))
                    {
                        this.anim.SetBool("Injured", false);
                        this.Injured = false;
                    }

                    gameObject.GetComponentInChildren <Buff_UI_Manager>().update_current_buffs(this);

                    float healthpercent = current_health / health;             //    120/180 = .667

                    float attack_deduction = 1 - healthpercent;                //   1 - .667 = .333
                    float reduction        = attack_deduction / 2;
                    float new_attack       = attacked_unit.attack * reduction; //   72 * .333 = 23.76
                    current_attack = attack + new_attack;                      // 72 - 23.76 = 48
                }
                end_attack_without_retaliate = true;
                attacked_unit_has_died       = true;

                StartCoroutine(Attack(hexGrid, unitCell, attacked_cell));

                //int index = targetable[rand_index].coords.X_coord + targetable[rand_index].coords.Z_coord * hexGrid.width + targetable[rand_index].coords.Z_coord / 2;
                //editor.RemoveUnitInfo(targetable[rand_index], index);

                editor.Units_To_Delete.Add(attacked_cell);
                attacked_unit.dead = true;


                yield return(new WaitForSeconds(0.3f));



                StartCoroutine(targetable[selectedTarget].unitOnTile.Hit());
                StartCoroutine(attacked_unit.Blink(editor.Unit_Hurt_Color, attacked_unit, Time.time + 1f));

                //attacked_unit.Fade_Out_Body();
                //Should start some sort of DEATH ANIMATION COROUTINE HERE
            }
            else
            {
                if (unitCell.coords.FindDistanceTo(attacked_cell.coords) <= attacked_cell.unitOnTile.attackRange)
                {
                    end_attack_without_retaliate = false;
                }
                else
                {
                    end_attack_without_retaliate = true;
                }
                if (current_health - 20 <= 0 && attacked_unit.gameObject.GetComponent <FortressHero>() != null)
                {
                    end_attack_without_retaliate = true;
                }
                StartCoroutine(Attack(hexGrid, unitCell, attacked_cell));
                yield return(new WaitForSeconds(0.3f));

                //SHOULD THORNMAIL BE ACTIVATED ON SPECIAL ATTACKS?
                if (attacked_unit.gameObject.GetComponent <FortressHero>() != null && damage != 0) // handling of if attacking fortress hero
                {
                    Debug.Log("Hurt by fortress hero's armor");
                    if (FloatingTextPrefab)
                    {
                        GameObject damagetext = Instantiate(FloatingTextPrefab, transform.position, Quaternion.identity, transform);
                        damagetext.GetComponent <TextMesh>().text          = 20.ToString();
                        damagetext.GetComponent <TextMesh>().color         = Color.yellow;
                        damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * (20f / 75f));
                        if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
                        {
                            damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                     damagetext.transform.localScale.z);

                            //damagetext.GetComponent<TextMesh>().color = Color.green;
                            //Debug.Log("BackWards Text");
                        }
                        else
                        {
                            if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                            {
                                damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                         damagetext.transform.localScale.z);
                            }
                        }
                    }

                    TakeDamage(this, 20f);
                    StartCoroutine(AttackToHit());
                    StartCoroutine(Blink(editor.Unit_Hurt_Color, this, Time.time + 1f));
                    if (current_health <= 0) // pretty sure there's more code needed here but i'll ask christophe later
                    {
                        editor.Units_To_Delete.Add(unitCell);
                        dead = true;
                    }
                }
                StartCoroutine(targetable[selectedTarget].unitOnTile.Hit());
                StartCoroutine(attacked_unit.Blink(editor.Unit_Hurt_Color, attacked_unit, Time.time + 1f));
            }
        }
        else
        {
            specialAttackCounter = 0;
            currently_attacking  = false;
        }
    }
Example #14
0
    public override IEnumerator Effect(HexagonMapEditor editor, Grid hexGrid, int x, int z, int size)
    {
        //Debug.Log("poison gas hurting people");
        List <HexagonCell> frontier = new List <HexagonCell>(); // list of nodes that the hazard has effect over
        HexagonCell        curr     = hexGrid.Get_Cell_Index(new HexagonCoord(x, z));

        //Debug.Log(type_name + " hazard epicenter at: " + curr.coords.x + "," + curr.coords.Y_coord + "," + curr.coords.z);
        for (int i = 0; i < hexGrid.cells.Length; i++)
        {
            int distance = curr.coords.FindDistanceTo(hexGrid.cells[i].coords);
            if (distance <= size)
            {
                frontier.Add(hexGrid.cells[i]);
            }
        }
        for (int j = 0; j < frontier.Count; j++)
        {
            if (frontier[j].occupied && frontier[j].unitOnTile.gameObject.tag != gameObject.tag)
            {
                //frontier[j].unitOnTile.current_health -= damageDealt;

                StartUnit  attacked_unit = frontier[j].unitOnTile;
                GameObject damagetext    = Instantiate(attacked_unit.FloatingTextPrefab, attacked_unit.transform.position, Quaternion.identity, attacked_unit.transform);
                damagetext.GetComponent <TextMesh>().color         = Color.yellow;
                damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * ((float)10 / 75f));
                damagetext.GetComponent <TextMesh>().text          = damageDealt.ToString();

                if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
                {
                    damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                             damagetext.transform.localScale.z);

                    //damagetext.GetComponent<TextMesh>().color = Color.green;
                    //Debug.Log("BackWards Text");
                }
                else
                {
                    if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                    {
                        damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                 damagetext.transform.localScale.z);
                    }
                }
                attacked_unit.TakeDamage(attacked_unit, damageDealt); // true damage so no need to incorporate
                attacked_unit.PlayHit();
                attacked_unit.PlayBlink(editor.Unit_Hurt_Color, attacked_unit, Time.time + 1f);

                if (attacked_unit.current_health <= 0)
                {
                    attacked_unit.dead = true;
                    editor.Units_To_Delete.Add(frontier[j]);
                    PoisonHero pHero;
                    if (gameObject.tag == "Player 1")
                    {
                        pHero = editor.P1Team[0].GetComponent <PoisonHero>();
                    }
                    else
                    {
                        pHero = editor.P2Team[0].GetComponent <PoisonHero>();
                    }
                    if (attacked_unit.tag == "TeamBuff") // was a buffmonster
                    {
                        GameObject buffItem = Instantiate(pHero.FloatingBuffPrefab, pHero.transform.position, Quaternion.identity, pHero.transform);
                        int        randBuff = Random.Range(0, 4);
                        //give correct buff accordingly
                        Debug.Log("acquiring buff");
                        if (randBuff == 0) // movement buff
                        {
                            buffItem.GetComponent <SpriteRenderer>().sprite = pHero.mobilityBuff;
                            Debug.Log(name + " got a movement buff");
                            pHero.current_mobility += 1;
                            pHero.move_buff         = true;
                            if (pHero.current_health != pHero.health)
                            {
                                pHero.current_health += 10;
                            }
                        }
                        else if (randBuff == 1) // crit buff
                        {
                            buffItem.GetComponent <SpriteRenderer>().sprite = pHero.critBuff;
                            Debug.Log(name + " got a crit buff");
                            pHero.crit     += 0.20f;
                            pHero.crit_buff = true;
                            if (pHero.current_health != pHero.health)
                            {
                                pHero.current_health += 10;
                            }
                        }
                        else if (randBuff == 2) // attack buff
                        {
                            Debug.Log(name + " got an attack buff");
                            buffItem.GetComponent <SpriteRenderer>().sprite = pHero.attackBuff;
                            pHero.attack         += 25;
                            pHero.current_attack += 25;
                            pHero.attack_buff     = true;
                            if (pHero.current_health != pHero.health)
                            {
                                pHero.current_health += 10;
                            }
                        }
                        else // health buff
                        {
                            Debug.Log(name + " got a health buff");
                            buffItem.GetComponent <SpriteRenderer>().sprite = pHero.healthBuff;
                            pHero.health         += 100;
                            pHero.current_health += 100;

                            pHero.health_buff = true;
                        }
                        if (pHero.current_health > (pHero.health * 0.4f))
                        {
                            pHero.anim.SetBool("Injured", false);
                            pHero.Injured = false;
                        }
                        float healthpercent = pHero.current_health / pHero.health; //    120/180 = .667

                        float attack_deduction = 1 - healthpercent;                //   1 - .667 = .333
                        float reduction        = attack_deduction / 2;
                        float new_attack       = pHero.attack * reduction;         //   72 * .333 = 23.76
                        pHero.current_attack = pHero.attack + new_attack;          // 72 - 23.76 = 48

                        gameObject.GetComponentInChildren <Buff_UI_Manager>().update_current_buffs(pHero);
                    }
                }
            }
        }
        GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().fizzleSound.Play();
        yield return(new WaitForSeconds(anim_time));

        GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().fizzleSound.Stop();
        Debug.Log("effect finishing");
    }
Example #15
0
 public void Change_Health(int change_by, StartUnit target)
 {
     target.current_health = target.current_health + change_by;
     target.health_bar.GetComponent <Image>().fillAmount = target.current_health / target.health;
 }
    void Debuff()
    {
        if (this.GetComponent <HexagonCell>().occupied) //if someones on this tile
        {
            mobility = this.GetComponent <HexagonCell>().unitOnTile.mobility;
            PrevUnit = this.GetComponent <HexagonCell>().unitOnTile;
            if (this.GetComponent <HexagonCell>().unitOnTile.current_mobility == mobility)//if our mobility equals our og mobility then debuff
            {
                if (grassDebuff)
                {
                    if (this.GetComponent <HexagonCell>().unitOnTile.current_mobility - 1 <= 0)
                    {
                        this.GetComponent <HexagonCell>().unitOnTile.current_mobility = 1;
                        //discovered = false;
                    }
                    else
                    {
                        this.GetComponent <HexagonCell>().unitOnTile.current_mobility = this.GetComponent <HexagonCell>().unitOnTile.current_mobility - 1;
                        //discovered = false;
                    }
                }
                if (waterDebuff)
                {
                    if (this.GetComponent <HexagonCell>().unitOnTile.current_mobility - 2 <= 0)
                    {
                        this.GetComponent <HexagonCell>().unitOnTile.current_mobility = 1;
                        // discovered = false;
                    }
                    else
                    {
                        this.GetComponent <HexagonCell>().unitOnTile.current_mobility = this.GetComponent <HexagonCell>().unitOnTile.current_mobility - 2;
                        // discovered = false;
                    }
                }
            }
        }
        //if (discovered && this.GetComponent<HexagonCell>().unitOnTile != null)
        //{
        //    if (grassDebuff)
        //    {
        //        if (this.GetComponent<HexagonCell>().occupied)
        //        {
        //            PrevUnit = this.GetComponent<HexagonCell>().unitOnTile;
        //            if (this.GetComponent<HexagonCell>().unitOnTile.mobility - 1 == 0)
        //            {
        //                this.GetComponent<HexagonCell>().unitOnTile.mobility = 1;
        //                discovered = false;
        //            }
        //            else
        //            {
        //                this.GetComponent<HexagonCell>().unitOnTile.mobility = this.GetComponent<HexagonCell>().unitOnTile.mobility - 1;
        //                discovered = false;
        //            }
        //        }
        //    }

        //    if (waterDebuff)
        //    {
        //        if (this.GetComponent<HexagonCell>().occupied)
        //        {
        //            PrevUnit = this.GetComponent<HexagonCell>().unitOnTile;
        //            if (this.GetComponent<HexagonCell>().unitOnTile.mobility - 2 == 0)
        //            {
        //                this.GetComponent<HexagonCell>().unitOnTile.mobility = 1;
        //                discovered = false;
        //            }
        //            else
        //            {
        //                this.GetComponent<HexagonCell>().unitOnTile.mobility = this.GetComponent<HexagonCell>().unitOnTile.mobility - 2;
        //                discovered = false;
        //            }
        //        }
        //    }
        //}
    }
Example #17
0
 public void PlayBlink(Color32 color, StartUnit unit, float time_until) // similar to PlayHit() to pass initiative to the object so it can actually perform the coroutine
 {
     StartCoroutine(Blink(color, unit, time_until));
 }
Example #18
0
    public virtual IEnumerator Retaliate(Grid hexGrid, HexagonCell unitCell_to_attack, HexagonCell unitCell_is_attacking) // return bool yes if dead false if no
    {
        //for effects that trigger on a unit getting attacked
        Unit_Getting_Attacked = unitCell_to_attack.unitOnTile.gameObject;
        //Debug.Log("Called_Retaliate");
        attacked_unit_has_died = false;
        string attacker = unitCell_is_attacking.unitOnTile.unit_name;
        string receiver = unitCell_to_attack.unitOnTile.unit_name;

        editor.cursor.Assign_Position(this.transform.position, hexGrid.GetCell(this.transform.position).coords);
        editor.Main_Cam.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, editor.Main_Cam.transform.position.z);
        //StartCoroutine(this.Blink(Color.green, this, Time.time + 0.8f));
        yield return(new WaitForSeconds(0.3f));


        StartUnit    attacked_unit = unitCell_to_attack.unitOnTile;
        HexagonCell  attacked_cell = unitCell_to_attack;
        HexagonCoord current       = unitCell_is_attacking.coords;

        float crit_chance   = Random.value;
        float miss_chance   = Random.value;
        float damage        = current_attack - attacked_unit.defense;
        int   dmg_txt       = (int)damage;
        bool  crit_happened = false;

        //deals with missing or critting

        if (miss_chance <= miss || damage <= 0)
        {
            damage = 0;
        }
        else if (crit_chance <= crit)
        {
            damage  = current_attack * crit_multiplier;
            dmg_txt = (int)damage;
            int rand = Random.Range(0, 2);
            if (rand == 0)
            {
                GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().PlayOneFromList(GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().critSounds);
            }
            crit_happened = true;
        }

        //Half Damage On Retaliate???
        if (!unitCell_is_attacking.unitOnTile.gameObject.CompareTag("TeamBuff"))
        {
            damage  = damage * 0.5f;
            dmg_txt = (int)damage;
        }
        else
        {
            Debug.Log("Buff Mob Retaliated ------->");
        }


        //Deals with facing the individual that is getting attacked

        if (attacked_cell.gameObject.transform.position.x > transform.position.x) //going right
        {
            if (!direction)                                                       //facing left
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                direction            = true;
            }
        }
        else //going left
        {
            if (direction)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                direction            = false;
            }
        }

        //Deals with Creating the correct Damage Text

        if (attacked_unit.FloatingTextPrefab)
        {
            GameObject damagetext = Instantiate(attacked_unit.FloatingTextPrefab, attacked_unit.transform.position, Quaternion.identity, attacked_unit.transform);
            if (damage == 0)
            {
                damagetext.GetComponent <TextMesh>().text = "MISS";
                int rand = Random.Range(0, 2);
                if (rand == 0)
                {
                    GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().PlayOneFromList(GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().missSounds);
                }
                damagetext.GetComponent <TextMesh>().color         = Color.white;
                damagetext.GetComponent <TextMesh>().characterSize = 0.06f;
            }


            if (damage != 0)
            {
                damagetext.GetComponent <TextMesh>().text = dmg_txt.ToString();
                if (crit_happened)
                {
                    damagetext.GetComponent <TextMesh>().color         = Color.red;
                    damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * ((float)dmg_txt / 75f));
                }
                else
                {
                    damagetext.GetComponent <TextMesh>().color         = Color.yellow;
                    damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * ((float)dmg_txt / 75f));
                }
            }

            if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
            {
                damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                         damagetext.transform.localScale.z);

                //damagetext.GetComponent<TextMesh>().color = Color.green;
                //Debug.Log("BackWards Text");
            }
            else
            {
                if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                {
                    damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                             damagetext.transform.localScale.z);
                }
            }
        }

        //Deal with change in health on attacked unit

        int to_deal = (int)(damage * -1);

        Change_Health(to_deal, attacked_unit);

        //Deals with damage health scaling... prolly shouldn't be done like this TBH

        //if (attacked_unit.current_attack > 10)
        //{
        //    float percenthealth = attacked_unit.current_health / attacked_unit.health;
        //    attacked_unit.current_attack *= percenthealth;
        //}
        Debug.Log("Retaliation: " + attacker + "hit " + receiver + "for " + damage);
        TakeDamage(attacked_unit, damage);

        if (attacked_unit.current_health <= 0)
        {
            attacked_unit_has_died = true;
        }

        StartCoroutine(Retaliate_Anim(attacked_unit));
        //Debug.Log("he dead");
        if (attacked_unit.current_health <= 0)
        {
            GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().PlayOneFromList(GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().killSounds);
            //int index = attacked_cell.coords.X_coord + attacked_cell.coords.Z_coord * hexGrid.width + attacked_cell.coords.Z_coord / 2;
            //editor.RemoveUnitInfo(attacked_cell, index);
            //Debug.Log("adding unit to delete list in relatiation");


            attacked_unit.dead = true;
            editor.Units_To_Delete.Add(attacked_cell);

            yield return(new WaitForSeconds(0.3f));

            StartCoroutine(attacked_unit.Hit());
            StartCoroutine(attacked_unit.Blink(editor.Unit_Hurt_Color, attacked_unit, Time.time + 1f));

            //Some Kinda Death Animation Coroutine Here
        }
        else
        {
            yield return(new WaitForSeconds(0.3f));

            if (attacked_unit.gameObject.GetComponent <FortressHero>() != null && damage != 0) // handling of if attacking fortress hero
            {
                Debug.Log("Hurt by fortress hero's armor in retaliation");
                if (FloatingTextPrefab)
                {
                    GameObject damagetext = Instantiate(FloatingTextPrefab, transform.position, Quaternion.identity, transform);
                    damagetext.GetComponent <TextMesh>().text          = 20.ToString();
                    damagetext.GetComponent <TextMesh>().color         = Color.yellow;
                    damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * (20f / 75f));
                    if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
                    {
                        damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                 damagetext.transform.localScale.z);

                        //damagetext.GetComponent<TextMesh>().color = Color.green;
                        //Debug.Log("BackWards Text");
                    }
                    else
                    {
                        if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                        {
                            damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                     damagetext.transform.localScale.z);
                        }
                    }
                }

                TakeDamage(this, 20f);
                StartCoroutine(AttackToHit());
                StartCoroutine(Blink(editor.Unit_Hurt_Color, this, Time.time + 1f));
                if (current_health <= 0) // pretty sure there's more code needed here but i'll ask christophe later
                {
                    editor.Units_To_Delete.Add(unitCell_is_attacking);
                    dead = true;
                }
            }

            StartCoroutine(attacked_unit.Hit());
            StartCoroutine(attacked_unit.Blink(editor.Unit_Hurt_Color, attacked_unit, Time.time + 1f));
        }
    }
Example #19
0
    private void _Move(string dir, int sign)
    {
        //Deal with indexing errors by checking len of cell array.
        //When going up or down on the stick just go in the y then z.

        prev_coords = coords;

        int prev_coord_x = coords.X_coord;
        int prev_coord_z = coords.Z_coord;

        if (dir.Equals("z"))
        {
            coords.z += sign;
        }

        if (dir.Equals("x"))
        {
            coords.x += sign;
        }

        if (dir.Equals("y"))
        {
            coords.x -= sign;
            coords.z += sign;
        }

        HexagonCoord next_cell;
        HexagonCell  next_hex_cell;

        try
        {
            next_cell     = _Grid.Get_Cell_Index(coords).coords;
            next_hex_cell = _Grid.Get_Cell_Index(coords);

            if (coords.X_coord == next_cell.X_coord && coords.Z_coord == next_cell.Z_coord)
            {
                //It found a real tile.
                if (editor.isUnitSelected)
                {
                    if (next_hex_cell.distance <= editor.SelectedUnit.current_mobility)
                    {
                        gameObject.transform.position = _Grid.Get_Cell_Index(coords).gameObject.transform.position;
                        Move_Sound.Play();
                    }
                    else
                    {
                        coords.x = prev_coord_x;
                        coords.z = prev_coord_z;
                    }
                }
                else
                {
                    gameObject.transform.position = _Grid.Get_Cell_Index(coords).gameObject.transform.position;
                    Move_Sound.Play();
                }
            }
            else
            {
                //It found a not-real tile. Revert Change.
                coords.x = prev_coord_x;
                coords.z = prev_coord_z;
            }
        }
        catch (System.IndexOutOfRangeException e)
        {
            coords.x = prev_coord_x;
            coords.z = prev_coord_z;
            Debug.Log(e.Message);
        }


        if (editor.isUnitSelected)
        {
            editor.Show_Units_In_Range();
            //add to if statement if you dont want the same unit to pop up in both
            //&& editor.SelectedUnit != _Grid.Get_Cell_Index(coords).unitOnTile
            if (_Grid.Get_Cell_Index(coords).unitOnTile != null)
            {
                //if(editor.allow_cursor_control)
                StartUnit _tileUnit = _Grid.Get_Cell_Index(coords).unitOnTile;

                BattleUI _tileUnit_UI = _tileUnit.Unit_Stats_Panel.GetComponent <BattleUI>();
                editor.Assign_Stats_Var(_tileUnit_UI, _tileUnit);
                _tileUnit_UI.Show();
            }
        }
        else
        {
            if (_Grid.Get_Cell_Index(coords).unitOnTile != null)
            {
                StartUnit _tileUnit = _Grid.Get_Cell_Index(coords).unitOnTile;

                BattleUI _tileUnit_UI = _tileUnit.Unit_Stats_Panel.GetComponent <BattleUI>();
                editor.Assign_Stats_Var(_tileUnit_UI, _tileUnit);
                _tileUnit_UI.Show();
            }
        }

        Hide_Prev_UI();

        Order_Cursor(_Grid.GetCell(transform.position).coords, _Grid.sprites_per_tile);

        //deal with UI_List_Manager On Move
        UI_List_Manager.update_current_controls();

        //Debug.Log("Current X " + coords.X_coord);
        //Debug.Log("Current Y " + coords.Y_coord);
        //Debug.Log("Current Z " + coords.Z_coord);
        //Debug.Log(_Grid.Get_Cell_Index(coords).gameObject.transform.position);
    }
Example #20
0
 public void update_current_buffs(StartUnit Unit_To_Buffdate)
 {
     remove_current_buffs();
     populate_current_buffs(Unit_To_Buffdate);
 }
Example #21
0
    public HexagonCell[] ChangeHexInfo(HexagonCell[] cells_, List <int> hexlist_, List <int> powercells_, List <int> hazards_, List <int> sky, List <int> water_)
    {
        if (hexlist_.Count != 0)
        {
            for (int i = 0; i < hexlist_.Count; i++)
            {
                cells_[hexlist_[i]].gameObject.tag = "Wall";
                cells_[hexlist_[i]].traversable    = false;
                cells_[hexlist_[i]].gameObject.GetComponent <PolygonCollider2D>().enabled = false;
                cells_[hexlist_[i]].gameObject.GetComponent <SpriteRenderer>().sprite     = Wall;

                //  cells_[hexlist_[i]].gameObject.GetComponent<SpriteRenderer>().color = Color.gray;
            }
        }

        if (powercells_.Count != 0)
        {
            for (int i = 0; i < powercells_.Count; i++)
            {
                GameObject GO = Instantiate(buffPrefab);
                GO.transform.position          = cells[powercells_[i]].transform.position;
                cells[powercells_[i]].occupied = true;
                StartUnit startUnit = GO.GetComponent <StartUnit>();
                Anima2D.SpriteMeshInstance[] Unit_Meshes = GO.gameObject.GetComponentsInChildren <Anima2D.SpriteMeshInstance>();
                for (int k = 0; k < Unit_Meshes.Length; k++)
                {
                    //puts each unit in a section of the sorting layer according to the tile they are on.
                    Unit_Meshes[k].sortingOrder = Unit_Meshes[k].GetComponent <Mesh_Layer>()._ordered_layer
                                                  + ((cells[powercells_[i]].coords.X_coord + cells[powercells_[i]].coords.Y_coord) * sprites_per_tile);
                    //Debug.Log("Color_Changed");
                }
                cells[powercells_[i]].unitOnTile = startUnit;
                startUnit.Unit_Stats_Panel.GetComponent <BattleUI>().Hide();
                //Anima2D.SpriteMeshInstance[] Unit_Meshes = startUnit.gameObject.GetComponentsInChildren<Anima2D.SpriteMeshInstance>();
            }
        }

        if (hazards_.Count != 0)
        {
            for (int i = 0; i < hazards_.Count; i++)
            {
                cells_[hazards_[i]].gameObject.tag = "SlowingTile";
                cells_[hazards_[i]].gameObject.AddComponent <TeamPowerupTiles>();
                cells_[hazards_[i]].gameObject.GetComponent <SpriteRenderer>().sprite = SlowingTile;
                //cells_[hazards_[i]].gameObject.GetComponent<TeamPowerupTiles>().discovered = true;
                cells_[hazards_[i]].gameObject.GetComponent <TeamPowerupTiles>().grassDebuff = true;
                // cells_[hazards_[i]].gameObject.GetComponent<SpriteRenderer>().color = Color.green;
            }
        }

        if (sky.Count != 0)
        {
            for (int i = 0; i < sky.Count; i++)
            {
                cells_[sky[i]].gameObject.tag = "Wall";
                cells_[sky[i]].traversable    = false;
                cells_[sky[i]].gameObject.GetComponent <PolygonCollider2D>().enabled = false;
                cells_[sky[i]].gameObject.GetComponent <SpriteRenderer>().sprite     = Sky;
            }
        }


        if (water_.Count != 0)
        {
            for (int i = 0; i < water_.Count; i++)
            {
                cells_[water_[i]].gameObject.tag = "Water";
                cells_[water_[i]].gameObject.AddComponent <TeamPowerupTiles>();
                cells_[water_[i]].gameObject.GetComponent <SpriteRenderer>().sprite = Water;
                // cells_[hazards_[i]].gameObject.GetComponent<TeamPowerupTiles>().discovered = true;
                cells_[water_[i]].gameObject.GetComponent <TeamPowerupTiles>().waterDebuff = true;
                //  cells_[water_[i]].gameObject.GetComponent<SpriteRenderer>().color = Color.blue;
            }
        }

        for (int i = 0; i < cells_.Length; i++)
        {
            Add_Clutter(cells_[i]);
            Order_Cell(cells_[i], sprites_per_tile);
        }
        return(cells_);
    }
Example #22
0
    public override IEnumerator Effect(HexagonMapEditor editor, Grid hexGrid, int x, int z, int size)
    {
        List <HexagonCell> frontier = new List <HexagonCell>(); // list of nodes that the hazard has effect over
        HexagonCell        curr     = hexGrid.Get_Cell_Index(new HexagonCoord(x, z));

        Debug.Log(type_name + " hazard epicenter at: " + curr.coords.x + "," + curr.coords.Y_coord + "," + curr.coords.z);
        curr.CreateMissile();
        GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().launchSound.Play(); // play launch sound instead
        for (int i = 0; i < hexGrid.cells.Length; i++)
        {
            int distance = curr.coords.FindDistanceTo(hexGrid.cells[i].coords);
            if (distance <= size)
            {
                frontier.Add(hexGrid.cells[i]);
                hexGrid.cells[i].Create_Caution_Sign();
            }
        }
        yield return(new WaitForSeconds(anim_time - 1));

        GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().explosionSound.Play(); // play explosion sound instead

        for (int j = 0; j < frontier.Count; j++)
        {
            Destroy(frontier[j].Caution_Sign_Obj);

            if (frontier[j].occupied)
            {
                //frontier[j].unitOnTile.current_health -= damage - frontier[j].unitOnTile.defense; // this should be changeed when we are trying to implement the fortress hero's defense

                StartUnit  attacked_unit = frontier[j].unitOnTile;
                GameObject damagetext    = Instantiate(attacked_unit.FloatingTextPrefab, attacked_unit.transform.position, Quaternion.identity, attacked_unit.transform);
                damagetext.GetComponent <TextMesh>().color         = Color.yellow;
                damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * ((float)10 / 75f));
                damagetext.GetComponent <TextMesh>().text          = (damage - frontier[j].unitOnTile.defense).ToString();

                if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
                {
                    damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                             damagetext.transform.localScale.z);

                    //damagetext.GetComponent<TextMesh>().color = Color.green;
                    //Debug.Log("BackWards Text");
                }
                else
                {
                    if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                    {
                        damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                 damagetext.transform.localScale.z);
                    }
                }

                attacked_unit.TakeDamage(attacked_unit, (damage - frontier[j].unitOnTile.defense));
                attacked_unit.PlayHit();
                attacked_unit.PlayBlink(editor.Unit_Hurt_Color, attacked_unit, Time.time + 1f);

                if (attacked_unit.current_health <= 0)
                {
                    attacked_unit.dead = true;
                    editor.Units_To_Delete.Add(frontier[j]);
                }
            }
        }
        yield return(new WaitForSeconds(1f));

        Debug.Log("effect finishing");
        Destroy(curr.Missile_Obj);
    }
Example #23
0
    public IEnumerator Kidnap(Grid hexGrid, HexagonCell unitCell) // kidnap a random dumbass
    {
        Debug.Log("kidnap the unit");
        end_attack_without_retaliate = true;
        attacked_unit_has_died       = false;

        string name = unitCell.unitOnTile.unit_name;

        attackRange = specialRange;

        //add a call to a retaliate function on the other unit
        List <HexagonCell> targetable = new List <HexagonCell>();

        //Debug.Log(unitCell.unitOnTile.unit_name + " atttacking: ");
        foreach (HexagonCell cell in hexGrid.cells)
        {
            if (unitCell.coords.FindDistanceTo(cell.coords) <= attackRange &&
                unitCell.coords.FindDistanceTo(cell.coords) > 0 &&
                cell.occupied &&
                !cell.unitOnTile.dead &&
                tag != cell.unitOnTile.tag)
            {
                targetable.Add(cell);
            }
        }

        if (targetable.Count >= 1)
        {
            editor.cursor.Assign_Position(this.transform.position, hexGrid.GetCell(this.transform.position).coords);
            Vector3 _new_Camera_Pos = new Vector3(this.transform.position.x, this.transform.position.y, editor.Main_Cam.transform.position.z);
            editor.Main_Cam.transform.position = Vector3.Lerp(editor.Main_Cam.transform.position, _new_Camera_Pos, 1f);

            yield return(new WaitForSeconds(0.3f));

            int selectedTarget = ChosenEnemy(targetable);

            float crit_chance = Random.value;
            float miss_chance = Random.value;
            float damage;
            if (targetable[selectedTarget].GetComponent <HeroUnit>() != null)
            {
                damage = (current_attack * 1.5f) - targetable[selectedTarget].unitOnTile.defense;
            }
            else
            {
                damage = current_attack - targetable[selectedTarget].unitOnTile.defense;
            }
            Debug.Log("Damage: " + damage);
            int  dmg_txt       = (int)damage;
            bool crit_happened = false;

            editor.printState();
            if (targetable[selectedTarget].unitOnTile.FloatingTextPrefab)
            {
                //Debug.Log("fadef");
                if (miss_chance <= miss)
                {
                    damage = 0;
                }
                else
                {
                    if (crit_chance <= crit && miss_chance > miss)
                    {
                        int rand = Random.Range(0, 2);
                        if (rand == 0)
                        {
                            GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().PlayOneFromList(GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().critSounds);
                        }
                        damage        = current_attack * crit_multiplier;
                        crit_happened = true;
                    }
                }
                dmg_txt = (int)damage;
            }



            //for (HexagonDirection d = HexagonDirection.NE; d <= HexagonDirection.NW; d++)
            //{
            //    HexagonCell neighbor = unitCell.GetNeighbor(d);
            //    if (!neighbor.occupied && neighbor.tag != "Wall" && targetable[selectedTarget].unitOnTile.GetComponent<HeroUnit>() == null) // if a neighbor to the hero is not occupied or wall unit not hero
            //    {
            //        targetable[selectedTarget].unitOnTile.transform.position = neighbor.transform.position; // move the bitch
            //        neighbor.occupied = true;
            //        neighbor.unitOnTile = targetable[selectedTarget].unitOnTile;
            //        temp_attacked_unit = neighbor.unitOnTile;
            //        temp_attacked_cell = neighbor;
            //        targetable[selectedTarget].occupied = false;
            //        targetable[selectedTarget].unitOnTile = null;
            //        //correctly sort kidnapped unit's meshes
            //        editor.re_sort_unit_position(temp_attacked_unit, temp_attacked_cell);
            //        break;
            //    }
            //}

            StartUnit   attacked_unit;
            HexagonCell attacked_cell;
            if (temp_attacked_unit != null)
            {
                attacked_unit = temp_attacked_unit;
                attacked_cell = temp_attacked_cell;
            }
            else
            {
                attacked_unit = targetable[selectedTarget].unitOnTile;
                attacked_cell = targetable[selectedTarget];
            }
            HexagonCoord current = unitCell.coords;

            if (attacked_cell.gameObject.transform.position.x > transform.position.x) //unit is to the right
            {
                if (!direction)                                                       //facing left, so needs to face right
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = true;
                }
            }
            else //unit is to the left
            {
                if (direction)
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = false;
                }
            }

            //-------------------------- Testing Kidnapp Stuff ----------------------

            StartCoroutine(move_to_kidnap(attacked_unit.gameObject, attacked_unit, attacked_cell, targetable[selectedTarget]));
            if (targetable[selectedTarget].unitOnTile.GetComponent <HeroUnit>() == null)
            {
                yield return(new WaitForSeconds(1.40f)); //---- for sync with kidnap to
            }
            else
            {
                yield return(new WaitForSeconds(2.10f)); //---- for sync with kidnap to
            }



            for (HexagonDirection d = HexagonDirection.NE; d <= HexagonDirection.NW; d++)
            {
                HexagonCell neighbor = unitCell.GetNeighbor(d);
                if (!neighbor.occupied && neighbor.tag != "Wall" && targetable[selectedTarget].unitOnTile.GetComponent <HeroUnit>() == null) // if a neighbor to the hero is not occupied or wall unit not hero
                {
                    targetable[selectedTarget].unitOnTile.transform.position = neighbor.transform.position;                                  // move the bitch
                    neighbor.occupied   = true;
                    neighbor.unitOnTile = targetable[selectedTarget].unitOnTile;
                    temp_attacked_unit  = neighbor.unitOnTile;
                    temp_attacked_cell  = neighbor;
                    targetable[selectedTarget].occupied   = false;
                    targetable[selectedTarget].unitOnTile = null;
                    //correctly sort kidnapped unit's meshes
                    editor.re_sort_unit_position(temp_attacked_unit, temp_attacked_cell);
                    break;
                }
            }

            yield return(new WaitForSeconds(0.26f)); //---- for sync with kidnap to


            if (temp_attacked_unit != null)
            {
                attacked_unit = temp_attacked_unit;
                attacked_cell = temp_attacked_cell;
            }
            else
            {
                attacked_unit = targetable[selectedTarget].unitOnTile;
                attacked_cell = targetable[selectedTarget];
            }

            if (attacked_cell.gameObject.transform.position.x > transform.position.x) //unit is to the right
            {
                if (!direction)                                                       //facing left, so needs to face right
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = true;
                }
            }
            else //unit is to the left
            {
                if (direction)
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = false;
                }
            }

            //-------------------------- Testing Kidnapp Stuff ---------------------- ^^^^

            if (attacked_unit.FloatingTextPrefab)
            {
                GameObject damagetext = Instantiate(attacked_unit.FloatingTextPrefab, attacked_unit.transform.position, Quaternion.identity, attacked_unit.transform);
                if (damage == 0)
                {
                    damagetext.GetComponent <TextMesh>().text = "MISS";
                    int rand = Random.Range(0, 2);
                    if (rand == 0)
                    {
                        GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().PlayOneFromList(GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().missSounds);
                    }
                    damagetext.GetComponent <TextMesh>().color         = Color.white;
                    damagetext.GetComponent <TextMesh>().characterSize = 0.06f;
                }


                if (damage != 0)
                {
                    damagetext.GetComponent <TextMesh>().text = dmg_txt.ToString();
                    if (crit_happened)
                    {
                        damagetext.GetComponent <TextMesh>().color         = Color.red;
                        damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * ((float)dmg_txt / 75f));
                    }
                    else
                    {
                        damagetext.GetComponent <TextMesh>().color         = Color.yellow;
                        damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * ((float)dmg_txt / 75f));
                    }
                }

                if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
                {
                    damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                             damagetext.transform.localScale.z);

                    //damagetext.GetComponent<TextMesh>().color = Color.green;
                    //Debug.Log("BackWards Text");
                }
                else
                {
                    if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                    {
                        damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                 damagetext.transform.localScale.z);
                    }
                }
            }
            Debug.Log(name + " attacked " + attacked_unit.unit_name + " for " + damage);
            TakeDamage(attacked_unit, damage);


            //Debug.Log("he dead");
            if (attacked_unit.current_health <= 0)
            {
                GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().PlayOneFromList(GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().killSounds);

                if (attacked_unit.tag == "TeamBuff") // was a buffmonster
                {
                    GameObject buffItem = Instantiate(FloatingBuffPrefab, transform.position, Quaternion.identity, transform);
                    int        randBuff = Random.Range(0, 4);
                    //give correct buff accordingly
                    Debug.Log("acquiring buff");
                    if (randBuff == 0) // movement buff
                    {
                        buffItem.GetComponent <SpriteRenderer>().sprite = mobilityBuff;
                        Debug.Log(name + " got a movement buff");
                        current_mobility += 1;
                        move_buff         = true;
                        if (current_health != health)
                        {
                            current_health += 10;
                        }
                    }
                    else if (randBuff == 1) // crit buff
                    {
                        buffItem.GetComponent <SpriteRenderer>().sprite = critBuff;
                        Debug.Log(name + " got a crit buff");
                        crit     += 0.20f;
                        crit_buff = true;
                        if (current_health != health)
                        {
                            current_health += 10;
                        }
                    }
                    else if (randBuff == 2) // attack buff
                    {
                        Debug.Log(name + " got an attack buff");
                        buffItem.GetComponent <SpriteRenderer>().sprite = attackBuff;
                        attack         += 25;
                        current_attack += 25;
                        attack_buff     = true;
                        if (current_health != health)
                        {
                            current_health += 10;
                        }
                    }
                    else // health buff
                    {
                        Debug.Log(name + " got a health buff");
                        buffItem.GetComponent <SpriteRenderer>().sprite = healthBuff;
                        health         += 100;
                        current_health += 100;

                        health_buff = true;
                    }

                    if (current_health > (health * 0.4f))
                    {
                        this.anim.SetBool("Injured", false);
                        this.Injured = false;
                    }

                    gameObject.GetComponentInChildren <Buff_UI_Manager>().update_current_buffs(this);

                    float healthpercent = current_health / health;             //    120/180 = .667

                    float attack_deduction = 1 - healthpercent;                //   1 - .667 = .333
                    float reduction        = attack_deduction / 2;
                    float new_attack       = attacked_unit.attack * reduction; //   72 * .333 = 23.76
                    current_attack = attack + new_attack;                      // 72 - 23.76 = 48
                }
                end_attack_without_retaliate = true;
                attacked_unit_has_died       = true;
                StartCoroutine(Attack(hexGrid, unitCell, attacked_cell));
                //int index = targetable[rand_index].coords.X_coord + targetable[rand_index].coords.Z_coord * hexGrid.width + targetable[rand_index].coords.Z_coord / 2;
                //editor.RemoveUnitInfo(targetable[rand_index], index);

                editor.Units_To_Delete.Add(attacked_cell);
                attacked_unit.dead = true;


                yield return(new WaitForSeconds(0.3f));

                StartCoroutine(attacked_unit.Hit());
                StartCoroutine(attacked_unit.Blink(editor.Unit_Hurt_Color, attacked_unit, Time.time + 1f));

                //attacked_unit.Fade_Out_Body();
                //Should start some sort of DEATH ANIMATION COROUTINE HERE
                specialAttackCounter = 3;
                attackRange          = 1;
                temp_attacked_cell   = null;
                temp_attacked_unit   = null;
            }
            else
            {
                if (unitCell.coords.FindDistanceTo(attacked_cell.coords) <= attacked_cell.unitOnTile.attackRange)
                {
                    end_attack_without_retaliate = false;
                }
                else
                {
                    end_attack_without_retaliate = true;
                }
                if (current_health - 20 <= 0 && attacked_unit.gameObject.GetComponent <FortressHero>() != null)
                {
                    end_attack_without_retaliate = true;
                }

                StartCoroutine(Attack(hexGrid, unitCell, attacked_cell));
                yield return(new WaitForSeconds(0.3f));

                //if (attacked_unit.gameObject.GetComponent<FortressHero>() != null && damage != 0) // handling of if attacking fortress hero
                //{
                //    Debug.Log("Hurt by fortress hero's armor");
                //    if (FloatingTextPrefab)
                //    {
                //        GameObject damagetext = Instantiate(FloatingTextPrefab, transform.position, Quaternion.identity, transform);
                //        damagetext.GetComponent<TextMesh>().text = 20.ToString();
                //        damagetext.GetComponent<TextMesh>().color = Color.yellow;
                //        damagetext.GetComponent<TextMesh>().characterSize = 0.03f + (0.06f * (20f / 75f));
                //        if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
                //        {
                //            damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                //                damagetext.transform.localScale.z);

                //            //damagetext.GetComponent<TextMesh>().color = Color.green;
                //            //Debug.Log("BackWards Text");
                //        }
                //        else
                //        {
                //            if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                //            {
                //                damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                //                    damagetext.transform.localScale.z);
                //            }
                //        }
                //    }

                //    TakeDamage(this, 20f);
                //    StartCoroutine(AttackToHit());
                //    StartCoroutine(Blink(editor.Unit_Hurt_Color, this, Time.time + 1f));
                //    if (current_health <= 0) // pretty sure there's more code needed here but i'll ask christophe later
                //    {
                //        editor.Units_To_Delete.Add(unitCell);
                //        dead = true;
                //    }

                //}
                StartCoroutine(attacked_unit.Hit());
                StartCoroutine(attacked_unit.Blink(editor.Unit_Hurt_Color, attacked_unit, Time.time + 1f));
            }
            specialAttackCounter = 3;
            attackRange          = 1;
            temp_attacked_cell   = null;
            temp_attacked_unit   = null;
        }
        else
        {
            specialAttackCounter = 0;
            attackRange          = 1;
            currently_attacking  = false;
        }
    }
Example #24
0
    public IEnumerator move_to_kidnap(GameObject Attacked_Unit, StartUnit attacked_unit, HexagonCell attacked_cell, HexagonCell cell_in_q)
    {
        if (cell_in_q.unitOnTile.GetComponent <HeroUnit>() == null)
        {
            this.anim.SetBool("Flash_Stepping", true);
            yield return(new WaitForSeconds(0.37f));

            Vector3 Origin_Pos   = this.gameObject.transform.position;
            Vector3 Attacked_Pos = Attacked_Unit.transform.position;
            if (direction)
            {
                //facing right
                this.gameObject.transform.position = new Vector3(Attacked_Pos.x - 10, Attacked_Pos.y, Attacked_Pos.z);
            }
            else
            {
                //facing left
                this.gameObject.transform.position = new Vector3(Attacked_Pos.x + 10, Attacked_Pos.y, Attacked_Pos.z);
            }
            yield return(new WaitForSeconds(1.03f));

            this.gameObject.transform.position = Origin_Pos;


            //---------------------- face unit as comes back
            if (temp_attacked_unit != null)
            {
                attacked_unit = temp_attacked_unit;
                attacked_cell = temp_attacked_cell;
            }
            else
            {
                attacked_unit = cell_in_q.unitOnTile;
                attacked_cell = cell_in_q;
            }

            if (attacked_cell.gameObject.transform.position.x > transform.position.x) //unit is to the right
            {
                if (!direction)                                                       //facing left, so needs to face right
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = true;
                }
            }
            else //unit is to the left
            {
                if (direction)
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = false;
                }
            }
            //--------------- face unit as comes back


            yield return(new WaitForSeconds(0.26f));

            this.anim.SetBool("Flash_Stepping", false);
        }
        else
        {
            this.anim.SetBool("Flash_Stepping_Hero", true);
            yield return(new WaitForSeconds(0.37f));

            Vector3 Origin_Pos   = this.gameObject.transform.position;
            Vector3 Attacked_Pos = Attacked_Unit.transform.position;
            if (direction)
            {
                //facing right
                this.gameObject.transform.position = new Vector3(Attacked_Pos.x - 13, Attacked_Pos.y, Attacked_Pos.z);
            }
            else
            {
                //facing left
                this.gameObject.transform.position = new Vector3(Attacked_Pos.x + 13, Attacked_Pos.y, Attacked_Pos.z);
            }
            yield return(new WaitForSeconds(1.73f));

            this.gameObject.transform.position = Origin_Pos;


            //---------------------- face unit as comes back
            if (temp_attacked_unit != null)
            {
                attacked_unit = temp_attacked_unit;
                attacked_cell = temp_attacked_cell;
            }
            else
            {
                attacked_unit = cell_in_q.unitOnTile;
                attacked_cell = cell_in_q;
            }

            if (attacked_cell.gameObject.transform.position.x > transform.position.x) //unit is to the right
            {
                if (!direction)                                                       //facing left, so needs to face right
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = true;
                }
            }
            else //unit is to the left
            {
                if (direction)
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = false;
                }
            }
            //--------------- face unit as comes back


            yield return(new WaitForSeconds(0.26f));

            this.anim.SetBool("Flash_Stepping_Hero", false);
        }
    }
Example #25
0
 public virtual void Debuf(StartUnit unit)
 {
     unit.current_attack -= 1;
 }
Example #26
0
    public override IEnumerator BasicAttack(Grid hexGrid, HexagonCell unitCell)
    {
        base.end_attack_without_retaliate = true;
        //add a call to a retaliate function on the other unit
        List <HexagonCell> targetable = new List <HexagonCell>();

        foreach (HexagonCell cell in hexGrid.cells)
        {
            if (unitCell.coords.FindDistanceTo(cell.coords) <= attackRange &&
                unitCell.coords.FindDistanceTo(cell.coords) > 0 &&
                cell.occupied &&
                !cell.unitOnTile.dead &&
                tag == cell.unitOnTile.tag &&
                cell.unitOnTile.current_health != cell.unitOnTile.health)
            {
                targetable.Add(cell);
            }
        }
        if (targetable.Count >= 1)
        {
            editor.cursor.Assign_Position(this.transform.position, hexGrid.GetCell(this.transform.position).coords);
            editor.Main_Cam.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, editor.Main_Cam.transform.position.z);
            //StartCoroutine(this.Blink(Color.green, this, Time.time + 0.8f));
            yield return(new WaitForSeconds(0.3f));

            int   rand_index    = Random.Range(0, targetable.Count);
            float crit_chance   = Random.value;
            float miss_chance   = Random.value;
            float damage        = current_attack;
            int   dmg_txt       = (int)damage;
            bool  crit_happened = false;

            if (miss_chance <= miss)
            {
                damage = 0;
            }
            if (crit_chance <= crit && miss_chance > miss)
            {
                damage  = current_attack * crit_multiplier;
                dmg_txt = (int)damage;
            }

            if (targetable[rand_index].unitOnTile.FloatingTextPrefab)
            {
                if (crit_chance < crit)
                {
                    damage        = current_attack * crit_multiplier;
                    crit_happened = true;
                }
                dmg_txt = (int)damage;
            }

            StartUnit    attacked_unit = targetable[rand_index].unitOnTile;
            HexagonCell  attacked_cell = targetable[rand_index];
            HexagonCoord current       = unitCell.coords;

            if (attacked_cell.gameObject.transform.position.x > transform.position.x) //unit is to the right
            {
                if (!direction)                                                       //facing left, so needs to face right
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = true;
                }
            }
            else //unit is to the left
            {
                if (direction)
                {
                    transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    direction            = false;
                }
            }

            if (attacked_unit.FloatingTextPrefab)
            {
                GameObject damagetext = Instantiate(attacked_unit.FloatingTextPrefab, attacked_unit.transform.position, Quaternion.identity, attacked_unit.transform);
                if (damage == 0)
                {
                    damagetext.GetComponent <TextMesh>().text          = "MISS";
                    damagetext.GetComponent <TextMesh>().color         = Color.white;
                    damagetext.GetComponent <TextMesh>().characterSize = 0.06f;
                }


                if (damage != 0)
                {
                    damagetext.GetComponent <TextMesh>().text = dmg_txt.ToString();
                    if (crit_happened)
                    {
                        damagetext.GetComponent <TextMesh>().color         = Color.green;
                        damagetext.GetComponent <TextMesh>().characterSize = 0.1f;
                    }
                    else
                    {
                        damagetext.GetComponent <TextMesh>().color         = Color.green;
                        damagetext.GetComponent <TextMesh>().characterSize = 0.06f;
                    }
                }

                if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
                {
                    damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                             damagetext.transform.localScale.z);

                    //damagetext.GetComponent<TextMesh>().color = Color.green;
                    //Debug.Log("BackWards Text");
                }
                else
                {
                    if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                    {
                        damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                 damagetext.transform.localScale.z);
                    }
                }
            }
            targetable[rand_index].unitOnTile.current_health += damage;
            if (this.gameObject.GetComponent <StartUnit>().current_health - 40 >= 40)
            {
                TakeDamage(this, 40f);
                if (FloatingTextPrefab)
                {
                    GameObject damagetext = Instantiate(FloatingTextPrefab, transform.position, Quaternion.identity, transform);
                    damagetext.GetComponent <TextMesh>().text          = 40.ToString();
                    damagetext.GetComponent <TextMesh>().color         = Color.yellow;
                    damagetext.GetComponent <TextMesh>().characterSize = 0.03f + (0.06f * (40f / 75f));
                    if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
                    {
                        damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                 damagetext.transform.localScale.z);
                    }
                    else
                    {
                        if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                        {
                            damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                                                                                     damagetext.transform.localScale.z);
                        }
                    }
                }
            }


            //this.GetComponent<StartUnit>().current_health -= 40;
            if (targetable[rand_index].unitOnTile.current_health > (targetable[rand_index].unitOnTile.health * 0.4f))
            {
                targetable[rand_index].unitOnTile.anim.SetBool("Injured", false);
                targetable[rand_index].unitOnTile.Injured = false;
            }

            if (targetable[rand_index].unitOnTile.current_health > targetable[rand_index].unitOnTile.health)
            {
                targetable[rand_index].unitOnTile.current_health = targetable[rand_index].unitOnTile.health;
            }
            float healthpercent = targetable[rand_index].unitOnTile.current_health / targetable[rand_index].unitOnTile.health; //    120/180 = .667
            Debug.Log(healthpercent);
            float attack_deduction = 1 - healthpercent;                                                                        //   1 - .667 = .333
            float reduction        = attack_deduction / 2;
            float new_attack       = targetable[rand_index].unitOnTile.attack * reduction;                                     //   72 * .333 = 23.76
            targetable[rand_index].unitOnTile.current_attack = targetable[rand_index].unitOnTile.attack + new_attack;          // 72 - 23.76 = 48

            if (targetable[rand_index].unitOnTile.current_attack >= targetable[rand_index].unitOnTile.attack)
            {
                targetable[rand_index].unitOnTile.current_attack = targetable[rand_index].unitOnTile.attack;
            }

            attacked_unit.health_bar.GetComponent <Image>().fillAmount = attacked_unit.current_health / attacked_unit.health; // fix?
            //if (targetable[rand_index].unitOnTile.current_attack > 10)
            //{
            //    float percenthealth = targetable[rand_index].unitOnTile.current_health / targetable[rand_index].unitOnTile.health;
            //    targetable[rand_index].unitOnTile.current_attack *= percenthealth;
            //}



            //Debug.Log("he dead");
            if (targetable[rand_index].unitOnTile.current_health > targetable[rand_index].unitOnTile.health)
            {
                end_attack_without_retaliate = true;
                StartCoroutine(Attack(hexGrid, unitCell, attacked_cell));
                //int index = targetable[rand_index].coords.X_coord + targetable[rand_index].coords.Z_coord * hexGrid.width + targetable[rand_index].coords.Z_coord / 2;
                //editor.RemoveUnitInfo(targetable[rand_index], index);
                targetable[rand_index].unitOnTile.current_health = targetable[rand_index].unitOnTile.health;
            }
            else
            {
                if (unitCell.coords.FindDistanceTo(attacked_cell.coords) <= attacked_cell.unitOnTile.attackRange)
                {
                    end_attack_without_retaliate = true;
                }
                else
                {
                    end_attack_without_retaliate = true;
                }

                StartCoroutine(Attack(hexGrid, unitCell, attacked_cell));
                yield return(new WaitForSeconds(0.3f));

                //if (FloatingTextPrefab)
                //{
                //    GameObject damagetext = Instantiate(FloatingTextPrefab, transform.position, Quaternion.identity, transform);
                //    damagetext.GetComponent<TextMesh>().text = 20.ToString();
                //    damagetext.GetComponent<TextMesh>().color = Color.yellow;
                //    damagetext.GetComponent<TextMesh>().characterSize = 0.03f + (0.06f * (20f / 75f));
                //    if (Mathf.Sign(damagetext.transform.parent.localScale.x) == -1 && Mathf.Sign(damagetext.transform.localScale.x) == 1)
                //    {
                //        damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                //            damagetext.transform.localScale.z);

                //    }
                //    else
                //    {
                //        if (Mathf.Sign(damagetext.transform.parent.localScale.x) == 1 && Mathf.Sign(damagetext.transform.localScale.x) == -1)
                //        {
                //            damagetext.gameObject.transform.localScale = new Vector3(damagetext.transform.localScale.x * -1, damagetext.transform.localScale.y,
                //                damagetext.transform.localScale.z);
                //        }
                //    }
                //}

                //TakeDamage(this, 20f);
                //StartCoroutine(AttackToHit());
                //StartCoroutine(Blink(editor.Unit_Hurt_Color, this, Time.time + 1f));
                //if (current_health <= 0)// pretty sure there's more code needed here but i'll ask christophe later
                //{
                //    editor.Units_To_Delete.Add(unitCell);
                //    dead = true;
                //}
                StartCoroutine(targetable[rand_index].unitOnTile.Hit());
                StartCoroutine(attacked_unit.Blink(editor.Unit_Hurt_Color, attacked_unit, Time.time + 1f));
            }
        }
        else
        {
            currently_attacking = false;
        }

        if (this.gameObject.GetComponent <StartUnit>().current_health <= 0)
        {
            editor.Units_To_Delete.Add(unitCell);
            this.dead = true;
        }
    }