I have a working rule about buying something from the location, but it doesn’t work except for naming every single item buyable. I want to generalize that for whatever piece of Equipment the player wants to buy. Below is a sample of two things (without using money currently). My game has almost a hundred buyable things.
Equipment is a kind of thing.
A block is a kind of equipment. An arrow is a kind of equipment.
The Lab is a room. "This is a normal room for conducting experiments.".
One block is in Lab. 15 arrows are in Lab.
The player carries two blocks and 3 arrows.
Instead of buying equipment (called target):
say "Paying for [target]";
if noun is block:
let chosen block be a random block in location;
try silently taking chosen block;
now the noun is the chosen block;
if noun is arrow:
let chosen arrow be a random arrow in location;
try silently taking chosen arrow;
now the noun is the chosen arrow;
When a thing is bought, it reduces its presence in the location and adds it to the player. If the player already has one or more, it increases the number of things of that kind the player has. (Most of this is done behind the scenes in the player acquisition rule.)
I really hate to duplicate code, and it is not a good idea in most languages. Can someone help generalize this rule?
Instead of buying equipment (called target):
If the player carries the target:
Say "You don't see any of those for sale." instead;
say "Paying for [target].";
try silently taking the target.
Does the player mean buying something that is carried by the player: it is very unlikely.
Just need the DTPM rule to make the random choice of which piece of equipment to buy default to something the player isn’t carrying, and I added a check to jump out of the logic if the only instance of the equipment is one the player already carries.
Dunno if it’s possible for the player to drop a piece of equipment they’ve already acquired here, in which case the buying command could get triggered when it shouldn’t; if that’s the case, you might want to have the buying logic cue off of a “for-sale” property or something like that.
I keep running into the problem of “You already have that.” response when I try to buy the second target. How can I turn off that check? The DTPM rule doesn’t do that.
It’s not the text generated by the ‘can’t take what’s already taken rule’ that you want to change (its response). It’s the operation of the rule. In your case, you probably want to block it only when buying.
So you can say:
the can't take what's already taken rule does nothing when buying;