mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-21 03:15:59 +01:00
Refactor out some EntrySets
This commit is contained in:
@@ -36,6 +36,7 @@ import emu.grasscutter.server.game.BaseGameSystem;
|
||||
import emu.grasscutter.server.game.GameServer;
|
||||
import emu.grasscutter.server.packet.send.*;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.Int2FloatArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
@@ -634,7 +635,7 @@ public class InventorySystem extends BaseGameSystem {
|
||||
Map<Integer, Float> oldPropMap = avatar.getFightProperties();
|
||||
if (oldLevel != level) {
|
||||
// Deep copy if level has changed
|
||||
oldPropMap = avatar.getFightProperties().int2FloatEntrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
oldPropMap = new Int2FloatArrayMap(avatar.getFightProperties());
|
||||
}
|
||||
|
||||
// Done
|
||||
@@ -696,7 +697,8 @@ public class InventorySystem extends BaseGameSystem {
|
||||
|
||||
public void destroyMaterial(Player player, List<MaterialInfo> list) {
|
||||
// Return materials
|
||||
Int2IntOpenHashMap returnMaterialMap = new Int2IntOpenHashMap();
|
||||
val returnMaterialMap = new Int2IntOpenHashMap();
|
||||
val inventory = player.getInventory();
|
||||
|
||||
for (MaterialInfo info : list) {
|
||||
// Sanity check
|
||||
@@ -704,28 +706,27 @@ public class InventorySystem extends BaseGameSystem {
|
||||
continue;
|
||||
}
|
||||
|
||||
GameItem item = player.getInventory().getItemByGuid(info.getGuid());
|
||||
GameItem item = inventory.getItemByGuid(info.getGuid());
|
||||
if (item == null || !item.isDestroyable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove
|
||||
int removeAmount = Math.min(info.getCount(), item.getCount());
|
||||
player.getInventory().removeItem(item, removeAmount);
|
||||
inventory.removeItem(item, removeAmount);
|
||||
|
||||
// Delete material return items
|
||||
if (item.getItemData().getDestroyReturnMaterial().length > 0) {
|
||||
for (int i = 0; i < item.getItemData().getDestroyReturnMaterial().length; i++) {
|
||||
returnMaterialMap.addTo(item.getItemData().getDestroyReturnMaterial()[i], item.getItemData().getDestroyReturnMaterialCount()[i]);
|
||||
val data = item.getItemData();
|
||||
if (data.getDestroyReturnMaterial().length > 0) {
|
||||
for (int i = 0; i < data.getDestroyReturnMaterial().length; i++) {
|
||||
returnMaterialMap.addTo(data.getDestroyReturnMaterial()[i], data.getDestroyReturnMaterialCount()[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Give back items
|
||||
if (returnMaterialMap.size() > 0) {
|
||||
for (Int2IntMap.Entry e : returnMaterialMap.int2IntEntrySet()) {
|
||||
player.getInventory().addItem(new GameItem(e.getIntKey(), e.getIntValue()));
|
||||
}
|
||||
returnMaterialMap.forEach((id, count) -> inventory.addItem(new GameItem(id, count)));
|
||||
}
|
||||
|
||||
// Packets
|
||||
|
||||
Reference in New Issue
Block a user