What would be the best approach to create a system to allow for custom item scripts?
Nethack example, Lets say I want to create an item: “Potion of Raise Level”. When user consumes this item, it raises the characters level. However, if it’s cursed, it actually raises the character itself up a physical dungeon level. But, lets say the function SendPlayerTo(‘Space Right Above Player’) returns “That space is blocked, epic fail”. I don’t want the potion to be “consumed”. Instead DisplayMessage("Newb, you can’t do that).
I thought about doing this with interfaces, and then creating each item as it’s own class, but that seems ugly.
It seems impossible to have this kind of “flexibility” by hard coding item definitions. My other idea was to create a List drinkActions;
and I would iterate through the actions and execute each one by one, but that doesn’t give me to oppurtunity to do like “If this action fails, do this instead”. But it does allow me to create items in XML, or a Unity Editor Extension.
Anyone else have any ideas?