public static function migrateDialogs($v1GameId, $v2GameId, $maps) { //returns two maps- one mapping npc ids to dialogs, one mapping nodes to scripts //note- although 'characters' get created in this function, they are NOT needed for further migration, and no map is kept of their IDs $dialogMap = array(); $dialogMap[0] = 0; $scriptMap = array(); $scriptMap[0] = 0; $optionMap = array(); $optionMap[0] = 0; $characters = array(); //not quite a map- actually a list of character objects $dialogs = migration_dbconnection::queryArray("SELECT * FROM npcs WHERE game_id = '{$v1GameId}'", "v1"); //construct map of nodes for quick recall as referenced by npc_conversations $nodes = migration_dbconnection::queryArray("SELECT * FROM nodes WHERE game_id = '{$v1GameId}'", "v1"); $nodeMap = array(); for ($i = 0; $i < count($nodes); $i++) { $nodeMap[$nodes[$i]->node_id] = $nodes[$i]; } for ($i = 0; $i < count($dialogs); $i++) { $dialogMap[$dialogs[$i]->npc_id] = 0; //set it to 0 in case of failure $newDialogId = migration_dbconnection::queryInsert("INSERT INTO dialogs (game_id, name, description, icon_media_id, created) VALUES ('{$v2GameId}','" . addslashes($dialogs[$i]->name) . "','" . addslashes($dialogs[$i]->description) . "','{$maps->media[$dialogs[$i]->icon_media_id]}',CURRENT_TIMESTAMP)", "v2"); $newCharacterId = migration::characterIdForGameNameMedia($v2GameId, $dialogs[$i]->name, $maps->media[$dialogs[$i]->media_id], $characters); $parentScriptId = 0; //create intro script if exists, and treat it as the root script for all others if ($dialogs[$i]->text && $dialogs[$i]->text != "") { $newIds = migration::textToScript(false, 0, $dialogs[$i]->text, $v2GameId, $newDialogId, $newCharacterId, $dialogs[$i]->name, $maps->media[$dialogs[$i]->media_id], 0, $characters, $maps); $parentScriptId = $newIds->lastScriptId; migration_dbconnection::query("UPDATE dialogs SET intro_dialog_script_id = '{$newIds->firstScriptId}' WHERE dialog_id = '{$newDialogId}'", "v2"); } else { //create empty intro script $newIds = migration::textToScript(false, 0, "<dialog><pc></pc></dialog>", $v2GameId, $newDialogId, $newCharacterId, $dialogs[$i]->name, $maps->media[$dialogs[$i]->media_id], 0, $characters, $maps); $parentScriptId = $newIds->lastScriptId; migration_dbconnection::query("UPDATE dialogs SET intro_dialog_script_id = '{$newIds->firstScriptId}' WHERE dialog_id = '{$newDialogId}'", "v2"); } //add exit option from greeting if ($newIds->exitToType) { //copy exitToId directly, once everything is migrated we'll go back and update ids (need to wait for not-yet-migrated stuff) migration_dbconnection::queryInsert("INSERT INTO dialog_options (game_id, dialog_id, parent_dialog_script_id, link_type, link_info, prompt, sort_index, created) VALUES ('{$v2GameId}','{$newDialogId}','{$parentScriptId}','{$newIds->exitToType}','{$newIds->exitToId}','Exit','999',CURRENT_TIMESTAMP)", "v2"); } else { migration_dbconnection::queryInsert("INSERT INTO dialog_options (game_id, dialog_id, parent_dialog_script_id, link_type, prompt, sort_index, created) VALUES ('{$v2GameId}','{$newDialogId}','{$parentScriptId}','EXIT','Exit','999',CURRENT_TIMESTAMP)", "v2"); } $options = migration_dbconnection::queryArray("SELECT * FROM npc_conversations WHERE game_id = '{$v1GameId}' AND npc_id = '{$dialogs[$i]->npc_id}'", "v1"); for ($j = 0; $j < count($options); $j++) { $node = migration_dbconnection::queryObject("SELECT * FROM nodes WHERE node_id = '{$options[$j]->node_id}'", "v1"); $newIds = migration::textToScript($options[$j]->text, $options[$j]->sort_index, $node->text, $v2GameId, $newDialogId, $newCharacterId, $dialogs[$i]->name, $maps->media[$dialogs[$i]->media_id], $parentScriptId, $characters, $maps); $optionMap[$options[$j]->node_id] = $newIds->firstOptionId; $scriptMap[$options[$j]->node_id] = $newIds->lastScriptId; if ($newIds->exitToType) { //copy exitToId directly, once everything is migrated we'll go back and update ids (need to wait for not-yet-migrated stuff) migration_dbconnection::queryInsert("INSERT INTO dialog_options (game_id, dialog_id, parent_dialog_script_id, link_type, link_info, prompt, sort_index, created) VALUES ('{$v2GameId}','{$newDialogId}','{$newIds->lastScriptId}','{$newIds->exitToType}','{$newIds->exitToId}','Exit','999',CURRENT_TIMESTAMP)", "v2"); } else { migration_dbconnection::queryInsert("INSERT INTO dialog_options (game_id, dialog_id, parent_dialog_script_id, link_id, prompt, sort_index, created) VALUES ('{$v2GameId}','{$newDialogId}','{$newIds->lastScriptId}','{$parentScriptId}','Continue','998',CURRENT_TIMESTAMP)", "v2"); } } $dialogMap[$dialogs[$i]->npc_id] = $newDialogId; } $returnMaps = new stdClass(); $returnMaps->dialogsMap = $dialogMap; $returnMaps->scriptsMap = $scriptMap; $returnMaps->optionsMap = $optionMap; return $returnMaps; }