Field Player Spawn Point Trigger - #359
Conversation
WalkthroughThe changes remove support for the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User/GameSession
participant FC as FieldCommand
participant SPC as SpawnPointsCommand
participant MS as MapMetadataStorage
participant ME as MapEntityStorage
U->>FC: Execute spawn points command
FC->>SPC: Invoke SpawnPointsCommand
SPC->>MS: Request map metadata
MS-->>SPC: Return metadata
SPC->>ME: Retrieve MapEntityMetadata
ME-->>SPC: Return spawn data
SPC->>U: Output spawn point details
sequenceDiagram
participant FM as FieldManager
participant ES as Entities.PlayerSpawns
participant FP as FieldPlayerSpawnPoint
participant D as fieldPlayerSpawnPoints
FM->>ES: Iterate over player spawns
ES-->>FM: Provide spawn data
FM->>FP: Create FieldPlayerSpawnPoint instance
FP-->>FM: Return new spawn point
FM->>D: Add spawn point to dictionary
Note over FM, D: Later lookup via TryGetPlayerSpawn
FM->>D: Lookup spawn point by ID
D-->>FM: Return spawn point (if exists)
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
Maple2.Server.Game/Commands/FieldCommand.cs (1)
73-110: Well-implemented SpawnPointsCommand.The SpawnPointsCommand is well-structured and follows the established pattern of other commands in this file. It includes proper error handling and clearly displays information about spawn points.
A minor enhancement could be to indicate spawn points that exist in metadata but aren't currently active in the field, providing more comprehensive information to users.
Consider modifying the loop to also show spawn points that exist in metadata but aren't in the field:
foreach ((int id, SpawnPointPC spawnPoint) in mapEntityMetadata.PlayerSpawns) { if (session.Field.TryGetPlayerSpawn(id, out FieldPlayerSpawnPoint? fieldPlayerSpawnPoint)) { ctx.Console.Out.WriteLine($"Id: {id}, Position: {spawnPoint.Position}. Enabled: {fieldPlayerSpawnPoint.Enable}"); + } else { + ctx.Console.Out.WriteLine($"Id: {id}, Position: {spawnPoint.Position}. Not active in field."); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
Maple2.Database/Storage/Metadata/MapEntityStorage.cs(0 hunks)Maple2.File.Ingest/Mapper/MapEntityMapper.cs(0 hunks)Maple2.Model/Metadata/MapEntity/MapEntity.cs(0 hunks)Maple2.Model/Metadata/MapEntity/Ms2RegionBoxSpawn.cs(0 hunks)Maple2.Model/Metadata/MapEntityMetadata.cs(0 hunks)Maple2.Server.Game/Commands/FieldCommand.cs(3 hunks)Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.State.cs(4 hunks)Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs(2 hunks)Maple2.Server.Game/Model/Field/Entity/FieldPlayerSpawnPoint.cs(1 hunks)Maple2.Server.Game/Trigger/TriggerContext.Field.cs(1 hunks)Maple2.Server.Game/Trigger/TriggerContext.Player.cs(1 hunks)
💤 Files with no reviewable changes (5)
- Maple2.Model/Metadata/MapEntity/Ms2RegionBoxSpawn.cs
- Maple2.Model/Metadata/MapEntity/MapEntity.cs
- Maple2.File.Ingest/Mapper/MapEntityMapper.cs
- Maple2.Model/Metadata/MapEntityMetadata.cs
- Maple2.Database/Storage/Metadata/MapEntityStorage.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: build
- GitHub Check: format
🔇 Additional comments (13)
Maple2.Server.Game/Trigger/TriggerContext.Field.cs (1)
89-89: Significant change in opacity calculation logic.The opacity calculation has been inverted from the previous implementation. Previously, opacity was calculated as
(byte)(100 - border), making it inversely proportional to the border value. Now, it's directly assigned to the border value. This change reverses the relationship between border values and visual opacity effects.Please verify that:
- This change is intentional
- All dependent systems expecting the previous opacity behavior have been updated
- This change integrates correctly with the new player spawn point functionality introduced in this PR
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.State.cs (4)
41-41: Added field for player spawn point managementThe new
fieldPlayerSpawnPointsfield provides a dedicated collection to manage player spawn points, which will help enable the spawn point trigger functionality described in the PR.
85-85: Updated spawn player logic to use the new fieldPlayerSpawnPoints collectionThe code now correctly uses the new
fieldPlayerSpawnPointsdictionary instead of directly accessingEntities.PlayerSpawns.Values. This change maintains consistency with the new spawn point management approach.
384-385: Fixed region spawns by using the correct collection typeThe code now correctly checks
Entities.RegionSpawnsinstead ofEntities.BoxRegionSpawnsand uses the appropriate type (Ms2RegionSpawn?instead ofMs2RegionBoxSpawn?). This addresses the region spawn issue mentioned in the PR objectives.
747-747: Simplified function call by removing unnecessary conversionRemoved the conversion to a list when calling
FunctionCubePacket.SendCubes, which is a small but worthwhile optimization.Maple2.Server.Game/Model/Field/Entity/FieldPlayerSpawnPoint.cs (1)
1-14: Well-structured new class for managing player spawn pointsThe new
FieldPlayerSpawnPointclass follows the established entity pattern and provides the necessary functionality to support enabling/disabling spawn points. TheEnableproperty is correctly initialized from the metadata and will be manipulated by triggers.Maple2.Server.Game/Trigger/TriggerContext.Player.cs (1)
14-20: Improved spawn point trigger implementation with proper error handlingThe implementation has been enhanced with several important improvements:
- Replaced
ErrorLogwithDebugLogfor better diagnostics- Added validation to check if the spawn point exists
- Added proper error logging with context information
- Implemented the actual toggling of the spawn point's
EnablepropertyThis provides robust handling of player spawn point triggers as outlined in the PR objectives.
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (2)
155-157: Added initialization for player spawn pointsThe new initialization code correctly populates the
fieldPlayerSpawnPointsdictionary by creating aFieldPlayerSpawnPointinstance for each entry inEntities.PlayerSpawns. This ensures that all player spawn points are properly set up when the field manager is initialized.
354-356: Added method to retrieve player spawn pointsThe new
TryGetPlayerSpawnmethod provides a clean way to access player spawn points by ID. This method is used by the trigger system to enable/disable spawn points, fulfilling the main goal of the PR.Maple2.Server.Game/Commands/FieldCommand.cs (4)
5-5: Appropriate import addition.The new import for
Maple2.Model.Metadatais necessary for accessing the MapEntityMetadata types needed by the new SpawnPointsCommand.
17-17: Good addition of required field.The addition of the
mapEntitiesfield is necessary to store the new constructor parameter and make it accessible to the SpawnPointsCommand.
19-19: Constructor properly updated.The constructor signature has been correctly updated to include the new MapEntityStorage parameter, and the field is properly initialized.
Also applies to: 22-22
25-25: Command registration looks good.The new SpawnPointsCommand is properly registered with the correct parameters.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Ms2RegionBoxSpawnfor a cleaner data model.