the clanfights have been adjusted to store the timestamp when the fight can be viewed. Also there is a new file that can be used to display event fights. The file can be executed like this -> event_kampf_anzeige.php?event_id=<event-id>&event_fight_id=<event-fight-id> and looks like any usual display :)

main
hecht 13 years ago
parent a322cc273f
commit a33f91757d

@ -22,44 +22,6 @@ $pagenum = validateUnsignedInteger($_GET['pagenum'], null);
$action = $_GET['action'];
$user = $user_ida;
function joinClan($user, $clanid){
$sql = 'SELECT * FROM user_clan_invitations WHERE userid = '.$user['id'].' and clanid = '.$clanid.' and valid > now();';
$clan_user = mysql_fetch_assoc(mysql_query($sql));
if($clan_user){
$clan = getClan($clanid);
$members = getClanMembersCount($clanid);
$members_max = getMaximumMembers($clan['id']);
if($members >= $members_max){
displayErrorMessage(NULL,'Konnte die Einladung des Clans nicht annehmen (Clan voll)!',displayHistoryBackLink());
return;
} else{
$sql = 'UPDATE user SET clan = '.$clanid.' WHERE id = '.$user['id'];
// echo $sql.'<br>';
mysql_query($sql);
// unset the leader if the user is moving from one clan to another
mysql_query('UPDATE clan SET leader = NULL WHERE leader = ' .$user['id']);
mysql_query('UPDATE clan SET co_leader = NULL WHERE co_leader = ' .$user['id']);
displayErrorMessage('Aufgenommen','Du wurdest erfolgreich in den Clan aufgenommen!','<a href="index.php?as=clan/clan_info">weiter</a>');
}
} else{
displayErrorMessage(NULL,'Konnte die Einladung des Clans nicht annehmen!',displayHistoryBackLink());
return;
}
mysql_query('DELETE FROM user_clan_invitations WHERE userid = '.$user['id'].' and clanid = '.$clanid);
}
function denyClan($user, $clanid){
mysql_query('DELETE FROM user_clan_invitations WHERE userid = '.$user['id'].' and clanid = '.$clanid);
if(mysql_affected_rows() > 0){
displayErrorMessage('Abgelehnt','Du hast die Einladung erfolgreich abgelehnt!','<a href="index.php?as=clan/add">weiter</a>');
} else{
displayErrorMessage(NULL,'Einladung des Clans konnte nicht abgelehnt werden!',displayHistoryBackLink());
}
}
if ($action == 'accept') {
joinClan($user_ida, $clanid);

@ -0,0 +1,21 @@
<?php
/*
*
* @copyright (c) 2011 animegame.eu
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
*
*/
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/config/db.inc.php');
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/kampf_anzeige.inc.php');
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/parse.inc.php');
$event_id = validateUnsignedInteger($_GET['event_id'], null);
$event_fight_id = validateUnsignedInteger($_GET['event_fight_id'], null);
if($event_id !== NULL && $event_fight_id !== NULL) {
displayEventFight($event_id, $event_fight_id);
} else {
echo 'Man kann die Seite so nicht aufrufen!!<br>';
}
?>

@ -21,6 +21,7 @@ function calculateArenaData($owner_id, $char_1, $char_2, $factor){
$arena['steh'] = 1000000;
$arena['sitz'] = 1000000;
$arena['loge'] = 1000000;
$arena['zustand'] = 1;
} else {
$arena = mysql_fetch_assoc(mysql_query('SELECT * FROM arena WHERE besitzer = '.$owner_id));
}

@ -16,6 +16,7 @@
*/
// required for status calculation!
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/event.inc.php');
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/clan_fights.inc.php');
/*
@ -73,6 +74,12 @@ function getStatus($charid, $buffer_enabled = true) {
return 'Clanfight';
}
$event_status = getEventStatus($charid);
if($event_status !== NULL) {
$GLOBALS['char_buffered_statuses'][$charid] = $event_status;
return $event_status;
}
$GLOBALS['char_buffered_statuses'][$charid] = 'Frei';
return 'Frei';
}

@ -7,6 +7,7 @@
*/
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/defines.inc.php');
include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/clan_fights.inc.php');
defineIfNotDefined('MAX_CHARS_CLANSIGN', 8);
$GLOBALS['clan_buffered_instances'] = array ();
@ -186,4 +187,48 @@ function fireMember($user, $member){
}
function joinClan($user, $clanid){
// last chance to lock the clan if in the old situation it was having to few members ;)
isClanLocked($clanid); // we only require the calculation not the result!
$sql = 'SELECT * FROM user_clan_invitations WHERE userid = '.$user['id'].' and clanid = '.$clanid.' and valid > now();';
$clan_user = mysql_fetch_assoc(mysql_query($sql));
if($clan_user){
$clan = getClan($clanid);
$members = getClanMembersCount($clanid);
$members_max = getMaximumMembers($clan['id']);
if($members >= $members_max){
displayErrorMessage(NULL,'Konnte die Einladung des Clans nicht annehmen (Clan voll)!',displayHistoryBackLink());
return;
} else{
$sql = 'UPDATE user SET clan = '.$clanid.' WHERE id = '.$user['id'];
// echo $sql.'<br>';
mysql_query($sql);
// unset the leader if the user is moving from one clan to another
mysql_query('UPDATE clan SET leader = NULL WHERE leader = ' .$user['id']);
mysql_query('UPDATE clan SET co_leader = NULL WHERE co_leader = ' .$user['id']);
displayErrorMessage('Aufgenommen','Du wurdest erfolgreich in den Clan aufgenommen!','<a href="index.php?as=clan/clan_info">weiter</a>');
}
} else{
displayErrorMessage(NULL,'Konnte die Einladung des Clans nicht annehmen!',displayHistoryBackLink());
return;
}
mysql_query('DELETE FROM user_clan_invitations WHERE userid = '.$user['id'].' and clanid = '.$clanid);
}
function denyClan($user, $clanid){
mysql_query('DELETE FROM user_clan_invitations WHERE userid = '.$user['id'].' and clanid = '.$clanid);
if(mysql_affected_rows() > 0){
displayErrorMessage('Abgelehnt','Du hast die Einladung erfolgreich abgelehnt!','<a href="index.php?as=clan/add">weiter</a>');
} else{
displayErrorMessage(NULL,'Einladung des Clans konnte nicht abgelehnt werden!',displayHistoryBackLink());
}
}
?>

@ -18,8 +18,12 @@ include_once ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/event.inc.php');
defineIfNotDefined('MIN_MEMBERS', 5);
defineIfNotDefined('MAX_OPEN_REQUESTS', 3);
defineIfNotDefined('CLANFIGHTS_MAX_FIGHTS_PER_24H', 6);
defineIfNotDefined('DAVY_BACK_FIGHT', 1);
defineIfNotDefined('SURVIVAL', 2);
defineIfNotDefined('DURATION_DAVY_BACK_FIGHT', 10);
defineIfNotDefined('DURATION_SURVIVAL_FIGHT', 10);
defineIfNotDefined('ATTACK_SET_DAVY_BACK_FIGHT', 2);
defineIfNotDefined('ATTACK_SET_SURVIVAL', 2);
@ -61,6 +65,8 @@ function challengeClan(array $user, $clanid, $anzahl = 5, $type = DAVY_BACK_FIGH
return 'Einer der Clans erfüllt die Anforderungen an Clanfights nichtmehr (wahrscheinlich zu wenig Members)!';
}
if(!semaphoreUP($ressource_clan1)) {
return 'Fehler beim Verarbeiten der Anfrage für \'' . $clan['clanname'] . '\' versuche es bitte nochmal! ';
}
@ -98,6 +104,28 @@ function challengeClan(array $user, $clanid, $anzahl = 5, $type = DAVY_BACK_FIGH
return 'Konnte den anderen Clan nicht herausfordern, da dieser Clan schoneinmal in den letzten 24 Stunden herausgefordert wurde!';
}
// it should not be possible to challenge a clan that already has an open match that is not yet calculated! ( not completely possible in sql)
$sql = 'select count(k.anzahl) as anzahl from (SELECT count(*) as anzahl FROM clan_challenges c inner join clan_challenge_clans ccc on c.clan_challenge_id = ccc.clan_challenge_id where (calculated = 1 or enddate > now()) and clan_id IN ('.$user['clan'].', '.$clanid.') group by c.clan_challenge_id) k where k.anzahl = 0';
//echo $sql .'<br>';
$row = mysql_fetch_assoc(mysql_query($sql));
if($row['anzahl'] > 0) {
semaphoreDown($ressource_clan1); // free the previously reserved semaphore!
semaphoreDown($ressource_clan2); // free the previously reserved semaphore!
return 'Du kannst einen Clan nicht herausfordern, wenn derzeit gerade ein Clanfight zwischen euch läuft oder offen ist!';
}
// now calculate how many open fights we currently had or have!
$sql = 'select count(*) as anzahl from (SELECT count(*) as anz FROM clan_challenges c inner join clan_challenge_clans ccc on c.clan_challenge_id = ccc.clan_challenge_id where calculated = 0 or TIMESTAMPADD(day, -1, now()) < enddate and clan_id IN ('.$user['clan'].', '.$clanid.') group by clan_id) k where k.anz >= ' . CLANFIGHTS_MAX_FIGHTS_PER_24H;
//echo $sql .'<br>';
$row = mysql_fetch_assoc(mysql_query($sql));
if($row['anzahl'] > 0) {
semaphoreDown($ressource_clan1); // free the previously reserved semaphore!
semaphoreDown($ressource_clan2); // free the previously reserved semaphore!
return 'Einer der beiden Clans hat das Limit von ' . CLANFIGHTS_MAX_FIGHTS_PER_24H . ' offenen und abgeschlossenen Clanfights innerhalb von 24 erreicht. Daher kann die Herausforderung nicht versandt werden!';
}
// Fordere heraus!
mysql_query('INSERT INTO clan_challenge_requests(clan_requester, clan_challenged, type, challenged_time, anzahl_chars, active) VALUES('.$user['clan'].', '.$clanid.','.$type.' , TIMESTAMPADD(HOUR, CURRENT_TIMESTAMP, 4), '.$anzahl.', true)');
@ -154,6 +182,15 @@ function acceptChallengeRequest($challenged_clan, array $user) {
return 'Einer der Clans erfüllt die Anforderungen an Clanfights nichtmehr (wahrscheinlich zu wenig Members)!';
}
// now calculate how many open fights we currently had or have! // FIXME: Good idea to pach this in a semaphore?
$sql = 'select count(*) as anzahl from (SELECT count(*) as anz FROM clan_challenges c inner join clan_challenge_clans ccc on c.clan_challenge_id = ccc.clan_challenge_id where calculated = 0 or TIMESTAMPADD(day, -1, now()) < enddate and clan_id IN ('.$clan_challenge['clan_challenged'].', '.$clan_challenge['clan_requester'].') group by clan_id) k where k.anz >= ' . CLANFIGHTS_MAX_FIGHTS_PER_24H;
// echo $sql . '<br>';
$row = mysql_fetch_assoc(mysql_query($sql));
if($row['anzahl'] > 0) {
return 'Einer der beiden Clans hat das Limit von ' . CLANFIGHTS_MAX_FIGHTS_PER_24H . ' offenen und abgeschlossenen Clanfights innerhalb von 24 erreicht. Daher kann die Herausforderung nicht angenommen werden!';
}
$oclan = getClan($clan_challenge['clan_requester']);
mysql_query('UPDATE clan_challenge_requests SET active = false WHERE clan_challenged = ' .$user['clan'] . ' AND clan_requester = ' .$challenged_clan . ' AND active = TRUE AND challenged_time > TIMESTAMPADD(day, -1, now())');
@ -483,6 +520,8 @@ function leaveChallenge($clan_challenge_id, array $user, $charid) {
function calculateChallenge($clan_challenge_id) {
$challenge = getChallenge($clan_challenge_id);
$start_time = time();
// okay the calculated flag is already set so readout all the required data for further processing!
$clan_ids = getParticipatingClanIDs($clan_challenge_id);
$clan_chars = array();
@ -497,23 +536,32 @@ function calculateChallenge($clan_challenge_id) {
}
}
$result = NULL;
// okay now determine the type of fight
switch($challenge['type']) {
case DAVY_BACK_FIGHT:
return calculateDavyBackClanFight($event_id, $clan_ids, $clan_chars);
$result = calculateDavyBackClanFight($event_id, $clan_ids, $clan_chars, $start_time);
if(!is_numeric($result))
return $result;
break;
case SURVIVAL:
return calculateSurvivalClanFight($event_id, $clan_ids, $clan_chars);
return calculateSurvivalClanFight($event_id, $clan_ids, $clan_chars, $start_time);
if(!is_numeric($result))
return $result;
break;
default:
// cannot create anything -.-
return 'Der Clanfight Typ "'.$challenge['type'].'" wird nicht unterstützt, bitte melde dich beim Administrator!' ;
}
mysql_query('UPDATE clan_challenges set event_id = '.$event_id.', enddate = \''.date("Y-m-d H:i:s",$result).'\' WHERE clan_challenge_id = ' .$clan_challenge_id);
return NULL;
}
function calculateDavyBackClanFight($event_id, array $clan_ids, array $clan_char_array) {
function calculateDavyBackClanFight($event_id, array $clan_ids, array $clan_char_array, $start_time) {
$duration = DURATION_DAVY_BACK_FIGHT * 60;
// okay, davy back fights are 1 vs. 1 and the winner is the one that has won the most fights.
if(count($clan_char_array) != 2) {
return 'Davy Back Fights können nur zwischen 2 Clans ausgetragen werden und nicht von ' . count($clan_char_array);
@ -528,11 +576,13 @@ function calculateDavyBackClanFight($event_id, array $clan_ids, array $clan_char
$char_clan_2 = $clan_char_array[$clan_ids[1]][$runde];
// we do not need to know right now who won the battle! This is required in the post processing (cronjob)!
battle($event_id, $char_clan_1, $char_clan_2, ATTACK_SET_DAVY_BACK_FIGHT);
battle($event_id, $char_clan_1, $char_clan_2, ATTACK_SET_DAVY_BACK_FIGHT, $start_time + ($runde-1) * $duration, $start_time + $runde * $duration);
}
return $start_time + ($runde-1) * $duration;
}
function calculateSurvivalClanFight($event_id, array $clan_ids, array $clan_char_array) {
function calculateSurvivalClanFight($event_id, array $clan_ids, array $clan_char_array, $start_time) {
$duration = DURATION_SURVIVAL_FIGHT * 60;
// okay, survival fights are 1 vs. 1 and the winner is the one that has the last man standing.
if(count($clan_char_array) != 2) {
return 'Survival Fights können nur zwischen 2 Clans ausgetragen werden und nicht von ' . count($clan_char_array);
@ -547,9 +597,11 @@ function calculateSurvivalClanFight($event_id, array $clan_ids, array $clan_char
$char_clan_1 = $clan_char_array[$clan_ids[0]][$counter_clan_1];
$char_clan_2 = $clan_char_array[$clan_ids[1]][$counter_clan_2];
$runde = 0;
// As long as char 1 and char 2 are set
while($char_clan_1 != NULL && $char_clan_2 != NULL) {
$sieger = battle($event_id, $char_clan_1, $char_clan_2, ATTACK_SET_SURVIVAL);
$runde++;
$sieger = battle($event_id, $char_clan_1, $char_clan_2, ATTACK_SET_SURVIVAL, $start_time + ($runde-1) * $duration, $start_time + $runde * $duration);
if($sieger['id'] != $char_clan_1['id']) {
// the loser is of clan 1
$char_clan_1 = $clan_char_array[$clan_ids[0]][++$counter_clan_1];
@ -559,6 +611,7 @@ function calculateSurvivalClanFight($event_id, array $clan_ids, array $clan_char
$char_clan_2 = $clan_char_array[$clan_ids[1]][++$counter_clan_2];
$char_clan_1 = $sieger; // the new array contains the adjusted health parameter
}
return $start_time + $runde * $duration;
}
}
@ -571,7 +624,7 @@ function calculateSurvivalClanFight($event_id, array $clan_ids, array $clan_char
* @param int $attack_set the attack set that should be used!
* @return the winners array
*/
function battle($event_id, array $char1, array $char2, $attack_set) {
function battle($event_id, array $char1, array $char2, $attack_set, $startTimestamp, $endTimestamp) {
$char1['attacken'] = implode(',', getCharAttackSet($char1['id'], $attack_set));
$char2['attacken'] = implode(',', getCharAttackSet($char2['id'], $attack_set));
@ -582,21 +635,22 @@ function battle($event_id, array $char1, array $char2, $attack_set) {
$combinedArray['data'][KEY_EXP_CHAR1] = $exp[$char1['id']];
$combinedArray['data'][KEY_EXP_CHAR2] = $exp[$char2['id']];
$arena = calculateArenaData(null, $char_1, $char_2, 0.01);
$arena = calculateArenaData(null, $char1, $char2, 0.01);
$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] = $result['geld'] * 0.7;
$combinedArray['data'][KEY_GELD_CHAR2] = $result['geld'] * 0.3;
$combinedArray['data'][KEY_GELD_CHAR1] = $arena['geld'] * 0.7;
$combinedArray['data'][KEY_GELD_CHAR2] = $arena['geld'] * 0.3;
} else {
$combinedArray['data'][KEY_GELD_CHAR2] = $result['geld'] * 0.7;
$combinedArray['data'][KEY_GELD_CHAR1] = $result['geld'] * 0.3;
$combinedArray['data'][KEY_GELD_CHAR2] = $arena['geld'] * 0.7;
$combinedArray['data'][KEY_GELD_CHAR1] = $arena['geld'] * 0.3;
}
// first persist the fight and then check who was the winner and adjust the char array for him ;)
persistFight($event_id, $combinedArray);
persistFight($event_id, $combinedArray, $startTimestamp, $endTimestamp);
return;
// now get the winners array

@ -17,13 +17,6 @@ defineIfNotDefined('EVENT_LIGA', 4);
defineIfNotDefined('EVENT_WANTED', 5);
defineIfNotDefined('EVENT_CLAN_FIGHT', 6);
// The fights duration is fixed
defineIfNotDefined('DURATIONTYPE_FIGHT', 0);
// The fights duration is resolved by the amount of rounds
defineIfNotDefined('DURATIONTYPE_ROUND', 1);
// The fights duration is fixed but the time ouf rounds is resolved!
defineIfNotDefined('DURATIONTYPE_FIGHT_RESOLVED_ROUNDS', 2);
defineIfNotDefined('KEY_LOGE', 'LOGE');
defineIfNotDefined('KEY_SITZ', 'SITZ');
defineIfNotDefined('KEY_STEH', 'STEH');
@ -64,8 +57,8 @@ function addParticipant($event_id, array $char) {
$hp = explode(',', $char['hp']);
$mp = explode(',', $char['mp']);
$sql = 'INSERT INTO event_chars(event_id, event_char_id, char_id, char_name, char_bild, user_id, user_name, hp, mp, strength, speed, defense, luck, stamina)';
$sql .= ' value('. $event_id . ', '.$char['id'] .', '.$char['id'] .', \''.$char['name'].'\', \''.$char['bild'].'\', '.$char['besitzer'].', \''.$user['nickname'].'\', '.$hp[1].', '.$mp[1].', '.$char['starke'].', '.$char['speed'].', '.$char['verteidigung'].', '.$char['glueck'].', '.$char['ausdauer'].')';
$sql = 'INSERT INTO event_chars(event_id, event_char_id, char_id, char_name, char_bild, user_id, user_name, hp, mp, strength, speed, defense, luck, stamina, block_begin, block_end)';
$sql .= ' value('. $event_id . ', '.$char['id'] .', '.$char['id'] .', \''.$char['name'].'\', \''.$char['bild'].'\', '.$char['besitzer'].', \''.$user['nickname'].'\', '.$hp[1].', '.$mp[1].', '.$char['starke'].', '.$char['speed'].', '.$char['verteidigung'].', '.$char['glueck'].', '.$char['ausdauer'].', now(), TIMESTAMPADD(Minute, 1, now()))';
// echo $sql . '<br>';
@ -84,7 +77,7 @@ function addParticipant($event_id, array $char) {
* @param int $durationValue the amount of time in minutes
* @return int the id of the fight
*/
function persistFight($event_id, array $combinedArray, $startTimestamp, $durationType, $durationValue) {
function persistFight($event_id, array $combinedArray, $startTimestamp, $endTimestamp) {
// persist a fight of two chars (calculated by the wrapper) ^^"
//echo 'The fight was about ' . count($combinedArray) . ' rounds <br>';
@ -99,7 +92,7 @@ function persistFight($event_id, array $combinedArray, $startTimestamp, $duratio
while(!$finished) {
$sql = 'SELECT IFNULL(max(event_fight_id),0) + 1 FROM event_fights';
$row = mysql_fetch_row(mysql_query($sql));
$sql = 'INSERT INTO event_fights(event_id, event_fight_id, host, winner) values('.$event_id.', \''.$row[0].'\', '. $hostId . ', ' . $winnerId .')';
$sql = 'INSERT INTO event_fights(event_id, event_fight_id, host, winner, visible) values('.$event_id.', \''.$row[0].'\', '. $hostId . ', ' . $winnerId .', \''.date("Y-m-d H:i:s",$endTimestamp).'\')';
if(mysql_query($sql) === FALSE)
break;
$finished = mysql_affected_rows() > 0;
@ -116,8 +109,8 @@ function persistFight($event_id, array $combinedArray, $startTimestamp, $duratio
// first persist char1
$chara_1 = $roundsArray[$round]['char1_array'];
$sql = 'INSERT INTO event_fight_rounds(event_id, event_fight_id, round, event_char_id, hp, mp, strength, speed, defense, luck, stamina, attack, damage)';
$sql .= ' values('.$event_id.','.$event_fight_id.','.$round.',' .$chara_1['id'].','. $chara_1['hp'].', '. $chara_1['mp'].', '. $chara_1['starke'].', '. $chara_1['speed'].', '. $chara_1['verteidigung'].', '. $chara_1['glueck'].', '. $chara_1['ausdauer'].', \''. $roundsArray[$round]['atk_char1'] .'\', \''. $roundsArray[$round]['dmg_char1'] .'\')';
$sql = 'INSERT INTO event_fight_rounds(event_id, event_fight_id, round, event_char_id, hp, mp, strength, speed, defense, luck, stamina, attack, damage, visible)';
$sql .= ' values('.$event_id.','.$event_fight_id.','.$round.',' .$chara_1['id'].','. $chara_1['hp'].', '. $chara_1['mp'].', '. $chara_1['starke'].', '. $chara_1['speed'].', '. $chara_1['verteidigung'].', '. $chara_1['glueck'].', '. $chara_1['ausdauer'].', \''. $roundsArray[$round]['atk_char1'] .'\', \''. $roundsArray[$round]['dmg_char1'] .'\', \''.date("Y-m-d H:i:s",$endTimestamp).'\')';
// echo $sql .'<br>';
@ -125,8 +118,8 @@ function persistFight($event_id, array $combinedArray, $startTimestamp, $duratio
// now persist char2
$chara_2 = $roundsArray[$round]['char2_array'];
$sql = 'INSERT INTO event_fight_rounds(event_id, event_fight_id, round, event_char_id, hp, mp, strength, speed, defense, luck, stamina, attack, damage)';
$sql .= ' values('.$event_id.','.$event_fight_id.','.$round.',' .$chara_2['id'].', '. $chara_2['hp'].', '. $chara_2['mp'].', '. $chara_2['starke'].', '. $chara_2['speed'].', '. $chara_2['verteidigung'].', '. $chara_2['glueck'].', '. $chara_2['ausdauer'].', \''. $roundsArray[$round]['atk_char2'] .'\', \''. $roundsArray[$round]['dmg_char2'] .'\')';
$sql = 'INSERT INTO event_fight_rounds(event_id, event_fight_id, round, event_char_id, hp, mp, strength, speed, defense, luck, stamina, attack, damage, visible)';
$sql .= ' values('.$event_id.','.$event_fight_id.','.$round.',' .$chara_2['id'].', '. $chara_2['hp'].', '. $chara_2['mp'].', '. $chara_2['starke'].', '. $chara_2['speed'].', '. $chara_2['verteidigung'].', '. $chara_2['glueck'].', '. $chara_2['ausdauer'].', \''. $roundsArray[$round]['atk_char2'] .'\', \''. $roundsArray[$round]['dmg_char2'] .'\', \''.date("Y-m-d H:i:s",$endTimestamp).'\')';
// echo $sql .'<br>';
@ -139,6 +132,34 @@ function persistFight($event_id, array $combinedArray, $startTimestamp, $duratio
// echo $sql . ' <br>';
mysql_query($sql);
}
mysql_query('UPDATE event_chars SET block_begin = \''.date("Y-m-d H:i:s",$startTimestamp).'\', block_end = \''.date("Y-m-d H:i:s",$endTimestamp).'\' WHERE event_id = ' . $event_id);
}
function getEventStatus($charid) {
$sql = 'SELECT event_type FROM event_chars ec inner join events e on ec.event_id = e.event_id where block_end > now() and char_id = ' . $charid;
$qry = mysql_query($sql);
$row = mysql_fetch_assoc($qry);
switch ($row['event_type']) {
case EVENT_TEST:
return 'Test';
case EVENT_SCHATZ_SUCHE:
return 'Schatzsuche';
case EVENT_TURNIER:
return 'Turnier';
case EVENT_KAMPF:
return 'Kampf';
case EVENT_LIGA:
return 'Liga';
case EVENT_WANTED:
return 'Wanted';
case EVENT_CLAN_FIGHT:
return 'Clanfight';
}
}
?>

@ -41,7 +41,7 @@ function displayCharTable($charbild, $charname, $starke, $ver, $speed, $ausdauer
<span class="statvals"><?php echo round($ausdauer); ?></span>
</td>
</tr>
</table>
</table>
<?php
}
@ -68,7 +68,31 @@ function displayAttacks($attacke1, $schaden1, $attacke2, $schaden2){
<?php
}
function displaySummary($char1_name, $char2_name, $sieger, $exp_char1, $exp_char2, $money_char1, $money_char2, $arena_exp1 = NULL, $arena_exp2 = NULL){
function displayFightIsOngoing($char1_name, $char2_name) {
echo '<tr><td colspan="3"><table class="stylish" width="50%""><tr><td><table width="100%">';
echo '<tr>' .
'<td class="greenstats" colspan="4">Der Fight läuft noch!</td>'.
'</tr>';
echo '<tr>' .
'<td class="greenstats">'.$char1_status.'</td>'.
'<td class="bold">???</td>'.
'<td class="greenstats">'.$char2_status.'</td>'.
'<td class="bold">???</td>' .
'</tr>';
echo '</table></td></tr>';
echo '</table>';
echo '</td></tr>';
}
function displaySummary($char1_name, $char2_name, $sieger, $exp_char1, $exp_char2, $money_char1, $money_char2, $arena_exp1 = NULL, $arena_exp2 = NULL, $loge = NULL, $sitz = NULL, $steh = NULL){
echo '<tr><td colspan="3"><table class="stylish" width="50%""><tr><td><table width="100%">';
@ -86,6 +110,8 @@ echo '<tr>' .
'<td class="bold">'.$char2_name.'</td>' .
'</tr>';
if($exp_char1 !== NULL || $exp_char2 !== NULL) {
echo '<tr>' .
'<td class="greenstats">Exp +</td>' .
'<td class="bold">'.$exp_char1.'</td>' .
@ -93,22 +119,60 @@ echo '<tr>' .
'<td class="bold">'.$exp_char2.'</td>'.
'</tr>';
}
if($money_char1 !== NULL || $money_char2 !== NULL) {
echo '<tr>'.
'<td class="greenstats">Geld +</td>'.
'<td class="bold">'.$money_char1.'</td>'.
'<td class="greenstats">Geld +</td>'.
'<td class="bold">'.$money_char2.'</td>' .
'</tr>';
echo '<tr>'.
'<td class="greenstats">Arena Exp +</td>'.
'<td class="bold">'.$arena_exp1.'</td>'.
'<td class="greenstats">Arena Exp +</td>'.
'<td class="bold">'.$arena_exp2.'</td>' .
'</tr>';
}
if($arena_exp1 !== NULL || $arena_exp2 !== NULL) {
echo '<tr>'.
'<td class="greenstats">Arena Exp +</td>'.
'<td class="bold">'.$arena_exp1.'</td>'.
'<td class="greenstats">Arena Exp +</td>'.
'<td class="bold">'.$arena_exp2.'</td>' .
'</tr>';
}
echo '</table></td></tr>';
echo '</table>';
if($loge !== NULL || $steh !== NULL || $sitz !== NULL) {
?>
<table class="stylish" width="50%"">
<tr>
<td>
<table width="100%">
<tr>
<td class="greenstats">Zuschauer</td>
<td class="bold"><?php echo $loge+$steh+$sitz; ?></td>
</tr>
<tr>
<td class="greenstats">Stehpl&auml;tze</td>
<td class="bold"><?php echo $steh; ?></td>
</tr>
<tr>
<td class="greenstats">Sitzpl&auml;tze</td>
<td class="bold"><?php echo $sitz; ?></td>
</tr>
<tr>
<td class="greenstats">Logenpl&auml;tze</td>
<td class="bold"><?php echo $loge; ?></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
echo '</td></tr>';
}
echo '</table></td></tr></table></td></tr>';
}
function displayFinalResult($items, $exp, $money, $final_result){
@ -132,11 +196,11 @@ echo '<tr>' .
'<td class="bold">';
// Letze Eintrag von Items ist false!!
if(!$items[0]){
echo '&nbsp;';
echo '&nbsp;';
} else{
for($i=0;$items[$i];$i++){
echo $items[$i]['name'].'<br>';
}
}
}
echo'</td></tr>';
echo '</table>' .
@ -169,25 +233,25 @@ function displaySchatzSuche($char){
echo '<tr><th class="top" colspan="3">Schatzsuche in '.$ort['stadt'].'</th></tr>';
// Hole die Ergebnisse die auch in die Datenbank eingetragen werden muessen!
$row = mysql_fetch_assoc(mysql_query('Select sum(exp) as exp, sum(geld) as geld, count(*) as anzahl from quest_fights where charid = '.$char['id']));
$row = mysql_fetch_assoc(mysql_query('Select sum(exp) as exp, sum(geld) as geld, count(*) as anzahl from quest_fights where charid = '.$char['id']));
// Ermittle den Endzustand des Chars
$end_qf = mysql_fetch_assoc(mysql_query('select max(fightnr) as mf from quest_fights where charid = '.$char['id']));
$end_qr = mysql_fetch_assoc(mysql_query('select max(roundnr) as mr from quest_rounds where fightnr = '.$end_qf['mf'].' and charid = '.$char['id']));
$last_round = mysql_fetch_assoc(mysql_query('Select * from quest_rounds where roundnr = '.$end_qr['mr'].' and fightnr = '.$end_qf['mf'].' and charid = '.$char['id']));
$last_fight = mysql_fetch_assoc(mysql_query('Select * from quest_fights where fightnr = '.$end_qf['mf'].' and charid = '.$char['id']));
// Ermittle die Reqs des Chars!
$sql = 'SELECT c_attack as a_name, count(*) as anzahl FROM quest_rounds q where roundnr > 0 and charid = '.$char['id'].' group by c_attack';
// echo $sql.'<br>';
$reqs = mysql_query($sql);
while($row_r = mysql_fetch_assoc($reqs)){
$c_attacken[] = $row_r;
// print_r($c_attacken);
// echo '<br>';
}
if($last_fight['sieger'] == $char['id']){
$final_result = 'won';
// Nur wer gewinnt bekommt was!
@ -201,19 +265,19 @@ function displaySchatzSuche($char){
$c_attacken[$i]['anzahl'] = floor($c_attacken[$i]['anzahl'] * $lose_rate);
}
}
// Zeige als erstes die Zusammenfassung an!
displayFinalResult($items, $row['exp'], $row['geld'], $final_result);
// Lade nun die Fights runter
$sql = 'Select * from quest_fights where charid = '.$char['id'];
$qry = mysql_query($sql);
while($fight = mysql_fetch_assoc($qry)){
displaySchatzSucheFight($quest, $char, $fight);
}
submitCharChanges($char['id'], $items, $row['exp'], $row['geld'], $quest['ortid'], array($last_round['c_hp']) , array($last_round['c_mp']), $c_attacken);
echo '</table></body></html>';
return null;
@ -223,11 +287,11 @@ function displaySchatzSucheFight($quest, $char, $fight){
// Lade das Monster aus der Datenbank
$sql = 'select * from quest_monster where id = '.$fight['monsterid'];
$monster = mysql_fetch_assoc(mysql_query($sql));
if($monster['bild'] == null || $monster['bild'] == ''){
$monster['bild'] = 'design/bilder/avatare/noavart.gif';
}
// Platziere den Table-Header
echo '<tr><th class="top" colspan="3">'.$char['name'].' Vs '.$monster['name'].'</th></tr>';
$sql = 'Select * from quest_rounds where charid = '.$char['id']. ' and fightnr = '.$fight['fightnr'];
@ -238,7 +302,7 @@ function displaySchatzSucheFight($quest, $char, $fight){
}
displaySummary($char['name'], $monster['name'], $fight['sieger']==$char['id']?$char['name']:$monster['name'], $fight['exp'], 0, $fight['geld'], 0);
// Und dann halt immer noch etwas platz nach unten lassen
echo '<tr height="5px"><td>&nbsp;</td></tr>';
}
@ -251,7 +315,7 @@ function displaySchatzSucheFightRound($char, $monster, $fight, $round){
}
echo '<tr><th class="round" colspan="3">'.$runde.'</th></tr>';
// Bild + Avantarinfo | Attacken + Schaden | Bild + Avantarinfo
// Bild + Avantarinfo | Attacken + Schaden | Bild + Avantarinfo
// In einer Reihe allerdings
echo '<tr><td>';
displayCharTable($char['bild'], $char['name'], $round['c_st'], $round['c_ver'], $round['c_sp'], $round['c_aus'], $round['c_gl'], $round['c_hp'], $char['hp_max'], $round['c_mp'], $char['mp_max'] );
@ -266,4 +330,116 @@ function displaySchatzSucheFightRound($char, $monster, $fight, $round){
echo '</td></tr>';
}
function displayEventFight($event_id, $event_fight_id) {
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/event.inc.php'); // for the defines :)
// Erstmal die Seite starten
echo '<html><head><link rel="stylesheet" type="text/css" href="design/FightStyle.css"></head><body><table width="100%">';
// :D
// first readout the required event data
$event_fight_data = mysql_fetch_assoc(mysql_query('SELECT *, visible <= now() as passed FROM event_fights WHERE event_id = ' . $event_id . ' AND event_fight_id = ' . $event_fight_id ));
// Okay and now get the data of the chars ;)
$sql = 'SELECT * FROM event_chars e where event_id = '.$event_id.' and event_char_id IN (SELECT event_char_id from event_fight_rounds where event_id = '.$event_id.' and event_fight_id = '.$event_fight_id.' and `round` = 0)';
// echo $sql . '<br>';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
if($row['char_bild'] == null || $row['char_bild'] == ''){
$row['char_bild'] = 'design/bilder/avatare/noavart.gif';
}
if($event_fight_data['host'] == $row['event_char_id']) {
$char1 = $row;
} else {
$char2 = $row;
}
}
// Platziere den Table-Header
echo '<tr><th class="top" colspan="3">'.$char1['char_name'].' Vs '.$char2['char_name'].'</th></tr>';
displayEventFightRound($char1, $char2, array(), array(), 0);
// now get the round data :D
$sql = 'SELECT * from event_fight_rounds WHERE event_id = ' .$event_id . ' AND event_fight_id = ' .$event_fight_id . ' and visible <= now()';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
if($event_fight_data['host'] == $row['event_char_id']) {
$char1_rounds[$row['round']] = $row;
} else {
$char2_rounds[$row['round']] = $row;
}
}
for($i=0;$i<count($char1_rounds);$i++) {
displayEventFightRound($char1, $char2, $char1_rounds[$i], $char2_rounds[$i], $i+1);
}
// TODO: check if this fight is fully visible!
// readout the meta-data of this fight :D
$sql = 'SELECT * FROM event_fight_metadata WHERE event_id = ' .$event_id . ' AND event_fight_id = ' .$event_fight_id;
$qry = mysql_query($sql);
$event_fight_metadata = array();
while($row = mysql_fetch_assoc($qry)) {
$event_fight_metadata[$row['key']] = $row['value'];
}
if($event_fight_data['passed'] == 1) {
displaySummary($char1['char_name'], $char2['char_name'], $event_fight_data['winner']==$char1['char_name']?$char1['char_name']:$char2['char_name'], $event_fight_metadata[KEY_EXP_CHAR1], $event_fight_metadata[KEY_EXP_CHAR2], $event_fight_metadata[KEY_GELD_CHAR1], $event_fight_metadata[KEY_GELD_CHAR2], $event_fight_metadata[KEY_AXP_CHAR1], $event_fight_metadata[KEY_AXP_CHAR2], $event_fight_metadata[KEY_LOGE], $event_fight_metadata[KEY_SITZ], $event_fight_metadata[KEY_STEH]);
} else {
displayFightIsOngoing($char1['char_name'], $char2['char_name']);
}
// Und dann halt immer noch etwas platz nach unten lassen
echo '<tr height="5px"><td>&nbsp;</td></tr>';
echo '</table></body></html>';
return null;
}
function displayEventFightRound(array $char1_data, array $char2_data, array $char1_round_data, array $char2_round_data, $roundnr) {
// xD
if($roundnr == 0){
$runde = 'Start:';
} else{
$runde = 'Runde: '.$roundnr;
}
echo '<tr><th class="round" colspan="3">'.$runde.'</th></tr>';
$c1_str = $roundnr==0?$char1_data['strength']:$char1_round_data['strength'];
$c1_def = $roundnr==0?$char1_data['defense']:$char1_round_data['defense'];
$c1_spd = $roundnr==0?$char1_data['speed']:$char1_round_data['speed'];
$c1_stm = $roundnr==0?$char1_data['stamina']:$char1_round_data['stamina'];
$c1_lck = $roundnr==0?$char1_data['luck']:$char1_round_data['luck'];
$c1_hp = $roundnr==0?$char1_data['hp']:$char1_round_data['hp'];
$c1_hpMax = $char1_data['hp'];
$c1_mp = $roundnr==0?$char1_data['mp']:$char1_round_data['mp'];
$c1_mpMax = $char1_data['mp'];
$c2_str = $roundnr==0?$char2_data['strength']:$char2_round_data['strength'];
$c2_def = $roundnr==0?$char2_data['defense']:$char2_round_data['defense'];
$c2_spd = $roundnr==0?$char2_data['speed']:$char2_round_data['speed'];
$c2_stm = $roundnr==0?$char2_data['stamina']:$char2_round_data['stamina'];
$c2_lck = $roundnr==0?$char2_data['luck']:$char2_round_data['luck'];
$c2_hp = $roundnr==0?$char2_data['hp']:$char2_round_data['hp'];
$c2_hpMax = $char2_data['hp'];
$c2_mp = $roundnr==0?$char2_data['mp']:$char2_round_data['mp'];
$c2_mpMax = $char2_data['mp'];
// Bild + Avantarinfo | Attacken + Schaden | Bild + Avantarinfo
// In einer Reihe allerdings
echo '<tr><td>';
displayCharTable($char1_data['char_bild'], $char1_data['char_name'], $c1_str, $c1_def, $c1_spd, $c1_stm, $c1_lck, $c1_hp, $c1_hpMax, $c1_mp, $c1_hpMax );
echo '</td><td>';
if($roundnr != 0){
displayAttacks($char1_round_data['attack'], $char1_round_data['damage'], $char2_round_data['attack'], $char2_round_data['damage']);
} else{
echo '&nbsp;';
}
echo '</td><td>';
displayCharTable($char2_data['char_bild'], $char2_data['char_name'], $c2_str, $c2_def, $c2_spd, $c2_stm, $c2_lck, $c2_hp, $c2_hpMax, $c2_mp, $c2_hpMax );
echo '</td></tr>';
}
?>

@ -235,12 +235,14 @@ function calculateExperience(array $char1, array $char2, $winner, $factor) {
$exp[$char1['id']] = 0;
$exp[$char2['id']] = 0;
if($winner == $char1['id']) {
$exp[$char1['id']] = (getPowerLevelWithBuffs($chara_1['id']) + getPowerLevelWithBuffs($chara_2['id'])) * 2.2 * $factor;
$exp[$char2['id']] = (getPowerLevelWithBuffs($chara_1['id']) + getPowerLevelWithBuffs($chara_2['id'])) * $factor;
$exp[$char1['id']] = (getPowerLevelWithBuffs($char1['id']) + getPowerLevelWithBuffs($char2['id'])) * 2.2 * $factor;
$exp[$char2['id']] = (getPowerLevelWithBuffs($char1['id']) + getPowerLevelWithBuffs($char2['id'])) * $factor;
} else {
$exp[$char1['id']] = (getPowerLevelWithBuffs($chara_1['id']) + getPowerLevelWithBuffs($chara_2['id'])) * $factor;
$exp[$char2['id']] = (getPowerLevelWithBuffs($chara_1['id']) + getPowerLevelWithBuffs($chara_2['id'])) * 2.2 * $factor;
$exp[$char1['id']] = (getPowerLevelWithBuffs($char1['id']) + getPowerLevelWithBuffs($char2['id'])) * $factor;
$exp[$char2['id']] = (getPowerLevelWithBuffs($char1['id']) + getPowerLevelWithBuffs($char2['id'])) * 2.2 * $factor;
}
$exp[$char1['id']] = round($exp[$char1['id']]);
$exp[$char2['id']] = round($exp[$char2['id']]);
return $exp;
}

@ -16,6 +16,7 @@ $acceptTestCase = true;
mysql_query('DELETE FROM clan_challenge_requests');
mysql_query('DELETE FROM clan_challenges');
mysql_query('DELETE FROM events');
$clan1 = getClan(786);
$clan2 = getClan(783);

File diff suppressed because it is too large Load Diff

@ -1,43 +0,0 @@
DROP TABLE IF EXISTS `test_ag`.`clan_fight_list`;
CREATE TABLE `test_ag`.`clan_fight_list` (
`id` int(13) NOT NULL auto_increment,
`clan` int(13) NOT NULL,
`gclan` int(13) NOT NULL,
`fighter` varchar(150) character set latin1 NOT NULL,
`gfighter` varchar(150) character set latin1 NOT NULL,
`clanfighttyp` int(13) NOT NULL,
`numberoffighter` int(13) NOT NULL,
`zeitpunkt` varchar(10) collate utf8_unicode_ci NOT NULL,
`status` int(5) NOT NULL,
`score_set` smallint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC;
DROP TABLE IF EXISTS `test_ag`.`clan_fights`;
CREATE TABLE `test_ag`.`clan_fights` (
`id` int(13) unsigned NOT NULL auto_increment,
`hp1` varchar(255) collate utf8_unicode_ci NOT NULL,
`hp2` varchar(255) collate utf8_unicode_ci NOT NULL,
`mp1` varchar(255) collate utf8_unicode_ci NOT NULL,
`mp2` varchar(255) collate utf8_unicode_ci NOT NULL,
`attacke1` text collate utf8_unicode_ci NOT NULL,
`attacke2` text collate utf8_unicode_ci NOT NULL,
`schaden1` text collate utf8_unicode_ci NOT NULL,
`schaden2` text collate utf8_unicode_ci NOT NULL,
`char1` int(20) NOT NULL default '0',
`char2` int(20) NOT NULL default '0',
`starke1` text collate utf8_unicode_ci NOT NULL,
`ver1` text collate utf8_unicode_ci NOT NULL,
`speed1` text collate utf8_unicode_ci NOT NULL,
`starke2` text collate utf8_unicode_ci NOT NULL,
`ver2` text collate utf8_unicode_ci NOT NULL,
`speed2` text collate utf8_unicode_ci NOT NULL,
`ausdauer1` varchar(255) collate utf8_unicode_ci NOT NULL,
`ausdauer2` varchar(255) collate utf8_unicode_ci NOT NULL,
`clanfight_id` int(20) NOT NULL default '0',
`runde` int(20) NOT NULL default '0',
`kampf` int(10) NOT NULL default '0',
`win` int(10) NOT NULL,
`lose` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Loading…
Cancel
Save