* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package SWDB */ require_once(PATH::HELPER . "Helper.php"); require_once(PATH::ENTITY . "Unit.php"); require_once(PATH::ENTITY . "Monster.php"); require_once(PATH::ENTITY . "Building.php"); require_once(PATH::ENTITY . "Buildable.php"); require_once(PATH::ENTITY . "Decoration.php"); require_once(PATH::ENTITY . "Decorative.php"); require_once(PATH::ENTITY . "Rune.php"); require_once(PATH::ENTITY . "Artifact.php"); require_once(PATH::ENTITY . "Enchantment.php"); require_once(PATH::ENTITY . "Item.php"); /** * HTML helper. * * Contains utilities to parse and format HTML and to build elements. * * @category Helper. */ final class HTML extends Helper{ /** * Escapes HTML characters * * Alias for htmlspecialchars([input], ENT_QUOTES) * * @param string $input Text to escape. * @return string Escaped text. */ public static function e($input){ return htmlspecialchars($input, ENT_QUOTES); } /** * Generates a unit panel. * * @param Unit|Monster Entity to get the info from. * @return string HTML content for a monster panel. Empty on error. */ public static function unit_panel($unit) { if ($unit instanceof Unit){ $k = $unit->get_monster(); $stars = $unit->get_stars(); $level = true; $teams = (sizeof($unit->get_teams()) > 0); $lock = $unit->is_locked(); $storage = $unit->is_in_storage(); $maxed = ($unit->get_level() == 40 && $unit->is_fully_skilled()); } elseif ($unit instanceof Monster){ $k = $unit; $stars = $unit->get_base_stars(); $level = false; $teams = 0; $lock = false; $storage = false; $maxed = false; } else{ return ""; } $html = ""; if ($k->get_awakens_from() == null && $k->get_awakens_to() == null){ // No to, no from if ($k->get_base_stars() >= 4){ // SFV Collab event units, always awakened. $star_class = "star_purple"; } elseif($k->get_archetype() == ARCHETYPE_ID::MATERIAL && $k->get_element() == ELEMENT_ID::LIGHT){ // Rainbowmon, always awakened $star_class = "star_purple"; } elseif($k->get_archetype() == ARCHETYPE_ID::MATERIAL && $k->get_element() == ELEMENT_ID::DARK){ // Devilmon, always unawakened $star_class = "star_silver"; } else{ // Unawakeable monster $star_class = "star_silver"; } } elseif ($k->get_awakens_from() != ""){ // Already awakened if ($k->get_base_stars() - $k->get_natural_stars() == 1){ // Normal awaken. $star_class ="star_purple"; } else{ // Second awaken. $star_class ="star_red"; } } elseif ($k->get_awakens_to() != ""){ // Awakeable. $star_class ="star_gold"; } $html .= "\n"; for ($i = 0; $i < $stars; $i ++){ $html .= "\n"; } $html .= "\n"; $html .= "\n"; if ($level){ $html .= "\n"; $html .= $unit->get_level() . "\n"; $html .= "\n"; } $html .= "\n"; if ($maxed){ $html .= ""; } if ($teams > 0){ $title = $teams . " teams"; if ($teams == 1){ $title = "1 team: " . $unit->get_teams()[0]->get_name(); } $html .= ""; } if ($lock == 1){ $html .= ""; } if ($storage){ $html .= ""; } $html .= "\n"; return $html; } /** * Generates a transformed monster panel. * * @param Unit|Monster Entity to get the info from. * @return string HTML content for a monster panel. Empty on error. */ public static function unit_transformation_panel($unit) { $html = ""; if ($unit instanceof Unit){ $k = $unit->get_unit(); } elseif ($unit instanceof Monster){ $k = $unit; } else{ return ""; } if ($k->get_transformation() == null){ return ""; } $html .= "
\n"; $html .= "\n"; $html .= "
\n"; return $html; } /** * Generates a rune panel. * * @param Rune rune Entity to get the info from. * @param Unit unit Optional. The unit the rune is assigned to. * @return string HTML content for a rune panel. Empty on error. */ public static function rune_panel($rune, $unit = null) { if (!($rune instanceof Rune)){ return ""; } $html = ""; $html .= "
\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $star_color = "gold"; if ($rune->geT_level() == 15){ $star_color = "purple"; } for ($i = 0; $i < $rune->get_stars(); $i ++){ $html .= "\n"; } $html .= "\n"; $html .= "\n"; $html .= $rune->get_level() . "\n"; $html .= "\n"; $html .= "
\n"; if ($unit instanceof Unit){ $html .= "
\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "
\n"; } return $html; } /** * Generates a rune table. * * @param Rune rune Entity to get the info from. * @param Unit unit Optional. The unit the rune is assigned to. * @return string HTML content for a rune table. Empty on error. */ public static function rune_table($rune, $unit = null) { if (!($rune instanceof Rune)){ return ""; } $html = ""; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; // Details $html .= "\n"; $html .= "\n"; $html .= "
\n"; $html .= HTML::rune_panel($rune, $unit) . "\n"; $html .= "\n"; $html .= "\n"; // Main stat $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; // Innate stat $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; for ($i = 0; $i < 4; $i ++){ if ($rune->get_substats()[$i] == null){ $stat_name = " "; $stat_value = ""; } elseif (in_array($rune->get_substats()[$i]->get_stat_name(), array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){ $stat_name = str_replace("%", "", $rune->get_substats()[$i]->get_stat_name()); $stat_value = "+" . $rune->get_substats()[$i]->get_value() . "%"; } else{ $stat_name = $rune->get_substats()[$i]->get_stat_name(); $stat_value = "+" . $rune->get_substats()[$i]->get_value(). " "; } $grind = ""; if ($rune->get_substats()[$i] != null && $rune->get_substats()[$i]->get_grind() > 0){ $grind = "+" . $rune->get_substats()[$i]->get_grind(); if (in_array($rune->get_substats()[$i]->get_stat_name(), array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){ $grind = $grind . "%"; } } $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; } $html .= "
\n"; if (in_array($rune->get_main_stat()->get_stat_name(), array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){ $stat_name = str_replace("%", "", $rune->get_main_stat()->get_stat_name()); $stat_value = "+" . $rune->get_main_stat()->get_value() . "%"; } else{ $stat_name = $rune->get_main_stat()->get_stat_name(); $stat_value = "+" . $rune->get_main_stat()->get_value(). " "; } $html .= $stat_name . "\n"; $html .= "\n"; $html .= $stat_value . "\n"; $html .= "\n"; $html .= "\n"; $html .= "
\n"; if ($rune->get_innate_stat() == null){ $stat_name = " "; $stat_value = ""; } elseif (in_array($rune->get_innate_stat()->get_stat_name(), array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){ $stat_name = str_replace("%", "", $rune->get_innate_stat()->get_stat_name()); $stat_value = "+" . $rune->get_innate_stat()->get_value() . "%"; } else{ $stat_name = $rune->get_innate_stat()->get_stat_name(); $stat_value = "+" . $rune->get_innate_stat()->get_value(). " "; } $html .= $stat_name . "\n"; $html .= "\n"; $html .= $stat_value . "\n"; $html .= "\n"; $html .= "
\n"; $html .= $stat_name . "\n"; $html .= "\n"; $html .= $stat_value . "\n"; $html .= "\n"; $html .= $grind . "\n"; if ($rune->get_substats()[$i] != null && $rune->get_substats()[$i]->is_enchanted()){ $html .= "\n"; } $html .= "
\n"; $html .= "
\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "
\n"; $html .= "QY.:\n"; $html .= "\n"; $html .= "\n"; $html .= $rune->get_quality_name() . "\n"; $html .= "\n"; $html .= "
\n"; $html .= "O.QY.:\n"; $html .= "\n"; $html .= "\n"; $html .= $rune->get_original_quality_name() . "\n"; $html .= "\n"; $html .= "
\n"; $html .= "Value:\n"; $html .= "\n"; $html .= number_format($rune->get_value(), 0, ".", ",") . "\n"; $html .= "
\n"; $html .= "EFF.:\n"; $html .= "\n"; $html .= number_format($rune->get_efficiency(), 2, ".", ",") . "%\n"; $html .= "
\n"; $html .= "MX.E.:\n"; $html .= "\n"; $html .= number_format($rune->get_max_efficiency(), 2, ".", ",") . "%\n"; $html .= "
\n"; $html .= "
\n"; return $html; } // TODO: Icon and background selection must go in the entity code. /** * Generates an artifact panel. * * @param Artifact artifact Entity to get the info from. * @param Unit unit Optional. The unit the artifact is assigned to. * @return string HTML content for an artifact panel. Empty on error. */ public static function artifact_panel($artifact, $unit = null) { if (!($artifact instanceof Artifact)){ return ""; } $html = ""; $html .= "
\n"; $background = ""; $icon = ""; if ($artifact->is_archetypal()){ $background = URL::IMG["ARTIFACT"] . "type_" . strtolower($artifact->get_quality_name()) . ".png"; $icon = URL::IMG["ARTIFACT"] . "type_"; switch ($artifact->get_archetype()){ case ARCHETYPE_ID::ATTACK: $icon .= "attack"; break; case ARCHETYPE_ID::DEFENSE: $icon .= "defense"; break; case ARCHETYPE_ID::HP: $icon .= "hp"; break; case ARCHETYPE_ID::SUPPORT: $icon .= "support"; break; } $icon .= ".png"; } else{ $background = URL::IMG["ARTIFACT"] . "element_" . strtolower($artifact->get_quality_name()) . ".png"; $icon = URL::IMG["ARTIFACT"] . "element_"; switch ($artifact->get_element()){ case ELEMENT_ID::WATER: $icon .= "water"; break; case ELEMENT_ID::WIND: $icon .= "wind"; break; case ELEMENT_ID::FIRE: $icon .= "fire"; break; case ELEMENT_ID::LIGHT: $icon .= "light"; break; case ELEMENT_ID::DARK: $icon .= "dark"; break; } $icon .= ".png"; } $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= $artifact->get_level() . "\n"; $html .= "\n"; $html .= "
\n"; if ($unit instanceof Unit){ $html .= "
\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "
\n"; } return $html; } /** * Generates a artifact table. * * @param Artifact artifact Entity to get the info from. * @param Unit unit Optional. The unit the artifact is assigned to. * @return string HTML content for a artifact table. Empty on error. */ public static function artifact_table($artifact, $unit = null) { if (!($artifact instanceof Artifact)){ return ""; } $html = ""; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "\n"; $html .= "
\n"; $html .= HTML::artifact_panel($artifact, $unit) . "\n"; $html .= "\n"; $html .= "\n"; // Main stat $html .= "\n"; $html .= "\n"; $html .= "\n"; //$effects = array($artifact->effect_1_description, $artifact->effect_2_description, $artifact->effect_3_description, $artifact->effect_4_description); for ($i = 0; $i < 4; $i ++){ $html .= "\n"; $html .= "\n"; $html .= "\n"; } $html .= "
\n"; $stat_name = $artifact->get_stat()->get_name(); $stat_value = "+" . $artifact->get_stat()->get_value(); $html .= $stat_name . "\n"; $html .= $stat_value . "\n"; $html .= "
\n"; if (count($artifact->get_effects()) <= $i){ $name = " "; } else{ $name = $artifact->get_effects()[$i]->get_name(); $name = str_replace("Increasing", "Inc.", $name); $name = str_replace("Decrease", "Dec.", $name); $name = str_replace("Critical", "Crit.", $name); $name = str_replace("Received ", "", $name); $name = str_replace("Damage", "Dmg.", $name); $name = str_replace("Additional", "Addl.", $name); $name = str_replace("Proportional", "Rel.", $name); $name = str_replace("Counterattack", "Counter", $name); $name = str_replace("Dealt by Attacking Together", "Attacking Together", $name); $name = str_replace("HP condition is bad", "bad HP", $name); $name = str_replace("HP condition is good", "good HP", $name); } $html .= $name; $html .= "
\n"; $html .= "
\n"; $html .= "EFF.: " . number_format($artifact->get_efficiency(), 2, ".", ",") . "%  \n"; $html .= "MX.E.: " . number_format($artifact->get_max_efficiency(), 2, ".", ",") . "%  \n"; $html .= "Value.: " . number_format($artifact->get_value(), 0, ".", ",") . "\n"; $html .= "
\n"; return $html; } /** * Generates a grindstone or gem panel. * * @param Enchantment Entity to get the info from. * @return string HTML content for a rune panel. Empty on error. */ public static function enchantment_panel($enchantment) { if (!($enchantment instanceof Enchantment)){ return ""; } $html = ""; if ($enchantment->is_gem()){ if ($enchantment->is_inmemorial()){ $base = URL::IMG["GRIND"] . "gem_inmemorial.png"; } else{ $base = URL::IMG["GRIND"] . "gem.png"; } } else{ if ($enchantment->is_inmemorial()){ $base = URL::IMG["GRIND"] . "grind_inmemorial.png"; } else{ $base = URL::IMG["GRIND"] . "grind.png"; } } if (! $enchantment->is_inmemorial() && $enchantment->get_rune_set() != null){ $icon = "\n"; } else{ $icon = ""; } if (in_array($enchantment->get_stat_name(), array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){ $stat_name = str_replace("%", "", $enchantment->get_stat_name()); $stat_value = "+" . $enchantment->get_min() . "~" . $enchantment->get_max() . "%"; } else{ $stat_name = $enchantment->get_stat_name(); $stat_value = "+" . $enchantment->get_min() . "~" . $enchantment->get_max(); } $html .= "
\n"; $html .= "\n"; $html .= $icon; $html .= "\n"; $html .= "" . $stat_name . "\n"; $html .= "" . $stat_value . "\n"; $html .= "\n"; if ($enchantment->get_amount() > 1){ $html .= "\n"; $html .= "x" . $enchantment->get_amount() . "\n"; $html .= "\n"; } $html .= "
\n"; return $html; } /** * Generates a building panel. * * @param Building|Decoration|Buildable|Decorative $building Entity to get the info from. * @return string HTML content for a building panel. Empty on error. */ public static function building_panel($building) { if ($building instanceof Building){ $level = false; $title = $building->get_buildable()->get_name(); $description = $building->get_buildable()->get_description(); $img = $building->get_buildable()->get_image(); } elseif ($building instanceof Buildable){ $level = false; $title = $building->get_name(); $description = $building->get_description(); $img = $building->get_image(); } elseif ($building instanceof Decoration){ $level = $building->get_level(); $title = $building->get_decorative()->get_name(); $description = $building->get_decorative()->get_description(); $img = $building->get_decorative()->get_image(); } elseif ($building instanceof Decorative){ $level = false; $title = $building->get_name(); $description = $building->get_description(); $img = $building->get_image(); } else{ return ""; } if (strlen($description) > 0){ $title .= ": " . $description; } $html = "
\n"; $html .= "\n"; if ($level){ $html .= "\n"; $html .= $level . "\n"; $html .= "\n"; } $html .= "
\n"; return $html; } /** * Generates a item panel. * * @param Inventory $item Entity to get the info from. * @return string HTML content for an item panel. Empty on error. */ public static function item_panel($item) { if (!($item instanceof Inventory) && !($item instanceof Item)){ return ""; } if ($item instanceof Item){ $html = "
\n"; $html .= "\n"; $html .= "\n"; $html .= $item->get_amount() . "\n"; $html .= "\n"; $html .= "
\n"; } elseif ($item instanceof Inventory){ $html = "
\n"; $html .= "\n"; $html .= "
\n"; } return $html; } /** * Generates a source panel. * * @param Inventory $source Entity to get the info from. * @return string HTML content for a source panel. Empty on error. */ public static function source_panel($source) { //if (!($item instanceof Source)){ // return ""; //} $html = "
\n"; $html .= "\n"; $html .= "
\n"; return $html; } /** * Generates an arena rank icon image. * * @param int $d Arena rank id. * @return string HTML content for the image. */ public static function arena_rank_icon($id) { switch ($id){ case ARENA_RANK_ID::BEGINER: $src = URL::IMG["RANK"] . "0901.png"; $tit = "Beginer"; break; case ARENA_RANK_ID::CHALLENGER_1: $src = URL::IMG["RANK"] . "1001.png"; $tit = "Challenger 1"; break; case ARENA_RANK_ID::CHALLENGER_2: $src = URL::IMG["RANK"] . "1002.png"; $tit = "Challenger 2"; break; case ARENA_RANK_ID::CHALLENGER_3: $src = URL::IMG["RANK"] . "1003.png"; $tit = "Challenger 3"; break; case ARENA_RANK_ID::FIGHTER_1: $src = URL::IMG["RANK"] . "2001.png"; $tit = "Fighter 1"; break; case ARENA_RANK_ID::FIGHTER_2: $src = URL::IMG["RANK"] . "2002.png"; $tit = "Fighter 2"; break; case ARENA_RANK_ID::FIGHTER_3: $src = URL::IMG["RANK"] . "2003.png"; $tit = "Fighter 3"; break; case ARENA_RANK_ID::CONQUEROR_1: $src = URL::IMG["RANK"] . "3001.png"; $tit = "Conqueror 1"; break; case ARENA_RANK_ID::CONQUEROR_2: $src = URL::IMG["RANK"] . "3002.png"; $tit = "Conqueror 2"; break; case ARENA_RANK_ID::CONQUEROR_3: $src = URL::IMG["RANK"] . "3003.png"; $tit = "Conqueror 3"; break; case ARENA_RANK_ID::GUARDIAN_1: $src = URL::IMG["RANK"] . "4001.png"; $tit = "Guardian 1"; break; case ARENA_RANK_ID::GUARDIAN_2: $src = URL::IMG["RANK"] . "4002.png"; $tit = "Guardian 2"; break; case ARENA_RANK_ID::GUARDIAN_3: $src = URL::IMG["RANK"] . "4003.png"; $tit = "Guardian 3"; break; case ARENA_RANK_ID::LEGEND: $src = URL::IMG["RANK"] . "5001.png"; $tit = "Legend"; default: $src = URL::IMG["RANK"] . "0901.png"; $tit = "Beginer"; } $html = "$tit"; return $html; } }