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; } } ?>