Custom costs for different gacha pulls

This commit is contained in:
AnimeGitB 2022-05-11 19:24:59 +09:30 committed by Melledy
parent 3f3ab11ef6
commit cda841dd62
2 changed files with 25 additions and 21 deletions

View File

@ -6,13 +6,18 @@ import emu.grasscutter.utils.Utils;
import static emu.grasscutter.Configuration.*;
import emu.grasscutter.data.common.ItemParamData;
public class GachaBanner {
private int gachaType;
private int scheduleId;
private String prefabPath;
private String previewPrefabPath;
private String titlePath;
private int costItem;
private int costItemId = 0;
private int costItemAmount = 1;
private int costItemId10 = 0;
private int costItemAmount10 = 10;
private int beginTime;
private int endTime;
private int sortId;
@ -36,11 +41,8 @@ public class GachaBanner {
// Kinda wanna deprecate these but they're in people's configs
private int[] rateUpItems1 = {};
private int[] rateUpItems2 = {};
private int softPity = -1;
private int hardPity = -1;
private int eventChance = -1;
private int baseYellowWeight = -1;
private int basePurpleWeight = -1;
private int costItem = 0;
public int getGachaType() {
return gachaType;
@ -66,8 +68,15 @@ public class GachaBanner {
return titlePath;
}
public ItemParamData getCost(int numRolls) {
return switch (numRolls) {
case 10 -> new ItemParamData((costItemId10 > 0) ? costItemId10 : getCostItem(), costItemAmount10);
default -> new ItemParamData(getCostItem(), costItemAmount * numRolls);
};
}
public int getCostItem() {
return costItem;
return (costItem > 0) ? costItem : costItemId;
}
public int getBeginTime() {
@ -82,14 +91,6 @@ public class GachaBanner {
return sortId;
}
public int getBaseYellowWeight() {
return baseYellowWeight;
}
public int getBasePurpleWeight() {
return basePurpleWeight;
}
public int[] getRateUpItems4() {
return (rateUpItems2.length > 0) ? rateUpItems2 : rateUpItems4;
}

View File

@ -19,6 +19,7 @@ import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.gacha.GachaBanner.BannerType;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.Inventory;
import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.inventory.MaterialType;
import emu.grasscutter.game.player.Player;
@ -233,7 +234,8 @@ public class GachaManager {
if (times != 10 && times != 1) {
return;
}
if (player.getInventory().getInventoryTab(ItemType.ITEM_WEAPON).getSize() + times > player.getInventory().getInventoryTab(ItemType.ITEM_WEAPON).getMaxCapacity()) {
Inventory inventory = player.getInventory();
if (inventory.getInventoryTab(ItemType.ITEM_WEAPON).getSize() + times > inventory.getInventoryTab(ItemType.ITEM_WEAPON).getMaxCapacity()) {
player.sendPacket(new PacketDoGachaRsp());
return;
}
@ -246,7 +248,8 @@ public class GachaManager {
}
// Spend currency
if (banner.getCostItem() > 0 && !player.getInventory().payItem(banner.getCostItem(), times)) {
ItemParamData cost = banner.getCost(times);
if (cost.getCount() > 0 && !inventory.payItem(cost)) {
return;
}
@ -304,9 +307,9 @@ public class GachaManager {
}
addStarglitter = (itemData.getRankLevel()==5)? 10 : 2;
int constItemId = itemId + 100;
GameItem constItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(constItemId);
GameItem constItem = inventory.getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(constItemId);
gachaItem.addTransferItems(GachaTransferItem.newBuilder().setItem(ItemParam.newBuilder().setItemId(constItemId).setCount(1)).setIsTransferItemNew(constItem == null));
player.getInventory().addItem(constItemId, 1);
inventory.addItem(constItemId, 1);
}
isTransferItem = true;
break;
@ -315,7 +318,7 @@ public class GachaManager {
// Create item
GameItem item = new GameItem(itemData);
gachaItem.setGachaItem(item.toItemParam());
player.getInventory().addItem(item);
inventory.addItem(item);
stardust += addStardust;
starglitter += addStarglitter;
@ -336,10 +339,10 @@ public class GachaManager {
// Add stardust/starglitter
if (stardust > 0) {
player.getInventory().addItem(stardustId, stardust);
inventory.addItem(stardustId, stardust);
}
if (starglitter > 0) {
player.getInventory().addItem(starglitterId, starglitter);
inventory.addItem(starglitterId, starglitter);
}
// Packets