Skip to content

Instantly share code, notes, and snippets.

View VirtuosiMedia's full-sized avatar

Virtuosi Media VirtuosiMedia

View GitHub Profile

Release Notes

Note 1

07/07/2019

Fix

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi porttitor est quis tellus aliquam, et cursus nisi lobortis. Nulla felis magna, scelerisque sit amet lobortis eget, fermentum blandit lacus. Ut id orci condimentum, pretium nunc sit amet, congue lorem. Vivamus est dolor, imperdiet ac lectus vel, feugiat ultrices dui. In tincidunt ante eu leo vehicula vehicula.

Note 2

07/08/2019

New

/**
* Calculates all trade functionality.
* Copyright Virtuosi Media, Inc.
*/
jg.calculate.trade = {
resources: false,
components: false,
/**
/**
* Renders the trade center screen.
* Copyright Virtuosi Media, Inc.
*/
jg.templates.commercial.tradeCenter = function(){
return {
updateManager: function(){
},
/**
* Cancels an order for a good from a holding.
* @param {int} holdingId The holding id.
* @param {string} good The good id.
*/
cancelTradeOrder: function(holdingId, good){
var holding = jg.data.holdings[holdingId];
var order = holding.data.economic.trade.orders[good];
if (order.orderType === 'order'){
/**
* Unlocks a purchase bid, canceling it and rerendering the table and the resource panel.
* @param {HTMLObject} target The unlock button.
*/
cancelBid: function(target){
var good = target.get('data-good');
var holding = jg.data.state.holding;
var template = jg.templates.commercial.tradeCenter();
jg.calculate.trade.cancelTradeOrder(holding, good);
/**
* Places an order for a good from a holding.
* @param {int} holdingId The holding id.
* @param {string} good The good id.
* @param {string} goodCategory The good category: resource, component.
* @param {float} price The price of the order.
* @param {int} quantity The quantity of goods ordered.
* @param {string} orderType The type of purchase: trade or order.
* @return {boolean} TRUE if the order was placed, FALSE if there were insufficient resources.
*/
/**
* Locks in a purchase bid, but checks for errors first then rerenders the table and the resource panel.
* @param {HTMLObject} target The lock button.
*/
placeBid: function(target){
var good = target.get('data-good');
var goodCategory = target.get('data-goodCategory');
var priceInput = _.$('purchasePrice-' + good);
var quantityInput = _.$('purchaseQuantity-' + good);
var price = parseFloat(priceInput.value);
/**
* Gets the order purchase price for a particular good from a holding.
* @param {int} holding The holding id.
* @param {string} good The good id.
* @return {mixed} The order purchase price if the order exists, false otherwise.
*/
getGoodOrderPrice: function(holding, good){
var orders = jg.data.holdings[holding].data.economic.trade.orders;
return (orders.hasKey(good)) ? orders[good].price : false;
},
/**
* Retrieves a base price for a given good based on the base prices of all resources used to craft it.
* @param {string} good The good id.
* @return {numeric} The base price of the good.
*/
getGoodBasePrice: function(good){
if (!this.resources){
this.resources = _.container(_.language.getDataSet('resources'));
}
/**
* Gets the average sales price for a good from all entities that are selling it.
* @param {int} holdingId The holding id.
* @param {string} good The good id.
* @return {numeric} The average sales price for the good.
*/
getAverageGoodSalesPrice: function(holdingId, good){
var numSellers = 1;
var totalPrice = this.getGoodBasePrice(good);