Implement item hints when receiving items

This commit is contained in:
Melledy
2023-10-23 23:39:21 -07:00
parent 2e579cffd5
commit 58eb400582
5 changed files with 340 additions and 10 deletions

View File

@@ -40,7 +40,7 @@ public class GiveAllCommand implements CommandHandler {
// Credits
items.add(new GameItem(2, 50_000_000));
// Add
args.getTarget().getInventory().addItems(items);
args.getTarget().getInventory().addItems(items, true);
// Send message
this.sendMessage(sender, "Giving " + args.getTarget().getName() + " " + items.size() + " items");
}

View File

@@ -33,17 +33,19 @@ public class GiveCommand implements CommandHandler {
return;
}
// Setup items
List<GameItem> items = new LinkedList<>();
if (itemData.isEquippable()) {
List<GameItem> items = new LinkedList<>();
for (int i = 0; i < amount; i++) {
items.add(new GameItem(itemData));
}
args.getTarget().getInventory().addItems(items);
} else {
GameItem item = new GameItem(itemData, amount);
args.getTarget().getInventory().addItem(item);
items.add(new GameItem(itemData, amount));
}
// Add and send message to player
args.getTarget().getInventory().addItems(items, true);
args.getTarget().sendMessage("Giving " + args.getTarget().getName() + " " + amount + " of " + itemId);
}

View File

@@ -17,6 +17,7 @@ import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.player.BasePlayerManager;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
import emu.lunarcore.server.packet.send.PacketScenePlaneEventScNotify;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -81,10 +82,8 @@ public class Inventory extends BasePlayerManager {
return null;
}
public boolean addItem(int itemId) {
return addItem(itemId, 1);
}
// Add/Remove items
public boolean addItem(int itemId, int count) {
ItemExcel itemExcel = GameData.getItemExcelMap().get(itemId);
@@ -113,6 +112,10 @@ public class Inventory extends BasePlayerManager {
}
public List<GameItem> addItems(Collection<GameItem> items) {
return addItems(items, false);
}
public List<GameItem> addItems(Collection<GameItem> items, boolean showHint) {
// Init results
List<GameItem> results = new ArrayList<GameItem>(items.size());
@@ -132,6 +135,9 @@ public class Inventory extends BasePlayerManager {
// Send packet (update)
if (results.size() > 0) {
getPlayer().sendPacket(new PacketPlayerSyncScNotify(results));
if (showHint) {
getPlayer().sendPacket(new PacketScenePlaneEventScNotify(items));
}
}
return results;

View File

@@ -0,0 +1,41 @@
package emu.lunarcore.server.packet.send;
import java.util.Collection;
import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.proto.ScenePlaneEventScNotifyOuterClass.ScenePlaneEventScNotify;
import emu.lunarcore.server.packet.BasePacket;
import emu.lunarcore.server.packet.CmdId;
public class PacketScenePlaneEventScNotify extends BasePacket {
public PacketScenePlaneEventScNotify(GameItem item) {
super(CmdId.ScenePlaneEventScNotify);
var data = ScenePlaneEventScNotify.newInstance();
if (item != null) {
data.getMutableGetItemList().addItemList(item.toProto());
} else {
data.getMutableGetItemList();
}
this.setData(data);
}
public PacketScenePlaneEventScNotify(Collection<GameItem> items) {
super(CmdId.ScenePlaneEventScNotify);
var data = ScenePlaneEventScNotify.newInstance();
if (items != null && items.size() > 0) {
for (var item : items) {
data.getMutableGetItemList().addItemList(item.toProto());
}
} else {
data.getMutableGetItemList();
}
this.setData(data);
}
}