Commit 8f9e5b87 authored by Brandon Pearce's avatar Brandon Pearce

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

parent 9a98b72b
Pipeline #500 passed with stage
in 1 minute and 27 seconds
package com.gildedgames.aether.api.shop;
import net.minecraft.item.ItemStack;
public interface IShopFilter
{
double getFilteredPrice(IShopInstance instance, double originalPrice);
double getFilteredPrice(IShopInstance instance, ItemStack stack, double originalPrice);
int getFilteredPrice(IShopInstance instance, int originalPrice);
int getFilteredPrice(IShopInstance instance, ItemStack stack, int originalPrice);
}
package com.gildedgames.aether.api.shop;
import com.gildedgames.aether.api.AetherAPI;
import net.minecraft.item.ItemStack;
import java.util.List;
public class ShopUtil
{
public static int getFilteredPrice(IShopInstance instance, int price, List<IShopFilter> filters)
public static int getFilteredPrice(IShopInstance instance, ItemStack stack, int price, List<IShopFilter> filters)
{
int filteredPrice = price;
for (IShopFilter filter : filters)
{
filteredPrice = filter.getFilteredPrice(instance, filteredPrice);
filteredPrice = filter.getFilteredPrice(instance, stack, filteredPrice);
}
return filteredPrice;
}
public static int getFilteredPrice(IShopInstance instance, int price)
public static int getFilteredPrice(IShopInstance instance, ItemStack stack, int price)
{
return getFilteredPrice(instance, price, AetherAPI.content().shop().getGlobalFilters());
return getFilteredPrice(instance, stack, price, AetherAPI.content().shop().getGlobalFilters());
}
public static double getFilteredPrice(IShopInstance instance, double price, List<IShopFilter> filters)
public static double getFilteredPrice(IShopInstance instance, ItemStack stack, double price, List<IShopFilter> filters)
{
double filteredPrice = price;
for (IShopFilter filter : filters)
{
filteredPrice = filter.getFilteredPrice(instance, filteredPrice);
filteredPrice = filter.getFilteredPrice(instance, stack, filteredPrice);
}
return filteredPrice;
......@@ -37,7 +38,7 @@ public class ShopUtil
public static int getFilteredPrice(IShopInstance instance, IShopBuy buy, List<IShopFilter> filters)
{
return getFilteredPrice(instance, buy.getPrice(), filters);
return getFilteredPrice(instance, buy.getItemStack(), buy.getPrice(), filters);
}
public static int getFilteredPrice(IShopInstance instance, IShopBuy buy)
......@@ -45,8 +46,8 @@ public class ShopUtil
return getFilteredPrice(instance, buy, AetherAPI.content().shop().getGlobalFilters());
}
public static double getFilteredPrice(IShopInstance instance, double price)
public static double getFilteredPrice(IShopInstance instance, ItemStack stack, double price)
{
return getFilteredPrice(instance, price, AetherAPI.content().shop().getGlobalFilters());
return getFilteredPrice(instance, stack, price, AetherAPI.content().shop().getGlobalFilters());
}
}
......@@ -447,14 +447,14 @@ public class GuiShop extends GuiViewer implements ICurrencyListener, IExtendedGu
if (shopBuy != null)
{
value = ShopUtil.getFilteredPrice(this.shopInstance, shopBuy.getSellingPrice()) * (double) stack.getCount();
value = ShopUtil.getFilteredPrice(this.shopInstance, stack, shopBuy.getSellingPrice()) * (double) stack.getCount();
this.sellCoins.setNonFilteredCurrencyValue(shopBuy.getSellingPrice() * stack.getCount());
}
else
{
double originalValue = AetherAPI.content().currency().getValue(stack, this.shopInstance.getCurrencyType().getClass());
value = ShopUtil.getFilteredPrice(this.shopInstance, originalValue);
value = ShopUtil.getFilteredPrice(this.shopInstance, stack, originalValue);
this.sellCoins.setNonFilteredCurrencyValue(originalValue);
}
......@@ -690,12 +690,14 @@ public class GuiShop extends GuiViewer implements ICurrencyListener, IExtendedGu
{
ItemStack stack = this.container.getSlot(0).getStack();
double singleValue = ShopUtil
.getFilteredPrice(this.shopInstance, AetherAPI.content().currency().getSingleValue(stack, this.shopInstance.getCurrencyType().getClass()));
.getFilteredPrice(this.shopInstance, stack,
AetherAPI.content().currency().getSingleValue(stack, this.shopInstance.getCurrencyType().getClass()));
if (singleValue < 1)
{
double wholeValue = ShopUtil
.getFilteredPrice(this.shopInstance, AetherAPI.content().currency().getValue(stack, this.shopInstance.getCurrencyType().getClass()));
.getFilteredPrice(this.shopInstance, stack,
AetherAPI.content().currency().getValue(stack, this.shopInstance.getCurrencyType().getClass()));
double decimals = wholeValue - MathHelper.floor(wholeValue);
double howManyTimesDivInto = decimals / singleValue;
......
......@@ -70,9 +70,9 @@ public class PacketShopSell implements IMessage
if (shopInstance != null)
{
ContainerShop container = (ContainerShop) player.openContainer;
ItemStack stack = container.getSlot(0).getStack();
ItemStack stackToSell = container.getSlot(0).getStack();
int hash = ItemHelper.getKeyForItemStack(stack);
int hash = ItemHelper.getKeyForItemStack(stackToSell);
IShopBuy shopBuy = null;
for (IShopBuy buy : container.getShopInstance().getStock())
......@@ -90,34 +90,35 @@ public class PacketShopSell implements IMessage
if (shopBuy != null)
{
value = ShopUtil.getFilteredPrice(shopInstance, shopBuy.getSellingPrice()) * stack.getCount();
value = ShopUtil.getFilteredPrice(shopInstance, stackToSell, shopBuy.getSellingPrice()) * stackToSell.getCount();
}
else
{
value = ShopUtil
.getFilteredPrice(shopInstance, AetherAPI.content().currency().getValue(stack, shopInstance.getCurrencyType().getClass()));
.getFilteredPrice(shopInstance, stackToSell,
AetherAPI.content().currency().getValue(stackToSell, shopInstance.getCurrencyType().getClass()));
}
if (value > 0)
{
ItemStack s = container.getSlot(0).getStack();
double singleValue = ShopUtil
.getFilteredPrice(shopInstance,
AetherAPI.content().currency().getSingleValue(s, shopInstance.getCurrencyType().getClass()));
.getFilteredPrice(shopInstance, stackToSell,
AetherAPI.content().currency().getSingleValue(stackToSell, shopInstance.getCurrencyType().getClass()));
if (shopBuy != null)
{
singleValue = ShopUtil.getFilteredPrice(shopInstance, shopBuy.getSellingPrice());
singleValue = ShopUtil.getFilteredPrice(shopInstance, stackToSell, shopBuy.getSellingPrice());
}
if (singleValue < 1)
{
double wholeValue = ShopUtil
.getFilteredPrice(shopInstance, AetherAPI.content().currency().getValue(s, shopInstance.getCurrencyType().getClass()));
.getFilteredPrice(shopInstance, stackToSell,
AetherAPI.content().currency().getValue(stackToSell, shopInstance.getCurrencyType().getClass()));
if (shopBuy != null)
{
wholeValue = ShopUtil.getFilteredPrice(shopInstance, shopBuy.getSellingPrice()) * s.getCount();
wholeValue = ShopUtil.getFilteredPrice(shopInstance, stackToSell, shopBuy.getSellingPrice()) * stackToSell.getCount();
}
double floored = MathHelper.floor(wholeValue);
......@@ -128,7 +129,7 @@ public class PacketShopSell implements IMessage
int leftover = MathHelper.floor(howManyTimesDivInto);
s.setCount(leftover);
stackToSell.setCount(leftover);
shopInstance.getCurrencyType().addValue((long) floored, playerAether);
}
......
......@@ -3,15 +3,18 @@ package com.gildedgames.aether.common.shop.filters;
import com.gildedgames.aether.api.shop.IShopFilter;
import com.gildedgames.aether.api.shop.IShopInstance;
import com.gildedgames.aether.common.AetherCelebrations;
import com.gildedgames.aether.common.util.helpers.ItemHelper;
import net.minecraft.item.ItemStack;
public class ShopFilterNewYearsEdisonSale implements IShopFilter
{
public static final float DISCOUNT = 0.5F;
@Override
public double getFilteredPrice(IShopInstance instance, double originalPrice)
public double getFilteredPrice(IShopInstance instance, ItemStack stack, double originalPrice)
{
if (AetherCelebrations.isEdisonNewYearsSale(instance))
if (AetherCelebrations.isEdisonNewYearsSale(instance) && instance.getStock().stream()
.anyMatch((stock) -> ItemHelper.areEqual(stock.getItemStack(), stack)))
{
return originalPrice * DISCOUNT;
}
......@@ -20,9 +23,10 @@ public class ShopFilterNewYearsEdisonSale implements IShopFilter
}
@Override
public int getFilteredPrice(IShopInstance instance, int originalPrice)
public int getFilteredPrice(IShopInstance instance, ItemStack stack, int originalPrice)
{
if (AetherCelebrations.isEdisonNewYearsSale(instance))
if (AetherCelebrations.isEdisonNewYearsSale(instance) && instance.getStock().stream()
.anyMatch((stock) -> ItemHelper.areEqual(stock.getItemStack(), stack)))
{
return (int) Math.max(1, originalPrice * DISCOUNT);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment