-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttackAction.cs
101 lines (87 loc) · 3.05 KB
/
AttackAction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace FinalProject
{
internal class AttackAction : CombatAction
{
private int _modifier { get; }
private StatusEffect _effect { get; }
public AttackAction(string name, int cooldown, int modifier) : base(name, cooldown)
{
_modifier = modifier;
}
public AttackAction(string name, int cooldown, int modifier, StatusEffect effect) : base(name, cooldown)
{
_modifier = modifier;
_effect = effect;
}
public void PerformAction(Combatant user, Combatant target)
{
WriteLine($"{user.Name} attacked {target.Name} with {Name}.");
Random random = new Random();
int critBonus = 0;
int crits = random.Next(0, 100);
int hitChance = 100 + (user.Level - target.Level) + (user.Dexterity - target.Agility);
int hit = random.Next(0, 100);
if (hit < 5)
{
hit = 5;
}
if (crits <= user.Critical)
{
critBonus = (int)Math.Round((decimal)(user.AttackPower * 7 / 10));
}
if (hit <= hitChance)
{
decimal damage = user.AttackPower;
damage += critBonus;
damage *= _modifier / 100;
damage -= target.Defence;
if (damage > 0)
{
WriteLine($"{user.Name} dealt {(int)damage} damage to {target.Name}.");
target.CurrentHealth -= (int)damage;
}
else
{
WriteLine($"{user.Name} dealt no damage to {target.Name}");
}
if (_effect != null)
{
if (StatusEffectData.Debuffs.ContainsKey(_effect.Name) && (random.Next(0, 10) == 1))
{
target.Effects.Add(_effect);
_effect.Effect(target);
}
else if (StatusEffectData.Buffs.ContainsKey(_effect.Name))
{
user.Effects.Add(_effect);
_effect.Effect(user);
}
}
}
else
{
WriteLine($"{target.Name} dodged.");
}
base.PerformAction(user);
}
public override string GetSkillInfo()
{
StringBuilder builder = new StringBuilder();
builder.AppendLine(Name);
builder.AppendLine("Type: Attack");
builder.AppendLine($"Damage modifier: {_modifier}%");
if (_effect != null)
{
builder.AppendLine($"Additional effect: {_effect.Name}");
}
builder.AppendLine($"Cooldown: {Cooldown}");
return builder.ToString();
}
}
}