Exemple #1
0
function setMovementEvent($caveID, $caveData, $targetX, $targetY, $unit, $resource, $movementID, $reqFood, $absDuration, $artefactID, $caveSpeedFactor)
{
    global $db, $unitTypeList, $resourceTypeList;
    // ziel-hoehlenID holen
    $res = $db->query("SELECT caveID FROM Cave WHERE xCoord = " . $targetX . " AND yCoord = " . $targetY);
    if ($db->affected_rows() < 1) {
        return 1;
    }
    $row = $res->nextRow();
    $targetCaveID = $row['caveID'];
    // updates fuer cave basteln
    $update = "UPDATE Cave ";
    $updateRollback = "UPDATE Cave ";
    $set = "SET caveID = {$caveID} ";
    $setRollback = "SET caveID = {$caveID} ";
    $where = "WHERE caveID = {$caveID} ";
    $whereRollback = "WHERE caveID = {$caveID} ";
    foreach ($unit as $unitID => $value) {
        if (!empty($value)) {
            $set .= ", " . $unitTypeList[$unitID]->dbFieldName . " = " . $unitTypeList[$unitID]->dbFieldName . " - {$value} ";
            $where .= "AND " . $unitTypeList[$unitID]->dbFieldName . " >= {$value} ";
            $where .= "AND {$value} >= 0 ";
            // check for values bigger 0!
            $setRollback .= ", " . $unitTypeList[$unitID]->dbFieldName . " = " . $unitTypeList[$unitID]->dbFieldName . " + {$value} ";
        }
    }
    foreach ($resource as $resourceID => $value) {
        $value_to_check = $value;
        if ($resourceID == 1) {
            $value += $reqFood;
        }
        if (!empty($value) || !empty($value_to_check)) {
            $set .= ", " . $resourceTypeList[$resourceID]->dbFieldName . " = " . $resourceTypeList[$resourceID]->dbFieldName . " - {$value} ";
            $where .= "AND " . $resourceTypeList[$resourceID]->dbFieldName . " >= {$value} ";
            if (!empty($value_to_check)) {
                $where .= "AND {$value_to_check} >= 0 ";
            }
            $setRollback .= ", " . $resourceTypeList[$resourceID]->dbFieldName . " = " . $resourceTypeList[$resourceID]->dbFieldName . " + {$value} ";
        }
    }
    $update = $update . $set . $where;
    $updateRollback = $updateRollback . $setRollback . $whereRollback;
    if (!$db->query($update) || $db->affected_rows() < 1) {
        return 2;
    }
    // insert fuer movement_event basteln
    $insert = "INSERT INTO Event_movement (caveID, source_caveID, " . "target_caveID, movementID, event_start, event_end, " . "artefactID, speedFactor, ";
    $i = 0;
    foreach ($unit as $uID => $val) {
        if (!empty($val)) {
            if ($i++ != 0) {
                $insert .= " , ";
            }
            $insert .= $unitTypeList[$uID]->dbFieldName;
        }
    }
    foreach ($resource as $rID => $val) {
        if (!empty($val)) {
            $insert .= " , " . $resourceTypeList[$rID]->dbFieldName;
        }
    }
    $speedFactor = getMaxSpeedFactor($unit) * $caveSpeedFactor;
    $insert .= " ) VALUES ( {$caveID} , {$caveID} , {$targetCaveID} , {$movementID} , " . "NOW()+0 , (NOW() + INTERVAL {$absDuration} MINUTE)+0 , {$artefactID}, " . "{$speedFactor}, ";
    $i = 0;
    foreach ($unit as $val) {
        if (!empty($val)) {
            if ($i++ != 0) {
                $insert .= " , ";
            }
            $insert .= $val;
        }
    }
    foreach ($resource as $val) {
        if (!empty($val)) {
            $insert .= " , " . $val;
        }
    }
    $insert .= " )";
    if (!$db->query($insert)) {
        // update rueckgaengig machen
        $db->query($updateRollback);
        return 3;
    } else {
        // remove the artefact if any
        if ($artefactID > 0) {
            // TODO: what should happen, if the first if succedes but one of the other fails afterwards
            if (!artefact_removeEffectsFromCave($artefactID)) {
                die("Fehler beim Artefakteffekte entfernen. Bitte an einen Admin mailen!");
            }
            if (!artefact_uninitiateArtefact($artefactID)) {
                die("Fehler beim Artefakt deinitialisieren. Bitte an einen Admin mailen!");
            }
            if (!artefact_removeArtefactFromCave($artefactID)) {
                die("Fehler beim Artefakt aus der Höhle entfernen. Bitte an einen Admin mailen!");
            }
        }
        return 0;
    }
}
Exemple #2
0
function setMovementEvent($caveID, $caveData, $targetX, $targetY, $unit, $resource, $movementID, $reqFood, $absDuration, $artefactID, $heroID, $caveSpeedFactor)
{
    global $db;
    // ziel-hoehlenID holen
    $sql = $db->prepare("SELECT caveID FROM " . CAVE_TABLE . " \n                       WHERE xCoord = :targetX AND yCoord = :targetY");
    $sql->bindValue('targetX', $targetX, PDO::PARAM_INT);
    $sql->bindVAlue('targetY', $targetY, PDO::PARAM_INT);
    if ($sql->rowCountSelect() != 1) {
        return 1;
    }
    if (!$sql->execute()) {
        return 1;
    }
    $row = $sql->fetch();
    $sql->closeCursor();
    $targetCaveID = $row['caveID'];
    // updates fuer cave basteln
    $update = "UPDATE " . CAVE_TABLE . " ";
    $updateRollback = "UPDATE " . CAVE_TABLE . " ";
    $where = "WHERE caveID = {$caveID} ";
    $whereRollback = "WHERE caveID = {$caveID} ";
    $set = $setRollback = array();
    foreach ($unit as $unitID => $value) {
        if (!empty($value)) {
            $set[] = $GLOBALS['unitTypeList'][$unitID]->dbFieldName . " = " . $GLOBALS['unitTypeList'][$unitID]->dbFieldName . " - {$value} ";
            $setRollback[] = $GLOBALS['unitTypeList'][$unitID]->dbFieldName . " = " . $GLOBALS['unitTypeList'][$unitID]->dbFieldName . " + {$value} ";
            $where .= "AND " . $GLOBALS['unitTypeList'][$unitID]->dbFieldName . " >= {$value} ";
            $where .= "AND {$value} >= 0 ";
            // check for values bigger 0!
        }
    }
    foreach ($resource as $resourceID => $value) {
        $value_to_check = $value;
        if ($resourceID == GameConstants::FUEL_RESOURCE_ID) {
            $value += $reqFood;
        }
        if (!empty($value) || !empty($value_to_check)) {
            $set[] = $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName . " = " . $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName . " - {$value} ";
            $setRollback[] = $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName . " = " . $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName . " + {$value} ";
            $where .= "AND " . $GLOBALS['resourceTypeList'][$resourceID]->dbFieldName . " >= {$value} ";
            if (!empty($value_to_check)) {
                $where .= "AND {$value_to_check} >= 0 ";
            }
        }
    }
    $update = $update . "SET " . implode(", ", $set) . $where;
    $updateRollback = $updateRollback . "SET " . implode(", ", $setRollback) . $whereRollback;
    if (!$db->exec($update)) {
        return 2;
    }
    // remove the artefact if any
    if ($artefactID > 0) {
        // TODO: what should happen, if the first succedes but one of the other fails afterwards
        if (!artefact_removeEffectsFromCave($artefactID)) {
            $db->query($updateRollback);
            return 3;
        }
        if (!artefact_uninitiateArtefact($artefactID)) {
            $db->query($updateRollback);
            return 3;
        }
        if (!artefact_removeArtefactFromCave($artefactID)) {
            $db->query($updateRollback);
            return 3;
        }
    }
    // remove hero if any
    if ($heroID > 0) {
        if (!hero_removeHeroFromCave($heroID)) {
            return 3;
        }
    }
    // insert fuer movement_event basteln
    $now = time();
    $insert = "INSERT INTO " . EVENT_MOVEMENT_TABLE . " (caveID, source_caveID, target_caveID, movementID, `start`, `end`, artefactID, heroID, speedFactor, exposeChance, ";
    $i = 0;
    foreach ($unit as $uID => $val) {
        if (!empty($val)) {
            if ($i++ != 0) {
                $insert .= " , ";
            }
            $insert .= $GLOBALS['unitTypeList'][$uID]->dbFieldName;
        }
    }
    foreach ($resource as $rID => $val) {
        if (!empty($val)) {
            $insert .= " , " . $GLOBALS['resourceTypeList'][$rID]->dbFieldName;
        }
    }
    $speedFactor = getMaxSpeedFactor($unit) * $caveSpeedFactor;
    // determine expose chance
    $exposeChance = (double) rand() / (double) getRandMax();
    $insert .= sprintf(" ) VALUES (%d, %d, %d, %d, " . "'%s', '%s', %d, %d, %f, %f, ", $caveID, $caveID, $targetCaveID, $movementID, time_toDatetime($now), time_toDatetime($now + $absDuration * 60), $artefactID, $heroID, $speedFactor, $exposeChance);
    $i = 0;
    foreach ($unit as $val) {
        if (!empty($val)) {
            if ($i++ != 0) {
                $insert .= " , ";
            }
            $insert .= $val;
        }
    }
    foreach ($resource as $val) {
        if (!empty($val)) {
            $insert .= " , " . $val;
        }
    }
    $insert .= " )";
    if (!$db->exec($insert)) {
        // update rueckgaengig machen
        $db->query($updateRollback);
        return 3;
    }
    return 0;
}
Exemple #3
0
 function remove()
 {
     global $db_game, $params;
     // get artefact
     $artefactID = intval($params->artefactID);
     $artefact = artefact_getArtefactByID($artefactID);
     if (!sizeof($artefact)) {
         $this->msgs[] = 'No such cave: (' . $params->xCoord . '|' . $params->yCoord . ')';
         return $this->getList();
     }
     // remove effects
     if (!artefact_removeEffectsFromCave($db_game, $artefact)) {
         $this->msgs[] = 'FATAL ERROR: Could not remove artefact\'s effects from it\'s cave';
         return $this->getList();
     }
     // uninitiate artefact
     if (!artefact_uninitiateArtefact($db_game, $artefactID)) {
         $this->msgs[] = 'FATAL ERROR: Could not uninitiate artefact';
         return $this->getList();
     }
     // remove from cave
     if (!artefact_removeArtefactFromCave($db_game, $artefact)) {
         $this->msgs[] = 'FATAL ERROR: Could not remove artefact from it\'s cave';
         return $this->getList();
     }
     $this->msgs[] = 'Successfully removed artefact.';
     return $this->getList();
 }
    echo "DELETE PLAYER {$playerID}: Delete hero event ";
    $sql = $db_game->prepare("DELETE FROM " . EVENT_HERO_TABLE . "\n                            WHERE caveID = :caveID");
    $sql->bindValue('caveID', $row['caveID'], PDO::PARAM_INT);
    if (!$sql->execute()) {
        echo "FAILURE\n";
    } else {
        echo "SUCCESS\n";
    }
    echo "DELETE PLAYER {$playerID}: Delete pet artes";
    $artefacts = artefact_getArtefactByCaveID($row['caveID']);
    if (!empty($artefacts)) {
        foreach ($artefacts as $artefact) {
            if ($artefact['pet'] == 1) {
                artefact_removeEffectsFromCave($artefact['artefactID']);
                artefact_removeArtefactFromCave($artefact['artefactID']);
                artefact_uninitiateArtefact($artefact['artefactID']);
            }
        }
    }
}
echo "DELETE PLAYER {$playerID}: Delete messages ";
$sql1 = $db_game->prepare("UPDATE " . MESSAGE_TABLE . "\n                         SET recipientDeleted = 1\n                         WHERE recipientID = :playerID");
$sql1->bindValue('playerID', $playerID, PDO::PARAM_INT);
$sql2 = $db_game->prepare("UPDATE " . MESSAGE_TABLE . "\n                           SET senderDeleted = 1\n                           WHERE senderID = :playerID");
$sql2->bindValue('playerID', $playerID, PDO::PARAM_INT);
if (!$sql1->execute() || !$sql2->execute()) {
    echo "FAILURE\n";
} else {
    echo "SUCCESS\n";
}
echo "DELETE PLAYER {$playerID}: Delete hero";