mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-17 15:54:36 +01:00
Add the ability for /give to set custom relic stats
This commit is contained in:
@@ -6,8 +6,11 @@ import emu.lunarcore.LunarCore;
|
|||||||
import emu.lunarcore.data.GameData;
|
import emu.lunarcore.data.GameData;
|
||||||
import emu.lunarcore.game.avatar.GameAvatar;
|
import emu.lunarcore.game.avatar.GameAvatar;
|
||||||
import emu.lunarcore.game.inventory.GameItem;
|
import emu.lunarcore.game.inventory.GameItem;
|
||||||
|
import emu.lunarcore.game.inventory.ItemSubAffix;
|
||||||
import emu.lunarcore.game.player.Player;
|
import emu.lunarcore.game.player.Player;
|
||||||
import emu.lunarcore.util.Utils;
|
import emu.lunarcore.util.Utils;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -21,6 +24,7 @@ public class CommandArgs {
|
|||||||
private int rank = -1;
|
private int rank = -1;
|
||||||
private int promotion = -1;
|
private int promotion = -1;
|
||||||
private int stage = -1;
|
private int stage = -1;
|
||||||
|
private Int2IntMap map;
|
||||||
|
|
||||||
private static String EMPTY_STRING = "";
|
private static String EMPTY_STRING = "";
|
||||||
|
|
||||||
@@ -55,6 +59,17 @@ public class CommandArgs {
|
|||||||
it.remove();
|
it.remove();
|
||||||
} else if (arg.startsWith("s")) { // Stage or Superimposition
|
} else if (arg.startsWith("s")) { // Stage or Superimposition
|
||||||
this.stage = Utils.parseSafeInt(arg.substring(1));
|
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();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,19 +180,37 @@ public class CommandArgs {
|
|||||||
hasChanged = true;
|
hasChanged = true;
|
||||||
}
|
}
|
||||||
} else if (item.getExcel().isRelic()) {
|
} 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
|
// Try to set level
|
||||||
if (this.getLevel() > 0) {
|
if (this.getLevel() > 0) {
|
||||||
int oldLevel = item.getLevel();
|
// Set relic level
|
||||||
int upgrades = 0;
|
item.setLevel(Math.min(this.getLevel(), 999));
|
||||||
|
|
||||||
item.setLevel(Math.min(this.getLevel(), 15));
|
|
||||||
|
|
||||||
for (int i = oldLevel + 1; i <= item.getLevel(); i++) {
|
|
||||||
if (i % 3 == 0) {
|
|
||||||
upgrades++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Apply sub stat upgrades to the relic
|
||||||
|
int upgrades = item.getMaxNormalSubAffixCount() - item.getCurrentSubAffixCount();
|
||||||
if (upgrades > 0) {
|
if (upgrades > 0) {
|
||||||
item.addSubAffixes(upgrades);
|
item.addSubAffixes(upgrades);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,43 +14,56 @@ import emu.lunarcore.game.inventory.GameItem;
|
|||||||
import emu.lunarcore.game.player.Player;
|
import emu.lunarcore.game.player.Player;
|
||||||
import emu.lunarcore.util.Utils;
|
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 {
|
public class GiveCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player sender, CommandArgs args) {
|
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
|
// Setup items
|
||||||
List<GameItem> items = new LinkedList<>();
|
List<GameItem> items = new LinkedList<>();
|
||||||
|
|
||||||
if (itemData.getItemMainType() == ItemMainType.AvatarCard) {
|
// Get amount to give
|
||||||
// Add avatar
|
int amount = Math.max(args.getAmount(), 1);
|
||||||
GameAvatar avatar = new GameAvatar(itemData.getId());
|
|
||||||
args.setProperties(avatar);
|
// Parse items
|
||||||
args.getTarget().addAvatar(avatar);
|
for (String arg : args.getList()) {
|
||||||
} else if (itemData.isEquippable()) {
|
// Parse item id
|
||||||
for (int i = 0; i < amount; i++) {
|
int itemId = Utils.parseSafeInt(arg);
|
||||||
GameItem item = new GameItem(itemData);
|
|
||||||
args.setProperties(item);
|
ItemExcel itemData = GameData.getItemExcelMap().get(itemId);
|
||||||
|
if (itemData == null) {
|
||||||
items.add(item);
|
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().getInventory().addItems(items, true);
|
||||||
args.getTarget().sendMessage("Giving " + args.getTarget().getName() + " " + amount + " of " + itemId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,14 @@ public class GameItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sub affixes
|
// Sub affixes
|
||||||
|
|
||||||
|
public void resetSubAffixes() {
|
||||||
|
if (this.subAffixes != null) {
|
||||||
|
this.subAffixes.clear();
|
||||||
|
} else {
|
||||||
|
this.subAffixes = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void addSubAffixes(int quantity) {
|
public void addSubAffixes(int quantity) {
|
||||||
for (int i = 0; i < quantity; i++) {
|
for (int i = 0; i < quantity; i++) {
|
||||||
@@ -207,13 +215,23 @@ public class GameItem {
|
|||||||
subAffix.incrementCount();
|
subAffix.incrementCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotalSubAffixCount() {
|
/**
|
||||||
|
* Returns the current count of sub affixes this item has
|
||||||
|
*/
|
||||||
|
public int getCurrentSubAffixCount() {
|
||||||
if (this.subAffixes == null) return 0;
|
if (this.subAffixes == null) return 0;
|
||||||
|
|
||||||
return this.subAffixes
|
return this.subAffixes
|
||||||
.stream()
|
.stream()
|
||||||
.reduce(0, (subtotal, subAffix) -> subtotal + subAffix.getCount(), Integer::sum);
|
.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
|
// Database
|
||||||
|
|
||||||
@@ -285,5 +303,4 @@ public class GameItem {
|
|||||||
.setPromotion(this.getPromotion())
|
.setPromotion(this.getPromotion())
|
||||||
.setUniqueId(this.getInternalUid());
|
.setUniqueId(this.getInternalUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,12 @@ public class ItemSubAffix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemSubAffix(RelicSubAffixExcel subAffix) {
|
public ItemSubAffix(RelicSubAffixExcel subAffix) {
|
||||||
|
this(subAffix, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemSubAffix(RelicSubAffixExcel subAffix, int count) {
|
||||||
this.id = subAffix.getAffixID();
|
this.id = subAffix.getAffixID();
|
||||||
this.count = 1;
|
this.count = count;
|
||||||
this.step = Utils.randomRange(0, subAffix.getStepNum());
|
this.step = Utils.randomRange(0, subAffix.getStepNum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user