mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-23 10:44:36 +01:00
Fix salvaging items
This commit is contained in:
@@ -32,6 +32,7 @@ public class GameConstants {
|
||||
public static final int MATERIAL_HCOIN_ID = 1; // Material id for jades. DO NOT CHANGE
|
||||
public static final int MATERIAL_COIN_ID = 2; // Material id for credits. DO NOT CHANGE
|
||||
public static final int TRAILBLAZER_EXP_ID = 22;
|
||||
public static final int RELIC_REMAINS_ID = 235;
|
||||
|
||||
public static final int INVENTORY_MAX_EQUIPMENT = 1500;
|
||||
public static final int INVENTORY_MAX_RELIC = 1500;
|
||||
|
||||
@@ -313,26 +313,31 @@ public class Inventory extends BasePlayerManager {
|
||||
List<GameItem> results = new ArrayList<GameItem>(items.size());
|
||||
|
||||
for (ItemParam param : items) {
|
||||
// Check param type
|
||||
if (param.getId() == GameConstants.MATERIAL_COIN_ID) {
|
||||
// Remove credits
|
||||
getPlayer().addSCoin(-param.getCount() * multiplier);
|
||||
} else if (param.getId() == GameConstants.MATERIAL_HCOIN_ID) {
|
||||
// Remove credits
|
||||
getPlayer().addHCoin(-param.getCount() * multiplier);
|
||||
} else if (param.getId() == GameConstants.ROGUE_TALENT_POINT_ITEM_ID) {
|
||||
// Remove credits
|
||||
getPlayer().addTalentPoints(-param.getCount() * multiplier);
|
||||
} else {
|
||||
// Remove param items
|
||||
GameItem item = this.getItemByParam(param);
|
||||
if (item == null) continue;
|
||||
|
||||
GameItem result = this.deleteItem(item, param.getCount() * multiplier);
|
||||
if (result != null) {
|
||||
results.add(result);
|
||||
// Remove virtual items first
|
||||
if (param.getType() == ItemParamType.PILE) {
|
||||
if (param.getId() == GameConstants.MATERIAL_COIN_ID) {
|
||||
// Remove credits
|
||||
getPlayer().addSCoin(-param.getCount() * multiplier);
|
||||
continue;
|
||||
} else if (param.getId() == GameConstants.MATERIAL_HCOIN_ID) {
|
||||
// Remove credits
|
||||
getPlayer().addHCoin(-param.getCount() * multiplier);
|
||||
continue;
|
||||
} else if (param.getId() == GameConstants.ROGUE_TALENT_POINT_ITEM_ID) {
|
||||
// Remove credits
|
||||
getPlayer().addTalentPoints(-param.getCount() * multiplier);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove param items
|
||||
GameItem item = this.getItemByParam(param);
|
||||
if (item == null) continue;
|
||||
|
||||
GameItem result = this.deleteItem(item, param.getCount() * multiplier);
|
||||
if (result != null) {
|
||||
results.add(result);
|
||||
}
|
||||
}
|
||||
|
||||
// Send packet (update)
|
||||
|
||||
@@ -4,12 +4,14 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import emu.lunarcore.GameConstants;
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.GameDepot;
|
||||
import emu.lunarcore.data.common.ItemParam;
|
||||
import emu.lunarcore.data.excel.*;
|
||||
import emu.lunarcore.data.excel.ItemComposeExcel.FormulaType;
|
||||
import emu.lunarcore.game.avatar.GameAvatar;
|
||||
import emu.lunarcore.game.enums.ItemRarity;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.server.game.BaseGameService;
|
||||
import emu.lunarcore.server.game.GameServer;
|
||||
@@ -552,20 +554,26 @@ public class InventoryService extends BaseGameService {
|
||||
player.sendPacket(new PacketPlayerSyncScNotify(relic));
|
||||
}
|
||||
|
||||
public Int2IntMap sellItems(Player player, List<ItemParam> items) {
|
||||
public Int2IntMap sellItems(Player player, boolean toMaterials, List<ItemParam> items) {
|
||||
// Verify items
|
||||
var returnItems = new Int2IntOpenHashMap();
|
||||
|
||||
for (ItemParam param : items) {
|
||||
// Get item in inventory
|
||||
GameItem item = player.getInventory().getItemByParam(param);
|
||||
if (item == null || item.isLocked() || item.getCount() < param.getCount()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Add return items
|
||||
for (ItemParam ret : item.getExcel().getReturnItemIDList()) {
|
||||
// Add to return items
|
||||
returnItems.put(ret.getId(), returnItems.getOrDefault(ret.getId(), 0) + ret.getCount());
|
||||
if (item.getExcel().getRarity() == ItemRarity.SuperRare && !toMaterials) {
|
||||
// Relic remains
|
||||
returnItems.addTo(GameConstants.RELIC_REMAINS_ID, 10);
|
||||
} else {
|
||||
// Add basic return items
|
||||
for (ItemParam ret : item.getExcel().getReturnItemIDList()) {
|
||||
returnItems.addTo(ret.getId(), ret.getCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class HandlerSellItemCsReq extends PacketHandler {
|
||||
items.add(new ItemParam(cost));
|
||||
}
|
||||
|
||||
var returnItems = session.getServer().getInventoryService().sellItems(session.getPlayer(), items);
|
||||
var returnItems = session.getServer().getInventoryService().sellItems(session.getPlayer(), req.getToMaterial(), items);
|
||||
session.send(new PacketSellItemScRsp(returnItems));
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public class Utils {
|
||||
* Add 2 integers without overflowing
|
||||
*/
|
||||
public static int safeAdd(int a, int b) {
|
||||
return safeAdd(a, b, Integer.MAX_VALUE, Integer.MIN_VALUE);
|
||||
return safeAdd(a, b, Integer.MAX_VALUE, 0);
|
||||
}
|
||||
|
||||
public static int safeAdd(int a, int b, long max, long min) {
|
||||
|
||||
Reference in New Issue
Block a user