mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-20 01:29:54 +02:00
Implement gacha banners (not newbie)
This commit is contained in:
@@ -207,7 +207,7 @@ public class Inventory extends PlayerManager {
|
||||
}
|
||||
|
||||
// Add items
|
||||
for (var param : params.getEntrySet()) {
|
||||
for (var param : params.entries()) {
|
||||
this.addItem(param.getIntKey(), param.getIntValue(), changes);
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public class Inventory extends PlayerManager {
|
||||
}
|
||||
|
||||
// Remove items
|
||||
for (var param : params.getEntrySet()) {
|
||||
for (var param : params.entries()) {
|
||||
this.removeItem(param.getIntKey(), param.getIntValue(), changes);
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ public class Inventory extends PlayerManager {
|
||||
public synchronized boolean verifyItems(ItemParamMap params) {
|
||||
boolean hasItems = true;
|
||||
|
||||
for (var param : params.getEntrySet()) {
|
||||
for (var param : params.entries()) {
|
||||
hasItems = this.verifyItem(param.getIntKey(), param.getIntValue());
|
||||
|
||||
if (!hasItems) {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package emu.nebula.game.inventory;
|
||||
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.proto.Public.AcqInfo;
|
||||
import emu.nebula.proto.Public.Acquire;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class ItemAcquireMap {
|
||||
private final Int2ObjectMap<ItemAcquireParam> items;
|
||||
|
||||
public ItemAcquireMap(Player player, IntList list) {
|
||||
this.items = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
for (int id : list) {
|
||||
// Get item data
|
||||
var data = GameData.getItemDataTable().get(id);
|
||||
if (data == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add to acquire map
|
||||
if (!this.getItems().containsKey(id)) {
|
||||
// Get starting count
|
||||
int count = 0;
|
||||
|
||||
// Check item type
|
||||
if (data.getItemType() == ItemType.Char) {
|
||||
var character = player.getCharacters().getCharacterById(id);
|
||||
|
||||
if (character != null) {
|
||||
count = 1;
|
||||
}
|
||||
} else if (data.getItemType() == ItemType.Disc) {
|
||||
var disc = player.getCharacters().getDiscById(id);
|
||||
|
||||
if (disc != null) {
|
||||
count = 1;
|
||||
count += disc.getStar();
|
||||
count += player.getInventory().getItemCount(disc.getData().getTransformItemId());
|
||||
}
|
||||
}
|
||||
|
||||
var acquireInfo = new ItemAcquireParam(data.getItemType(), count);
|
||||
acquireInfo.add();
|
||||
|
||||
this.getItems().put(id, acquireInfo);
|
||||
} else {
|
||||
this.getItems().get(id).add();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Proto
|
||||
|
||||
public Acquire toProto() {
|
||||
var proto = Acquire.newInstance();
|
||||
|
||||
for (var entry : this.items.int2ObjectEntrySet()) {
|
||||
var a = AcqInfo.newInstance()
|
||||
.setTid(entry.getIntKey())
|
||||
.setBegin(entry.getValue().getBegin())
|
||||
.setCount(entry.getValue().getCount());
|
||||
|
||||
proto.addList(a);
|
||||
}
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class ItemAcquireParam {
|
||||
private ItemType type;
|
||||
private int begin;
|
||||
private int count;
|
||||
|
||||
public ItemAcquireParam(ItemType type, int i) {
|
||||
this.type = type;
|
||||
this.begin = i;
|
||||
}
|
||||
|
||||
public void add() {
|
||||
this.count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,13 @@ import java.util.stream.Stream;
|
||||
import emu.nebula.proto.Public.Item;
|
||||
import emu.nebula.proto.Public.ItemInfo;
|
||||
import emu.nebula.proto.Public.ItemTpl;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntLinkedOpenHashMap;
|
||||
|
||||
import us.hebi.quickbuf.RepeatedMessage;
|
||||
|
||||
public class ItemParamMap extends Int2IntOpenHashMap {
|
||||
public class ItemParamMap extends Int2IntLinkedOpenHashMap {
|
||||
private static final long serialVersionUID = -4186524272780523459L;
|
||||
|
||||
public FastEntrySet entries() {
|
||||
return this.int2IntEntrySet();
|
||||
}
|
||||
|
||||
@Override @Deprecated
|
||||
public int addTo(int itemId, int count) {
|
||||
@@ -55,9 +53,7 @@ public class ItemParamMap extends Int2IntOpenHashMap {
|
||||
return params;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
public FastEntrySet getEntrySet() {
|
||||
public FastEntrySet entries() {
|
||||
return this.int2IntEntrySet();
|
||||
}
|
||||
|
||||
@@ -74,13 +70,13 @@ public class ItemParamMap extends Int2IntOpenHashMap {
|
||||
}
|
||||
|
||||
public Stream<ItemTpl> toItemTemplateStream() {
|
||||
return getEntrySet()
|
||||
return entries()
|
||||
.stream()
|
||||
.map(e -> ItemTpl.newInstance().setTid(e.getIntKey()).setQty(e.getIntValue()));
|
||||
}
|
||||
|
||||
public Stream<Item> toItemProtoStream() {
|
||||
return getEntrySet()
|
||||
return entries()
|
||||
.stream()
|
||||
.map(e -> Item.newInstance().setTid(e.getIntKey()).setQty(e.getIntValue()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user