Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the kidnapped child can be removed from the cage #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Web/static/javascript/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] === "~"){
Expand All @@ -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);
Expand Down
44 changes: 43 additions & 1 deletion Web/static/javascript/GameObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -1902,4 +1902,46 @@ link_rooms(KernelFiles, MoreKernelFiles);
//MIT level links
link_rooms(Home, MIT);
link_rooms(MIT, StataCenter);
link_rooms(MIT, AthenaCluster);
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;
}
}
26 changes: 21 additions & 5 deletions Web/static/javascript/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down