示例#1
0
文件: unit.inc.php 项目: norter/Game
function unit_processOrder($unitID, $quantity, $caveID, $details)
{
    global $db;
    if ($quantity == -1) {
        $quantity = MAX_SIMULTAN_BUILDED_UNITS;
        while (!processProductionCost($GLOBALS['unitTypeList'][$unitID], $caveID, $details, $quantity) && $quantity != 0) {
            $quantity--;
        }
        if ($quantity <= 0) {
            return 4;
        }
    } else {
        if ($quantity > MAX_SIMULTAN_BUILDED_UNITS || $quantity <= 0) {
            return 4;
        }
        // take the production costs from cave
        if (!processProductionCost($GLOBALS['unitTypeList'][$unitID], $caveID, $details, $quantity)) {
            return 2;
        }
    }
    $prodTime = 0;
    // calculate the production time;
    if ($time_formula = $GLOBALS['unitTypeList'][$unitID]->productionTimeFunction) {
        $time_eval_formula = formula_parseToPHP($time_formula, '$details');
        eval('$prodTime=' . $time_eval_formula . ';');
    }
    $prodTime *= BUILDING_TIME_BASE_FACTOR * $quantity;
    $now = time();
    $sql = $db->prepare("INSERT INTO " . EVENT_UNIT_TABLE . " (caveID, unitID, quantity, " . "start, end) VALUES (:caveID, :unitID, :quantity, :start, :end)");
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    $sql->bindValue('unitID', $unitID, PDO::PARAM_INT);
    $sql->bindValue('quantity', $quantity, PDO::PARAM_INT);
    $sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
    $sql->bindValue('end', time_toDatetime($now + $prodTime), PDO::PARAM_STR);
    if (!$sql->execute() || $sql->rowCount() == 0) {
        processProductionCostSetBack($GLOBALS['unitTypeList'][$unitID], $caveID, $details, $quantity);
        return 2;
    }
    return 3;
}
示例#2
0
function merchant_processOrder($tradeID, $caveID, $caveData)
{
    global $db;
    $sql = $db->prepare("SELECT LockTill < :LockTill as allowed\n                       FROM " . TRADELOCK_TABLE . "\n                       WHERE PlayerID= :playerID \n                        AND cat = :cat");
    $sql->bindValue('LockTill', date("Y-m-d H:i:s", time()), PDO::PARAM_STR);
    $sql->bindValue('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
    $sql->bindValue('cat', $GLOBALS['tradeTypeList'][$tradeID]->category, PDO::PARAM_STR);
    if ($sql->execute()) {
        $row = $sql->fetch(PDO::FETCH_ASSOC);
        if ($row["allowed"] == 0 && $row) {
            return -2;
        }
    }
    $sql = $db->prepare("DELETE FROM " . TRADELOCK_TABLE . "\n                       WHERE  PlayerID= :playerID\n                        AND cat = :cat");
    $sql->bindValue('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
    $sql->bindValue('cat', $GLOBALS['tradeTypeList'][$tradeID]->category, PDO::PARAM_STR);
    if (!$sql->execute()) {
        return -1;
    }
    // take production costs from cave
    if (!processProductionCost($GLOBALS['tradeTypeList'][$tradeID], $caveID, $caveData)) {
        return 0;
    }
    $now = time();
    if ($GLOBALS['tradeTypeList'][$tradeID]->category == "potion") {
        foreach ($GLOBALS['tradeTypeList'][$tradeID]->impactList[0]['potions'] as $potionID => $potion) {
            if (!$GLOBALS['potionTypeList'][$potionID]) {
                processProductionCostSetBack($GLOBALS['tradeTypeList'][$tradeID], $caveID, $caveData);
                return -1;
            }
            $sql = $db->prepare("UPDATE " . PLAYER_TABLE . "\n                           SET " . $GLOBALS['potionTypeList'][$potionID]->dbFieldName . " =  " . $GLOBALS['potionTypeList'][$potionID]->dbFieldName . " + :absolute \n                           WHERE playerID = :playerID");
            $sql->bindValue('absolute', $potion['absolute'], PDO::PARAM_INT);
            $sql->bindValue('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
            if (!$sql->execute() || $sql->rowCount() == 0) {
                processProductionCostSetBack($GLOBALS['tradeTypeList'][$tradeID], $caveID, $caveData);
                return -1;
            }
        }
    } else {
        // create a random factor between -0.3 and +0.3
        $delayRandFactor = rand(0, getrandmax()) / getrandmax() * 0.6 - 0.3;
        // now calculate the delayDelta depending on the first impact's delay
        $delayDelta = $GLOBALS['tradeTypeList'][$tradeID]->impactList[0]['delay'] * $delayRandFactor;
        foreach ($GLOBALS['tradeTypeList'][$tradeID]->impactList as $impactID => $impact) {
            $delay = (int) (($delayDelta + $impact['delay']) * WONDER_TIME_BASE_FACTOR);
            $sql = $db->prepare("INSERT INTO " . EVENT_TRADE_TABLE . " \n                           (targetID, tradeID, impactID, start, end)\n                            VALUES (:targetID, :tradeID, :impactID, :start, :end)");
            $sql->bindValue('targetID', $caveID, PDO::PARAM_INT);
            $sql->bindValue('tradeID', $tradeID - 1, PDO::PARAM_INT);
            $sql->bindValue('impactID', $impactID, PDO::PARAM_INT);
            $sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
            $sql->bindValue('end', time_toDatetime($now + $delay), PDO::PARAM_STR);
            if (!$sql->execute() || $sql->rowCount() == 0) {
                processProductionCostSetBack($GLOBALS['tradeTypeList'][$tradeID], $caveID, $caveData);
                return -1;
            }
        }
    }
    $lock = $now + $GLOBALS['tradeCategoriesTypeList'][$GLOBALS['tradeTypeList'][$tradeID]->category]->secondsbetween;
    $sql = $db->prepare("INSERT INTO " . TRADELOCK_TABLE . " \n                       (PlayerID, cat, LockTill)\n                        VALUES (:playerID, :cat, :LockTill)");
    $sql->bindValue('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
    $sql->bindValue('cat', $GLOBALS['tradeTypeList'][$tradeID]->category, PDO::PARAM_STR);
    $sql->bindValue('LockTill', time_toDatetime($lock), PDO::PARAM_STR);
    if (!$sql->execute() || $sql->rowCount() == 0) {
        return -1;
    }
    return 1;
}
示例#3
0
function science_processOrder($scienceID, $caveID, $cave)
{
    global $defenseSystemTypeList, $buildingTypeList, $scienceTypeList, $resourceTypeList, $unitTypeList;
    global $config, $db;
    $science = $scienceTypeList[$scienceID];
    $maxLevel = round(eval('return ' . formula_parseToPHP("{$science->maxLevel};", '$cave')));
    // check, that this science isn't researched in an other cave at the
    // same time
    $sql = $db->prepare("SELECT event_scienceID\n                       FROM " . EVENT_SCIENCE_TABLE . "\n                       WHERE playerID = :playerID \n                         AND scienceID = :scienceID");
    $sql->bindValue('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
    $sql->bindValue('scienceID', $scienceID, PDO::PARAM_INT);
    if ($sql->rowCountSelect() != 0) {
        return 4;
    }
    // check for scienceMaxDeps in Event_Handler
    $dep_count = 0;
    $deps = '';
    foreach ($science->maxScienceDepList as $key => $value) {
        if ($value != -1 && $cave[$scienceTypeList[$key]->dbFieldName] > $value - 1) {
            if ($dep_count) {
                $deps .= ", ";
            }
            $deps .= $key;
            $dep_count++;
        }
    }
    if ($dep_count) {
        $sql = $db->prepare("SELECT event_scienceID\n                         FROM " . EVENT_SCIENCE_TABLE . "\n                         WHERE playerID = :playerID\n                           AND scienceID IN ({$deps})");
        $sql->bindValue('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
        if ($sql->rowCountSelect() != 0) {
            return 5;
        }
    }
    // take production costs from cave
    if (!processProductionCost($science, $caveID, $cave)) {
        return 2;
    }
    $prodTime = 0;
    // calculate the production time;
    if ($time_formula = $science->productionTimeFunction) {
        $time_eval_formula = formula_parseToPHP($time_formula, '$cave');
        $time_eval_formula = "\$prodTime={$time_eval_formula};";
        eval($time_eval_formula);
    }
    $prodTime *= SCIENCE_TIME_BASE_FACTOR;
    $now = time();
    $sql = $db->prepare("INSERT INTO " . EVENT_SCIENCE_TABLE . " (caveID, playerID, scienceID, " . "start, end) VALUES (:caveID, :playerID, :scienceID, :start, :end)");
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    $sql->bindValue('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
    $sql->bindValue('scienceID', $scienceID, PDO::PARAM_INT);
    $sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
    $sql->bindValue('end', time_toDatetime($now + $prodTime), PDO::PARAM_STR);
    if (!$sql->execute() || !$sql->rowCount() == 1) {
        processProductionCostSetBack($science, $caveID, $cave);
        return 2;
    }
    return 3;
}
示例#4
0
function improvement_processOrder($buildingID, $caveID, $caveData)
{
    global $db;
    $sql = $db->prepare("SELECT count(*) as count\n                       FROM " . EVENT_EXPANSION_TABLE . " \n                       WHERE caveID = :caveID");
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    if (!$sql->execute()) {
        return 2;
    }
    $return = $sql->fetch();
    $sql->closeCursor();
    if ($return['count'] != 0) {
        return 2;
    }
    $building = $GLOBALS['buildingTypeList'][$buildingID];
    // take production costs from cave
    if (!processProductionCost($building, $caveID, $caveData)) {
        return 2;
    }
    $prodTime = 0;
    // calculate the production time;
    if ($time_formula = $building->productionTimeFunction) {
        $time_eval_formula = formula_parseToPHP($time_formula, '$caveData');
        $time_eval_formula = "\$prodTime={$time_eval_formula};";
        eval($time_eval_formula);
    }
    $prodTime *= BUILDING_TIME_BASE_FACTOR;
    $now = time();
    $sql = $db->prepare("INSERT INTO " . EVENT_EXPANSION_TABLE . " \n                      (caveID, expansionID, start, end) \n                      VALUES (:caveID, :expansionID, :start, :end)");
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    $sql->bindValue('expansionID', $buildingID, PDO::PARAM_INT);
    $sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
    $sql->bindValue('end', time_toDatetime($now + $prodTime), PDO::PARAM_STR);
    if (!$sql->execute() || !$sql->rowCount() == 1) {
        processProductionCostSetBack($building, $caveID, $caveData);
        return 2;
    }
    return 3;
}
示例#5
0
function wonder_processOrder($playerID, $wonderID, $caveID, $coordX, $coordY, $caveData)
{
    global $db;
    if ($GLOBALS['wonderTypeList'][$wonderID]->target == "same") {
        $targetID = $caveID;
        $sql = $db->prepare("SELECT * FROM " . CAVE_TABLE . " \n                         WHERE caveID = :targetID");
        $sql->bindValue('targetID', $targetID);
        if (!$sql->execute() || !($targetData = $sql->fetch(PDO::FETCH_ASSOC))) {
            return -3;
        }
        $sql->closeCursor();
        $coordX = $targetData['xCoord'];
        $coordY = $targetData['yCoord'];
    } else {
        // check the target cave
        $sql = $db->prepare("SELECT * FROM " . CAVE_TABLE . " \n                        WHERE xCoord = :coordX\n                        AND yCoord = :coordY");
        $sql->bindValue('coordX', $coordX, PDO::PARAM_INT);
        $sql->bindValue('coordY', $coordY, PDO::PARAM_INT);
        if (!$sql->execute() || !($targetData = $sql->fetch(PDO::FETCH_ASSOC))) {
            return -3;
        }
        $sql->closeCursor();
        $targetID = $targetData['caveID'];
    }
    // check, if cave allowed
    if ($GLOBALS['wonderTypeList'][$wonderID]->target == "own") {
        $allowed = $playerID == $targetData['playerID'];
    } else {
        if ($GLOBALS['wonderTypeList'][$wonderID]->target == "other") {
            $allowed = $playerID != $targetData['playerID'];
        } else {
            // $wonderTypeList[$wonderID]->target == "all"  or == "same"
            $allowed = 1;
        }
    }
    if (!$allowed) {
        return -2;
    }
    // take production costs from cave
    if (!processProductionCost($GLOBALS['wonderTypeList'][$wonderID], $caveID, $caveData)) {
        return 0;
    }
    // calculate the chance and evaluate into $chance
    if ($chance_formula = $GLOBALS['wonderTypeList'][$wonderID]->chance) {
        $chance_eval_formula = formula_parseToPHP($chance_formula, '$caveData');
        $chance_eval_formula = "\$chance={$chance_eval_formula};";
        eval($chance_eval_formula);
    }
    // if this wonder is offensive
    // calculate the wonder resistance and evaluate into $resistance
    // TODO: Wertebereich der Resistenz ist derzeit 0 - 1, also je höher desto resistenter
    if ($GLOBALS['wonderTypeList'][$wonderID]->offensiveness == "offensive") {
        $resistance_eval_formula = formula_parseToPHP(GameConstants::WONDER_RESISTANCE, '$targetData');
        $resistance_eval_formula = "\$resistance={$resistance_eval_formula};";
        eval($resistance_eval_formula);
    } else {
        $resistance = 0.0;
    }
    // does the wonder fail?
    if ((double) rand() / (double) getRandMax() > $chance - $resistance) {
        return 2;
        // wonder did fail
    }
    // schedule the wonder's impacts
    // create a random factor between -0.3 and +0.3
    $delayRandFactor = rand(0, getrandmax()) / getrandmax() * 0.6 - 0.3;
    // now calculate the delayDelta depending on the first impact's delay
    $delayDelta = $GLOBALS['wonderTypeList'][$wonderID]->impactList[0]['delay'] * $delayRandFactor;
    foreach ($GLOBALS['wonderTypeList'][$wonderID]->impactList as $impactID => $impact) {
        $delay = (int) (($delayDelta + $impact['delay']) * WONDER_TIME_BASE_FACTOR);
        $now = time();
        $sql = $db->prepare("INSERT INTO " . EVENT_WONDER_TABLE . " (casterID, sourceID, targetID, \n                     wonderID, impactID, start, end) \n                     VALUES (:playerID, :caveID, :targetID, :wonderID, :impactID, :start, :end)");
        $sql->bindValue('playerID', $playerID, PDO::PARAM_INT);
        $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
        $sql->bindValue('targetID', $targetID, PDO::PARAM_INT);
        $sql->bindValue('wonderID', $wonderID, PDO::PARAM_INT);
        $sql->bindValue('impactID', $impactID, PDO::PARAM_INT);
        $sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
        $sql->bindValue('end', time_toDatetime($now + $delay), PDO::PARAM_STR);
        if (!$sql->execute()) {
            //give production costs back
            processProductionCostSetBack($GLOBALS['wonderTypeList'][$wonderID], $caveID, $caveData);
            return -1;
        }
    }
    // create messages
    $messageClass = new Messages();
    $sourceMessage = 'Sie haben auf die Höhle in ' . $coordX . '/' . $coordY . ' ein Wunder ' . $GLOBALS['wonderTypeList'][$wonderID]->name . ' erwirkt.';
    $targetMessage = 'Der Besitzer der Höhle in ' . $caveData['xCoord'] . '/' . $caveData['yCoord'] . ' hat auf Ihre Höhle in ' . $coordX . '/' . $coordY . ' ein Wunder gewirkt.';
    // create xml message
    $casterxml = new SimpleXMLElement('<?xml version=\'1.0\' encoding=\'utf-8\'?><wonderMessageCaster></wonderMessageCaster>');
    $casterxml->addChild('timestamp', time());
    $casterxml->addChild('wonderType', 'caster');
    $casterxml->addChild('source');
    $casterxml->source->addChild('xCoord', $caveData['xCoord']);
    $casterxml->source->addChild('yCoord', $caveData['yCoord']);
    $casterxml->source->addChild('caveName', $caveData['name']);
    $casterxml->addChild('target');
    $casterxml->target->addChild('xCoord', $targetData['xCoord']);
    $casterxml->target->addChild('yCoord', $targetData['yCoord']);
    $casterxml->target->addChild('caveName', $targetData['name']);
    $casterxml->addChild('wonderName', $GLOBALS['wonderTypeList'][$wonderID]->name);
    $targetxml = new SimpleXMLElement('<?xml version=\'1.0\' encoding=\'utf-8\'?><wonderMessageTarget></wonderMessageTarget>');
    $targetxml->addChild('timestamp', time());
    $targetxml->addChild('wonderType', 'target');
    $targetxml->addChild('source');
    $targetxml->source->addChild('xCoord', $caveData['xCoord']);
    $targetxml->source->addChild('yCoord', $caveData['yCoord']);
    $targetxml->source->addChild('caveName', $caveData['name']);
    $targetxml->addChild('target');
    $targetxml->target->addChild('xCoord', $targetData['xCoord']);
    $targetxml->target->addChild('yCoord', $targetData['yCoord']);
    $targetxml->target->addChild('caveName', $targetData['name']);
    $messageClass->sendSystemMessage($playerID, 9, 'Wunder erwirkt auf ' . $coordX . '/' . $coordY, $sourceMessage, $casterxml->asXML());
    $messageClass->sendSystemMessage($targetData['playerID'], 9, 'Wunder!', $targetMessage, $targetxml->asXML());
    return 1;
}
示例#6
0
/**
 *
 */
function defense_processOrder($defenseID, $caveID, $cave)
{
    global $db;
    // take production costs from cave
    if (!processProductionCost($GLOBALS['defenseSystemTypeList'][$defenseID], $caveID, $cave)) {
        return 6;
    }
    // calculate the production time;
    $prodTime = 0;
    if ($time_formula = $GLOBALS['defenseSystemTypeList'][$defenseID]->productionTimeFunction) {
        $time_eval_formula = formula_parseToPHP($time_formula, '$cave');
        $time_eval_formula = "\$prodTime = {$time_eval_formula};";
        eval($time_eval_formula);
    }
    $prodTime *= DEFENSESYSTEM_TIME_BASE_FACTOR;
    $now = time();
    $sql = $db->prepare("INSERT INTO " . EVENT_DEFENSE_SYSTEM_TABLE . " \n                         (caveID, defenseSystemID, start, end)\n                       VALUES\n                         (:caveID, :defenseID, :start, :end)");
    $sql->bindValue('caveID', $caveID, PDO::PARAM_INT);
    $sql->bindValue('defenseID', $defenseID, PDO::PARAM_INT);
    $sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
    $sql->bindValue('end', time_toDatetime($now + $prodTime), PDO::PARAM_STR);
    if (!$sql->execute() || $sql->rowCount() == 0) {
        //give production costs back
        processProductionCostSetBack($GLOBALS['defenseSystemTypeList'][$defenseID], $caveID, $cave);
        return 6;
    }
    return 7;
}