diff --git a/system/libs/creatures.php b/system/libs/creatures.php
index 8e7d77fa..97f9bb92 100644
--- a/system/libs/creatures.php
+++ b/system/libs/creatures.php
@@ -11,33 +11,33 @@
defined('MYAAC') or die('Direct access not allowed!');
class Creatures {
- private static $monstersList = null;
+ private static $monstersList;
private static $lastError = '';
-
+
public static function loadFromXML($show = false) {
- global $config, $db;
-
- try { $db->query("DELETE FROM `myaac_monsters`;"); } catch(PDOException $error) {}
-
+ global $db;
+
+ try { $db->exec('DELETE FROM `' . TABLE_PREFIX . 'monsters`;'); } catch(PDOException $error) {}
+
if($show) {
echo '
Reload monsters.
';
- echo "All records deleted from table 'myaac_monsters' in database.
";
+ echo "All records deleted from table '" . TABLE_PREFIX . "monsters' in database.
";
}
-
+
try {
- self::$monstersList = new OTS_MonstersList($config['data_path'].'monster/');
+ self::$monstersList = new OTS_MonstersList(config('data_path') . 'monster/');
}
catch(Exception $e) {
self::$lastError = $e->getMessage();
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'];
+ Items::load();
+ foreach((array)Items::$items as $id => $item) {
+ $items[$item['name']] = $id;
}
-
+
//$names_added must be an array
$names_added[] = '';
//add monsters
@@ -49,7 +49,7 @@ class Creatures {
}
continue;
}
-
+
//load monster mana needed to summon/convince
$mana = $monster->getManaCost();
@@ -72,7 +72,7 @@ class Creatures {
$use_haste = 1;
}
}
-
+
//load race
$race = $monster->getRace();
@@ -82,7 +82,7 @@ class Creatures {
$flags['summonable'] = '0';
if(!isset($flags['convinceable']))
$flags['convinceable'] = '0';
-
+
$loot = $monster->getLoot();
foreach($loot as &$item) {
if(!Validator::number($item['id'])) {
@@ -107,7 +107,7 @@ class Creatures {
'race' => $race,
'loot' => json_encode($loot)
));
-
+
if($show) {
success('Added: ' . $name . '
');
}
@@ -117,18 +117,18 @@ class Creatures {
warning('Error while adding monster (' . $name . '): ' . $error->getMessage());
}
}
-
+
$names_added[] = $name;
}
}
-
+
return true;
}
-
+
public static function getMonstersList() {
return self::$monstersList;
}
-
+
public static function getLastError() {
return self::$lastError;
}
diff --git a/system/libs/items.php b/system/libs/items.php
index 6820a0fc..de7ae890 100644
--- a/system/libs/items.php
+++ b/system/libs/items.php
@@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!');
class Items
{
private static $error = '';
- private static $items;
+ public static $items;
public static function loadFromXML($show = false)
{
@@ -22,10 +22,10 @@ class Items
self::$error = 'Cannot load file ' . $file_path;
return false;
}
-
+
$xml = new DOMDocument;
$xml->load($file_path);
-
+
$items = array();
foreach ($xml->getElementsByTagName('item') as $item) {
if ($item->getAttribute('fromid')) {
@@ -36,52 +36,52 @@ class Items
} else {
$tmp = self::parseNode($item->getAttribute('id'), $item, $show);
$items[$tmp['id']] = $tmp['content'];
- }
+ }
}
-
+
require_once LIBS . 'cache_php.php';
$cache_php = new Cache_PHP(config('cache_prefix'), CACHE);
$cache_php->set('items', $items);
return true;
}
-
+
public static function parseNode($id, $node, $show = false) {
$name = $node->getAttribute('name');
$article = $node->getAttribute('article');
$plural = $node->getAttribute('plural');
-
+
$attributes = array();
foreach($node->getElementsByTagName('attribute') as $attr) {
$attributes[strtolower($attr->getAttribute('key'))] = $attr->getAttribute('value');
}
-
+
return array('id' => $id, 'content' => array('article' => $article, 'name' => $name, 'plural' => $plural, 'attributes' => $attributes));
}
-
+
public static function getError() {
return self::$error;
}
-
- public static function loadItems() {
+
+ public static function load() {
if(self::$items) {
return;
}
-
+
require_once LIBS . 'cache_php.php';
$cache_php = new Cache_PHP(config('cache_prefix'), CACHE);
self::$items = $cache_php->get('items');
}
-
- public static function getItem($id) {
- self::loadItems();
+
+ public static function get($id) {
+ self::load();
return self::$items[$id];
}
-
+
public static function getDescription($id, $count = 1) {
global $db;
-
- $item = self::getItem($id);
-
+
+ $item = self::get($id);
+
$attr = $item['attributes'];
$s = '';
if(!empty($item['name'])) {
@@ -89,7 +89,7 @@ class Items
if($attr['showcount']) {
$s .= $count . ' ';
}
-
+
if(!empty($item['plural'])) {
$s .= $item['plural'];
}
@@ -104,22 +104,22 @@ class Items
if(!empty($item['aticle'])) {
$s .= $item['article'] . ' ';
}
-
+
$s .= $item['name'];
}
}
else
$s .= 'an item of type ' . $item['id'];
-
+
if(isset($attr['type']) && strtolower($attr['type']) == 'rune') {
$query = $db->query('SELECT `level`, `maglevel`, `vocations` FROM `' . TABLE_PREFIX . 'spells` WHERE `item_id` = ' . $id);
if($query->rowCount() == 1) {
$query = $query->fetch();
-
+
if($query['level'] > 0 && $query['maglevel'] > 0) {
$s .= '. ' . ($count > 1 ? "They" : "It") . ' can only be used by ';
}
-
+
$configVocations = config('vocations');
if(!empty(trim($query['vocations']))) {
$vocations = json_decode($query['vocations']);
@@ -132,9 +132,9 @@ class Items
else {
$s .= 'players';
}
-
+
$s .= ' with';
-
+
}
}
return $s;