Commit f90b6512 authored by zhaodice's avatar zhaodice Committed by GitHub
Browse files

Fix no static gadget in the map,example: no tree but a fruit in the air (#1415)

* fixGadget

* fixGadget

* add gadgetObject

* fix bug
parent b7032015
...@@ -138,6 +138,7 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -138,6 +138,7 @@ public class EntityGadget extends EntityBaseGadget {
case Worktop -> new GadgetWorktop(this); case Worktop -> new GadgetWorktop(this);
case RewardStatue -> new GadgetRewardStatue(this); case RewardStatue -> new GadgetRewardStatue(this);
case Chest -> new GadgetChest(this); case Chest -> new GadgetChest(this);
case Gadget -> new GadgetObject(this);
default -> null; default -> null;
}; };
......
package emu.grasscutter.game.entity.gadget;
import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.GadgetInteractReqOuterClass;
import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass;
public class GadgetObject extends GadgetContent{
public GadgetObject(EntityGadget gadget) {
super(gadget);
}
@Override
public boolean onInteract(Player player, GadgetInteractReqOuterClass.GadgetInteractReq req) {
return false;
}
@Override
public void onBuildProto(SceneGadgetInfoOuterClass.SceneGadgetInfo.Builder gadgetInfo) {
}
}
...@@ -438,17 +438,17 @@ public class Scene { ...@@ -438,17 +438,17 @@ public class Scene {
// TODO - Test // TODO - Test
public synchronized void checkSpawns() { public synchronized void checkSpawns() {
int RANGE = 100;
SpatialIndex<SpawnGroupEntry> list = GameDepot.getSpawnListById(this.getId()); SpatialIndex<SpawnGroupEntry> list = GameDepot.getSpawnListById(this.getId());
Set<SpawnDataEntry> visible = new HashSet<>(); Set<SpawnDataEntry> visible = new HashSet<>();
for (Player player : this.getPlayers()) { for (Player player : this.getPlayers()) {
int RANGE = 100; Position position = player.getPos();
Collection<SpawnGroupEntry> entries = list.query( Collection<SpawnGroupEntry> entries = list.query(
new double[] {player.getPos().getX() - RANGE, player.getPos().getZ() - RANGE}, new double[] {position.getX() - RANGE, position.getZ() - RANGE},
new double[] {player.getPos().getX() + RANGE, player.getPos().getZ() + RANGE} new double[] {position.getX() + RANGE, position.getZ() + RANGE}
); );
for (SpawnGroupEntry entry : entries) { for (SpawnGroupEntry entry : entries) {
for (SpawnDataEntry spawnData : entry.getSpawns()) { for (SpawnDataEntry spawnData : entry.getSpawns()) {
visible.add(spawnData); visible.add(spawnData);
...@@ -467,10 +467,10 @@ public class Scene { ...@@ -467,10 +467,10 @@ public class Scene {
// Todo // Todo
List<GameEntity> toAdd = new LinkedList<>(); List<GameEntity> toAdd = new LinkedList<>();
List<GameEntity> toRemove = new LinkedList<>(); List<GameEntity> toRemove = new LinkedList<>();
var spawnedEntities = this.getSpawnedEntities();
for (SpawnDataEntry entry : visible) { for (SpawnDataEntry entry : visible) {
// If spawn entry is in our view and hasnt been spawned/killed yet, we should spawn it // If spawn entry is in our view and hasnt been spawned/killed yet, we should spawn it
if (!this.getSpawnedEntities().contains(entry) && !this.getDeadSpawnedEntities().contains(entry)) { if (!spawnedEntities.contains(entry) && !this.getDeadSpawnedEntities().contains(entry)) {
// Entity object holder // Entity object holder
GameEntity entity = null; GameEntity entity = null;
...@@ -494,6 +494,10 @@ public class Scene { ...@@ -494,6 +494,10 @@ public class Scene {
gadget.setGroupId(entry.getGroup().getGroupId()); gadget.setGroupId(entry.getGroup().getGroupId());
gadget.setConfigId(entry.getConfigId()); gadget.setConfigId(entry.getConfigId());
gadget.setSpawnEntry(entry); gadget.setSpawnEntry(entry);
int state = entry.getGadgetState();
if(state>0) {
gadget.setState(state);
}
gadget.buildContent(); gadget.buildContent();
gadget.setFightProperty(FightProperty.FIGHT_PROP_BASE_HP, 99999); gadget.setFightProperty(FightProperty.FIGHT_PROP_BASE_HP, 99999);
...@@ -507,13 +511,15 @@ public class Scene { ...@@ -507,13 +511,15 @@ public class Scene {
// Add to scene and spawned list // Add to scene and spawned list
toAdd.add(entity); toAdd.add(entity);
getSpawnedEntities().add(entry); spawnedEntities.add(entry);
} }
} }
for (GameEntity entity : this.getEntities().values()) { for (GameEntity entity : this.getEntities().values()) {
if (entity.getSpawnEntry() != null && !visible.contains(entity.getSpawnEntry())) { var spawnEntry = entity.getSpawnEntry();
if (spawnEntry != null && !visible.contains(spawnEntry)) {
toRemove.add(entity); toRemove.add(entity);
spawnedEntities.remove(spawnEntry);
} }
} }
......
...@@ -12,6 +12,7 @@ public class SpawnDataEntry { ...@@ -12,6 +12,7 @@ public class SpawnDataEntry {
private int level; private int level;
private int poseId; private int poseId;
private int gatherItemId; private int gatherItemId;
private int gadgetState;
private Position pos; private Position pos;
private Position rot; private Position rot;
...@@ -31,6 +32,10 @@ public class SpawnDataEntry { ...@@ -31,6 +32,10 @@ public class SpawnDataEntry {
return gadgetId; return gadgetId;
} }
public int getGadgetState() {
return gadgetState;
}
public int getConfigId() { public int getConfigId() {
return configId; return configId;
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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