Skip to content

Commit

Permalink
getAgreement now uses a dictionary
Browse files Browse the repository at this point in the history
And we move to version 1.4
  • Loading branch information
ThePix committed Mar 11, 2023
1 parent 869988a commit 15b35d6
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 27 deletions.
Binary file added QuestJS-1-4.zip
Binary file not shown.
8 changes: 4 additions & 4 deletions game-eg/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1046,16 +1046,16 @@ createItem("Lara", NPC(true), {
failed:true,
},
],
getAgreementTake:function(item) {
if (item === w.brick) {
getAgreementTake:function(options) {
if (options.item === w.brick) {
msg("'I'm not picking up any bricks,' says Lara indignantly.")
return false
}
return true
},
getAgreementGo:function(ex) {
getAgreementGo:function(options) {
if (!this.happy) {
msg("'I'm not going " + ex.dir + ",' says Lara indignantly. 'I don't like that room.'")
msg("'I'm not going " + options.exit.dir + ",' says Lara indignantly. 'I don't like that room.'")
return false
}
return true
Expand Down
2 changes: 2 additions & 0 deletions game-house/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ const GENERIC = function() {
return false
},
examine:function() {
if (!world.isCreated) return
const room = w[player.loc]
if (typeof room['examine_' + this.alias] === 'function') {
room['examine_' + this.alias]()
Expand Down Expand Up @@ -278,6 +279,7 @@ createItem("generic_panelling", GENERIC(), {
return zones[w[loc].zone].panelling || w[loc].panelling
},
examine:function() {
if (!world.isCreated) return
if (!w.generic_panelling.examinedIn) {
w.generic_panelling.examinedIn = currentLocation.name
w.wooden_panel.loc = currentLocation.name
Expand Down
4 changes: 2 additions & 2 deletions game-house/medieval.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,9 +910,9 @@ createItem("tiny_man", NPC(false), {
msg("'Follow me,' says Mandy to {nm:npc:the}.", {npc:obj})
return falsemsg("'If it's all the same to you, I'll stay here.'")
},
getAgreement:function(verb, item) {
getAgreement:function(verb, options) {
if (verb !== 'Repair') return falsemsg("'Sorry, lady-giant, I've got to much to do here. In fact I best get on.'")
if (item !== w.boots && item !== w.tiny_shoes) return falsemsg("'Sorry, lady-giant, I can do shoes, maybe boots at a push, but... No, not that.'")
if (options.item !== w.boots && options.item !== w.tiny_shoes) return falsemsg("'Sorry, lady-giant, I can do shoes, maybe boots at a push, but... No, not that.'")
return true
},
take:function() {
Expand Down
2 changes: 1 addition & 1 deletion game-house/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict"

settings.playMode = "play"
settings.playMode = "dev"

settings.title = "The House on Highfield Lane"
settings.author = "Andy Joel"
Expand Down
8 changes: 4 additions & 4 deletions game-item-links/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,16 +969,16 @@ createItem("Lara", NPC(true), {
msg:"'That's not a carrot,' Lara points out.",
},
],
getAgreementTake:function(item) {
if (item === w.brick) {
getAgreementTake:function(options) {
if (options.item === w.brick) {
msg("'I'm not picking up any bricks,' says Lara indignantly.")
return false
}
return true
},
getAgreementGo:function(ex) {
getAgreementGo:function(options) {
if (!this.happy) {
msg("'I'm not going " + ex.dir + ",' says Lara indignantly. 'I don't like that room.'")
msg("'I'm not going " + options.exit.dir + ",' says Lara indignantly. 'I don't like that room.'")
return false
}
return true
Expand Down
2 changes: 1 addition & 1 deletion game-tutorial/npcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ createItem("robot", NPC(false), {
if (situation === world.PARSER || w.me.loc === 'laboratory') return true
},

getAgreementGo:function(ex) {
getAgreementGo:function(options) {
if (w.rope.isAttachedTo(this)) {
msg("'I cannot move while tied to the rope.'");
if (!this.ropeMoveFlag) {
Expand Down
6 changes: 3 additions & 3 deletions lib/_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class NpcCmd extends Cmd {
const multiple = (objects[1].length > 1 || parser.currentCommand.all)
for (let obj of objects[1]) {
const options = {multiple:multiple, char:npc, item:obj}
if (!npc.getAgreement(this.cmdCategory, obj, this)) continue
if (!npc.getAgreement(this.cmdCategory, {item:obj, cmd:this})) continue
if (!obj[this.attName]) {
this.default(options)
}
Expand Down Expand Up @@ -367,7 +367,7 @@ class ExitCmd extends Cmd {
if (!currentLocation.hasExit(this.dir)) {
const exitObj = lang.exit_list.find(el => el.name === this.dir )
if (exitObj.not_that_way) return failedmsg(exitObj.not_that_way, {char:player, dir:this.dir})
if (settings.customNoExitMsg) return failedmsg(settings.customNoExitMsg(player, dir))
if (settings.customNoExitMsg) return failedmsg(settings.customNoExitMsg(player, this.dir))
return failedmsg(lang.not_that_way, {char:player, dir:this.dir})
}
else {
Expand Down Expand Up @@ -422,7 +422,7 @@ class NpcExitCmd extends Cmd {
}

if (npc.testMove && !npc.testMove(ex)) return world.FAILED
if (!npc.getAgreement("Go", ex)) return world.FAILED
if (!npc.getAgreement("Go", {exit:ex})) return world.FAILED

const flag = ex.use(npc, ex)
if (flag) npc.pause()
Expand Down
12 changes: 6 additions & 6 deletions lib/_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,7 @@ function handleFillFromVessel(char, source, sink, fluid) {
if (!sink.vessel && !sink.sink) return failedmsg(lang.not_sink, options)
if (sink.vessel && sink.containedFluidName) return failedmsg(lang.already_full, options)
if (!char.testManipulate(source, "fill")) return world.FAILED
if (!char.getAgreement("Fill", source, sink, fluid)) return world.FAILED
if (!char.getAgreement("Fill", {source:source, sink:sink, fluid:fluid})) return world.FAILED
if (!source.isAtLoc(char.name)) return failedmsg(lang.not_carrying, options)
if (source.containedFluidName !== fluid) return failedmsg(lang.no_fluid_here, options);
return source.doEmpty(options) ? world.SUCCESS: world.FAILED;
Expand All @@ -2051,7 +2051,7 @@ function handleFillFromSource(char, source, sink, fluid) {
if (!sink.vessel) return failedmsg(lang.not_vessel, options)
if (sink.containedFluidName) return failedmsg(lang.already_full, options)
if (!char.testManipulate(sink, "fill")) return world.FAILED
if (!char.getAgreement("Fill", source, sink, fluid)) return world.FAILED
if (!char.getAgreement("Fill", {source:source, sink:sink, fluid:fluid})) return world.FAILED
// if the source is the room itself, we assume it is here
if (!source.room && !source.isAtLoc(char.loc)) return failedmsg(lang.not_here, options)
if (!source.isSourceOf(fluid)) return failedmsg(lang.no_fluid_here, options)
Expand Down Expand Up @@ -2104,7 +2104,7 @@ function handleInOutContainer(char, objects, verb, func) {
function handleSingleDropInContainer(char, container, obj, options) {
options.fromLoc = char.name
options.toLoc = container.name
if (!char.getAgreement("Drop/in", obj, container)) return
if (!char.getAgreement("Drop/in", {item:obj, container:container})) return
if (!container.testForRecursion(char, obj)) return false
if (obj.testDrop && !obj.testDrop(options)) return false
if (!obj.msgDropIn) return falsemsg(lang.cannot_drop, options)
Expand All @@ -2125,7 +2125,7 @@ function handleSingleDropInContainer(char, container, obj, options) {
function handleSingleTakeOutContainer(char, container, obj, options) {
options.toLoc = char.name
options.fromLoc = container.name
if (!char.getAgreement("Take", obj)) return false
if (!char.getAgreement("Take", {item:obj})) return false
if (!obj.isAtLoc(container.name)) return failedmsg(lang.not_inside, {container:container, item:obj})
if (obj.getTakeDropCount) obj.getTakeDropCount(options, container.name)
if (obj.testTake && !obj.testTake(options)) return false
Expand Down Expand Up @@ -2173,7 +2173,7 @@ function handleStandUp(objects) {
failedmsg(lang.already, {item:npc});
return world.FAILED;
}
if (!npc.getAgreement("Posture", "stand")) {
if (!npc.getAgreement("Posture", {posture:"stand"})) {
// The getAgreement should give the response
return world.FAILED;
}
Expand Down Expand Up @@ -2204,7 +2204,7 @@ function handlePushExit(char, objects) {
if (room[dir].isLocked()) return failedmsg(lang.locked_exit, {char:char, exit:room[dir]})
if (typeof room[dir].noShiftingMsg === "function") return failedmsg(room[dir].noShiftingMsg(char, item))
if (typeof room[dir].noShiftingMsg === "string") return failedmsg(room[dir].noShiftingMsg)
if (!char.getAgreement("Push", obj, dir)) return false
if (!char.getAgreement("Push", {item:obj, dir:dir})) return false

if (typeof obj.shift === "function") {
const res = obj.shift(char, dir, verb);
Expand Down
2 changes: 1 addition & 1 deletion lib/_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const settings = {
tests:false,
maxUndo:10,
moneyFormat:"$!",
questVersion:'1.3.0',
questVersion:'1.4.0',
mapStyle:{right:'0', top:'200px', width:'300px', height:'300px', 'background-color':'beige' },
openQuotation:"'",
closeQuotation:"'",
Expand Down
10 changes: 5 additions & 5 deletions lib/_templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ const SWITCHABLE = function(alreadyOn, nameModifier) {
return false;
}
if (!this.testSwitchOn(options)) return false
if (!options.char.getAgreement("SwitchOn", this, true)) return false
if (!options.char.getAgreement("SwitchOn", {item:this, switchOn:true})) return false

if (!this.suppressMsgs) options.char.msg(this.msgSwitchOn, options);
this.doSwitchon(options);
Expand All @@ -954,7 +954,7 @@ const SWITCHABLE = function(alreadyOn, nameModifier) {
return false;
}
if (!this.testSwitchOff(options)) return false
if (!options.char.getAgreement("SwitchOn", this, false)) return false
if (!options.char.getAgreement("SwitchOn", {item:this})) return false

if (!this.suppressMsgs) options.char.msg(this.msgSwitchOff, options);
this.doSwitchoff(options);
Expand Down Expand Up @@ -1707,8 +1707,8 @@ const CHARACTER = function() {
followers:[],
money:0,

getAgreement:function(cmdType, obj1, obj2) {
if (this['getAgreement' + cmdType]) return this['getAgreement' + cmdType](obj1, obj2)
getAgreement:function(cmdType, options) {
if (this['getAgreement' + cmdType]) return this['getAgreement' + cmdType](options)
if (this.getAgreementDefault) return this.getAgreementDefault()
return true
},
Expand Down Expand Up @@ -1736,7 +1736,7 @@ const CHARACTER = function() {

handleGiveTo:function(options) {
if (!options.item.isAtLoc(options.char.name)) return falsemsg(lang.not_carrying, options)
if (!options.char.getAgreement("Give", options.item, this)) return false
if (!options.char.getAgreement("Give", options)) return false
if (!options.char.testManipulate(options.item, "give")) return false

options.extraTest = function(options, response) {
Expand Down

0 comments on commit 15b35d6

Please sign in to comment.