Complete basic crafting functionality
This commit is contained in:
@@ -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}
|
||||
}"
|
||||
|
||||
Reference in New Issue
Block a user