Add the ability for /give to set custom relic stats

This commit is contained in:
Melledy 2023-12-01 04:22:45 -08:00
parent 00d2eccf08
commit 36595c01db
4 changed files with 107 additions and 40 deletions

View File

@ -6,8 +6,11 @@ import emu.lunarcore.LunarCore;
import emu.lunarcore.data.GameData;
import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.game.inventory.ItemSubAffix;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.util.Utils;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import lombok.Getter;
@Getter
@ -21,6 +24,7 @@ public class CommandArgs {
private int rank = -1;
private int promotion = -1;
private int stage = -1;
private Int2IntMap map;
private static String EMPTY_STRING = "";
@ -55,6 +59,17 @@ public class CommandArgs {
it.remove();
} else if (arg.startsWith("s")) { // Stage or Superimposition
this.stage = Utils.parseSafeInt(arg.substring(1));
it.remove();
}
} else if (arg.contains(":")) {
String[] split = arg.split(":");
if (split.length >= 2) {
int key = Integer.parseInt(split[0]);
int value = Integer.parseInt(split[1]);
if (this.map == null) this.map = new Int2IntOpenHashMap();
this.map.put(key, value);
it.remove();
}
}
@ -165,19 +180,37 @@ public class CommandArgs {
hasChanged = true;
}
} else if (item.getExcel().isRelic()) {
// Sub stats
if (this.getMap() != null) {
item.resetSubAffixes();
hasChanged = true;
for (var entry : this.getMap().int2IntEntrySet()) {
if (entry.getIntValue() <= 0) continue;
var subAffix = GameData.getRelicSubAffixExcel(item.getExcel().getRelicExcel().getSubAffixGroup(), entry.getIntKey());
if (subAffix == null) continue;
item.getSubAffixes().add(new ItemSubAffix(subAffix, entry.getIntValue()));
}
}
// Main stat
if (this.getStage() > 0) {
var mainAffix = GameData.getRelicMainAffixExcel(item.getExcel().getRelicExcel().getMainAffixGroup(), this.getStage());
if (mainAffix != null) {
item.setMainAffix(mainAffix.getAffixID());
hasChanged = true;
}
}
// Try to set level
if (this.getLevel() > 0) {
int oldLevel = item.getLevel();
int upgrades = 0;
item.setLevel(Math.min(this.getLevel(), 15));
for (int i = oldLevel + 1; i <= item.getLevel(); i++) {
if (i % 3 == 0) {
upgrades++;
}
}
// Set relic level
item.setLevel(Math.min(this.getLevel(), 999));
// Apply sub stat upgrades to the relic
int upgrades = item.getMaxNormalSubAffixCount() - item.getCurrentSubAffixCount();
if (upgrades > 0) {
item.addSubAffixes(upgrades);
}

View File

@ -14,43 +14,56 @@ import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.util.Utils;
@Command(label = "give", aliases = {"g"}, permission = "player.give", requireTarget = true, desc = "/give [item id] x[amount]. Gives the targetted player an item.")
@Command(
label = "give",
aliases = {"g", "item"},
permission = "player.give",
requireTarget = true,
desc = "/give [item id] x(amount). Gives the targeted player an item."
)
public class GiveCommand implements CommandHandler {
@Override
public void execute(Player sender, CommandArgs args) {
int itemId = Utils.parseSafeInt(args.get(0));
int amount = Math.max(args.getAmount(), 1);
ItemExcel itemData = GameData.getItemExcelMap().get(itemId);
if (itemData == null) {
this.sendMessage(sender, "Error: Item data not found");
return;
}
// Setup items
List<GameItem> items = new LinkedList<>();
if (itemData.getItemMainType() == ItemMainType.AvatarCard) {
// Add avatar
GameAvatar avatar = new GameAvatar(itemData.getId());
args.setProperties(avatar);
args.getTarget().addAvatar(avatar);
} else if (itemData.isEquippable()) {
for (int i = 0; i < amount; i++) {
GameItem item = new GameItem(itemData);
args.setProperties(item);
items.add(item);
// Get amount to give
int amount = Math.max(args.getAmount(), 1);
// Parse items
for (String arg : args.getList()) {
// Parse item id
int itemId = Utils.parseSafeInt(arg);
ItemExcel itemData = GameData.getItemExcelMap().get(itemId);
if (itemData == null) {
this.sendMessage(sender, "Item \"" + arg + "\" does not exist!");
continue;
}
} else {
items.add(new GameItem(itemData, amount));
// Add item
if (itemData.getItemMainType() == ItemMainType.AvatarCard) {
// Add avatar
GameAvatar avatar = new GameAvatar(itemData.getId());
args.setProperties(avatar);
args.getTarget().addAvatar(avatar);
} else if (itemData.isEquippable()) {
for (int i = 0; i < amount; i++) {
GameItem item = new GameItem(itemData);
args.setProperties(item);
items.add(item);
}
} else {
items.add(new GameItem(itemData, amount));
}
// Send message
this.sendMessage(sender, "Giving " + args.getTarget().getName() + " " + amount + " of " + itemId);
}
// Add and send message to player
// Add to player inventory
args.getTarget().getInventory().addItems(items, true);
args.getTarget().sendMessage("Giving " + args.getTarget().getName() + " " + amount + " of " + itemId);
}
}

View File

@ -148,6 +148,14 @@ public class GameItem {
}
// Sub affixes
public void resetSubAffixes() {
if (this.subAffixes != null) {
this.subAffixes.clear();
} else {
this.subAffixes = new ArrayList<>();
}
}
public void addSubAffixes(int quantity) {
for (int i = 0; i < quantity; i++) {
@ -207,13 +215,23 @@ public class GameItem {
subAffix.incrementCount();
}
public int getTotalSubAffixCount() {
/**
* Returns the current count of sub affixes this item has
*/
public int getCurrentSubAffixCount() {
if (this.subAffixes == null) return 0;
return this.subAffixes
.stream()
.reduce(0, (subtotal, subAffix) -> subtotal + subAffix.getCount(), Integer::sum);
}
/**
* Returns the maximum amount of sub affixes this item should normally have
*/
public int getMaxNormalSubAffixCount() {
return (getExcel().getRarity().getVal() - 1) + (int) Math.floor(this.getLevel() / 3.0);
}
// Database
@ -285,5 +303,4 @@ public class GameItem {
.setPromotion(this.getPromotion())
.setUniqueId(this.getInternalUid());
}
}

View File

@ -19,8 +19,12 @@ public class ItemSubAffix {
}
public ItemSubAffix(RelicSubAffixExcel subAffix) {
this(subAffix, 1);
}
public ItemSubAffix(RelicSubAffixExcel subAffix, int count) {
this.id = subAffix.getAffixID();
this.count = 1;
this.count = count;
this.step = Utils.randomRange(0, subAffix.getStepNum());
}