-
Notifications
You must be signed in to change notification settings - Fork 0
/
Npc.cs
143 lines (128 loc) · 4.74 KB
/
Npc.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace KnightsAndWarlocks
{
enum NpcClasses { Warrior, Rogue, Mage }
enum NpcRaces { Skeleton, Goblin, Troll }
class Npc
{
public NpcRaces NpcRace { get; private set; }
public NpcClasses NpcClass { get; private set; }
public short Health { get; set; } = 100;
private const double _accuracyN = 0.80;
private double _turnChoice;
private const double _dropChance = 0.60;
//Constructor calls 2 functions to create an enemy.
public Npc()
{
NpcEnemyRace();
NpcEnemyClass();
}
public void DropItem(Player player)
{
if (GameFunctions.RndNextDouble() > _dropChance)
{
switch (GameFunctions.RndNext(1, 3))
{
case 1:
GameFunctions.AddToEnemyLog($"The {NpcRace} dropped a {player.HealItemsType}!");
player.HealItems++;
break;
case 2:
GameFunctions.AddToEnemyLog($"The {NpcRace} dropped a potion labeled 'Special Attack!'");
player.SpecialMoves++;
break;
}
}
}
//Creates random enemy race.
public void NpcEnemyRace()
{
short rdmNpcRace = GameFunctions.RndNext(0, 3);
switch (rdmNpcRace)
{
case 0:
NpcRace = NpcRaces.Skeleton;
break;
case 1:
NpcRace = NpcRaces.Goblin;
break;
case 2:
NpcRace = NpcRaces.Troll;
break;
}
}
//Creates random enemy class.
public void NpcEnemyClass()
{
short rdmNpcClass = GameFunctions.RndNext(0, 3);
switch (rdmNpcClass)
{
case 0:
NpcClass = NpcClasses.Warrior;
break;
case 1:
NpcClass = NpcClasses.Rogue;
break;
case 2:
NpcClass = NpcClasses.Mage;
break;
}
}
public bool HitOrHeal()
{
//Npc intelligence => heal chance thresholds
if (Health > 95) _turnChoice = 1.00;
else if (Health > 50) _turnChoice = 0.85;
else _turnChoice = 0.70;
return GameFunctions.RndNextDouble() < _turnChoice;
}
public bool IsAccuracySuccessful() => GameFunctions.RndNextDouble() < _accuracyN;
public void NpcChoice(Player name)
{
if (HitOrHeal())
{
if (IsAccuracySuccessful())
{
short dmg = GameFunctions.RndNext(11, 16);
name.Health -= dmg;
//clamp health to not go below 0
if (name.Health < 0) name.Health = 0;
else //Gives each foe a unique roleplay element.
{
if (NpcClass == NpcClasses.Warrior)
{
GameFunctions.AddToEnemyLog($"The {NpcRace} {NpcClass} slashed their sword at you for {dmg} damage!");
}
else if (NpcClass == NpcClasses.Rogue)
{
GameFunctions.AddToEnemyLog($"The {NpcRace} {NpcClass} threw a knife at you for {dmg} damage!");
}
else if (NpcClass == NpcClasses.Mage)
{
GameFunctions.AddToEnemyLog($"The {NpcRace} {NpcClass} hurled a fireball at you for {dmg} damage!");
}
}
}
else
{
GameFunctions.AddToEnemyLog($"{NpcRace} {NpcClass} missed!");
}
}
else
{
short heal = GameFunctions.RndNext(12, 16);
short newHealth = (short)(Health + heal);
//Clamp health to not go above 100
if (newHealth > 100) newHealth = 100;
//Swap placeholder health(newHealth) back into health
Health = newHealth;
GameFunctions.AddToEnemyLog($"{NpcRace} {NpcClass} healed by {heal}.");
}
}
}
}