public async Task ShowTurnResult(CombatUtil.CombatAction playerAction, CombatUtil.CombatAction enemyAction) { _combatTurnResult.Visible = true; await _combatTurnResult.ShowTurnCompare(playerAction, enemyAction); _combatTurnResult.ShowWinResult(playerAction, enemyAction); }
protected override float GetEffectChance(CombatUtil.CombatAction action) { var weapon = PlayerWeaponRecord; return(action switch { CombatUtil.CombatAction.Quick => weapon.quickEffectChance, CombatUtil.CombatAction.Counter => weapon.counterEffectChance, CombatUtil.CombatAction.Heavy => weapon.heavyEffectChance, _ => 0f });
public void Attack(CombatChar target, CombatUtil.CombatAction action, int damage, BaseEntity instance, BaseEntity targetInstance) { if (CharacterInstance.statusEffects.ContainsKey("Weak")) { damage /= 2; } damage = Mathf.Max(damage, 1); var damageType = GetDamageType(action); target.TakeDamage(damage, damageType); var statusEffect = GetStatusEffect(action); if (statusEffect == "none") { return; } var statusEffectChance = GetEffectChance(action); var enemy = target.CharacterInstance as BaseEnemy; if (enemy?.Stat.Resistance == "Fire" && statusEffect == "OnFire") { return; } if (Utility.Random.NextDouble() < statusEffectChance) { target.CharacterInstance.AddStatusEffect(statusEffect); if (AudioSystem.SFXCollection.TryGetValue($"BattleStatus{statusEffect}", out var sfx)) { AudioSystem.PlaySFX(sfx); } else { GD.PrintErr($"No SFX found for {statusEffect} status"); } if (enemy != null) { GD.Print($"Applied {statusEffect} to {enemy.enemyName}"); } } }
public override int GetBaseDamage(CombatUtil.CombatAction action) { var weapon = PlayerWeaponRecord; var damage = action switch { CombatUtil.CombatAction.Quick => weapon.quickDamage, CombatUtil.CombatAction.Counter => weapon.counterDamage, CombatUtil.CombatAction.Heavy => weapon.heavyDamage, _ => throw new ArgumentOutOfRangeException() }; damage *= 1 + CombatUtil.MULTIPLIER_PER_COMBO * hitCombo; return(damage / 2); }
private async Task Tie(CombatUtil.CombatAction action) { var enemyDamage = _enemyCombat.GetBaseDamage(action); var playerDamage = _playerCombat.GetBaseDamage(action); switch (action) { case CombatUtil.CombatAction.Quick: await _combatMenu.AnimatePlayerAttack(_playerCombat, action); _playerCombat.Attack(_enemyCombat, action, playerDamage, _playerInstance, _enemyInstance); _enemyCombat.Attack(_playerCombat, action, enemyDamage, _enemyInstance, _playerInstance); await _combatMenu.AnimatePlayerHurt(enemyDamage); break; case CombatUtil.CombatAction.Counter: await ToSignal(GetTree().CreateTimer(1.5f), "timeout"); break; case CombatUtil.CombatAction.Heavy: await _combatMenu.AnimatePlayerAttack(_playerCombat, action); playerDamage /= 2; _playerCombat.Attack(_enemyCombat, action, playerDamage, _playerInstance, _enemyInstance); enemyDamage /= 2; _enemyCombat.Attack(_playerCombat, action, enemyDamage, _enemyInstance, _playerInstance); await _combatMenu.AnimatePlayerHurt(enemyDamage); break; default: _combatMenu.HideTurnResult(); await _combatMenu.ShowCombatLabel("ERROR. Unknown Action on Tie()", 2); throw new ArgumentOutOfRangeException(nameof(action), action, null); } }
public async Task AnimatePlayerAttack(PlayerCombat playerCombat, CombatUtil.CombatAction action) { if (action == CombatUtil.CombatAction.Counter) { await _attackEffect.Play(_effectAnimations.GetAnimation("counter"), CombatUtil.GetActionColor(CombatUtil.CombatAction.Heavy)); } var damageType = playerCombat.GetDamageType(action); if (damageType == "none") { return; } var effectAnimation = _effectAnimations.GetAnimation(damageType); await _attackEffect.Play(effectAnimation, CombatUtil.GetActionColor(action)); }
public async void ShowWinResult(CombatUtil.CombatAction playerAction, CombatUtil.CombatAction enemyAction, float duration = 0) { if (playerAction == CombatUtil.CombatAction.Flee || enemyAction == CombatUtil.CombatAction.Flee) { await ToSignal(GetTree(), "idle_frame"); return; } var win = CombatUtil.ActionCompare(playerAction, enemyAction); switch (win) { case CombatUtil.TurnOutcome.Tie: SetWinLabel("TIE", playerAction); break; case CombatUtil.TurnOutcome.PlayerWin: SetWinLabel("Player Win", playerAction); break; case CombatUtil.TurnOutcome.EnemyWin: SetWinLabel("Enemy Win", enemyAction); break; default: SetWinLabel("Error", CombatUtil.CombatAction.Invalid); throw new ArgumentOutOfRangeException(); } winContainer.Visible = true; if (duration > 0) { await ToSignal(GetTree().CreateTimer(duration), "timeout"); winContainer.Visible = false; } }
private async Task <bool> PlayerFlee(CombatUtil.CombatAction enemyAction) { var rule = new CombatUtil.FleeRule(enemyAction); var enemyDamage = _enemyCombat.GetBaseDamage(enemyAction); var outcome = rule.Roll(); switch (outcome) { case CombatUtil.FleeRule.FleeOutcome.Success: await _combatMenu.ShowCombatLabel("Got away safely", 2); return(true); case CombatUtil.FleeRule.FleeOutcome.SuccessDmg: _enemyCombat.Attack(_playerCombat, enemyAction, (int)(enemyDamage * rule.damageModifier), _enemyInstance, _playerInstance); await _combatMenu.AnimatePlayerHurt(enemyDamage); await _combatMenu.ShowCombatLabel("Got away not so safely", 2); return(true); case CombatUtil.FleeRule.FleeOutcome.Fail: await _combatMenu.ShowCombatLabel("Failed to flee", 2); _enemyCombat.Attack(_playerCombat, enemyAction, (int)(enemyDamage * rule.damageModifier), _enemyInstance, _playerInstance); await _combatMenu.AnimatePlayerHurt(enemyDamage); return(false); default: throw new ArgumentOutOfRangeException(); } }
private async Task PlayerWin(CombatUtil.CombatAction playerAction) { var playerDamage = _playerCombat.GetBaseDamage(playerAction); _playerCombat.hitCombo += 1; switch (playerAction) { case CombatUtil.CombatAction.Quick: await _combatMenu.AnimatePlayerAttack(_playerCombat, playerAction); _playerCombat.Attack(_enemyCombat, playerAction, playerDamage, _playerInstance, _enemyInstance); break; case CombatUtil.CombatAction.Counter: await _combatMenu.AnimatePlayerAttack(_playerCombat, playerAction); _playerCombat.Attack(_enemyCombat, playerAction, playerDamage, _playerInstance, _enemyInstance); break; case CombatUtil.CombatAction.Heavy: await _combatMenu.AnimatePlayerAttack(_playerCombat, playerAction); _playerCombat.Attack(_enemyCombat, playerAction, playerDamage, _playerInstance, _enemyInstance); break; default: _combatMenu.HideTurnResult(); await _combatMenu.ShowCombatLabel( "ERROR. Unknown Action on PlayerWin()", 2); throw new ArgumentOutOfRangeException(nameof(playerAction), playerAction, null); } }
private async Task EnemyWin(CombatUtil.CombatAction enemyAction) { var enemyDamage = _enemyCombat.GetBaseDamage(enemyAction); switch (enemyAction) { case CombatUtil.CombatAction.Quick: _enemyCombat.Attack(_playerCombat, enemyAction, enemyDamage, _enemyInstance, _playerInstance); await _combatMenu.AnimatePlayerHurt(enemyDamage); break; case CombatUtil.CombatAction.Counter: enemyDamage /= 2; _enemyCombat.Attack(_playerCombat, enemyAction, enemyDamage, _enemyInstance, _playerInstance); await _combatMenu.AnimatePlayerHurt(enemyDamage, true); break; case CombatUtil.CombatAction.Heavy: _enemyCombat.Attack(_playerCombat, enemyAction, enemyDamage, _enemyInstance, _playerInstance); await _combatMenu.AnimatePlayerHurt(enemyDamage); break; default: _combatMenu.HideTurnResult(); await _combatMenu.ShowCombatLabel( "ERROR. Unknown Action on EnemyWin()", 2); throw new ArgumentOutOfRangeException(nameof(enemyAction), enemyAction, null); } }
public abstract int GetBaseDamage(CombatUtil.CombatAction action);
public abstract string GetDamageType(CombatUtil.CombatAction action);
protected abstract string GetStatusEffect(CombatUtil.CombatAction action);
protected abstract float GetEffectChance(CombatUtil.CombatAction action);
private void SetWinLabel(string actor, CombatUtil.CombatAction action) { _winActorLabel.Text = actor; _winActionLabel.Text = CombatUtil.GetActionName(action); _winActionLabel.Modulate = CombatUtil.GetActionColor(action); }