Skip to content

Field Player Spawn Point Trigger - #359

Merged
AngeloTadeucci merged 3 commits into
MS2Community:masterfrom
Zintixx:dungeons
Mar 11, 2025
Merged

Field Player Spawn Point Trigger#359
AngeloTadeucci merged 3 commits into
MS2Community:masterfrom
Zintixx:dungeons

Conversation

@Zintixx

@Zintixx Zintixx commented Mar 11, 2025

Copy link
Copy Markdown
Collaborator
  • Enable/Disable player spawn points by triggers
  • Fixes Region Spawns, mobs should be spawning once more.

Summary by CodeRabbit

  • New Features

    • Introduced a new command to display all spawn points in the current map.
    • Enhanced player spawn point management with new retrieval methods for better organization.
  • Bug Fixes

    • Improved error logging for invalid spawn point IDs.
  • Refactor

    • Removed legacy structures related to Ms2RegionBoxSpawn for a cleaner data model.
    • Simplified the initialization process for player spawn points within the game field.
    • Updated timer display handling in the trigger context.

@coderabbitai

coderabbitai Bot commented Mar 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes remove support for the Ms2RegionBoxSpawn entity by eliminating its dedicated dictionary, JSON serialization attribute, mapping case, record declaration, and associated metadata property. Additionally, a new SpawnPointsCommand is added to FieldCommand to display spawn point information. FieldManager now initializes and manages player spawn points through a new dictionary and retrieval method. Minor modifications include adjustments in logging, opacity calculation in trigger methods, and type handling in region spawn processing.

Changes

File(s) Change Summary
Maple2.Database/.../MapEntityStorage.cs, Maple2.File.Ingest/.../MapEntityMapper.cs, Maple2.Model/Metadata/MapEntity/MapEntity.cs, Maple2.Model/Metadata/MapEntity/Ms2RegionBoxSpawn.cs, Maple2.Model/Metadata/MapEntityMetadata.cs Removed Ms2RegionBoxSpawn support: eliminated dictionary storage, JSON derived type, mapping case, record definition, and metadata property.
Maple2.Server.Game/.../FieldCommand.cs Added new SpawnPointsCommand; updated FieldCommand constructor to include MapEntityStorage for spawn point display.
Maple2.Server.Game/Manager/Field/FieldManager.State.cs, Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs Enhanced FieldManager: introduced fieldPlayerSpawnPoints dictionary, changed spawn source from box to region, and added the TryGetPlayerSpawn method.
Maple2.Server.Game/Model/Field/Entity/FieldPlayerSpawnPoint.cs Introduced new FieldPlayerSpawnPoint class for managing player spawn data.
Maple2.Server.Game/Trigger/TriggerContext.Field.cs, Maple2.Server.Game/Trigger/TriggerContext.Player.cs Modified trigger context methods: updated opacity calculation and logging in spawn point enablement, adding spawn point validation via Field.TryGetPlayerSpawn.

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
Loading
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)
Loading

Possibly related PRs

  • Bug fixes #329: The changes in the main PR, which involve the removal of case handling for Ms2RegionBoxSpawn in the Get method of MapEntityStorage, are related to the changes in the retrieved PR that also involve the removal of handling for IMS2RegionBoxSpawn in the ParseMap method of MapEntityMapper, as both modifications affect the processing of the same entity type.

Suggested reviewers

  • AngeloTadeucci

Poem

Hoppin’ through the lines of code, I say,
Removing spawns in a clever way.
A command to show the points so bright,
Code now leaps from day to night.
A rabbit’s cheer in ASCII art – pure delight!
Hop on, dear code, and keep it light!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15a8af0 and d03a5d6.

📒 Files selected for processing (2)
  • Maple2.Server.Game/Trigger/TriggerContext.Field.cs (1 hunks)
  • Maple2.Server.Game/Trigger/TriggerContext.Field.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • Maple2.Server.Game/Trigger/TriggerContext.Field.cs
  • Maple2.Server.Game/Trigger/TriggerContext.Field.cs
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: format
  • GitHub Check: build

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4722a24 and 119caab.

📒 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:

  1. This change is intentional
  2. All dependent systems expecting the previous opacity behavior have been updated
  3. 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 management

The new fieldPlayerSpawnPoints field 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 collection

The code now correctly uses the new fieldPlayerSpawnPoints dictionary instead of directly accessing Entities.PlayerSpawns.Values. This change maintains consistency with the new spawn point management approach.


384-385: Fixed region spawns by using the correct collection type

The code now correctly checks Entities.RegionSpawns instead of Entities.BoxRegionSpawns and uses the appropriate type (Ms2RegionSpawn? instead of Ms2RegionBoxSpawn?). This addresses the region spawn issue mentioned in the PR objectives.


747-747: Simplified function call by removing unnecessary conversion

Removed 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 points

The new FieldPlayerSpawnPoint class follows the established entity pattern and provides the necessary functionality to support enabling/disabling spawn points. The Enable property 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 handling

The implementation has been enhanced with several important improvements:

  1. Replaced ErrorLog with DebugLog for better diagnostics
  2. Added validation to check if the spawn point exists
  3. Added proper error logging with context information
  4. Implemented the actual toggling of the spawn point's Enable property

This 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 points

The new initialization code correctly populates the fieldPlayerSpawnPoints dictionary by creating a FieldPlayerSpawnPoint instance for each entry in Entities.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 points

The new TryGetPlayerSpawn method 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.Metadata is necessary for accessing the MapEntityMetadata types needed by the new SpawnPointsCommand.


17-17: Good addition of required field.

The addition of the mapEntities field 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.

@AngeloTadeucci
AngeloTadeucci merged commit 1204b6a into MS2Community:master Mar 11, 2025
@Zintixx
Zintixx deleted the dungeons branch March 11, 2025 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants