-
Notifications
You must be signed in to change notification settings - Fork 0
/
Market.java
109 lines (91 loc) · 3.44 KB
/
Market.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package primary;
import java.util.ArrayList;
import java.util.Random;
/**
* This class contains the items for each region's marketplace
*/
public class Market {
private ArrayList<Item> itemsOffering = new ArrayList<Item>();
private CharacterUpgrade specialItem;
private static int itemsPerMarket = 6;
private static final double TECH_LEVEL_DISCOUNT_FACTOR = 0.1;
private static final double DISCOUNT_MERCHANT_LEVEL = 3;
private static final double MARKET_DEPRECIATION = 0.9;
private static final double FUEL_COST_PER_UNIT = 1.5;
private static final int FUEL_PER_JUG = 100;
private static final int COST_PER_HP = 200;
private static final int COST_WINNING_ITEM = 1000;
private Random rand = new Random();
public void generateMarket(Region currentRegion) {
itemsOffering = new ArrayList<Item>();
Item temp = null;
for (int i = 0; i < itemsPerMarket; i++) {
boolean isNotValid = true;
while (isNotValid) {
temp = new Item();
isNotValid = false;
if (itemsOffering.size() > 0) {
for (Item item : itemsOffering) {
if (temp.getName().equals(item.getName())) {
isNotValid = true;
break;
}
}
}
if (temp.getTechLevel() > currentRegion.getTechLevel()) {
isNotValid = true;
}
}
itemsOffering.add(temp);
calculateAdjustedPrice(itemsOffering.get(i), currentRegion.getTechLevel());
}
boolean isNotValidUpgrade = true;
CharacterUpgrade tempUpgrade = null;
while (isNotValidUpgrade) {
tempUpgrade = new CharacterUpgrade();
isNotValidUpgrade = tempUpgrade.getTechLevel() > currentRegion.getTechLevel();
}
specialItem = tempUpgrade;
}
//final price is going to be discounted based on the tech level
// difference between item and region, plus a random
//decrease or increase
private void calculateAdjustedPrice(Item item, int regionTech) {
item.setAdjustedPrice((int) (item.getPrice()
- (regionTech - item.getTechLevel())
* TECH_LEVEL_DISCOUNT_FACTOR * item.getPrice()
+ item.getPrice() * rand.nextDouble() / 5));
}
private void calculateAdjustedPrice(CharacterUpgrade item, int regionTech) {
item.setAdjustedPrice((int) (item.getPrice() - (regionTech - item.getTechLevel())
* TECH_LEVEL_DISCOUNT_FACTOR * item.getPrice()
+ item.getPrice() * rand.nextDouble() / 5));
}
public ArrayList<Item> getItemsOffering() {
return itemsOffering;
}
public int getItemsPerMarket() {
return itemsPerMarket;
}
public static double getDiscountMerchantLevel() {
return DISCOUNT_MERCHANT_LEVEL;
}
public CharacterUpgrade getSpecialItem() {
return specialItem;
}
public static double getMarketDepreciation() {
return MARKET_DEPRECIATION;
}
public static double getFuelCostPerUnit() {
return FUEL_COST_PER_UNIT;
}
public static int getFuelPerJug() {
return FUEL_PER_JUG;
}
public static int getCostPerHp() {
return COST_PER_HP;
}
public static int getCostWinningItem() {
return COST_WINNING_ITEM;
}
}