diff --git a/Web/static/javascript/Game.js b/Web/static/javascript/Game.js index 8621159..7948c81 100644 --- a/Web/static/javascript/Game.js +++ b/Web/static/javascript/Game.js @@ -74,7 +74,11 @@ $(document).ready(function() { if (args.length > 0 && args[0].indexOf("/") > 0){ var rooms_in_order = args[0].split("/"); var cur_room_to_test = current_room; - for (var i = 0; i < rooms_in_order.length; i++){ + var num_iters = rooms_in_order.length; + if (command === "mv") { + num_iters--; + } + for (var i = 0; i < num_iters; i++){ prev_room_to_test = cur_room_to_test; var room_to_cd = rooms_in_order[i]; if (i > 0 && rooms_in_order[i-1] === "~"){ @@ -88,8 +92,11 @@ $(document).ready(function() { term.echo("That is not reachable from here."); exec = false; } + } + if (command !== "mv") { + // if it is a mv, the argument should just be the whole original string + args[0] = cur_room_to_test.room_name; } - args[0] = cur_room_to_test.room_name; } if (exec){ var text_to_display = prev_room_to_test[command](args); diff --git a/Web/static/javascript/GameObjects.js b/Web/static/javascript/GameObjects.js index c0f82df..bf722ed 100644 --- a/Web/static/javascript/GameObjects.js +++ b/Web/static/javascript/GameObjects.js @@ -1902,4 +1902,46 @@ link_rooms(KernelFiles, MoreKernelFiles); //MIT level links link_rooms(Home, MIT); link_rooms(MIT, StataCenter); -link_rooms(MIT, AthenaCluster); \ No newline at end of file +link_rooms(MIT, AthenaCluster); + +function get_room_from_name(room_name) { + switch(room_name) { + case "Home": return Home; + case "WesternForest": return WesternForest; + case "SpellCastingAcademy": return SpellCastingAcademy; + case "PracticeRoom": return PracticeRoom; + case "Box": return Box; + case "NorthernMeadow": return NorthernMeadow; + case "EasternMountains": return EasternMountains; + case "Lessons": return Lessons; + case "Cave": return Cave; + case "DarkCorridor": return DarkCorridor; + case "Staircase": return Staircase; + case "DankRoom": return DankRoom; + case "SmallHole": return SmallHole; + case "Tunnel": return Tunnel; + case "StoneChamber": return StoneChamber; + case "Portal": return Portal; + case "TownSquare": return TownSquare; + case "Marketplace": return Marketplace; + case "Library": return Library; + case "BackRoom": return BackRoom; + case "RockyPath": return RockyPath; + case "ArtisanShop": return ArtisanShop; + case "Farm": return Farm; + case "Clearing": return Clearing; + case "BrokenBridge": return BrokenBridge; + case "OminousLookingPath": return OminousLookingPath; + case "Slide": return Slide; + case "KernelFiles": return KernelFiles; + case "MoreKernelFiles": return MoreKernelFiles; + case "Paradise": return Paradise; + case "CaveOfDisgruntledTrolls": return CaveOfDisgruntledTrolls; + case "Cage": return Cage; + case "AthenaCluster": return AthenaCluster; + case "MIT": return MIT; + case "StataCenter": return StataCenter; + case "MagicLocker": return MagicLocker; + default: return null; + } +} \ No newline at end of file diff --git a/Web/static/javascript/Room.js b/Web/static/javascript/Room.js index f345275..286b3fa 100644 --- a/Web/static/javascript/Room.js +++ b/Web/static/javascript/Room.js @@ -276,17 +276,33 @@ Room.prototype.mv = function(args){ if (args.length != 2){ return "You need to move thing A to place B. Use mov [thingA] [placeB]."; } else { - var item_name_to_move = this.itemStringArray().indexOf(args[0]); - if ((item_name_to_move >= 0) && (this.childrenStringArray().indexOf(args[1]) >= 0)){ - itemtoadd = this.items[this.itemStringArray().indexOf(args[0])]; - this.children[this.childrenStringArray().indexOf(args[1])].addItem(itemtoadd); + var path_to_item = args[0].split("/"); + var name_of_item = path_to_item[path_to_item.length - 1]; + var removing_room = this; + if (path_to_item.length > 1) { + // should have checked if cd-able from before this function call + removing_room = get_room_from_name(path_to_item[path_to_item.length-2]); + } + var item_name_to_move = removing_room.itemStringArray().indexOf(name_of_item); + + if ((item_name_to_move >= 0) && + ((this.childrenStringArray().indexOf(args[1]) >= 0)||args[1]==="." || args[1] ===".." )){ + var itemtoadd = removing_room.items[removing_room.itemStringArray().indexOf(name_of_item)]; + + if (args[1] === ".") { + current_room.addItem(itemtoadd); + } else if (args[1] === "..") { + this.parents[0].addItem(itemtoadd); + } else { + this.children[this.childrenStringArray().indexOf(args[1])].addItem(itemtoadd); + } if ((args[0] === "UglyTroll") && (this.room_name === "CaveOfDisgruntledTrolls")){ this.ev.fire("openSlide"); } if ((args[0] === "Boulder") && (this.room_name === "DankRoom")){ this.ev.fire("mvBoulder"); } - this.removeItem(args[0]); + removing_room.removeItem(name_of_item); return "Moved " + args[0] + " to " + args[1] + "."; } else { return "Must be a valid item and location to move it.";