adjusted the clanfights so some things are now persisted (there is also a small test-php file that can be tempoary be used to run some things localy)
parent
307b85fbdd
commit
8cfa7e5332
@ -0,0 +1,107 @@
|
||||
<?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/user.inc.php');
|
||||
|
||||
define('EVENT_TEST', 0);
|
||||
define('EVENT_SCHATZ_SUCHE', 1);
|
||||
define('EVENT_TURNIER', 2);
|
||||
define('EVENT_KAMPF', 3);
|
||||
define('EVENT_LIGA', 4);
|
||||
define('EVENT_WANTED', 5);
|
||||
define('EVENT_CLAN_FIGHT', 6);
|
||||
|
||||
/**
|
||||
* Creates an event for a given type and returns the id of this event!
|
||||
* @param string $type
|
||||
* @return int the id of the event
|
||||
*/
|
||||
function createEvent($type) {
|
||||
while(!$finished) {
|
||||
$sql = 'SELECT IFNULL(max(event_id),0) + 1 FROM events';
|
||||
$row = mysql_fetch_row(mysql_query($sql));
|
||||
mysql_query('INSERT INTO events(event_id, event_type) values('.$row[0].', \''.$type.'\')');
|
||||
$finished = mysql_affected_rows() > 0;
|
||||
$id = $row[0];
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
/**
|
||||
* Adds a participant to a given event
|
||||
* @param int event_id
|
||||
* @param array $char
|
||||
* @return int the id of the participant (usually the charid), NULL on failure!
|
||||
*/
|
||||
function addParticipant($event_id, array $char) {
|
||||
// Okay now add the char ;)
|
||||
$user = getUser($char['besitzer']);
|
||||
$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'].')';
|
||||
|
||||
// echo $sql . '<br>';
|
||||
|
||||
mysql_query($sql);
|
||||
if(mysql_affected_rows() == 0)
|
||||
return NULL;
|
||||
return $char['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists a fight of one event.
|
||||
* @param int $event_id
|
||||
* @param array combined array that is calculated in the kampf_wrapper
|
||||
* @return int the id of the fight
|
||||
*/
|
||||
function persistFight($event_id, array $combinedArray) {
|
||||
// persist a fight of two chars (calculated by the wrapper) ^^"
|
||||
//echo 'The fight was about ' . count($combinedArray) . ' rounds <br>';
|
||||
|
||||
// first get a fight id ;).
|
||||
$finished = FALSE;
|
||||
while(!$finished) {
|
||||
$sql = 'SELECT IFNULL(max(event_fight_id),0) + 1 FROM event_fights';
|
||||
$row = mysql_fetch_row(mysql_query($sql));
|
||||
mysql_query('INSERT INTO event_fights(event_id, event_fight_id) values('.$event_id.', \''.$row[0].'\')');
|
||||
$finished = mysql_affected_rows() > 0;
|
||||
$event_fight_id = $row[0];
|
||||
}
|
||||
|
||||
// now we have a $event_fight_id ;) lets insert the other stuff ;)
|
||||
|
||||
|
||||
|
||||
for($round = 0; $round < count($combinedArray) ; $round++) {
|
||||
// persist this round ^^"
|
||||
|
||||
// first persist char1
|
||||
$chara_1 = $combinedArray[$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'].', \''. $combinedArray[$round]['atk_char1'] .'\', \''. $combinedArray[$round]['dmg_char1'] .'\')';
|
||||
|
||||
// echo $sql .'<br>';
|
||||
|
||||
mysql_query($sql);
|
||||
// now persist char2
|
||||
$chara_2 = $combinedArray[$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'].', \''. $combinedArray[$round]['atk_char2'] .'\', \''. $combinedArray[$round]['dmg_char2'] .'\')';
|
||||
|
||||
// echo $sql .'<br>';
|
||||
|
||||
mysql_query($sql);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/*
|
||||
*
|
||||
* @copyright (c) 2011 animegame.eu
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Converts the learn-ids of a char to the attack ids (that can be used to determine the technique)
|
||||
* @param array $learnids
|
||||
* @param int $char_id
|
||||
*/
|
||||
function convertLearnIDToAttackID (array $learnids, $char_id) {
|
||||
$result = array();
|
||||
$sql = 'SELECT id, at_id FROM lernen WHERE id IN ('.implode(',', $learnids).') AND besitzer = ' . $char_id;
|
||||
// echo $sql .'<br>';
|
||||
$qry = mysql_query($sql);
|
||||
while($row = mysql_fetch_assoc($qry)) {
|
||||
for($i=0;$i<count($learnids);$i++) {
|
||||
if($learnids[$i] == $row['id']) {
|
||||
$result[$i] = $row['at_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Lets char1 fight against char2 (the attacks that are in the entry "attacken" will be used, no conditions!)
|
||||
* @param array $char1 the char-array for the first char that should be used (like it is)
|
||||
* @param array $char2 the char-array for the second char that should be used (like it is)
|
||||
* @return an array with the contents of the several rounds
|
||||
*/
|
||||
function calculateFight(array $char1, array $char2) {
|
||||
|
||||
$chara_1 = $char1;
|
||||
$chara_2 = $char2;
|
||||
|
||||
################## Init Kaempfer 1
|
||||
|
||||
$k_hp1 = explode(',', $chara_1['hp']);
|
||||
$k_mp1 = explode(',', $chara_1['mp']);
|
||||
|
||||
$k_starke[0] = $chara_1['starke'];
|
||||
$k_speed[0] = $chara_1['speed'];
|
||||
$k_ver[0] = $chara_1['verteidigung'];
|
||||
$k_ausdauer[0] = $chara_1['ausdauer'];
|
||||
$k_glueck[0] = $chara_1['glueck'];
|
||||
|
||||
// readout the attacks of fighter one
|
||||
|
||||
$k_attacke1 = convertLearnIDToAttackID(explode(',', $chara_1['attacken']), $chara_1['id']);
|
||||
|
||||
$k_hp[0] = round($k_hp1[0]);
|
||||
$k_mp[0] = round($k_mp1[0]);
|
||||
|
||||
$k_aufgabe_a_1 = $k_hp1[1] / 100;
|
||||
$k_aufgabe[0] = $k_aufgabe_a_1 * $chara_1['aufgeben'];
|
||||
|
||||
################## Init Kaempfer 2
|
||||
|
||||
$k_hp2 = explode(',', $chara_2['hp']);
|
||||
$k_mp2 = explode(',', $chara_2['mp']);
|
||||
|
||||
$k_starke[1] = $chara_2['starke'];
|
||||
$k_speed[1] = $chara_2['speed'];
|
||||
$k_ver[1] = $chara_2['verteidigung'];
|
||||
$k_ausdauer[1] = $chara_2['ausdauer'];
|
||||
$k_glueck[1] = $chara_2['glueck'];
|
||||
|
||||
$k_attacke2 = convertLearnIDToAttackID(explode(',', $chara_2['attacken']), $chara_2['id']);
|
||||
|
||||
$k_hp[1] = round($k_hp2[0]);
|
||||
$k_mp[1] = round($k_mp2[0]);
|
||||
|
||||
$k_aufgabe_a_2 = $k_hp2[1] / 100;
|
||||
$k_aufgabe[1] = $k_aufgabe_a_2 * $chara_2['aufgeben'];
|
||||
|
||||
|
||||
$runden_type1 = 0;
|
||||
$runden_type2 = 0;
|
||||
$x = 0;
|
||||
|
||||
$runden_summon1 = '';
|
||||
$runden_summon2 = '';
|
||||
$runden_gif1 = 0;
|
||||
$runden_gif_technik1 = '';
|
||||
$runden_gif2 = 0;
|
||||
$runden_gif_technik2 = '';
|
||||
|
||||
// now that we know what attacks our chars are capable of readout the attack information!
|
||||
$kombined = array_merge($k_attacke1, $k_attacke2);
|
||||
if(count($kombined) > 0) {
|
||||
$sql = 'SELECT * FROM attacken WHERE id IN(' .implode(',', $kombined) . ')';
|
||||
// echo $sql .'<br>';
|
||||
$qry = mysql_query($sql);
|
||||
|
||||
$attack_data = array();
|
||||
while($row = mysql_fetch_assoc($qry)) {
|
||||
$attack_data[$row['id']] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
## Start the fight ;)
|
||||
|
||||
// The "rundenArray" has a specific structure. For each round played another entry is placed.
|
||||
// An entry contains { char1_array*, char2_array*, atk_char1, atk_char2, dmg_char1, dmg_char2 }
|
||||
// the char arrays contain the stats of the chars at the end of the round !
|
||||
|
||||
|
||||
|
||||
$rundenArray = array();
|
||||
|
||||
$tmp_hp = array();
|
||||
while ($k_hp[0] > $k_aufgabe[0] AND $k_hp[1] > $k_aufgabe[1] AND $x < 10) {
|
||||
|
||||
$runde = array();
|
||||
$runde['char1_array'] = $char1;
|
||||
$runde['char2_array'] = $char2;
|
||||
|
||||
$technick1 = $attack_data[$k_attacke1[$x]];
|
||||
$technick2 = $attack_data[$k_attacke2[$x]];
|
||||
|
||||
///////////////////Hier laedt er den RELOAD der technik wenn die zusammen setzung nicht stimmen sollte
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/andere_technik.php'); /////////////////// Wenn man ne andere technik sich aussuchen will...
|
||||
|
||||
$speeds_char1 = ($k_speed[0] + $technick1[speed]);
|
||||
$speeds_char2 = ($k_speed[1] + $technick2[speed]);
|
||||
|
||||
////// MUSS SO BLEIBEN WICHTIG
|
||||
$aussetzten_runde = '';
|
||||
$tmp_hp[0] = 0;
|
||||
$tmp_hp[1] = 0;
|
||||
##################################MP, SSJ Verwandlungen, HP, Koerper Tausch Technicken
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/majin.php');
|
||||
|
||||
if (!$aussetzten_runde) { /////DAS FUER MAJIN ATTACKEN
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/atk_wert.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/tausch2.php'); //////////////////Muss ganz oben sein wegen technik Tauschen
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/gift.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/frucht.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/mp.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/hp.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/hp2.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/SSJ.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/kaioken.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/kaioken2.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/copy.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/lose.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/lose2.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/ausdauer.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/mpv.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/tausch.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/hpmp.php');
|
||||
//Als letztes um alle HP-Attacken zu kontern (in $tmp_hp gespeichert)
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/konter_heal.php');
|
||||
//include "kampf/summon.php";
|
||||
}
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/atk_wert.php');
|
||||
if (!$aussetzten_runde) { /////DAS FUER MAJIN ATTACKEN
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/schatten.php');
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/runde.php');
|
||||
}
|
||||
|
||||
#####################################KAMPF SYSTEM
|
||||
include ($_SERVER['DOCUMENT_ROOT'] . 'ag/include/kampf/kampf_rechnung.php');
|
||||
|
||||
// $db_query = mysql_fetch_array(mysql_query("SELECT * FROM kampf WHERE (char1='$chara_1[id]' OR char1='$chara_2[id]') AND dauer='0' order by id DESC LIMIT 1"));
|
||||
// mysql_query("UPDATE kampf SET hp1='$db_query[hp1],$k_hp7[0]', hp2='$db_query[hp2],$k_hp7[1]', mp1='$db_query[mp1],$k_mp7[0]', mp2='$db_query[mp2],$k_mp7[1]', schaden1='$db_query[schaden1],$schaden_1', schaden2='$db_query[schaden2],$schaden_2', attacke1='$db_query[attacke1],$technick1[name]', attacke2='$db_query[attacke2],$technick2[name]', starke1='$db_query[starke1],$k_starke[0]', starke2='$db_query[starke2],$k_starke[1]', ver1='$db_query[ver1],$k_ver[0]', ver2='$db_query[ver2],$k_ver[1]', speed1='$db_query[speed1],$k_speed[0]', speed2='$db_query[speed2],$k_speed[1]', ausdauer1='$db_query[ausdauer1],$k_ausdauer[0]', ausdauer2='$db_query[ausdauer2],$k_ausdauer[1]', glueck1='$db_query[glueck1],$k_glueck[0]', glueck2='$db_query[glueck2],$k_glueck[1]' WHERE id='$db_query[id]'");
|
||||
|
||||
|
||||
// stupid, i know .... but what else should i do if i don't want to rewrite it all -.-
|
||||
|
||||
$chara_1['starke'] = $k_starke[0];
|
||||
$chara_1['speed'] = $k_speed[0];
|
||||
$chara_1['verteidigung'] = $k_ver[0];
|
||||
$chara_1['ausdauer'] = $k_ausdauer[0];
|
||||
$chara_1['glueck'] = $k_glueck[0];
|
||||
|
||||
$chara_1['hp'] = $k_hp[0];
|
||||
$chara_1['hp_max'] = $k_hp1[1];
|
||||
$chara_1['mp'] = $k_mp[0];
|
||||
$chara_1['mp_max'] = $k_mp1[1];
|
||||
|
||||
$chara_2['starke'] = $k_starke[1];
|
||||
$chara_2['speed'] = $k_speed[1];
|
||||
$chara_2['verteidigung'] = $k_ver[1];
|
||||
$chara_2['ausdauer'] = $k_ausdauer[1];
|
||||
$chara_2['glueck'] = $k_glueck[1];
|
||||
|
||||
$chara_2['hp'] = $k_hp[1];
|
||||
$chara_2['hp_max'] = $k_hp2[1];
|
||||
$chara_2['mp'] = $k_hp[1];
|
||||
$chara_2['mp_max'] = $k_hp2[1];
|
||||
|
||||
$runde['char1_array'] = $chara_1;
|
||||
$runde['char2_array'] = $chara_2;
|
||||
$runde['atk_char1'] = $technick1['name'];
|
||||
$runde['atk_char2'] = $technick2['name'];
|
||||
$runde['dmg_char1'] = $schaden_1;
|
||||
$runde['dmg_char2'] = $schaden_2;
|
||||
|
||||
$x++;
|
||||
$rundenArray[] = $runde;
|
||||
|
||||
}
|
||||
|
||||
return $rundenArray;
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,23 @@
|
||||
<?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/kampf_wrapper.inc.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/event.inc.php');
|
||||
include_once($_SERVER['DOCUMENT_ROOT'].'ag/include/char.inc.php');
|
||||
|
||||
|
||||
$event_id = createEvent(EVENT_TEST);
|
||||
|
||||
$charid = addParticipant($event_id, getChar(4113));
|
||||
$charid = addParticipant($event_id, getChar(4162));
|
||||
|
||||
$combinedArray = calculateFight(getChar(4113), getChar(4162));
|
||||
|
||||
persistFight($event_id, $combinedArray);
|
||||
|
||||
?>
|
Loading…
Reference in new issue