mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-15 06:45:04 +01:00
Implement /avatar command
This commit is contained in:
@@ -13,10 +13,11 @@ public class CommandArgs {
|
|||||||
private Player target;
|
private Player target;
|
||||||
|
|
||||||
private int targetUid;
|
private int targetUid;
|
||||||
private int level;
|
|
||||||
private int amount;
|
private int amount;
|
||||||
private int rank;
|
private int level = -1;
|
||||||
private int promotion;
|
private int rank = -1;
|
||||||
|
private int promotion = -1;
|
||||||
|
private int stage = -1;
|
||||||
|
|
||||||
private static String EMPTY_STRING = "";
|
private static String EMPTY_STRING = "";
|
||||||
|
|
||||||
@@ -46,6 +47,9 @@ public class CommandArgs {
|
|||||||
} else if (arg.startsWith("p")) {
|
} else if (arg.startsWith("p")) {
|
||||||
this.promotion = Utils.parseSafeInt(arg.substring(1));
|
this.promotion = Utils.parseSafeInt(arg.substring(1));
|
||||||
it.remove();
|
it.remove();
|
||||||
|
} else if (arg.startsWith("s")) {
|
||||||
|
this.stage = Utils.parseSafeInt(arg.substring(1));
|
||||||
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package emu.lunarcore.command.commands;
|
||||||
|
|
||||||
|
import emu.lunarcore.command.Command;
|
||||||
|
import emu.lunarcore.command.CommandArgs;
|
||||||
|
import emu.lunarcore.command.CommandHandler;
|
||||||
|
import emu.lunarcore.data.GameData;
|
||||||
|
import emu.lunarcore.game.avatar.GameAvatar;
|
||||||
|
import emu.lunarcore.game.player.Player;
|
||||||
|
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
||||||
|
|
||||||
|
@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 {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Player sender, CommandArgs args) {
|
||||||
|
// Check target
|
||||||
|
if (args.getTarget() == null) {
|
||||||
|
this.sendMessage(sender, "Error: Targeted player not found or offline");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get current leader avatar
|
||||||
|
GameAvatar avatar = args.getTarget().getCurrentLeaderAvatar();
|
||||||
|
if (avatar == null) {
|
||||||
|
// No leader!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasChanged = false;
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
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
|
||||||
|
avatar.save();
|
||||||
|
|
||||||
|
// Send packet
|
||||||
|
args.getTarget().sendPacket(new PacketPlayerSyncScNotify(avatar));
|
||||||
|
|
||||||
|
// Send message
|
||||||
|
sender.sendMessage("Set avatar properties successfully");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("No avatar properties to change");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@ import emu.lunarcore.data.ResourceType;
|
|||||||
import emu.lunarcore.game.battle.skills.MazeSkill;
|
import emu.lunarcore.game.battle.skills.MazeSkill;
|
||||||
import emu.lunarcore.game.enums.AvatarBaseType;
|
import emu.lunarcore.game.enums.AvatarBaseType;
|
||||||
import emu.lunarcore.game.enums.DamageType;
|
import emu.lunarcore.game.enums.DamageType;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -35,6 +37,7 @@ public class AvatarExcel extends GameResource {
|
|||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private transient AvatarPromotionExcel[] promotionData;
|
private transient AvatarPromotionExcel[] promotionData;
|
||||||
private transient List<AvatarSkillTreeExcel> defaultSkillTrees;
|
private transient List<AvatarSkillTreeExcel> defaultSkillTrees;
|
||||||
|
private transient IntSet skillTreeIds;
|
||||||
private transient String nameKey;
|
private transient String nameKey;
|
||||||
private transient int maxSp;
|
private transient int maxSp;
|
||||||
|
|
||||||
@@ -45,6 +48,7 @@ public class AvatarExcel extends GameResource {
|
|||||||
|
|
||||||
public AvatarExcel() {
|
public AvatarExcel() {
|
||||||
this.defaultSkillTrees = new ArrayList<>();
|
this.defaultSkillTrees = new ArrayList<>();
|
||||||
|
this.skillTreeIds = new IntOpenHashSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import emu.lunarcore.data.ResourceType.LoadPriority;
|
|||||||
import emu.lunarcore.data.common.ItemParam;
|
import emu.lunarcore.data.common.ItemParam;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.bytebuddy.asm.Advice.This;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ResourceType(name = {"AvatarSkillTreeConfig.json"}, loadPriority = LoadPriority.LOW)
|
@ResourceType(name = {"AvatarSkillTreeConfig.json"}, loadPriority = LoadPriority.LOW)
|
||||||
@@ -53,11 +54,15 @@ public class AvatarSkillTreeExcel extends GameResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load to excel
|
// Load to excel
|
||||||
AvatarExcel excel = GameData.getAvatarExcelMap().get(AvatarID);
|
AvatarExcel excel = GameData.getAvatarExcelMap().get(this.AvatarID);
|
||||||
if (excel == null) return;
|
if (excel == null) return;
|
||||||
|
|
||||||
|
// Add to default avatar skills
|
||||||
if (this.isDefaultUnlock()) {
|
if (this.isDefaultUnlock()) {
|
||||||
excel.getDefaultSkillTrees().add(this);
|
excel.getDefaultSkillTrees().add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add point id to avatar excel
|
||||||
|
excel.getSkillTreeIds().add(this.getPointID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public class BattleService extends BaseGameService {
|
|||||||
|
|
||||||
// Add buffs to battle
|
// Add buffs to battle
|
||||||
if (isPlayerCaster) {
|
if (isPlayerCaster) {
|
||||||
GameAvatar avatar = player.getLineupManager().getCurrentLeaderAvatar();
|
GameAvatar avatar = player.getCurrentLeaderAvatar();
|
||||||
if (avatar != null) {
|
if (avatar != null) {
|
||||||
// Maze skill attack event
|
// Maze skill attack event
|
||||||
if (castedSkill) { // Dont need to null check maze skill since we already did it in HandlerSceneCastSkillCsReq
|
if (castedSkill) { // Dont need to null check maze skill since we already did it in HandlerSceneCastSkillCsReq
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class LineupManager {
|
|||||||
private transient Player player;
|
private transient Player player;
|
||||||
|
|
||||||
private PlayerLineup[] lineups;
|
private PlayerLineup[] lineups;
|
||||||
private int currentIndex;
|
private int currentIndex; // Team index
|
||||||
private int currentLeader;
|
private int currentLeader;
|
||||||
private int mp;
|
private int mp;
|
||||||
|
|
||||||
|
|||||||
@@ -243,6 +243,15 @@ public class Player {
|
|||||||
public PlayerLineup getCurrentLineup() {
|
public PlayerLineup getCurrentLineup() {
|
||||||
return this.getLineupManager().getCurrentLineup();
|
return this.getLineupManager().getCurrentLineup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameAvatar getCurrentLeaderAvatar() {
|
||||||
|
try {
|
||||||
|
int avatarId = getCurrentLineup().getAvatars().get(this.getLineupManager().getCurrentLeader());
|
||||||
|
return this.getAvatarById(avatarId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initUid() {
|
private void initUid() {
|
||||||
if (this.uid > 0) return;
|
if (this.uid > 0) return;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class HandlerSceneCastSkillCsReq extends PacketHandler {
|
|||||||
session.getPlayer().getCurrentLineup().removeMp(1);
|
session.getPlayer().getCurrentLineup().removeMp(1);
|
||||||
session.send(new PacketSceneCastSkillMpUpdateScNotify(req.getAttackedGroupId(), session.getPlayer().getLineupManager().getMp()));
|
session.send(new PacketSceneCastSkillMpUpdateScNotify(req.getAttackedGroupId(), session.getPlayer().getLineupManager().getMp()));
|
||||||
// Cast skill effects
|
// Cast skill effects
|
||||||
GameAvatar caster = session.getPlayer().getLineupManager().getCurrentLeaderAvatar();
|
GameAvatar caster = session.getPlayer().getCurrentLeaderAvatar();
|
||||||
if (caster != null && caster.getExcel().getMazeSkill() != null) {
|
if (caster != null && caster.getExcel().getMazeSkill() != null) {
|
||||||
MazeSkill skill = caster.getExcel().getMazeSkill();
|
MazeSkill skill = caster.getExcel().getMazeSkill();
|
||||||
skill.onCast(caster, req.getTargetMotion());
|
skill.onCast(caster, req.getTargetMotion());
|
||||||
|
|||||||
Reference in New Issue
Block a user