generic tournament adjustments (part 2)

main
hecht 7 years ago
parent 81c381db80
commit 4621896dba

@ -68,6 +68,53 @@ function addParticipant($event_id, array $char) {
return $char['id']; 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. * Persists a fight of one event.
* @param int $event_id * @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) { 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) if($result)
return $result; return $result;
return NULL; return NULL;

Loading…
Cancel
Save