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: 3.0
6+ Current Revision: 3.0.1
77Change Log---------------------------------------------------------------------------------------------------------------------------------------------------
88Date Revision Changed By Changes
99------ --------- ------------ ---------------------------------------------------------------------------------------------------------------------
@@ -70,7 +70,11 @@ Date Revision Changed By Changes
7070 -Redid health calculation.
7171 -Redid damage calculation.
7272 -Added some variability to attack damage.
73- =============================================================================================================================================================
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+ =============================================================================================================================================================
7478*/
7579
7680/*
@@ -110,18 +114,50 @@ bool blBattleDebugMode = false;
110114void SetBattleDebugMode (bool isDebug ) {blBattleDebugMode = isDebug ;}
111115/*********************************************************************************************************/
112116
117+
118+
113119bool StunCheck (int intAttackerLuck , int intDefenderLuck )
114120{
115121 if (intDefenderLuck < intAttackerLuck ) {if (rand ()% 101 < (intAttackerLuck - intDefenderLuck ) / 3 ) {return true;}}
116122 return false;
117123}
118124
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+ }
153+
119154bool MonsterAttack (int MonsterDamage , double MonsterMuli , bool ishealing )
120155{
121156 //Holds stuff for when monster attacks.
122157 //Only returns true if player died.
123158 //Is in its own function so I can call it a couple of different places.
124159 cout <<endl ;
160+ MonsterDamage = floor (MonsterDamage * DamageHealthPercent (MonsterHealth [0 ],MonsterHealth [1 ])); //Reduce damage based on health.
125161 if (ishealing ) {floor (MonsterDamage /= 2 );} //if player is healing reduce damage.
126162 if (MonsterDamage != 0 )
127163 {
@@ -140,10 +176,11 @@ bool PlayerAttack(int PlayerDamage, double PlayerMuli)
140176 //Only returns true if monster died.
141177 //Is in its own function so I can call it a couple of different places.
142178 cout <<endl ;
179+ PlayerDamage = floor (PlayerDamage * DamageHealthPercent (PlayerHealth [0 ],PlayerHealth [1 ])); //Reduce damage based on health.
143180 if (PlayerDamage != 0 )
144181 {
145182 if (PlayerMuli > 1 ){cout <<"You got a crit on the " <<MonsterName <<"! " ;}
146- cout <<"You hit the " <<MonsterName <<" for " <<PlayerDamage <<"." ;
183+ cout <<"You " << HitName ()<< " the " <<MonsterName <<" for " <<PlayerDamage <<"." ;
147184 }
148185 else {cout <<"The " <<MonsterName <<" dodged your attack." ;}
149186 MonsterHealth [0 ] -= PlayerDamage ;
@@ -204,7 +241,7 @@ int CalculateDamage(int DamageLevel, int StrStat, int DefStat)
204241 //A simple function for calculating damage.
205242 //In its own function so future changes will be changed everywhere.
206243 int DamageTemp = 0 ;
207- int intMinDamage = floor ((MonsterHealth [1 ]+ 5 + PlayerHealth [1 ])/20 ) + 1 ;
244+ int intMinDamage = floor ((MonsterHealth [1 ]+ PlayerHealth [1 ])/20 ) + 1 ;
208245 StrStat += rand () % DamageLevel ;
209246 DefStat += rand () % DamageLevel ;
210247 if (DefStat > StrStat ) {return intMinDamage ;}
@@ -628,7 +665,7 @@ char PlayerInitialize()
628665 cout <<"In this game there are five stats that effect different elements of the game." ;
629666 cout <<endl <<"Strength (STR) - Effects how much damage you do when you attack." <<endl ;
630667 cout <<"Constitution (CONS) - Effects how much health you have." <<endl ;
631- 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 ;
632669 cout <<"Defence (DEF) - Effects how much damage you take." <<endl ;
633670 cout <<"Luck (LUK) - The random chance things will go your way, with dodges, crits, and rare modifiers that appear on monsters." <<endl ;
634671 int intSkillPointsLeft = 100 ;
0 commit comments