1
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet.git synced 2024-07-02 06:45:06 +03:00
salet/lib/character.coffee
Alexander Yakovlev f406c0e692 Renamed objects to units.
Hopefully *this* will clear up the terminology a little bit.
2016-06-03 09:40:48 +07:00

41 lines
880 B
CoffeeScript

invlink = (content, ref) ->
return "<a href='./_inv_#{ref}' class='once'>#{content}</a>"
class Character
constructor: (spec) ->
@inventory = []
@take = (thing) =>
@inventory.push thing
@drop = (thing) =>
for i in @inventory
if i.name == thing
index = @inventory.indexOf(thing)
@inventory.splice(index, 1)
@has = (thing) =>
for i in @inventory
if i.name == thing
return true
return false
@listinv = (thing) =>
for i in @inventory
if i.name == thing
return invlink(i.display, i.name)
@inv = (thing) =>
for i in @inventory
if i.name == thing
return i.inv.fcall(i)
for index, value of spec
this[index] = value
return this
character = (spec) ->
spec ?= {}
return( new Character(spec) )
module.exports = character