33/*
44Made By: Patrick J. Rye
55Purpose: A header to hold all the functions related to battling, levelling up and player stats.
6- Current Revision: 2.3 .1
6+ Current Revision: 3.0 .1
77Change Log---------------------------------------------------------------------------------------------------------------------------------------------------
88Date Revision Changed By Changes
99------ --------- ------------ ---------------------------------------------------------------------------------------------------------------------
@@ -65,6 +65,16 @@ Date Revision Changed By Changes
65652015/03/06 2.3.1 Patrick Rye -Changed system("pause") to getchar();
6666 -Added more pauses.
6767=============================================================================================================================================================
68+ 2015/03/06 3.0 Patrick Rye -Added chance for stun.
69+ -Redid monster levelling.
70+ -Redid health calculation.
71+ -Redid damage calculation.
72+ -Added some variability to attack damage.
73+ =============================================================================================================================================================
74+ 2015/03/09 3.0.1 Patrick Rye -Changed some text to better reflect certain changes.
75+ -The less health something has the less damage it will do.
76+ -Nerffered attack damage a bit.
77+ =============================================================================================================================================================
6878*/
6979
7080/*
@@ -79,7 +89,7 @@ For Stat Arrays
7989/*********************************************************************************************************/
8090/*A quick note on the base stats, a stat cannot be lower than 6, as a modifier might reduce the value by 5 points.
8191 The base stat point should also add up to be 100. */
82- int MonsterBaseStats [5 ] = {25 , 25 , 10 , 25 , 15 }; //A base array for the monsters
92+ int MonsterBaseStats [5 ] = {20 , 20 , 20 , 20 , 20 }; //A base array for the monsters
8393const int ZombieBaseStats [5 ] = {25 ,25 ,10 ,25 ,15 };
8494const int SkeletonBaseStats [5 ] = {35 ,18 ,6 ,35 ,6 };
8595const int WitchBaseStats [5 ] = {15 ,15 ,20 ,20 ,30 };
@@ -101,13 +111,53 @@ int PlayerStats[5] = {5,5,5,5,5};
101111int intBattleLevel = 1 ;
102112bool blBattleDebugMode = false;
103113/*********************************************************************************************************/
114+ void SetBattleDebugMode (bool isDebug ) {blBattleDebugMode = isDebug ;}
115+ /*********************************************************************************************************/
116+
117+
118+
119+ bool StunCheck (int intAttackerLuck , int intDefenderLuck )
120+ {
121+ if (intDefenderLuck < intAttackerLuck ) {if (rand ()% 101 < (intAttackerLuck - intDefenderLuck ) / 3 ) {return true;}}
122+ return false;
123+ }
124+
125+ float DamageHealthPercent (int CurrentHealth , int MaximumHealth )
126+ {
127+ /*Function that returns a percentage value that will be multiplied by the damage.
128+ The value will vary with health so that the less health something has
129+ The less damage it will do.
130+ The max value it return is about 1.01 or something similar, the min value
131+ is about 0.64 */
132+
133+ float HealthPercent = CurrentHealth / MaximumHealth ;
134+ float TempValue = 0 ;
135+ TempValue -= 0.8981 * pow (HealthPercent , 3 );
136+ TempValue += 1.297 * pow (HealthPercent , 2 );
137+ TempValue -= 0.0358 * HealthPercent ;
138+ TempValue += 0.64 ;
139+ return TempValue ;
140+ }
141+
142+ string HitName ()
143+ {
144+ /*Outputs a string that represents an attack,
145+ for example rather than just "hit" over and over,
146+ you could get "stabbed" "hit"*/
147+ const string HitStringArray [5 ] = {"hit" ,"stabbed" ,"cut" ,"slashed" ,"damaged" };
148+ string TempString ;
149+ TempString = HitStringArray [rand () % 5 ];
150+ if (TempString != "" ) {return TempString ;}
151+ return "hit" ;
152+ }
104153
105154bool MonsterAttack (int MonsterDamage , double MonsterMuli , bool ishealing )
106155{
107156 //Holds stuff for when monster attacks.
108157 //Only returns true if player died.
109158 //Is in its own function so I can call it a couple of different places.
110159 cout <<endl ;
160+ MonsterDamage = floor (MonsterDamage * DamageHealthPercent (MonsterHealth [0 ],MonsterHealth [1 ])); //Reduce damage based on health.
111161 if (ishealing ) {floor (MonsterDamage /= 2 );} //if player is healing reduce damage.
112162 if (MonsterDamage != 0 )
113163 {
@@ -126,10 +176,11 @@ bool PlayerAttack(int PlayerDamage, double PlayerMuli)
126176 //Only returns true if monster died.
127177 //Is in its own function so I can call it a couple of different places.
128178 cout <<endl ;
179+ PlayerDamage = floor (PlayerDamage * DamageHealthPercent (PlayerHealth [0 ],PlayerHealth [1 ])); //Reduce damage based on health.
129180 if (PlayerDamage != 0 )
130181 {
131182 if (PlayerMuli > 1 ){cout <<"You got a crit on the " <<MonsterName <<"! " ;}
132- cout <<"You hit the " <<MonsterName <<" for " <<PlayerDamage <<"." ;
183+ cout <<"You " << HitName ()<< " the " <<MonsterName <<" for " <<PlayerDamage <<"." ;
133184 }
134185 else {cout <<"The " <<MonsterName <<" dodged your attack." ;}
135186 MonsterHealth [0 ] -= PlayerDamage ;
@@ -179,18 +230,33 @@ int CalculateHealth(int HealthLevel, int ConsStat)
179230{
180231 //A simple function for calculating health.
181232 //In its own function so future changes will be changed everywhere.
182- return floor ((23 * ((5.25 + 0.5625 * HealthLevel + 0.00375 * pow (HealthLevel ,2 ))+ (1 + 0.066 * HealthLevel )* (ConsStat /16 ))));
233+ double HealthTemp = 0 ;
234+ HealthTemp = (0.9722 * pow (HealthLevel , 2 ) )+ ( 0.4167 * HealthLevel ) + 48.611 ;
235+ HealthTemp += 23.979 * exp (0.01414 * ConsStat );
236+ return floor (HealthTemp );
183237}
184238
185239int CalculateDamage (int DamageLevel , int StrStat , int DefStat )
186240{
187- //A simple function for calculating damage
241+ //A simple function for calculating damage.
188242 //In its own function so future changes will be changed everywhere.
189- return floor (((((2 * (DamageLevel /5 ) + 2 ) * ((10 * DamageLevel )/DefStat ))* (StrStat ))+ 5 ));
243+ int DamageTemp = 0 ;
244+ int intMinDamage = floor ((MonsterHealth [1 ]+ PlayerHealth [1 ])/20 ) + 1 ;
245+ StrStat += rand () % DamageLevel ;
246+ DefStat += rand () % DamageLevel ;
247+ if (DefStat > StrStat ) {return intMinDamage ;}
248+ else if (DefStat == StrStat ) {return intMinDamage + rand () % (DamageLevel * 2 );}
249+ else
250+ {
251+ DamageTemp = floor ((StrStat - DefStat )* 1.75 );
252+ DamageTemp += intMinDamage ;
253+ DamageTemp += rand () % (DamageLevel * 2 );
254+ return DamageTemp ;
255+ }
256+
257+ return intMinDamage ;
190258}
191259
192- void SetBattleDebugMode (bool isDebug ) {blBattleDebugMode = isDebug ;}
193-
194260void RandomMonster ()
195261{
196262 //Generates a number 0 - 4 representing the location of a monster in the monster name array
@@ -301,6 +367,31 @@ void RandomMonsterModifier()
301367//End of random monster modifier.
302368}
303369
370+ void LevelUpMonster ()
371+ {
372+ //Function to level up the monster.
373+ int StatUpgradeChance [5 ] = {0 ,0 ,0 ,0 ,0 };
374+ int intStatPoints = (intBattleLevel - 1 ) * 5 ; //How many stat points the monster gets.
375+ int intRandomStatChoice = 0 ;
376+
377+ StatUpgradeChance [0 ] = MonsterBaseStats [0 ];
378+ for (int i = 0 ; i < 5 ; i ++ ) {MonsterStats [i ] = MonsterBaseStats [i ];}
379+ for (int i = 1 ; i < 5 ; i ++ ) {StatUpgradeChance [i ] = StatUpgradeChance [i - 1 ] + MonsterBaseStats [i ];}
380+ for (int i = 0 ; i < intStatPoints ; i ++ ) //Random place points in the different stats.
381+ {
382+ intRandomStatChoice = rand () % 101 ;
383+ if (intRandomStatChoice < StatUpgradeChance [0 ]) {MonsterStats [0 ] += 1 ;}
384+ else if (intRandomStatChoice < StatUpgradeChance [1 ]) {MonsterStats [1 ] += 1 ;}
385+ else if (intRandomStatChoice < StatUpgradeChance [2 ]) {MonsterStats [2 ] += 1 ;}
386+ else if (intRandomStatChoice < StatUpgradeChance [3 ]) {MonsterStats [3 ] += 1 ;}
387+ else {MonsterStats [4 ] += 1 ;}
388+ }
389+ if (blBattleDebugMode ) {for (int i = 0 ; i < 5 ; i ++ ) {cout <<endl <<MonsterStats [i ];}}
390+ //Recalculate healths and re-heal them
391+ MonsterHealth [1 ] = floor (CalculateHealth (intBattleLevel ,MonsterStats [1 ])/2 );
392+ MonsterHealth [0 ] = MonsterHealth [1 ];
393+ }
394+
304395void LevelUpFunction ()
305396{
306397 //Holds function for levelling up.
@@ -387,13 +478,8 @@ char BattleScene()
387478 double douPlayerHealAmount ;
388479 char chrPlayerBattleChoice ;
389480
390- //Recalculate all of the stats needed.
391- //Update monster stats to new level.
392- for (int i = 0 ; i < 5 ; i ++ ) {MonsterStats [i ] = floor (((intBattleLevel - 1 )* 4 + MonsterBaseStats [i ]));/*cout<<endl<<MonsterStats[i];*/ /*Debugging line*/ }
481+ LevelUpMonster ();
393482
394- //Recalculate healths and re-heal them
395- MonsterHealth [1 ] = floor (CalculateHealth (intBattleLevel ,MonsterStats [1 ])/3 );
396- MonsterHealth [0 ] = MonsterHealth [1 ];
397483 //Recalculate amount player heals for.
398484 douPlayerHealAmount = floor (PlayerHealth [1 ]/10 );
399485 BattleGoto :
@@ -447,16 +533,25 @@ char BattleScene()
447533 //Monster attacks first.
448534 blPlayerDead = MonsterAttack (intMonsterDamage ,douMonsterDamageMuli ,false);
449535 if (blPlayerDead ) {return 'F' ;}
450- blMonsterDead = PlayerAttack (intPlayerDamage ,douPlayerDamageMuli );
451- if (blMonsterDead ) {return 'T' ;}
536+ if (!StunCheck (MonsterStats [4 ],PlayerStats [4 ]))
537+ {
538+ blMonsterDead = PlayerAttack (intPlayerDamage ,douPlayerDamageMuli );
539+ if (blMonsterDead ) {return 'T' ;}
540+ }
541+ else {cout <<endl <<"You were stunned and unable to attack." ;}
452542 }
453543 else
454544 {
455545 //Player attacks first.
456546 blMonsterDead = PlayerAttack (intPlayerDamage ,douPlayerDamageMuli );
457547 if (blMonsterDead ) {return 'T' ;}
458- blPlayerDead = MonsterAttack (intMonsterDamage ,douMonsterDamageMuli ,false);
459- if (blPlayerDead ) {return 'F' ;}
548+ if (!StunCheck (PlayerStats [4 ],MonsterStats [4 ]))
549+ {
550+ blPlayerDead = MonsterAttack (intMonsterDamage ,douMonsterDamageMuli ,false);
551+ if (blPlayerDead ) {return 'F' ;}
552+ }
553+ else {cout <<endl <<"The " <<MonsterName <<" was stunned by your hit and unable to attack." ;}
554+
460555 }
461556 cout <<endl ;
462557 getchar ();
@@ -471,8 +566,12 @@ char BattleScene()
471566 blPlayerDead = MonsterAttack (intMonsterDamage ,douMonsterDamageMuli ,true);
472567 if (blPlayerDead ) {return 'F' ;}
473568
474- if (PlayerHealth [0 ]+ douPlayerHealAmount > PlayerHealth [1 ]) {PlayerHealth [0 ]= PlayerHealth [1 ];}
475- else {PlayerHealth [0 ] += douPlayerHealAmount ;}
569+ if (!StunCheck (MonsterStats [4 ],PlayerStats [4 ]))
570+ {
571+ if (PlayerHealth [0 ]+ douPlayerHealAmount > PlayerHealth [1 ]) {PlayerHealth [0 ]= PlayerHealth [1 ];}
572+ else {PlayerHealth [0 ] += douPlayerHealAmount ;}
573+ }
574+ else {cout <<endl <<"You were stunned and unable to heal." ;}
476575 }
477576 else
478577 {
@@ -566,7 +665,7 @@ char PlayerInitialize()
566665 cout <<"In this game there are five stats that effect different elements of the game." ;
567666 cout <<endl <<"Strength (STR) - Effects how much damage you do when you attack." <<endl ;
568667 cout <<"Constitution (CONS) - Effects how much health you have." <<endl ;
569- cout <<"Dexterity (DEX) - Effects if your chance to dodge." <<endl ;
668+ cout <<"Dexterity (DEX) - Effects if your chance to dodge, and if you attack first ." <<endl ;
570669 cout <<"Defence (DEF) - Effects how much damage you take." <<endl ;
571670 cout <<"Luck (LUK) - The random chance things will go your way, with dodges, crits, and rare modifiers that appear on monsters." <<endl ;
572671 int intSkillPointsLeft = 100 ;
0 commit comments