[Activity] Added onLoadScene function to ActivityHandler to register dynamic groups when a scene is loaded

This commit is contained in:
hartie95 2024-03-31 01:42:26 +01:00
parent 1119b3761a
commit 3eedd5087b
8 changed files with 78 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import emu.grasscutter.game.activity.condition.ActivityConditionExecutor;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.WatcherTriggerType;
import emu.grasscutter.game.quest.enums.QuestCond;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.utils.DateHelper;
import lombok.AccessLevel;
import lombok.Getter;
@ -30,8 +31,9 @@ public abstract class ActivityHandler {
@Getter ActivityData activityData;
Map<WatcherTriggerType, List<ActivityWatcher>> watchersMap = new HashMap<>();
abstract public void onProtoBuild(PlayerActivityData playerActivityData, ActivityInfo activityInfo);
abstract public void onInitPlayerActivityData(PlayerActivityData playerActivityData);
public abstract void onProtoBuild(PlayerActivityData playerActivityData, ActivityInfo activityInfo);
public abstract void onInitPlayerActivityData(PlayerActivityData playerActivityData);
public abstract void onLoadScene(Scene scene, Player player, ActivityConfigItem activityInfo);
public void initWatchers(Map<WatcherTriggerType, ConstructorAccess<?>> activityWatcherTypeMap){
activityData = GameData.getActivityDataMap().get(activityConfigItem.getActivityId());

View File

@ -9,6 +9,7 @@ import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActivityType;
import emu.grasscutter.game.props.WatcherTriggerType;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.server.packet.send.PacketActivityScheduleInfoNotify;
import lombok.Getter;
import lombok.val;
@ -213,4 +214,12 @@ public class ActivityManager extends BasePlayerManager {
.toList();
}
public void triggerSceneLoadForActiveActivity(Scene scene){
getActiveActivityIds().forEach(activityId -> {
val activityConfig = activityConfigItemMap.get(activityId);
val activityHandler = activityConfig.getActivityHandler();
activityHandler.onLoadScene(scene, player, activityConfig);
});
}
}

View File

@ -1,6 +1,8 @@
package emu.grasscutter.game.activity;
import emu.grasscutter.game.props.ActivityType;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.Scene;
import messages.activity.ActivityInfo;
@GameActivity(ActivityType.NONE)
@ -14,4 +16,9 @@ public class DefaultActivityHandler extends ActivityHandler{
public void onInitPlayerActivityData(PlayerActivityData playerActivityData) {
}
@Override
public void onLoadScene(Scene scene, Player player, ActivityConfigItem activityInfo) {
}
}

View File

@ -1,15 +1,20 @@
package emu.grasscutter.game.activity.aster;
import emu.grasscutter.data.GameData;
import emu.grasscutter.game.activity.ActivityConfigItem;
import emu.grasscutter.game.activity.ActivityHandler;
import emu.grasscutter.game.activity.GameActivity;
import emu.grasscutter.game.activity.PlayerActivityData;
import emu.grasscutter.game.props.ActivityType;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.server.packet.send.*;
import lombok.val;
import messages.activity.ActivityInfo;
import messages.activity.aster.*;
import messages.general.Vector;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -68,4 +73,38 @@ public class AsterActivityHandler extends ActivityHandler {
}
@Override
public void onLoadScene(Scene scene, Player player, ActivityConfigItem activityInfo) {
if(scene.getId() != 3){
return;
}
val groups = List.of(302001001,
302001002,
302001003,
302001004,
302001005,
302001006,
302001007,
302001008,
302001009,
302001010,
302001011,
302001012,
302001013,
302001014,
302001015,
302001016,
302001017,
302001018,
302001019,
302001041,
302001042,
302001043,
302001144,
302001901,
302001902,
302001903,
302001904);
groups.forEach(scene::loadDynamicGroup);
}
}

View File

@ -1,9 +1,12 @@
package emu.grasscutter.game.activity.musicgame;
import emu.grasscutter.game.activity.ActivityConfigItem;
import emu.grasscutter.game.activity.ActivityHandler;
import emu.grasscutter.game.activity.GameActivity;
import emu.grasscutter.game.activity.PlayerActivityData;
import emu.grasscutter.game.props.ActivityType;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.utils.JsonUtils;
import lombok.val;
import messages.activity.ActivityInfo;
@ -91,4 +94,9 @@ public class MusicGameActivityHandler extends ActivityHandler {
playerActivityData.setDetail(musicGamePlayerData);
playerActivityData.save();
}
@Override
public void onLoadScene(Scene scene, Player player, ActivityConfigItem activityInfo) {
}
}

View File

@ -5,8 +5,7 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.ActivityWatcherData;
import emu.grasscutter.data.excels.TrialAvatarActivityDataData;
import emu.grasscutter.game.activity.ActivityWatcher;
import emu.grasscutter.game.activity.DefaultWatcher;
import emu.grasscutter.game.activity.*;
import emu.grasscutter.game.dungeons.settle_listeners.TrialAvatarDungeonSettleListener;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason;
@ -15,6 +14,7 @@ import emu.grasscutter.game.activity.ActivityHandler;
import emu.grasscutter.game.activity.GameActivity;
import emu.grasscutter.game.activity.PlayerActivityData;
import emu.grasscutter.game.props.ActivityType;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.server.packet.send.PacketActivityInfoNotify;
import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify;
import emu.grasscutter.utils.JsonUtils;
@ -128,4 +128,9 @@ public class TrialAvatarActivityHandler extends ActivityHandler {
toProto(playerActivityData, player.getActivityManager().getConditionExecutor())
));
}
@Override
public void onLoadScene(Scene scene, Player player, ActivityConfigItem activityInfo) {
}
}

View File

@ -1341,6 +1341,8 @@ public class Player {
}
*/
// Activity needed for some quests
activityManager = new ActivityManager(this);
// Create world
World world = new World(this);
world.addPlayer(this);
@ -1352,8 +1354,6 @@ public class Player {
// Execute daily reset logic if this is a new day.
this.doDailyReset();
// Activity needed for some quests
activityManager = new ActivityManager(this);
// Rewind active quests, and put the player to a rewind position it finds (if any) of an active quest
getQuestManager().onLogin();

View File

@ -106,6 +106,8 @@ public class Scene {
this.startWorldTime = world.getWorldTime();
this.scriptManager = new SceneScriptManager(this);
getWorld().getHost().getActivityManager().triggerSceneLoadForActiveActivity(this);
//Create scene entity
this.sceneEntity = new EntityScene(this);