Skip to content

Commit

Permalink
fix: HomeModuleManager isnt ticked unless player changes module (Gras…
Browse files Browse the repository at this point in the history
  • Loading branch information
hamusuke0323 authored Sep 16, 2023
1 parent c4dbb68 commit 5458d36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/main/java/emu/grasscutter/game/home/HomeModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public void refreshMainHouse() {
}

public void onUpdateArrangement() {
this.fireAllAvatarRewardEvent();
this.cancelSummonEventIfAvatarLeave();
this.fireAllAvatarRewardEvents();
this.cancelSummonEventsIfAvatarLeave();
}

private void fireAllAvatarRewardEvent() {
private void fireAllAvatarRewardEvents() {
this.rewardEvents.clear();
var allBlockItems =
Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem())
Expand Down Expand Up @@ -111,7 +111,7 @@ private void fireAllAvatarRewardEvent() {
}
}

private void cancelSummonEventIfAvatarLeave() {
private void cancelSummonEventsIfAvatarLeave() {
var avatars =
Stream.of(this.getOutdoorSceneItem(), this.getIndoorSceneItem())
.map(HomeSceneItem::getBlockItems)
Expand Down Expand Up @@ -225,10 +225,14 @@ public void onSetModule() {

this.outdoor.addEntities(this.getOutdoorSceneItem().getAnimals(this.outdoor));
this.indoor.addEntities(this.getIndoorSceneItem().getAnimals(this.indoor));
this.fireAllAvatarRewardEvent();
this.fireAllAvatarRewardEvents();
}

public void onRemovedModule() {
if (this.moduleId == 0) {
return;
}

this.outdoor.getEntities().clear();
this.indoor.getEntities().clear();
}
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/emu/grasscutter/game/home/HomeWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import emu.grasscutter.server.packet.send.PacketDelTeamEntityNotify;
import emu.grasscutter.server.packet.send.PacketPlayerChatNotify;
import emu.grasscutter.server.packet.send.PacketPlayerGameTimeNotify;
import lombok.Getter;

import java.util.List;
import java.util.function.Consumer;
import lombok.Getter;

@Getter
public class HomeWorld extends World {
@Getter private final GameHome home;
@Getter private HomeModuleManager moduleManager;
private final GameHome home;
private HomeModuleManager moduleManager;

public HomeWorld(GameServer server, Player owner) {
super(server, owner);
Expand Down Expand Up @@ -60,7 +62,11 @@ public int getActiveOutdoorSceneId() {
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex
HomeChooseModuleReqOuterClass.HomeChooseModuleReq.parseFrom(payload);
session.getPlayer().addRealmList(req.getModuleId());
session.getPlayer().setCurrentRealmId(req.getModuleId());
session.getPlayer().getCurHomeWorld().refreshModuleManager();
session.send(new PacketHomeChooseModuleRsp(req.getModuleId()));
session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer()));
session.send(new PacketHomeComfortInfoNotify(session.getPlayer()));
Expand Down

0 comments on commit 5458d36

Please sign in to comment.