public bool NextAction(out Equipment.Ability ac) { ac = equipment.actions[action]; cooldown = equipment.actions[action].cooldown + 1; action = (action + 1) % equipment.actions.Length; if (ac.action != Equipment.Action.none) { durability--; } return(durability > 0); }
public void SetCards(CharacterWrapper character, Action <EquipmentWrapper, Equipment.Ability> onSelect) { bool hasAction = false; List <EquipmentWrapper> list = character.equipment; bool hasInventory = character.inventory.Count > 0; while (transform.childCount < list.Count + 2) { Instantiate(transform.GetChild(0).gameObject, transform); } for (int i = 0; i < list.Count; i++) { EquipmentWrapper e = list[i]; Transform t = transform.GetChild(i); t.GetChild(0).GetComponent <Image>().sprite = e.equipment.icon; t.GetChild(1).GetComponent <Text>().text = e.ActionString(); Button b = t.GetComponent <Button>(); b.onClick.RemoveAllListeners(); b.onClick.AddListener(() => { onSelect(e, null); }); b.interactable = e.cooldown <= 0; hasAction = hasAction | b.interactable; t.gameObject.SetActive(true); } for (int i = list.Count; i < transform.childCount; i++) { transform.GetChild(i).gameObject.SetActive(false); } if (hasInventory) { Transform t = transform.GetChild(list.Count); t.GetChild(0).GetComponent <Image>().sprite = changeIcon; Button b = t.GetComponent <Button>(); b.onClick.RemoveAllListeners(); t.GetChild(1).GetComponent <Text>().text = "Swap Equipment"; b.onClick.AddListener(() => { onSelect(null, null); }); b.interactable = true; t.gameObject.SetActive(true); } if (!hasAction) { Transform t = transform.GetChild(list.Count + 1); t.GetChild(0).GetComponent <Image>().sprite = changeIcon; Button b = t.GetComponent <Button>(); b.onClick.RemoveAllListeners(); Equipment.Ability playerAction = new Equipment.Ability(); playerAction.action = Equipment.Action.none; playerAction.name = "Wait"; t.GetChild(1).GetComponent <Text>().text = "Wait"; b.onClick.AddListener(() => { onSelect(null, playerAction); }); b.interactable = true; t.gameObject.SetActive(true); } }
public void ThrowEquipment(EquipmentWrapper ew) { if (!battleUI.activeSelf) { return; } Inventory.Close(); Equipment.Ability ac = new Equipment.Ability(); ac.action = Equipment.Action.damage; ac.amount = ew.equipment.type == Equipment.Type.weapon ? 6 : 4; ac.name = "Throw " + ew.equipment.name; SetPlayerAction(ew, ac); reward += 20; }
void SetPlayerAction(EquipmentWrapper e, Equipment.Ability action) { if (e == null && action == null) { Inventory.Show(player); } else { playerCards.Clear(); Equipment.Ability playerAction; bool remove = false; if (action != null) { playerAction = action; } else { remove = !e.NextAction(out playerAction); } Equipment.Ability enemyAction; var ee = enemy.GetAbility(out enemyAction); FlashText.Flash(enemyAction.name + "\n\n\n\n" + playerAction.name, Color.white); HandleAction(player, enemy, ref playerAction, ref enemyAction, playerAnimation, enemyAnimation); HandleAction(enemy, player, ref enemyAction, ref playerAction, enemyAnimation, playerAnimation); if (remove) { FlashText.Flash("Your " + e.equipment.name.ToLower() + " broke!", Color.red); player.RemoveEquipment(e); } if (ee != null) { enemy.RemoveEquipment(ee); } if (player.health <= 0 && enemy.health >= player.health) { StartCoroutine(BattleOver(player)); return; } else if (enemy.health <= 0 && player.health > enemy.health) { StartCoroutine(BattleOver(enemy)); return; } reward += 3; StartCoroutine(DelayedNextTurn()); } }
void HandleAction(CharacterWrapper p1, CharacterWrapper p2, ref Equipment.Ability a1, ref Equipment.Ability a2, CombatAnimation ca1 = null, CombatAnimation ca2 = null) { switch (a1.action) { case Equipment.Action.none: break; case Equipment.Action.damage: if (ca1 != null) { ca1.PlayAttack(); } if (a2.action != Equipment.Action.block) { DoDamage(p2, a1.amount); if (ca2 != null) { ca2.PlayDamage(); } } else if (p2 == player) { reward += 15; } break; case Equipment.Action.damageStrength: if (ca1 != null) { ca1.PlayAttack(); } if (a2.action != Equipment.Action.block) { float damage = p1.strength * a1.amount; DoDamage(p2, damage); if (ca2 != null) { ca2.PlayDamage(); } } else if (p2 == player) { reward += 15; } break; case Equipment.Action.damageAgility: if (ca1 != null) { ca1.PlayAttack(); } if (a2.action != Equipment.Action.block) { float damage = p1.agility * a1.amount; DoDamage(p2, damage); if (ca2 != null) { ca2.PlayDamage(); } } else if (p2 == player) { reward += 15; } break; case Equipment.Action.block: if (ca1 != null) { ca1.PlayBlock(); } break; case Equipment.Action.cheer: if (ca1 != null) { ca1.PlayUtility(); } if (p1 == player) { reward += 30; } break; default: break; } }
public EquipmentWrapper GetAbility(out Equipment.Ability ability) { float sum = character.aggressive + character.defensive + character.utility; if (sum < 0.01f) { ability = new Equipment.Ability(); ability.name = "Wait"; ability.action = Equipment.Action.none; return(null); } float rnd = Random.value * sum; EquipmentWrapper e = null; if (rnd < character.aggressive) { for (int i = 0; i < equipment.Count; i++) { if ((equipment[i].equipment.type == Equipment.Type.aggressive || equipment[i].equipment.type == Equipment.Type.weapon) && equipment[i].cooldown <= 0) { e = equipment[i]; int r = Random.Range(0, equipment.Count); equipment[i] = equipment[r]; equipment[r] = e; break; } } if (e == null) { float tmp = character.aggressive; character.aggressive = 0f; e = GetAbility(out ability); character.aggressive = tmp; return(e); } } else { rnd -= character.aggressive; if (rnd < character.defensive) { for (int i = 0; i < equipment.Count; i++) { if ((equipment[i].equipment.type == Equipment.Type.armor || equipment[i].equipment.type == Equipment.Type.shield) && equipment[i].cooldown <= 0) { e = equipment[i]; int r = Random.Range(0, equipment.Count); equipment[i] = equipment[r]; equipment[r] = e; break; } } if (e == null) { float tmp = character.defensive; character.defensive = 0f; e = GetAbility(out ability); character.defensive = tmp; return(e); } } else { for (int i = 0; i < equipment.Count; i++) { if (equipment[i].equipment.type == Equipment.Type.utility && equipment[i].cooldown <= 0) { e = equipment[i]; int r = Random.Range(0, equipment.Count); equipment[i] = equipment[r]; equipment[r] = e; break; } } if (e == null) { float tmp = character.utility; character.utility = 0f; e = GetAbility(out ability); character.utility = tmp; return(e); } } } if (!e.NextAction(out ability)) { return(e); } return(null); }