Merchant parametrization.

This commit is contained in:
marcins78@gmail.com
2012-03-13 15:15:25 +00:00
parent 1e3e30969d
commit 3738eed287
2 changed files with 9 additions and 5 deletions

View File

@@ -20,7 +20,8 @@ public class ParametrizedMerchant implements Merchant {
private final long _easingTimeMs = 30 * DAY;
private final float _profitMargin = 0.7f;
private final double _returnPrizeSlope = 0.3;
private final double _decreasePrizeSlope = 0.8;
private final double _decreasePrizeSlope = 4;
private final long _decreaseHalfedMs = 30 * DAY;
private MerchantDAO _merchantDao;
private Map<Integer, SetRarity> _rarity = new HashMap<Integer, SetRarity>();
@@ -83,14 +84,16 @@ public class ParametrizedMerchant implements Merchant {
return null;
lastTrans = new MerchantDAO.Transaction(_merchantSetupDate, basePrice, MerchantDAO.TransactionType.SELL);
}
if (lastTrans.getDate().getTime() + _priceRevertTimeMs > currentTime.getTime())
if (lastTrans.getDate().getTime() + _priceRevertTimeMs > currentTime.getTime()) {
if (lastTrans.getTransactionType() == MerchantDAO.TransactionType.SELL) {
return (1 + _fluctuationValue) * lastTrans.getPrice() / (1 + (_fluctuationValue * Math.pow(1f * (currentTime.getTime() - lastTrans.getDate().getTime()) / _priceRevertTimeMs, _returnPrizeSlope)));
} else {
return (1 - _fluctuationValue) * lastTrans.getPrice() / (1 - (_fluctuationValue * Math.pow(1f * (currentTime.getTime() - lastTrans.getDate().getTime()) / _priceRevertTimeMs, _returnPrizeSlope)));
}
}
long timeSinceRevertMs = currentTime.getTime() - lastTrans.getDate().getTime() - _priceRevertTimeMs;
// (stored price)/(1+(fluctuation value * ms since last transaction)/(price revert time in ms))
return lastTrans.getPrice() / (1 + (_fluctuationValue * Math.pow(1f * (currentTime.getTime() - lastTrans.getDate().getTime() - _priceRevertTimeMs) / _priceRevertTimeMs, _decreasePrizeSlope)));
return lastTrans.getPrice() / (1 + Math.pow(1f * timeSinceRevertMs / _decreaseHalfedMs, _decreasePrizeSlope));
}
private Integer getBasePrice(String blueprintId) {

View File

@@ -2,11 +2,12 @@ package com.gempukku.lotro.merchant;
import com.gempukku.lotro.db.MerchantDAO;
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.util.Date;
import static org.junit.Assert.assertTrue;
public class ParametrizedMerchantTest {
@Test
public void checkTransactionRevertsPriceAfterFiveDays() {
@@ -48,7 +49,7 @@ public class ParametrizedMerchantTest {
long hour = 1000 * 60 * 60;
System.out.println("-2,1000,700,1000,700");
for (long time = 0; time < hour * 24 * 20L; time += hour * 2) {
for (long time = 0; time < hour * 24 * 35L; time += hour * 2) {
System.out.println(time / hour + "," + ((int) merchant.getCardSellPrice("1_1", new Date(time))) + "," + ((int) merchant.getCardBuyPrice("1_1", new Date(time)))
+ "," + ((int) merchant.getCardSellPrice("1_2", new Date(time))) + "," + ((int) merchant.getCardBuyPrice("1_2", new Date(time))));
}