@ -19,6 +19,41 @@ defineIfNotDefined('TASK_EDIT', 'dochange');
defineIfNotDefined('TASK_CREATE', 'docreate');
defineIfNotDefined('NPC_USER_NAME', 'animegame-npc');
function getDropItemsAsOptions(){
$result = NULL;
$index = 0;
// Die etwas abgewandelten SQL-Querys aus dem auktion_functions.php
$query = 'SELECT id, name, \'ware\' as tablename FROM item i WHERE s_type = \'Trank\'
union
SELECT id, name, \'sp_ware\' as tablename FROM sp_item i
union
SELECT id, item AS name, \'wochen_ware\' as tablename FROM wochen_markt w;';
$qry = mysql_query($query);
// Damit waeren alle noetigen Datenbankaufrufe erledigt!
while($row = mysql_fetch_assoc($qry)){
$result[$index++] = '< option value = \''.$row['id'].','.$row['tablename'].'\' > '.$row['name'].'< / option > ';
}
$result[$index++] = '< option value = \'lernpunkte,chars\' > Lernpunkte< / option > ';
$result[$index++] = '< option value = \'training_points,chars\' > Trainingspunkte< / option > ';
$result[$index++] = '< option value = \'starke,chars\' > Stä rke< / option > ';
$result[$index++] = '< option value = \'speed,chars\' > Geschwindigkeit< / option > ';
$result[$index++] = '< option value = \'verteidigung,chars\' > Verteidigung< / option > ';
$result[$index++] = '< option value = \'ausdauer,chars\' > Ausdauer< / option > ';
$result[$index++] = '< option value = \'glueck,chars\' > Glü ck< / option > ';
$result[$index++] = '< option value = \'hp,chars\' > HP< / option > ';
$result[$index++] = '< option value = \'mp,chars\' > MP< / option > ';
return $result;
}
function istrinstr($source, $insert, $search) {
$pos = strpos($source, $search);
$newstr = substr($source, 0, $pos).$insert.substr($source, $pos);
return $newstr;
}
function getNPCUser() {
$qry = mysql_query('SELECT * FROM user WHERE nickname = "'.NPC_USER_NAME.'";');
return mysql_fetch_assoc($qry);
@ -105,13 +140,15 @@ function displayNPCInfo($action, $task, $charid) {
'Ausdauer', 'Glück', 'Kampfdauer in Sekunden', 'Level', 'Min-Level', 'Max-Level', 'Bild');
$attset = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
$attset_names = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
$drop_items = getDropItemsAsOptions();
//initialisieren falls editiert wird (dort existieren schon Inhalte)
if($task == TASK_EDIT) {
$attset = getCharAttackSet($charid, NORMALKAMPF);
$attset_names = getAttackNamesFromAttackSet($attset);
// $sql = 'SELECT * FROM chars c inner join npc_item ni on ni.charakter = c.id inner join kampf_list kl on ni.charakter = kl.charakter WHERE c.id ='.$charid;
$sql = 'SELECT * FROM chars c inner join kampf_list kl on c.id = kl.charakter WHERE c.id ='.$charid;
$sql = 'SELECT * FROM chars c inner join npc_item ni on ni.charakter = c.id inner join kampf_list kl on ni.charakter = kl.charakter WHERE c.id ='.$charid;
// $sql = 'SELECT * FROM chars c inner join kampf_list kl on c.id = kl.charakter WHERE c.id ='.$charid;
$qry = mysql_query($sql);
$row = mysql_fetch_assoc($qry);
}
@ -145,6 +182,27 @@ function displayNPCInfo($action, $task, $charid) {
}
}
//dropitems
echo "\t".'< tr > < td colspan = "'.$colspan.'" style = "text-align:center" > Drop< / td > < / tr > '."\n";
echo "\t\t".'< tr > < td > Item< / td > < td style = "text-align:center" > < select id = "input" name = "data[drop]" > ';
//zusammenbauen des suchparameters
if($row['datensatz'] == 'chars') {
$selected = '\''.$row['feld'].','.$row['datensatz'].'\'';
} else {
$selected = '\''.$row['item'].','.$row['datensatz'].'\'';
}
foreach($drop_items as $drop) {
if(strpos($drop, $selected) == true) {
echo istrinstr($drop, ' selected', '>');
} else {
echo $drop;
}
}
echo '< / select > < / td > < / tr > '."\n";
echo "\t\t".'< tr > < td > Anzahl< / td > < td style = "text-align:center" > < input name = "data[drop_anzahl]" value = "'.debbcode($row['wieviel']).'" > < / input > < / td > < / tr > '."\n";
echo "\t\t".'< tr > < td > maximale Wiederholungen< / td > < td style = "text-align:center" > < input name = "data[drop_max]" value = "'.debbcode($row['mal']).'" > < / input > < / td > < / tr > '."\n";
echo "\t\t".'< tr > < td > Preis< / td > < td style = "text-align:center" > < input name = "data[preis]" value = "'.debbcode($row['preis']).'" > < / input > < / td > < / tr > '."\n";
//attacken informationen
echo "\t".'< tr > < td colspan = "'.$colspan.'" style = "text-align:center" > Attacken bearbeiten< / td > < / tr > '."\n";
for($i = 1;$i< 11 ; $ i + + ) {
@ -155,6 +213,7 @@ function displayNPCInfo($action, $task, $charid) {
}
echo '< / select > < / td > < / tr > '."\n";
}
//menü
echo "\t".'< tr > < td colspan = "'.$colspan.'" style = "text-align:center" > < input type = "submit" value = "speichern" > < / td > < / tr > '."\n";
echo "\t".'< tr > < td colspan = "'.$colspan.'" style = "text-align:center" > < a href = "'.$_SERVER['PHP_SELF'].'?choose=npc" > NPC Übersicht< / a > < / td > < / tr > '."\n";
@ -167,7 +226,7 @@ function editNPC($charid, $data, $att_ids) {
$d_array = array('name', 'type', 'hp', 'mp', 'starke', 'verteidigung', 'speed',
'ausdauer', 'glueck', 'level', 'bild');
$sql = 'UPDATE chars c INNER JOIN kampf_list kl ON c.id=kl.charakter SET c.';
$sql = 'UPDATE chars c INNER JOIN kampf_list kl ON c.id=kl.charakter INNER JOIN npc_item n ON c.id=n.charakter SET c.';
$sql .= $d_array[0].' = \''.encodeNoHTMLWithBB($data[$d_array[0]]).'\'';
for($i=1;$i< count ( $ d_array ) ; $ i + + ) {
@ -179,7 +238,20 @@ function editNPC($charid, $data, $att_ids) {
$sql .= ', kl.'. $d_array[$i].' = \''.encodeNoHTMLWithBB($data[$d_array[$i]]).'\'';
}
$info = explode(',', encodeNoHTMLWithBB($data['drop']));
if($info[1] == 'chars') {
$sql .= ', n.feld = \''.$info[0].'\'';
} else {
$sql .= ', n.item = \''.$info[0].'\'';
}
$sql .= ', n.datensatz = \''.$info[1].'\'';
$sql .= ', n.wieviel = \''.encodeNoHTMLWithBB($data['drop_anzahl']).'\'';
$sql .= ', n.mal = \''.encodeNoHTMLWithBB($data['drop_max']).'\'';
$sql .= ', n.preis = \''.encodeNoHTMLWithBB($data['preis']).'\'';
$sql .= ' WHERE c.id=\''.$charid.'\'';
//echo $sql;
$u = mysql_query($sql);
$log = 0;
@ -208,15 +280,11 @@ function editNPC($charid, $data, $att_ids) {
}
function createNPC($data, $att_ids) {
$d_array = array('charakter', 'name', 'type', 'hp', 'mp', 'starke', 'verteidigung', 'speed',
'ausdauer', 'glueck', 'zeit_rec', 'level', 'lvlmin', 'lvlmax', 'bild');
foreach ($data as $info) {
if($info == NULL) {
//TODO: FEHLER!
echo 'fehler dude!';
foreach ($data as $key => $value) {
if($value == NULL) {
echo 'fehler dude! bei '.$key;
} else {
$info = encodeNoHTMLWithBB($info );
$value = encodeNoHTMLWithBB($value);
}
}
@ -235,6 +303,18 @@ function createNPC($data, $att_ids) {
$data['zeit_rec'].','.$data['lvlmax'].',0,'.$data['lvlmin'].');';
mysql_query($sql);
//drops hinzufügen :D
$sql = 'INSERT INTO npc_item(charakter,item,feld,mal,datensatz,wieviel,preis) VALUES('.$char_id;
$info = explode(',', $data['drop']);
if($info[1] == 'chars') {
$sql .= ',0,\''.$info[0].'\'';
} else {
$sql .= ','.$info[0].',\'\'';
}
$sql .= ','.$data['drop_max'].',\''.$info[1].'\','.$data['drop_anzahl'].','.$data['preis'].');';
echo $sql;
mysql_query($sql);
//Attacksets soweit einbinden
$attset = buildAttackSet($char_id, $att_ids);
$error = validateAttackSetTypes($attset);
@ -315,7 +395,7 @@ function displayNPCOverview($page) {
$total = mysql_num_rows(mysql_query('SELECT '.join($d_array,',').' from chars where rasse = \'NPC\''));
$url = '< a href = "'.$_SERVER['PHP_SELF'].'?choose=npc&page=###PAGE###" > ###LABEL###< / a > ';
echo "\t".'< tr > < td colspan = "'.$colspan.'" > '.displayPagelinksNew(20, $total, $page, $url).'< / td > < / tr > '."\n";
echo "\t".'< tr > < td colspan = "'.$colspan.'" style = "text-align:center" > < a href = "'.$_SERVER['PHP_SELF'].'?choose=npc&action=create" > Create a new NPC< / a > < / td > < / tr > '."\n";
echo "\t".'< tr > < td colspan = "'.$colspan.'" style = "text-align:center" > < hr > < / td > < / tr > '."\n";
}