mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 20:34:36 +01:00
Fix gift boxes not giving gifts when being bought from the shop
This commit is contained in:
40
src/main/java/emu/nebula/data/resources/DropPkgDef.java
Normal file
40
src/main/java/emu/nebula/data/resources/DropPkgDef.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package emu.nebula.data.resources;
|
||||
|
||||
import emu.nebula.data.BaseDef;
|
||||
import emu.nebula.data.ResourceType;
|
||||
import emu.nebula.util.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@ResourceType(name = "DropPkg.json")
|
||||
public class DropPkgDef extends BaseDef {
|
||||
private int PkgId;
|
||||
private int ItemId;
|
||||
|
||||
private static Int2ObjectMap<IntList> PACKAGES = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return PkgId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
var packageList = PACKAGES.computeIfAbsent(this.PkgId, i -> new IntArrayList());
|
||||
packageList.add(this.ItemId);
|
||||
}
|
||||
|
||||
public static int getRandomDrop(int packageId) {
|
||||
var packageList = PACKAGES.get(packageId);
|
||||
|
||||
if (packageList == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Utils.randomElement(packageList);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import dev.morphia.annotations.Id;
|
||||
import emu.nebula.GameConstants;
|
||||
import emu.nebula.Nebula;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.data.resources.DropPkgDef;
|
||||
import emu.nebula.data.resources.MallShopDef;
|
||||
import emu.nebula.data.resources.ResidentGoodsDef;
|
||||
import emu.nebula.database.GameDatabaseObject;
|
||||
@@ -284,8 +285,8 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
|
||||
change = new PlayerChangeInfo();
|
||||
}
|
||||
|
||||
// Sanity
|
||||
if (count == 0) {
|
||||
// Sanity check
|
||||
if (id <= 0 || count == 0) {
|
||||
return change;
|
||||
}
|
||||
|
||||
@@ -339,11 +340,32 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
|
||||
}
|
||||
}
|
||||
case Item -> {
|
||||
// Check if item is a random package
|
||||
if (data.getItemSubType() == ItemSubType.RandomPackage && data.getUseParams() != null) {
|
||||
// Cannot remove packages
|
||||
if (count <= 0) break;
|
||||
|
||||
// Add random packages
|
||||
for (var entry : data.getUseParams()) {
|
||||
int pkgId = entry.getIntKey();
|
||||
int pkgCount = entry.getIntValue() * count;
|
||||
|
||||
for (int i = 0; i < pkgCount; i++) {
|
||||
int pkgDropId = DropPkgDef.getRandomDrop(pkgId);
|
||||
this.addItem(pkgDropId, 1, change);
|
||||
}
|
||||
}
|
||||
|
||||
// End early
|
||||
break;
|
||||
}
|
||||
|
||||
// Get item
|
||||
var item = this.items.get(id);
|
||||
int diff = 0;
|
||||
|
||||
if (amount > 0) {
|
||||
// Add resource
|
||||
// Add item
|
||||
if (item == null) {
|
||||
item = new GameItem(this.getPlayer(), id, amount);
|
||||
this.items.put(item.getItemId(), item);
|
||||
|
||||
Reference in New Issue
Block a user