//======================= // archer.cpp //======================= #include "archer.h" #include // use for setting field width #include // use for generating random factor #include using namespace std; // constructor. default values don't need to be repeated here archer::archer(int lv_in, string name_in) { role=ar; // enumerate type of job LV=lv_in; name=name_in; // Initialising the character's properties, based on his level HPmax=150+8*(LV-1); // HP increases 8 point2 per level HP=HPmax; MPmax=75+2*(LV-1); // MP increases 2 points per level MP=MPmax; AP=25+4*(LV-1); // AP increases 4 points per level DP=25+4*(LV-1); // DP increases 4 points per level speed=25+2*(LV-1); // speed increases 2 points per level playerdeath=0; EXP=LV*LV*75; bag.set(lv_in, lv_in); } void archer::isLevelUp() { if(EXP>=LV*LV*75) { LV++; AP+=4; DP+=4; HPmax+=8; MPmax+=2; speed+=2; cout<p.speed) && (rand()%100<(speed-p.speed))) // rand()%100 means generates a number no greater than 100 { HPtemp=(int)((1.0*AP/p.DP)*AP*5/(rand()%4+10)); // opponent's HP decrement calculated based their AP/DP, and uncertain chance cout< cout< system("pause"); return 1; // Attack success } bool archer::specialatt(player &p) { if(MP<40) { cout<<"You don't have enough magic points!"< EXPtemp=(int)(HPtemp*1.5); // special attack provides more experience cout<0)&&(HP>(int)((1.0*p.AP/DP)*p.AP*0.5))) // AI's HP cannot sustain 3 rounds && not too lavish && still has heal && won't be killed in next round { useHeal(); } else { if(MP>=40 && HP>0.5*HPmax && rand()%100<=30) // AI has enough MP, it has 30% to make special attack { specialatt(p); p.isDead(); // check whether player is dead } else { if (MP<40 && HP>0.5*HPmax && bag.nOfMW()) // Not enough MP && HP is safe && still has magic water { useMW(); } else { attack(p); // normal attack p.isDead(); } } } }