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 {
case Worktop -> new GadgetWorktop(this);
case RewardStatue -> new GadgetRewardStatue(this);
case Chest -> new GadgetChest(this);
case Gadget -> new GadgetObject(this);
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 {
// TODO - Test
public synchronized void checkSpawns() {
int RANGE = 100;
SpatialIndex<SpawnGroupEntry> list = GameDepot.getSpawnListById(this.getId());
Set<SpawnDataEntry> visible = new HashSet<>();
for (Player player : this.getPlayers()) {
int RANGE = 100;
Position position = player.getPos();
Collection<SpawnGroupEntry> entries = list.query(
new double[] {player.getPos().getX() - RANGE, player.getPos().getZ() - RANGE},
new double[] {player.getPos().getX() + RANGE, player.getPos().getZ() + RANGE}
new double[] {position.getX() - RANGE, position.getZ() - RANGE},
new double[] {position.getX() + RANGE, position.getZ() + RANGE}
);
for (SpawnGroupEntry entry : entries) {
for (SpawnDataEntry spawnData : entry.getSpawns()) {
visible.add(spawnData);
......@@ -467,10 +467,10 @@ public class Scene {
// Todo
List<GameEntity> toAdd = new LinkedList<>();
List<GameEntity> toRemove = new LinkedList<>();
var spawnedEntities = this.getSpawnedEntities();
for (SpawnDataEntry entry : visible) {
// 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
GameEntity entity = null;
......@@ -494,6 +494,10 @@ public class Scene {
gadget.setGroupId(entry.getGroup().getGroupId());
gadget.setConfigId(entry.getConfigId());
gadget.setSpawnEntry(entry);
int state = entry.getGadgetState();
if(state>0) {
gadget.setState(state);
}
gadget.buildContent();
gadget.setFightProperty(FightProperty.FIGHT_PROP_BASE_HP, 99999);
......@@ -507,13 +511,15 @@ public class Scene {
// Add to scene and spawned list
toAdd.add(entity);
getSpawnedEntities().add(entry);
spawnedEntities.add(entry);
}
}
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);
spawnedEntities.remove(spawnEntry);
}
}
......
......@@ -12,6 +12,7 @@ public class SpawnDataEntry {
private int level;
private int poseId;
private int gatherItemId;
private int gadgetState;
private Position pos;
private Position rot;
......@@ -31,6 +32,10 @@ public class SpawnDataEntry {
return gadgetId;
}
public int getGadgetState() {
return gadgetState;
}
public int getConfigId() {
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