From 8ff766997191a1a9b00a2dc00b3f6dbc940a6e85 Mon Sep 17 00:00:00 2001 From: hecht Date: Wed, 30 Nov 2011 22:51:03 +0000 Subject: [PATCH] Did some changes that were required for #59. So all functions required for calculating and assigning experience are available. --- ag/include/clan.inc.php | 24 +++++++++++++++++++++--- ag/include/clan_fights.inc.php | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/ag/include/clan.inc.php b/ag/include/clan.inc.php index c0096f6..90d3d31 100644 --- a/ag/include/clan.inc.php +++ b/ag/include/clan.inc.php @@ -89,10 +89,11 @@ function getMaximumMembers($clanid) { function getRequiredClanExp($level) { //return pow(2, $level) * 10; - $level = $level + 1; + $level = $level + 1; // 12,5*(neuesLevel)^2-22,5*(neues Level)+10 - $value = 12.5 * pow($level, 2) - 22.5 * $level + 10; - $value = beautifyNumericValue($value, 5); + // 10-22,5*(neues Level)+12,5*(neuesLevel)^2 + $value = 12.5 * pow($level, 2) - 22.5 * $level + 5; + $value = beautifyNumericValue($value, 10); return $value; } @@ -331,5 +332,22 @@ function sendClanNewsletter($user, $text){ } +function addClanExp($clan_id, $exp) { + $clan = getClan($clan_id, false); + if($clan['level'] == 18) + return; + $n_exp = $clan['exp'] + $exp; + $n_level = $clan['level']; + $req_exp = getRequiredClanExp($clan['level']); + if($req_exp <= $n_exp) { + $n_exp = 0; + $n_level++; + } + mysql_query('UPDATE clan SET exp = ' .$n_exp. ', level = ' .$n_level . ' WHERE id = ' .$clan_id . ' AND exp = ' .$clan['exp'] . ' AND level = ' .$clan['level']); + if(mysql_affected_rows() == 0) { + echo 'Fehler beim zuweisen der Clanexp, dadurch sind dem Clan mit der ID ' . $clan['level'] . ' ' .$exp . ' exp fl&omul;ten gegangen!! Neue exp wären ' . $n_exp . ' bei level ' .$n_level; + } +} + ?> diff --git a/ag/include/clan_fights.inc.php b/ag/include/clan_fights.inc.php index 9d8e54b..1829b5f 100644 --- a/ag/include/clan_fights.inc.php +++ b/ag/include/clan_fights.inc.php @@ -29,6 +29,9 @@ defineIfNotDefined('DURATION_SURVIVAL_FIGHT', 15); defineIfNotDefined('ATTACK_SET_DAVY_BACK_FIGHT', 2); defineIfNotDefined('ATTACK_SET_SURVIVAL', 2); +defineIfNotDefined('CLAN_EXP_FAKTOR_G', 1); + + $GLOBALS['clan_challenge_buffered_instances'] = array (); @@ -972,6 +975,23 @@ function isAuthorizedClanfightCoordinator($clan_id, $user_id, $clan_fight_id = N return true; } +/** + * Calculates the clan exp for clan1 + * @param array $clan1 the clan for whom the experience is calculated + * @param array $clan2 the other clan that was participating + * @param int $winner the id of the clan that has won + */ +function calculateClanExperience(array $clan1, array $clan2, $winner) { + $m = 1+pow(($clan2['level'] - $clan1['level'])/20,10); + $g = CLAN_EXP_FAKTOR_G; + if($clan1['id'] == $winner) { + $exp = (($clan1['level'] + $clan2['level'])/2)*$m*$g; + } else { + $exp = (($clan1['level'] + $clan2['level'])/3)*$m*$g; + } + return $exp; +} + /** * Returns how many chars were assigned by the leader for the given fight * @param int $clan_id