Exemplo n.º 1
0
function wonder_processOrder($playerID, $wonderID, $caveID, $coordX, $coordY, $caveData, $db)
{
    global $defenseSystemTypeList, $unitTypeList, $buildingTypeList, $scienceTypeList, $resourceTypeList, $wonderTypeList;
    // ADDED by chris--- for farmschutz: protection_end in sql
    // check the target cave
    $query = "SELECT playerID, caveID, protection_end FROM Cave " . "WHERE xCoord = '{$coordX}' " . "AND yCoord = '{$coordY}'";
    if (!($result = $db->query($query)) || !($targetData = $result->nextRow())) {
        return -3;
    }
    // ADDED by chris--- for farmschutz
    if (date("YmdHis", time()) < $targetData[protection_end]) {
        return -4;
    }
    // ----------------------------------
    $targetID = $targetData[caveID];
    // check, if cave allowed
    if ($wonderTypeList[$wonderID]->target == "same") {
        $allowed = $caveID == $targetID;
    } else {
        if ($wonderTypeList[$wonderID]->target == "own") {
            $allowed = $playerID == $targetData[playerID];
        } else {
            if ($wonderTypeList[$wonderID]->target == "other") {
                $allowed = $playerID != $targetData[playerID];
            } else {
                // $wonderTypeList[$wonderID]->target == "all"
                $allowed = 1;
            }
        }
    }
    if (!$allowed) {
        return -2;
    }
    $set = array();
    $setBack = array();
    $where = array("WHERE caveID = '{$caveID}' ");
    // get all the resource costs
    foreach ($wonderTypeList[$wonderID]->resourceProductionCost as $key => $value) {
        if ($value != "" && $value != "0") {
            $formula = formula_parseToSQL($value);
            $dbField = $resourceTypeList[$key]->dbFieldName;
            array_push($set, "{$dbField} = {$dbField} - ({$formula})");
            array_push($setBack, "{$dbField} = {$dbField} + ({$formula})");
            array_push($where, "{$dbField} >= ({$formula})");
        }
    }
    // get all the unit costs
    foreach ($wonderTypeList[$wonderID]->unitProductionCost as $key => $value) {
        if ($value != "" && $value != "0") {
            $formula = formula_parseToSQL($value);
            $dbField = $unitTypeList[$key]->dbFieldName;
            array_push($set, "{$dbField} = {$dbField} - {$formula}");
            array_push($setBack, "{$dbField} = {$dbField} + {$formula}");
            array_push($where, "{$dbField} >= {$formula}");
        }
    }
    // generate SQL
    if (sizeof($set)) {
        $set = implode(", ", $set);
        $set = "UPDATE Cave SET {$set} ";
        $setBack = implode(", ", $setBack);
        $setBack = "UPDATE Cave SET {$setBack} WHERE caveID = '{$caveID}'";
    }
    // generate dependecies
    foreach ($wonderTypeList[$wonderID]->buildingDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$buildingTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->maxBuildingDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$wonderTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->defenseSystemDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->maxDefenseSystemDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->resourceDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$resourceTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->maxResourceDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$resourceTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->scienceDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$scienceTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->maxScienceDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$scienceTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->unitDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$unitTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->maxUnitDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$unitTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    $where = implode(" AND ", $where);
    if (!$db->query($set . $where) || $db->affected_rows() != 1) {
        return 0;
    }
    // calculate the chance and evaluate into $chance
    if ($chance_formula = $wonderTypeList[$wonderID]->chance) {
        $chance_eval_formula = formula_parseToPHP($chance_formula, '$caveData');
        $chance_eval_formula = "\$chance={$chance_eval_formula};";
        eval($chance_eval_formula);
    }
    // does the wonder fail?
    //  if ((double)rand() / (double)getRandMax() > $chance) {
    srand((double) microtime() * 1000000);
    $wond1 = (double) rand();
    $wond2 = (double) getRandMax();
    //echo $wond1." / ".$wond2." = ".$wond1/$wond2." -- ". $chance."<br>";
    if ($wond1 / $wond2 > $chance) {
        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 imact's delay
    $delayDelta = $wonderTypeList[$wonderID]->impactList[0][delay] * $delayRandFactor;
    foreach ($wonderTypeList[$wonderID]->impactList as $impactID => $impact) {
        $delay = (int) (($delayDelta + $impact[delay]) * WONDER_TIME_BASE_FACTOR);
        $query = "INSERT INTO Event_wonder " . "(casterID, sourceID, targetID, wonderID, impactID, event_start, " . "event_end) " . "VALUES ('{$playerID}', '{$caveID}', '{$targetID}', '{$wonderID}', " . "'{$impactID}', NOW()+0, (NOW() + INTERVAL {$delay} SECOND)+0)";
        if (!$db->query($query)) {
            $db->query($setBack);
            return -1;
        }
    }
    // create messages
    $sourceMessage = "Sie haben auf die Siedlung in {$coordX}/{$coordY} einen Zauber " . $wonderTypeList[$wonderID]->name . " erwirkt.";
    $targetMessage = "Der Besitzer der Siedlung in {$caveData['xCoord']}/{$caveData['yCoord']} " . "hat auf Ihre Siedlung in {$coordX}/{$coordY} einen Zauber gewirkt.";
    messages_sendSystemMessage($playerID, 9, "Zauber erwirkt auf {$coordX}/{$coordY}", $sourceMessage, $db);
    messages_sendSystemMessage($targetData[playerID], 9, "Zauber!", $targetMessage, $db);
    return 1;
}
Exemplo n.º 2
0
function wonder_processOrder($playerID, $wonderID, $caveID, $coordX, $coordY, $caveData, $db)
{
    global $defenseSystemTypeList, $unitTypeList, $buildingTypeList, $scienceTypeList, $resourceTypeList, $wonderTypeList, $WONDERRESISTANCE;
    if ($wonderTypeList[$wonderID]->target == "same") {
        $targetID = $caveID;
        $query = "SELECT * FROM Cave " . "WHERE caveID = '{$targetID}' ";
        if (!($result = $db->query($query)) || !($targetData = $result->nextRow())) {
            return -3;
        }
        $coordX = $targetData['xCoord'];
        $coordY = $targetData['yCoord'];
    } else {
        // check the target cave
        $query = "SELECT * FROM Cave " . "WHERE xCoord = '{$coordX}' " . "AND yCoord = '{$coordY}'";
        if (!($result = $db->query($query)) || !($targetData = $result->nextRow())) {
            return -3;
        }
        $targetID = $targetData['caveID'];
    }
    // check, if cave allowed
    if ($wonderTypeList[$wonderID]->target == "own") {
        $allowed = $playerID == $targetData['playerID'];
    } else {
        if ($wonderTypeList[$wonderID]->target == "other") {
            $allowed = $playerID != $targetData['playerID'];
        } else {
            // $wonderTypeList[$wonderID]->target == "all"  or == "same"
            $allowed = 1;
        }
    }
    if (!$allowed) {
        return -2;
    }
    $set = array();
    $setBack = array();
    $where = array("WHERE caveID = '{$caveID}' ");
    // get all the resource costs
    foreach ($wonderTypeList[$wonderID]->resourceProductionCost as $key => $value) {
        if ($value != "" && $value != "0") {
            $formula = formula_parseToSQL($value);
            $dbField = $resourceTypeList[$key]->dbFieldName;
            array_push($set, "{$dbField} = {$dbField} - ({$formula})");
            array_push($setBack, "{$dbField} = {$dbField} + ({$formula})");
            array_push($where, "{$dbField} >= ({$formula})");
        }
    }
    // get all the unit costs
    foreach ($wonderTypeList[$wonderID]->unitProductionCost as $key => $value) {
        if ($value != "" && $value != "0") {
            $formula = formula_parseToSQL($value);
            $dbField = $unitTypeList[$key]->dbFieldName;
            array_push($set, "{$dbField} = {$dbField} - {$formula}");
            array_push($setBack, "{$dbField} = {$dbField} + {$formula}");
            array_push($where, "{$dbField} >= {$formula}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->buildingProductionCost as $key => $value) {
        if ($value != "" && $value != "0") {
            $formula = formula_parseToSQL($value);
            $dbField = $buildingTypeList[$key]->dbFieldName;
            array_push($set, "{$dbField} = {$dbField} - {$formula}");
            array_push($setBack, "{$dbField} = {$dbField} + {$formula}");
            array_push($where, "{$dbField} >= {$formula}");
        }
    }
    // generate SQL
    if (sizeof($set)) {
        $set = implode(", ", $set);
        $set = "UPDATE Cave SET {$set} ";
        $setBack = implode(", ", $setBack);
        $setBack = "UPDATE Cave SET {$setBack} WHERE caveID = '{$caveID}'";
    }
    // generate dependecies
    foreach ($wonderTypeList[$wonderID]->buildingDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$buildingTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->maxBuildingDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$wonderTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->defenseSystemDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->maxDefenseSystemDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$defenseSystemTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->resourceDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$resourceTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->maxResourceDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$resourceTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->scienceDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$scienceTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->maxScienceDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$scienceTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->unitDepList as $key => $value) {
        if ($value != "" && $value != "0") {
            array_push($where, "{$unitTypeList[$key]->dbFieldName} >= {$value}");
        }
    }
    foreach ($wonderTypeList[$wonderID]->maxUnitDepList as $key => $value) {
        if ($value != -1) {
            array_push($where, "{$unitTypeList[$key]->dbFieldName} <= {$value}");
        }
    }
    $where = implode(" AND ", $where);
    if (!$db->query($set . $where) || $db->affected_rows() != 1) {
        return 0;
    }
    // calculate the chance and evaluate into $chance
    if ($chance_formula = $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 ($wonderTypeList[$wonderID]->offensiveness == "offensive") {
        $resistance_eval_formula = formula_parseToPHP($WONDERRESISTANCE, '$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 = $wonderTypeList[$wonderID]->impactList[0]['delay'] * $delayRandFactor;
    foreach ($wonderTypeList[$wonderID]->impactList as $impactID => $impact) {
        $delay = (int) (($delayDelta + $impact['delay']) * WONDER_TIME_BASE_FACTOR);
        $now = time();
        $query = sprintf("INSERT INTO Event_wonder (casterID, sourceID, targetID, " . "wonderID, impactID, `start`, `end`) " . "VALUES (%d, %d, %d, %d, %d, '%s', '%s')", $playerID, $caveID, $targetID, $wonderID, $impactID, time_toDatetime($now), time_toDatetime($now + $delay));
        if (!$db->query($query)) {
            $db->query($setBack);
            return -1;
        }
    }
    // create messages
    $sourceMessage = "Sie haben auf die H&ouml;hle in {$coordX}/{$coordY} ein Wunder " . $wonderTypeList[$wonderID]->name . " erwirkt.";
    $targetMessage = "Der Besitzer der H&ouml;hle in {$caveData['xCoord']}/{$caveData['yCoord']} " . "hat auf Ihre H&ouml;hle in {$coordX}/{$coordY} ein Wunder gewirkt.";
    messages_sendSystemMessage($playerID, 9, "Wunder erwirkt auf {$coordX}/{$coordY}", $sourceMessage, $db);
    messages_sendSystemMessage($targetData['playerID'], 9, "Wunder!", $targetMessage, $db);
    return 1;
}
Exemplo n.º 3
0
function tribe_processKickMember($playerID, $tag, $db)
{
    // leader must not be kicked
    if (tribe_isLeaderOrJuniorLeader($playerID, $tag, $db)) {
        return -2;
    }
    // do not kick in wartime
    if (!relation_leaveTribeAllowed($tag, $db)) {
        return -15;
    }
    // blocked
    if (!tribe_changeTribeAllowedForPlayerID($playerID, $db)) {
        return -16;
    }
    // get player
    $player = getPlayerByID($playerID);
    // no such player
    if (!$player) {
        return -1;
    }
    // remove player
    if (!tribe_leaveTribe($playerID, $tag, $db)) {
        return -1;
    }
    Player::addHistoryEntry($db, $playerID, sprintf(_('wird aus dem Stamm \'%s\' geworfen'), $tag));
    // block player
    tribe_setBlockingPeriodPlayerID($playerID, $db);
    tribe_sendTribeMessage($tag, TRIBE_MESSAGE_MEMBER, "Spieler rausgeschmissen", "Der Spieler {$player['name']} wurde soeben vom Anführer aus dem Stamm " . "ausgeschlossen.");
    messages_sendSystemMessage($playerID, 8, "Clanausschluss.", "Sie wurden aus dem Clan {$tag} ausgeschlossen. Bitte loggen Sie sich aus " . "und melden Sie sich wieder an, damit das Stammesmenü bei Ihnen wieder " . "richtig funktioniert.", $db);
    return 1;
}
Exemplo n.º 4
0
function tribe_processKickMember($playerID, $tag, $db)
{
    if (tribe_isLeader($playerID, $tag, $db)) {
        return -2;
    }
    if (!($player = getPlayerFromID($playerID))) {
        return -1;
    }
    if (!tribe_leaveTribe($playerID, $tag, $db)) {
        return -1;
    }
    tribe_sendTribeMessage($tag, TRIBE_MESSAGE_MEMBER, "Spieler rausgeschmissen", "Der Spieler {$player['name']} wurde soeben vom " . "Anf&uuml;hrer aus dem Clan ausgeschlossen.");
    messages_sendSystemMessage($playerID, 8, "Clanausschluss.", "Sie wurden aus dem Clan {$tag} " . "ausgeschlossen. Bitte loggen Sie sich aus und " . "melden Sie sich wieder an, damit das " . "Clanmen&uuml; bei Ihnen wieder richtig " . "funktioniert.", $db);
    return 1;
}