Core/Cleanup

* try to give included files a logical structure
 * move objects from Util and Game to their own files
 * make non-essential files auto-loaded
This commit is contained in:
Sarjuuk
2025-04-01 19:46:19 +02:00
parent 3a6c86092b
commit db1d3ccace
32 changed files with 1440 additions and 1323 deletions

View File

@@ -19,6 +19,10 @@ define('TDB_WORLD_EXPECTED_VER', 24041);
// https://www.wowhead.com/wotlk/es/search=vuelo
define('WOWHEAD_LINK', 'https://www.wowhead.com/wotlk/%s/%s=%s');
define('LOG_LEVEL_ERROR', 1);
define('LOG_LEVEL_WARN', 2);
define('LOG_LEVEL_INFO', 3);
define('MIME_TYPE_TEXT', 'Content-Type: text/plain; charset=utf-8');
define('MIME_TYPE_XML', 'Content-Type: text/xml; charset=utf-8');
define('MIME_TYPE_JSON', 'Content-Type: application/x-javascript; charset=utf-8');
@@ -387,182 +391,6 @@ define('EXP_CLASSIC', 0);
define('EXP_BC', 1);
define('EXP_WOTLK', 2);
enum ChrClass : int
{
case WARRIOR = 1;
case PALADIN = 2;
case HUNTER = 3;
case ROGUE = 4;
case PRIEST = 5;
case DEATHKNIGHT = 6;
case SHAMAN = 7;
case MAGE = 8;
case WARLOCK = 9;
case DRUID = 11;
public const MASK_ALL = 0x5FF;
public function matches(int $classMask) : bool
{
return !$classMask || $this->value & $classMask;
}
public function toMask() : int
{
return 1 << ($this->value - 1);
}
public static function fromMask(int $classMask = self::MASK_ALL) : array
{
$x = [];
foreach (self::cases() as $cl)
if ($cl->toMask() & $classMask)
$x[] = $cl->value;
return $x;
}
public function json() : string
{
return match ($this)
{
self::WARRIOR => 'warrior',
self::PALADIN => 'paladin',
self::HUNTER => 'hunter',
self::ROGUE => 'rogue',
self::PRIEST => 'priest',
self::DEATHKNIGHT => 'deathknight',
self::SHAMAN => 'shaman',
self::MAGE => 'mage',
self::WARLOCK => 'warlock',
self::DRUID => 'druid'
};
}
}
enum ChrRace : int
{
case HUMAN = 1;
case ORC = 2;
case DWARF = 3;
case NIGHTELF = 4;
case UNDEAD = 5;
case TAUREN = 6;
case GNOME = 7;
case TROLL = 8;
case BLOODELF = 10;
case DRAENEI = 11;
public const MASK_ALLIANCE = 0x44D;
public const MASK_HORDE = 0x2B2;
public const MASK_ALL = 0x6FF;
public function matches(int $raceMask) : bool
{
return !$raceMask || $this->value & $raceMask;
}
public function toMask() : int
{
return 1 << ($this->value - 1);
}
public function isAlliance() : bool
{
return $this->toMask() & self::MASK_ALLIANCE;
}
public function isHorde() : bool
{
return $this->toMask() & self::MASK_HORDE;
}
public function getSide() : int
{
if ($this->isHorde() && $this->isAlliance())
return SIDE_BOTH;
else if ($this->isHorde())
return SIDE_HORDE;
else if ($this->isAlliance())
return SIDE_ALLIANCE;
else
return SIDE_NONE;
}
public function getTeam() : int
{
if ($this->isHorde() && $this->isAlliance())
return TEAM_NEUTRAL;
else if ($this->isHorde())
return TEAM_HORDE;
else if ($this->isAlliance())
return TEAM_ALLIANCE;
else
return TEAM_NEUTRAL;
}
public function json() : string
{
return match ($this)
{
self::HUMAN => 'human',
self::ORC => 'orc',
self::DWARF => 'dwarf',
self::NIGHTELF => 'nightelf',
self::UNDEAD => 'undead',
self::TAUREN => 'tauren',
self::GNOME => 'gnome',
self::TROLL => 'troll',
self::BLOODELF => 'bloodelf',
self::DRAENEI => 'draenei'
};
}
public static function fromMask(int $raceMask = self::MASK_ALL) : array
{
$x = [];
foreach (self::cases() as $cl)
if ($cl->toMask() & $raceMask)
$x[] = $cl->value;
return $x;
}
public static function sideFromMask(int $raceMask) : int
{
// Any
if (!$raceMask || ($raceMask & self::MASK_ALL) == self::MASK_ALL)
return SIDE_BOTH;
// Horde
if ($raceMask & self::MASK_HORDE && !($raceMask & self::MASK_ALLIANCE))
return SIDE_HORDE;
// Alliance
if ($raceMask & self::MASK_ALLIANCE && !($raceMask & self::MASK_HORDE))
return SIDE_ALLIANCE;
return SIDE_BOTH;
}
public static function teamFromMask(int $raceMask) : int
{
// Any
if (!$raceMask || ($raceMask & self::MASK_ALL) == self::MASK_ALL)
return TEAM_NEUTRAL;
// Horde
if ($raceMask & self::MASK_HORDE && !($raceMask & self::MASK_ALLIANCE))
return TEAM_HORDE;
// Alliance
if ($raceMask & self::MASK_ALLIANCE && !($raceMask & self::MASK_HORDE))
return TEAM_ALLIANCE;
return TEAM_NEUTRAL;
}
}
// SpellFamilyNames
define('SPELLFAMILY_GENERIC', 0);
define('SPELLFAMILY_UNK1', 1); // events, holidays