mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 09:19:22 +02:00
* PLEASE RELOAD YOUR ITEMS AND MONSTERS AFTER THIS UPDATE
* save monster loot in database in json format instead loading it every time from xml file * store monster voices and immunities in json format * removed useless monsters.gfx_name field from database * convert item name to item id in loot in monsters.xml loader * after changing template you will be redirected to latest viewed page * display gallery add image form only on main gallery page * fixed displaying monster loot when item.name in loot is used instead of item.id * (intern) added new function getItemNameById($id) * (intern) renamed database field monsters.hide_creature to hidden
This commit is contained in:
parent
d4900eac84
commit
c2678aa91f
@ -28,7 +28,7 @@ session_start();
|
||||
|
||||
define('MYAAC', true);
|
||||
define('MYAAC_VERSION', '0.6.1');
|
||||
define('DATABASE_VERSION', 13);
|
||||
define('DATABASE_VERSION', 14);
|
||||
define('TABLE_PREFIX', 'myaac_');
|
||||
define('START_TIME', microtime(true));
|
||||
define('MYAAC_OS', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? 'WINDOWS' : (strtoupper(PHP_OS) == 'DARWIN' ? 'MAC' : 'LINUX'));
|
||||
|
@ -155,9 +155,9 @@ define('PAGE', $page);
|
||||
$template_place_holders = array();
|
||||
|
||||
require_once(SYSTEM . 'init.php');
|
||||
require_once(SYSTEM . 'template.php');
|
||||
require_once(SYSTEM . 'login.php');
|
||||
require_once(SYSTEM . 'status.php');
|
||||
require_once(SYSTEM . 'template.php');
|
||||
|
||||
$twig->addGlobal('config', $config);
|
||||
$twig->addGlobal('status', $status);
|
||||
|
@ -140,20 +140,19 @@ CREATE TABLE `myaac_items`
|
||||
|
||||
CREATE TABLE `myaac_monsters` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`hide_creature` tinyint(1) NOT NULL default '0',
|
||||
`hidden` tinyint(1) NOT NULL default 0,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`mana` int(11) NOT NULL,
|
||||
`mana` int(11) NOT NULL DEFAULT 0,
|
||||
`exp` int(11) NOT NULL,
|
||||
`health` int(11) NOT NULL,
|
||||
`speed_lvl` int(11) NOT NULL default '1',
|
||||
`speed_lvl` int(11) NOT NULL default 1,
|
||||
`use_haste` tinyint(1) NOT NULL,
|
||||
`voices` text NOT NULL,
|
||||
`immunities` varchar(255) NOT NULL,
|
||||
`summonable` tinyint(1) NOT NULL,
|
||||
`convinceable` tinyint(1) NOT NULL,
|
||||
`race` varchar(255) NOT NULL,
|
||||
`gfx_name` varchar(255) NOT NULL,
|
||||
`file_path` varchar(255) NOT NULL,
|
||||
`loot` varchar(500) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = MyISAM;
|
||||
|
||||
|
@ -117,17 +117,26 @@ function getGuildLink($name, $generate = true)
|
||||
return generateLink($url, $name);
|
||||
}
|
||||
|
||||
function getItemImage($id, $count = 1)
|
||||
{
|
||||
function getItemNameById($id) {
|
||||
global $db;
|
||||
|
||||
$tooltip = '';
|
||||
$query = $db->query('SELECT `name` FROM `' . TABLE_PREFIX . 'items` WHERE `id` = ' . $db->quote($id) . ' LIMIT 1;');
|
||||
if($query->rowCount() == 1) {
|
||||
$item = $query->fetch();
|
||||
$tooltip = ' class="tooltip" title="' . $item['name'] . '"';
|
||||
return $item['name'];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
function getItemImage($id, $count = 1)
|
||||
{
|
||||
$tooltip = '';
|
||||
|
||||
$name = getItemNameById($id);
|
||||
if(!empty($name)) {
|
||||
$tooltip = ' class="tooltip" title="' . $name . '"';
|
||||
}
|
||||
|
||||
$file_name = $id;
|
||||
if($count > 1)
|
||||
$file_name .= '-' . $count;
|
||||
|
@ -33,6 +33,12 @@ class Creatures {
|
||||
return false;
|
||||
}
|
||||
|
||||
$items = array();
|
||||
$items_db = $db->query('SELECT `id`, `name` FROM `' . TABLE_PREFIX . 'items`;');
|
||||
foreach($items_db->fetchAll() as $item) {
|
||||
$items[$item['name']] = $item['id'];
|
||||
}
|
||||
|
||||
//$names_added must be an array
|
||||
$names_added[] = '';
|
||||
//add monsters
|
||||
@ -44,10 +50,10 @@ class Creatures {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
//load monster mana needed to summon/convince
|
||||
$mana = $monster->getManaCost();
|
||||
//load monster experience
|
||||
$exp = $monster->getExperience();
|
||||
|
||||
//load monster name
|
||||
$name = $monster->getName();
|
||||
//load monster health
|
||||
@ -67,51 +73,44 @@ class Creatures {
|
||||
$use_haste = 1;
|
||||
}
|
||||
}
|
||||
//load monster flags
|
||||
$flags = $monster->getFlags();
|
||||
//create string with immunities
|
||||
$immunities = $monster->getImmunities();
|
||||
$imu_nr = 0;
|
||||
$imu_count = count($immunities);
|
||||
$immunities_string = '';
|
||||
foreach($immunities as $immunitie) {
|
||||
$immunities_string .= $immunitie;
|
||||
$imu_nr++;
|
||||
if($imu_count != $imu_nr) {
|
||||
$immunities_string .= ", ";
|
||||
}
|
||||
}
|
||||
|
||||
//create string with voices
|
||||
$voices = $monster->getVoices();
|
||||
$voice_nr = 0;
|
||||
$voice_count = count($voices);
|
||||
$voices_string = '';
|
||||
foreach($voices as $voice) {
|
||||
$voices_string .= '"'.$voice.'"';
|
||||
$voice_nr++;
|
||||
if($voice_count != $voice_nr) {
|
||||
$voices_string .= ", ";
|
||||
}
|
||||
}
|
||||
//load race
|
||||
$race = $monster->getRace();
|
||||
//create monster gfx name
|
||||
//$gfx_name = str_replace(" ", "", trim(mb_strtolower($name))).".gif";
|
||||
$gfx_name = trim(mb_strtolower($name)).".gif";
|
||||
//don't add 2 monsters with same name, like Butterfly
|
||||
|
||||
|
||||
//load monster flags
|
||||
$flags = $monster->getFlags();
|
||||
if(!isset($flags['summonable']))
|
||||
$flags['summonable'] = '0';
|
||||
if(!isset($flags['convinceable']))
|
||||
$flags['convinceable'] = '0';
|
||||
|
||||
$loot = $monster->getLoot();
|
||||
foreach($loot as &$item) {
|
||||
if(!Validator::number($item['id'])) {
|
||||
if(isset($items[$item['id']])) {
|
||||
$item['id'] = $items[$item['id']];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!in_array($name, $names_added)) {
|
||||
try {
|
||||
$db->query("INSERT INTO `myaac_monsters` (`hide_creature`, `name`, `mana`, `exp`, `health`, `speed_lvl`, `use_haste`, `voices`, `immunities`, `summonable`, `convinceable`, `race`, `gfx_name`, `file_path`) VALUES (0, " . $db->quote($name) . ", " . $db->quote(empty($mana) ? 0 : $mana) . ", " . $db->quote($exp) . ", " . $db->quote($health) . ", " . $db->quote($speed_lvl) . ", " . $db->quote($use_haste) . ", " . $db->quote($voices_string) . ", " . $db->quote($immunities_string) . ", " . $db->quote($flags['summonable'] > 0 ? 1 : 0) . ", " . $db->quote($flags['convinceable'] > 0 ? 1 : 0) . ", ".$db->quote($race).", ".$db->quote($gfx_name).", " . $db->quote(self::$monstersList->currentFile()) . ")");
|
||||
$db->insert(TABLE_PREFIX . 'monsters', array(
|
||||
'name' => $name,
|
||||
'mana' => empty($mana) ? 0 : $mana,
|
||||
'exp' => $monster->getExperience(),
|
||||
'health' => $health,
|
||||
'speed_lvl' => $speed_lvl,
|
||||
'use_haste' => $use_haste,
|
||||
'voices' => json_encode($monster->getVoices()),
|
||||
'immunities' => json_encode($monster->getImmunities()),
|
||||
'summonable' => $flags['summonable'] > 0 ? 1 : 0,
|
||||
'convinceable' => $flags['convinceable'] > 0 ? 1 : 0,
|
||||
'race' => $race,
|
||||
'loot' => json_encode($loot)
|
||||
));
|
||||
|
||||
if($show) {
|
||||
success("Added: ".$name."<br/>");
|
||||
success('Added: ' . $name . '<br/>');
|
||||
}
|
||||
}
|
||||
catch(PDOException $error) {
|
||||
|
@ -194,7 +194,6 @@ class OTS_Monster extends DOMDocument
|
||||
|
||||
/**
|
||||
* @return array List of item IDs.
|
||||
* @deprecated 0.1.0 Use getItems().
|
||||
*/
|
||||
public function getLoot()
|
||||
{
|
||||
@ -208,13 +207,25 @@ class OTS_Monster extends DOMDocument
|
||||
// adds all items
|
||||
foreach( $element->getElementsByTagName('item') as $item)
|
||||
{
|
||||
$id = $item->getAttribute('id');
|
||||
|
||||
// avoid redundancy
|
||||
if( !in_array($id, $loot) )
|
||||
{
|
||||
$loot[] = $id;
|
||||
$chance = $item->getAttribute('chance');
|
||||
if(empty($chance)) {
|
||||
$chance = $item->getAttribute('chance1');
|
||||
if(empty($chance)) {
|
||||
$chance = 100000;
|
||||
}
|
||||
}
|
||||
|
||||
$count = $item->getAttribute('countmax');
|
||||
if(empty($count)) {
|
||||
$count = 1;
|
||||
}
|
||||
|
||||
$id = $item->getAttribute('id');
|
||||
if(empty($id)) {
|
||||
$id = $item->getAttribute('name');
|
||||
}
|
||||
|
||||
$loot[] = array('id' => $id, 'count' => $count, 'chance' => $chance);
|
||||
}
|
||||
}
|
||||
|
||||
|
18
system/migrations/14.php
Normal file
18
system/migrations/14.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
// change monsters.file_path field to loot
|
||||
if(fieldExist('file_path', TABLE_PREFIX . 'monsters')) {
|
||||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `file_path` `loot` VARCHAR(5000);");
|
||||
}
|
||||
|
||||
// update loot to empty string
|
||||
$db->query("UPDATE `" . TABLE_PREFIX . "monsters` SET `loot` = '';");
|
||||
|
||||
// drop monsters.gfx_name field
|
||||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `gfx_name`;");
|
||||
|
||||
// rename hide_creature to hidden
|
||||
if(fieldExist('hide_creature', TABLE_PREFIX . 'monsters')) {
|
||||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `hide_creature` `hidden` TINYINT(1) NOT NULL DEFAULT 0;");
|
||||
}
|
||||
?>
|
@ -12,62 +12,24 @@
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
$title = "Creatures";
|
||||
|
||||
$rarity = array(
|
||||
'Not Rare' => 7,
|
||||
'Semi Rare' => 2,
|
||||
'Rare' => 0.5,
|
||||
'Very Rare' => 0
|
||||
);
|
||||
|
||||
function addLoot($loot, $level=1)
|
||||
{
|
||||
foreach($loot as $test) {
|
||||
$chance = $test['chance'];
|
||||
if(!$chance)
|
||||
$chance = $test['chance1'];
|
||||
|
||||
printLoot($level, $test['id'], $test['countmax'], $chance);
|
||||
foreach($test as $k => $v)
|
||||
addLoot($v->item, $level + 1);
|
||||
}
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
function printLoot($level, $itemid, $count, $chance)
|
||||
{
|
||||
global $itemList, $rarity, $i;
|
||||
|
||||
$chance /= 1000;
|
||||
if(isset($_GET['lootrate'])) {
|
||||
global $lootRate;
|
||||
$chance *= $lootRate;
|
||||
}
|
||||
|
||||
foreach($rarity as $lootRarity => $percent) {
|
||||
if($chance >= $percent) {
|
||||
if(isset($itemid))
|
||||
echo str_repeat("... ", $level) . '<u>' . ($count ? $count : 1) . '</u> <span style="color: #7878FF; font-weight: bold;">' . $itemList[(int)$itemid] . '</span> ' . $itemid . ' <span style="color: #C45; font-weight: bold;">' . $lootRarity . '</span> (<span style="color: #FF9A9A;">' . $chance . '%</span>)<br />';
|
||||
|
||||
if($i % 6 == 0)
|
||||
{
|
||||
if($i != 0)
|
||||
echo '</td></tr>';
|
||||
echo '<tr bgcolor="'.getStyle(0).'"><td width="100">';
|
||||
}
|
||||
echo getItemImage($itemid);
|
||||
$i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript" src="tools/tipped.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="tools/tipped.css"/>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
Tipped.create('.tooltip');
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
$canEdit = hasFlag(FLAG_CONTENT_MONSTERS) || admin();
|
||||
if(isset($_POST['reload_monsters']) && $canEdit)
|
||||
{
|
||||
require LIBS . 'creatures.php';
|
||||
if(Creatures::loadFromXML(true))
|
||||
if(Creatures::getMonstersList()->hasErrors())
|
||||
if(Creatures::loadFromXML(true)) {
|
||||
if (Creatures::getMonstersList()->hasErrors())
|
||||
error('There were some problems loading your monsters.xml file. Please check system/logs/error.log for more info.');
|
||||
}
|
||||
else {
|
||||
error(Creatures::getLastError());
|
||||
}
|
||||
@ -114,7 +76,7 @@ if(empty($_REQUEST['creature']))
|
||||
$whereandorder = ' ORDER BY name';
|
||||
}
|
||||
//send query to database
|
||||
$monsters = $db->query('SELECT * FROM '.$db->tableName(TABLE_PREFIX . 'monsters').' WHERE hide_creature != 1'.$whereandorder);
|
||||
$monsters = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'monsters` WHERE `hidden` != 1'.$whereandorder);
|
||||
echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['vdarkborder'].'>';
|
||||
if($order == 'name' && !isset($_REQUEST['desc'])) {
|
||||
echo '<TD class="white" width="200"><B><a href="?subtopic=creatures&order=name&desc=1"><font class="white">Name DESC</a></B></TD>';
|
||||
@ -173,7 +135,7 @@ if(empty($_REQUEST['creature']))
|
||||
|
||||
|
||||
$monster_name = stripslashes(trim(ucwords($_REQUEST['creature'])));
|
||||
$monster = $db->query('SELECT * FROM '.$db->tableName(TABLE_PREFIX . 'monsters').' WHERE '.$db->fieldName('hide_creature').' != 1 AND '.$db->fieldName('name').' = '.$db->quote($monster_name).';')->fetch();
|
||||
$monster = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'monsters` WHERE `hidden` != 1 AND `name` = '.$db->quote($monster_name).';')->fetch();
|
||||
if(isset($monster['name']))
|
||||
{
|
||||
$title = $monster['name'] . " - Creatures";
|
||||
@ -209,6 +171,7 @@ if(isset($monster['name']))
|
||||
echo '</TABLE></td><td align=left>
|
||||
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=40%>
|
||||
<tr><td align=left>';
|
||||
$monster['gfx_name'] = trim(mb_strtolower($monster['name'])).".gif";
|
||||
if(!file_exists('images/monsters/'.$monster['gfx_name'])) {
|
||||
$gfx_name = str_replace(" ", "", $monster['gfx_name']);
|
||||
if(file_exists('images/monsters/' . $gfx_name))
|
||||
@ -222,33 +185,59 @@ if(isset($monster['name']))
|
||||
echo '</td></tr>
|
||||
</TABLE></td></tr><tr><td>
|
||||
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>';
|
||||
if(!empty($monster['immunities']))
|
||||
$immunities = json_decode($monster['immunities'], true);
|
||||
if(count($immunities) > 0)
|
||||
{
|
||||
$number_of_rows++;
|
||||
echo '<tr BGCOLOR="'.getStyle($number_of_rows).'"><td width="100"><b>Immunities: </b></td><td width="100%">'.$monster['immunities'].'</td></tr>';
|
||||
echo '<tr BGCOLOR="'.getStyle($number_of_rows).'"><td width="100"><b>Immunities: </b></td><td width="100%">'.implode(', ', $immunities).'</td></tr>';
|
||||
}
|
||||
if(!empty($monster['voices']))
|
||||
|
||||
$voices = json_decode($monster['voices'], true);
|
||||
if(count($voices) > 0)
|
||||
{
|
||||
foreach($voices as &$voice) {
|
||||
$voice = '"' . $voice . '"';
|
||||
}
|
||||
|
||||
$number_of_rows++;
|
||||
echo '<tr BGCOLOR="'.getStyle($number_of_rows).'"><td width="100"><b>Voices: </b></td><td width="100%">'.$monster['voices'].'</td></tr>';
|
||||
echo '<tr BGCOLOR="'.getStyle($number_of_rows).'"><td width="100"><b>Voices: </b></td><td width="100%">'.implode(', ', $voices).'</td></tr>';
|
||||
}
|
||||
echo '</TABLE></td></tr>';
|
||||
|
||||
echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>';
|
||||
$loot = simplexml_load_file($config['data_path'] . 'monster/' . $monster['file_path']);
|
||||
|
||||
$loot = json_decode($monster['loot'], true);
|
||||
if($loot)
|
||||
{
|
||||
if($item = $loot->loot->item)
|
||||
addLoot($item);
|
||||
{
|
||||
echo '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><tr><td style="display: block;">';
|
||||
function sort_by_chance($a, $b)
|
||||
{
|
||||
if($a['chance'] == $b['chance']) {
|
||||
return 0;
|
||||
}
|
||||
return ($a['chance'] > $b['chance']) ? -1 : 1;
|
||||
}
|
||||
|
||||
usort($loot, 'sort_by_chance');
|
||||
|
||||
$i = 0;
|
||||
foreach($loot as $item) {
|
||||
$name = getItemNameById($item['id']);
|
||||
$tooltip = $name . '<br/>Chance: ' . round($item['chance'] / 1000, 2) . '%<br/>Max count: ' . $item['count'];
|
||||
|
||||
echo '<img src="' . $config['item_images_url'] . $item['id'] . '.gif" class="tooltip" title="' . $tooltip . '" width="32" height="32" border="0" alt=" ' .$name . '" />';
|
||||
$i++;
|
||||
}
|
||||
|
||||
echo '</td></tr></TABLE>';
|
||||
}
|
||||
|
||||
echo '</TABLE></td></tr>';
|
||||
echo '</td></tr>';
|
||||
echo '</TABLE>';
|
||||
}
|
||||
else
|
||||
{
|
||||
echo 'Monster with name <b>'.$monster_name.'</b> doesn\'t exist.';
|
||||
echo "Monster with name <b>" . $monster_name . "</b> doesn't exist.";
|
||||
}
|
||||
|
||||
//back button
|
||||
echo $twig->render('creatures.back_button.html.twig');
|
||||
?>
|
||||
|
@ -56,14 +56,16 @@ if($canEdit) {
|
||||
echo $twig->render('error_box.html.twig', array('errors' => $errors));
|
||||
}
|
||||
|
||||
echo $twig->render('gallery.form.html.twig', array(
|
||||
'link' => getLink('gallery/' . ($action == 'edit' ? 'edit' : 'add')),
|
||||
'action' => $action,
|
||||
'id' => isset($id) ? $id : null,
|
||||
'comment' => isset($comment) ? $comment : null,
|
||||
'image' => isset($image) ? $image : null,
|
||||
'author' => isset($author) ? $author : null
|
||||
));
|
||||
if(!isset($_GET['image'])) {
|
||||
echo $twig->render('gallery.form.html.twig', array(
|
||||
'link' => getLink('gallery/' . ($action == 'edit' ? 'edit' : 'add')),
|
||||
'action' => $action,
|
||||
'id' => isset($id) ? $id : null,
|
||||
'comment' => isset($comment) ? $comment : null,
|
||||
'image' => isset($image) ? $image : null,
|
||||
'author' => isset($author) ? $author : null
|
||||
));
|
||||
}
|
||||
}
|
||||
else
|
||||
echo 'You cannot edit/add gallery items as it seems your PHP installation doesnt have GD support enabled. Visit <a href="http://be2.php.net/manual/en/image.installation.php">PHP Manual</a> for more info.';
|
||||
|
@ -20,6 +20,7 @@ if($config['template_allow_change'])
|
||||
if(!preg_match("/[^A-z0-9_\-]/", $template_name)) { // validate template
|
||||
//setcookie('template', $template_name, 0, BASE_DIR . '/', $_SERVER["SERVER_NAME"]);
|
||||
setSession('template', $template_name);
|
||||
header('Location:' . getSession('last_uri'));
|
||||
}
|
||||
else
|
||||
$template_name = $config['template'];
|
||||
|
@ -1,9 +1,9 @@
|
||||
<script type="text/javascript" src="tools/tipped.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="tools/tipped.css"/>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
Tipped.create('.tooltip');
|
||||
});
|
||||
$(document).ready(function() {
|
||||
Tipped.create('.tooltip');
|
||||
});
|
||||
</script>
|
||||
{% set rows = 0 %}
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>
|
||||
|
Loading…
x
Reference in New Issue
Block a user