generated from sigonasr2/CPlusPlusProjectTemplate
Implement defend command and refactor damage calculation formula to be in its own separate function
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
6fbcc64f44
commit
e96e5248e8
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
#include "battlemoves.h"
|
|
@ -1,8 +0,0 @@
|
|||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <array>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef BATTLEMOVES_H
|
|
||||||
#define BATTLEMOVES_H
|
|
||||||
#endif
|
|
62
main.cpp
62
main.cpp
@ -273,6 +273,7 @@ enum class BattleMoveName{
|
|||||||
TESTMOVE2,
|
TESTMOVE2,
|
||||||
TESTMOVE3,
|
TESTMOVE3,
|
||||||
BASH,
|
BASH,
|
||||||
|
DEFEND,
|
||||||
HAILSTORM_A,
|
HAILSTORM_A,
|
||||||
HAILSTORM_B,
|
HAILSTORM_B,
|
||||||
HAILSTORM_G,
|
HAILSTORM_G,
|
||||||
@ -343,9 +344,7 @@ namespace Battle{
|
|||||||
Move(std::string name,std::string desc,int baseDmg,int randomDmg,int PPCost,int range,int channelTime,bool friendly,std::array<int,4>composition,Effect*eff=nullptr,bool pctDamage=false,std::vector<std::pair<Property,int>> properties={})
|
Move(std::string name,std::string desc,int baseDmg,int randomDmg,int PPCost,int range,int channelTime,bool friendly,std::array<int,4>composition,Effect*eff=nullptr,bool pctDamage=false,std::vector<std::pair<Property,int>> properties={})
|
||||||
:Move(name,desc,0,baseDmg,randomDmg,PPCost,range,channelTime,friendly,composition,eff,pctDamage,properties){};
|
:Move(name,desc,0,baseDmg,randomDmg,PPCost,range,channelTime,friendly,composition,eff,pctDamage,properties){};
|
||||||
Move(std::string name,std::string desc,int grade,int baseDmg,int randomDmg,int PPCost,int range,int channelTime,bool friendly,std::array<int,4>composition,Effect*eff=nullptr,bool pctDamage=false,std::vector<std::pair<Property,int>> properties={})
|
Move(std::string name,std::string desc,int grade,int baseDmg,int randomDmg,int PPCost,int range,int channelTime,bool friendly,std::array<int,4>composition,Effect*eff=nullptr,bool pctDamage=false,std::vector<std::pair<Property,int>> properties={})
|
||||||
:name(name),grade(grade),PPCost(PPCost),desc(desc),randomDmg(randomDmg),baseDmg(baseDmg),range(range),friendly(friendly),eff(eff),channelTime(channelTime),composition(composition),pctDamage(pctDamage),properties(properties){
|
:name(name),grade(grade),PPCost(PPCost),desc(desc),randomDmg(randomDmg),baseDmg(baseDmg),range(range),friendly(friendly),eff(eff),channelTime(channelTime),composition(composition),pctDamage(pctDamage),properties(properties){}
|
||||||
this->channelTime=180;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1041,7 +1040,10 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
//BATTLE_STATE=BattleState::ITEM_SELECT;
|
//BATTLE_STATE=BattleState::ITEM_SELECT;
|
||||||
}break;
|
}break;
|
||||||
case 3:{ //Defend selected.
|
case 3:{ //Defend selected.
|
||||||
DisplayMessageBox("Not implemented yet.");
|
//DisplayMessageBox("Not implemented yet.");
|
||||||
|
PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove=MOVELIST[BattleMoveName::DEFEND];
|
||||||
|
ConfirmPlayerTargetSelection();
|
||||||
|
BATTLE_STATE=BattleState::WAIT;
|
||||||
}break;
|
}break;
|
||||||
case 4:{ //Move selected.
|
case 4:{ //Move selected.
|
||||||
//DisplayMessageBox("Not implemented yet.");
|
//DisplayMessageBox("Not implemented yet.");
|
||||||
@ -1202,16 +1204,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
}
|
}
|
||||||
if (ACTIONKEYPRESSED) {
|
if (ACTIONKEYPRESSED) {
|
||||||
PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget=SELECTED_TARGET;
|
PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget=SELECTED_TARGET;
|
||||||
if (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove==nullptr) { //We have to check for this because other actions will need a target select and will override this.
|
ConfirmPlayerTargetSelection();
|
||||||
PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove=BATTLE_MOVELIST_DISPLAY[POWER_SELECTION_CURSOR[-CURRENT_TURN-1]][POWER_GRADE_CURSOR[-CURRENT_TURN-1]];
|
|
||||||
}
|
|
||||||
for (int i=0;i<PARTY_MEMBER_COUNT;i++) {
|
|
||||||
PARTY_MEMBER_OBJ[i]->highlighted=false;
|
|
||||||
}
|
|
||||||
for (int i=0;i<BATTLE_ENCOUNTER->objs.size();i++) {
|
|
||||||
BATTLE_ENCOUNTER->objs[i]->obj->highlighted=false;
|
|
||||||
}
|
|
||||||
PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->channelTimeRemaining=PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->channelTime;
|
|
||||||
BATTLE_STATE=BattleState::WAIT;
|
BATTLE_STATE=BattleState::WAIT;
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
@ -2191,6 +2184,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
MOVELIST[BattleMoveName::TESTMOVE2]=new Battle::Move("Test Move 2","An attack",40,10,ㅍ 0,1,0,false,{0,0,0,0});
|
MOVELIST[BattleMoveName::TESTMOVE2]=new Battle::Move("Test Move 2","An attack",40,10,ㅍ 0,1,0,false,{0,0,0,0});
|
||||||
MOVELIST[BattleMoveName::TESTMOVE3]=new Battle::Move("Test Move 3","An attack",25,5,ㅍ 0,3,0,false,{0,0,20,0});
|
MOVELIST[BattleMoveName::TESTMOVE3]=new Battle::Move("Test Move 3","An attack",25,5,ㅍ 0,3,0,false,{0,0,20,0});
|
||||||
MOVELIST[BattleMoveName::BASH]=new Battle::Move("Bash","Regular attack.",5,5,ㅍ 0,1,0,false,{0,0,0,0});
|
MOVELIST[BattleMoveName::BASH]=new Battle::Move("Bash","Regular attack.",5,5,ㅍ 0,1,0,false,{0,0,0,0});
|
||||||
|
MOVELIST[BattleMoveName::DEFEND]=new Battle::Move("Defend","Defend.",0,0,ㅍ 0,1,5*60,true,{0,0,0,0});
|
||||||
MOVELIST[BattleMoveName::HAILSTORM_A]=new Battle::Move("Hailstorm","Causes heavy ice rocks to crash",ALPHA,40,20,ㅍ 4,4,0,false,{0,0,20,0});
|
MOVELIST[BattleMoveName::HAILSTORM_A]=new Battle::Move("Hailstorm","Causes heavy ice rocks to crash",ALPHA,40,20,ㅍ 4,4,0,false,{0,0,20,0});
|
||||||
MOVELIST[BattleMoveName::HAILSTORM_B]=new Battle::Move("Hailstorm","Causes heavy ice rocks to crash",BETA,80,20,ㅍ 12,4,0,false,{0,0,20,0});
|
MOVELIST[BattleMoveName::HAILSTORM_B]=new Battle::Move("Hailstorm","Causes heavy ice rocks to crash",BETA,80,20,ㅍ 12,4,0,false,{0,0,20,0});
|
||||||
MOVELIST[BattleMoveName::HAILSTORM_G]=new Battle::Move("Hailstorm","Causes heavy ice rocks to crash",GAMMA,120,20,ㅍ 28,4,0,false,{0,0,20,0});
|
MOVELIST[BattleMoveName::HAILSTORM_G]=new Battle::Move("Hailstorm","Causes heavy ice rocks to crash",GAMMA,120,20,ㅍ 28,4,0,false,{0,0,20,0});
|
||||||
@ -3081,6 +3075,15 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
case BattleState::WAIT_ANIMATION:{
|
case BattleState::WAIT_ANIMATION:{
|
||||||
BATTLE_ROLLING_COUNTER_WAITTIME=5;
|
BATTLE_ROLLING_COUNTER_WAITTIME=5;
|
||||||
BATTLE_ANIMATION_TIMER++;
|
BATTLE_ANIMATION_TIMER++;
|
||||||
|
if (CURRENT_TURN<0) {
|
||||||
|
if (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove==MOVELIST[BattleMoveName::DEFEND]) {
|
||||||
|
BATTLE_ANIMATION_TIMER=999;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove==MOVELIST[BattleMoveName::DEFEND]) {
|
||||||
|
BATTLE_ANIMATION_TIMER=999;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (BATTLE_ANIMATION_TIMER==30) {
|
if (BATTLE_ANIMATION_TIMER==30) {
|
||||||
Effect*eff=(CURRENT_TURN<0)?PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->eff:BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->eff;
|
Effect*eff=(CURRENT_TURN<0)?PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->eff:BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->eff;
|
||||||
if (eff!=nullptr) {
|
if (eff!=nullptr) {
|
||||||
@ -3110,9 +3113,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
if (BATTLE_ENCOUNTER->objs[PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget]->GetHP()>0) {
|
if (BATTLE_ENCOUNTER->objs[PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget]->GetHP()>0) {
|
||||||
//Enemies have their health directly set.
|
//Enemies have their health directly set.
|
||||||
for (auto&ent:GetEntitiesInRange(PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget,PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->channelPos,PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove)) {
|
for (auto&ent:GetEntitiesInRange(PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget,PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->channelPos,PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove)) {
|
||||||
int dmgAmt = PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->baseDmg+
|
int dmgAmt = CalculateDamage(PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]],ent);
|
||||||
((PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->randomDmg>0)?rand()%PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->randomDmg:0)
|
|
||||||
+PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->baseAtk;
|
|
||||||
if (ent->GetHP()>0) {
|
if (ent->GetHP()>0) {
|
||||||
std::cout << PARTY_MEMBER_OBJ[-CURRENT_TURN-1]->name << " uses " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->name << " " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->grade << " on " << ent->obj->name << " dealing " << dmgAmt << " health.\n";
|
std::cout << PARTY_MEMBER_OBJ[-CURRENT_TURN-1]->name << " uses " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->name << " " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->grade << " on " << ent->obj->name << " dealing " << dmgAmt << " health.\n";
|
||||||
ent->_SetDirectHP(ent->GetHP()-dmgAmt);
|
ent->_SetDirectHP(ent->GetHP()-dmgAmt);
|
||||||
@ -3146,9 +3147,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
} else {
|
} else {
|
||||||
if (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget-1]]->GetHP()>0) {
|
if (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget-1]]->GetHP()>0) {
|
||||||
for (auto&ent:GetEntitiesInRange(BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget,BATTLE_ENCOUNTER->objs[CURRENT_TURN]->channelPos,BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove)) {
|
for (auto&ent:GetEntitiesInRange(BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget,BATTLE_ENCOUNTER->objs[CURRENT_TURN]->channelPos,BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove)) {
|
||||||
int dmgAmt = BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->baseDmg+
|
int dmgAmt = CalculateDamage(BATTLE_ENCOUNTER->objs[CURRENT_TURN],ent);
|
||||||
((rand()%BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->randomDmg>0)?rand()%BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->randomDmg:0)
|
|
||||||
+BATTLE_ENCOUNTER->objs[CURRENT_TURN]->baseAtk;
|
|
||||||
if (ent->GetHP()>0) {
|
if (ent->GetHP()>0) {
|
||||||
std::cout << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->obj->name << " uses " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->name << " " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->grade << " on " << ent->obj->name << " dealing " << dmgAmt << " health.\n";
|
std::cout << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->obj->name << " uses " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->name << " " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->grade << " on " << ent->obj->name << " dealing " << dmgAmt << " health.\n";
|
||||||
ent->SubtractHP(dmgAmt);
|
ent->SubtractHP(dmgAmt);
|
||||||
@ -3557,6 +3556,29 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Can run this after target selection to reset states.
|
||||||
|
void ConfirmPlayerTargetSelection() {
|
||||||
|
for (int i=0;i<PARTY_MEMBER_COUNT;i++) {
|
||||||
|
PARTY_MEMBER_OBJ[i]->highlighted=false;
|
||||||
|
}
|
||||||
|
for (int i=0;i<BATTLE_ENCOUNTER->objs.size();i++) {
|
||||||
|
BATTLE_ENCOUNTER->objs[i]->obj->highlighted=false;
|
||||||
|
}
|
||||||
|
PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->channelTimeRemaining=PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->channelTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CalculateDamage(Entity*attacker,Entity*defender) {
|
||||||
|
int finalDamage = 0;
|
||||||
|
int attackerDamage = (attacker->selectedMove->baseDmg+
|
||||||
|
((rand()%attacker->selectedMove->randomDmg>0)?rand()%attacker->selectedMove->randomDmg:0)
|
||||||
|
+attacker->baseAtk);
|
||||||
|
finalDamage += attackerDamage;
|
||||||
|
if (defender->selectedMove==MOVELIST[BattleMoveName::DEFEND]) {
|
||||||
|
finalDamage*=0.4;
|
||||||
|
}
|
||||||
|
return finalDamage;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user