private void MainEditor_MouseMove(object sender, MouseEventArgs e) { labelXYCoords.Text = "XY coords: " + e.Location.ToString(); var mainWindowOwner = (Owner as MainWindow); labelHexCoords.Text = "Hex coords: " + HexagonCoord.GetHexCoords(e.X, e.Y, mainWindowOwner.EditingGrid.EdgeLenght, new Point()).ToString(); }
public int damageDealt = 30; // amount of damage dealt by this effect public override HazardInfo CreateHazardAt(HexagonCell cell, Grid hexGrid) { // code to spawn the particle system or whatever to show the effect //Debug.Log("shooting poison gas on map"); HexagonCoord coord = cell.coords; int size = 1; List <HexagonCell> frontier = new List <HexagonCell>(); //HexagonCell curr = hexGrid.Get_Cell_Index(new HexagonCoord(rand.x, rand.z)); //HexagonCell hexa_cell = coord. for (int i = 0; i < hexGrid.cells.Length; i++) { int distance = cell.coords.FindDistanceTo(hexGrid.cells[i].coords); if (distance <= size) { frontier.Add(hexGrid.cells[i]); } } for (int j = 0; j < frontier.Count; j++) { frontier[j].Create_Poison_Cloud(); } //GameObject.FindGameObjectWithTag("SoundManager").GetComponent<SoundManager>().lightningSound.Play(); //GameObject.FindGameObjectWithTag("SoundManager").GetComponent<SoundManager>().rainSound.Play(); return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, 1)); }
public override HazardInfo CreateHazard(int size, HexagonCoord coord, Grid hexGrid) { //int randRange = Random.Range(0, hexGrid.cells.Length); //HexagonCoord rand = hexGrid.cells[randRange].coords; //int size = Random.Range(2,5); // 0 = 1, 1 = 3, 2 = 5 Debug.Log("hazard at (" + coord.x + "," + coord.z + ") with size: " + size); List <HexagonCell> frontier = new List <HexagonCell>(); HexagonCell curr = hexGrid.Get_Cell_Index(new HexagonCoord(coord.x, coord.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++) { frontier[j].Create_Rain(); } GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().lightningSound.Play(); GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().rainSound.Play(); return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, size)); }
public override HazardInfo CreateHazardAt(HexagonCell cell, Grid hexGrid) { HexagonCoord coord = cell.coords; int size = Random.Range(2, 3); // 0 = 1, 1 = 3, 2 = 5 List <HexagonCell> frontier = new List <HexagonCell>(); //HexagonCell curr = hexGrid.Get_Cell_Index(new HexagonCoord(rand.x, rand.z)); for (int i = 0; i < hexGrid.cells.Length; i++) { int distance = cell.coords.FindDistanceTo(hexGrid.cells[i].coords); if (distance <= size) { frontier.Add(hexGrid.cells[i]); } } for (int j = 0; j < frontier.Count; j++) { frontier[j].Create_Rain(); } cell.Create_Weather_Vane(); GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().lightningSound.Play(); GameObject.FindGameObjectWithTag("SoundManager").GetComponent <SoundManager>().rainSound.Play(); return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, size, true)); }
public int FindDistanceTo(HexagonCoord other) { return (((X_coord < other.X_coord ? other.X_coord - X_coord : X_coord - other.X_coord) + (Y_coord < other.Y_coord ? other.Y_coord - Y_coord : Y_coord - other.Y_coord) + (Z_coord < other.Z_coord ? other.Z_coord - Z_coord : Z_coord - other.Z_coord)) / 2); }
public virtual HazardInfo CreateHazard(int size, HexagonCoord coord, Grid hexGrid) { //HexagonCoord rand = hexGrid.cells[Random.Range(0, hexGrid.cells.Length)].coords; //int size = Random.Range(0, 3); // 0 = 1, 1 = 3, 2 = 5 Debug.Log("hazard at (" + coord.x + "," + coord.z + ") with size: " + size); return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, size)); }
public HexagonCell GetCell(Vector3 position) { position = transform.InverseTransformPoint(position); HexagonCoord coordinates = HexagonCoord.FromPosition(position); int index = coordinates.X_coord + coordinates.Z_coord * width + coordinates.Z_coord / 2; return(cells[index]); }
public void Order_Cursor(HexagonCoord _coord, int num_sprites_per_cell) { int _current_sorting_order = gameObject.GetComponent <SpriteRenderer>().sortingOrder; gameObject.GetComponent <SpriteRenderer>().sortingOrder = original_sorting_value + ((_coord.X_coord + _coord.Y_coord) * num_sprites_per_cell); //Debug.Log(original_sorting_value + // ((_coord.X_coord + _coord.Y_coord) * num_sprites_per_cell)); }
public virtual HazardInfo CreateHazardAt(HexagonCell cell, Grid hexGrid) { // code to spawn the particle system or whatever to show the effect //Debug.Log("shooting poison gas on map"); HexagonCoord coord = cell.coords; int size = Random.Range(0, 3); return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, size)); }
void TouchCell(Vector3 position) { position = transform.InverseTransformPoint(position); HexagonCoord coordinates = HexagonCoord.FromPosition(position); int index = coordinates.X_coord + coordinates.Z_coord * width + coordinates.Z_coord / 2; Debug.Log(index); HexagonCell cell = cells[index]; cell.color = touchedColor; hexMesh.Triangulate(cells); }
public override HazardInfo CreateHazardAt(HexagonCell cell, Grid hexGrid) { HexagonCoord coord = cell.coords; //int randRange = Random.Range(0, hexGrid.cells.Length); //HexagonCoord rand = hexGrid.cells[randRange].coords; int size = Random.Range(1, 3); // 0 = 1, 1 = 3, 2 = 5 Debug.Log("hazard at (" + coord.x + "," + coord.z + ") with size: " + size); cell.Create_Weather_Vane(); return(new HazardInfo(this, coord.x, coord.Y_coord, coord.z, timeOnBoard, size, true)); }
public IEnumerator HopToPlace(Grid hexGrid, HexagonCell unitCell, int index, int distance) { //All Movement Audio Goes Here if (Moving_Lines_List.Length > 0) { int Chosen_Voice_Line_Index = Random.Range(0, Moving_Lines_List.Length); Moving_Lines_List[Chosen_Voice_Line_Index].Play(); } string name = unitCell.unitOnTile.unit_name; Stack <HexagonCell> result = hexGrid.FindPath(unitCell, hexGrid.cells[index]); HexagonCoord current = unitCell.coords; while (result.Count > 0) { HexagonCell temp = result.Pop(); if (temp.coords.x > current.x || (temp.coords.x == current.x && temp.coords.z == current.z + 1)) //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; } } StartCoroutine(Moving()); yield return(new WaitForSeconds(0.3f)); transform.position = temp.transform.position; current = temp.coords; editor.re_sort_unit_position(this, hexGrid.GetCell(temp.transform.position)); yield return(new WaitForSeconds(0.3f)); } if (slowed) { slowing_counter -= 1; Debug.Log(name + " is slowed for " + slowing_counter + " more turns"); if (slowing_counter == 0) { current_mobility = mobility; slowed = false; Debug.Log(name + " is no longer slowed"); } } }
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); }
void CreateCell(int a, int b, int c) // should only be called once when initializing the map { Vector3 position; position.x = (a + b * 0.5f - b / 2) * (HexagonInfo.innerRadius * 2f); position.y = b * (HexagonInfo.outerRadius * 1.5f); position.z = 0f; int rand_tile = Random.Range(0, 3); HexagonCell cell = cells[c] = Instantiate <HexagonCell>(cellPrefabs[rand_tile]); cell.transform.SetParent(transform, false); cell.transform.localPosition = position; cell.coords = HexagonCoord.FromOffsetCoordinates(a, b); cell.spriteRenderer.color = defaultColor; if (a > 0) { cell.SetNeighbor(HexagonDirection.W, cells[c - 1]); } if (b > 0) { if ((b & 1) == 0) { cell.SetNeighbor(HexagonDirection.SE, cells[c - width]); if (a > 0) { cell.SetNeighbor(HexagonDirection.SW, cells[c - width - 1]); } } else { cell.SetNeighbor(HexagonDirection.SW, cells[c - width]); if (a < width - 1) { cell.SetNeighbor(HexagonDirection.SE, cells[c - width + 1]); } } } cell.tag = "Floor"; }
public int DistanceTo(HexagonCoord other) { return(x < other.x ? other.x - x : x - other.x); }
public Tile(int e, int ne) { this.coord = new HexagonCoord(e, ne); }
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; } }
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)); } }
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); }
public HexagonCell Get_Cell_Index(HexagonCoord coordinates) { int index = coordinates.X_coord + coordinates.Z_coord * width + coordinates.Z_coord / 2; return(cells[index]); }
public int Get_Index(HexagonCoord coordinates) { int index = coordinates.X_coord + coordinates.Z_coord * width + coordinates.Z_coord / 2; return(index); }
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; } }
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; } }