Complete basic crafting functionality

This commit is contained in:
Andrew Miner
2014-12-24 19:17:37 -08:00
parent 3ea6a845c7
commit 1a84ce2e28
20 changed files with 427 additions and 90 deletions
+33 -9
View File
@@ -5,8 +5,10 @@
# All rights reserved.
###
BaseModel = require './base_model'
Inventory = require './inventory'
BaseModel = require './base_model'
CraftingPlan = require './crafting_plan'
{Event} = require '../constants'
Inventory = require './inventory'
########################################################################################################################
@@ -14,14 +16,36 @@ module.exports = class CraftingTable extends BaseModel
constructor: (attributes={}, options={})->
if not attributes.catalog? then throw new Error "attributes.catalog is required"
attributes.name ?= null
attributes.quantity ?= 1
attributes.includingTools ?= false
attributes.have ?= new Inventory
attributes.plan ?= null
super attributes, options
@have = new Inventory
@make = new Inventory
@get = new Inventory
# Public Methods ###############################################################################
craft: (name, quantity=1, includingTools=false)->
toolPhrase = if includingTools then ' includingTools' else ''
logger.verbose "calculating build plan for #{quantity} #{name}#{toolPhrase} with inventory: #{@have}"
craft: ->
if not @name?.length
@plan = null
return
toolPhrase = if @includingTools then ' includingTools' else ''
logger.verbose "calculating build plan for #{@quantity} #{@name}#{toolPhrase} with inventory: #{@have}"
plan = new CraftingPlan @catalog, @includingTools
plan.includingTools = @includingTools
plan.craft @name, @quantity, @have
@plan = plan
# Object Overrides #############################################################################
toString: ->
return "#{@constructor.name} (#{@cid}) {
name:#{@name},
quantity:#{@quantity},
includingTools:#{@includingTools},
have:#{@have},
plan:#{@plan}
}"