Game Design: Calculating Experience Points earned after a battle
I'm developing a simple text battle game and having some issues calculating how much XP should be earned after a battle, theres a few factors that i want to consider:
1) Players should of course earn good XP if they beat someone of the same level
2) Players should earn great XP if they beat someone of a higher level
3) Players should earn poor XP if they defeat someone of a lower level.
4) The above should scale nicely, i.e. if player A is level 10 and battles Player B who's level 9 or 11 the difference shouldn't be huge (they would of course gain more XP for defeating the level 11 character but we wouldn't expect t开发者_开发问答his to be huge), but if he was to battle a level 5 or 15 this difference should be huge.
Just having trouble calculating something that works well in all scenarios, currently my XP table looks like the below:
Current Level XP Needed Increase from Last Level
1 30 0
2 65 35
3 106 41
4 154 48
5 210 56
...
10 672 123
In PHP my code looks like the below to calculate the XP Needed:
$offset = 30;
$multiplier = 1.17;
$base = $prevXp * $multiplier;
$xp = $base + $offset;
I've tried a few different things but i haven't been impressed with any of them, I'd like to work with calculating the difference in XP between the two players and then using some kind of multiplier but i haven't been impressed with the results so far.
Any help / input would be appreciated.
Here is the fight method I used for a FB game I ditched. You might find it useful.
public function fight(Player $attacker, Player $defender){ $return = 'Attacking '.$defender->getName().'
'; // if the defener has greater def than attackers attack, repel the attack // if the attacker has greater attack then the denfenders defense, penetrate if($attacker->getAttack() > $defender->getDefense()){ $attacker->takeTemper(1); // penetration -- that's what she said!!! // figure out how much to damage each player $dmgDefender = rand(5, 25); $defender->takeHP($dmgDefender); $dmgAttacker = rand(0, 10); // figure out the reward // give between 1 and 5 XP and 10% of the defenders money $gainedXP = rand(1, 5); $attacker->addXP($gainedXP); $gainedMoney = floor($defender->getMoney() * .1); $attacker->addMoney($gainedMoney); $defender->takeMoney($gainedMoney); $return .= 'You won the fight and gained '.$gainedXP.' XP and $'.$gainedMoney.'
'; if($dmgAttacker > 0){ $return .= 'Unfortuantely you took '.$dmgAttacker.' damage in the fight. The good news is you did '.$dmgDefender.' damage to '.$defender->getName().'
'; $attacker->takeHP($dmgAttacker); } // check if the player leveled $nextLevelXP = $this->_level->levelXP( $attacker->getLevel() + 1 ); if( ( $attacker->getXP() >= $nextLevelXP ) ){ $gainedFounderPoints = $this->gainLevel($attacker); $return .= 'You gained a level'; if($gainedFounderPoints > 0) $return .= ' and '.$gainedFounderPoints.IMG_FOUNDER_POINT; $return .= '
'; } } else { // attack deflected $return .= 'The attack was deflected by '.$defender->getName().'
'; // reward defender -- how about 10% of the attackers money? $reward = ceil($attacker->getMoney() * .1); if($reward > 0){ // demerit attacker $attacker->takeMoney($reward); $defender->giveMoney($reward); $return .= 'You lost $'.$reward.'
'; } else { // the attacker is broke ... take his XP!!! -- 1 percent $reward = ceil($attacker->getXP() * .01); $attacker->takeXP($reward); $defender->addXP($reward); $return .= 'You lost '.$reward.' XP
'; } } // save data $attacker->save(); $defender->save(); // output return $return; }
this is kind of simple but it fits your criteria
xpGain = getbasexp(); //whatever you were doing before
xpGain *= opponentxp * 1.0 / playerxp;
精彩评论