37.tpl ## ## (craniu, cand eroul e mort -> tot 37.tpl) ## ## - centru : portretul eroului + inelul Health(rosu)/Experience(albastru) ## - dreapta sus : numarul de aventuri -> 37_adventures.tpl ## ## - dreapta jos : argintul -> 37_auction.tpl ## ## ## ## Toate valorile sunt reale (nimic hardcodat). Inelul e SVG desenat din ## ## procentele efective, NU o imagine statica. ## ## ## ################################################################################# /** * Gard 1: fara sesiune de jucator real nu afisam nimic. * $isRestrictedUser vine din header.tpl (contul special cu id 1). */ if (!isset($session) || !is_object($session)) { return; } if (isset($isRestrictedUser) && $isRestrictedUser) { return; } if (!isset($database) || !is_object($database)) { return; } $tzHeroUid = (int) $session->uid; if ($tzHeroUid <= 0) { return; } /** * Functiile T4 de erou (aventuri / licitatii / argint) sunt optionale. * Cand steagul e stins, ramane doar cercul cu erou + casa, fiindca * Adventures si Silver n-ar avea unde sa duca. */ $tzHeroT4 = defined('NEW_FUNCTIONS_HERO_T4') && NEW_FUNCTIONS_HERO_T4; /** * --------------------------------------------------------------------------- * 1. Randul eroului * --------------------------------------------------------------------------- * getHero($uid, 1) intoarce TOTI eroii, ordonati dupa lastupdate DESC. * Alegem, ca in Units::Hero(), primul erou viu si care nu e in antrenament; * daca nu exista, luam primul rand (cel mai recent folosit) - asa prindem * si eroul mort, de care avem nevoie pentru starea DEAD. */ $tzHeroRow = false; $tzHeroRows = $database->getHero($tzHeroUid, 1); if (is_array($tzHeroRows) && count($tzHeroRows)) { foreach ($tzHeroRows as $tzRow) { if ((int) $tzRow['dead'] !== 1 && (int) $tzRow['intraining'] !== 1) { $tzHeroRow = $tzRow; break; } } if (!$tzHeroRow) { $tzHeroRow = $tzHeroRows[0]; } } $tzHeroExists = is_array($tzHeroRow); $tzHeroDead = $tzHeroExists ? ((int) $tzHeroRow['dead'] === 1) : false; $tzHeroTraining = $tzHeroExists ? ((int) $tzHeroRow['intraining'] === 1) : false; $tzHeroName = $tzHeroExists ? (string) $tzHeroRow['name'] : ''; $tzHeroLevel = $tzHeroExists ? (int) $tzHeroRow['level'] : 0; $tzHeroUnit = $tzHeroExists ? (int) $tzHeroRow['unit'] : 0; $tzHeroWref = $tzHeroExists ? (int) $tzHeroRow['wref'] : 0; /** * health e float(12,9) in baza de date. Il rotunjim doar la afisare. */ $tzHeroHealth = $tzHeroExists ? (float) $tzHeroRow['health'] : 0; $tzHeroHealth = max(0, min(100, $tzHeroHealth)); if ($tzHeroDead) { $tzHeroHealth = 0; } /** * --------------------------------------------------------------------------- * 2. Procentul de Experience catre nivelul urmator * --------------------------------------------------------------------------- * Aceeasi formula ca in Templates/Build/37_hero.tpl, ca sa nu existe doua * adevaruri diferite in interfata. $hero_levels vine din * GameEngine/Data/hero_full.php, incarcat de Session.php pe fiecare pagina. */ $tzHeroLevels = (isset($GLOBALS['hero_levels']) && is_array($GLOBALS['hero_levels']) && count($GLOBALS['hero_levels']) > 1) ? $GLOBALS['hero_levels'] : array(0 => 0, 1 => 100); $tzMaxLevel = max(array_keys($tzHeroLevels)) - 1; $tzMaxExp = isset($tzHeroLevels[$tzMaxLevel]) ? (int) $tzHeroLevels[$tzMaxLevel] : 0; $tzCurExp = $tzHeroExists ? (int) $tzHeroRow['experience'] : 0; $tzExpCur = isset($tzHeroLevels[$tzHeroLevel]) ? (int) $tzHeroLevels[$tzHeroLevel] : 0; $tzExpNext = isset($tzHeroLevels[$tzHeroLevel + 1]) ? (int) $tzHeroLevels[$tzHeroLevel + 1] : $tzMaxExp; if ($tzHeroExists && $tzCurExp < $tzMaxExp && $tzExpNext > $tzExpCur && $tzHeroLevel < $tzMaxLevel) { $tzHeroExpPct = ($tzCurExp - $tzExpCur) / ($tzExpNext - $tzExpCur) * 100; $tzHeroExpPct = max(0, min(100, $tzHeroExpPct)); } else { $tzHeroExpPct = $tzHeroExists ? 100 : 0; } /** * --------------------------------------------------------------------------- * 3. Unde se afla eroul acum * --------------------------------------------------------------------------- * Refolosim HeroItems::heroAwayReason(), aceeasi sursa de adevar ca pagina de * echipare: un singur query cu subinterogari separate, care intoarce * '' (acasa) | 'nohero' | 'adventure' | 'attack' | 'reinforcement'. * - 'adventure' : hero_adventure cu status = 1 * - 'attack' : movement sort_type 3 (dus) sau 4 (intors) cu attacks.t11 * - 'reinforcement' : enforcement.hero pornit dintr-un sat al jucatorului * Metoda are cache static pe uid, deci daca o mai cheama cineva pe aceeasi * pagina nu se duce a doua oara la baza de date. */ $tzHeroAway = ''; $tzHeroTarget = 0; $tzHeroEndtime = 0; $tzHeroSort = 0; if ($tzHeroExists && !$tzHeroDead && !$tzHeroTraining && class_exists('HeroItems')) { $tzAwayObject = new HeroItems(); if (method_exists($tzAwayObject, 'heroLocation')) { $tzLoc = $tzAwayObject->heroLocation($tzHeroUid); $tzHeroAway = (string) $tzLoc['reason']; $tzHeroTarget = (int) $tzLoc['target']; $tzHeroEndtime = (int) $tzLoc['endtime']; $tzHeroSort = (int) $tzLoc['sort']; } else { // rezerva, daca ajunge pe un server cu HeroItems.php vechi $tzHeroAway = (string) $tzAwayObject->heroAwayReason($tzHeroUid); } } // 'nohero' nu ne intereseaza aici - stim deja ca eroul exista if ($tzHeroAway === 'nohero') { $tzHeroAway = ''; } /** * Coordonatele destinatiei si secundele ramase pana la sosire. * La intoarcere (sort_type 4) destinatia e chiar satul jucatorului. */ $tzHeroTargetCoor = ''; if ($tzHeroTarget > 0) { $tzCoor = $database->getCoor($tzHeroTarget); if (is_array($tzCoor) && isset($tzCoor['x'], $tzCoor['y'])) { $tzHeroTargetCoor = '(' . (int) $tzCoor['x'] . '|' . (int) $tzCoor['y'] . ')'; } } $tzHeroSecondsLeft = ($tzHeroEndtime > 0) ? max(0, $tzHeroEndtime - time()) : 0; /** * Starea unica a componentei, din care ies si iconita, si tooltip-ul. * Ordinea conteaza: mort > inexistent > in antrenament > plecat > acasa. */ if (!$tzHeroExists) { $tzHeroState = 'nohero'; } elseif ($tzHeroDead) { $tzHeroState = 'dead'; } elseif ($tzHeroTraining) { $tzHeroState = 'training'; } elseif ($tzHeroAway !== '') { $tzHeroState = $tzHeroAway; } else { $tzHeroState = 'home'; } /** * --------------------------------------------------------------------------- * 4. Satul eroului * --------------------------------------------------------------------------- */ $tzHeroVillage = ''; if ($tzHeroWref > 0) { $tzHeroVillage = (string) $database->getVillageField($tzHeroWref, 'name'); } /** * --------------------------------------------------------------------------- * 5. Aventuri disponibile * --------------------------------------------------------------------------- * Un erou mort nu poate pleca in aventura, deci afisam 0 (cerinta 7), * dar zona ramane clickabila. */ $tzHeroAdv = 0; if ($tzHeroT4 && !$tzHeroDead && class_exists('HeroAdventure')) { $tzAdvObject = new HeroAdventure(); $tzAdvOffers = $tzAdvObject->getOffers($tzHeroUid); $tzHeroAdv = is_array($tzAdvOffers) ? count($tzAdvOffers) : 0; } /** * --------------------------------------------------------------------------- * 6. Argintul * --------------------------------------------------------------------------- * Refolosim exact acelasi cache ca blocul de aur din header.tpl * ($GLOBALS['t4SilverValue']), ca sa nu iasa doua interogari pe pagina. */ $tzHeroSilver = 0; if ($tzHeroT4 && class_exists('HeroItems')) { if (!isset($GLOBALS['t4SilverValue'])) { $tzSilverObject = new HeroItems(); $GLOBALS['t4SilverValue'] = (int) $tzSilverObject->getSilver($tzHeroUid); } $tzHeroSilver = (int) $GLOBALS['t4SilverValue']; } /** * --------------------------------------------------------------------------- * 7. Link-urile catre Resedinta Eroului * --------------------------------------------------------------------------- * 37.tpl / 37_adventures.tpl / 37_auction.tpl nu sunt URL-uri: se ajunge * la ele prin build.php pe campul unde e cladirea 37, cu parametrul t4tab. * * getTypeField() cauta DOAR in satul curent. Daca jucatorul se uita la un * sat fara Resedinta Eroului, trimitem catre satul unde sta eroul, cu * newdid + gid=37 (build.php pastreaza t4tab peste redirect - vezi patch-ul * din build.php livrat impreuna cu acest fisier). */ $tzHeroField = 0; if (isset($building) && is_object($building) && method_exists($building, 'getTypeField')) { $tzHeroField = (int) $building->getTypeField(37); } if ($tzHeroField > 0) { $tzHeroBase = 'build.php?id=' . $tzHeroField; } elseif ($tzHeroWref > 0) { $tzHeroBase = 'build.php?newdid=' . $tzHeroWref . '&gid=37'; } else { $tzHeroBase = 'build.php?gid=37'; } $tzLinkHero = $tzHeroBase; $tzLinkAdv = $tzHeroBase . '&t4tab=adventures'; $tzLinkAuc = $tzHeroBase . '&t4tab=auction'; /** * --------------------------------------------------------------------------- * 8. Portretul eroului * --------------------------------------------------------------------------- * img/u2/uN.gif sunt portretele mari (150x120), existente pentru toate * unitatile de erou, inclusiv triburile noi 6-9 (u51..u90). Daca lipseste * fisierul, cadem pe iconita mica img/u/N.gif. */ $tzHeroPortrait = ''; if ($tzHeroUnit > 0) { $tzBig = GP_LOCATE . 'img/u2/u' . $tzHeroUnit . '.gif'; $tzSmall = GP_LOCATE . 'img/u/' . $tzHeroUnit . '.gif'; if (@file_exists($tzBig)) { $tzHeroPortrait = $tzBig; } elseif (@file_exists($tzSmall)) { $tzHeroPortrait = $tzSmall; } } /** * --------------------------------------------------------------------------- * 9. Geometria inelului * --------------------------------------------------------------------------- * Doua arce concentrice, in acelasi SVG: exterior = Health (rosu), * interior = Experience (albastru). Lungimea vizibila se obtine cu * stroke-dasharray, iar rotate(-90) porneste arcele de sus. */ $tzRingR1 = 26.5; // raza arcului de Health $tzRingR2 = 21; // raza arcului de Experience $tzRingC1 = 2 * M_PI * $tzRingR1; // circumferinte $tzRingC2 = 2 * M_PI * $tzRingR2; $tzDashHealth = round($tzRingC1 * $tzHeroHealth / 100, 2); $tzDashExp = round($tzRingC2 * $tzHeroExpPct / 100, 2); /** * --------------------------------------------------------------------------- * 10. Texte * --------------------------------------------------------------------------- * Tiparul defined()?: e cel folosit deja in 37_hero.tpl / 37_t4nav.tpl - * componenta merge si pe servere care n-au inca noile constante de limba. */ $tzTxtAtHome = defined('HERO_HEADER_AT_HOME') ? HERO_HEADER_AT_HOME : 'Hero at home'; $tzTxtDead = defined('HERO_HEADER_DEAD') ? HERO_HEADER_DEAD : 'Hero is dead'; $tzTxtTraining = defined('HERO_HEADER_TRAINING') ? HERO_HEADER_TRAINING : 'Hero in training'; $tzTxtNoHero = defined('HERO_HEADER_NOHERO') ? HERO_HEADER_NOHERO : 'No hero yet'; $tzTxtAdventure = defined('HERO_HEADER_ADVENTURE') ? HERO_HEADER_ADVENTURE : 'Hero on adventure'; $tzTxtAttack = defined('HERO_HEADER_ATTACK') ? HERO_HEADER_ATTACK : 'Hero is with the army'; $tzTxtReinforce = defined('HERO_HEADER_REINFORCE') ? HERO_HEADER_REINFORCE : 'Hero is reinforcing'; $tzTxtIn = defined('HERO_HEADER_IN') ? HERO_HEADER_IN : 'in'; $tzTxtVillage = defined('VILLAGE') ? VILLAGE : 'Village'; $tzTxtLevel = defined('LEVEL') ? LEVEL : 'Level'; $tzTxtHealth = defined('TZ_HEALTH') ? TZ_HEALTH : 'Health'; $tzTxtExperience = defined('EXPERIENCE') ? EXPERIENCE : 'Experience'; $tzTxtSilver = defined('HERO_SILVER') ? HERO_SILVER : 'Silver'; $tzTxtAdventures = defined('HERO_T4_TAB_ADVENTURES') ? HERO_T4_TAB_ADVENTURES : 'Adventures'; /** * Numele afisate vin din baza de date, deci trec obligatoriu prin escape. */ $tzHeroNameSafe = htmlspecialchars($tzHeroName, ENT_QUOTES, 'UTF-8'); $tzHeroVillageSafe = htmlspecialchars($tzHeroVillage, ENT_QUOTES, 'UTF-8'); ?>
0) { ?>