Groovy Documentation

de.dewarim.goblin
[Groovy] Class ProductionService

java.lang.Object
  de.dewarim.goblin.ProductionService

class ProductionService

Property Summary
static java.lang.Object transactional

 
Constructor Summary
ProductionService()

 
Method Summary
java.lang.Boolean checkResources(ProductionJob job)

Check if the player has enough resources to pay for the production of an item.

java.lang.Integer computeMaxProduction(Product product, PlayerCharacter pc)

Compute how many items of this product the PC can produce.

void createNewProductionJob(Product product, PlayerCharacter pc, java.lang.Object params)

Create a new ProductionJob for the selected product.

void createProduct(ProductionJob job)

Create the items which make up this product and delete the ProductionJob afterwards.

java.lang.Boolean enoughResourcesSelected(Product product, PlayerCharacter pc, java.lang.Object params)

Check if a player has selected enough resources to create a given product.

java.util.List extractItemListFromParams(java.lang.Object params)

An item has an html input field with name item_$id.

java.util.Map fetchItemCountMapFromParams(java.lang.Object params)

Turn the item ids in the HTTP request into a map of [itemType::amount]

java.util.Map fetchItemMap(Product product, PlayerCharacter pc)

Go through the player character's items and collect a map(component,List::item) of those items which may be used to create the product.

java.lang.Integer makeProducts()

Go through the list of ProductionJobs and try to create each product if the PC has the required amount of products ready.

void spendResources(ProductionJob job)

Spend the required resources on a production job.

void terminateJob(ProductionJob job)

Terminate a ProductionJob, either because the product is finished or because the player character has not been able to create this item.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Property Detail

transactional

static java.lang.Object transactional


 
Constructor Detail

ProductionService

ProductionService()


 
Method Detail

checkResources

java.lang.Boolean checkResources(ProductionJob job)
Check if the player has enough resources to pay for the production of an item. This method examines each resource and makes sure that
Parameters:
job
Returns:


computeMaxProduction

java.lang.Integer computeMaxProduction(Product product, PlayerCharacter pc)
Compute how many items of this product the PC can produce.
Parameters:
product - the product to make
pc - the player character who wants to craft
Returns:
the maximum amount of items the player can create given his current resources.


createNewProductionJob

void createNewProductionJob(Product product, PlayerCharacter pc, java.lang.Object params)
Create a new ProductionJob for the selected product. Verify that the correct amount of items has been selected.
Parameters:
product - the product that the player wants to create
pc - the player character
params - http request params


createProduct

void createProduct(ProductionJob job)
Create the items which make up this product and delete the ProductionJob afterwards. TODO: send a message to the player telling him that the job is done.
Parameters:
job - the ProductionJob which describes the product and who will get the resulting items.


enoughResourcesSelected

java.lang.Boolean enoughResourcesSelected(Product product, PlayerCharacter pc, java.lang.Object params)
Check if a player has selected enough resources to create a given product. This does not check if the resources are actually available at this point. The player sort of makes a promise: "I will have the required resources later on, and I want to use the following piles of items I have here." If the promise is believable (that is, if the ItemTypes are correct and the total amount promised is at least equal to the amount of required resources), a ProductionJob may be created.
Parameters:
product - the product the player wants to create
pc - the player character
params - the http request params
Returns:
true if enough resources have been selected, false otherwise


extractItemListFromParams

java.util.List extractItemListFromParams(java.lang.Object params)
An item has an html input field with name item_$id. This method extracts the id, loads the item and puts it into a list.
Parameters:
params - the http request params
Returns:
a list of items


fetchItemCountMapFromParams

java.util.Map fetchItemCountMapFromParams(java.lang.Object params)
Turn the item ids in the HTTP request into a map of [itemType::amount]
Parameters:
params - the http request parameters
Returns:
a map of itemType::amount


fetchItemMap

java.util.Map fetchItemMap(Product product, PlayerCharacter pc)
Go through the player character's items and collect a map(component,List::item) of those items which may be used to create the product. This method is used to create the selectComponents view of the ProductionController
Parameters:
product - the product the player wishes to create
pc - the active player character
Returns:
a map of items that this PC owns which may be used to create the product


makeProducts

java.lang.Integer makeProducts()
Go through the list of ProductionJobs and try to create each product if the PC has the required amount of products ready. Otherwise, put his production on hold for some time. Note: I want a player to be able to create a list of production jobs, and each of them should be able to create items that will be used "further down the line". But what if the list of ProductionJobs is clogged with jobs that cannot be completed, because the player has left the game or has just put hundreds of fake jobs on the line? Thus a ProductionJob has a limited TTL (Time-To-Live). It will be bumped back in the line until it can be completed - or until its TTL is reached. This way, a player may create a ProductionJob to be done with resources that are not available at this very moment but may be there soon (for example, components which will be produced over night). This of course only goes so far - the player has to decide on an actual item to use, for example: "I want to use 20 of those gold ingots to create a golden grail. No matter that I only got 10 at the moment, but later on I will have all 20 after my 'create gold ingot from ore' production job is through." Note that the player should not be able to submit a job where he has not selected a resource. The program cannot guess if he wanted to enchant one of 99 arrows or his big bad sword to create an expensive rune weapon. Todo: this text should go into the wiki. Once we have one. Todo: multiple production lines. Crossover between PLs
Returns:
the number of processed production jobs.


spendResources

void spendResources(ProductionJob job)
Spend the required resources on a production job. If an item is depleted (that is, there are not more of it around), it will be deleted.
Parameters:
job


terminateJob

void terminateJob(ProductionJob job)
Terminate a ProductionJob, either because the product is finished or because the player character has not been able to create this item.
Parameters:
job - the ProductionJob that will be deleted.


 

Groovy Documentation