function buildpg() { global $txt, $x7c, $x7s, $print, $db, $prefix; $errore = ''; $ok = true; $pg = $x7s->username; include_once './lib/sheet_lib.php'; $query = $db->DoQuery("SELECT * FROM {$prefix}users WHERE username='******'"); $row_user = $db->Do_Fetch_Assoc($query); if (!$row_user) { die("Users not in database: should not happen"); } if (isset($_GET['build'])) { $starting_xp = $x7c->settings['starting_xp']; $xp_avail = $starting_xp; $query = $db->DoQuery("SELECT u.ability_id AS ab_id, u.value AS value, a.dep AS dep, a.dep_val AS dep_val, a.name AS name\n\t\t\t\t\t\t\tFROM \t{$prefix}userability u, \n\t\t\t\t\t\t\t\t{$prefix}ability a\n\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\tu.ability_id = a.id AND\n\t\t\t\t\t\t\t\tusername='******' AND\n\t\t\t\t\t\t\t\tcorp=''\n\t\t\t\t\t\t\tORDER BY a.name"); $ability = ''; while ($row = $db->Do_Fetch_Assoc($query)) { $ability[$row['ab_id']] = $row; if (!isset($_POST[$row['ab_id']])) { $ok = false; break; } } if (!isset($_POST['xp'])) { $ok = false; } //Controllo se le abilit� non sono state abbassate o superano il massimo //Il master fa quel che gli pare: niente controlli $tot_used = 0; $lvl_gained = 0; if ($ok) { $max_ab = $x7c->settings['max_ab_constr']; foreach ($ability as $cur) { if ($cur['value'] != $_POST[$cur['ab_id']]) { $new_value = $_POST[$cur['ab_id']]; while ($new_value > $cur['value']) { $tot_used += $new_value; $new_value--; } if ($cur['value'] > $_POST[$cur['ab_id']]) { $errore .= "Errore, non puoi scendere sotto il valore attuale<br>"; $ok = false; break; } elseif ($_POST[$cur['ab_id']] > $max_ab) { $errore .= "Errore, non puoi superare il valore massimo<br>"; $ok = false; break; } } } if ($tot_used > $xp_avail) { $errore .= "Hai usato troppi PX<br>"; $ok = false; } if ($tot_used < $starting_xp) { $errore .= "Non hai usato tutti i punti abilità {$tot_used}/{$starting_xp}<br>"; $ok = false; } if ($ok) { //Controllo le dipendenze foreach ($ability as $cur) { if ($cur['value'] != $_POST[$cur['ab_id']]) { if ($cur['dep'] != "") { if ($_POST[$cur['ab_id']] > 0 && 2 * $_POST[$cur['dep']] < $_POST[$cur['ab_id']]) { $right_value = 2 * $_POST[$cur['dep']] > 0 ? 2 * $_POST[$cur['dep']] : 1; $errore .= "Errore, non puoi avere " . $_POST[$cur['ab_id']] . " gradi in <b>" . $cur['name'] . "</b> senza vere almeno " . $right_value . " gradi in b>" . $ability[$cur['dep']]['name'] . "<br>"; $ok = false; break; } } } } } } if (isset($_POST['name']) && isset($_POST['age']) && isset($_POST['nat']) && isset($_POST['marr']) && isset($_POST['gender'])) { if ($_POST['name'] == '') { $ok = false; $errore .= "Non hai specificato il nome<br>"; } if ($_POST['age'] == '' || $_POST['age'] < 16) { $ok = false; $errore .= "Età non valida... deve essere maggiore di 16<br>"; } if ($_POST['nat'] == '') { $ok = false; $errore .= "Non hai specificato la nazionalità<br>"; } } else { $ok = false; $errore .= "Parametri mancanti<br>"; } if (isset($_POST['ch']) && $_POST['ch'] > 0) { $errore .= "Non hai usato tutti i tuoi punti caratteristica<br>"; } else { $query = $db->DoQuery("SELECT * FROM {$prefix}characteristic ORDER BY name"); $char = ''; while ($row = $db->Do_Fetch_Assoc($query)) { $char[$row['id']] = $row; } $total_char = 0; //Controllo se le caratteristiche non sono state abbassate o superano il massimo foreach ($char as $cur) { if (!isset($_POST[$cur['id']])) { $ok = false; break; } $total_char += $_POST[$cur['id']]; if ($_POST[$cur['id']] < $x7c->settings['min_ch']) { $errore .= "Errore, non puoi abbassare le caratteristiche sotto il {$x7c->settings['min_ch']}<br>"; $ok = false; break; } elseif ($_POST[$cur['id']] > $x7c->settings['max_ch']) { $errore .= "Errore, le caratteristiche non possono superare il valore massimo {$x7c->settings['max_ch']}<br>"; $ok = false; break; } } if ($total_char > $x7c->settings['starting_ch']) { $errore .= "Errore, hai usato troppi punti caratteristica<br>"; $ok = false; } } if ($ok) { //Ora posso aggiornare $newxp = $row_user['xp'] - $tot_used * $x7c->settings['xp_ratio']; $newlvl = 1; if ($_POST['gender'] == 0) { if ($_POST['marr'] == 0) { $marr = "Libero"; } else { $marr = "Sposato"; } } else { if ($_POST['marr'] == 0) { $marr = "Libera"; } else { $marr = "Sposata"; } } $pf = $_POST['rob'] * 2; $db->DoQuery("UPDATE {$prefix}users SET\n\t\t\t\t\t\t\t\tname='{$_POST['name']}',\n\t\t\t\t\t\t\t\tage='{$_POST['age']}',\n\t\t\t\t\t\t\t\tnat='{$_POST['nat']}',\n\t\t\t\t\t\t\t\tmarr='{$marr}',\n\t\t\t\t\t\t\t\tgender='{$_POST['gender']}',\n\t\t\t\t\t\t\t\tinfo='{$pf}'\n\t\t\t\t\t\t\t\tWHERE username='******'"); foreach ($char as $cur) { if (!isset($_POST[$cur['id']])) { $ok = false; break; } $db->DoQuery("UPDATE {$prefix}usercharact\n\t\t\t\t\t\t\t\t\t\tSET value='{$_POST[$cur['id']]}'\n\t\t\t\t\t\t\t\t\t\tWHERE username='******'\n\t\t\t\t\t\t\t\t\t\t AND charact_id='{$cur['id']}'"); } $db->DoQuery("UPDATE {$prefix}users \n\t\t\t\t\t\t\t\t\tSET xp='{$newxp}',\n\t\t\t\t\t\t\t\t\tlvl='{$newlvl}'\n\t\t\t\t\t\t\t\t\tWHERE username='******'"); foreach ($ability as $cur) { if ($cur['value'] != $_POST[$cur['ab_id']]) { $db->DoQuery("UPDATE {$prefix}userability \n\t\t\t\t\t\t\t\t\tSET value='{$_POST[$cur['ab_id']]}'\n\t\t\t\t\t\t\t\t\tWHERE username='******'\n\t\t\t\t\t\t\t\t\t AND ability_id='{$cur['ab_id']}'"); } } $spazio = ($_POST['for'] - 3) * 2; $db->DoQuery("UPDATE {$prefix}users\n\t\t\t\t\t\t\t\t\tSET sheet_ok='1', spazio = {$spazio}\n\t\t\t\t\t\t\t\t\tWHERE username='******'"); $db->DoQuery("INSERT INTO {$prefix}user_feat\n\t\t\t\t\t\t\t(username, feat_id)\n\t\t\t\t\t\t\tVALUES ('{$pg}', '{$_POST['add_feat']}')"); // Default equipment /*if ($row_user['base_group'] == $x7c->settings['usergroup_default']) { include_once('lib/shop_lib.php'); global $shopper, $start_cogs; pay($start_cogs, $shopper, $pg); }*/ $id = get_object_id("ID Pod"); assign_object($id, $pg, true); if ($_POST['gender'] == 0) { $id2 = get_object_id("Abiti comuni maschili"); } else { $id2 = get_object_id("Abiti comuni femminili"); } assign_object($id2, $pg, true); header('Location: ./index.php'); return; } } $max_ab = $x7c->settings['max_ab_constr']; //Characteristics $query_char = $db->DoQuery("SELECT * FROM {$prefix}characteristic"); $ch_descr_vector = "\n"; while ($row_ch = $db->Do_Fetch_Assoc($query_char)) { $charact[$row_ch['id']] = $row_ch; $ch_descr_vector .= "\t\t\t\t\t\tdescr['{$row_ch['id']}']=\"{$row_ch['descr']}\";\n"; } $ch_fields = ''; foreach ($charact as $cur_ch) { $ch_fields .= "<tr " . ">\n\t\t\t\t\t<td>{$cur_ch['name']}:</td><td><input class=\"button\" type=\"button\" value=\"-\" onMouseDown=\"return sub_ch('{$cur_ch['id']}');\">\n\t\t\t\t\t<input type=\"text\" name=\"{$cur_ch['id']}_display\" value=\"{$x7c->settings['min_ch']}\" size=\"2\" style=\"text-align: right; color: blue;\" disabled/>\n\t\t\t\t\t\t<input type=\"hidden\" name=\"{$cur_ch['id']}\" value=\"{$x7c->settings['min_ch']}\"/>\n\t\t\t\t\t\t<input class=\"button\" type=\"button\" value=\"+\" onMouseDown=\"return add_ch('{$cur_ch['id']}');\">\n</td></tr>"; } $ch = $x7c->settings['starting_ch'] - $x7c->settings['min_ch'] * sizeof($charact); //Ability $xp = $x7c->settings['starting_xp']; $max_ab = $x7c->settings['max_ab_constr']; $query = $db->DoQuery("SELECT * FROM \t{$prefix}userability,\n\t\t\t\t\t\t\t{$prefix}ability\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tability_id=id AND\n\t\t\t\t\t\t\tusername='******'\n\t\t\t\t\t\tORDER BY dep,name"); while ($row = $db->Do_Fetch_Assoc($query)) { $ability[$row['ability_id']] = $row; } $ab_descr_vector = "\n"; foreach ($ability as $cur) { $ab_descr_vector .= "\t\t\t\t\t\tdescr['{$cur['ability_id']}']=\"{$cur['descr']}\";\n"; } $ab_fields = ''; foreach ($ability as $cur) { if ($cur['dep'] == "") { $ab_fields .= "<tr " . ">"; $ab_fields .= "<td style=\"font-weight: bold;\">" . $cur['name'] . "</td>\n\t\t\t\t\t<td><input class=\"button\" type=\"button\" value=\"-\" onClick=\"return sub('{$cur['ability_id']}');\">\n\t\t\t\t\t<input type=\"text\" name=\"{$cur['ability_id']}_display\" value=\"{$cur['value']}\" size=\"2\" style=\"text-align: right; color: blue;\" disabled/>\n\t\t\t\t\t<input type=\"hidden\" name=\"{$cur['ability_id']}\" value=\"{$cur['value']}\"/>\n\t\t\t\t\t<input class=\"button\" type=\"button\" value=\"+\" onClick=\"return add('{$cur['ability_id']}');\">\n\t\t\t\t\t<input type=\"hidden\" name=\"" . $cur['ability_id'] . "_min\" value=\"{$cur['value']}\">\n\t\t\t\t\t<input type=\"hidden\" name=\"" . $cur['ability_id'] . "_name\" value=\"{$cur['name']}\">\n\t\t\t\t\t<input type=\"hidden\" name=\"" . $cur['ability_id'] . "_dep\" value=\"{$cur['dep']}\">"; $query = $db->DoQuery("SELECT id FROM {$prefix}ability WHERE dep='{$cur['ability_id']}' ORDER BY name"); $ab_fields .= "\n\t\t\t\t\t<input type=\"hidden\" name=\"" . $cur['ability_id'] . "_leaf\" value=\""; while ($leaf = $db->Do_Fetch_Assoc($query)) { $ab_fields .= $leaf['id'] . "|"; } $ab_fields .= "\">"; $ab_fields .= "</td></tr>\n"; foreach ($ability as $cur2) { if ($cur2['dep'] == $cur['ability_id']) { $ab_fields .= "<tr " . ">\n"; $ab_fields .= "<td style=\"font-weight: bold;\"> " . $cur2['name'] . "</td>\n\t\t\t\t\t\t\t\t<td><input class=\"button\" type=\"button\" value=\"-\" onMouseDown=\"return sub('{$cur2['ability_id']}');\">\n\t\t\t\t\t\t\t\t<input type=\"text\" name=\"{$cur2['ability_id']}_display\" value=\"{$cur2['value']}\" size=\"2\" style=\"text-align: right; color: blue;\" disabled/>\n\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"{$cur2['ability_id']}\" value=\"{$cur2['value']}\"/>\n\t\t\t\t\t\t\t\t<input class=\"button\" type=\"button\" value=\"+\" onMouseDown=\"return add('{$cur2['ability_id']}');\">\n\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"" . $cur2['ability_id'] . "_min\" value=\"{$cur2['value']}\">\n\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"" . $cur2['ability_id'] . "_name\" value=\"{$cur2['name']}\">\n\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"" . $cur2['ability_id'] . "_dep\" value=\"{$cur2['dep']}\">"; if ($cur2['dep'] != "") { $ab_fields .= "\n\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"" . $cur2['ability_id'] . "_dep_val\" value=\"{$cur2['dep_val']}\">"; } $ab_fields .= "</td></tr>\n"; } } } } $full_name_form = ' <tr ' . '> <td>Nome e Cognome:</td> <td><input class="sheet_input" type="text" name="name" size="16" /></td> </tr> <tr> <td> <b>NOTA:</b> Nome e cognome verranno utilizzati<br> per identificare il vostro personaggio nelle stanze </td> </tr> '; $features_form = "<select name=\"add_feat\">"; $query_feat_list = $db->DoQuery("SELECT id, feat_id FROM {$prefix}features\n\t\t\t\t\tORDER BY feat_id"); while ($row_feat_list = $db->Do_Fetch_Assoc($query_feat_list)) { $features_form .= "<option value={$row_feat_list['id']}>\n\t\t\t\t{$row_feat_list['feat_id']}</option>"; } $features_form .= "</select>"; $body = ' <script language="javascript" type="text/javascript"> var descr=Array(); ' . $ab_descr_vector . $ch_descr_vector . ' descr[\'naz\']="La Nazionalità indica lo stato dal quale provenite. Italiana, statunitense, russa... Facile dai!"; descr[\'nome\']="Il nome completo del pg è inteso come il vero nome anagrafico del personaggio, quello \\"legale\\" ... Quindi il <b>NICK</b> e\' quello che appare in chat (scorpion, butterfly, volpe quel che vi pare...) ma questo è la Vera Identità del player. Non sono quindi ammessi nomi impossibili (Leo-99 o Topolina 74) o cretini (the undead lord o Diabolik), come nemmeno nomi fantasy (Gandalf il bianco, Elandriel Blacwisdom o cose simili)... Insomma siate veritieri..."; descr[\'sesso\']="Sesso? Spesso e volentieri grazie... Non vi spiego cosa sia, tanto il menù a tendina non vi permetterà grossi errori!"; descr[\'civile\']="Indica se siete sposati o single."; function add_ch(ch_name){ var value = parseInt(document.sheet_form[ch_name].value); var ch = parseInt(document.sheet_form["ch"].value); if (ch > 0 && value < 12){ document.sheet_form[ch_name].value = value + 1; document.sheet_form["ch"].value = ch - 1; } do_ch_form_refresh(ch_name); } function sub_ch(ch_name){ var value = parseInt(document.sheet_form[ch_name].value); var ch = parseInt(document.sheet_form["ch"].value); if (value > 4){ document.sheet_form[ch_name].value = value -1; document.sheet_form["ch"].value = ch + 1; } do_ch_form_refresh(ch_name); } function do_ch_form_refresh(ch_name){ document.sheet_form[ch_name+"_display"].value = document.sheet_form[ch_name].value; document.sheet_form["ch_display"].value = document.sheet_form["ch"].value; enable_send(); } ' . ability_script($max_ab) . ' function do_form_refresh(ab_name){ document.sheet_form[ab_name+"_display"].value = document.sheet_form[ab_name].value; document.sheet_form["xp_display"].value = document.sheet_form["xp"].value; enable_send(); } function show_desc(el){ document.getElementById("help").innerHTML = \'<a target="_blank" href="../manual">Vedi il regolamento</a>\'; document.getElementById("help").style.visibility = "visible"; } function hide_desc(){ document.getElementById("help").style.visibility = "hidden"; document.getElementById("help").innerHTML = ""; } function enable_send(){ var xp=document.sheet_form["xp"].value; var ch=document.sheet_form["ch"].value; var send = document.getElementById("send"); if(xp > 0 || ch > 0){ send.disabled = true; } else{ send.disabled = false; } } </script> <p>Completa la scheda del tuo personaggio<BR> Per proseguire devi completare tutti i campi e usare tutti i punti abilità e caratteristica. </p> <p class="error_msg">' . $errore . '</p> <form action="index.php?act=buildpg&build" method="post" name="sheet_form"> <div class="overflow" id="all"> <table> ' . $full_name_form . ' <tr> <td>Età</td> <td><input class="sheet_input" type="text" name="age" value="16" size="2" style="text-align: right;" /></td> </tr> <tr ' . '> <td>Nazionalità</td> <td><input class="sheet_input" type="text" name="nat" size="16" /></td> </tr> </tr> <tr ' . '><td>Sesso:</td> <td> <select class="button" name="gender"> <option value="0">M</option> <option value="1">F</option> </select> </td> </tr> <tr ' . '> <td>Stato civile:</td> <td> <select class="button" name="marr"> <option value="0">Libero</option> <option value="1">Sposato</option> </select> </td> </tr> <tr><td colspan=2><hr></td></tr> <tr> <td>Punti caratteristica:</td> <td><input type="text" size="2" name="ch_display" value="' . $ch . '" style="text-align: right; color: blue;" disabled> <input type="hidden" name="ch" value="' . $ch . '"> </td> </tr> ' . $ch_fields . ' <tr><td>Talento:</td><td>' . $features_form . '</tr></td> <tr> <td><INPUT id="send" name="aggiorna" class="button" type="SUBMIT" value="Crea personaggio" disabled></td> </tr> </table> </div> <div class="overflow" id="ability"> <table> <tr> <td>Punti abilità:</td><td><input type="text" size="2" name="xp_display" value="' . $xp . '" style="text-align: right; color: blue;" disabled> <input type="hidden" name="xp" value="' . $xp . '"></td> </tr> ' . $ab_fields . ' </table> </div> </form> <div id="help"><a onClick="javascript: opener.focus();" target="_blank" href="../manual">Vedi il regolamento</a></div> '; //Old show desc /*function show_desc(el){ document.getElementById("help").innerHTML = descr[el]; document.getElementById("help").style.visibility = "visible"; }*/ return $body; }
function build_ability_javascript($max_ab) { $body = ''; if (!checkIfMaster()) { $body .= ' <script language="javascript" type="text/javascript"> ' . ability_script($max_ab) . ' function do_form_refresh(ab_name){ document.sheet_form[ab_name+"_display"].value = document.sheet_form[ab_name].value; document.sheet_form["xp_display"].value = document.sheet_form["xp"].value; }'; } else { $body .= ' <script language="javascript" type="text/javascript"> function add(ab_name){ var value = parseInt(document.sheet_form[ab_name].value); document.sheet_form[ab_name].value = value + 1; do_form_refresh(ab_name); } function sub(ab_name){ var value = parseInt(document.sheet_form[ab_name].value); document.sheet_form[ab_name].value = value - 1; do_form_refresh(ab_name); } function do_form_refresh(ab_name){ document.sheet_form[ab_name+"_display"].value = document.sheet_form[ab_name].value; }'; } $body .= ' function modify(){ if(document.getElementById("visual")) document.getElementById("visual").style.visibility="hidden"; if(document.getElementById("visual2")) document.getElementById("visual2").style.visibility="hidden"; if(document.getElementById("modifiable")) document.getElementById("modifiable").style.visibility="visible"; if(document.getElementById("modifiable2")) document.getElementById("modifiable2").style.visibility="visible"; if(document.getElementById("modifiable3")) document.getElementById("modifiable3").style.visibility="visible"; if(document.getElementById("modify")) document.getElementById("modify").style.visibility="hidden"; if(document.getElementById("modify2")) document.getElementById("modify2").style.visibility="hidden"; if(document.getElementById("modify3")) document.getElementById("modify3").style.visibility="hidden"; if(document.getElementById("aggiorna")) document.getElementById("aggiorna").style.visibility="visible"; } </script>'; return $body; }