2016-03-20 15:46:40 +02:00
|
|
|
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
|
2016-06-03 05:40:48 +03:00
|
|
|
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
|
|
|
|
|
2016-03-20 15:46:40 +02:00
|
|
|
@listinv = (thing) =>
|
|
|
|
for i in @inventory
|
|
|
|
if i.name == thing
|
2016-05-09 07:01:11 +03:00
|
|
|
return invlink(i.display, i.name)
|
2016-03-20 15:46:40 +02:00
|
|
|
|
|
|
|
@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
|