added the crafting feature

main
hecht 8 years ago
parent 45b747d462
commit 31b4ff3049

@ -35,6 +35,7 @@ include_once(ROOT_PATH.'/gm/include/clan.inc.php');
include_once(ROOT_PATH.'/gm/include/geheim.inc.php');
include_once(ROOT_PATH.'/gm/include/info.inc.php');
include_once(ROOT_PATH.'/gm/include/item.inc.php');
include_once(ROOT_PATH.'/gm/include/rezept.inc.php');
include_once(ROOT_PATH.'/gm/include/monster.inc.php');
include_once(ROOT_PATH.'/gm/include/npc.inc.php');
include_once(ROOT_PATH.'/gm/include/shop.inc.php');
@ -124,6 +125,7 @@ function displayOptions(){
"attackentypen" => "Attackentypen bearbeiten",
"poll" => "Umfragen bearbeiten",
"items" => "Items bearbeiten",
"rezept" => "Rezepte bearbeiten",
"clan" => "Clan bearbeiten",
"geheim" => "Geheim bearbeiten",
"usergroups" => "Nutzergruppen bearbeiten",
@ -180,6 +182,8 @@ if(checkLoginData($_SESSION['user'],$_SESSION['password'])){
displayBannOptions($_REQUEST['action'], $_REQUEST['username'],$_REQUEST['opfer'],$_REQUEST['gamebann'],$_REQUEST['shoutbann'],$_REQUEST['forenbann'],$_REQUEST['anonid']);
} else if($_REQUEST['choose'] == 'items'){
displayItems($_REQUEST['action'], $_REQUEST['task'], $_REQUEST['itemid'], $_REQUEST['itemtable'], $_REQUEST['searchstring'],$_REQUEST['s_itemtable'],$_REQUEST['page'], $_REQUEST['data']);
} else if($_REQUEST['choose'] == 'rezept') {
displayRezepte($_REQUEST);
} else if($_REQUEST['choose'] == 'faq'){
displayFaq($_REQUEST['action'], $_REQUEST['faqentry'],$_REQUEST['parent'],$_REQUEST['header'],$_REQUEST['body'], $_REQUEST['child']);
} else if($_REQUEST['choose'] == 'qnpc'){

@ -358,4 +358,4 @@ function displayItems($action, $task, $itemid, $itemtable, $searchstring, $s_ite
echo '</form>'."\n";
}
?>
?>

@ -0,0 +1,314 @@
<?php
/*
* Created on 01.09.2016
*
* @copyright (c) 2016 animegame.eu
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
*
*/
function getItemsMap() {
$items_map = array();
$qry = db_query('SELECT * from sp_item WHERE type != \'Teufels Frucht\'');
while( $row = mysql_fetch_assoc($qry) ) {
$row['table_name'] = 'sp_item';
$items_map['sp_item'][$row['id']] = $row;
}
$qry = db_query('SELECT * from item');
while( $row = mysql_fetch_assoc($qry)) {
$row['table_name'] = 'item';
$items_map['item'][$row['id']] = $row;
}
$qry = db_query('SELECT * from wochen_markt');
while( $row = mysql_fetch_assoc($qry) ) {
$row['name'] = $row['item'];
$row['table_name'] = 'wochen_markt';
$items_map['wochen_markt'][$row['id']] = $row;
}
return $items_map;
}
function item2Name($item) {
return $item['name'].'('.$item['table_name'].')';
}
function item2Value($item) {
return $item['id'].'_'.$item['table_name'];
}
function get_set_definitions() {
$items_map = getItemsMap();
$qry = db_query('SELECT * from sp_sets');
$sets = array();
while( $row = mysql_fetch_assoc($qry) ) {
$set = array();
$set['item'] = $items_map[$row['table_name']][$row['item_id']];
$dep_items = array();
$qry2 = db_query('SELECT * from sp_set_ingredient WHERE set_id = '.$row['set_id']);
while( $row2 = mysql_fetch_assoc($qry2) ) {
$dep_items[] = $items_map[$row2['table_name']][$row2['item_id']];
}
$set['deps'] = $dep_items;
$set['id'] = $row['set_id'];
$sets[] = $set;
}
return $sets;
}
function getSetDefinition($set_id) {
$sets = get_set_definitions();
foreach ($sets as $set) {
if ($set['id'] == $set_id) {
return $set;
}
}
return NULL;
}
function lookupItem($items, $itemIdHash) {
$pair = explode('_', $itemIdHash, 2);
return $items[$pair[1]][$pair[0]];
}
function getSetDefinitionFromRequest($request) {
$items = getItemsMap();
$craft_item = lookupItem($items, $request['crafted']);
$deps = array();
for ($i=0; $i<5;$i++) {
$dep_item = lookupItem($items, $request['ingredient_'.$i]);
if ( $dep_item !== NULL ) {
$deps[]=$dep_item;
}
}
$set['item'] = $craft_item;
$set['deps'] = $deps;
return $set;
}
function displayRezepte($request) {
switch ( $request['action'] ) {
case 'create':
displayRezepteCreateMenu($request);
break;
case 'edit':
displayRezepteEditMenu($request);
break;
case 'delete':
displayRezepteDeleteMenu($request);
break;
default:
displayRezepteMainMenu($request);
break;
}
}
function displayRezepteMainMenu($request) {
?>
<table>
<tr>
<th colspan="3">Rezepte</th>
</tr>
<tr>
<th>Item</th><th width="50%">Zutaten</th><th>Action</th>
</tr>
<?php
$sets = get_set_definitions();
foreach ($sets as $set) {
$dep_item_names = array();
foreach( $set['deps'] as $dep_item ) {
$dep_item_names[]=$dep_item['name'];
}
echo '<tr><td>'.$set['item']['name'].'</td><td align="center">'.join(',',$dep_item_names).'</td><td align="center"><a href="?choose=rezept&action=edit&set='.$set['id'].'">Edit</a> | <a href="?choose=rezept&action=delete&set='.$set['id'].'">Delete</a></td></tr>';
}
?>
<tr><td colspan="3" align="center"><a href="?choose=rezept&action=create">Neues Rezept erstellen</a></td></tr>
<tr>
<td colspan="3"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Zum Hauptmenu</a>
</td>
</tr>
</table>
<?php
}
function itemEquals($lhs, $rhs) {
return $lhs['id'] == $rhs['id'] && $lhs['table_name'] == $rhs['table_name'];
}
function createRezeptEntry($set) {
$qry = db_query('Select max(set_id) FROM sp_sets');
$new_id = mysql_fetch_row($qry)[0];
do {
$new_id++;
db_query('INSERT sp_sets(set_id, table_name, item_id) values('.$new_id.',\''.$set['item']['table_name'].'\','.$set['item']['id'].')');
} while(mysql_affected_rows() == 0);
return $new_id;
}
function updateRezept($base, $edit) {
if ($base['id'] === NULL) {
$base['id'] = createRezeptEntry($edit);
} else {
if ( !itemEquals($base['item'], $edit['item']) ) {
db_query('UPDATE sp_sets SET table_name=\''.$edit['item']['table_name'].'\', item_id='.$edit['item']['id'].' WHERE set_id='.$base['id']);
}
}
if( $base['deps'] === NULL ) {
$base['deps'] = array();
}
$to_add = array();
// first add the items that are in edit, but not in base
foreach ($edit['deps'] as $new_dep) {
$add = true;
foreach ($base['deps'] as $old_dep) {
if (itemEquals($new_dep, $old_dep)) {
$add = false;
break;
}
}
if($add) {
$to_add[]=$new_dep;
}
}
$to_remove = array();
foreach ($base['deps'] as $old_dep) {
$remove = true;
foreach ($edit['deps'] as $new_dep) {
if (itemEquals($old_dep, $new_dep)) {
$remove=false;
break;
}
}
if($remove) {
$to_remove[]=$old_dep;
}
}
foreach ($to_add as $item) {
db_query('INSERT sp_set_ingredient(set_id, table_name, item_id) values('.$base['id'].', \''.$item['table_name'].'\', '.$item['id'].')');
}
foreach ($to_remove as $item) {
db_query('DELETE FROM sp_set_ingredient WHERE set_id = '.$base['id'].' and table_name = \''.$item['table_name'].'\' and item_id = '.$item['id']);
}
return getSetDefinition($base['id']);
}
function displayRezepteEditMenu($request) {
$set = getSetDefinition($request['set']);
if ($set === NULL) {
displayErrorMessage("Rezept konnte nicht bearbeitet werden", "Set existiert nicht!", displayHistoryBackLink());
return;
}
if ( isset($request['crafted']) ) {
$set_changes = getSetDefinitionFromRequest($request);
updateRezept($set, $set_changes);
$set = getSetDefinition($request['set']);
}
displayForm($request, $set);
}
function displayRezepteCreateMenu($request) {
if ( isset($request['crafted']) ) {
$set_changes = getSetDefinitionFromRequest($request);
$set = updateRezept(array(), $set_changes);
$request['set'] = $set['id'];
$request['action'] = 'edit';
displayForm($request, $set);
return;
}
displayForm($request, array());
}
function displayForm($request, $set) {
$itemsMap = getItemsMap();
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input name="choose" value="<?php echo $request['choose']; ?>" type="hidden" />
<input name="action" value="<?php echo $request['action']; ?>" type="hidden" />
<input name="set" value="<?php echo $set['id']; ?>" type="hidden" />
<table>
<tr>
<th colspan="2">Rezept <?php echo $set['id']; ?></th>
</tr>
<tr>
<td>Item</td>
<td>
<select name="crafted"><?php
foreach ($itemsMap as $table) {
foreach ($table as $item) {
$selected = '';
if($set['item']['table_name'] == $item['table_name'] && $set['item']['id'] == $item['id']) {
$selected = 'selected="selected"';
}
echo '<option value="'.item2Value($item).'" '.$selected.'>'.item2Name($item).'</option>';
}
}
?>
</select>
</td>
</tr>
<?php
for ($i=0;$i<5;$i++){
?>
<tr>
<td>Zutat <?php echo $i+1; ?>:</td>
<td>
<?php
$dep_item = $set['deps'][$i];
echo '<select name="ingredient_'.$i.'">';
echo '<option value="">None</option>';
foreach ($itemsMap as $table) {
foreach ($table as $item) {
$selected = '';
if($dep_item['table_name'] == $item['table_name'] && $dep_item['id'] == $item['id']) {
$selected = 'selected="selected"';
}
echo '<option value="'.item2Value($item).'" '.$selected.'>'.item2Name($item).'</option>';
}
}
?>
</select>
</td>
<?php
}
?>
<tr>
<td colspan="2" align="center"><input type="submit" value="&Auml;ndern" /></td>
</tr>
<tr>
<td colspan="2"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?choose=rezept">Zum Rezeptemenu</a>
</td>
</tr>
<tr>
<td colspan="2"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Zum Hauptmenu</a>
</td>
</tr>
</table>
</form>
<?php
}
function displayRezepteDeleteMenu($request) {
$set = getSetDefinition($request['set']);
if ($set === NULL) {
displayErrorMessage("Rezept konnte nicht gel&ouml;scht werden", "Set existiert nicht!", displayHistoryBackLink());
return;
}
db_query('DELETE FROM sp_sets WHERE set_id = '.$set['id']);
db_query('DELETE FROM sp_set_ingredient WHERE set_id = '.$set['id']);
displayRezepteMainMenu(array());
}

@ -121,6 +121,7 @@ if ($name AND $passwort) {
$status_009 .= '<a href="index.php?as=nachricht">User Postfach</a><br>';
$status_009 .= '<a href="index.php?as=item">Meine Items</a><br>';
$status_009 .= '<a href="index.php?as=sets">Crafting</a><br>';
$status_009 .= '<a href="javascript:markt();">Markt</a><br>';
$status_009 .= '<a href="index.php?as=auktion">Auktions Markt</a><br>';
// $status_009 .= '<a href="index.php?as=shop">Shakkys Abzockbar</a><br>';

@ -48,7 +48,7 @@ $as = $_GET['as'];
/////////////////////////Item Info
if($info) {
$item = mysql_fetch_array(mysql_query("SELECT * FROM item WHERE id='$info' LIMIT 1"));
$item = mysql_fetch_array(mysql_query("SELECT * FROM item WHERE id='$info' and preis>0 LIMIT 1"));
$head = "$item[name] Info";
$text .= "St&auml;rke: $item[starke]<br>";
$text .= "Verteidigung: $item[verteidigung]<br>";
@ -97,7 +97,7 @@ $u=1;
while($u < count($w_item_anzahl)) {
if($w_item_anzahl[$u]) {
$item = mysql_fetch_array(mysql_query("SELECT preis, anzahl, name FROM item WHERE id='$w_item_id[$u]' LIMIT 1"));
$item = mysql_fetch_array(mysql_query("SELECT preis, anzahl, name FROM item WHERE id='$w_item_id[$u]' and preis>0 LIMIT 1"));
$item_preis = $item_preis + ($item['preis'] * $w_item_anzahl[$u]);
if($item['anzahl'] < $w_item_anzahl[$u]) {
@ -144,7 +144,7 @@ while($u < count($w_item_anzahl)) {
if($w_item_anzahl[$u]) {
$item = mysql_fetch_array(mysql_query("SELECT anzahl, name, s_type FROM item WHERE id='$w_item_id[$u]' LIMIT 1"));
$item = mysql_fetch_array(mysql_query("SELECT anzahl, name, s_type FROM item WHERE id='$w_item_id[$u]' and preis>0 LIMIT 1"));
$t=0;
while($t < $w_item_anzahl[$u]) {
if($item['s_type'] != "Trank") { $ru_malss = 1; }
@ -185,9 +185,9 @@ exit;
if(!$oder) { $oder = 'level,preis'; }
if(!$ords) { $ords = "Trank"; }
$item_name = mysql_query("SELECT * FROM item WHERE $filter AND s_type='$ords' order by $oder ASC LIMIT $pagenum, 10");
$item_name = mysql_query("SELECT * FROM item WHERE preis>0 and $filter AND s_type='$ords' order by $oder ASC LIMIT $pagenum, 10");
$user = mysql_Fetch_array(mysql_query("SELECT id, geld, item_res FROM user WHERE id='$user_ida[id]' LIMIT 1"));
$user_item = mysql_query("SELECT name, id FROM item ");
$user_item = mysql_query("SELECT name, id FROM item WHERE preis>0");
$GELD = $user['geld'];
@ -242,7 +242,7 @@ exit;
}
$Total = mysql_num_rows(mysql_query("SELECT id FROM item WHERE $filter AND s_type='$ords'"));
$Total = mysql_num_rows(mysql_query("SELECT id FROM item WHERE preis>0 and $filter AND s_type='$ords'"));
$pages = ceil($Total/10);
$z = 1;

@ -0,0 +1,176 @@
<?php
/*
*
* @copyright (c) 2016 animegame.eu
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public Licence
*
*/
include_once('path.inc.php'); // get the path ;)
include_once(ROOT_PATH.'/include/config.inc.php');
include_once(ROOT_PATH.'/include/fehlerausgabe.inc.php');
include_once(ROOT_PATH.'/include/designfunctions.inc.php');
include_once(ROOT_PATH.'/include/parse.inc.php');
include_once(ROOT_PATH.'/include/erstellfunctions.inc.php');
include_once(ROOT_PATH.'/include/semaphore.inc.php');
include_once(ROOT_PATH.'/include/random.inc.php');
$charm = $_GET['charm'];
$set = $_GET['set'];
?>
<SCRIPT language="JavaScript">
<!--
function create_set(id, name){
if (confirm('Do you really want to create the item ' + name + "?" )) {
window.open('?as=sets&charm=1&set=' + id, '_self');
}
}
-->
</SCRIPT>
<?php
function get_set_definitions() {
$items_map = array();
$qry = db_query('SELECT * from sp_item');
while( $row = mysql_fetch_assoc($qry) ) {
$row['table_name'] = 'sp_item';
$items_map['sp_item'][$row['id']] = $row;
}
$qry = db_query('SELECT * from item');
while( $row = mysql_fetch_assoc($qry)) {
$row['table_name'] = 'item';
$items_map['item'][$row['id']] = $row;
}
$qry = db_query('SELECT * from wochen_markt');
while( $row = mysql_fetch_assoc($qry) ) {
$row['name'] = $row['item'];
$row['table_name'] = 'wochen_markt';
$items_map['wochen_markt'][$row['id']] = $row;
}
$qry = db_query('SELECT * from sp_sets');
$sets = array();
while( $row = mysql_fetch_assoc($qry) ) {
$set = array();
$set['item'] = $items_map[$row['table_name']][$row['item_id']];
$dep_items = array();
$qry2 = db_query('SELECT * from sp_set_ingredient WHERE set_id = '.$row['set_id']);
while( $row2 = mysql_fetch_assoc($qry2) ) {
$dep_items[] = $items_map[$row2['table_name']][$row2['item_id']];
}
$set['deps'] = $dep_items;
$set['id'] = $row['set_id'];
$sets[] = $set;
}
return $sets;
}
function get_user_items($user_ida) {
$items_map = array();
$qry = db_query('SELECT * from sp_ware where user = '.$user_ida['id']);
while( $row = mysql_fetch_assoc($qry) ) {
$items_map['sp_item'][$row['item']] = $row;
}
$qry = db_query('SELECT * from ware where user = '.$user_ida['id']);
while( $row = mysql_fetch_assoc($qry)) {
$items_map['item'][$row['item_id']] = $row;
}
$qry = db_query('SELECT * from wochen_ware where user = '.$user_ida['id']);
while( $row = mysql_fetch_assoc($qry) ) {
$row['name'] = $row['item'];
$items_map['wochen_markt'][$row['item']] = $row;
}
return $items_map;
}
function displaySets($user_ida) {
?>
<table>
<tr><th colspan="3">Rezepte f&uuml;rs Crafting</th></tr>
<tr><th>Item</th><th>Zutaten</th><th>Aktion</th>
<?php
$sets = get_set_definitions();
$user_items = get_user_items($user_ida);
foreach( $sets as $set ) {
$deps = array();
$enable = true;
foreach( $set['deps'] as $dep_item ) {
if ( $user_items[$dep_item['table_name']][$dep_item['id']] !== NULL ) {
$deps[] = $dep_item['name'];
} else {
$deps[] = '<span style="color:red">'.$dep_item['name'].'</span>';
$enable = false;
}
}
?>
<tr>
<td><?php echo $set['item']['name']; ?></td>
<td><?php echo join(',', $deps); ?></td>
<td><button type="button" onclick="create_set(<?php echo $set['id']; ?>, '<?php echo $set['item']['name']; ?>');" <?php echo ($enable?'':'disabled="disabled"') ;?>>Erzeugen</button></td>
</tr>
<?php
}
?>
</table>
<?php
}
function worker($charm, $set_id, $user_ida) {
$sets = get_set_definitions();
$user_items = get_user_items($user_ida);
$ware_table=array('item' => 'ware', 'sp_item' => 'sp_ware', 'wochen_markt' => 'wochen_ware');
foreach ( $sets as $set ) {
if ($set['id'] == $set_id ) {
$enable = true;
foreach( $set['deps'] as $dep_item ) {
if ( $user_items[$dep_item['table_name']][$dep_item['id']] === NULL ) {
displayErrorMessage("Item konnte nicht erzeugt werden", "Nicht alle Zutaten vorhanden!", displayHistoryBackLink());
return;
}
}
foreach( $set['deps'] as $dep_item ) {
$rowname = 'item';
if ( $ware_table[$dep_item['table_name']] == 'ware' ) { $rowname = 'item_id'; };
db_query('DELETE FROM '.$ware_table[$dep_item['table_name']].' WHERE user = '.$user_ida['id'].' and '.$rowname.' = '.$dep_item['id'].' LIMIT 1');
if (mysql_affected_rows() == 0) {
// it failed!! (BUG, currently no roll back for the already deleted items)
displayErrorMessage("Item konnte nicht erzeugt werden", "Nicht alle Zutaten vorhanden! (Error-Code:2)", displayHistoryBackLink());
return;
}
}
if ( $ware_table[$set['item']['table_name']] == 'ware' ) {
$ru = $set['item']['s_type']=='Trank'?' ':'1';
db_query('INSERT ware(user,item_id,ru_mal) values('.$user_ida['id'].', '.$set['item']['id'].', \''.$ru.'\')');
} else {
db_query('INSERT '.$ware_table[$set['item']['table_name']].'(user, item) values('.$user_ida['id'].', '.$set['item']['id'].')');
}
if ( mysql_affected_rows() > 0 ) {
echo $set['item']['name'].' wurde erfolgreich erzeugt!';
} else {
echo $set['item']['name'].' konnte nicht erzeugt werden!';
}
displaySets($user_ida);
}
}
}
if($charm !== NULL && $set !== NULL){
worker($charm, $set,$user_ida);
} else{
displaySets($user_ida);
}
Loading…
Cancel
Save