* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package SWDB */ require_once(PATH::HELPER . "Helper.php"); /** * Application helper. * * Contains app-related utilities. * * @category Helper. */ final class APPLICATION extends Helper{ /** * Checks if a value is a valid one in a constant class. * * It will intentionally fail when used for a non constant class. * * @param string $class Name of the class. * @param int $value Value to check. * @return bool True if the value is defined, false otherwise. */ public static function valid_id($class, $value){ if (strtoupper($class) != $class){ return false; } if (!class_exists($class, false)){ return false; } $reflect = new ReflectionClass($class); if (in_array($value, $reflect->getConstants())){ return true; } else{ return false; } } /** * Forms an image URL. * * It will intentionally fail when used for a non constant class. * * @param string $type Image type. valid values are: * ICON, LOGO, CURRENCY, UNIT, * AREA, SKILL, ESSENCE, RUNE, * GRIND, ELEMENT, SKILL_GUILD, DECORATION, * SOURCE, SKILL_LEADER, INVENTORY, EFFECT, * BUILDING * @param string|int $name Filename, with no path or extension. It can also * skip the padding. An id can be used. * @return string URL if found. If not, the URL to an 'unknown' icon. */ public static function img($type, $name){ $pad = 1; $url = URL::IMG["UNKNOWN"]; while ($pad < 10){ if (isset(PATH::IMG[$type]) && file_exists(PATH::IMG[$type] . str_pad($name, $pad, '0', STR_PAD_LEFT) . ".png")){ $url = URL::IMG[$type] . str_pad($name, $pad, '0', STR_PAD_LEFT) . ".png"; break; } $pad ++; } return $url; } /** * Calculates the effective damage. * * @param int $atk Attack stat. * @param int $crr Critical rate stat. * @param int $crd Critical damage stat. * @return int Damage stat. */ public static function calculate_dmg($atk, $crr, $crd){ if (! is_numeric($atk) || ! is_numeric($crr) || ! is_numeric($crd)){ return 0; } if ($crr > 100){ $crr = 100; } $edmg = ceil(($atk * (100 - $crr) / 100) + (($atk + ($atk * $crd / 100)) * $crr / 100)); return $edmg; } /** * Calculates the effective HP of a unit. * @param int $hp HP stat * @param int $def Defense stat. * @return int Effective HP. */ public static function calculate_ehp($hp, $def){ $ehp = ceil(((($def * 3.5) + 1140) * $hp) / 1000); return $ehp; } }