So for fun I started to write a simplistic fantasy text RPG. One of the things
included is the notion of various items a character can randomly find, such as
treasures, weapons, and armor. I thought that it would be useful to randomly
create an item (here a weapon) in the following manner:
type
Item* = ref object of RootObj
description*: string
Treasure* = ref object of Item
baseValue*: int
Weapon* = ref object of Treasure
baseDamage*: int
Sword* = ref object of Weapon
Axe* = ref object of Weapon
Wand* = ref object of Weapon
Daggers* = ref object of Weapon
type
Damaging {.explain.} = concept w
w.baseDamage is int
proc newSword(): Sword =
discard
proc newAxe(): Axe =
discard
proc newWand(): Wand =
discard
proc newDaggers(): Daggers =
discard
const Weapons: seq[proc():Damaging] = @[newSword, newAxe, newWand,
newDaggers]
proc genWeapon(): Weapon =
Weapons[random(Weapons.len)]()
Unfortunately, using concepts in this way doesn't seem to work. Is there some
approach I could take to achieve this?
Best regards,
Steve