diff --git a/Input.js b/Input.js index 149a6e1..efd1a87 100644 --- a/Input.js +++ b/Input.js @@ -30,6 +30,7 @@ const buySynonyms = ["buy", "purchase", "barter", "trade", "swap", "exchange"] const sellSynonyms = ["sell"] const dropSynonyms = ["remove", "discard", "drop", "leave", "dispose", "toss", "throw", "throwaway", "trash", "donate", "eat", "consume", "use", "drink", "pay"] const giveSynonyms = ["give", "handover", "hand", "gift"] +const renameItemSynonyms = ["renameitem", "renameobject", "renamegear", "renameequipment"] const inventorySynonyms = ["inv", "inventory", "backpack", "gear", "showinv", "showinventory", "viewinventory", "viewinv"] const clearInventorySynonyms = ["clearinventory", "clearinv", "emptyinventory", "emptybackpack", "clearbackpack", "emptygear", "cleargear"] const learnSpellSynonyms = ["learnspell", "learnmagic", "learnincantation", "learnritual", "memorizespell", "memorizemagic", "memorizeincantation", "memorizeritual", "learnsspell", "learnsmagic", "learnsincantation", "learnsritual", "memorizesspell", "memorizesmagic", "memorizesincantation", "memorizesritual", "learn"] @@ -124,6 +125,7 @@ const modifier = (text) => { if (text == null) text = processCommandSynonyms(command, commandName, takeSynonyms, doTake) if (text == null) text = processCommandSynonyms(command, commandName, dropSynonyms, doDrop) if (text == null) text = processCommandSynonyms(command, commandName, giveSynonyms, doGive) + if (text == null) text = processCommandSynonyms(command, commandName, renameItemSynonyms, doRenameItem) if (text == null) text = processCommandSynonyms(command, commandName, inventorySynonyms, doInventory) if (text == null) text = processCommandSynonyms(command, commandName, clearInventorySynonyms, doClearInventory) if (text == null) text = processCommandSynonyms(command, commandName, learnSpellSynonyms, doLearnSpell) @@ -1436,6 +1438,36 @@ function doSell(command) { return doBuy(`buy ${buyQuantity} ${buyName} ${sellQuantity} ${sellName}`) } +function doRenameItem(command) { + var arg0 = getArgument(command, 0) + if (arg0 == null) { + state.show = "none" + return "\n[Error: Not enough parameters. See #help]\n" + } + + var arg1 = getArgument(command, 1) + if (arg1 == null) { + state.show = "none" + return "\n[Error: Not enough parameters. See #help]\n" + } + + var commandName = getCommandName(command) + var character = getCharacter() + var haveWord = character.name == "You" ? "have" : "has" + var possessiveName = getPossessiveName(character.name) + + state.show = "none" + var text = `\n[${possessiveName} ${arg0} has been renamed to ${arg1}]\n` + + var index = character.inventory.findIndex((element) => element.name.toLowerCase() == arg0.toLowerCase()) + if (index >= 0 ) { + var existingItem = character.inventory[index] + existingItem.name = arg1 + } + + return text +} + function doInventory(command) { state.show = "inventory" return " " diff --git a/Output.js b/Output.js index 2993932..29c4548 100644 --- a/Output.js +++ b/Output.js @@ -283,6 +283,8 @@ const modifier = (text) => { text += "\n Removes the specified quantity of item from the character's inventory. If a quantity is omitted, it's assumed to be 1. The words the, a, and an are ignored." text += "\n#give other_character (quantity or all|every) item" text += "\n Removes the quantity of item from the character's inventory and adds it to the other_character's inventory. If a quantity is omitted, it's assumed to be 1. The words the, a, and an are ignored." + text += "\n#renameitem original_name new_name" + text += "\n Renames the item indicated by original_name to the new_name. The quantity remains the same. Quotes are necessary for items with spaces in the name." text += "\n#inventory" text += "\n Shows the items in the inventory of the character." text += "\n#clearinventory" diff --git a/README.md b/README.md index cb83045..7912d0b 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ Personalized note system that does not take up context space
See the [user guide here](https://github.com/raeleus/Hashtag-DnD/wiki). +v. 0.1.0 +* Added #renameitem to rename an existing item + v. 0.0.6 * #cast no longer requires quotes * Minor bug fixes and improvements @@ -36,4 +39,4 @@ v. 0.0.2 * Minor improvements and bug fixes v. 0.0.1 -* Initial release +* Initial release \ No newline at end of file