mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-06-26 18:14:50 +08:00
Compare commits
No commits in common. "2e24d77bc28aa4b10e7cff320ff4919136728456" and "7c02e6c91243846eedaf858fa336b584c9bb57f1" have entirely different histories.
2e24d77bc2
...
7c02e6c912
@ -75,7 +75,6 @@ public class GameData {
|
|||||||
private static final Int2ObjectMap<ShopGoodsData> shopGoodsDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<ShopGoodsData> shopGoodsDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
private static final Int2ObjectMap<CombineData> combineDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<CombineData> combineDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
private static final Int2ObjectMap<RewardPreviewData> rewardPreviewDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<RewardPreviewData> rewardPreviewDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
private static final Int2ObjectMap<GatherData> gatherDataMap = new Int2ObjectOpenHashMap<>();
|
|
||||||
private static final Int2ObjectMap<TowerFloorData> towerFloorDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<TowerFloorData> towerFloorDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
private static final Int2ObjectMap<TowerLevelData> towerLevelDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<TowerLevelData> towerLevelDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
private static final Int2ObjectMap<TowerScheduleData> towerScheduleDataMap = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<TowerScheduleData> towerScheduleDataMap = new Int2ObjectOpenHashMap<>();
|
||||||
@ -348,8 +347,4 @@ public class GameData {
|
|||||||
public static Int2ObjectMap<QuestData> getQuestDataMap() {
|
public static Int2ObjectMap<QuestData> getQuestDataMap() {
|
||||||
return questDataMap;
|
return questDataMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Int2ObjectMap<GatherData> getGatherDataMap() {
|
|
||||||
return gatherDataMap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
package emu.grasscutter.data.def;
|
|
||||||
|
|
||||||
import emu.grasscutter.data.GameResource;
|
|
||||||
import emu.grasscutter.data.ResourceType;
|
|
||||||
|
|
||||||
@ResourceType(name = "GatherExcelConfigData.json")
|
|
||||||
public class GatherData extends GameResource {
|
|
||||||
private int PointType;
|
|
||||||
private int Id;
|
|
||||||
private int GadgetId;
|
|
||||||
private int ItemId;
|
|
||||||
private int Cd; // Probably hours
|
|
||||||
private boolean IsForbidGuest;
|
|
||||||
private boolean InitDisableInteract;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getId() {
|
|
||||||
return this.PointType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getGatherId() {
|
|
||||||
return Id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getGadgetId() {
|
|
||||||
return GadgetId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getItemId() {
|
|
||||||
return ItemId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCd() {
|
|
||||||
return Cd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isForbidGuest() {
|
|
||||||
return IsForbidGuest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean initDisableInteract() {
|
|
||||||
return InitDisableInteract;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoad() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,6 +12,7 @@ public class SceneData extends GameResource {
|
|||||||
private SceneType Type;
|
private SceneType Type;
|
||||||
private String ScriptData;
|
private String ScriptData;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return this.Id;
|
return this.Id;
|
||||||
|
@ -3,15 +3,9 @@ package emu.grasscutter.game.entity;
|
|||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.data.GameData;
|
import emu.grasscutter.data.GameData;
|
||||||
import emu.grasscutter.data.def.GadgetData;
|
import emu.grasscutter.data.def.GadgetData;
|
||||||
import emu.grasscutter.game.entity.gadget.GadgetChest;
|
|
||||||
import emu.grasscutter.game.entity.gadget.GadgetContent;
|
|
||||||
import emu.grasscutter.game.entity.gadget.GadgetGatherPoint;
|
|
||||||
import emu.grasscutter.game.entity.gadget.GadgetRewardStatue;
|
|
||||||
import emu.grasscutter.game.entity.gadget.GadgetWorktop;
|
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.game.props.EntityIdType;
|
import emu.grasscutter.game.props.EntityIdType;
|
||||||
import emu.grasscutter.game.props.EntityType;
|
import emu.grasscutter.game.props.EntityType;
|
||||||
import emu.grasscutter.game.props.FightProperty;
|
|
||||||
import emu.grasscutter.game.props.PlayerProperty;
|
import emu.grasscutter.game.props.PlayerProperty;
|
||||||
import emu.grasscutter.game.world.Scene;
|
import emu.grasscutter.game.world.Scene;
|
||||||
import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo;
|
import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo;
|
||||||
@ -28,7 +22,6 @@ import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
|
|||||||
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
|
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
|
||||||
import emu.grasscutter.net.proto.VectorOuterClass.Vector;
|
import emu.grasscutter.net.proto.VectorOuterClass.Vector;
|
||||||
import emu.grasscutter.net.proto.WorktopInfoOuterClass.WorktopInfo;
|
import emu.grasscutter.net.proto.WorktopInfoOuterClass.WorktopInfo;
|
||||||
import emu.grasscutter.server.packet.send.PacketGadgetStateNotify;
|
|
||||||
import emu.grasscutter.utils.Position;
|
import emu.grasscutter.utils.Position;
|
||||||
import emu.grasscutter.utils.ProtoHelper;
|
import emu.grasscutter.utils.ProtoHelper;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
|
||||||
@ -47,8 +40,7 @@ public class EntityGadget extends EntityBaseGadget {
|
|||||||
private int gadgetId;
|
private int gadgetId;
|
||||||
|
|
||||||
private int state;
|
private int state;
|
||||||
private int pointType;
|
private IntSet worktopOptions;
|
||||||
private GadgetContent content;
|
|
||||||
|
|
||||||
public EntityGadget(Scene scene, int gadgetId, Position pos) {
|
public EntityGadget(Scene scene, int gadgetId, Position pos) {
|
||||||
super(scene);
|
super(scene);
|
||||||
@ -59,22 +51,19 @@ public class EntityGadget extends EntityBaseGadget {
|
|||||||
this.rot = new Position();
|
this.rot = new Position();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityGadget(Scene scene, int gadgetId, Position pos, GadgetContent content) {
|
|
||||||
this(scene, gadgetId, pos);
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GadgetData getGadgetData() {
|
public GadgetData getGadgetData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Position getPosition() {
|
public Position getPosition() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return this.pos;
|
return this.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Position getRotation() {
|
public Position getRotation() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return this.rot;
|
return this.rot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,48 +83,27 @@ public class EntityGadget extends EntityBaseGadget {
|
|||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateState(int state){
|
public IntSet getWorktopOptions() {
|
||||||
this.setState(state);
|
return worktopOptions;
|
||||||
this.getScene().broadcastPacket(new PacketGadgetStateNotify(this, state));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPointType() {
|
public void addWorktopOptions(int[] options) {
|
||||||
return pointType;
|
if (this.worktopOptions == null) {
|
||||||
|
this.worktopOptions = new IntOpenHashSet();
|
||||||
|
}
|
||||||
|
Arrays.stream(options).forEach(this.worktopOptions::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPointType(int pointType) {
|
public void removeWorktopOption(int option) {
|
||||||
this.pointType = pointType;
|
if (this.worktopOptions == null) {
|
||||||
}
|
|
||||||
|
|
||||||
public GadgetContent getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated // Dont use!
|
|
||||||
public void setContent(GadgetContent content) {
|
|
||||||
this.content = this.content == null ? content : this.content;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO refactor
|
|
||||||
public void buildContent() {
|
|
||||||
if (getContent() != null || getGadgetData() == null || getGadgetData().getType() == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.worktopOptions.remove(option);
|
||||||
EntityType type = getGadgetData().getType();
|
|
||||||
GadgetContent content = switch (type) {
|
|
||||||
case GatherPoint -> new GadgetGatherPoint(this);
|
|
||||||
case Worktop -> new GadgetWorktop(this);
|
|
||||||
case RewardStatue -> new GadgetRewardStatue(this);
|
|
||||||
case Chest -> new GadgetChest(this);
|
|
||||||
default -> null;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.content = content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Int2FloatOpenHashMap getFightProperties() {
|
public Int2FloatOpenHashMap getFightProperties() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,12 +144,41 @@ public class EntityGadget extends EntityBaseGadget {
|
|||||||
.setIsEnableInteract(true)
|
.setIsEnableInteract(true)
|
||||||
.setAuthorityPeerId(this.getScene().getWorld().getHostPeerId());
|
.setAuthorityPeerId(this.getScene().getWorld().getHostPeerId());
|
||||||
|
|
||||||
if (this.getContent() != null) {
|
if (this.getGadgetData().getType() == EntityType.Worktop && this.getWorktopOptions() != null) {
|
||||||
this.getContent().onBuildProto(gadgetInfo);
|
WorktopInfo worktop = WorktopInfo.newBuilder()
|
||||||
|
.addAllOptionList(this.getWorktopOptions())
|
||||||
|
.build();
|
||||||
|
gadgetInfo.setWorktop(worktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
entityInfo.setGadget(gadgetInfo);
|
entityInfo.setGadget(gadgetInfo);
|
||||||
|
|
||||||
return entityInfo.build();
|
return entityInfo.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void openChest(Player player) {
|
||||||
|
var chestRewardMap = getScene().getWorld().getServer().getWorldDataManager().getChestRewardMap();
|
||||||
|
var chestReward = chestRewardMap.get(this.getGadgetData().getJsonName());
|
||||||
|
if(chestReward == null){
|
||||||
|
Grasscutter.getLogger().warn("Could not found the config of this type of Chests {}", this.getGadgetData().getJsonName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.earnExp(chestReward.getAdvExp());
|
||||||
|
player.getInventory().addItem(201, chestReward.getResin());
|
||||||
|
|
||||||
|
var mora = chestReward.getMora() * (1 + (player.getWorldLevel() - 1) * 0.5);
|
||||||
|
player.getInventory().addItem(202, (int)mora);
|
||||||
|
|
||||||
|
for(int i=0;i<chestReward.getContent().size();i++){
|
||||||
|
getScene().addItemEntity(chestReward.getContent().get(i).getItemId(), chestReward.getContent().get(i).getCount(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
var random = new Random(System.currentTimeMillis());
|
||||||
|
for(int i=0;i<chestReward.getRandomCount();i++){
|
||||||
|
var index = random.nextInt(chestReward.getRandomContent().size());
|
||||||
|
var item = chestReward.getRandomContent().get(index);
|
||||||
|
getScene().addItemEntity(item.getItemId(), item.getCount(), this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
package emu.grasscutter.game.entity.gadget;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import emu.grasscutter.Grasscutter;
|
|
||||||
import emu.grasscutter.game.entity.EntityGadget;
|
|
||||||
import emu.grasscutter.game.player.Player;
|
|
||||||
import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType;
|
|
||||||
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
|
|
||||||
import emu.grasscutter.scripts.constants.ScriptGadgetState;
|
|
||||||
import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp;
|
|
||||||
|
|
||||||
public class GadgetChest extends GadgetContent {
|
|
||||||
|
|
||||||
public GadgetChest(EntityGadget gadget) {
|
|
||||||
super(gadget);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onInteract(Player player) {
|
|
||||||
var chestRewardMap = getGadget().getScene().getWorld().getServer().getWorldDataManager().getChestRewardMap();
|
|
||||||
var chestReward = chestRewardMap.get(getGadget().getGadgetData().getJsonName());
|
|
||||||
if (chestReward == null) {
|
|
||||||
Grasscutter.getLogger().warn("Could not found the config of this type of Chests {}", getGadget().getGadgetData().getJsonName());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.earnExp(chestReward.getAdvExp());
|
|
||||||
player.getInventory().addItem(201, chestReward.getResin());
|
|
||||||
|
|
||||||
var mora = chestReward.getMora() * (1 + (player.getWorldLevel() - 1) * 0.5);
|
|
||||||
player.getInventory().addItem(202, (int)mora);
|
|
||||||
|
|
||||||
for(int i=0;i<chestReward.getContent().size();i++){
|
|
||||||
getGadget().getScene().addItemEntity(chestReward.getContent().get(i).getItemId(), chestReward.getContent().get(i).getCount(), getGadget());
|
|
||||||
}
|
|
||||||
|
|
||||||
var random = new Random(System.currentTimeMillis());
|
|
||||||
for(int i=0;i<chestReward.getRandomCount();i++){
|
|
||||||
var index = random.nextInt(chestReward.getRandomContent().size());
|
|
||||||
var item = chestReward.getRandomContent().get(index);
|
|
||||||
getGadget().getScene().addItemEntity(item.getItemId(), item.getCount(), getGadget());
|
|
||||||
}
|
|
||||||
|
|
||||||
getGadget().updateState(ScriptGadgetState.ChestOpened);
|
|
||||||
player.sendPacket(new PacketGadgetInteractRsp(getGadget(), InteractType.INTERACT_OPEN_CHEST));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBuildProto(SceneGadgetInfo.Builder gadgetInfo) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package emu.grasscutter.game.entity.gadget;
|
|
||||||
|
|
||||||
import emu.grasscutter.game.entity.EntityGadget;
|
|
||||||
import emu.grasscutter.game.player.Player;
|
|
||||||
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
|
|
||||||
|
|
||||||
public abstract class GadgetContent {
|
|
||||||
private final EntityGadget gadget;
|
|
||||||
|
|
||||||
public GadgetContent(EntityGadget gadget) {
|
|
||||||
this.gadget = gadget;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityGadget getGadget() {
|
|
||||||
return gadget;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract boolean onInteract(Player player);
|
|
||||||
|
|
||||||
public abstract void onBuildProto(SceneGadgetInfo.Builder gadgetInfo);
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package emu.grasscutter.game.entity.gadget;
|
|
||||||
|
|
||||||
import emu.grasscutter.data.GameData;
|
|
||||||
import emu.grasscutter.data.def.GatherData;
|
|
||||||
import emu.grasscutter.game.entity.EntityGadget;
|
|
||||||
import emu.grasscutter.game.inventory.GameItem;
|
|
||||||
import emu.grasscutter.game.player.Player;
|
|
||||||
import emu.grasscutter.game.props.ActionReason;
|
|
||||||
import emu.grasscutter.net.proto.GatherGadgetInfoOuterClass.GatherGadgetInfo;
|
|
||||||
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
|
|
||||||
|
|
||||||
public class GadgetGatherPoint extends GadgetContent {
|
|
||||||
private GatherData gatherData;
|
|
||||||
|
|
||||||
public GadgetGatherPoint(EntityGadget gadget) {
|
|
||||||
super(gadget);
|
|
||||||
this.gatherData = GameData.getGatherDataMap().get(gadget.getPointType());
|
|
||||||
}
|
|
||||||
|
|
||||||
public GatherData getGatherData() {
|
|
||||||
return gatherData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getItemId() {
|
|
||||||
return getGatherData().getItemId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onInteract(Player player) {
|
|
||||||
GameItem item = new GameItem(gatherData.getItemId(), 1);
|
|
||||||
|
|
||||||
player.getInventory().addItem(item, ActionReason.Gather);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBuildProto(SceneGadgetInfo.Builder gadgetInfo) {
|
|
||||||
GatherGadgetInfo gatherGadgetInfo = GatherGadgetInfo.newBuilder()
|
|
||||||
.setItemId(this.getItemId())
|
|
||||||
.setIsForbidGuest(this.getGatherData().isForbidGuest())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
gadgetInfo.setGatherGadget(gatherGadgetInfo);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package emu.grasscutter.game.entity.gadget;
|
|
||||||
|
|
||||||
import emu.grasscutter.game.entity.EntityGadget;
|
|
||||||
import emu.grasscutter.game.player.Player;
|
|
||||||
import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType;
|
|
||||||
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
|
|
||||||
import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp;
|
|
||||||
|
|
||||||
public class GadgetRewardStatue extends GadgetContent {
|
|
||||||
|
|
||||||
public GadgetRewardStatue(EntityGadget gadget) {
|
|
||||||
super(gadget);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onInteract(Player player) {
|
|
||||||
if (player.getScene().getChallenge() != null) {
|
|
||||||
player.getScene().getChallenge().getStatueDrops(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendPacket(new PacketGadgetInteractRsp(getGadget(), InteractType.INTERACT_OPEN_STATUE));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBuildProto(SceneGadgetInfo.Builder gadgetInfo) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
package emu.grasscutter.game.entity.gadget;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import emu.grasscutter.game.entity.EntityGadget;
|
|
||||||
import emu.grasscutter.game.player.Player;
|
|
||||||
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo;
|
|
||||||
import emu.grasscutter.net.proto.WorktopInfoOuterClass.WorktopInfo;
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
|
||||||
|
|
||||||
public class GadgetWorktop extends GadgetContent {
|
|
||||||
private IntSet worktopOptions;
|
|
||||||
|
|
||||||
public GadgetWorktop(EntityGadget gadget) {
|
|
||||||
super(gadget);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntSet getWorktopOptions() {
|
|
||||||
return worktopOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addWorktopOptions(int[] options) {
|
|
||||||
if (this.worktopOptions == null) {
|
|
||||||
this.worktopOptions = new IntOpenHashSet();
|
|
||||||
}
|
|
||||||
Arrays.stream(options).forEach(this.worktopOptions::add);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeWorktopOption(int option) {
|
|
||||||
if (this.worktopOptions == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.worktopOptions.remove(option);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onInteract(Player player) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBuildProto(SceneGadgetInfo.Builder gadgetInfo) {
|
|
||||||
if (this.worktopOptions == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
WorktopInfo worktop = WorktopInfo.newBuilder()
|
|
||||||
.addAllOptionList(this.getWorktopOptions())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
gadgetInfo.setWorktop(worktop);
|
|
||||||
}
|
|
||||||
}
|
|
@ -918,20 +918,29 @@ public class Player {
|
|||||||
else
|
else
|
||||||
this.getScene().broadcastPacket(new PacketGadgetInteractRsp(drop, InteractType.INTERACT_PICK_ITEM));
|
this.getScene().broadcastPacket(new PacketGadgetInteractRsp(drop, InteractType.INTERACT_PICK_ITEM));
|
||||||
}
|
}
|
||||||
} else if (entity instanceof EntityGadget gadget) {
|
} else if (entity instanceof EntityGadget) {
|
||||||
if (gadget.getContent() == null) {
|
EntityGadget gadget = (EntityGadget) entity;
|
||||||
return;
|
|
||||||
|
if (gadget.getGadgetData().getType() == EntityType.RewardStatue) {
|
||||||
|
if (scene.getChallenge() != null) {
|
||||||
|
scene.getChallenge().getStatueDrops(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendPacket(new PacketGadgetInteractRsp(gadget, InteractType.INTERACT_OPEN_STATUE));
|
||||||
}
|
}
|
||||||
|
else if (gadget.getGadgetData().getType() == EntityType.Chest) {
|
||||||
|
getScene().updateGadgetState(gadget, ScriptGadgetState.ChestOpened);
|
||||||
|
gadget.openChest(this);
|
||||||
|
|
||||||
boolean shouldDelete = gadget.getContent().onInteract(this);
|
this.sendPacket(new PacketGadgetInteractRsp(gadget, InteractType.INTERACT_OPEN_CHEST));
|
||||||
|
getScene().killEntity(gadget, 0);
|
||||||
if (shouldDelete) {
|
|
||||||
entity.getScene().removeEntity(entity);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Delete directly
|
// Delete directly
|
||||||
entity.getScene().removeEntity(entity);
|
entity.getScene().removeEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
|
@ -20,7 +20,6 @@ import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
|
|||||||
import emu.grasscutter.scripts.SceneIndexManager;
|
import emu.grasscutter.scripts.SceneIndexManager;
|
||||||
import emu.grasscutter.scripts.SceneScriptManager;
|
import emu.grasscutter.scripts.SceneScriptManager;
|
||||||
import emu.grasscutter.scripts.data.SceneBlock;
|
import emu.grasscutter.scripts.data.SceneBlock;
|
||||||
import emu.grasscutter.scripts.data.SceneGadget;
|
|
||||||
import emu.grasscutter.scripts.data.SceneGroup;
|
import emu.grasscutter.scripts.data.SceneGroup;
|
||||||
import emu.grasscutter.server.packet.send.*;
|
import emu.grasscutter.server.packet.send.*;
|
||||||
import emu.grasscutter.utils.Position;
|
import emu.grasscutter.utils.Position;
|
||||||
@ -531,14 +530,13 @@ public class Scene {
|
|||||||
public List<SceneGroup> playerMeetGroups(Player player, SceneBlock block){
|
public List<SceneGroup> playerMeetGroups(Player player, SceneBlock block){
|
||||||
int RANGE = 100;
|
int RANGE = 100;
|
||||||
|
|
||||||
List<SceneGroup> sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPos(), RANGE);
|
var sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPos(), RANGE);
|
||||||
|
|
||||||
List<SceneGroup> groups = sceneGroups.stream()
|
var groups = new ArrayList<>(sceneGroups.stream()
|
||||||
.filter(group -> !scriptManager.getLoadedGroupSetPerBlock().get(block.id).contains(group))
|
.filter(group -> !scriptManager.getLoadedGroupSetPerBlock().get(block.id).contains(group))
|
||||||
.peek(group -> scriptManager.getLoadedGroupSetPerBlock().get(block.id).add(group))
|
.peek(group -> scriptManager.getLoadedGroupSetPerBlock().get(block.id).add(group)).toList());
|
||||||
.toList();
|
|
||||||
|
|
||||||
if (groups.size() == 0) {
|
if(groups.size() == 0){
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,14 +574,6 @@ public class Scene {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load garbages
|
|
||||||
List<SceneGadget> garbageGadgets = group.getGarbageGadgets();
|
|
||||||
|
|
||||||
if (garbageGadgets != null) {
|
|
||||||
garbageGadgets.forEach(g -> scriptManager.createGadget(group.id, group.block_id, g));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load suites
|
|
||||||
int suite = group.init_config.suite;
|
int suite = group.init_config.suite;
|
||||||
|
|
||||||
if (suite == 0) {
|
if (suite == 0) {
|
||||||
@ -707,4 +697,9 @@ public class Scene {
|
|||||||
addEntity(entity);
|
addEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateGadgetState(EntityGadget gadget, int state){
|
||||||
|
gadget.setState(state);
|
||||||
|
broadcastPacket(new PacketGadgetStateNotify(gadget, state));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,11 +351,6 @@ public class SceneScriptManager {
|
|||||||
entity.setGroupId(groupId);
|
entity.setGroupId(groupId);
|
||||||
entity.getRotation().set(g.rot);
|
entity.getRotation().set(g.rot);
|
||||||
entity.setState(g.state);
|
entity.setState(g.state);
|
||||||
entity.setPointType(g.point_type);
|
|
||||||
entity.buildContent();
|
|
||||||
|
|
||||||
// Lua event
|
|
||||||
this.callEvent(EventType.EVENT_GADGET_CREATE, new ScriptArgs(entity.getConfigId()));
|
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
@ -394,22 +389,31 @@ public class SceneScriptManager {
|
|||||||
this.getScriptMonsterSpawnService()
|
this.getScriptMonsterSpawnService()
|
||||||
.onMonsterCreatedListener.forEach(action -> action.onNotify(entity));
|
.onMonsterCreatedListener.forEach(action -> action.onNotify(entity));
|
||||||
|
|
||||||
// Lua event
|
|
||||||
callEvent(EventType.EVENT_ANY_MONSTER_LIVE, new ScriptArgs(entity.getConfigId()));
|
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEntity(GameEntity gameEntity){
|
public void addEntity(GameEntity gameEntity){
|
||||||
getScene().addEntity(gameEntity);
|
getScene().addEntity(gameEntity);
|
||||||
|
callCreateEvent(gameEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void meetEntities(List<? extends GameEntity> gameEntity){
|
public void meetEntities(List<? extends GameEntity> gameEntity){
|
||||||
getScene().addEntities(gameEntity, VisionTypeOuterClass.VisionType.VISION_MEET);
|
getScene().addEntities(gameEntity, VisionTypeOuterClass.VisionType.VISION_MEET);
|
||||||
|
gameEntity.forEach(this::callCreateEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEntities(List<? extends GameEntity> gameEntity){
|
public void addEntities(List<? extends GameEntity> gameEntity){
|
||||||
getScene().addEntities(gameEntity);
|
getScene().addEntities(gameEntity);
|
||||||
|
gameEntity.forEach(this::callCreateEvent);
|
||||||
|
}
|
||||||
|
public void callCreateEvent(GameEntity gameEntity){
|
||||||
|
if(!isInit){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(gameEntity instanceof EntityMonster entityMonster){
|
||||||
|
callEvent(EventType.EVENT_ANY_MONSTER_LIVE, new ScriptArgs(entityMonster.getConfigId()));
|
||||||
|
}
|
||||||
|
if(gameEntity instanceof EntityGadget entityGadget){
|
||||||
|
this.callEvent(EventType.EVENT_GADGET_CREATE, new ScriptArgs(entityGadget.getConfigId()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PhTree<SceneBlock> getBlocksIndex() {
|
public PhTree<SceneBlock> getBlocksIndex() {
|
||||||
|
@ -4,7 +4,6 @@ import emu.grasscutter.game.dungeons.DungeonChallenge;
|
|||||||
import emu.grasscutter.game.entity.EntityGadget;
|
import emu.grasscutter.game.entity.EntityGadget;
|
||||||
import emu.grasscutter.game.entity.EntityMonster;
|
import emu.grasscutter.game.entity.EntityMonster;
|
||||||
import emu.grasscutter.game.entity.GameEntity;
|
import emu.grasscutter.game.entity.GameEntity;
|
||||||
import emu.grasscutter.game.entity.gadget.GadgetWorktop;
|
|
||||||
import emu.grasscutter.scripts.data.SceneGroup;
|
import emu.grasscutter.scripts.data.SceneGroup;
|
||||||
import emu.grasscutter.scripts.data.SceneRegion;
|
import emu.grasscutter.scripts.data.SceneRegion;
|
||||||
import emu.grasscutter.server.packet.send.PacketCanUseSkillNotify;
|
import emu.grasscutter.server.packet.send.PacketCanUseSkillNotify;
|
||||||
@ -95,22 +94,21 @@ public class ScriptLib {
|
|||||||
public int SetWorktopOptionsByGroupId(int groupId, int configId, int[] options) {
|
public int SetWorktopOptionsByGroupId(int groupId, int configId, int[] options) {
|
||||||
logger.debug("[LUA] Call SetWorktopOptionsByGroupId with {},{},{}",
|
logger.debug("[LUA] Call SetWorktopOptionsByGroupId with {},{},{}",
|
||||||
groupId,configId,options);
|
groupId,configId,options);
|
||||||
|
|
||||||
Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
||||||
.filter(e -> e.getConfigId() == configId && e.getGroupId() == groupId).findFirst();
|
.filter(e -> e.getConfigId() == configId && e.getGroupId() == groupId).findFirst();
|
||||||
|
|
||||||
|
if (entity.isEmpty()) {
|
||||||
if (entity.isEmpty() || !(entity.get() instanceof EntityGadget gadget)) {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(gadget.getContent() instanceof GadgetWorktop worktop)) {
|
if (!(entity.get() instanceof EntityGadget)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
worktop.addWorktopOptions(options);
|
EntityGadget gadget = (EntityGadget) entity.get();
|
||||||
|
gadget.addWorktopOptions(options);
|
||||||
|
|
||||||
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));
|
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,17 +123,18 @@ public class ScriptLib {
|
|||||||
Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
Optional<GameEntity> entity = getSceneScriptManager().getScene().getEntities().values().stream()
|
||||||
.filter(e -> e.getConfigId() == configId && e.getGroupId() == groupId).findFirst();
|
.filter(e -> e.getConfigId() == configId && e.getGroupId() == groupId).findFirst();
|
||||||
|
|
||||||
if (entity.isEmpty() || !(entity.get() instanceof EntityGadget gadget)) {
|
if (entity.isEmpty()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(gadget.getContent() instanceof GadgetWorktop worktop)) {
|
if (!(entity.get() instanceof EntityGadget)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
worktop.removeWorktopOption(option);
|
EntityGadget gadget = (EntityGadget) entity.get();
|
||||||
|
gadget.removeWorktopOption(option);
|
||||||
|
|
||||||
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));
|
getSceneScriptManager().getScene().broadcastPacket(new PacketWorktopOptionNotify(gadget));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,14 +375,11 @@ public class ScriptLib {
|
|||||||
var configId = table.get("config_id").toint();
|
var configId = table.get("config_id").toint();
|
||||||
|
|
||||||
var group = getCurrentGroup();
|
var group = getCurrentGroup();
|
||||||
|
if(group.isEmpty()){
|
||||||
if (group.isEmpty()) {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var gadget = group.get().gadgets.get(configId);
|
var gadget = group.get().gadgets.get(configId);
|
||||||
var entity = getSceneScriptManager().createGadget(group.get().id, group.get().block_id, gadget);
|
var entity = getSceneScriptManager().createGadget(group.get().id, group.get().block_id, gadget);
|
||||||
|
|
||||||
getSceneScriptManager().addEntity(entity);
|
getSceneScriptManager().addEntity(entity);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -440,8 +436,8 @@ public class ScriptLib {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity instanceof EntityGadget entityGadget) {
|
if(entity instanceof EntityGadget entityGadget){
|
||||||
entityGadget.updateState(state);
|
getSceneScriptManager().getScene().updateGadgetState(entityGadget, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -95,7 +95,7 @@ public class ScriptLoader {
|
|||||||
return sc.get();
|
return sc.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Grasscutter.getLogger().info("Loading script " + path);
|
Grasscutter.getLogger().info("Loaded Script" + path);
|
||||||
|
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ public class ScriptLoader {
|
|||||||
scriptsCache.put(path, new SoftReference<>(script));
|
scriptsCache.put(path, new SoftReference<>(script));
|
||||||
return script;
|
return script;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Grasscutter.getLogger().error("Loading script {} failed!", path, e);
|
Grasscutter.getLogger().error("Loaded Script {} failed!", path, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package emu.grasscutter.scripts.data;
|
|
||||||
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
@ToString
|
|
||||||
@Setter
|
|
||||||
public class SceneBusiness {
|
|
||||||
public int type;
|
|
||||||
}
|
|
@ -8,5 +8,4 @@ import lombok.ToString;
|
|||||||
public class SceneGadget extends SceneObject{
|
public class SceneGadget extends SceneObject{
|
||||||
public int gadget_id;
|
public int gadget_id;
|
||||||
public int state;
|
public int state;
|
||||||
public int point_type;
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
package emu.grasscutter.scripts.data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
@ToString
|
|
||||||
@Setter
|
|
||||||
public class SceneGarbage {
|
|
||||||
public List<SceneGadget> gadgets;
|
|
||||||
}
|
|
@ -26,20 +26,21 @@ public class SceneGroup {
|
|||||||
public int refresh_id;
|
public int refresh_id;
|
||||||
public Position pos;
|
public Position pos;
|
||||||
|
|
||||||
public Map<Integer,SceneMonster> monsters; // <ConfigId, Monster>
|
/**
|
||||||
public Map<Integer, SceneGadget> gadgets; // <ConfigId, Gadgets>
|
* ConfigId - Monster
|
||||||
|
*/
|
||||||
|
public Map<Integer,SceneMonster> monsters;
|
||||||
|
/**
|
||||||
|
* ConfigId - Gadget
|
||||||
|
*/
|
||||||
|
public Map<Integer, SceneGadget> gadgets;
|
||||||
public Map<String, SceneTrigger> triggers;
|
public Map<String, SceneTrigger> triggers;
|
||||||
|
|
||||||
public List<SceneRegion> regions;
|
public List<SceneRegion> regions;
|
||||||
public List<SceneSuite> suites;
|
public List<SceneSuite> suites;
|
||||||
public List<SceneVar> variables;
|
|
||||||
|
|
||||||
public SceneBusiness business;
|
|
||||||
public SceneGarbage garbages;
|
|
||||||
public SceneInitConfig init_config;
|
public SceneInitConfig init_config;
|
||||||
|
|
||||||
|
public List<SceneVar> variables;
|
||||||
private transient boolean loaded; // Not an actual variable in the scripts either
|
private transient boolean loaded; // Not an actual variable in the scripts either
|
||||||
private transient CompiledScript script;
|
|
||||||
|
|
||||||
public boolean isLoaded() {
|
public boolean isLoaded() {
|
||||||
return loaded;
|
return loaded;
|
||||||
@ -49,13 +50,7 @@ public class SceneGroup {
|
|||||||
this.loaded = loaded;
|
this.loaded = loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBusinessType() {
|
private transient CompiledScript script; // Not an actual variable in the scripts either
|
||||||
return this.business == null ? 0 : this.business.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SceneGadget> getGarbageGadgets() {
|
|
||||||
return this.garbages == null ? null : this.garbages.gadgets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompiledScript getScript() {
|
public CompiledScript getScript() {
|
||||||
return script;
|
return script;
|
||||||
@ -80,7 +75,6 @@ public class SceneGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.script = cs;
|
this.script = cs;
|
||||||
|
|
||||||
// Eval script
|
// Eval script
|
||||||
try {
|
try {
|
||||||
cs.eval(bindings);
|
cs.eval(bindings);
|
||||||
@ -100,13 +94,12 @@ public class SceneGroup {
|
|||||||
|
|
||||||
suites = ScriptLoader.getSerializer().toList(SceneSuite.class, bindings.get("suites"));
|
suites = ScriptLoader.getSerializer().toList(SceneSuite.class, bindings.get("suites"));
|
||||||
regions = ScriptLoader.getSerializer().toList(SceneRegion.class, bindings.get("regions"));
|
regions = ScriptLoader.getSerializer().toList(SceneRegion.class, bindings.get("regions"));
|
||||||
garbages = ScriptLoader.getSerializer().toObject(SceneGarbage.class, bindings.get("garbages"));
|
|
||||||
init_config = ScriptLoader.getSerializer().toObject(SceneInitConfig.class, bindings.get("init_config"));
|
init_config = ScriptLoader.getSerializer().toObject(SceneInitConfig.class, bindings.get("init_config"));
|
||||||
|
|
||||||
// Add variables to suite
|
// Add variables to suite
|
||||||
variables = ScriptLoader.getSerializer().toList(SceneVar.class, bindings.get("variables"));
|
variables = ScriptLoader.getSerializer().toList(SceneVar.class, bindings.get("variables"));
|
||||||
|
|
||||||
// Add monsters and gadgets to suite
|
// Add monsters to suite
|
||||||
for (SceneSuite suite : suites) {
|
for (SceneSuite suite : suites) {
|
||||||
suite.sceneMonsters = new ArrayList<>(
|
suite.sceneMonsters = new ArrayList<>(
|
||||||
suite.monsters.stream()
|
suite.monsters.stream()
|
||||||
@ -133,7 +126,6 @@ public class SceneGroup {
|
|||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
Grasscutter.getLogger().error("Error loading group " + id + " in scene " + sceneId, e);
|
Grasscutter.getLogger().error("Error loading group " + id + " in scene " + sceneId, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Grasscutter.getLogger().info("group {} in scene {} is loaded successfully.", id, sceneId);
|
Grasscutter.getLogger().info("group {} in scene {} is loaded successfully.", id, sceneId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package emu.grasscutter.server.packet.send;
|
package emu.grasscutter.server.packet.send;
|
||||||
|
|
||||||
import emu.grasscutter.game.entity.EntityGadget;
|
import emu.grasscutter.game.entity.EntityGadget;
|
||||||
import emu.grasscutter.game.entity.gadget.GadgetWorktop;
|
|
||||||
import emu.grasscutter.net.packet.BasePacket;
|
import emu.grasscutter.net.packet.BasePacket;
|
||||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||||
import emu.grasscutter.net.proto.WorktopOptionNotifyOuterClass.WorktopOptionNotify;
|
import emu.grasscutter.net.proto.WorktopOptionNotifyOuterClass.WorktopOptionNotify;
|
||||||
@ -14,8 +13,8 @@ public class PacketWorktopOptionNotify extends BasePacket {
|
|||||||
WorktopOptionNotify.Builder proto = WorktopOptionNotify.newBuilder()
|
WorktopOptionNotify.Builder proto = WorktopOptionNotify.newBuilder()
|
||||||
.setGadgetEntityId(gadget.getId());
|
.setGadgetEntityId(gadget.getId());
|
||||||
|
|
||||||
if (gadget.getContent() instanceof GadgetWorktop worktop) {
|
if (gadget.getWorktopOptions() != null) {
|
||||||
proto.addAllOptionList(worktop.getWorktopOptions());
|
proto.addAllOptionList(gadget.getWorktopOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setData(proto);
|
this.setData(proto);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user