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

* fixGadget

* fixGadget

* add gadgetObject

* fix bug
This commit is contained in:
zhaodice 2022-07-02 02:41:53 +08:00 committed by GitHub
parent 696206c73c
commit 5416a2f9fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36529 additions and 93 deletions

View File

@ -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;
};

View File

@ -0,0 +1,22 @@
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) {
}
}

View File

@ -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);
}
}

View File

@ -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;
}

File diff suppressed because one or more lines are too long