public static void Battle(Unit attacker, Unit recipient) { TurnScheduler turnScheduler = GameAssets.MyInstance.turnScheduler; bool hit = new Random().Next(1, 100) <= attacker.stats[StatString.HIT_RATE].Value; bool crit = new Random().Next(1, 100) <= attacker.stats[StatString.CRIT_RATE].Value; if (!recipient.isDead()) { if (hit) { // must take into account whether the main attack is magic or physical int attackDamage = CalculateBaseDamage(attacker, recipient); attackDamage = crit ? attackDamage * CritMultiplier : attackDamage; recipient.TakeDamage(attackDamage); attacker.UseWeapon(); DamagePopUp.Create(recipient.transform.position, string.Format("- {0} HP", (int)attackDamage), PopupType.DAMAGE, crit); } else { DamagePopUp.Create(recipient.transform.position, "MISS!", PopupType.DAMAGE); } } bool killed = false; if (recipient.isDead()) { turnScheduler.StartCoroutine(turnScheduler.RemoveUnit(recipient)); killed = true; } else { recipient.UpdateUI(); } // add exp if (hit) { int exp = Level.CalculateExp(recipient.level, attacker.level, killed); attacker.level.AddExp(exp); } attacker.UpdateUI(); }
//初始化动作 void InitAction() { actionDic = new Dictionary <PlayerAction, Action>(); actionDic.Add(PlayerAction.Attack, () => { player.UseWeapon(); }); actionDic.Add(PlayerAction.Roll, () => { if (input.Axis.x != 0) { AbilManager.GetAbil <Abil_Target>("Roll").Cast(player, player.pos + Vector2.right * input.Axis.x); } else { int dir = Camera.main.ScreenToWorldPoint(Input.mousePosition).x > player.transform.position.x ? 1 : -1; AbilManager.GetAbil <Abil_Target>("Roll").Cast(player, player.pos + Vector2.right * dir); } }); }