1
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet.git synced 2024-07-04 07:45:03 +03:00
salet/lib/character.coffee

41 lines
880 B
CoffeeScript
Raw Normal View History

invlink = (content, ref) ->
return "<a href='./_inv_#{ref}' class='once'>#{content}</a>"
2016-02-10 15:35:44 +02:00
class Character
constructor: (spec) ->
@inventory = []
@take = (thing) =>
@inventory.push thing
@drop = (thing) =>
for i in @inventory
if i.name == thing
index = @inventory.indexOf(thing)
2016-02-10 15:35:44 +02:00
@inventory.splice(index, 1)
2016-03-20 14:41:47 +02:00
@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)
2016-02-10 15:35:44 +02:00
for index, value of spec
this[index] = value
return this
character = (spec) ->
spec ?= {}
return( new Character(spec) )
module.exports = character