mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 10:55:56 +00:00
More usage of payItems
This commit is contained in:
parent
c7d5d8640c
commit
74783cfecd
@ -128,7 +128,7 @@ public class GachaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Spend currency
|
// Spend currency
|
||||||
if (banner.getCostItem() > 0 && !player.getInventory().payItems(new ItemParamData[] {new ItemParamData(banner.getCostItem(), times)})) {
|
if (banner.getCostItem() > 0 && !player.getInventory().payItem(banner.getCostItem(), times)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,6 +272,14 @@ public class Inventory implements Iterable<GameItem> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean payItem(int id, int count) {
|
||||||
|
return payItem(new ItemParamData(id, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean payItem(ItemParamData costItem) {
|
||||||
|
return payItems(new ItemParamData[] {costItem}, 1, null);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean payItems(ItemParamData[] costItems) {
|
public boolean payItems(ItemParamData[] costItems) {
|
||||||
return payItems(costItems, 1, null);
|
return payItems(costItems, 1, null);
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ public class InventoryManager {
|
|||||||
|
|
||||||
private final static int RELIC_MATERIAL_1 = 105002; // Sanctifying Unction
|
private final static int RELIC_MATERIAL_1 = 105002; // Sanctifying Unction
|
||||||
private final static int RELIC_MATERIAL_2 = 105003; // Sanctifying Essence
|
private final static int RELIC_MATERIAL_2 = 105003; // Sanctifying Essence
|
||||||
|
private final static int RELIC_MATERIAL_EXP_1 = 2500; // Sanctifying Unction
|
||||||
|
private final static int RELIC_MATERIAL_EXP_2 = 10000; // Sanctifying Essence
|
||||||
|
|
||||||
private final static int WEAPON_ORE_1 = 104011; // Enhancement Ore
|
private final static int WEAPON_ORE_1 = 104011; // Enhancement Ore
|
||||||
private final static int WEAPON_ORE_2 = 104012; // Fine Enhancement Ore
|
private final static int WEAPON_ORE_2 = 104012; // Fine Enhancement Ore
|
||||||
@ -86,6 +88,7 @@ public class InventoryManager {
|
|||||||
int moraCost = 0;
|
int moraCost = 0;
|
||||||
int expGain = 0;
|
int expGain = 0;
|
||||||
|
|
||||||
|
List<GameItem> foodRelics = new ArrayList<GameItem>();
|
||||||
for (long guid : foodRelicList) {
|
for (long guid : foodRelicList) {
|
||||||
// Add to delete queue
|
// Add to delete queue
|
||||||
GameItem food = player.getInventory().getItemByGuid(guid);
|
GameItem food = player.getInventory().getItemByGuid(guid);
|
||||||
@ -97,23 +100,21 @@ public class InventoryManager {
|
|||||||
expGain += food.getItemData().getBaseConvExp();
|
expGain += food.getItemData().getBaseConvExp();
|
||||||
// Feeding artifact with exp already
|
// Feeding artifact with exp already
|
||||||
if (food.getTotalExp() > 0) {
|
if (food.getTotalExp() > 0) {
|
||||||
expGain += (int) Math.floor(food.getTotalExp() * .8f);
|
expGain += (food.getTotalExp() * 4) / 5;
|
||||||
}
|
}
|
||||||
|
foodRelics.add(food);
|
||||||
}
|
}
|
||||||
|
List<ItemParamData> payList = new ArrayList<ItemParamData>();
|
||||||
for (ItemParam itemParam : list) {
|
for (ItemParam itemParam : list) {
|
||||||
GameItem food = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(itemParam.getItemId());
|
int amount = itemParam.getCount(); // Previously this capped to inventory amount, but rejecting the payment makes more sense for an invalid order
|
||||||
if (food == null || food.getItemData().getMaterialType() != MaterialType.MATERIAL_RELIQUARY_MATERIAL) {
|
int gain = amount * switch(itemParam.getItemId()) {
|
||||||
continue;
|
case RELIC_MATERIAL_1 -> RELIC_MATERIAL_EXP_1;
|
||||||
}
|
case RELIC_MATERIAL_2 -> RELIC_MATERIAL_EXP_2;
|
||||||
int amount = Math.min(food.getCount(), itemParam.getCount());
|
default -> 0;
|
||||||
int gain = 0;
|
};
|
||||||
if (food.getItemId() == RELIC_MATERIAL_2) {
|
|
||||||
gain = 10000 * amount;
|
|
||||||
} else if (food.getItemId() == RELIC_MATERIAL_1) {
|
|
||||||
gain = 2500 * amount;
|
|
||||||
}
|
|
||||||
expGain += gain;
|
expGain += gain;
|
||||||
moraCost += gain;
|
moraCost += gain;
|
||||||
|
payList.add(new ItemParamData(itemParam.getItemId(), itemParam.getCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure exp gain is valid
|
// Make sure exp gain is valid
|
||||||
@ -121,28 +122,14 @@ public class InventoryManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check mora
|
// Confirm payment of materials and mora (assume food relics are payable afterwards)
|
||||||
if (player.getMora() < moraCost) {
|
payList.add(new ItemParamData(202, moraCost));
|
||||||
|
if (!player.getInventory().payItems(payList.toArray(new ItemParamData[0]))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.setMora(player.getMora() - moraCost);
|
|
||||||
|
|
||||||
// Consume food items
|
// Consume food relics
|
||||||
for (long guid : foodRelicList) {
|
player.getInventory().removeItems(foodRelics);
|
||||||
GameItem food = player.getInventory().getItemByGuid(guid);
|
|
||||||
if (food == null || !food.isDestroyable()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
player.getInventory().removeItem(food);
|
|
||||||
}
|
|
||||||
for (ItemParam itemParam : list) {
|
|
||||||
GameItem food = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(itemParam.getItemId());
|
|
||||||
if (food == null || food.getItemData().getMaterialType() != MaterialType.MATERIAL_RELIQUARY_MATERIAL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int amount = Math.min(food.getCount(), itemParam.getCount());
|
|
||||||
player.getInventory().removeItem(food, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implement random rate boost
|
// Implement random rate boost
|
||||||
int rate = 1;
|
int rate = 1;
|
||||||
@ -232,22 +219,16 @@ public class InventoryManager {
|
|||||||
}
|
}
|
||||||
expGain += food.getItemData().getWeaponBaseExp();
|
expGain += food.getItemData().getWeaponBaseExp();
|
||||||
if (food.getTotalExp() > 0) {
|
if (food.getTotalExp() > 0) {
|
||||||
expGain += (int) Math.floor(food.getTotalExp() * .8f);
|
expGain += (food.getTotalExp() * 4) / 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (ItemParam param : itemParamList) {
|
for (ItemParam param : itemParamList) {
|
||||||
GameItem food = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(param.getItemId());
|
expGain += param.getCount() * switch(param.getItemId()) {
|
||||||
if (food == null || food.getItemData().getMaterialType() != MaterialType.MATERIAL_WEAPON_EXP_STONE) {
|
case WEAPON_ORE_1 -> WEAPON_ORE_EXP_1;
|
||||||
continue;
|
case WEAPON_ORE_2 -> WEAPON_ORE_EXP_2;
|
||||||
}
|
case WEAPON_ORE_3 -> WEAPON_ORE_EXP_3;
|
||||||
int amount = Math.min(param.getCount(), food.getCount());
|
default -> 0;
|
||||||
if (food.getItemId() == WEAPON_ORE_3) {
|
};
|
||||||
expGain += 10000 * amount;
|
|
||||||
} else if (food.getItemId() == WEAPON_ORE_2) {
|
|
||||||
expGain += 2000 * amount;
|
|
||||||
} else if (food.getItemId() == WEAPON_ORE_1) {
|
|
||||||
expGain += 400 * amount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try
|
// Try
|
||||||
@ -289,65 +270,45 @@ public class InventoryManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get exp gain
|
// Get exp gain
|
||||||
int expGain = 0, moraCost = 0;
|
int expGain = 0, expGainFree = 0;
|
||||||
|
List<GameItem> foodWeapons = new ArrayList<GameItem>();
|
||||||
for (long guid : foodWeaponGuidList) {
|
for (long guid : foodWeaponGuidList) {
|
||||||
GameItem food = player.getInventory().getItemByGuid(guid);
|
GameItem food = player.getInventory().getItemByGuid(guid);
|
||||||
if (food == null || !food.isDestroyable()) {
|
if (food == null || !food.isDestroyable()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
expGain += food.getItemData().getWeaponBaseExp();
|
expGain += food.getItemData().getWeaponBaseExp();
|
||||||
moraCost += (int) Math.floor(food.getItemData().getWeaponBaseExp() * .1f);
|
|
||||||
if (food.getTotalExp() > 0) {
|
if (food.getTotalExp() > 0) {
|
||||||
expGain += (int) Math.floor(food.getTotalExp() * .8f);
|
expGainFree += (food.getTotalExp() * 4) / 5; // No tax :D
|
||||||
}
|
}
|
||||||
|
foodWeapons.add(food);
|
||||||
}
|
}
|
||||||
|
List<ItemParamData> payList = new ArrayList<ItemParamData>();
|
||||||
for (ItemParam param : itemParamList) {
|
for (ItemParam param : itemParamList) {
|
||||||
GameItem food = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(param.getItemId());
|
int amount = param.getCount(); // Previously this capped to inventory amount, but rejecting the payment makes more sense for an invalid order
|
||||||
if (food == null || food.getItemData().getMaterialType() != MaterialType.MATERIAL_WEAPON_EXP_STONE) {
|
int gain = amount * switch(param.getItemId()) {
|
||||||
continue;
|
case WEAPON_ORE_1 -> WEAPON_ORE_EXP_1;
|
||||||
}
|
case WEAPON_ORE_2 -> WEAPON_ORE_EXP_2;
|
||||||
int amount = Math.min(param.getCount(), food.getCount());
|
case WEAPON_ORE_3 -> WEAPON_ORE_EXP_3;
|
||||||
int gain = 0;
|
default -> 0;
|
||||||
if (food.getItemId() == WEAPON_ORE_3) {
|
};
|
||||||
gain = 10000 * amount;
|
|
||||||
} else if (food.getItemId() == WEAPON_ORE_2) {
|
|
||||||
gain = 2000 * amount;
|
|
||||||
} else if (food.getItemId() == WEAPON_ORE_1) {
|
|
||||||
gain = 400 * amount;
|
|
||||||
}
|
|
||||||
expGain += gain;
|
expGain += gain;
|
||||||
moraCost += (int) Math.floor(gain * .1f);
|
payList.add(new ItemParamData(param.getItemId(), amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure exp gain is valid
|
// Make sure exp gain is valid
|
||||||
|
int moraCost = expGain / 10;
|
||||||
|
expGain += expGainFree;
|
||||||
if (expGain <= 0) {
|
if (expGain <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mora check
|
// Confirm payment of materials and mora (assume food weapons are payable afterwards)
|
||||||
if (player.getMora() >= moraCost) {
|
payList.add(new ItemParamData(202, moraCost));
|
||||||
player.setMora(player.getMora() - moraCost);
|
if (!player.getInventory().payItems(payList.toArray(new ItemParamData[0]))) {
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
player.getInventory().removeItems(foodWeapons);
|
||||||
// Consume weapon/items used to feed
|
|
||||||
for (long guid : foodWeaponGuidList) {
|
|
||||||
GameItem food = player.getInventory().getItemByGuid(guid);
|
|
||||||
if (food == null || !food.isDestroyable()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
player.getInventory().removeItem(food);
|
|
||||||
}
|
|
||||||
for (ItemParam param : itemParamList) {
|
|
||||||
GameItem food = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(param.getItemId());
|
|
||||||
if (food == null || food.getItemData().getMaterialType() != MaterialType.MATERIAL_WEAPON_EXP_STONE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int amount = Math.min(param.getCount(), food.getCount());
|
|
||||||
player.getInventory().removeItem(food, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Level up
|
// Level up
|
||||||
int maxLevel = promoteData.getUnlockMaxLevel();
|
int maxLevel = promoteData.getUnlockMaxLevel();
|
||||||
@ -394,7 +355,7 @@ public class InventoryManager {
|
|||||||
player.sendPacket(new PacketWeaponUpgradeRsp(weapon, oldLevel, leftovers));
|
player.sendPacket(new PacketWeaponUpgradeRsp(weapon, oldLevel, leftovers));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ItemParam> getLeftoverOres(float leftover) {
|
private List<ItemParam> getLeftoverOres(int leftover) {
|
||||||
List<ItemParam> leftoverOreList = new ArrayList<>(3);
|
List<ItemParam> leftoverOreList = new ArrayList<>(3);
|
||||||
|
|
||||||
if (leftover < WEAPON_ORE_EXP_1) {
|
if (leftover < WEAPON_ORE_EXP_1) {
|
||||||
@ -402,11 +363,11 @@ public class InventoryManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get leftovers
|
// Get leftovers
|
||||||
int ore3 = (int) Math.floor(leftover / WEAPON_ORE_EXP_3);
|
int ore3 = leftover / WEAPON_ORE_EXP_3;
|
||||||
leftover = leftover % WEAPON_ORE_EXP_3;
|
leftover = leftover % WEAPON_ORE_EXP_3;
|
||||||
int ore2 = (int) Math.floor(leftover / WEAPON_ORE_EXP_2);
|
int ore2 = leftover / WEAPON_ORE_EXP_2;
|
||||||
leftover = leftover % WEAPON_ORE_EXP_2;
|
leftover = leftover % WEAPON_ORE_EXP_2;
|
||||||
int ore1 = (int) Math.floor(leftover / WEAPON_ORE_EXP_1);
|
int ore1 = leftover / WEAPON_ORE_EXP_1;
|
||||||
|
|
||||||
if (ore3 > 0) {
|
if (ore3 > 0) {
|
||||||
leftoverOreList.add(ItemParam.newBuilder().setItemId(WEAPON_ORE_3).setCount(ore3).build());
|
leftoverOreList.add(ItemParam.newBuilder().setItemId(WEAPON_ORE_3).setCount(ore3).build());
|
||||||
@ -595,34 +556,25 @@ public class InventoryManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameItem feedItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(itemId);
|
|
||||||
|
|
||||||
if (feedItem == null || feedItem.getItemData().getMaterialType() != MaterialType.MATERIAL_EXP_FRUIT || feedItem.getCount() < count) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calc exp
|
// Calc exp
|
||||||
int expGain = 0, moraCost = 0;
|
int expGain = switch(itemId) {
|
||||||
|
case AVATAR_BOOK_1 -> AVATAR_BOOK_EXP_1 * count;
|
||||||
|
case AVATAR_BOOK_2 -> AVATAR_BOOK_EXP_2 * count;
|
||||||
|
case AVATAR_BOOK_3 -> AVATAR_BOOK_EXP_3 * count;
|
||||||
|
default -> 0;
|
||||||
|
};
|
||||||
|
|
||||||
// TODO clean up
|
// Sanity check
|
||||||
if (itemId == AVATAR_BOOK_3) {
|
if (expGain <= 0) {
|
||||||
expGain = AVATAR_BOOK_EXP_3 * count;
|
|
||||||
} else if (itemId == AVATAR_BOOK_2) {
|
|
||||||
expGain = AVATAR_BOOK_EXP_2 * count;
|
|
||||||
} else if (itemId == AVATAR_BOOK_1) {
|
|
||||||
expGain = AVATAR_BOOK_EXP_1 * count;
|
|
||||||
}
|
|
||||||
moraCost = (int) Math.floor(expGain * .2f);
|
|
||||||
|
|
||||||
// Mora check
|
|
||||||
if (player.getMora() >= moraCost) {
|
|
||||||
player.setMora(player.getMora() - moraCost);
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consume items
|
// Payment check
|
||||||
player.getInventory().removeItem(feedItem, count);
|
int moraCost = expGain / 5;
|
||||||
|
ItemParamData[] costItems = new ItemParamData[] {new ItemParamData(itemId, count), new ItemParamData(202, moraCost)};
|
||||||
|
if (!player.getInventory().payItems(costItems)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Level up
|
// Level up
|
||||||
upgradeAvatar(player, avatar, promoteData, expGain);
|
upgradeAvatar(player, avatar, promoteData, expGain);
|
||||||
@ -783,14 +735,11 @@ public class InventoryManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameItem costItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(talentData.getMainCostItemId());
|
// Pay constellation item if possible
|
||||||
if (costItem == null || costItem.getCount() < talentData.getMainCostItemCount()) {
|
if (!player.getInventory().payItem(talentData.getMainCostItemId(), 1)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consume item
|
|
||||||
player.getInventory().removeItem(costItem, talentData.getMainCostItemCount());
|
|
||||||
|
|
||||||
// Apply + recalc
|
// Apply + recalc
|
||||||
avatar.getTalentIdList().add(talentData.getId());
|
avatar.getTalentIdList().add(talentData.getId());
|
||||||
avatar.setCoreProudSkillLevel(currentTalentLevel + 1);
|
avatar.setCoreProudSkillLevel(currentTalentLevel + 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user