mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-16 23:34:50 +01:00
Improve commands that involve changing of avatar/item properties
This commit is contained in:
@@ -3,6 +3,9 @@ package emu.lunarcore.command;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import emu.lunarcore.LunarCore;
|
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.player.Player;
|
import emu.lunarcore.game.player.Player;
|
||||||
import emu.lunarcore.util.Utils;
|
import emu.lunarcore.util.Utils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -81,4 +84,91 @@ public class CommandArgs {
|
|||||||
}
|
}
|
||||||
return this.list.get(index);
|
return this.list.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Utility commands
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the properties of an avatar based on the arguments provided
|
||||||
|
* @param avatar The targeted avatar to change
|
||||||
|
* @return A boolean of whether or not any changes were made to the avatar
|
||||||
|
*/
|
||||||
|
public boolean setProperties(GameAvatar avatar) {
|
||||||
|
boolean hasChanged = false;
|
||||||
|
|
||||||
|
// Try to set level
|
||||||
|
if (this.getLevel() > 0) {
|
||||||
|
avatar.setLevel(this.getLevel());
|
||||||
|
hasChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to set level
|
||||||
|
if (this.getLevel() > 0) {
|
||||||
|
avatar.setLevel(Math.min(this.getLevel(), 80));
|
||||||
|
avatar.setPromotion(Utils.getMinPromotionForLevel(avatar.getLevel()));
|
||||||
|
hasChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to set promotion (ascension level)
|
||||||
|
if (this.getPromotion() >= 0) {
|
||||||
|
avatar.setPromotion(Math.min(this.getPromotion(), avatar.getExcel().getMaxPromotion()));
|
||||||
|
hasChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to set rank (eidolons)
|
||||||
|
if (this.getRank() >= 0) {
|
||||||
|
avatar.setRank(Math.min(this.getRank(), avatar.getExcel().getMaxRank()));
|
||||||
|
hasChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to set skill trees
|
||||||
|
if (this.getStage() > 0) {
|
||||||
|
for (int pointId : avatar.getExcel().getSkillTreeIds()) {
|
||||||
|
var skillTree = GameData.getAvatarSkillTreeExcel(pointId, 1);
|
||||||
|
if (skillTree == null) continue;
|
||||||
|
|
||||||
|
int minLevel = skillTree.isDefaultUnlock() ? 1 : 0;
|
||||||
|
int pointLevel = Math.max(Math.min(this.getStage(), skillTree.getMaxLevel()), minLevel);
|
||||||
|
|
||||||
|
avatar.getSkills().put(pointId, pointLevel);
|
||||||
|
}
|
||||||
|
hasChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the properties of an item based on the arguments provided
|
||||||
|
* @param item The targeted item to change
|
||||||
|
* @return A boolean of whether or not any changes were made to the item
|
||||||
|
*/
|
||||||
|
public boolean setProperties(GameItem item) {
|
||||||
|
boolean hasChanged = false;
|
||||||
|
|
||||||
|
if (item.getExcel().isEquipment()) {
|
||||||
|
// Try to set level
|
||||||
|
if (this.getLevel() > 0) {
|
||||||
|
item.setLevel(Math.min(this.getLevel(), 80));
|
||||||
|
item.setPromotion(Utils.getMinPromotionForLevel(item.getLevel()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to set promotion
|
||||||
|
if (this.getPromotion() >= 0) {
|
||||||
|
item.setPromotion(Math.min(this.getPromotion(), item.getExcel().getEquipmentExcel().getMaxPromotion()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to set rank (superimposition)
|
||||||
|
if (this.getRank() >= 0) {
|
||||||
|
item.setRank(Math.min(this.getRank(), item.getExcel().getEquipmentExcel().getMaxRank()));
|
||||||
|
}
|
||||||
|
} else if (item.getExcel().isRelic()) {
|
||||||
|
// Try to set level
|
||||||
|
if (this.getLevel() > 0) {
|
||||||
|
item.setLevel(Math.min(this.getLevel(), 15));
|
||||||
|
// TODO add substats
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasChanged;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ package emu.lunarcore.command.commands;
|
|||||||
import emu.lunarcore.command.Command;
|
import emu.lunarcore.command.Command;
|
||||||
import emu.lunarcore.command.CommandArgs;
|
import emu.lunarcore.command.CommandArgs;
|
||||||
import emu.lunarcore.command.CommandHandler;
|
import emu.lunarcore.command.CommandHandler;
|
||||||
import emu.lunarcore.data.GameData;
|
|
||||||
import emu.lunarcore.game.avatar.GameAvatar;
|
import emu.lunarcore.game.avatar.GameAvatar;
|
||||||
import emu.lunarcore.game.player.Player;
|
import emu.lunarcore.game.player.Player;
|
||||||
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
||||||
import emu.lunarcore.util.Utils;
|
|
||||||
|
|
||||||
@Command(label = "avatar", aliases = {"a"}, permission = "player.avatar", desc = "/avatar lv(level) p(ascension) r(eidolon) s(skill levels). Sets the current avatar's properties")
|
@Command(label = "avatar", aliases = {"a"}, permission = "player.avatar", desc = "/avatar lv(level) p(ascension) r(eidolon) s(skill levels). Sets the current avatar's properties")
|
||||||
public class AvatarCommand implements CommandHandler {
|
public class AvatarCommand implements CommandHandler {
|
||||||
@@ -27,49 +25,8 @@ public class AvatarCommand implements CommandHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasChanged = false;
|
// Change properties
|
||||||
|
if (args.setProperties(avatar)) {
|
||||||
// Try to set level
|
|
||||||
if (args.getLevel() > 0) {
|
|
||||||
avatar.setLevel(args.getLevel());
|
|
||||||
hasChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to set level
|
|
||||||
if (args.getLevel() > 0) {
|
|
||||||
avatar.setLevel(Math.min(args.getLevel(), 80));
|
|
||||||
avatar.setPromotion(Utils.getMinPromotionForLevel(avatar.getLevel()));
|
|
||||||
hasChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to set promotion (ascension level)
|
|
||||||
if (args.getPromotion() >= 0) {
|
|
||||||
avatar.setPromotion(Math.min(args.getPromotion(), avatar.getExcel().getMaxPromotion()));
|
|
||||||
hasChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to set rank (eidolons)
|
|
||||||
if (args.getRank() >= 0) {
|
|
||||||
avatar.setRank(Math.min(args.getRank(), avatar.getExcel().getMaxRank()));
|
|
||||||
hasChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to set skill trees
|
|
||||||
if (args.getStage() > 0) {
|
|
||||||
for (int pointId : avatar.getExcel().getSkillTreeIds()) {
|
|
||||||
var skillTree = GameData.getAvatarSkillTreeExcel(pointId, 1);
|
|
||||||
if (skillTree == null) continue;
|
|
||||||
|
|
||||||
int minLevel = skillTree.isDefaultUnlock() ? 1 : 0;
|
|
||||||
int pointLevel = Math.max(Math.min(args.getStage(), skillTree.getMaxLevel()), minLevel);
|
|
||||||
|
|
||||||
avatar.getSkills().put(pointId, pointLevel);
|
|
||||||
}
|
|
||||||
hasChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Done
|
|
||||||
if (hasChanged) {
|
|
||||||
// Save avatar
|
// Save avatar
|
||||||
avatar.save();
|
avatar.save();
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import emu.lunarcore.command.CommandArgs;
|
|||||||
import emu.lunarcore.command.CommandHandler;
|
import emu.lunarcore.command.CommandHandler;
|
||||||
import emu.lunarcore.data.GameData;
|
import emu.lunarcore.data.GameData;
|
||||||
import emu.lunarcore.data.excel.ItemExcel;
|
import emu.lunarcore.data.excel.ItemExcel;
|
||||||
|
import emu.lunarcore.game.avatar.GameAvatar;
|
||||||
import emu.lunarcore.game.enums.ItemMainType;
|
import emu.lunarcore.game.enums.ItemMainType;
|
||||||
import emu.lunarcore.game.enums.ItemRarity;
|
import emu.lunarcore.game.enums.ItemRarity;
|
||||||
import emu.lunarcore.game.enums.ItemSubType;
|
import emu.lunarcore.game.enums.ItemSubType;
|
||||||
@@ -25,6 +26,7 @@ public class GiveAllCommand implements CommandHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player target = args.getTarget();
|
||||||
String type = args.get(0).toLowerCase();
|
String type = args.get(0).toLowerCase();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -43,51 +45,72 @@ public class GiveAllCommand implements CommandHandler {
|
|||||||
items.add(new GameItem(2, 50_000_000));
|
items.add(new GameItem(2, 50_000_000));
|
||||||
|
|
||||||
// Add to target's inventory
|
// Add to target's inventory
|
||||||
args.getTarget().getInventory().addItems(items, true);
|
target.getInventory().addItems(items, true);
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
this.sendMessage(sender, "Giving " + args.getTarget().getName() + " " + items.size() + " items");
|
this.sendMessage(sender, "Giving " + target.getName() + " " + items.size() + " items");
|
||||||
}
|
}
|
||||||
case "lc", "lightcones" -> {
|
case "lc", "lightcones" -> {
|
||||||
// Get lightcones
|
// Get lightcones
|
||||||
List<GameItem> items = GameData.getItemExcelMap().values()
|
List<GameItem> items = GameData.getItemExcelMap().values()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(ItemExcel::isEquipment)
|
.filter(ItemExcel::isEquipment)
|
||||||
.map(excel -> new GameItem(excel, 1))
|
.map(excel -> {
|
||||||
|
var item = new GameItem(excel, 1);
|
||||||
|
args.setProperties(item);
|
||||||
|
return item;
|
||||||
|
})
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
// Add to target's inventory
|
// Add to target's inventory
|
||||||
args.getTarget().getInventory().addItems(items, true);
|
target.getInventory().addItems(items, true);
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
this.sendMessage(sender, "Giving " + args.getTarget().getName() + " " + items.size() + " light cones");
|
this.sendMessage(sender, "Giving " + target.getName() + " " + items.size() + " light cones");
|
||||||
}
|
}
|
||||||
case "r", "relics" -> {
|
case "r", "relics" -> {
|
||||||
// Get relics
|
// Get relics
|
||||||
List<GameItem> items = GameData.getItemExcelMap().values()
|
List<GameItem> items = GameData.getItemExcelMap().values()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(excel -> excel.isRelic() && excel.getRarity() == ItemRarity.SuperRare)
|
.filter(excel -> excel.isRelic() && excel.getRarity() == ItemRarity.SuperRare)
|
||||||
.map(excel -> new GameItem(excel, 1))
|
.map(excel -> {
|
||||||
|
var item = new GameItem(excel, 1);
|
||||||
|
args.setProperties(item);
|
||||||
|
return item;
|
||||||
|
})
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
// Add to target's inventory
|
// Add to target's inventory
|
||||||
args.getTarget().getInventory().addItems(items, true);
|
target.getInventory().addItems(items, true);
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
this.sendMessage(sender, "Giving " + args.getTarget().getName() + " " + items.size() + " relics");
|
this.sendMessage(sender, "Giving " + target.getName() + " " + items.size() + " relics");
|
||||||
}
|
}
|
||||||
case "a", "characters", "avatars" -> {
|
case "a", "characters", "avatars" -> {
|
||||||
// All avatars and their eidolons
|
// All avatars and their eidolons
|
||||||
for (ItemExcel excel : GameData.getItemExcelMap().values()) {
|
for (ItemExcel excel : GameData.getItemExcelMap().values()) {
|
||||||
if (excel.getItemMainType() == ItemMainType.AvatarCard) {
|
if (excel.getItemMainType() == ItemMainType.AvatarCard) {
|
||||||
args.getTarget().getInventory().addItem(excel, 1);
|
// Skip if target already has this avatar
|
||||||
|
if (target.getAvatars().hasAvatar(excel.getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add avatar
|
||||||
|
target.getInventory().addItem(excel, 1);
|
||||||
|
|
||||||
|
// Set avatar properties
|
||||||
|
GameAvatar avatar = target.getAvatarById(excel.getId());
|
||||||
|
if (avatar != null) {
|
||||||
|
args.setProperties(avatar);
|
||||||
|
}
|
||||||
} else if (excel.getItemSubType() == ItemSubType.Eidolon) {
|
} else if (excel.getItemSubType() == ItemSubType.Eidolon) {
|
||||||
args.getTarget().getInventory().addItem(excel, 6);
|
// Add eidolons
|
||||||
|
target.getInventory().addItem(excel, 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
this.sendMessage(sender, "Giving " + args.getTarget().getName() + " all avatars");
|
this.sendMessage(sender, "Giving " + target.getName() + " all avatars");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,22 +41,10 @@ public class GiveCommand implements CommandHandler {
|
|||||||
if (itemData.getItemMainType() == ItemMainType.AvatarCard) {
|
if (itemData.getItemMainType() == ItemMainType.AvatarCard) {
|
||||||
// Add avatar
|
// Add avatar
|
||||||
GameAvatar avatar = new GameAvatar(itemData.getId());
|
GameAvatar avatar = new GameAvatar(itemData.getId());
|
||||||
|
|
||||||
if (args.getTarget().addAvatar(avatar)) {
|
if (args.getTarget().addAvatar(avatar)) {
|
||||||
// Try to set level
|
// Change avatar properties
|
||||||
if (args.getLevel() > 0) {
|
args.setProperties(avatar);
|
||||||
avatar.setLevel(Math.min(args.getLevel(), 80));
|
|
||||||
avatar.setPromotion(Utils.getMinPromotionForLevel(avatar.getLevel()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to set promotion
|
|
||||||
if (args.getPromotion() >= 0) {
|
|
||||||
avatar.setPromotion(Math.min(args.getPromotion(), avatar.getExcel().getMaxPromotion()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to set rank
|
|
||||||
if (args.getRank() >= 0) {
|
|
||||||
avatar.setRank(Math.min(args.getRank(), avatar.getExcel().getMaxRank()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (itemData.isEquippable()) {
|
} else if (itemData.isEquippable()) {
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user