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
...@@ -39,13 +39,13 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -39,13 +39,13 @@ public class EntityGadget extends EntityBaseGadget {
private final Position pos; private final Position pos;
private final Position rot; private final Position rot;
private int gadgetId; private int gadgetId;
private int state; private int state;
private int pointType; private int pointType;
private GadgetContent content; private GadgetContent content;
private Int2FloatOpenHashMap fightProp; private Int2FloatOpenHashMap fightProp;
private SceneGadget metaGadget; private SceneGadget metaGadget;
public EntityGadget(Scene scene, int gadgetId, Position pos, Position rot) { public EntityGadget(Scene scene, int gadgetId, Position pos, Position rot) {
super(scene); super(scene);
this.data = GameData.getGadgetDataMap().get(gadgetId); this.data = GameData.getGadgetDataMap().get(gadgetId);
...@@ -63,7 +63,7 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -63,7 +63,7 @@ public class EntityGadget extends EntityBaseGadget {
this(scene, gadgetId, pos, rot); this(scene, gadgetId, pos, rot);
this.content = content; this.content = content;
} }
public GadgetData getGadgetData() { public GadgetData getGadgetData() {
return data; return data;
} }
...@@ -77,7 +77,7 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -77,7 +77,7 @@ public class EntityGadget extends EntityBaseGadget {
public Position getRotation() { public Position getRotation() {
return this.rot; return this.rot;
} }
public int getGadgetId() { public int getGadgetId() {
return gadgetId; return gadgetId;
} }
...@@ -93,7 +93,7 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -93,7 +93,7 @@ public class EntityGadget extends EntityBaseGadget {
public void setState(int state) { public void setState(int state) {
this.state = state; this.state = state;
} }
public void updateState(int state){ public void updateState(int state){
this.setState(state); this.setState(state);
this.getScene().broadcastPacket(new PacketGadgetStateNotify(this, state)); this.getScene().broadcastPacket(new PacketGadgetStateNotify(this, state));
...@@ -130,7 +130,7 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -130,7 +130,7 @@ public class EntityGadget extends EntityBaseGadget {
if (getContent() != null || getGadgetData() == null || getGadgetData().getType() == null) { if (getContent() != null || getGadgetData() == null || getGadgetData().getType() == null) {
return; return;
} }
EntityType type = getGadgetData().getType(); EntityType type = getGadgetData().getType();
GadgetContent content = switch (type) { GadgetContent content = switch (type) {
case GatherPoint -> new GadgetGatherPoint(this); case GatherPoint -> new GadgetGatherPoint(this);
...@@ -138,9 +138,10 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -138,9 +138,10 @@ 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;
}; };
this.content = content; this.content = content;
} }
...@@ -149,7 +150,7 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -149,7 +150,7 @@ public class EntityGadget extends EntityBaseGadget {
if (this.fightProp == null) this.fightProp = new Int2FloatOpenHashMap(); if (this.fightProp == null) this.fightProp = new Int2FloatOpenHashMap();
return this.fightProp; return this.fightProp;
} }
@Override @Override
public void onCreate() { public void onCreate() {
// Lua event // Lua event
...@@ -166,7 +167,7 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -166,7 +167,7 @@ public class EntityGadget extends EntityBaseGadget {
} }
getScene().getScriptManager().callEvent(EventType.EVENT_ANY_GADGET_DIE, new ScriptArgs(this.getConfigId())); getScene().getScriptManager().callEvent(EventType.EVENT_ANY_GADGET_DIE, new ScriptArgs(this.getConfigId()));
} }
@Override @Override
public SceneEntityInfo toProto() { public SceneEntityInfo toProto() {
EntityAuthorityInfo authority = EntityAuthorityInfo.newBuilder() EntityAuthorityInfo authority = EntityAuthorityInfo.newBuilder()
...@@ -175,7 +176,7 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -175,7 +176,7 @@ public class EntityGadget extends EntityBaseGadget {
.setAiInfo(SceneEntityAiInfo.newBuilder().setIsAiOpen(true).setBornPos(Vector.newBuilder())) .setAiInfo(SceneEntityAiInfo.newBuilder().setIsAiOpen(true).setBornPos(Vector.newBuilder()))
.setBornPos(Vector.newBuilder()) .setBornPos(Vector.newBuilder())
.build(); .build();
SceneEntityInfo.Builder entityInfo = SceneEntityInfo.newBuilder() SceneEntityInfo.Builder entityInfo = SceneEntityInfo.newBuilder()
.setEntityId(getId()) .setEntityId(getId())
.setEntityType(ProtEntityType.PROT_ENTITY_TYPE_GADGET) .setEntityType(ProtEntityType.PROT_ENTITY_TYPE_GADGET)
...@@ -184,13 +185,13 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -184,13 +185,13 @@ public class EntityGadget extends EntityBaseGadget {
.setEntityClientData(EntityClientData.newBuilder()) .setEntityClientData(EntityClientData.newBuilder())
.setEntityAuthorityInfo(authority) .setEntityAuthorityInfo(authority)
.setLifeState(1); .setLifeState(1);
PropPair pair = PropPair.newBuilder() PropPair pair = PropPair.newBuilder()
.setType(PlayerProperty.PROP_LEVEL.getId()) .setType(PlayerProperty.PROP_LEVEL.getId())
.setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, 1)) .setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, 1))
.build(); .build();
entityInfo.addPropList(pair); entityInfo.addPropList(pair);
// We do not use the getter to null check because the getter will create a fight prop map if it is null // We do not use the getter to null check because the getter will create a fight prop map if it is null
if (this.fightProp != null) { if (this.fightProp != null) {
this.addAllFightPropsToEntityInfo(entityInfo); this.addAllFightPropsToEntityInfo(entityInfo);
...@@ -203,13 +204,13 @@ public class EntityGadget extends EntityBaseGadget { ...@@ -203,13 +204,13 @@ public class EntityGadget extends EntityBaseGadget {
.setGadgetState(this.getState()) .setGadgetState(this.getState())
.setIsEnableInteract(true) .setIsEnableInteract(true)
.setAuthorityPeerId(this.getScene().getWorld().getHostPeerId()); .setAuthorityPeerId(this.getScene().getWorld().getHostPeerId());
if (this.getContent() != null) { if (this.getContent() != null) {
this.getContent().onBuildProto(gadgetInfo); this.getContent().onBuildProto(gadgetInfo);
} }
entityInfo.setGadget(gadgetInfo); entityInfo.setGadget(gadgetInfo);
return entityInfo.build(); return entityInfo.build();
} }
public void die() { public void die() {
......
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) {
}
}
...@@ -75,11 +75,11 @@ public class Scene { ...@@ -75,11 +75,11 @@ public class Scene {
public World getWorld() { public World getWorld() {
return world; return world;
} }
public SceneData getSceneData() { public SceneData getSceneData() {
return this.sceneData; return this.sceneData;
} }
public SceneType getSceneType() { public SceneType getSceneType() {
return getSceneData().getSceneType(); return getSceneData().getSceneType();
} }
...@@ -201,18 +201,18 @@ public class Scene { ...@@ -201,18 +201,18 @@ public class Scene {
public boolean isInScene(GameEntity entity) { public boolean isInScene(GameEntity entity) {
return this.entities.containsKey(entity.getId()); return this.entities.containsKey(entity.getId());
} }
public synchronized void addPlayer(Player player) { public synchronized void addPlayer(Player player) {
// Check if player already in // Check if player already in
if (getPlayers().contains(player)) { if (getPlayers().contains(player)) {
return; return;
} }
// Remove player from prev scene // Remove player from prev scene
if (player.getScene() != null) { if (player.getScene() != null) {
player.getScene().removePlayer(player); player.getScene().removePlayer(player);
} }
// Add // Add
getPlayers().add(player); getPlayers().add(player);
player.setSceneId(this.getId()); player.setSceneId(this.getId());
...@@ -220,31 +220,31 @@ public class Scene { ...@@ -220,31 +220,31 @@ public class Scene {
this.setupPlayerAvatars(player); this.setupPlayerAvatars(player);
} }
public synchronized void removePlayer(Player player) { public synchronized void removePlayer(Player player) {
// Remove from challenge if leaving // Remove from challenge if leaving
if (this.getChallenge() != null && this.getChallenge().inProgress()) { if (this.getChallenge() != null && this.getChallenge().inProgress()) {
player.sendPacket(new PacketDungeonChallengeFinishNotify(this.getChallenge())); player.sendPacket(new PacketDungeonChallengeFinishNotify(this.getChallenge()));
} }
// Remove player from scene // Remove player from scene
getPlayers().remove(player); getPlayers().remove(player);
player.setScene(null); player.setScene(null);
// Remove player avatars // Remove player avatars
this.removePlayerAvatars(player); this.removePlayerAvatars(player);
// Remove player gadgets // Remove player gadgets
for (EntityBaseGadget gadget : player.getTeamManager().getGadgets()) { for (EntityBaseGadget gadget : player.getTeamManager().getGadgets()) {
this.removeEntity(gadget); this.removeEntity(gadget);
} }
// Deregister scene if not in use // Deregister scene if not in use
if (this.getPlayerCount() <= 0 && !this.dontDestroyWhenEmpty()) { if (this.getPlayerCount() <= 0 && !this.dontDestroyWhenEmpty()) {
this.getWorld().deregisterScene(this); this.getWorld().deregisterScene(this);
} }
} }
private void setupPlayerAvatars(Player player) { private void setupPlayerAvatars(Player player) {
// Clear entities from old team // Clear entities from old team
player.getTeamManager().getActiveTeam().clear(); player.getTeamManager().getActiveTeam().clear();
...@@ -255,13 +255,13 @@ public class Scene { ...@@ -255,13 +255,13 @@ public class Scene {
EntityAvatar entity = new EntityAvatar(player.getScene(), player.getAvatars().getAvatarById(avatarId)); EntityAvatar entity = new EntityAvatar(player.getScene(), player.getAvatars().getAvatarById(avatarId));
player.getTeamManager().getActiveTeam().add(entity); player.getTeamManager().getActiveTeam().add(entity);
} }
// Limit character index in case its out of bounds // Limit character index in case its out of bounds
if (player.getTeamManager().getCurrentCharacterIndex() >= player.getTeamManager().getActiveTeam().size() || player.getTeamManager().getCurrentCharacterIndex() < 0) { if (player.getTeamManager().getCurrentCharacterIndex() >= player.getTeamManager().getActiveTeam().size() || player.getTeamManager().getCurrentCharacterIndex() < 0) {
player.getTeamManager().setCurrentCharacterIndex(player.getTeamManager().getCurrentCharacterIndex() - 1); player.getTeamManager().setCurrentCharacterIndex(player.getTeamManager().getCurrentCharacterIndex() - 1);
} }
} }
private void removePlayerAvatars(Player player) { private void removePlayerAvatars(Player player) {
Iterator<EntityAvatar> it = player.getTeamManager().getActiveTeam().iterator(); Iterator<EntityAvatar> it = player.getTeamManager().getActiveTeam().iterator();
while (it.hasNext()) { while (it.hasNext()) {
...@@ -269,18 +269,18 @@ public class Scene { ...@@ -269,18 +269,18 @@ public class Scene {
it.remove(); it.remove();
} }
} }
public void spawnPlayer(Player player) { public void spawnPlayer(Player player) {
if (this.isInScene(player.getTeamManager().getCurrentAvatarEntity())) { if (this.isInScene(player.getTeamManager().getCurrentAvatarEntity())) {
return; return;
} }
if (player.getTeamManager().getCurrentAvatarEntity().getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) <= 0f) { if (player.getTeamManager().getCurrentAvatarEntity().getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) <= 0f) {
player.getTeamManager().getCurrentAvatarEntity().setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 1f); player.getTeamManager().getCurrentAvatarEntity().setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 1f);
} }
this.addEntity(player.getTeamManager().getCurrentAvatarEntity()); this.addEntity(player.getTeamManager().getCurrentAvatarEntity());
// Notify the client of any extra skill charges // Notify the client of any extra skill charges
for (EntityAvatar entity : player.getTeamManager().getActiveTeam()) { for (EntityAvatar entity : player.getTeamManager().getActiveTeam()) {
if (entity.getAvatar().getSkillExtraChargeMap().size() > 0) { if (entity.getAvatar().getSkillExtraChargeMap().size() > 0) {
...@@ -288,12 +288,12 @@ public class Scene { ...@@ -288,12 +288,12 @@ public class Scene {
} }
} }
} }
private void addEntityDirectly(GameEntity entity) { private void addEntityDirectly(GameEntity entity) {
getEntities().put(entity.getId(), entity); getEntities().put(entity.getId(), entity);
entity.onCreate(); // Call entity create event entity.onCreate(); // Call entity create event
} }
public synchronized void addEntity(GameEntity entity) { public synchronized void addEntity(GameEntity entity) {
this.addEntityDirectly(entity); this.addEntityDirectly(entity);
this.broadcastPacket(new PacketSceneEntityAppearNotify(entity)); this.broadcastPacket(new PacketSceneEntityAppearNotify(entity));
...@@ -307,7 +307,7 @@ public class Scene { ...@@ -307,7 +307,7 @@ public class Scene {
public void addEntities(Collection<? extends GameEntity> entities){ public void addEntities(Collection<? extends GameEntity> entities){
addEntities(entities, VisionType.VISION_TYPE_BORN); addEntities(entities, VisionType.VISION_TYPE_BORN);
} }
public synchronized void addEntities(Collection<? extends GameEntity> entities, VisionType visionType) { public synchronized void addEntities(Collection<? extends GameEntity> entities, VisionType visionType) {
if(entities == null || entities.isEmpty()){ if(entities == null || entities.isEmpty()){
return; return;
...@@ -315,18 +315,18 @@ public class Scene { ...@@ -315,18 +315,18 @@ public class Scene {
for (GameEntity entity : entities) { for (GameEntity entity : entities) {
this.addEntityDirectly(entity); this.addEntityDirectly(entity);
} }
this.broadcastPacket(new PacketSceneEntityAppearNotify(entities, visionType)); this.broadcastPacket(new PacketSceneEntityAppearNotify(entities, visionType));
} }
private GameEntity removeEntityDirectly(GameEntity entity) { private GameEntity removeEntityDirectly(GameEntity entity) {
return getEntities().remove(entity.getId()); return getEntities().remove(entity.getId());
} }
public void removeEntity(GameEntity entity) { public void removeEntity(GameEntity entity) {
this.removeEntity(entity, VisionType.VISION_TYPE_DIE); this.removeEntity(entity, VisionType.VISION_TYPE_DIE);
} }
public synchronized void removeEntity(GameEntity entity, VisionType visionType) { public synchronized void removeEntity(GameEntity entity, VisionType visionType) {
GameEntity removed = this.removeEntityDirectly(entity); GameEntity removed = this.removeEntityDirectly(entity);
if (removed != null) { if (removed != null) {
...@@ -351,7 +351,7 @@ public class Scene { ...@@ -351,7 +351,7 @@ public class Scene {
public void showOtherEntities(Player player) { public void showOtherEntities(Player player) {
List<GameEntity> entities = new LinkedList<>(); List<GameEntity> entities = new LinkedList<>();
GameEntity currentEntity = player.getTeamManager().getCurrentAvatarEntity(); GameEntity currentEntity = player.getTeamManager().getCurrentAvatarEntity();
for (GameEntity entity : this.getEntities().values()) { for (GameEntity entity : this.getEntities().values()) {
if (entity == currentEntity) { if (entity == currentEntity) {
continue; continue;
...@@ -361,26 +361,26 @@ public class Scene { ...@@ -361,26 +361,26 @@ public class Scene {
player.sendPacket(new PacketSceneEntityAppearNotify(entities, VisionType.VISION_TYPE_MEET)); player.sendPacket(new PacketSceneEntityAppearNotify(entities, VisionType.VISION_TYPE_MEET));
} }
public void handleAttack(AttackResult result) { public void handleAttack(AttackResult result) {
//GameEntity attacker = getEntityById(result.getAttackerId()); //GameEntity attacker = getEntityById(result.getAttackerId());
GameEntity target = getEntityById(result.getDefenseId()); GameEntity target = getEntityById(result.getDefenseId());
if (target == null) { if (target == null) {
return; return;
} }
// Godmode check // Godmode check
if (target instanceof EntityAvatar) { if (target instanceof EntityAvatar) {
if (((EntityAvatar) target).getPlayer().inGodmode()) { if (((EntityAvatar) target).getPlayer().inGodmode()) {
return; return;
} }
} }
// Sanity check // Sanity check
target.damage(result.getDamage(), result.getAttackerId()); target.damage(result.getDamage(), result.getAttackerId());
} }
public void killEntity(GameEntity target, int attackerId) { public void killEntity(GameEntity target, int attackerId) {
GameEntity attacker = getEntityById(attackerId); GameEntity attacker = getEntityById(attackerId);
...@@ -404,7 +404,7 @@ public class Scene { ...@@ -404,7 +404,7 @@ public class Scene {
} }
this.removeEntity(target); this.removeEntity(target);
// Death event // Death event
target.onDeath(attackerId); target.onDeath(attackerId);
} }
...@@ -427,96 +427,102 @@ public class Scene { ...@@ -427,96 +427,102 @@ public class Scene {
challenge.onCheckTimeOut(); challenge.onCheckTimeOut();
} }
} }
public int getEntityLevel(int baseLevel, int worldLevelOverride) { public int getEntityLevel(int baseLevel, int worldLevelOverride) {
int level = worldLevelOverride > 0 ? worldLevelOverride + baseLevel - 22 : baseLevel; int level = worldLevelOverride > 0 ? worldLevelOverride + baseLevel - 22 : baseLevel;
level = level >= 100 ? 100 : level; level = level >= 100 ? 100 : level;
level = level <= 0 ? 1 : level; level = level <= 0 ? 1 : level;
return level; return level;
} }
// 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);
} }
} }
} }
// World level // World level
WorldLevelData worldLevelData = GameData.getWorldLevelDataMap().get(getWorld().getWorldLevel()); WorldLevelData worldLevelData = GameData.getWorldLevelDataMap().get(getWorld().getWorldLevel());
int worldLevelOverride = 0; int worldLevelOverride = 0;
if (worldLevelData != null) { if (worldLevelData != null) {
worldLevelOverride = worldLevelData.getMonsterLevel(); worldLevelOverride = worldLevelData.getMonsterLevel();
} }
// 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;
// Check if spawn entry is monster or gadget // Check if spawn entry is monster or gadget
if (entry.getMonsterId() > 0) { if (entry.getMonsterId() > 0) {
MonsterData data = GameData.getMonsterDataMap().get(entry.getMonsterId()); MonsterData data = GameData.getMonsterDataMap().get(entry.getMonsterId());
if (data == null) continue; if (data == null) continue;
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(), level);
monster.getRotation().set(entry.getRot()); 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());
monster.setSpawnEntry(entry); monster.setSpawnEntry(entry);
entity = monster; entity = monster;
} else if (entry.getGadgetId() > 0) { } else if (entry.getGadgetId() > 0) {
EntityGadget gadget = new EntityGadget(this, entry.getGadgetId(), entry.getPos(), entry.getRot()); EntityGadget gadget = new EntityGadget(this, entry.getGadgetId(), entry.getPos(), entry.getRot());
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);
gadget.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 99999); gadget.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 99999);
gadget.setFightProperty(FightProperty.FIGHT_PROP_MAX_HP, 99999); gadget.setFightProperty(FightProperty.FIGHT_PROP_MAX_HP, 99999);
entity = gadget; entity = gadget;
} }
if (entity == null) continue; if (entity == null) continue;
// 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);
} }
} }
if (toAdd.size() > 0) { if (toAdd.size() > 0) {
toAdd.stream().forEach(this::addEntityDirectly); toAdd.stream().forEach(this::addEntityDirectly);
this.broadcastPacket(new PacketSceneEntityAppearNotify(toAdd, VisionType.VISION_TYPE_BORN)); this.broadcastPacket(new PacketSceneEntityAppearNotify(toAdd, VisionType.VISION_TYPE_BORN));
...@@ -615,10 +621,10 @@ public class Scene { ...@@ -615,10 +621,10 @@ public class Scene {
if (group.init_config == null) { if (group.init_config == null) {
continue; continue;
} }
// Load garbages // Load garbages
List<SceneGadget> garbageGadgets = group.getGarbageGadgets(); List<SceneGadget> garbageGadgets = group.getGarbageGadgets();
if (garbageGadgets != null) { if (garbageGadgets != null) {
entities.addAll(garbageGadgets.stream().map(g -> scriptManager.createGadget(group.id, group.block_id, g)) entities.addAll(garbageGadgets.stream().map(g -> scriptManager.createGadget(group.id, group.block_id, g))
.filter(Objects::nonNull) .filter(Objects::nonNull)
...@@ -647,7 +653,7 @@ public class Scene { ...@@ -647,7 +653,7 @@ public class Scene {
//groups.forEach(g -> scriptManager.callEvent(EventType.EVENT_GROUP_LOAD, null)); //groups.forEach(g -> scriptManager.callEvent(EventType.EVENT_GROUP_LOAD, null));
Grasscutter.getLogger().info("Scene {} loaded {} group(s)", this.getId(), groups.size()); Grasscutter.getLogger().info("Scene {} loaded {} group(s)", this.getId(), groups.size());
} }
public void onUnloadBlock(SceneBlock block) { public void onUnloadBlock(SceneBlock block) {
List<GameEntity> toRemove = this.getEntities().values().stream() List<GameEntity> toRemove = this.getEntities().values().stream()
.filter(e -> e.getBlockId() == block.id).toList(); .filter(e -> e.getBlockId() == block.id).toList();
...@@ -669,53 +675,53 @@ public class Scene { ...@@ -669,53 +675,53 @@ public class Scene {
Grasscutter.getLogger().info("Scene {} Block {} is unloaded.", this.getId(), block.id); Grasscutter.getLogger().info("Scene {} Block {} is unloaded.", this.getId(), block.id);
} }
// Gadgets // Gadgets
public void onPlayerCreateGadget(EntityClientGadget gadget) { public void onPlayerCreateGadget(EntityClientGadget gadget) {
// Directly add // Directly add
this.addEntityDirectly(gadget); this.addEntityDirectly(gadget);
// Add to owner's gadget list // Add to owner's gadget list
gadget.getOwner().getTeamManager().getGadgets().add(gadget); gadget.getOwner().getTeamManager().getGadgets().add(gadget);
// Optimization // Optimization
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == gadget.getOwner()) { if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == gadget.getOwner()) {
return; return;
} }
this.broadcastPacketToOthers(gadget.getOwner(), new PacketSceneEntityAppearNotify(gadget)); this.broadcastPacketToOthers(gadget.getOwner(), new PacketSceneEntityAppearNotify(gadget));
} }
public void onPlayerDestroyGadget(int entityId) { public void onPlayerDestroyGadget(int entityId) {
GameEntity entity = getEntities().get(entityId); GameEntity entity = getEntities().get(entityId);
if (entity == null || !(entity instanceof EntityClientGadget)) { if (entity == null || !(entity instanceof EntityClientGadget)) {
return; return;
} }
// Get and remove entity // Get and remove entity
EntityClientGadget gadget = (EntityClientGadget) entity; EntityClientGadget gadget = (EntityClientGadget) entity;
this.removeEntityDirectly(gadget); this.removeEntityDirectly(gadget);
// Remove from owner's gadget list // Remove from owner's gadget list
gadget.getOwner().getTeamManager().getGadgets().remove(gadget); gadget.getOwner().getTeamManager().getGadgets().remove(gadget);
// Optimization // Optimization
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == gadget.getOwner()) { if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == gadget.getOwner()) {
return; return;
} }
this.broadcastPacketToOthers(gadget.getOwner(), new PacketSceneEntityDisappearNotify(gadget, VisionType.VISION_TYPE_DIE)); this.broadcastPacketToOthers(gadget.getOwner(), new PacketSceneEntityDisappearNotify(gadget, VisionType.VISION_TYPE_DIE));
} }
// Broadcasting // Broadcasting
public void broadcastPacket(BasePacket packet) { public void broadcastPacket(BasePacket packet) {
// Send to all players - might have to check if player has been sent data packets // Send to all players - might have to check if player has been sent data packets
for (Player player : this.getPlayers()) { for (Player player : this.getPlayers()) {
player.getSession().send(packet); player.getSession().send(packet);
} }
} }
public void broadcastPacketToOthers(Player excludedPlayer, BasePacket packet) { public void broadcastPacketToOthers(Player excludedPlayer, BasePacket packet) {
// Optimization // Optimization
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == excludedPlayer) { if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == excludedPlayer) {
......
...@@ -12,9 +12,10 @@ public class SpawnDataEntry { ...@@ -12,9 +12,10 @@ 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;
public SpawnGroupEntry getGroup() { public SpawnGroupEntry getGroup() {
return group; return group;
} }
...@@ -26,23 +27,27 @@ public class SpawnDataEntry { ...@@ -26,23 +27,27 @@ public class SpawnDataEntry {
public int getMonsterId() { public int getMonsterId() {
return monsterId; return monsterId;
} }
public int getGadgetId() { public int getGadgetId() {
return gadgetId; return gadgetId;
} }
public int getConfigId() { public int getGadgetState() {
return gadgetState;
}
public int getConfigId() {
return configId; return configId;
} }
public int getLevel() { public int getLevel() {
return level; return level;
} }
public int getPoseId() { public int getPoseId() {
return poseId; return poseId;
} }
public int getGatherItemId() { public int getGatherItemId() {
return gatherItemId; return gatherItemId;
} }
...@@ -50,18 +55,18 @@ public class SpawnDataEntry { ...@@ -50,18 +55,18 @@ public class SpawnDataEntry {
public Position getPos() { public Position getPos() {
return pos; return pos;
} }
public Position getRot() { public Position getRot() {
return rot; return rot;
} }
public static class SpawnGroupEntry { public static class SpawnGroupEntry {
private int sceneId; private int sceneId;
private int groupId; private int groupId;
private int blockId; private int blockId;
private Position pos; private Position pos;
private List<SpawnDataEntry> spawns; private List<SpawnDataEntry> spawns;
public int getSceneId() { public int getSceneId() {
return sceneId; return sceneId;
} }
......
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