Commit 16f77ee5 authored by dogdie233's avatar dogdie233 Committed by Melledy
Browse files

Add EnterDungeonCmd, fix error when enter dungeon by changescene, import spawn cmd

parent fe2d2e8e
package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
import java.util.List;
@Command(label = "enterdungeon", usage = "enterdungeon <dungeon id>",
description = "Enter a dungeon", aliases = {"dungeon"}, permission = "player.enterdungeon")
public final class EnterDungeonCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: enterdungeon <dungeon id>");
return;
}
try {
int dungeonId = Integer.parseInt(args.get(0));
if (dungeonId == sender.getSceneId()) {
CommandHandler.sendMessage(sender, "You are already in that dungeon");
return;
}
boolean result = sender.getServer().getDungeonManager().enterDungeon(sender.getSession().getPlayer(), 0, dungeonId);
CommandHandler.sendMessage(sender, "Changed to dungeon " + dungeonId);
if (!result) {
CommandHandler.sendMessage(sender, "Dungeon does not exist");
}
} catch (Exception e) {
CommandHandler.sendMessage(sender, "Usage: enterdungeon <dungeon id>");
}
}
}
...@@ -3,14 +3,22 @@ package emu.grasscutter.command.commands; ...@@ -3,14 +3,22 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.GadgetData;
import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.data.def.MonsterData; import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.*;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.EntityType;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import javax.swing.text.html.parser.Entity;
import java.util.List; import java.util.List;
import java.util.Random;
@Command(label = "spawn", usage = "spawn <entityId|entityName> [level] [amount]", @Command(label = "spawn", usage = "spawn <entityId> [amount] [level(monster only)]",
description = "Spawns an entity near you", permission = "server.spawn") description = "Spawns an entity near you", permission = "server.spawn")
public final class SpawnCommand implements CommandHandler { public final class SpawnCommand implements CommandHandler {
...@@ -22,30 +30,65 @@ public final class SpawnCommand implements CommandHandler { ...@@ -22,30 +30,65 @@ public final class SpawnCommand implements CommandHandler {
} }
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: spawn <entityId|entityName> [amount]"); CommandHandler.sendMessage(sender, "Usage: spawn <entityId> [amount] [level(monster only)]");
return; return;
} }
try { try {
int entity = Integer.parseInt(args.get(0)); int id = Integer.parseInt(args.get(0));
int level = args.size() > 1 ? Integer.parseInt(args.get(1)) : 1; int amount = args.size() > 1 ? Integer.parseInt(args.get(1)) : 1;
int amount = args.size() > 2 ? Integer.parseInt(args.get(2)) : 1; int level = args.size() > 2 ? Integer.parseInt(args.get(2)) : 1;
MonsterData entityData = GameData.getMonsterDataMap().get(entity); MonsterData monsterData = GameData.getMonsterDataMap().get(id);
if (entityData == null) { GadgetData gadgetData = GameData.getGadgetDataMap().get(id);
ItemData itemData = GameData.getItemDataMap().get(id);
if (monsterData == null && gadgetData == null && itemData == null) {
CommandHandler.sendMessage(sender, "Invalid entity id."); CommandHandler.sendMessage(sender, "Invalid entity id.");
return; return;
} }
float range = (5f + (.1f * amount)); double maxRadius = Math.sqrt(amount * 0.2 / Math.PI);
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
Position pos = sender.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); Position pos = GetRandomPositionInCircle(sender.getPos(), maxRadius).addY(3);
EntityMonster monster = new EntityMonster(sender.getScene(), entityData, pos, level); GameEntity entity = null;
sender.getScene().addEntity(monster); if (itemData != null) {
entity = new EntityItem(sender.getScene(), null, itemData, pos, 1, true);
} }
CommandHandler.sendMessage(sender, String.format("Spawned %s of %s.", amount, entity)); if (gadgetData != null) {
entity = new EntityVehicle(sender.getScene(), sender.getSession().getPlayer(), gadgetData.getId(), 0, pos, sender.getRotation());
int gadgetId = gadgetData.getId();
switch (gadgetId) {
// TODO: Not hardcode this. Waverider (skiff)
case 45001001, 45001002 -> {
entity.addFightProperty(FightProperty.FIGHT_PROP_BASE_HP, 10000);
entity.addFightProperty(FightProperty.FIGHT_PROP_BASE_ATTACK, 100);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, 100);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 10000);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, 0);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_SPEED, 0);
entity.addFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, 0);
entity.addFightProperty(FightProperty.FIGHT_PROP_MAX_HP, 10000);
}
default -> {}
}
}
if (monsterData != null) {
entity = new EntityMonster(sender.getScene(), monsterData, pos, level);
}
sender.getScene().addEntity(entity);
}
CommandHandler.sendMessage(sender, String.format("Spawned %s of %s.", amount, id));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid item or player ID."); CommandHandler.sendMessage(sender, "Invalid entity ID.");
} }
} }
private Position GetRandomPositionInCircle(Position origin, double radius){
Position target = origin.clone();
double angle = Math.random() * 360;
double r = Math.sqrt(Math.random() * radius * radius);
target.addX((float) (r * Math.cos(angle))).addZ((float) (r * Math.sin(angle)));
return target;
}
} }
...@@ -37,11 +37,11 @@ public class DungeonManager { ...@@ -37,11 +37,11 @@ public class DungeonManager {
player.sendPacket(new PacketDungeonEntryInfoRsp(player, entry.getPointData())); player.sendPacket(new PacketDungeonEntryInfoRsp(player, entry.getPointData()));
} }
public void enterDungeon(Player player, int pointId, int dungeonId) { public boolean enterDungeon(Player player, int pointId, int dungeonId) {
DungeonData data = GameData.getDungeonDataMap().get(dungeonId); DungeonData data = GameData.getDungeonDataMap().get(dungeonId);
if (data == null) { if (data == null) {
return; return false;
} }
Grasscutter.getLogger().info(player.getNickname() + " is trying to enter dungeon " + dungeonId); Grasscutter.getLogger().info(player.getNickname() + " is trying to enter dungeon " + dungeonId);
...@@ -53,6 +53,7 @@ public class DungeonManager { ...@@ -53,6 +53,7 @@ public class DungeonManager {
player.getScene().setPrevScenePoint(pointId); player.getScene().setPrevScenePoint(pointId);
player.sendPacket(new PacketPlayerEnterDungeonRsp(pointId, dungeonId)); player.sendPacket(new PacketPlayerEnterDungeonRsp(pointId, dungeonId));
return true;
} }
public void exitDungeon(Player player) { public void exitDungeon(Player player) {
......
...@@ -175,7 +175,7 @@ public class Scene { ...@@ -175,7 +175,7 @@ public class Scene {
} }
public void setDungeonData(DungeonData dungeonData) { public void setDungeonData(DungeonData dungeonData) {
if (this.dungeonData != null || this.getSceneType() != SceneType.SCENE_DUNGEON || dungeonData.getSceneId() != this.getId()) { if (dungeonData == null || this.dungeonData != null || this.getSceneType() != SceneType.SCENE_DUNGEON || dungeonData.getSceneId() != this.getId()) {
return; return;
} }
this.dungeonData = dungeonData; this.dungeonData = dungeonData;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment