Beispiel #1
0
function improvement_breakDown($buildingID, $caveID, $caveData, $db)
{
    global $resourceTypeList, $buildingTypeList, $config;
    $bFieldName = $buildingTypeList[$buildingID]->dbFieldName;
    // can't tear down
    if (!improvement_toreDownIsPossible($caveID, $db)) {
        return 8;
    }
    // no building of that type
    if ($caveData[$bFieldName] < 1) {
        return 7;
    }
    $query = "UPDATE Cave ";
    $where = "WHERE caveID = '{$caveID}' " . "AND {$bFieldName} > 0 ";
    // add resources gain
    /*
    if (is_array($buildingTypeList[$buildingID]->resourceProductionCost)){
      $resources = array();
      foreach ($buildingTypeList[$buildingID]->resourceProductionCost as $key => $value){
        if ($value != "" && $value != "0"){
          $formula     = formula_parseToSQL($value);
          $dbField     = $resourceTypeList[$key]->dbFieldName;
          $maxLevel    = round(eval('return '.formula_parseToPHP("{$resourceTypeList[$key]->maxLevel};", '$caveData')));
          $resources[] = "$dbField = LEAST($maxLevel, $dbField + ($formula) / {$config->IMPROVEMENT_PAY_BACK_DIVISOR})";
        }
      }
      $set .= implode(", ", $resources);
    }
    */
    // ATTENTION: "SET building = building - 1" has to be placed BEFORE
    //            the calculation of the resource return. Otherwise
    //            mysql would calculate the cost of the NEXT step not
    //            of the LAST building step (returns would be too high)...
    $query .= "SET {$bFieldName} = {$bFieldName} - 1, " . "toreDownTimeout = (NOW() + INTERVAL " . TORE_DOWN_TIMEOUT . " MINUTE)+0 ";
    if (strlen($set)) {
        $query .= ", {$set} ";
    }
    if (!$db->query($query . $where) || !$db->affected_rows() == 1) {
        return 6;
    }
    return 5;
}
Beispiel #2
0
function improvement_Demolishing($buildingID, $caveID, $caveData)
{
    global $db;
    $bFieldName = $GLOBALS['buildingTypeList'][$buildingID]->dbFieldName;
    // can't demolish
    if (!improvement_toreDownIsPossible($caveID)) {
        return 8;
    }
    // no building of that type
    if ($caveData[$bFieldName] < 1) {
        return 7;
    }
    // add resources gain
    /*
    if (is_array($GLOBALS['buildingTypeList'][$buildingID]->resourceProductionCost)){
      $resources = array();
      foreach ($GLOBALS['buildingTypeList'][$buildingID]->resourceProductionCost as $key => $value){
        if ($value != "" && $value != "0"){
          $formula     = formula_parseToSQL($value);
          $dbField     = $GLOBALS['resourceTypeList'][$key]->dbFieldName;
          $maxLevel    = round(eval('return '.formula_parseToPHP("{$GLOBALS['resourceTypeList'][$key]->maxLevel};", '$caveData')));
          $resources[] = "$dbField = LEAST($maxLevel, $dbField + ($formula) / {Config::IMPROVEMENT_PAY_BACK_DIVISOR})";
        }
      }
      $set .= implode(", ", $resources);
    }
    */
    // ATTENTION: "SET building = building - 1" has to be placed BEFORE
    //            the calculation of the resource return. Otherwise
    //            mysql would calculate the cost of the NEXT step not
    //            of the LAST building step (returns would be too high)...
    $sql = $db->prepare("UPDATE " . CAVE_TABLE . "\n                       SET {$bFieldName} = {$bFieldName} - 1,\n                         toreDownTimeout = (NOW() + INTERVAL " . TORE_DOWN_TIMEOUT . " MINUTE) + 0\n                       WHERE caveID = :caveID\n                         AND {$bFieldName} > 0");
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    if (!$sql->execute() || $sql->rowCount() == 0) {
        return 6;
    }
    return 5;
}