mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 06:31:26 +00:00
Add rotation to /spawn
(#2372)
This commit is contained in:
parent
92bd09eeed
commit
5f5e6c38b1
@ -54,4 +54,15 @@ public class CommandHelpers {
|
|||||||
});
|
});
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float parseRelative(String input, Float current) {
|
||||||
|
if (input.contains("~")) { // Relative
|
||||||
|
if (!input.equals("~")) { // Relative with offset
|
||||||
|
current += Float.parseFloat(input.replace("~", ""));
|
||||||
|
} // Else no offset, no modification
|
||||||
|
} else { // Absolute
|
||||||
|
current = Float.parseFloat(input);
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,9 @@ import lombok.Setter;
|
|||||||
label = "spawn",
|
label = "spawn",
|
||||||
aliases = {"drop", "s"},
|
aliases = {"drop", "s"},
|
||||||
usage = {
|
usage = {
|
||||||
"<itemId> [x<amount>] [blk<blockId>] [grp<groupId>] [cfg<configId>] <x> <y> <z>",
|
"<itemId> [x<amount>] [blk<blockId>] [grp<groupId>] [cfg<configId>] [<x> <y> <z>] [<rotX> <rotY> <rotZ>]",
|
||||||
"<gadgetId> [x<amount>] [state<state>] [maxhp<maxhp>] [hp<hp>(0 for infinite)] [atk<atk>] [def<def>] [blk<blockId>] [grp<groupId>] [cfg<configId>] <x> <y> <z>",
|
"<gadgetId> [x<amount>] [state<state>] [maxhp<maxhp>] [hp<hp>(0 for infinite)] [atk<atk>] [def<def>] [blk<blockId>] [grp<groupId>] [cfg<configId>] [<x> <y> <z>] [<rotX> <rotY> <rotZ>]",
|
||||||
"<monsterId> [x<amount>] [lv<level>] [ai<aiId>] [maxhp<maxhp>] [hp<hp>(0 for infinite)] [atk<atk>] [def<def>] [blk<blockId>] [grp<groupId>] [cfg<configId>] <x> <y> <z>"
|
"<monsterId> [x<amount>] [lv<level>] [ai<aiId>] [maxhp<maxhp>] [hp<hp>(0 for infinite)] [atk<atk>] [def<def>] [blk<blockId>] [grp<groupId>] [cfg<configId>] [<x> <y> <z>] [<rotX> <rotY> <rotZ>]"
|
||||||
},
|
},
|
||||||
permission = "server.spawn",
|
permission = "server.spawn",
|
||||||
permissionTargeted = "server.spawn.others")
|
permissionTargeted = "server.spawn.others")
|
||||||
@ -53,14 +53,25 @@ public final class SpawnCommand implements CommandHandler {
|
|||||||
sendUsageMessage(sender); // Reachable if someone does `/give lv90` or similar
|
sendUsageMessage(sender); // Reachable if someone does `/give lv90` or similar
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Position pos = targetPlayer.getPosition();
|
||||||
|
Position rot = targetPlayer.getRotation();
|
||||||
|
|
||||||
switch (args.size()) {
|
switch (args.size()) {
|
||||||
|
case 7:
|
||||||
|
try {
|
||||||
|
rot.setX(CommandHelpers.parseRelative(args.get(4), rot.getX()));
|
||||||
|
rot.setY(CommandHelpers.parseRelative(args.get(5), rot.getY()));
|
||||||
|
rot.setZ(CommandHelpers.parseRelative(args.get(6), rot.getZ()));
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
CommandHandler.sendMessage(
|
||||||
|
sender, translate(sender, "commands.execution.argument_error"));
|
||||||
|
} // Fallthrough
|
||||||
case 4:
|
case 4:
|
||||||
try {
|
try {
|
||||||
float x, y, z;
|
pos.setX(CommandHelpers.parseRelative(args.get(1), pos.getX()));
|
||||||
x = Float.parseFloat(args.get(1));
|
pos.setY(CommandHelpers.parseRelative(args.get(2), pos.getY()));
|
||||||
y = Float.parseFloat(args.get(2));
|
pos.setZ(CommandHelpers.parseRelative(args.get(3), pos.getZ()));
|
||||||
z = Float.parseFloat(args.get(3));
|
|
||||||
param.pos = new Position(x, y, z);
|
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
CommandHandler.sendMessage(
|
CommandHandler.sendMessage(
|
||||||
sender, translate(sender, "commands.execution.argument_error"));
|
sender, translate(sender, "commands.execution.argument_error"));
|
||||||
@ -77,6 +88,8 @@ public final class SpawnCommand implements CommandHandler {
|
|||||||
sendUsageMessage(sender);
|
sendUsageMessage(sender);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
param.pos = pos;
|
||||||
|
param.rot = rot;
|
||||||
|
|
||||||
MonsterData monsterData = GameData.getMonsterDataMap().get(param.id);
|
MonsterData monsterData = GameData.getMonsterDataMap().get(param.id);
|
||||||
GadgetData gadgetData = GameData.getGadgetDataMap().get(param.id);
|
GadgetData gadgetData = GameData.getGadgetDataMap().get(param.id);
|
||||||
@ -102,12 +115,8 @@ public final class SpawnCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double maxRadius = Math.sqrt(param.amount * 0.2 / Math.PI);
|
double maxRadius = Math.sqrt(param.amount * 0.2 / Math.PI);
|
||||||
if (param.pos == null) {
|
|
||||||
param.pos = targetPlayer.getPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < param.amount; i++) {
|
for (int i = 0; i < param.amount; i++) {
|
||||||
Position pos = GetRandomPositionInCircle(param.pos, maxRadius).addY(3);
|
pos = GetRandomPositionInCircle(param.pos, maxRadius).addY(3);
|
||||||
GameEntity entity = null;
|
GameEntity entity = null;
|
||||||
if (itemData != null) {
|
if (itemData != null) {
|
||||||
entity = createItem(itemData, param, pos);
|
entity = createItem(itemData, param, pos);
|
||||||
@ -128,12 +137,12 @@ public final class SpawnCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private EntityItem createItem(ItemData itemData, SpawnParameters param, Position pos) {
|
private EntityItem createItem(ItemData itemData, SpawnParameters param, Position pos) {
|
||||||
return new EntityItem(param.scene, null, itemData, pos, 1, true);
|
return new EntityItem(param.scene, null, itemData, pos, param.rot, 1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EntityMonster createMonster(
|
private EntityMonster createMonster(
|
||||||
MonsterData monsterData, SpawnParameters param, Position pos) {
|
MonsterData monsterData, SpawnParameters param, Position pos) {
|
||||||
var entity = new EntityMonster(param.scene, monsterData, pos, param.lvl);
|
var entity = new EntityMonster(param.scene, monsterData, pos, param.rot, param.lvl);
|
||||||
if (param.ai != -1) {
|
if (param.ai != -1) {
|
||||||
entity.setAiId(param.ai);
|
entity.setAiId(param.ai);
|
||||||
}
|
}
|
||||||
@ -144,16 +153,13 @@ public final class SpawnCommand implements CommandHandler {
|
|||||||
GadgetData gadgetData, SpawnParameters param, Position pos, Player targetPlayer) {
|
GadgetData gadgetData, SpawnParameters param, Position pos, Player targetPlayer) {
|
||||||
EntityBaseGadget entity;
|
EntityBaseGadget entity;
|
||||||
if (gadgetData.getType() == EntityType.Vehicle) {
|
if (gadgetData.getType() == EntityType.Vehicle) {
|
||||||
entity =
|
entity = new EntityVehicle(param.scene, targetPlayer, param.id, 0, pos, param.rot);
|
||||||
new EntityVehicle(
|
|
||||||
param.scene, targetPlayer, param.id, 0, pos, targetPlayer.getRotation());
|
|
||||||
} else {
|
} else {
|
||||||
entity = new EntityGadget(param.scene, param.id, pos, targetPlayer.getRotation());
|
entity = new EntityGadget(param.scene, param.id, pos, param.rot);
|
||||||
if (param.state != -1) {
|
if (param.state != -1) {
|
||||||
((EntityGadget) entity).setState(param.state);
|
((EntityGadget) entity).setState(param.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,6 +213,7 @@ public final class SpawnCommand implements CommandHandler {
|
|||||||
@Setter public int def = -1;
|
@Setter public int def = -1;
|
||||||
@Setter public int ai = -1;
|
@Setter public int ai = -1;
|
||||||
@Setter public Position pos = null;
|
@Setter public Position pos = null;
|
||||||
|
@Setter public Position rot = null;
|
||||||
public Scene scene = null;
|
public Scene scene = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,18 +16,6 @@ import java.util.List;
|
|||||||
permissionTargeted = "player.teleport.others")
|
permissionTargeted = "player.teleport.others")
|
||||||
public final class TeleportCommand implements CommandHandler {
|
public final class TeleportCommand implements CommandHandler {
|
||||||
|
|
||||||
private float parseRelative(
|
|
||||||
String input, Float current) { // TODO: Maybe this will be useful elsewhere later
|
|
||||||
if (input.contains("~")) { // Relative
|
|
||||||
if (!input.equals("~")) { // Relative with offset
|
|
||||||
current += Float.parseFloat(input.replace("~", ""));
|
|
||||||
} // Else no offset, no modification
|
|
||||||
} else { // Absolute
|
|
||||||
current = Float.parseFloat(input);
|
|
||||||
}
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||||
Position pos = targetPlayer.getPosition();
|
Position pos = targetPlayer.getPosition();
|
||||||
@ -46,9 +34,9 @@ public final class TeleportCommand implements CommandHandler {
|
|||||||
} // Fallthrough
|
} // Fallthrough
|
||||||
case 3:
|
case 3:
|
||||||
try {
|
try {
|
||||||
x = this.parseRelative(args.get(0), x);
|
x = CommandHelpers.parseRelative(args.get(0), x);
|
||||||
y = this.parseRelative(args.get(1), y);
|
y = CommandHelpers.parseRelative(args.get(1), y);
|
||||||
z = this.parseRelative(args.get(2), z);
|
z = CommandHelpers.parseRelative(args.get(2), z);
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
CommandHandler.sendMessage(
|
CommandHandler.sendMessage(
|
||||||
sender, translate(sender, "commands.teleport.invalid_position"));
|
sender, translate(sender, "commands.teleport.invalid_position"));
|
||||||
|
@ -241,7 +241,7 @@ public interface HandbookActions {
|
|||||||
|
|
||||||
// Create the entity.
|
// Create the entity.
|
||||||
for (var i = 1; i <= request.getAmount(); i++) {
|
for (var i = 1; i <= request.getAmount(); i++) {
|
||||||
var entity = new EntityMonster(scene, entityData, player.getPosition(), level);
|
var entity = new EntityMonster(scene, entityData, player.getPosition(), player.getRotation(), level);
|
||||||
scene.addEntity(entity);
|
scene.addEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ public class EntityHomeAnimal extends EntityMonster implements Rebornable {
|
|||||||
@Getter private final int rebirthCD;
|
@Getter private final int rebirthCD;
|
||||||
private final AtomicBoolean disappeared = new AtomicBoolean();
|
private final AtomicBoolean disappeared = new AtomicBoolean();
|
||||||
|
|
||||||
public EntityHomeAnimal(Scene scene, HomeWorldAnimalData data, Position pos) {
|
public EntityHomeAnimal(Scene scene, HomeWorldAnimalData data, Position pos, Position rot) {
|
||||||
super(scene, GameData.getMonsterDataMap().get(data.getMonsterID()), pos, 1);
|
super(scene, GameData.getMonsterDataMap().get(data.getMonsterID()), pos, rot, 1);
|
||||||
|
|
||||||
this.rebornPos = pos.clone();
|
this.rebornPos = pos.clone();
|
||||||
this.rebirth = data.getIsRebirth();
|
this.rebirth = data.getIsRebirth();
|
||||||
|
@ -54,14 +54,14 @@ public class EntityMonster extends GameEntity {
|
|||||||
@Getter private List<Player> playerOnBattle;
|
@Getter private List<Player> playerOnBattle;
|
||||||
@Nullable @Getter @Setter private SceneMonster metaMonster;
|
@Nullable @Getter @Setter private SceneMonster metaMonster;
|
||||||
|
|
||||||
public EntityMonster(Scene scene, MonsterData monsterData, Position pos, int level) {
|
public EntityMonster(Scene scene, MonsterData monsterData, Position pos, Position rot, int level) {
|
||||||
super(scene);
|
super(scene);
|
||||||
|
|
||||||
this.id = this.getWorld().getNextEntityId(EntityIdType.MONSTER);
|
this.id = this.getWorld().getNextEntityId(EntityIdType.MONSTER);
|
||||||
this.monsterData = monsterData;
|
this.monsterData = monsterData;
|
||||||
this.fightProperties = new Int2FloatOpenHashMap();
|
this.fightProperties = new Int2FloatOpenHashMap();
|
||||||
this.position = new Position(pos);
|
this.position = new Position(pos);
|
||||||
this.rotation = new Position();
|
this.rotation = new Position(rot);
|
||||||
this.bornPos = this.getPosition().clone();
|
this.bornPos = this.getPosition().clone();
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.playerOnBattle = new ArrayList<>();
|
this.playerOnBattle = new ArrayList<>();
|
||||||
|
@ -107,7 +107,8 @@ public class HomeSceneItem {
|
|||||||
return new EntityHomeAnimal(
|
return new EntityHomeAnimal(
|
||||||
scene,
|
scene,
|
||||||
GameData.getHomeWorldAnimalDataMap().get(homeAnimalItem.getFurnitureId()),
|
GameData.getHomeWorldAnimalDataMap().get(homeAnimalItem.getFurnitureId()),
|
||||||
homeAnimalItem.getSpawnPos());
|
homeAnimalItem.getSpawnPos(),
|
||||||
|
homeAnimalItem.getSpawnRot());
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ public final class BlossomActivity {
|
|||||||
|
|
||||||
var monsterData = GameData.getMonsterDataMap().get((int) entry);
|
var monsterData = GameData.getMonsterDataMap().get((int) entry);
|
||||||
var level = scene.getEntityLevel(1, worldLevelOverride);
|
var level = scene.getEntityLevel(1, worldLevelOverride);
|
||||||
var entity = new EntityMonster(scene, monsterData, pos.nearby2d(4f), level);
|
var entity = new EntityMonster(scene, monsterData, pos.nearby2d(4f), Position.ZERO, level);
|
||||||
scene.addEntity(entity);
|
scene.addEntity(entity);
|
||||||
newMonsters.add(entity);
|
newMonsters.add(entity);
|
||||||
}
|
}
|
||||||
|
@ -816,8 +816,7 @@ public class Scene {
|
|||||||
|
|
||||||
int level = this.getEntityLevel(entry.getLevel(), worldLevelOverride);
|
int level = this.getEntityLevel(entry.getLevel(), worldLevelOverride);
|
||||||
|
|
||||||
EntityMonster monster = new EntityMonster(this, data, entry.getPos(), level);
|
EntityMonster monster = new EntityMonster(this, data, entry.getPos(), entry.getRot(), level);
|
||||||
monster.getRotation().set(entry.getRot());
|
|
||||||
monster.setGroupId(entry.getGroup().getGroupId());
|
monster.setGroupId(entry.getGroup().getGroupId());
|
||||||
monster.setPoseId(entry.getPoseId());
|
monster.setPoseId(entry.getPoseId());
|
||||||
monster.setConfigId(entry.getConfigId());
|
monster.setConfigId(entry.getConfigId());
|
||||||
|
@ -1037,8 +1037,7 @@ public class SceneScriptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Spawn mob
|
// Spawn mob
|
||||||
EntityMonster entity = new EntityMonster(getScene(), data, monster.pos, level);
|
EntityMonster entity = new EntityMonster(getScene(), data, monster.pos, monster.rot, level);
|
||||||
entity.getRotation().set(monster.rot);
|
|
||||||
entity.setGroupId(groupId);
|
entity.setGroupId(groupId);
|
||||||
entity.setBlockId(blockId);
|
entity.setBlockId(blockId);
|
||||||
entity.setConfigId(monster.config_id);
|
entity.setConfigId(monster.config_id);
|
||||||
|
@ -61,7 +61,7 @@ public class HandlerQuestCreateEntityReq extends PacketHandler {
|
|||||||
val monsterId = entity.getMonsterId();
|
val monsterId = entity.getMonsterId();
|
||||||
val level = entity.getLevel();
|
val level = entity.getLevel();
|
||||||
MonsterData monsterData = GameData.getMonsterDataMap().get(monsterId);
|
MonsterData monsterData = GameData.getMonsterDataMap().get(monsterId);
|
||||||
gameEntity = new EntityMonster(scene, monsterData, pos, level);
|
gameEntity = new EntityMonster(scene, monsterData, pos, rot, level);
|
||||||
}
|
}
|
||||||
case NPC_ID -> {}
|
case NPC_ID -> {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user