Rename creatures to monsters

This commit is contained in:
slawkens 2024-02-03 20:54:09 +01:00
parent 3f5744964a
commit ccfd2b4f55
13 changed files with 170 additions and 165 deletions

View File

@ -57,7 +57,7 @@ Minimum PHP version for this release is 8.1.
* Highscores
* frags works for TFS 1.x
* cached
* creatures
* Monsters
* moved pages to Twig:
* experience stages
* update player_deaths entries on name change

View File

@ -74,4 +74,7 @@ function fieldExist($field, $table)
global $db;
return $db->hasColumn($table, $field);
}
?>
function getCreatureImgPath($creature): string {
return getMonsterImgPath($creature);
}

View File

@ -105,7 +105,7 @@ function getPlayerLink($name, $generate = true): string
function getMonsterLink($name, $generate = true): string
{
$url = BASE_URL . (setting('core.friendly_urls') ? '' : 'index.php/') . 'creatures/' . urlencode($name);
$url = BASE_URL . (setting('core.friendly_urls') ? '' : 'index.php/') . 'monsters/' . urlencode($name);
if(!$generate) return $url;
return generateLink($url, $name);
@ -1559,18 +1559,19 @@ function right($str, $length) {
return substr($str, -$length);
}
function getCreatureImgPath($creature){
$creature_path = setting('core.monsters_images_url');
$creature_gfx_name = trim(strtolower($creature)) . setting('core.monsters_images_extension');
if (!file_exists($creature_path . $creature_gfx_name)) {
$creature_gfx_name = str_replace(" ", "", $creature_gfx_name);
if (file_exists($creature_path . $creature_gfx_name)) {
return $creature_path . $creature_gfx_name;
function getMonsterImgPath($monster): string
{
$monster_path = setting('core.monsters_images_url');
$monster_gfx_name = trim(strtolower($monster)) . setting('core.monsters_images_extension');
if (!file_exists($monster_path . $monster_gfx_name)) {
$monster_gfx_name = str_replace(" ", "", $monster_gfx_name);
if (file_exists($monster_path . $monster_gfx_name)) {
return $monster_path . $monster_gfx_name;
} else {
return $creature_path . 'nophoto.png';
return $monster_path . 'nophoto.png';
}
} else {
return $creature_path . $creature_gfx_name;
return $monster_path . $monster_gfx_name;
}
}

View File

@ -9,3 +9,4 @@ Menu::where('link', 'lastkills')->update(['link' => 'last-kills']);
Menu::where('link', 'serverInfo')->update(['link' => 'server-info']);
Menu::where('link', 'experienceStages')->update(['link' => 'exp-stages']);
Menu::where('link', 'experienceTable')->update(['link' => 'exp-table']);
Menu::where('link', 'creatures')->update(['link' => 'monsters']);

View File

@ -1,86 +0,0 @@
<?php
/**
* Creatures
*
* @package MyAAC
* @author Gesior <jerzyskalski@wp.pl>
* @author Slawkens <slawkens@gmail.com>
* @author Lee
* @copyright 2020 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Monster;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Creatures';
if (empty($_REQUEST['name'])) {
// display list of monsters
$preview = setting('core.monsters_images_preview');
$creatures = Monster::where('hide', '!=', 1)->when(!empty($_REQUEST['boss']), function ($query) {
$query->where('rewardboss', 1);
})->get()->toArray();
if ($preview) {
foreach($creatures as $key => &$creature)
{
$creature['img_link'] = getCreatureImgPath($creature['name']);
}
}
$twig->display('creatures.html.twig', array(
'creatures' => $creatures,
'preview' => $preview
));
return;
}
// display monster
$creature_name = urldecode(stripslashes(ucwords(strtolower($_REQUEST['name']))));
$creature = Monster::where('hide', '!=', 1)->where('name', $creature_name)->first()->toArray();
if (isset($creature['name'])) {
function sort_by_chance($a, $b)
{
if ($a['chance'] == $b['chance']) {
return 0;
}
return ($a['chance'] > $b['chance']) ? -1 : 1;
}
$title = $creature['name'] . " - Creatures";
$creature['img_link']= getCreatureImgPath($creature_name);
$voices = json_decode($creature['voices'], true);
$summons = json_decode($creature['summons'], true);
$elements = json_decode($creature['elements'], true);
$immunities = json_decode($creature['immunities'], true);
$loot = json_decode($creature['loot'], true);
usort($loot, 'sort_by_chance');
foreach ($loot as &$item) {
$item['name'] = getItemNameById($item['id']);
$item['rarity_chance'] = round($item['chance'] / 1000, 2);
$item['rarity'] = getItemRarity($item['chance']);
$item['tooltip'] = ucfirst($item['name']) . '<br/>Chance: ' . $item['rarity'] . (setting('core.monsters_loot_percentage') ? ' ('. $item['rarity_chance'] .'%)' : '') . '<br/>Max count: ' . $item['count'];
}
$creature['loot'] = isset($loot) ? $loot : null;
$creature['voices'] = isset($voices) ? $voices : null;
$creature['summons'] = isset($summons) ? $summons : null;
$creature['elements'] = isset($elements) ? $elements : null;
$creature['immunities'] = isset($immunities) ? $immunities : null;
$twig->display('creature.html.twig', array(
'creature' => $creature,
));
} else {
echo "Creature with name <b>" . $creature_name . "</b> doesn't exist.";
}
// back button
$twig->display('creatures.back_button.html.twig');

86
system/pages/monsters.php Normal file
View File

@ -0,0 +1,86 @@
<?php
/**
* Monsters
*
* @package MyAAC
* @author Gesior <jerzyskalski@wp.pl>
* @author Slawkens <slawkens@gmail.com>
* @author Lee
* @copyright 2020 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Monster;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Monsters';
if (empty($_REQUEST['name'])) {
// display list of monsters
$preview = setting('core.monsters_images_preview');
$monsters = Monster::where('hide', '!=', 1)->when(!empty($_REQUEST['boss']), function ($query) {
$query->where('rewardboss', 1);
})->get()->toArray();
if ($preview) {
foreach($monsters as $key => &$monster)
{
$monster['img_link'] = getMonsterImgPath($monster['name']);
}
}
$twig->display('monsters.html.twig', array(
'monsters' => $monsters,
'preview' => $preview
));
return;
}
// display monster
$monster_name = urldecode(stripslashes(ucwords(strtolower($_REQUEST['name']))));
$monster = Monster::where('hide', '!=', 1)->where('name', $monster_name)->first()->toArray();
if (isset($monster['name'])) {
function sort_by_chance($a, $b)
{
if ($a['chance'] == $b['chance']) {
return 0;
}
return ($a['chance'] > $b['chance']) ? -1 : 1;
}
$title = $monster['name'] . " - Monsters";
$monster['img_link']= getMonsterImgPath($monster_name);
$voices = json_decode($monster['voices'], true);
$summons = json_decode($monster['summons'], true);
$elements = json_decode($monster['elements'], true);
$immunities = json_decode($monster['immunities'], true);
$loot = json_decode($monster['loot'], true);
usort($loot, 'sort_by_chance');
foreach ($loot as &$item) {
$item['name'] = getItemNameById($item['id']);
$item['rarity_chance'] = round($item['chance'] / 1000, 2);
$item['rarity'] = getItemRarity($item['chance']);
$item['tooltip'] = ucfirst($item['name']) . '<br/>Chance: ' . $item['rarity'] . (setting('core.monsters_loot_percentage') ? ' ('. $item['rarity_chance'] .'%)' : '') . '<br/>Max count: ' . $item['count'];
}
$monster['loot'] = $loot ?? null;
$monster['voices'] = $voices ?? null;
$monster['summons'] = $summons ?? null;
$monster['elements'] = $elements ?? null;
$monster['immunities'] = $immunities ?? null;
$twig->display('monster.html.twig', array(
'monster' => $monster,
));
} else {
echo "Monster with name <b>" . $monster_name . "</b> doesn't exist.";
}
// back button
$twig->display('monsters.back_button.html.twig');

View File

@ -33,7 +33,7 @@ return [
['GET', 'bans/{page:int}[/]', 'bans.php'],
[['GET', 'POST'], 'characters[/{name:string}]', 'characters.php'],
['GET', 'changelog[/{page:int}]', 'changelog.php'],
[['GET', 'POST'], 'creatures[/{name:string}]', 'creatures.php'],
[['GET', 'POST'], 'monsters[/{name:string}]', 'monsters.php'],
[['GET', 'POST'], 'faq[/{action:string}]', 'faq.php'],

View File

@ -46,16 +46,16 @@ class DataLoader
self::$startTime = microtime(true);
if(Creatures::loadFromXML()) {
if(Monsters::loadFromXML()) {
success(self::$locale['step_database_loaded_monsters'] . self::getLoadedTime());
if(Creatures::getMonstersList()->hasErrors()) {
if(Monsters::getMonstersList()->hasErrors()) {
self::$locale['step_database_error_monsters'] = str_replace('$LOG$', 'system/logs/error.log', self::$locale['step_database_error_monsters']);
warning(self::$locale['step_database_error_monsters']);
}
}
else {
error(Creatures::getLastError());
error(Monsters::getLastError());
}
self::$startTime = microtime(true);

View File

@ -13,7 +13,7 @@ namespace MyAAC;
use MyAAC\Models\Monster;
class Creatures {
class Monsters {
/**
* @var \OTS_MonstersList
*/

View File

@ -114,7 +114,7 @@ $template['link_account_logout'] = getLink('account/logout');
$template['link_news_archive'] = getLink('news/archive');
$links = array('news', 'changelog', 'rules', 'downloads', 'characters', 'online', 'highscores', 'powergamers', 'lastkills' => 'last-kills', 'houses', 'guilds', 'wars', 'polls', 'bans', 'team', 'creatures', 'spells', 'commands', 'exp-stages', 'freeHouses', 'serverInfo', 'exp-table', 'faq', 'points', 'gifts', 'bugtracker', 'gallery');
$links = array('news', 'changelog', 'rules', 'downloads', 'characters', 'online', 'highscores', 'powergamers', 'lastkills' => 'last-kills', 'houses', 'guilds', 'wars', 'polls', 'bans', 'team', 'creatures' => 'monsters', 'monsters', 'spells', 'commands', 'exp-stages', 'freeHouses', 'serverInfo', 'exp-table', 'faq', 'points', 'gifts', 'bugtracker', 'gallery');
foreach($links as $key => $value) {
$key = is_string($key) ? $key : $value;
$template['link_' . $key] = getLink($value);

View File

@ -1,7 +1,7 @@
<script type="text/javascript" src="tools/js/tipped.js"></script>
<link rel="stylesheet" type="text/css" href="tools/css/tipped.css"/>
<style>
.creature_img {
.monster_img {
background-position: center center;
background-repeat: no-repeat;
width: 64px;
@ -9,7 +9,7 @@
padding: 5px;
}
.creature_name {
.monster_name {
font-size: 18px;
font-weight: bold;
width: 100%;
@ -20,7 +20,7 @@
padding-bottom: 15px;
}
.creature_voice {
.monster_voice {
font-weight: bold;
font-size: 8pt;
color: #FE6500;
@ -63,8 +63,8 @@
});
</script>
<div class="creature_name">{{ creature.name }}</div>
<table class="CreatureInfo" border="0" cellspacing="0" cellpadding="4" width="100%">
<div class="monster_name">{{ monster.name }}</div>
<table class="MonsterInfo" border="0" cellspacing="0" cellpadding="4" width="100%">
<thead>
<tr>
<th align="center" colspan="4"><b>General information</b></th>
@ -73,50 +73,50 @@
<tbody>
<tr>
<td width="10%">
<div class="creature_img" style="background-image: url({{ creature.img_link }}"></div>
<div class="monster_img" style="background-image: url({{ monster.img_link }}"></div>
</td>
<td align="center" width="30%">
<strong>Health:</strong> {{ creature.health }}<br>
<strong>Experience:</strong> {{ creature.exp }}<br>
<strong>Speed:</strong> {{ creature.speed_lvl }} {{ (creature.use_haste) ? ' (+haste)' : '' }}
<strong>Health:</strong> {{ monster.health }}<br>
<strong>Experience:</strong> {{ monster.exp }}<br>
<strong>Speed:</strong> {{ monster.speed_lvl }} {{ (monster.use_haste) ? ' (+haste)' : '' }}
</td>
<td align="center" width="30%">
<b>Summonable:</b> {{ (creature.summonable) ? creature.mana ~ ' mana' : 'Impossible' }}<br>
<b>Convinceable:</b> {{ (creature.convinceable) ? creature.mana ~ ' mana' : 'Impossible' }}
<b>Summonable:</b> {{ (monster.summonable) ? monster.mana ~ ' mana' : 'Impossible' }}<br>
<b>Convinceable:</b> {{ (monster.convinceable) ? monster.mana ~ ' mana' : 'Impossible' }}
</td>
<td width="30%" align="center">
<strong>Armor:</strong> {{ creature.armor }}<br>
<strong>Defense:</strong> {{ creature.defense }}
<strong>Armor:</strong> {{ monster.armor }}<br>
<strong>Defense:</strong> {{ monster.defense }}
</td>
</tr>
</tbody>
</table><br>
{% if ( creature.voices is not empty or creature.summons is not empty) %}
<table class="CreatureVoice" border="0" cellspacing="0" cellpadding="4" width="100%">
{% if ( monster.voices is not empty or monster.summons is not empty) %}
<table class="MonsterVoice" border="0" cellspacing="0" cellpadding="4" width="100%">
<thead>
<tr>
{% if ( creature.summons is not empty) %}
{% if ( monster.summons is not empty) %}
<th width="50%"><b>Summons</b></th>
{% endif %}
{% if ( creature.voices is not empty) %}
{% if ( monster.voices is not empty) %}
<th width="50%"><b>Voices</b></th>
{% endif %}
</tr>
</thead>
<tbody>
<tr>
{% if ( creature.summons is not empty) %}
{% if ( monster.summons is not empty) %}
<td>
{% for summon in creature.summons %}
{% for summon in monster.summons %}
<span>{{ summon.chance }}% chance to summon a <b>{{ getMonsterLink(summon.name, true)|raw }}</b><br/></span>
{% endfor %}
</td>
{% endif %}
{% if ( creature.voices is not empty) %}
{% if ( monster.voices is not empty) %}
<td align="center">
<span class="creature_voice">
{% for voice in creature.voices %}
<span class="monster_voice">
{% for voice in monster.voices %}
"{{ voice }}"<br/>
{% endfor %}
</span>
@ -127,30 +127,30 @@
</table><br/>
{% endif %}
{% if (creature.elements|length > 0 or creature.immunities|length > 0 ) %}
<table class="CreatureElements" border="0" cellspacing="0" cellpadding="4" width="100%">
{% if (monster.elements|length > 0 or monster.immunities|length > 0 ) %}
<table class="MonsterElements" border="0" cellspacing="0" cellpadding="4" width="100%">
<tr>
<th colspan="{{ creature.elements|length }}">Elements and Immunities</th>
<th colspan="{{ monster.elements|length }}">Elements and Immunities</th>
</tr>
{% if (creature.elements|length > 0) %}
<tr>{% for element in creature.elements %}
{% if (monster.elements|length > 0) %}
<tr>{% for element in monster.elements %}
<td align="center"><b> {{ element.name }}</b><br/>{{ element.percent }}%</td>
{% endfor %}</tr>
{% endif %}
{% if (creature.immunities|length > 0 ) %}
{% if (monster.immunities|length > 0 ) %}
<tr>
<td colspan="{{ creature.elements|length }}"><b>Immunities:</b> {{ creature.immunities|join(' | ') }}</td>
<td colspan="{{ monster.elements|length }}"><b>Immunities:</b> {{ monster.immunities|join(' | ') }}</td>
</tr>
{% endif %}
</table><br/>
{% endif %}
{% if (not creature.loot is empty) %}
<table class="CreatureLoot" border="0" cellspacing="0" cellpadding="4" width="100%">
{% if (not monster.loot is empty) %}
<table class="MonsterLoot" border="0" cellspacing="0" cellpadding="4" width="100%">
<tr><th>Loot</th></tr>
<tr>
<td>
{% for item in creature.loot %}
{% for item in monster.loot %}
<span class="loot_bg">
{% if (item.count > 1) %}
<span class="loot_amount">{{ item.count }}</span>

View File

@ -1,6 +1,6 @@
<br/></br>
<br/><br/>
<div style="text-align:center">
<form action="{{ getLink('creatures') }}" method="post">
<form action="{{ getLink('monsters') }}" method="post">
{{ include('buttons.back.html.twig') }}
</form>
</div>
</div>

View File

@ -1,15 +1,15 @@
{% if creatures is not empty %}
{% if monsters is not empty %}
{% if preview %}
<style>
.creatureImages {
.monsterImages {
width: 100px;
height: 100px;
margin: 0px;
float: left;
}
.creatureBoss {
.monsterBoss {
box-sizing: border-box;
border-radius: 10px;
border: 1px rgba(179, 179, 179, 0.50) solid;
@ -20,7 +20,7 @@
$(document).ready(function () {
$("#ciSearch").on("keyup", function () {
var value = $(this).val().toLowerCase();
$("#creatureiTable div").filter(function () {
$("#monsteriTable div").filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
@ -28,15 +28,15 @@
</script>
<div style="float: right;"><input id="ciSearch" type="text" placeholder="Search.."></div>
<div style="display: table; width: 100%; ">
<div style="text-align: center; " id="creatureiTable">
{% for creature in creatures %}
<div style="text-align: center; " id="monsteriTable">
{% for monster in monsters %}
{% set i = i + 1 %}
<div class="creatureImages">
<a href="{{ getMonsterLink(creature.name, false)|raw }}">
<div class="creature_img " style="background-image: url({{ creature.img_link }}"></div>
<img class=" {{ (creature.rewardboss ? 'creatureBoss' : '') }}" src="{{ creature.img_link }}" border="0"/>
<div class="monsterImages">
<a href="{{ getMonsterLink(monster.name, false)|raw }}">
<div class="monster_img " style="background-image: url({{ monster.img_link }}"></div>
<img class=" {{ (monster.rewardboss ? 'monsterBoss' : '') }}" src="{{ monster.img_link }}" border="0"/>
</a>
<div>{{ creature.name }}</div>
<div>{{ monster.name }}</div>
</div>
{% endfor %}
</div>
@ -46,14 +46,14 @@
$(document).ready(function () {
$("#cSearch").on("keyup", function () {
var value = $(this).val().toLowerCase();
$("#creatureTable tr").filter(function () {
$("#monsterTable tr").filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
{{ generateLink(getLink('creatures'), 'All', false)|raw }} - <a href="?subtopic=creatures&boss=view">Bosses</a>
<table width="100%" id="creaturestb">
{{ generateLink(getLink('monsters'), 'All', false)|raw }} - <a href="{{ getLink('monsters') }}?boss=view">Bosses</a>
<table width="100%" id="monsters_datatable">
<thead>
<tr>
<th>Name</th>
@ -65,18 +65,18 @@
<th>Race</th>
</tr>
</thead>
<tbody id="creatureTable">
<tbody id="monsterTable">
{% set i = 0 %}
{% for creature in creatures %}
{% for monster in monsters %}
{% set i = i + 1 %}
<tr>
<td>{{ getMonsterLink(creature.name, true)|raw }}</td>
<td>{{ (creature.rewardboss) ? 'Yes' : '---' }}</td>
<td>{{ creature.health|number_format(0, '.', ',') }}</td>
<td>{{ creature.exp|number_format(0, '.', ',') }}</td>
<td>{{ (creature.convinceable) ? creature.mana : '---' }} </td>
<td>{{ (creature.summonable) ? creature.mana : '---' }} </td>
<td>{{ creature.race|title }}</td>
<td>{{ getMonsterLink(monster.name, true)|raw }}</td>
<td>{{ (monster.rewardboss) ? 'Yes' : '---' }}</td>
<td>{{ monster.health|number_format(0, '.', ',') }}</td>
<td>{{ monster.exp|number_format(0, '.', ',') }}</td>
<td>{{ (monster.convinceable) ? monster.mana : '---' }} </td>
<td>{{ (monster.summonable) ? monster.mana : '---' }} </td>
<td>{{ monster.race|title }}</td>
</tr>
{% endfor %}
</tbody>
@ -84,7 +84,7 @@
{% endif %}
<script>
$(document).ready(function () {
$('#creaturestb').DataTable();
$('#monsters_datatable').DataTable();
});
</script>
@ -94,10 +94,10 @@
{% else %}
<table width="100%">
<tr>
<th>Creatures</th>
<th>Monsters</th>
</tr>
<tr>
<td>No Creatures on the server.</td>
<td>No Monsters on the server.</td>
</tr>
</table>
{% endif %}