From 4621896dba846e61a9b8765d219c40016bbc5495 Mon Sep 17 00:00:00 2001 From: hecht Date: Wed, 30 Aug 2017 07:43:29 +0000 Subject: [PATCH] generic tournament adjustments (part 2) --- ag/include/event.inc.php | 52 ++++++++++++++++++++++++++++++++++++++- ag/include/random.inc.php | 6 ++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/ag/include/event.inc.php b/ag/include/event.inc.php index 2e851be..570dfa1 100644 --- a/ag/include/event.inc.php +++ b/ag/include/event.inc.php @@ -68,6 +68,53 @@ function addParticipant($event_id, array $char) { return $char['id']; } + +function calculateEventFight($event_id, array $char1, array $char2, $attack_set, $startTimestamp, $endTimestamp, $expFactor, $arenaFactor, array $metaData = array()) { + $char1['attacken'] = implode(',', getAttackSet($char1['id'], $attack_set)); + $char2['attacken'] = implode(',', getAttackSet($char2['id'], $attack_set)); + $combinedArray = calculateFight($char1, $char2); + + $exp = calculateExperience($char1, $char2, $combinedArray['winner'], $expFactor); + + $combinedArray['data'][KEY_EXP_CHAR1] = $exp[$char1['id']]; + $combinedArray['data'][KEY_EXP_CHAR2] = $exp[$char2['id']]; + + $arena = calculateArenaData(null, $char1, $char2, $arenaFactor); + + $combinedArray['data'][KEY_LOGE] = $arena['loge']; + $combinedArray['data'][KEY_SITZ] = $arena['sitz']; + $combinedArray['data'][KEY_STEH] = $arena['steh']; + + if($combinedArray['winner'] == $char1['id']) { + $combinedArray['data'][KEY_GELD_CHAR1] = $arena['geld'] * 0.7; + $combinedArray['data'][KEY_GELD_CHAR2] = $arena['geld'] * 0.3; + } else { + $combinedArray['data'][KEY_GELD_CHAR2] = $arena['geld'] * 0.7; + $combinedArray['data'][KEY_GELD_CHAR1] = $arena['geld'] * 0.3; + } + + foreach ($metaData as $key => $value) { + $combinedArray['data'][$key] = $value; + } + + // first persist the fight and then check who was the winner and adjust the char array for him ;) + persistFight($event_id, $combinedArray, $startTimestamp, $endTimestamp); + + // now get the winners array + $rounds = $combinedArray['rounds']; + $lastRound = $rounds[count($rounds) - 1]; + + $newChar = null; + if($lastRound['char1_array']['id'] == $combinedArray['winner']){ + $newChar = $lastRound['char1_array']; + } else { + $newChar = $lastRound['char2_array']; + } + $newChar['mp'] = $newChar['mp']. ','.$newChar['mp_max']; + $newChar['hp'] = $newChar['hp']. ','.$newChar['hp_max']; + return $newChar; +} + /** * Persists a fight of one event. * @param int $event_id @@ -285,8 +332,11 @@ function getEventChar($event_id, $event_char_id) { } +/** + * @return array with fight value (+ a passed column to indicate the fight is over) + */ function getEventFight($event_id, $event_fight_id) { - $result = mysqli_fetch_assoc(db_query('SELECT * FROM event_fights WHERE event_id = ' . $event_id. ' AND event_fight_id = ' .$event_fight_id )); + $result = mysqli_fetch_assoc(db_query('SELECT *, visible <= now() as passed FROM event_fights WHERE event_id = ' . $event_id. ' AND event_fight_id = ' .$event_fight_id )); if($result) return $result; return NULL; diff --git a/ag/include/random.inc.php b/ag/include/random.inc.php index 9a8cd1f..4ab274d 100644 --- a/ag/include/random.inc.php +++ b/ag/include/random.inc.php @@ -13,7 +13,7 @@ */ function mt_random_wrapper($min, $max) { if ($max < $min) { - return mt_rand ( $max, $min ); + return mt_rand( $max, $min ); } - return mt_rand ( $min, $max ); -} \ No newline at end of file + return mt_rand( $min, $max ); +}