Example #1
0
function page_refreshUserData()
{
    global $db;
    $player = Player::getPlayer($_SESSION['player']->playerID);
    if (!$player) {
        return false;
    }
    $_SESSION['player'] = $player;
    return true;
}
Example #2
0
function page_refreshUserData()
{
    global $db, $params, $config;
    $player = Player::getPlayer($params->SESSION->player->playerID);
    if (!$player) {
        return FALSE;
    }
    $_SESSION['player'] = $player;
    $params->SESSION->player = $player;
    return TRUE;
}
Example #3
0
function tribe_getContent($caveID, $tribeID)
{
    global $db, $template;
    if (!$tribeID) {
        $template->throwError('Der Stamm wurde nicht gefunden.');
        return;
    }
    // open template
    $template->setFile('tribeDetail.tmpl');
    $template->setShowResource(false);
    $tribe = Tribe::getByID($tribeID);
    if ($tribe == null) {
        $template->throwError('Der Stamm wurde nicht gefunden.');
        return;
    }
    // parse tribe message
    $parser = new parser();
    $tribe['description'] = $parser->p($tribe['description']);
    $ranking = Tribe::getRanking($tribeID);
    $tribe['rank'] = $ranking;
    // leader
    if ($tribe['leaderID'] != 0) {
        $leader = Player::getPlayer($tribe['leaderID']);
        $tribe['leader_name'] = $leader->name;
    }
    $template->addVar('tribe_details', $tribe);
    // history
    $template->addVar('tribe_history', Tribe::getHistory($tribeID));
    // player list
    $template->addVar('tribe_player_list', Tribe::getPlayerList($tribeID, true, true));
    // relations
    $relations = TribeRelation::getRelations($tribeID);
    $relationsData = array();
    if (isset($relations['own'])) {
        foreach ($relations['own'] as $target => $relationData) {
            $relationsData[$target] = array('tribe' => $relationData['targetTag'], 'tribeID_target' => $relationData['tribeID_target'], 'relation_to' => $GLOBALS['relationList'][$relationData['relationType']]['name'], 'relation_from' => isset($relations['other'][$target]) && $relations['other'][$target] ? $GLOBALS['relationList'][$relations['other'][$target]['relationType']]['name'] : $GLOBALS['relationList'][0]['name']);
        }
    }
    if (isset($relations['other'])) {
        foreach ($relations['other'] as $target => $relationData) {
            // already printed out this relation
            if (isset($relationsData[$target])) {
                continue;
            }
            $relationsData[$target] = array('tribe' => $relationData['targetTag'], 'tribeID_target' => $relationData['tribeID_target'], 'relation_to' => $GLOBALS['relationList'][0]['name'], 'relation_from' => $GLOBALS['relationList'][$relationData['relationType']]['name']);
        }
    }
    $template->addVar('relations_data', $relationsData);
}
Example #4
0
if (!$db) {
    page_dberror();
}
//check user from Session-table with id
$query = "SELECT * FROM Session " . "WHERE s_id = '{$params->POST->id}' " . "AND playerID = '{$params->POST->userID}'";
$dbresult = $db->query($query);
if (!$dbresult || $dbresult->isEmpty()) {
    page_error403(__FILE__ . ":" . __LINE__ . ": Falsche SessionID.");
}
$session_row = $dbresult->nextRow(MYSQL_ASSOC);
// sessionstart sollte nur einmal augerufen werden können
$query = "UPDATE `Session` SET s_id_used = 1 " . "WHERE s_id = '{$params->POST->id}' " . "AND playerID = '{$params->POST->userID}' " . "AND s_id_used = 0";
$dbresult = $db->query($query);
if (!$dbresult || !$db->affected_rows() == 1) {
    page_error403(__FILE__ . ":" . __LINE__ . ": Ungültige SessionID.");
}
// get player by playerID for session
$player = Player::getPlayer($params->POST->userID);
if (!$player) {
    page_error403(__FILE__ . ":" . __LINE__ . ": Ungültige SpielerID.");
}
// put user, its session and nogfx flag into session
$_SESSION['player'] = $player;
$_SESSION['nogfx'] = $params->POST->nogfx == 1;
$_SESSION['session'] = $session_row;
$_SESSION['logintime'] = date("YmdHis");
// initiate Session messages
$_SESSION['messages'] = array();
// go to ugastart.php
Header("Location: {$config->GAME_START_URL}");
exit;
Example #5
0
function takeover_transfer_cave_to($caveID, $playerID)
{
    global $db;
    // check parameters
    $caveID = (int) $caveID;
    $playerID = (int) $playerID;
    // get player
    $winner = Player::getPlayer($playerID, true);
    if (!sizeof($winner)) {
        echo "ERROR (takeover_transfer_cave_to): Could not transfer Cave {$caveID} to Player {$playerID}.\n";
        return FALSE;
    }
    // secureCaveCredits
    $hasCredits = $winner['secureCaveCredits'] > 0 ? 1 : 0;
    // transfer cave to player
    $sql = $db->prepare("UPDATE " . CAVE_TABLE . "\n                       SET playerID = :playerID,\n                         takeoverable = 0,\n                         secureCave = :secureCave\n                       WHERE caveID = :caveID");
    $sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
    $sql->bindValue('secureCave', $hasCredits, PDO::PARAM_INT);
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    if (!$sql->execute()) {
        return FALSE;
    }
    // update secureCaveCredits
    $sql = $db->prepare("UPDATE " . PLAYER_TABLE . "\n                       SET secureCaveCredits = GREATEST(0, secureCaveCredits - 1)\n                       WHERE playerID = :playerID");
    $sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
    if (!$sql->execute()) {
        echo "ERROR (takeover_transfer_cave_to): Could not update secureCaveCredits of Player {$playerID}.\n";
        return FALSE;
    }
    // copy sciences
    if (sizeof($GLOBALS['scienceTypeList'])) {
        $set = array();
        foreach ($GLOBALS['scienceTypeList'] as $science) {
            $temp = $science->dbFieldName;
            $set[] = "{$temp} = '{$winner[$temp]}'";
        }
        $set = implode(", ", $set);
        $sql = $db->prepare("UPDATE " . CAVE_TABLE . "\n                         SET " . $set . "\n                         WHERE playerID = :playerID");
        $sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
        if (!$sql->execute()) {
            echo "ERROR (takeover_transfer_cave_to): Could not update sciences of Player {$playerID}.\n";
            return FALSE;
        }
    }
    // get the cave's data
    $cave = getCaveByID($caveID);
    takeover_send_transfer($playerID, $cave);
}
Example #6
0
 public static function changeLeader($tribeID, $newLeaderID, $oldLeaderID)
 {
     if (empty($tribeID) || $newLeaderID == $oldLeaderID) {
         return false;
         //nothing changed
     }
     if ($newLeaderID != $oldLeaderID) {
         if ($oldLeaderID && !self::removeLeader($tribeID)) {
             return -2;
         }
         if ($newLeaderID != 0 && !self::setLeader($newLeaderID, $tribeID)) {
             return -3;
         }
     }
     if ($newLeaderID != $oldLeaderID) {
         if ($newLeaderID == 0) {
             TribeMessage::sendIntern($tribeID, Tribe::MESSAGE_LEADER, _('Stammesführung'), _('Der Stamm hat momentan kein Oberhaupt mehr.'));
         }
         if ($newLeaderID > 0) {
             $player = Player::getPlayer($newLeaderID);
             TribeMessage::sendIntern($tribeID, Tribe::MESSAGE_LEADER, _('Stammesführung'), sprintf(_('Ihr Stamm hat ein neues Oberhaupt: %s.'), $player->name));
         }
     }
     return $newLeaderID;
 }
Example #7
0
function hero_usePotion($potionID, $value)
{
    global $db;
    $playerID = $_SESSION['player']->playerID;
    $playerData = Player::getPlayer($playerID, true);
    $hero = getHeroByPlayer($playerID);
    $potion = $GLOBALS['potionTypeList'][$potionID];
    if (!$potion) {
        return -8;
    }
    if ($potion->needed_level > $hero['lvl']) {
        return -10;
    }
    if ($playerData[$potion->dbFieldName] < $value) {
        return -9;
    }
    // remove potions
    $sql = $db->prepare("UPDATE " . PLAYER_TABLE . "\n                       SET " . $potion->dbFieldName . " = " . $potion->dbFieldName . " - :value\n                       WHERE playerID = :playerID");
    $sql->bindValue('value', $value, PDO::PARAM_INT);
    $sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
    $sql_setback = $db->prepare("UPDATE " . PLAYER_TABLE . "\n                               SET " . $potion->dbFieldName . " = " . $potion->dbFieldName . " + :value\n                               WHERE playerID = :playerID");
    $sql_setback->bindValue('value', $value, PDO::PARAM_INT);
    $sql_setback->bindValue('playerID', $playerID, PDO::PARAM_INT);
    if (!$sql->execute()) {
        return -8;
    }
    // apply potion effects
    $newHealPoints = $hero['healPoints'];
    for ($i = 0; $i < $value; $i++) {
        $newHealPoints += floor($hero['maxHealPoints'] * $potion->hp_prozentual_increase / 100) + $potion->hp_increase;
    }
    if ($hero['maxHealPoints'] < $newHealPoints) {
        $newHealPoints = $hero['maxHealPoints'];
    }
    if ($potion->tp_setBack == false) {
        $sql = $db->prepare("UPDATE " . HERO_TABLE . "\n                         SET healPoints = :newHealPoints\n                         WHERE playerID = :playerID");
        $sql->bindValue('newHealPoints', $newHealPoints, PDO::PARAM_INT);
        $sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
        if (!$sql->execute()) {
            $sql_setback->execute();
            return -8;
        }
    } else {
        //remove hero effects from cave
        if (!hero_removeHeroEffectsFromCave($playerID)) {
            return -8;
        }
        //remove hero effect from hero
        if (!hero_clearHeroEffectsAndSkills($playerID)) {
            return -8;
        }
        $tpFree = $hero['maxHpLvl'] + $hero['regHpLvl'] + $hero['tpFree'];
        foreach ($GLOBALS['heroSkillTypeList'] as $skill) {
            if ($hero[$skill['dbFieldName']]) {
                $tpFree += $skill['costTP'] * $hero[$skill['dbFieldName']];
            }
        }
        $healPoints = eval("return " . hero_parseFormulas($GLOBALS['heroTypesList'][$hero['heroTypeID']]['maxHP_formula']) . ";");
        $sql = $db->prepare("UPDATE " . HERO_TABLE . " SET\n                           maxHpLvl = 0, maxHealPoints = :maxHealPoints,\n                           healPoints = :healpoints,\n                           regHpLvl = 0, regHP = 0,\n                           tpFree = :tpFree,\n                           heroTypeID = 1000\n                         WHERE playerID = :playerID");
        $sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
        $sql->bindValue('tpFree', $tpFree, PDO::PARAM_INT);
        $sql->bindValue('maxHealPoints', $healPoints, PDO::PARAM_INT);
        $sql->bindValue('healpoints', floor($healPoints / 2), PDO::PARAM_INT);
        if (!$sql->execute()) {
            $sql_setback->execute();
            return -8;
        }
        return 6;
    }
    return 5;
}
Example #8
0
function getCaveReport($caveID, $ownCaves, $targetCaveID, $method)
{
    global $template;
    if (!$targetCaveID) {
        $template->throwError('Es wurde keine Höhle ausgewählt.');
        return;
    }
    if ($method == 'ajax') {
        $shortVersion = true;
        $template->setFile('mapDetailAjax.tmpl');
    } else {
        $shortVersion = false;
        $template->setFile('mapDetail.tmpl');
    }
    $cave = getCaveByID($targetCaveID);
    $caveDetails = array();
    $playerDetails = null;
    $showArtePossible = false;
    if ($cave['playerID'] != 0) {
        $caveDetails = getCaves($cave['playerID']);
        $playerDetails = Player::getPlayer($cave['playerID']);
        $showArtePossible = $playerDetails->tribe != GOD_ALLY ? true : false;
    }
    $cave['terrain_name'] = $GLOBALS['terrainList'][$cave['terrain']]['name'];
    $cave['terrain_img'] = $GLOBALS['terrainList'][$cave['terrain']]['img'];
    if ($GLOBALS['terrainList'][$cave['terrain']]['tribeRegion']) {
        $cave['terrain_description'] = $GLOBALS['terrainList'][$cave['terrain']]['description'];
        $cave['terrain_tribe_cave'] = $GLOBALS['terrainList'][$cave['terrain']]['tribeRegion'];
        $attackerTribe = Tribe::getByID($cave['lastAttackingTribeID']);
        $cave['tribe_cave_tag'] = $attackerTribe['tag'];
    }
    $region = getRegionByID($cave['regionID']);
    // Wenn die Höhle ein Artefakt enthält und man berechtigt ist -> anzeigen
    if ($cave['hasArtefact'] && ($showArtePossible || $_SESSION['player']->tribe == GOD_ALLY)) {
        $cave['hasArtefact'] = true;
    } else {
        $cave['hasArtefact'] = false;
    }
    if ($cave['hasPet'] && ($showArtePossible || $_SESSION['player']->tribe == GOD_ALLY)) {
        $cave['hasPet'] = true;
    } else {
        $cave['hasArtefact'] = false;
    }
    $template->addVar('cave_details', $cave);
    if ($cave['playerID'] != 0) {
        $template->addVar('player_details', $playerDetails);
        /****************************************************************************************************
        *
        * Alle Höhlen des Spielers ausgeben
        *
        ****************************************************************************************************/
        $caves = array();
        foreach ($caveDetails as $key => $value) {
            $temp = array('caveName' => $value['name'], 'xCoord' => $value['xCoord'], 'yCoord' => $value['yCoord'], 'terrain' => $GLOBALS['terrainList'][$value['terrain']]['name'], 'caveSize' => floor($value[CAVE_SIZE_DB_FIELD] / 50) + 1, 'secureCave' => $value['secureCave']);
            if ($value['hasArtefact'] && ($playerDetails->tribe != GOD_ALLY || $_SESSION['player']->tribe == GOD_ALLY)) {
                $temp['artefact'] = true;
            }
            if ($value['hasPet'] && ($playerDetails->tribe != GOD_ALLY || $_SESSION['player']->tribe == GOD_ALLY)) {
                $temp['pet'] = true;
            }
            $caves[] = $temp;
        }
        $template->addVar('player_caves', $caves);
    } else {
        if (sizeof($ownCaves) < $_SESSION['player']->takeover_max_caves) {
            if ($cave['starting_position'] == 0 && $cave['takeoverable'] == 0 && $cave['takeover_level'] > 0) {
                $template->addVar('maybe_takeoverable', true);
            } else {
                if ($cave['takeoverable'] == 1) {
                    $template->addVar('takeoverable', true);
                }
            }
        }
    }
}
Example #9
0
function player_getContent($caveID, $playerID)
{
    global $db, $template;
    // open template
    $template->setFile('playerDetail.tmpl');
    $template->setShowResource(false);
    // workaround, if no playerID is submitted! TODO
    if ($playerID == 0) {
        $playerID = $_SESSION['player']->playerID;
    }
    $playerDetails = Player::getPlayer($playerID, true);
    if (!$playerDetails) {
        $template->throwError('Da wollte irgendwie was nicht aus der Datenbank ausgelesen werden :(');
        return;
    }
    if ($playerDetails['avatar']) {
        $playerDetails['avatar'] = @unserialize($playerDetails['avatar']);
        $template->addVars(array('player_avatar' => $playerDetails['avatar']['path'], 'player_avatar_width' => $playerDetails['avatar']['width'], 'player_avatar_height' => $playerDetails['avatar']['height']));
    }
    if (!empty($playerDetails['awards'])) {
        $tmp = explode('|', $playerDetails['awards']);
        $awards = array();
        foreach ($tmp as $tag) {
            $awards[] = $tag;
        }
        $playerDetails['award'] = $awards;
    }
    unset($playerDetails['awards']);
    foreach ($playerDetails as $k => $v) {
        if (!$v) {
            $playerDetails[$k] = _('k.A.');
        }
    }
    $playerDetails['mail_receiver'] = urlencode($playerDetails['name']);
    $playerDetails['caveID'] = $caveID;
    $playerTribe = $playerDetails['tribe'];
    $timediff = getUgaAggaTimeDiff(time_fromDatetime($playerDetails['created']), time());
    $playerDetails['age'] = 18 + $timediff['year'];
    // init messages class
    $parser = new parser();
    $playerDetails['description'] = $parser->p($playerDetails['description']);
    // show player's caves
    $caves = getCaves($playerID);
    if ($caves) {
        $template->addVar('player_caves', $caves);
    }
    // show player's history
    $history = Player::getHistory($playerID);
    if (sizeof($history)) {
        $template->addVar('player_history', $history);
    }
    //get player rank
    $sql = $db->prepare("SELECT rank FROM " . RANKING_TABLE . " WHERE playerID = :playerID");
    $sql->bindValue('playerID', $playerID, pDo::PARAM_INT);
    if (!$sql->execute()) {
        page_dberror();
    }
    if ($row = $sql->fetch()) {
        $playerDetails['rank'] = $row['rank'];
    } else {
        $playerDetails['rank'] = '';
    }
    $template->addVars(array('player_details' => $playerDetails));
}
Example #10
0
$sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
if (!$sql->execute()) {
    header("Location: " . Config::GAME_END_URL . "?id=wrongSessionID");
    exit;
}
$sessionRow = $sql->fetch(PDO::FETCH_ASSOC);
$sql->closeCursor();
// sessionstart sollte nur einmal augerufen werden können
$sql = $db->prepare("UPDATE " . SESSION_TABLE . "\n                     SET s_id_used = 1\n                     WHERE s_id = :s_id\n                       AND playerID = :playerID\n                       AND s_id_used = 0");
$sql->bindValue('s_id', $sessionID, PDO::PARAM_STR);
$sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
if (!$sql->execute() || $sql->rowCount() == 0) {
    header("Location: " . Config::GAME_END_URL . "?id=wrongSessionID");
    exit;
}
// get player by playerID for session
$player = Player::getPlayer($playerID);
if (!$player) {
    header("Location: " . Config::GAME_END_URL . "?id=wrongSessionID");
    exit;
}
// put user, its session and nogfx flag into session
$_SESSION['player'] = $player;
$_SESSION['nogfx'] = $noGfx == 1;
$_SESSION['session'] = $sessionRow;
$_SESSION['logintime'] = date("YmdHis");
// initiate Session messages
$_SESSION['messages'] = array();
// go to start url
header("Location: " . Config::GAME_START_URL);
exit;
Example #11
0
function unitAction($caveID, &$meineHoehlen)
{
    global $config, $db, $MAX_RESOURCE, $MOVEMENTCOSTCONSTANT, $MOVEMENTSPEEDCONSTANT, $params, $resourceTypeList, $unitTypeList, $FUELRESOURCEID;
    // get movements
    $ua_movements = Movement::getMovements();
    $details = $meineHoehlen[$caveID];
    /***************************************************************************/
    /**                                                                       **/
    /** CHECK ARTEFACTS                                                       **/
    /**                                                                       **/
    /***************************************************************************/
    // artefact moving: get ID if any
    //
    // $params->POST->myartefacts will be
    //   NULL, if it is not set at all
    //   -1 when choosing no artefact to move
    //   0 if there was a real choice
    // default: Move No Artefact (this var holds the artefactID to move)
    $moveArtefact = 0;
    // this array shall contain the artefacts if any
    $myartefacts = array();
    // does the cave contain an artefact at least?
    if ($details['artefacts'] > 0) {
        // get artefacts
        $myartefacts = artefact_getArtefactsReadyForMovement($caveID);
        // was an artefact chosen?
        if ((int) $params->POST->myartefacts > 0) {
            $tempID = (int) $params->POST->myartefacts;
            // now check, whether this artefactID belongs to this cave
            foreach ($myartefacts as $key => $value) {
                // if found, set it
                if ($tempID == $value['artefactID']) {
                    $moveArtefact = $tempID;
                    break;
                }
            }
        }
    }
    // now $moveArtefact should contain 0 for 'move no artefact'
    // or the artefactID of the artefact to be moved
    /***************************************************************************/
    /***************************************************************************/
    /***************************************************************************/
    // put user, its session and nogfx flag into session
    $_SESSION['player'] = Player::getPlayer($params->SESSION->player->playerID);
    $params->SESSION->player = $_SESSION['player'];
    // get Map Size
    $size = getMapSize();
    $dim_x = ($size['maxX'] - $size['minX'] + 1) / 2;
    $dim_y = ($size['maxY'] - $size['minY'] + 1) / 2;
    $foodPerCave = eval('return ' . formula_parseToPHP($MOVEMENTCOSTCONSTANT . ';', '$details'));
    $minutesPerCave = eval('return ' . formula_parseToPHP($MOVEMENTSPEEDCONSTANT . ';', '$details'));
    $minutesPerCave *= MOVEMENT_TIME_BASE_FACTOR / 60;
    if (isset($params->POST->moveit) && sizeof($params->POST->unit)) {
        $targetXCoord = intval($params->POST->targetXCoord);
        $targetYCoord = intval($params->POST->targetYCoord);
        $targetCaveName = $params->POST->targetCaveName;
        $targetCaveID = intval($params->POST->targetCaveID);
        $movementID = intval($params->POST->movementID);
        // check for scripters
        check_timestamp($params->POST->tstamp);
        $validCaveName = FALSE;
        // targetCaveID >>> coords
        if (isset($targetCaveID) && $targetCaveID > 0) {
            $result = getCaveByID(intval($targetCaveID));
            if (sizeof($result) != 0) {
                $targetXCoord = $result['xCoord'];
                $targetYCoord = $result['yCoord'];
                $validCaveName = TRUE;
            }
            // name >>> coords
        } else {
            if (isset($targetCaveName)) {
                $result = getCaveByName($targetCaveName);
                if (sizeof($result) != 0) {
                    $targetXCoord = $result['xCoord'];
                    $targetYCoord = $result['yCoord'];
                    $validCaveName = TRUE;
                }
            }
        }
        // get target player
        $result = getCaveByCoords(intval($targetXCoord), intval($targetYCoord));
        if (sizeof($result) != 0) {
            $targetPlayer = new Player(getPlayerByID($result['playerID']));
        }
        // Array von Nullwerten befreien
        $unit = array_filter($params->POST->unit, "filterZeros");
        $unit = array_map("checkFormValues", $unit);
        $resource = array_map("checkFormValues", $params->POST->rohstoff);
        // Test, ob Einheitentragekapazität ausgelastet
        foreach ($resource as $resKey => $aRes) {
            $capacity = 0;
            foreach ($unit as $unitKey => $aUnit) {
                $capacity += $aUnit * $unitTypeList[$unitKey]->encumbranceList[$resKey];
            }
            if ($capacity < $aRes) {
                $overloaded = 1;
                break;
            }
        }
        if ($movementID == 2) {
            // move units/resources
            if (strtoupper($targetPlayer->tribe) != strtoupper($params->SESSION->player->tribe)) {
                //may tade in own tribe
                $ownTribe = $params->SESSION->player->tribe;
                $targetTribe = $targetPlayer->tribe;
                $targetIsNonPlayer = $targetPlayer->playerID == 0;
                $ownTribeAtWar = tribe_isAtWar($ownTribe, TRUE, $db);
                $targetTribeAtWar = tribe_isAtWar($targetTribe, TRUE, $db);
                $TribesMayTrade = relation_areAllies($ownTribe, $targetTribe, $db) || relation_areEnemys($ownTribe, $targetTribe, $db) || $targetIsNonPlayer;
                $denymovement_nonenemy = $ownTribeAtWar && !$TribesMayTrade;
                $denymovement_targetwar = $targetTribeAtWar && !$TribesMayTrade;
            }
        }
        if ($params->POST->movementID == 0) {
            $msg = _('Bitte Bewegungsart auswählen!');
        } else {
            if (!sizeof($unit)) {
                $msg = _('Es sind keine Einheiten ausgewählt!');
            } else {
                if (empty($targetXCoord) || empty($targetYCoord) and empty($targetCaveName)) {
                    $msg = _('Es fehlt eine Zielkoordinate oder ein Zielhöhlenname!');
                } else {
                    if (empty($targetXCoord) || empty($targetYCoord) and !empty($targetCaveName) and $validCaveName === FALSE) {
                        $msg = sprintf(_('Es gibt keine Höhle mit dem Namen "%s"!'), $targetCaveName);
                    } else {
                        if ($overloaded) {
                            $msg = _('Deine Krieger können die Menge an Ressourcen nicht tragen!!');
                        } else {
                            if (beginner_isCaveProtectedByCoord($targetXCoord, $targetYCoord, $db)) {
                                $msg = _('Die Zielhöhle steht unter Anfängerschutz.');
                            } else {
                                if (beginner_isCaveProtectedByID($caveID, $db)) {
                                    $msg = _('Ihre Höhle steht unter Anfängerschutz. Sie können den Schutz sofort unter dem Punkt <a href="?modus=cave_detail">Bericht über diese Höhle</a> beenden');
                                } else {
                                    if ($params->POST->movementID == 6 && cave_isCaveSecureByCoord($targetXCoord, $targetYCoord, $db)) {
                                        $msg = _('Sie können diese Höhle nicht übernehmen. Sie ist gegen Übernahmen geschützt.');
                                    } else {
                                        if ($denymovement_nonenemy) {
                                            $msg = _('Sie können im Krieg keine Einheiten zu unbeteiligten Parteien verschieben!');
                                        } else {
                                            if ($denymovement_targetwar) {
                                                $msg = _('Sie können keine Einheiten zu kriegführenden Stämmen verschieben, wenn Sie unbeteiligt sind.');
                                            } else {
                                                // Entfernung x Dauer pro Höhle x größter Geschwindigkeitsfaktor x Bewegungsfaktor
                                                $duration = ceil(getDistanceByCoords($details['xCoord'], $details['yCoord'], $targetXCoord, $targetYCoord) * $minutesPerCave * getMaxSpeedFactor($unit) * $ua_movements[$movementID]->speedfactor);
                                                $distance = ceil(getDistanceByCoords($details['xCoord'], $details['yCoord'], $targetXCoord, $targetYCoord));
                                                $tmpdist = 0;
                                                $i = 0;
                                                if ($distance > 15) {
                                                    $distance = $distance - 15;
                                                    $tmpdist = 15;
                                                    if (floor($distance / 5) < 11) {
                                                        $tmpdist += $distance % 5 * (1 - 0.1 * floor($distance / 5));
                                                    }
                                                    for ($i = 1; $i <= floor($distance / 5) && $i < 11; $i++) {
                                                        $tmpdist += 5 * (1 - 0.1 * ($i - 1));
                                                    }
                                                } else {
                                                    $tmpdist = $distance;
                                                }
                                                // Dauer x Rationen x Größe einer Ration x Bewegungsfaktor
                                                $reqFood = ceil($tmpdist * $minutesPerCave * getMaxSpeedFactor($unit) * $ua_movements[$movementID]->speedfactor * calcRequiredFood($unit) * $foodPerCave * $ua_movements[$movementID]->foodfactor);
                                                if ($details[$resourceTypeList[$FUELRESOURCEID]->dbFieldName] < $reqFood) {
                                                    $msg = _('Nicht genug Nahrung zum Ernähren der Krieger auf ihrem langen Marsch vorhanden!');
                                                } else {
                                                    $msgID = setMovementEvent($caveID, $details, $targetXCoord, $targetYCoord, $unit, $resource, $movementID, $reqFood, $duration, $moveArtefact, $minutesPerCave * $ua_movements[$movementID]->speedfactor);
                                                    switch ($msgID) {
                                                        case 0:
                                                            $msg = sprintf(_('Die Krieger wurden losgeschickt und haben %d Nahrung mitgenommen!'), $reqFood);
                                                            break;
                                                        case 1:
                                                            $msg = _('In diesen Koordinaten liegt keine Höhle!');
                                                            break;
                                                        case 2:
                                                            $msg = _('Für diese Bewegung sind nicht genügend Einheiten/Rohstoffe verfügbar!');
                                                            break;
                                                        case 3:
                                                            $msg = _('Schwerer Fehler: Bitte Admin kontaktieren!');
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (!empty($params->POST->eventID)) {
            $msgID = reverseMovementEvent($caveID, $params->POST->eventID);
            switch ($msgID) {
                case 0:
                    $msg = _('Die Einheiten kehren zurück!');
                    break;
                case 1:
                    $msg = _('Fehler bei der Rückkehr!');
                    break;
            }
        }
    }
    // refresh this cave
    $temp = getCaveSecure($caveID, $params->SESSION->player->playerID);
    $meineHoehlen[$caveID] = $details = $temp->nextRow(MYSQL_ASSOC);
    // make sure that bagged artefacts are not shown again
    if ($moveArtefact != 0) {
        $myartefacts = artefact_getArtefactsReadyForMovement($caveID);
    }
    // //////////////////////////////////////////////////////////////
    // Create the page
    // //////////////////////////////////////////////////////////////
    $template = tmpl_open($params->SESSION->player->getTemplatePath() . 'unitaction.ihtml');
    // messages
    if (isset($msg)) {
        tmpl_set($template, '/MESSAGE/msg', $msg);
    }
    // javascript support
    tmpl_set($template, 'currentX', $details['xCoord']);
    tmpl_set($template, 'currentY', $details['yCoord']);
    tmpl_set($template, 'dim_x', $dim_x);
    tmpl_set($template, 'dim_y', $dim_y);
    tmpl_set($template, 'speed', $minutesPerCave);
    tmpl_set($template, 'fuel_id', $FUELRESOURCEID);
    tmpl_set($template, 'fuel_name', $resourceTypeList[$FUELRESOURCEID]->name);
    tmpl_set($template, 'movementcostconstant', $foodPerCave);
    tmpl_set($template, "resourceTypes", $MAX_RESOURCE);
    tmpl_set($template, "rules_path", RULES_PATH);
    // movements
    $selectable_movements = array();
    foreach ($ua_movements as $value) {
        if ($value->playerMayChoose) {
            $selectable_movements[] = get_object_vars($value);
        }
    }
    tmpl_set($template, 'SELECTACTION', $selectable_movements);
    // resources
    $resources = array();
    for ($res = 0; $res < sizeof($resourceTypeList); $res++) {
        if (!$resourceTypeList[$res]->nodocumentation) {
            $resources[] = array('resourceID' => $resourceTypeList[$res]->resourceID, 'name' => $resourceTypeList[$res]->name, 'currentAmount' => "0" + $details[$resourceTypeList[$res]->dbFieldName], 'dbFieldName' => $resourceTypeList[$res]->dbFieldName);
        }
    }
    tmpl_set($template, 'RESOURCE', $resources);
    tmpl_set($template, 'TOTAL', $resources);
    tmpl_set($template, 'RESOURCE_LUGGAGE', $resources);
    // units table
    $unitprops = array();
    $units = array();
    for ($i = 0; $i < sizeof($unitTypeList); $i++) {
        // if no units of this type, next type
        if (!$details[$unitTypeList[$i]->dbFieldName]) {
            continue;
        }
        $temp = array();
        $encumbrance = array();
        for ($j = 0; $j < count($resourceTypeList); $j++) {
            if (!$resourceTypeList[$j]->nodocumentation) {
                $encumbrance[$j] = array('resourceID' => $j, 'load' => "0" + $unitTypeList[$i]->encumbranceList[$j]);
                $temp[] = "0" + $unitTypeList[$i]->encumbranceList[$j];
            }
        }
        $unitprops[] = array('unitID' => $unitTypeList[$i]->unitID, 'foodCost' => $unitTypeList[$i]->foodCost, 'speedFactor' => $unitTypeList[$i]->wayCost, 'resourceLoad' => implode(",", $temp), 'maxWarriorAnzahl' => $details[$unitTypeList[$i]->dbFieldName]);
        $units[] = array('name' => $unitTypeList[$i]->name, 'modus' => UNIT_PROPERTIES, 'unitID' => $unitTypeList[$i]->unitID, 'foodCost' => $unitTypeList[$i]->foodCost, 'speedFactor' => $unitTypeList[$i]->wayCost, 'maxWarriorAnzahl' => $details[$unitTypeList[$i]->dbFieldName], 'warriorID' => $i, 'ENCUMBRANCE' => $encumbrance);
    }
    tmpl_set($template, 'UNITPROPS', $unitprops);
    tmpl_set($template, 'SELECTWARRIOR', $units);
    // weitergereichte Koordinaten
    if (empty($params->POST->movementID)) {
        tmpl_set($template, 'targetXCoord', $params->POST->targetXCoord);
        tmpl_set($template, 'targetYCoord', $params->POST->targetYCoord);
        tmpl_set($template, 'targetCaveName', $params->POST->targetCaveName);
    }
    // weitere Paramter
    $hidden = array(array('name' => 'modus', 'value' => UNIT_MOVEMENT), array('name' => 'moveit', 'value' => 'true'), array('name' => 'trigger', 'value' => 'self'), array('name' => 'tstamp', 'value' => "" . time()));
    tmpl_set($template, 'PARAMS', $hidden);
    $movements = digest_getMovements(array($caveID => $details), array(), true);
    //$movements = digest_getMovements($meineHoehlen, array(), true);
    foreach ($movements as $move) {
        if ($move['isOwnMovement']) {
            tmpl_iterate($template, 'MOVEMENT/MOVE');
            tmpl_set($template, 'MOVEMENT/MOVE', $move);
        } else {
            tmpl_iterate($template, 'OPPMOVEMENT/MOVE');
            tmpl_set($template, 'OPPMOVEMENT/MOVE', $move);
        }
    }
    // artefakte
    if (sizeof($myartefacts) != 0) {
        tmpl_set($template, '/ARTEFACTS/ARTEFACT', $myartefacts);
    }
    // Module "CaveBookmarks" Integration
    // FIXME should know whether the module is installed
    if (TRUE) {
        // show CAVEBOOKMARKS context
        tmpl_set($template, '/CAVEBOOKMARKS/iterate', '');
        // get model
        $cb_model = new CaveBookmarks_Model();
        // get bookmarks
        $bookmarks = $cb_model->getCaveBookmarks(true);
        // set bookmarks
        if (sizeof($bookmarks)) {
            tmpl_set($template, '/CAVEBOOKMARKS/CAVEBOOKMARK', $bookmarks);
            tmpl_set($template, '/CAVEBOOKMARKS/CAVEBOOKMARKJS', $bookmarks);
        }
    }
    return tmpl_parse($template);
}
Example #12
0
function unit_Movement($caveID, &$ownCave)
{
    global $db, $template;
    $safeForm = true;
    // get movements
    $ua_movements = Movement::getMovements();
    $details = $ownCave[$caveID];
    /***************************************************************************/
    /**                                                                       **/
    /** CHECK ARTEFACTS                                                       **/
    /**                                                                       **/
    /***************************************************************************/
    // artefact moving: get ID if any
    //
    // $params->POST->myartefacts will be
    //   NULL, if it is not set at all
    //   -1 when choosing no artefact to move
    //   0 if there was a real choice
    // default: Move No Artefact (this var holds the artefactID to move)
    $moveArtefact = 0;
    // this array shall contain the artefacts if any
    $myartefacts = array();
    // does the cave contain an artefact at least?
    if ($details['artefacts'] > 0) {
        // get artefacts
        $myartefacts = artefact_getArtefactsReadyForMovement($caveID);
        $moveArtefactID = Request::getVar('myartefacts', 0);
        // was an artefact chosen?
        if ($moveArtefactID > 0) {
            // now check, whether this artefactID belongs to this cave
            foreach ($myartefacts as $key => $value) {
                // if found, set it
                if ($moveArtefactID == $value['artefactID']) {
                    $moveArtefact = $moveArtefactID;
                    break;
                }
            }
        }
    }
    // now $moveArtefact should contain 0 for 'move no artefact'
    // or the artefactID of the artefact to be moved
    /***************************************************************************/
    /***************************************************************************/
    /***************************************************************************/
    /**
     * HERO MOVEMENT
     */
    $moveHero = 0;
    if ($details['hero'] != 0) {
        $hero = getHeroByPlayer($_SESSION['player']->playerID);
        if ($hero['isAlive'] != 1) {
            $details['hero'] = 0;
        }
    }
    if ($details['hero'] != 0 && Request::getVar('moveHero', false) == true) {
        $moveHero = $details['hero'];
    }
    /**
     * END HERO MOVEMENTS
     */
    // put user, its session and nogfx flag into session
    $_SESSION['player'] = Player::getPlayer($_SESSION['player']->playerID);
    // get Map Size
    $size = getMapSize();
    $dim_x = ($size['maxX'] - $size['minX'] + 1) / 2;
    $dim_y = ($size['maxY'] - $size['minY'] + 1) / 2;
    $foodPerCave = eval('return ' . formula_parseToPHP(GameConstants::MOVEMENT_COST . ';', '$details'));
    $minutesPerCave = eval('return ' . formula_parseToPHP(GameConstants::MOVEMENT_SPEED . ';', '$details'));
    $minutesPerCave *= MOVEMENT_TIME_BASE_FACTOR / 60;
    if (Request::getVar('moveit', false) && sizeof(Request::getVar('unit', array('' => '')))) {
        $targetXCoord = Request::getVar('targetXCoord', 0);
        $targetYCoord = Request::getVar('targetYCoord', 0);
        $targetCaveName = Request::getVar('targetCaveName', '');
        $targetCaveID = Request::getVar('targetCaveID', 0);
        $movementID = Request::getVar('movementID', 0);
        // check for scripters
        check_timestamp(Request::getVar('tstamp', 0));
        $validCaveName = false;
        // targetCaveID >>> coords
        if ($targetCaveID > 0) {
            $result = getCaveByID(intval($targetCaveID));
            if (sizeof($result) != 0) {
                $targetXCoord = $result['xCoord'];
                $targetYCoord = $result['yCoord'];
                $validCaveName = true;
            }
            // name >>> coords
        } else {
            if ($targetCaveName != "") {
                $result = getCaveByName($targetCaveName);
                if (sizeof($result) != 0) {
                    $targetXCoord = $result['xCoord'];
                    $targetYCoord = $result['yCoord'];
                    $validCaveName = true;
                }
            }
        }
        // get target player
        $result = getCaveByCoords(intval($targetXCoord), intval($targetYCoord));
        if (sizeof($result) != 0) {
            $targetPlayer = new Player(getPlayerByID($result['playerID']));
        }
        // Array von Nullwerten befreien
        $unit = array_filter(Request::getVar('unit', array('' => '')), "filterZeros");
        $unit = array_map("checkFormValues", $unit);
        $resource = array_map("checkFormValues", Request::getVar('rohstoff', array('' => '')));
        // Test, ob Einheitentragekapazität ausgelastet
        $overloaded = 0;
        foreach ($resource as $resKey => $aRes) {
            $capacity = 0;
            foreach ($unit as $unitKey => $aUnit) {
                if (isset($GLOBALS['unitTypeList'][$unitKey]->encumbranceList[$resKey])) {
                    $capacity += $aUnit * $GLOBALS['unitTypeList'][$unitKey]->encumbranceList[$resKey];
                }
            }
            if ($capacity < $aRes) {
                $overloaded = 1;
                break;
            }
        }
        $denymovement_nonenemy = false;
        $denymovement_targetwar = false;
        if ($movementID == 2) {
            // move units/resources
            if (strtoupper($targetPlayer->tribe) != strtoupper($_SESSION['player']->tribe)) {
                //may tade in own tribe
                $ownTribe = $_SESSION['player']->tribe;
                $targetTribe = $targetPlayer->tribe;
                $targetIsNonPlayer = $targetPlayer->playerID == 0;
                $ownTribeAtWar = tribe_isAtWar($ownTribe, TRUE);
                $targetTribeAtWar = tribe_isAtWar($targetTribe, TRUE);
                $TribesMayTrade = relation_areAllies($ownTribe, $targetTribe) || relation_areEnemys($ownTribe, $targetTribe) || $targetIsNonPlayer;
                $denymovement_nonenemy = $ownTribeAtWar && !$TribesMayTrade;
                $denymovement_targetwar = $targetTribeAtWar && !$TribesMayTrade;
            }
        }
        // check if army is small enough for hero
        $denymovement_hero = false;
        if ($moveHero && (Request::getVar('movementID', 0) == 3 || Request::getVar('movementID', 0) == 6)) {
            //calculate size of army
            $armySize = 0;
            foreach ($unit as $unitID => $value) {
                $armySize += $GLOBALS['unitTypeList'][$unitID]->hitPoints * $value;
            }
            if ($armySize > $hero['exp']) {
                $denymovement_hero = true;
            }
        }
        if (Request::getVar('movementID', 0) == 0) {
            $msg = array('type' => 'error', 'message' => _('Bitte Bewegungsart auswählen!'));
            $moveHero = 0;
        } else {
            if (!sizeof($unit)) {
                $msg = array('type' => 'error', 'message' => _('Es sind keine Einheiten ausgewählt!'));
                $moveHero = 0;
            } else {
                if (($targetXCoord == 0 || $targetYCoord == 0) && $targetCaveName == "") {
                    $msg = array('type' => 'error', 'message' => _('Es fehlt eine Zielkoordinate oder ein Zielhöhlenname!'));
                    $moveHero = 0;
                } else {
                    if (($targetXCoord == 0 || $targetYCoord == 0) && !($targetCaveName == "") && $validCaveName === FALSE) {
                        $msg = array('type' => 'error', 'message' => sprintf(_('Es gibt keine Höhle mit dem Namen "%s"!'), $targetCaveName));
                        $moveHero = 0;
                    } else {
                        if ($overloaded) {
                            $msg = array('type' => 'error', 'message' => _('Deine Krieger können die Menge an Ressourcen nicht tragen!!'));
                            $moveHero = 0;
                        } else {
                            if (beginner_isCaveProtectedByCoord($targetXCoord, $targetYCoord)) {
                                $msg = array('type' => 'error', 'message' => _('Die Zielhöhle steht unter Anfängerschutz.'));
                                $moveHero = 0;
                            } else {
                                if (beginner_isCaveProtectedByID($caveID)) {
                                    $msg = array('type' => 'error', 'message' => _('Ihre Höhle steht unter Anfängerschutz. Sie können den Schutz sofort unter dem Punkt <a href="?modus=cave_detail">Bericht über diese Höhle</a> beenden'));
                                    $moveHero = 0;
                                } else {
                                    if (Request::getVar('movementID', 0) == 6 && cave_isCaveSecureByCoord($targetXCoord, $targetYCoord)) {
                                        $msg = array('type' => 'error', 'message' => _('Sie können diese Höhle nicht übernehmen. Sie ist gegen übernahmen geschützt.'));
                                        $moveHero = 0;
                                    } else {
                                        if ($denymovement_nonenemy) {
                                            $msg = array('type' => 'error', 'message' => _('Sie können im Krieg keine Einheiten zu unbeteiligten Parteien verschieben!'));
                                        } else {
                                            if ($denymovement_targetwar) {
                                                $msg = array('type' => 'error', 'message' => _('Sie können keine Einheiten zu kriegführenden Stämmen verschieben, wenn Sie unbeteiligt sind.'));
                                                $moveHero = 0;
                                            } else {
                                                if ($denymovement_hero) {
                                                    $msg = array('type' => 'error', 'message' => _('Die Armee ist zu groß um vom Helden unterstützt zu werden!'));
                                                    $moveHero = 0;
                                                } else {
                                                    // Entfernung x Dauer pro Höhle x größter Geschwindigkeitsfaktor x Bewegungsfaktor
                                                    $duration = ceil(getDistanceByCoords($details['xCoord'], $details['yCoord'], $targetXCoord, $targetYCoord) * $minutesPerCave * getMaxSpeedFactor($unit) * $ua_movements[$movementID]->speedfactor);
                                                    $distance = ceil(getDistanceByCoords($details['xCoord'], $details['yCoord'], $targetXCoord, $targetYCoord));
                                                    $tmpdist = 0;
                                                    $i = 0;
                                                    if ($distance > 15) {
                                                        $distance = $distance - 15;
                                                        $tmpdist = 15;
                                                        if (floor($distance / 5) < 11) {
                                                            $tmpdist += $distance % 5 * (1 - 0.1 * floor($distance / 5));
                                                        }
                                                        for ($i = 1; $i <= floor($distance / 5) && $i < 11; $i++) {
                                                            $tmpdist += 5 * (1 - 0.1 * ($i - 1));
                                                        }
                                                    } else {
                                                        $tmpdist = $distance;
                                                    }
                                                    // Dauer x Rationen x Größe einer Ration x Bewegungsfaktor
                                                    $reqFood = ceil($tmpdist * $minutesPerCave * getMaxSpeedFactor($unit) * $ua_movements[$movementID]->speedfactor * calcRequiredFood($unit) * $foodPerCave * $ua_movements[$movementID]->foodfactor);
                                                    if ($details[$GLOBALS['resourceTypeList'][GameConstants::FUEL_RESOURCE_ID]->dbFieldName] < $reqFood) {
                                                        $msg = array('type' => 'error', 'message' => _('Nicht genug Nahrung zum Ernähren der Krieger auf ihrem langen Marsch vorhanden!'));
                                                    } else {
                                                        $msgID = setMovementEvent($caveID, $details, $targetXCoord, $targetYCoord, $unit, $resource, $movementID, $reqFood, $duration, $moveArtefact, $moveHero, $minutesPerCave * $ua_movements[$movementID]->speedfactor);
                                                        switch ($msgID) {
                                                            case 0:
                                                                $msg = array('type' => 'success', 'message' => sprintf(_('Die Krieger wurden losgeschickt und haben %d Nahrung mitgenommen!'), $reqFood));
                                                                $safeForm = false;
                                                                break;
                                                            case 1:
                                                                $msg = array('type' => 'error', 'message' => _('In diesen Koordinaten liegt keine Höhle!'));
                                                                $moveHero = 0;
                                                                break;
                                                            case 2:
                                                                $msg = array('type' => 'error', 'message' => _('Für diese Bewegung sind nicht genügend Einheiten/Rohstoffe verfügbar!'));
                                                                $moveHero = 0;
                                                                break;
                                                            case 3:
                                                                $msg = array('type' => 'error', 'message' => _('Schwerer Fehler: Bitte Admin kontaktieren!'));
                                                                $moveHero = 0;
                                                                break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (Request::isPost('action') && Request::getVar('action', '') == 'cancel' && ($eventID = Request::getVar('eventID', 0))) {
            $msgID = reverseMovementEvent($caveID, $eventID);
            switch ($msgID) {
                case 0:
                    $msg = array('type' => 'success', 'message' => _('Die Einheiten kehren zurück!'));
                    break;
                case 1:
                    $msg = array('type' => 'error', 'message' => _('Fehler bei der Rückkehr!'));
                    break;
            }
        } else {
            if (Request::getVar('moveit', false) && !sizeof(Request::getVar('unit', array('' => '')))) {
                $msg = array('type' => 'error', 'message' => _('Einheiten mitnehmen?'));
            }
        }
    }
    // refresh this cave
    $temp = getCaveSecure($caveID, $_SESSION['player']->playerID);
    $ownCave[$caveID] = $details = $temp;
    // make sure that bagged artefacts are not shown again
    if ($moveArtefact != 0) {
        $myartefacts = artefact_getArtefactsReadyForMovement($caveID);
    }
    // make sure that moved hero is not shown again
    if ($moveHero != 0) {
        $details['hero'] = 0;
    }
    // //////////////////////////////////////////////////////////////
    // Create the page
    // //////////////////////////////////////////////////////////////
    // open template
    $template->setFile('unitMovement.tmpl');
    $template->addVars(array('currentX' => $details['xCoord'], 'currentY' => $details['yCoord'], 'dim_x' => $dim_x, 'dim_y' => $dim_y, 'speed' => $minutesPerCave, 'fuel_id' => GameConstants::FUEL_RESOURCE_ID, 'fuel_name' => $GLOBALS['resourceTypeList'][GameConstants::FUEL_RESOURCE_ID]->name, 'movement_cost_constant' => $foodPerCave, 'resource_types' => GameConstants::MAX_RESOURCE, 'status_msg' => isset($msg) ? $msg : ''));
    // movements
    $selectable_movements = array();
    foreach ($ua_movements as $value) {
        if ($value->playerMayChoose) {
            $selectable_movements[] = get_object_vars($value);
        }
    }
    $template->addVar('selectable_movements', $selectable_movements);
    // resources
    $resources = array();
    foreach ($GLOBALS['resourceTypeList'] as $resourceID => $dummy) {
        if (!$GLOBALS['resourceTypeList'][$resourceID]->nodocumentation) {
            $resources[] = array('resource_id' => $GLOBALS['resourceTypeList'][$resourceID]->resourceID, 'name' => $GLOBALS['resourceTypeList'][$resourceID]->name, 'current_amount' => "0" + $details[$GLOBALS['resourceTypeList'][$resourceID]->dbFieldName], 'dbFieldName' => $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName, 'value' => $safeForm && isset($resource[$resourceID]) && $resource[$resourceID] > 0 ? $resource[$resourceID] : '');
        }
    }
    $template->addVar('resource', $resources);
    // units table
    $unitprops = array();
    $units = array();
    foreach ($GLOBALS['unitTypeList'] as $unitID => $dummy) {
        // if no units of this type, next type
        if (!$details[$GLOBALS['unitTypeList'][$unitID]->dbFieldName]) {
            continue;
        }
        $temp = array();
        $encumbrance = array();
        foreach ($GLOBALS['resourceTypeList'] as $resourceID => $dummy) {
            if (!$GLOBALS['resourceTypeList'][$resourceID]->nodocumentation) {
                $encumbrance[$resourceID] = array('resourceID' => $resourceID, 'load' => "0" + (isset($GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID]) ? $GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID] : 0));
                $temp[] = "0" + (isset($GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID]) ? $GLOBALS['unitTypeList'][$unitID]->encumbranceList[$resourceID] : 0);
            }
        }
        $units[] = array('name' => $GLOBALS['unitTypeList'][$unitID]->name, 'unit_id' => $unitID, 'food_cost' => $GLOBALS['unitTypeList'][$unitID]->foodCost, 'resource_load' => implode(",", $temp), 'speed_factor' => $GLOBALS['unitTypeList'][$unitID]->wayCost, 'max_unit_count' => $details[$GLOBALS['unitTypeList'][$unitID]->dbFieldName], 'encumbrance' => $encumbrance, 'hitPoints' => $GLOBALS['unitTypeList'][$unitID]->hitPoints, 'value' => $safeForm && isset($unit[$unitID]) ? $unit[$unitID] : '');
    }
    $template->addVar('unit_list', $units);
    // weitergereichte Koordinaten
    if (!Request::getVar('movementID', 0) || $safeForm) {
        if (Request::getVar('targetCaveID', 0) > 0) {
            $caveData = getCaveByID(Request::getVar('targetCaveID', 0));
            $template->addVars(array('target_x_coord' => $caveData['xCoord'], 'target_y_coord' => $caveData['yCoord'], 'target_cave_name' => $caveData['name']));
        } else {
            $template->addVars(array('target_x_coord' => Request::getVar('targetXCoord', ''), 'target_y_coord' => Request::getVar('targetYCoord', ''), 'target_cave_name' => Request::getVar('targetCaveName', '')));
        }
    }
    // weitere Paramter
    $template->addVar('params', array(array('name' => 'modus', 'value' => UNIT_MOVEMENT), array('name' => 'moveit', 'value' => 'true'), array('name' => 'trigger', 'value' => 'self'), array('name' => 'tstamp', 'value' => "" . time())));
    $movements = digest_getMovements(array($caveID => $details), array(), true);
    $ownMovement = $oppMovement = array();
    foreach ($movements as $move) {
        if ($move['isOwnMovement']) {
            $ownMovement[] = $move;
        } else {
            $oppMovement[] = $move;
        }
    }
    $template->addVars(array('ownMovement' => $ownMovement, 'oppMovement' => $oppMovement));
    // artefakte
    if (sizeof($myartefacts) != 0) {
        //tmpl_set($template, '/ARTEFACTS/ARTEFACT', $myartefacts);
        $template->addVar('artefact', $myartefacts);
    }
    // hero
    if ($details['hero'] != 0) {
        $template->addVar('hero', $hero);
    }
    // Module "CaveBookmarks" Integration
    // FIXME should know whether the module is installed
    if (TRUE) {
        // get model
        $cb_model = new CaveBookmarks_Model();
        // get bookmarks
        $bookmarks = $cb_model->getCaveBookmarks(true);
        // set bookmarks
        if (sizeof($bookmarks)) {
            $template->addVar('bookmarks_cave', $bookmarks);
        }
    }
}
function effect_getEffectWonderDetailContent($caveID, $caveData)
{
    global $buildingTypeList, $defenseSystemTypeList, $resourceTypeList, $scienceTypeList, $unitTypeList, $wonderTypeList, $effectTypeList, $terrainList, $config, $params, $db;
    // don't show the resource bar
    $no_resource_flag = 1;
    // open the template
    $template = tmpl_open($params->SESSION->player->getTemplatePath() . 'effectWonderDetail.ihtml');
    $wonders = wonder_getActiveWondersForCaveID($caveID, $db);
    $wondersData = array();
    if ($wonders) {
        foreach ($wonders as $key => $data) {
            if ($wonderTypeList[$data['wonderID']]->groupID == 0 or $wonderTypeList[$data['wonderID']]->groupID == 3) {
                $wonderData = array("name" => $wonderTypeList[$data['wonderID']]->name, "end" => $data['end_time']);
                $effectsData = array();
                // iterating through effectTypes
                foreach ($effectTypeList as $effect) {
                    if ($value = $data[$effect->dbFieldName] + 0) {
                        $effectsData[] = array("name" => $effect->name, "value" => ($value > 0 ? "+" : "") . $value);
                    }
                }
                // iterating through resourceTypes
                foreach ($resourceTypeList as $resource) {
                    if ($value = $data[$resource->dbFieldName] + 0) {
                        $effectsData[] = array("name" => $resource->name, "value" => ($value > 0 ? "+" : "") . $value);
                    }
                }
                // iterating through buildingTypes
                foreach ($buildingTypeList as $building) {
                    if ($value = $data[$building->dbFieldName] + 0) {
                        $effectsData[] = array("name" => $building->name, "value" => ($value > 0 ? "+" : "") . $value);
                    }
                }
                // iterating through scienceTypes
                foreach ($scienceTypeList as $science) {
                    if ($value = $data[$science->dbFieldName] + 0) {
                        $effectsData[] = array("name" => $science->name, "value" => ($value > 0 ? "+" : "") . $value);
                    }
                }
                // iterating through unitTypes
                foreach ($unitTypeList as $unit) {
                    if ($value = $data[$unit->dbFieldName] + 0) {
                        $effectsData[] = array("name" => $unit->name, "value" => ($value > 0 ? "+" : "") . $value);
                    }
                }
                // iterating through defenseSystemTypes
                foreach ($defenseSystemTypeList as $defenseSystem) {
                    if ($value = $data[$defenseSystem->dbFieldName] + 0) {
                        $effectsData[] = array("name" => $defenseSystem->name, "value" => ($value > 0 ? "+" : "") . $value);
                    }
                }
                $wonderData['EFFECT'] = $effectsData;
                $wondersData[] = $wonderData;
            }
        }
        // end iterating through active wonders
    }
    // ADDED by chris--- for terrain effects ****************************
    global $effect, $effectname;
    $terraineffectData = array();
    $cave = getCaveByID($caveID);
    $terrainvalue = $cave['terrain'];
    $terraineffectsData[] = array("name" => $terrainList[$terrainvalue]['name'] . ":", "value" => "");
    for ($t = 0; $t < count($effect[$terrainvalue]); $t++) {
        $effectvalue = explode(" = ", $effect[$terrainvalue][$t]);
        $effectkey[$t] = $effectvalue[0];
        $effectv[$t] = substr($effectvalue[1], 1, -1);
        $terraineffectsData[] = array("name" => $effectname[$terrainvalue][$t], "value" => $effectv[$t]);
    }
    // *******************************************************************
    $effectsData = array();
    foreach ($effectTypeList as $data) {
        $value = $caveData[$data->dbFieldName] + 0;
        if ($value) {
            $effectsData[] = array("name" => $data->name, "value" => $value);
        }
    }
    // end iterating through effectTypes
    $data = array();
    if (!sizeof($wondersData)) {
        $data['NOWONDER'] = array('dummy' => "");
    } else {
        $data['WONDER'] = $wondersData;
    }
    if (!sizeof($effectsData)) {
        $data['NOEFFECT'] = array('dummy' => "");
    } else {
        $data['EFFECT'] = $effectsData;
    }
    if (sizeof($terraineffectsData) < 2) {
        $data['TERRAINNOEFFECT'] = array('dummy' => "");
    } else {
        $data['TERRAINEFFECT'] = $terraineffectsData;
    }
    // put user, its session and nogfx flag into session
    $_SESSION['player'] = Player::getPlayer($params->SESSION->player->playerID);
    $params->SESSION->player = $_SESSION['player'];
    $data['farmpoints'] = $params->SESSION->player->fame;
    $data['rules_path'] = RULES_PATH;
    tmpl_set($template, "/", $data);
    return tmpl_parse($template);
}
Example #14
0
function artefact_getDetail($caveID, &$myCaves)
{
    global $template;
    $messageText = array(-5 => array('type' => 'error', 'message' => _('Dieses Artefakt kann nicht noch einmal eingeweiht werden.')), -4 => array('type' => 'error', 'message' => _('Fehler: Artefakt konnte nicht auf ARTEFACT_INITIATING gestellt werden.')), -3 => array('type' => 'error', 'message' => _('Sie weihen bereits ein anderes Artefakt ein.')), -2 => array('type' => 'error', 'message' => _('Es fehlen die notwendigen Voraussetzungen.')), -1 => array('type' => 'error', 'message' => _('Fehler: Ritual nicht gefunden.')), 0 => array('type' => 'notice', 'message' => _('Über dieses Artefakt weiß man nichts!')), 1 => array('type' => 'success', 'message' => _('Die Einweihung des Artefakts wurde gestartet!')));
    // open template
    $template->setFile('artefactDetail.tmpl');
    $show_artefact = TRUE;
    $artefactID = Request::getVar('artefactID', 0);
    $artefact = artefact_getArtefactByID($artefactID);
    if (empty($artefact)) {
        $messageID = 0;
    } else {
        $description_initiated = $artefact['description_initiated'];
        unset($artefact['description_initiated']);
        // Gott oder nicht?
        if ($_SESSION['player']->tribe != GOD_ALLY) {
            // gibts nicht oder nicht in einer Höhle
            if (!$artefact['caveID']) {
                $show_artefact = FALSE;
            } else {
                $cave = getCaveByID($artefact['caveID']);
                // leere Höhle
                if (!$cave['playerID']) {
                    $show_artefact = FALSE;
                } else {
                    $owner = Player::getPlayer($cave['playerID']);
                    // Besitzer ist ein Gott
                    if ($owner->tribe == GOD_ALLY) {
                        $show_artefact = FALSE;
                    }
                }
            }
        }
        $showRitual = 0;
        $showStatus = 0;
        $template->addVars(array('show_artefact' => $show_artefact));
        if ($show_artefact) {
            $artefact['img'] = $artefact['uninitiationImg'];
            // Bild vom uninitalisierten Artefakt per default anzeigen!
            // eigene Höhle ...
            if (isset($myCaves[$artefact['caveID']])) {
                $showStatus = 1;
                // Ritual ausführen?
                if (Request::isPost('initiate')) {
                    $messageID = artefact_beginInitiation($artefact);
                    // reload
                    $myCaves = getCaves($_SESSION['player']->playerID);
                    // wenn noch uneingeweiht und in der "richtigen" Höhle, ritual zeigen
                } else {
                    if ($artefact['caveID'] == $caveID && $artefact['initiated'] == ARTEFACT_UNINITIATED) {
                        // Check, ob bereits eingeweiht wird.
                        if (sizeof(artefact_getArtefactInitiationsForCave($caveID)) == 0) {
                            $showRitual = 1;
                            // Hol das Einweihungsritual
                            $ritual = artefact_getRitualByID($artefact['initiationID']);
                            // Hol die Kosten und beurteile ob genug da ist
                            $merged_game_rules = array_merge($GLOBALS['resourceTypeList'], $GLOBALS['buildingTypeList'], $GLOBALS['unitTypeList'], $GLOBALS['scienceTypeList'], $GLOBALS['defenseSystemTypeList']);
                            $cost = array();
                            foreach ($merged_game_rules as $val) {
                                if (isset($ritual[$val->dbFieldName])) {
                                    if ($ritual[$val->dbFieldName]) {
                                        $object_context = ceil($ritual[$val->dbFieldName]) > floor($myCaves[$artefact['caveID']][$val->dbFieldName]) ? 'less-' : 'enough ';
                                        array_push($cost, array('object' => $val->name, 'amount' => $ritual[$val->dbFieldName], 'class' => $object_context));
                                    }
                                }
                            }
                            $artefact['initiation'] = array('cost' => $cost, 'name' => $ritual['name'], 'description' => $ritual['description'], 'duration' => time_formatDuration($ritual['duration']), 'initiate' => 1);
                        } else {
                            $showRitual = -1;
                        }
                    } elseif ($artefact['caveID'] == $caveID && $artefact['initiated'] == ARTEFACT_INITIATING) {
                        // Arte wird gerade eingeweiht
                        $showRitual = -1;
                    }
                }
                // Besitzer des Artefaktes und initalisiert? Alle Daten des Artefakts anzeigen
                if ($artefact['initiated'] == ARTEFACT_INITIATED && isset($myCaves[$artefact['caveID']])) {
                    $artefact['name'] = $artefact['name_initiated'];
                    $artefact['description_initiated'] = $description_initiated;
                    $artefact['img'] = $artefact['initiationImg'];
                }
            }
            $template->addVars(array('artefact' => $artefact));
            $template->addVars(array('showRitual' => $showRitual));
            $template->addVars(array('showStatus' => $showStatus));
        } else {
            // über dieses Artefakt weiß man nichts!
            $messageID = 0;
        }
    }
    $template->addVar('status_msg', isset($messageID) ? $messageText[$messageID] : '');
}
Example #15
0
/** This function returns basic hero details
 *
 *  @param caveID       the current caveID
 *  @param ownCaves  all the data of all your caves
 */
function hero_getHeroDetail($caveID, &$ownCaves)
{
    global $db, $template;
    // open template
    $template->setFile('hero.tmpl');
    // get current playerID by user
    $playerID = $_SESSION['player']->playerID;
    $player = Player::getPlayer($playerID, true);
    $newhero = false;
    $messageText = array(-24 => array('type' => 'error', 'message' => _('Es können nur Rohstoffe aus der aktuellen Höhle geopfert werden!')), -23 => array('type' => 'error', 'message' => _('Die Fähigkeit wurde schon erlernt!')), -22 => array('type' => 'error', 'message' => _('Dein Held hat den falschen Typ, um die Fähigkeit zu erlernen!')), -21 => array('type' => 'error', 'message' => _('Fehler beim Erlernen der Fähigkeit!')), -20 => array('type' => 'error', 'message' => _('Dein Held hat nicht das erforderliche Level!')), -19 => array('type' => 'error', 'message' => _('Fehler beim Eintragen des neuen Heldentyps!')), -18 => array('type' => 'error', 'message' => _('Euer Held ist tot!')), -17 => array('type' => 'error', 'message' => _('Euer Held ist gar nicht tot!')), -16 => array('type' => 'error', 'message' => _('Fehler beim Eintragen der Erfahrungspunkte nach der Opferung!')), -15 => array('type' => 'error', 'message' => _('Fehler beim Abziehen der geopferten Rohstoffe!')), -14 => array('type' => 'error', 'message' => _('Nicht genug Rohstoffe zum Opfern vorhanden!')), -13 => array('type' => 'error', 'message' => _('Fehler beim Holen der Opferwerte!')), -12 => array('type' => 'error', 'message' => _('Fehler beim Erhöhen des Levels!')), -11 => array('type' => 'error', 'message' => _('Nicht genug Talentpunkte vorhanden!')), -10 => array('type' => 'error', 'message' => _('Ihr Held ist noch nicht erfahren genug, diesen Trank zu nutzen!')), -9 => array('type' => 'error', 'message' => _('Nicht genug Tränke vorhanden!')), -8 => array('type' => 'error', 'message' => _('Fehler beim Anwenden des Trankes!')), -7 => array('type' => 'error', 'message' => _('Fehler beim Schreiben in die Datenbank.')), -6 => array('type' => 'error', 'message' => _('Der Held existiert bereits.')), -5 => array('type' => 'error', 'message' => _('Maximallevel des Skills erreicht.')), -4 => array('type' => 'notice', 'message' => _('Fehler beim Abbrechen der Wiederbelebung.')), -3 => array('type' => 'error', 'message' => _('Nicht genug Rohstoffe zum Wiederbeleben.')), -2 => array('type' => 'error', 'message' => _('Der Held wird bereits wiederbelebt.')), -1 => array('type' => 'error', 'message' => _('Dafür sind nicht genug Talentpunkte vorhanden.')), 0 => array('type' => 'error', 'message' => _('Euch steht noch kein Held zur Verfügung.')), 1 => array('type' => 'success', 'message' => _('Euer Held hat eine neue Fähigkeit erlernt.')), 2 => array('type' => 'notice', 'message' => _('Die Wiederbelebung eures Helden hat begonnen.')), 3 => array('type' => 'success', 'message' => _('Euer Held wurde erstellt.')), 4 => array('type' => 'notice', 'message' => _('Wählt mit Bedacht, dies lässt sich womöglich nicht mehr rückgängig machen.')), 5 => array('type' => 'success', 'message' => _('Der Trank hat seine Wirkung entfaltet. Die Lebenspunkte wurden erhöht.')), 6 => array('type' => 'success', 'message' => _('Der Trank des Vergessens hat Wirkung gezeigt. Der Held ist nun wieder unerfahren.')), 7 => array('type' => 'success', 'message' => _('Euer Held hat das nächste Level erreicht!')), 8 => array('type' => 'success', 'message' => _('Eurem Helden wurden expValue Erfahrungspunkte gutgeschrieben.')), 9 => array('type' => 'success', 'message' => _('Die Wiederbelebung wurde erfolgreich abgebrochen.')), 10 => array('type' => 'success', 'message' => _('Heldentyp erfolgreich gewechselt!')), 11 => array('type' => 'success', 'message' => _('Dein Held hat eine neue Fähigkeit erlernt!')));
    // create new hero
    $action = Request::getVar('action', '');
    $newHeroID = Request::getVar('id', '');
    if ($action == "createHero") {
        if (isset($GLOBALS['heroTypesList'][$newHeroID])) {
            $messageID = createNewHero($GLOBALS['heroTypesList'][$newHeroID]['heroTypeID'], $playerID, $caveID);
        }
    }
    $hero = getHeroByPlayer($playerID);
    $showTypesList = false;
    $changeType = false;
    if ($hero['heroTypeID'] == 1000) {
        $hero = null;
        $changeType = true;
        $showTypesList = true;
    }
    if ($hero != null) {
        $showLevelUp = false;
        $ritual = getRitual($hero);
        $resource['duration'] = $ritual['duration'];
        $cave = getCaveSecure($caveID, $playerID);
        foreach ($GLOBALS['resourceTypeList'] as $key) {
            $dbFieldName = $key->dbFieldName;
            if (!isset($ritual[$dbFieldName])) {
                continue;
            }
            $enough = $ritual[$dbFieldName] <= $cave[$dbFieldName];
            $tmp = array('enough' => $enough, 'value' => $ritual[$dbFieldName], 'missing' => $ritual[$dbFieldName] - $cave[$dbFieldName], 'dbFieldName' => $dbFieldName, 'name' => $key->name);
            $resource[$key->dbFieldName] = $tmp;
        }
        $action = Request::getVar('action', '');
        switch ($action) {
            case 'reincarnate':
                if ($hero['isAlive'] == 1) {
                    $messageID = -17;
                    break;
                }
                if (checkEventHeroExists($playerID)) {
                    $messageID = -2;
                } else {
                    $messageID = createRitual($caveID, $playerID, $resource, $hero, $ownCaves);
                }
                break;
            case 'cancelOrder':
                if (checkEventHeroExists($playerID)) {
                    $messageID = hero_cancelOrder();
                }
                break;
            case 'skill':
                if ($hero['isAlive'] != 1) {
                    $messageID = -18;
                    break;
                }
                if ($hero['tpFree'] >= 1) {
                    $skill = Request::getVar('skill', '');
                    switch ($skill) {
                        //            case 'force':
                        //              //typ='force';
                        //              if ($hero['forceLvl']<10) {
                        //                if (skillForce($playerID, $hero)) {
                        //                  $messageID = 1;
                        //                }
                        //                break;
                        //              }
                        //
                        //              $messageID = -5;
                        //            break;
                        case 'maxHP':
                            //typ='maxHP';
                            if ($hero['maxHpLvl'] < 10) {
                                if (skillMaxHp($playerID, $hero)) {
                                    $messageID = 1;
                                } else {
                                    $messageID = -5;
                                }
                                break;
                            }
                            $messageID = -5;
                            break;
                        case 'regHP':
                            //typ='regHP';
                            if ($hero['regHpLvl'] < 10) {
                                if (skillRegHp($playerID, $hero)) {
                                    $messageID = 1;
                                } else {
                                    $messageID = -5;
                                }
                                break;
                            }
                            $messageID = -5;
                            break;
                    }
                }
                break;
            case 'skill_ability':
                if ($hero['isAlive'] != 1) {
                    $messageID = -18;
                    break;
                }
                if ($hero['tpFree'] >= 1) {
                    if ($skillID = Request::getVar('skillID', '')) {
                        $messageID = hero_skillAbility($skillID, $hero);
                    }
                }
                break;
            case 'lvlUp':
                if ($hero['isAlive'] != 1) {
                    $messageID = -18;
                    break;
                }
                $messageID = hero_levelUp($hero);
                break;
            case 'immolateResources':
                $value = Request::getVar('value', array('' => ''));
                $resultArray = hero_immolateResources($value, $caveID, $ownCaves);
                $messageID = $resultArray['messageID'];
                // set exp value in message
                if ($resultArray['value'] > 0) {
                    $messageText[$messageID]['message'] = str_replace('expValue', $resultArray['value'], $messageText[$messageID]['message']);
                }
                break;
            case 'usePotion':
                if ($hero['isAlive'] != 1) {
                    $messageID = -18;
                    break;
                }
                $potionID = Request::getVar('potionID', -1);
                $value = Request::getVar('value', 0);
                if ($potionID == -1) {
                    $messageID = -8;
                    break;
                }
                if ($value != 1 && $value != 5) {
                    $messageID = -8;
                    break;
                }
                $messageID = hero_usePotion($potionID, $value);
                if ($messageID == 6) {
                    $hero = null;
                    $showTypesList = true;
                    $changeType = true;
                }
                break;
        }
        $queue = getHeroQueue($playerID);
        $potions = array();
        foreach ($GLOBALS['potionTypeList'] as $potionID => $potion) {
            if ($player[$potion->dbFieldName] > 0) {
                $potion->value = $player[$potion->dbFieldName];
                $potions[] = $potion;
            }
        }
    } elseif ($changeType) {
        if (Request::getVar('action', '') == 'changeType') {
            $messageID = hero_changeType(Request::getVar('id', -1));
            if ($messageID < 0) {
                $showTypesList = true;
            } else {
                $showTypesList = false;
                $hero = getHeroByPlayer($playerID);
            }
        }
    } else {
        if ($player['heroism'] >= 1) {
            $messageID = 4;
            $newhero = true;
        } else {
            $messageID = 0;
        }
    }
    /****************************************************************************************************
     *
     * Übergeben ans Template
     *
     ****************************************************************************************************/
    $template->addVars(array('status_msg' => isset($messageID) ? $messageText[$messageID] : ''));
    if (isset($queue) && $queue) {
        $template->addVars(array('quene_show' => true, 'quene_finish' => time_formatDatetime($queue['end'])));
    }
    if ($hero != null) {
        $hero = getHeroByPlayer($playerID);
        $ritual = getRitual($hero);
        if ($hero['expLeft'] <= 0) {
            $showLevelUp = true;
        }
        if ($hero['healPoints'] <= 0.2 * $hero['maxHealPoints']) {
            $hero['HPbar'] = 'error';
        } else {
            $hero['HPbar'] = 'success';
        }
        $template->addVars(array('hero' => $hero, 'showLevelUp' => isset($showLevelUp) ? $showLevelUp : '', 'delay' => time_formatDuration($ritual['duration']), 'ritual' => $ritual, 'resource' => $resource, 'resourceTypeList' => $GLOBALS['resourceTypeList']));
    }
    if ($newhero) {
        $template->addVars(array('newhero' => $newhero, 'heroTypesList' => $GLOBALS['heroTypesList']));
    }
    if ($showTypesList) {
        $template->addVars(array('changeType' => $changeType, 'heroTypesList' => $GLOBALS['heroTypesList']));
    }
    $showImmolation = false;
    if ($ownCaves[$caveID]['hero']) {
        $showImmolation = true;
    }
    $template->addVar('showImmolation', $showImmolation);
    if (isset($potions) && $potions) {
        $template->addVar('potions', $potions);
    }
    if ($GLOBALS['heroSkillTypeList']) {
        $skills = array();
        foreach ($GLOBALS['heroSkillTypeList'] as $skillID => $skill) {
            // calculate skill effect
            foreach ($skill['effects'] as $effect_dbFieldName => $effect) {
                foreach ($GLOBALS['effectTypeList'] as $eff) {
                    if ($eff->dbFieldName == $effect_dbFieldName) {
                        $name = $eff->name;
                        break;
                    }
                }
                $skill['effect_values'][] = $name . ": " . $skill['skillFactor'] * $hero[$skill['dbFieldName']];
            }
            // get level of skill
            $skill['level'] = $hero[$skill['dbFieldName']];
            // filter skills by hero type
            foreach ($skill['requiredType'] as $rt) {
                if ($rt == $hero['id']) {
                    $skills[] = $skill;
                }
            }
        }
        // check if send button is disabled
        foreach ($skills as $skillID => $skill) {
            if ($skill['costTP'] > $hero['tpFree'] || $skill['requiredLevel'] > $hero['lvl'] || $skill['maxLevel'] <= $skill['level']) {
                $skills[$skillID]['disableButton'] = true;
            }
        }
        $template->addVar('skills', $skills);
    }
}