fix: HomeModuleManager isnt ticked unless player changes module (#2365)

This commit is contained in:
hamusuke 2023-09-16 09:51:16 +09:00 committed by GitHub
parent c4dbb6851b
commit 5458d36102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -59,11 +59,11 @@ public class HomeModuleManager {
} }
public void onUpdateArrangement() { public void onUpdateArrangement() {
this.fireAllAvatarRewardEvent(); this.fireAllAvatarRewardEvents();
this.cancelSummonEventIfAvatarLeave(); this.cancelSummonEventsIfAvatarLeave();
} }
private void fireAllAvatarRewardEvent() { private void fireAllAvatarRewardEvents() {
this.rewardEvents.clear(); this.rewardEvents.clear();
var allBlockItems = var allBlockItems =
Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem()) Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem())
@ -111,7 +111,7 @@ public class HomeModuleManager {
} }
} }
private void cancelSummonEventIfAvatarLeave() { private void cancelSummonEventsIfAvatarLeave() {
var avatars = var avatars =
Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem()) Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem())
.map(HomeSceneItem::getBlockItems) .map(HomeSceneItem::getBlockItems)
@ -225,10 +225,14 @@ public class HomeModuleManager {
this.outdoor.addEntities(this.getOutdoorSceneItem().getAnimals(this.outdoor)); this.outdoor.addEntities(this.getOutdoorSceneItem().getAnimals(this.outdoor));
this.indoor.addEntities(this.getIndoorSceneItem().getAnimals(this.indoor)); this.indoor.addEntities(this.getIndoorSceneItem().getAnimals(this.indoor));
this.fireAllAvatarRewardEvent(); this.fireAllAvatarRewardEvents();
} }
public void onRemovedModule() { public void onRemovedModule() {
if (this.moduleId == 0) {
return;
}
this.outdoor.getEntities().clear(); this.outdoor.getEntities().clear();
this.indoor.getEntities().clear(); this.indoor.getEntities().clear();
} }

View File

@ -11,13 +11,15 @@ import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.packet.send.PacketDelTeamEntityNotify; import emu.grasscutter.server.packet.send.PacketDelTeamEntityNotify;
import emu.grasscutter.server.packet.send.PacketPlayerChatNotify; import emu.grasscutter.server.packet.send.PacketPlayerChatNotify;
import emu.grasscutter.server.packet.send.PacketPlayerGameTimeNotify; import emu.grasscutter.server.packet.send.PacketPlayerGameTimeNotify;
import java.util.List;
import java.util.function.Consumer;
import lombok.Getter; import lombok.Getter;
import java.util.List;
import java.util.function.Consumer;
@Getter
public class HomeWorld extends World { public class HomeWorld extends World {
@Getter private final GameHome home; private final GameHome home;
@Getter private HomeModuleManager moduleManager; private HomeModuleManager moduleManager;
public HomeWorld(GameServer server, Player owner) { public HomeWorld(GameServer server, Player owner) {
super(server, owner); super(server, owner);
@ -60,7 +62,11 @@ public class HomeWorld extends World {
} }
public int getActiveIndoorSceneId() { public int getActiveIndoorSceneId() {
return this.getSceneById(this.getActiveOutdoorSceneId()).getSceneItem().getRoomSceneId(); return this.isRealmIdValid() ? this.getSceneById(this.getActiveOutdoorSceneId()).getSceneItem().getRoomSceneId() : -1;
}
public boolean isRealmIdValid() {
return this.getHost().getCurrentRealmId() > 0;
} }
@Override @Override

View File

@ -14,6 +14,7 @@ public class HandlerHomeChooseModuleReq extends PacketHandler {
HomeChooseModuleReqOuterClass.HomeChooseModuleReq.parseFrom(payload); HomeChooseModuleReqOuterClass.HomeChooseModuleReq.parseFrom(payload);
session.getPlayer().addRealmList(req.getModuleId()); session.getPlayer().addRealmList(req.getModuleId());
session.getPlayer().setCurrentRealmId(req.getModuleId()); session.getPlayer().setCurrentRealmId(req.getModuleId());
session.getPlayer().getCurHomeWorld().refreshModuleManager();
session.send(new PacketHomeChooseModuleRsp(req.getModuleId())); session.send(new PacketHomeChooseModuleRsp(req.getModuleId()));
session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer())); session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer()));
session.send(new PacketHomeComfortInfoNotify(session.getPlayer())); session.send(new PacketHomeComfortInfoNotify(session.getPlayer()));