Browse Source

change: Holiday Sale only affects holiday items for selling back to the shop.

merge-requests/45/head
Brandon Pearce 2 months ago
parent
commit
8f9e5b871b

+ 4
- 2
src/api/java/com/gildedgames/aether/api/shop/IShopFilter.java View File

@@ -1,8 +1,10 @@
1 1
 package com.gildedgames.aether.api.shop;
2 2
 
3
+import net.minecraft.item.ItemStack;
4
+
3 5
 public interface IShopFilter
4 6
 {
5
-	double getFilteredPrice(IShopInstance instance, double originalPrice);
7
+	double getFilteredPrice(IShopInstance instance, ItemStack stack, double originalPrice);
6 8
 
7
-	int getFilteredPrice(IShopInstance instance, int originalPrice);
9
+	int getFilteredPrice(IShopInstance instance, ItemStack stack, int originalPrice);
8 10
 }

+ 10
- 9
src/api/java/com/gildedgames/aether/api/shop/ShopUtil.java View File

@@ -1,35 +1,36 @@
1 1
 package com.gildedgames.aether.api.shop;
2 2
 
3 3
 import com.gildedgames.aether.api.AetherAPI;
4
+import net.minecraft.item.ItemStack;
4 5
 
5 6
 import java.util.List;
6 7
 
7 8
 public class ShopUtil
8 9
 {
9
-	public static int getFilteredPrice(IShopInstance instance, int price, List<IShopFilter> filters)
10
+	public static int getFilteredPrice(IShopInstance instance, ItemStack stack, int price, List<IShopFilter> filters)
10 11
 	{
11 12
 		int filteredPrice = price;
12 13
 
13 14
 		for (IShopFilter filter : filters)
14 15
 		{
15
-			filteredPrice = filter.getFilteredPrice(instance, filteredPrice);
16
+			filteredPrice = filter.getFilteredPrice(instance, stack, filteredPrice);
16 17
 		}
17 18
 
18 19
 		return filteredPrice;
19 20
 	}
20 21
 
21
-	public static int getFilteredPrice(IShopInstance instance, int price)
22
+	public static int getFilteredPrice(IShopInstance instance, ItemStack stack, int price)
22 23
 	{
23
-		return getFilteredPrice(instance, price, AetherAPI.content().shop().getGlobalFilters());
24
+		return getFilteredPrice(instance, stack, price, AetherAPI.content().shop().getGlobalFilters());
24 25
 	}
25 26
 
26
-	public static double getFilteredPrice(IShopInstance instance, double price, List<IShopFilter> filters)
27
+	public static double getFilteredPrice(IShopInstance instance, ItemStack stack, double price, List<IShopFilter> filters)
27 28
 	{
28 29
 		double filteredPrice = price;
29 30
 
30 31
 		for (IShopFilter filter : filters)
31 32
 		{
32
-			filteredPrice = filter.getFilteredPrice(instance, filteredPrice);
33
+			filteredPrice = filter.getFilteredPrice(instance, stack, filteredPrice);
33 34
 		}
34 35
 
35 36
 		return filteredPrice;
@@ -37,7 +38,7 @@ public class ShopUtil
37 38
 
38 39
 	public static int getFilteredPrice(IShopInstance instance, IShopBuy buy, List<IShopFilter> filters)
39 40
 	{
40
-		return getFilteredPrice(instance, buy.getPrice(), filters);
41
+		return getFilteredPrice(instance, buy.getItemStack(), buy.getPrice(), filters);
41 42
 	}
42 43
 
43 44
 	public static int getFilteredPrice(IShopInstance instance, IShopBuy buy)
@@ -45,8 +46,8 @@ public class ShopUtil
45 46
 		return getFilteredPrice(instance, buy, AetherAPI.content().shop().getGlobalFilters());
46 47
 	}
47 48
 
48
-	public static double getFilteredPrice(IShopInstance instance, double price)
49
+	public static double getFilteredPrice(IShopInstance instance, ItemStack stack, double price)
49 50
 	{
50
-		return getFilteredPrice(instance, price, AetherAPI.content().shop().getGlobalFilters());
51
+		return getFilteredPrice(instance, stack, price, AetherAPI.content().shop().getGlobalFilters());
51 52
 	}
52 53
 }

+ 6
- 4
src/main/java/com/gildedgames/aether/client/gui/dialog/GuiShop.java View File

@@ -447,14 +447,14 @@ public class GuiShop extends GuiViewer implements ICurrencyListener, IExtendedGu
447 447
 
448 448
 			if (shopBuy != null)
449 449
 			{
450
-				value = ShopUtil.getFilteredPrice(this.shopInstance, shopBuy.getSellingPrice()) * (double) stack.getCount();
450
+				value = ShopUtil.getFilteredPrice(this.shopInstance, stack, shopBuy.getSellingPrice()) * (double) stack.getCount();
451 451
 				this.sellCoins.setNonFilteredCurrencyValue(shopBuy.getSellingPrice() * stack.getCount());
452 452
 			}
453 453
 			else
454 454
 			{
455 455
 				double originalValue = AetherAPI.content().currency().getValue(stack, this.shopInstance.getCurrencyType().getClass());
456 456
 
457
-				value = ShopUtil.getFilteredPrice(this.shopInstance, originalValue);
457
+				value = ShopUtil.getFilteredPrice(this.shopInstance, stack, originalValue);
458 458
 				this.sellCoins.setNonFilteredCurrencyValue(originalValue);
459 459
 			}
460 460
 
@@ -690,12 +690,14 @@ public class GuiShop extends GuiViewer implements ICurrencyListener, IExtendedGu
690 690
 		{
691 691
 			ItemStack stack = this.container.getSlot(0).getStack();
692 692
 			double singleValue = ShopUtil
693
-					.getFilteredPrice(this.shopInstance, AetherAPI.content().currency().getSingleValue(stack, this.shopInstance.getCurrencyType().getClass()));
693
+					.getFilteredPrice(this.shopInstance, stack,
694
+							AetherAPI.content().currency().getSingleValue(stack, this.shopInstance.getCurrencyType().getClass()));
694 695
 
695 696
 			if (singleValue < 1)
696 697
 			{
697 698
 				double wholeValue = ShopUtil
698
-						.getFilteredPrice(this.shopInstance, AetherAPI.content().currency().getValue(stack, this.shopInstance.getCurrencyType().getClass()));
699
+						.getFilteredPrice(this.shopInstance, stack,
700
+								AetherAPI.content().currency().getValue(stack, this.shopInstance.getCurrencyType().getClass()));
699 701
 				double decimals = wholeValue - MathHelper.floor(wholeValue);
700 702
 
701 703
 				double howManyTimesDivInto = decimals / singleValue;

+ 12
- 11
src/main/java/com/gildedgames/aether/common/network/packets/PacketShopSell.java View File

@@ -70,9 +70,9 @@ public class PacketShopSell implements IMessage
70 70
 					if (shopInstance != null)
71 71
 					{
72 72
 						ContainerShop container = (ContainerShop) player.openContainer;
73
-						ItemStack stack = container.getSlot(0).getStack();
73
+						ItemStack stackToSell = container.getSlot(0).getStack();
74 74
 
75
-						int hash = ItemHelper.getKeyForItemStack(stack);
75
+						int hash = ItemHelper.getKeyForItemStack(stackToSell);
76 76
 						IShopBuy shopBuy = null;
77 77
 
78 78
 						for (IShopBuy buy : container.getShopInstance().getStock())
@@ -90,34 +90,35 @@ public class PacketShopSell implements IMessage
90 90
 
91 91
 						if (shopBuy != null)
92 92
 						{
93
-							value = ShopUtil.getFilteredPrice(shopInstance, shopBuy.getSellingPrice()) * stack.getCount();
93
+							value = ShopUtil.getFilteredPrice(shopInstance, stackToSell, shopBuy.getSellingPrice()) * stackToSell.getCount();
94 94
 						}
95 95
 						else
96 96
 						{
97 97
 							value = ShopUtil
98
-									.getFilteredPrice(shopInstance, AetherAPI.content().currency().getValue(stack, shopInstance.getCurrencyType().getClass()));
98
+									.getFilteredPrice(shopInstance, stackToSell,
99
+											AetherAPI.content().currency().getValue(stackToSell, shopInstance.getCurrencyType().getClass()));
99 100
 						}
100 101
 
101 102
 						if (value > 0)
102 103
 						{
103
-							ItemStack s = container.getSlot(0).getStack();
104 104
 							double singleValue = ShopUtil
105
-									.getFilteredPrice(shopInstance,
106
-											AetherAPI.content().currency().getSingleValue(s, shopInstance.getCurrencyType().getClass()));
105
+									.getFilteredPrice(shopInstance, stackToSell,
106
+											AetherAPI.content().currency().getSingleValue(stackToSell, shopInstance.getCurrencyType().getClass()));
107 107
 
108 108
 							if (shopBuy != null)
109 109
 							{
110
-								singleValue = ShopUtil.getFilteredPrice(shopInstance, shopBuy.getSellingPrice());
110
+								singleValue = ShopUtil.getFilteredPrice(shopInstance, stackToSell, shopBuy.getSellingPrice());
111 111
 							}
112 112
 
113 113
 							if (singleValue < 1)
114 114
 							{
115 115
 								double wholeValue = ShopUtil
116
-										.getFilteredPrice(shopInstance, AetherAPI.content().currency().getValue(s, shopInstance.getCurrencyType().getClass()));
116
+										.getFilteredPrice(shopInstance, stackToSell,
117
+												AetherAPI.content().currency().getValue(stackToSell, shopInstance.getCurrencyType().getClass()));
117 118
 
118 119
 								if (shopBuy != null)
119 120
 								{
120
-									wholeValue = ShopUtil.getFilteredPrice(shopInstance, shopBuy.getSellingPrice()) * s.getCount();
121
+									wholeValue = ShopUtil.getFilteredPrice(shopInstance, stackToSell, shopBuy.getSellingPrice()) * stackToSell.getCount();
121 122
 								}
122 123
 
123 124
 								double floored = MathHelper.floor(wholeValue);
@@ -128,7 +129,7 @@ public class PacketShopSell implements IMessage
128 129
 
129 130
 								int leftover = MathHelper.floor(howManyTimesDivInto);
130 131
 
131
-								s.setCount(leftover);
132
+								stackToSell.setCount(leftover);
132 133
 
133 134
 								shopInstance.getCurrencyType().addValue((long) floored, playerAether);
134 135
 							}

+ 8
- 4
src/main/java/com/gildedgames/aether/common/shop/filters/ShopFilterNewYearsEdisonSale.java View File

@@ -3,15 +3,18 @@ package com.gildedgames.aether.common.shop.filters;
3 3
 import com.gildedgames.aether.api.shop.IShopFilter;
4 4
 import com.gildedgames.aether.api.shop.IShopInstance;
5 5
 import com.gildedgames.aether.common.AetherCelebrations;
6
+import com.gildedgames.aether.common.util.helpers.ItemHelper;
7
+import net.minecraft.item.ItemStack;
6 8
 
7 9
 public class ShopFilterNewYearsEdisonSale implements IShopFilter
8 10
 {
9 11
 	public static final float DISCOUNT = 0.5F;
10 12
 
11 13
 	@Override
12
-	public double getFilteredPrice(IShopInstance instance, double originalPrice)
14
+	public double getFilteredPrice(IShopInstance instance, ItemStack stack, double originalPrice)
13 15
 	{
14
-		if (AetherCelebrations.isEdisonNewYearsSale(instance))
16
+		if (AetherCelebrations.isEdisonNewYearsSale(instance) && instance.getStock().stream()
17
+				.anyMatch((stock) -> ItemHelper.areEqual(stock.getItemStack(), stack)))
15 18
 		{
16 19
 			return originalPrice * DISCOUNT;
17 20
 		}
@@ -20,9 +23,10 @@ public class ShopFilterNewYearsEdisonSale implements IShopFilter
20 23
 	}
21 24
 
22 25
 	@Override
23
-	public int getFilteredPrice(IShopInstance instance, int originalPrice)
26
+	public int getFilteredPrice(IShopInstance instance, ItemStack stack, int originalPrice)
24 27
 	{
25
-		if (AetherCelebrations.isEdisonNewYearsSale(instance))
28
+		if (AetherCelebrations.isEdisonNewYearsSale(instance) && instance.getStock().stream()
29
+				.anyMatch((stock) -> ItemHelper.areEqual(stock.getItemStack(), stack)))
26 30
 		{
27 31
 			return (int) Math.max(1, originalPrice * DISCOUNT);
28 32
 		}

Loading…
Cancel
Save