scrom / Experiments

a NodeJS text adventure - deliberately coded badly to re-experience the pain of legacy code
http://mvta.herokuapp.com/
2 stars 0 forks source link

Handle charges, quantities, duplicate, multiples and plurals properly #151

Open scrom opened 10 years ago

scrom commented 10 years ago

This area of the game code is a complete mess. At the moment, we have "charges" and "quantity" on an artifact but neither are well implemented.

If I have 5 ice creams, I want to see "5 ice creams". Not "some ice cream" or "an ice cream, an ice cream... and an ice cream".

"charges" are used for "hasPower", "consume" and "consumeItem".

"quantity" is used for grammar around plurals and nothing else. The only item to use quantity right now is "beans" - and this is set to -1. It's not set for "crisps" (although it should be).

Milk, Money (bag), Beans and Chocolate all have a positive value set for "charges". These are used for "deliver" and nothing else.

Torch has a value of -1 for charges. This is used for "hasPower".

All these quantities have different uses and approaches. Beans - is an undefined plural but there are enough for 10 cups of coffee. Milk is the same. Chocolate is a single bar and charges is simply used to consume it. The money bag isn't properly used for anything (we have a different method of tracking money).

scrom commented 10 years ago

Have just added quantity attribute for: sugar, milk, sweet coffee and coffee. All these cases are to support proper use of plurals in item description.

scrom commented 10 years ago

use of plurals in description now done.

scrom commented 10 years ago

Next step in sorting quantities has been checked in - this is an interim step prior to entirely removing the "quantity" attribute for a while and replacing it with some form of "plural" flag.

scrom commented 10 years ago

Quantity attribute now removed - replaced with "plural" attribute flag

scrom commented 10 years ago

Have also implemented some tweaks for "charges" - these will need follow on work but there are now 2 new optional attributes. These come into play when examining an object and retrieving the detailed description... If "charges" is set to a positive value, when describing an item we'll check for the attribute "chargesDescription": If this exists, we'll use this rather than a default string. Furthermore, this description can take 2 placeholders: $charges and $chargeUnit $charges will be substituted for the current value of _charges on the item. $chargeUnit will take the attribute value of "chargeUnit" and append an s to make this plural if charges are greater than 1. (if charges are only 1 - they won't be reported at all)

Here's an example: "charges": 10, "chargeUnit": "cup", "chargesDescription": "There's enough for about $charges $chargeUnit of coffee",

scrom commented 10 years ago

Charges for food and drink are now properly implemented. Note the default is still -1 so when creating food items, it's important to explicitly define 1 or more charges in order for it to be fully consumed.

(the -1 works so that for example a player can "drink water" from a tap endlessly (or almost)

scrom commented 10 years ago

note. Plural attribute flag needs better handling in inventory description. e.g. "it contains" vs "they contain"

scrom commented 10 years ago

pluralisation (contains/contain) is now fixed. in addition, charges for items that combine now works reasonably well. "reasonably" being if you add the item with charges to a container first, it's all added. If you add it at the end, only one charge is used. I'm actually quite happy with that approach. The alternative would be to ask the user how much of x to add to y - that would need a lot more work.

scrom commented 10 years ago

duplicates still not working - hard to resolve

scrom commented 9 years ago

an idea on duplicates. when an item is added to inventory, if another identical item exists, call a "merge" function. merging an item would set a "merged" flag. "charges" would be set to the number of items merged "weight" would be the sum of merged items.

there's a bit of a trick in adding an item to inventory where same items have previously been merged but I think that can be handled.

when the same item is requested back from the inventory, call a "split" function. also allow retrieving the merged item directly by name e.g. "5 chocolate bars".

there's some subtleties around whether an item is identical to be sorted.

scrom commented 9 years ago

that was a good idea but didn't work so well in practice - too many references to handle. current approach is simply to spot and consolidate duplicates when describing contents of inventory.

So far it works well but again, we cannot reference the consolidated items properly.

ugh

scrom commented 9 years ago

step 1 completed - showing collations in inventory descriptions! need to handle user interacting with collations though :(