Skip to content

Adjust Field Instancing & Vibrate Cubes - #431

Merged
AngeloTadeucci merged 3 commits into
masterfrom
instance-changes
Apr 28, 2025
Merged

Adjust Field Instancing & Vibrate Cubes#431
AngeloTadeucci merged 3 commits into
masterfrom
instance-changes

Conversation

@Zintixx

@Zintixx Zintixx commented Apr 28, 2025

Copy link
Copy Markdown
Collaborator
  • If Instance map is channelScale type, allow for others to also join first available field (This allows for event maps not to be solo instances)
  • Adjust Vibrate cubes to only vibrate from region skills if they have BrokenOffense > 0
  • Fixed healing spots not applying buffs.

Summary by CodeRabbit

  • New Features

    • Added support for new vibration entity properties, including BreakDefense and BreakTick, which are now tracked and persisted.
    • Introduced a method to retrieve vibration entities by their ID.
  • Improvements

    • Enhanced field selection and creation logic to better handle new instance types and concurrency.
    • Updated skill targeting to support a new RegionBuff type.
    • Improved vibration and breakage handling during skill and damage interactions.
  • Bug Fixes

    • Corrected player state when lifting objects to ensure battle status is set appropriately.
  • Refactor

    • Renamed an enum member for clarity.
    • Refactored FieldActor to inherit from a base actor class and updated its constructor.
    • Streamlined skill and damage handling for vibration effects and network packets.
  • Chores

    • Removed unused variables and cleaned up code for maintainability.

@coderabbitai

coderabbitai Bot commented Apr 28, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This update introduces several changes across the codebase. It adds BreakDefense and BreakTick properties to FieldVibrateEntity, updating their serialization, deserialization, and usage in map data parsing. The FieldActor class is refactored to inherit from a generic Actor base class, updating its constructor and property overrides. The ApplyTargetType enum member Player3 is renamed to RegionBuff, and corresponding logic is added for this target type in the FieldManager. The control flow for field retrieval and creation is refined in the FieldManager.Factory class. Vibration logic is updated to use DamageRecord instead of SkillRecord, with corresponding changes in packet handling and broadcasting. Minor cleanups and property initializations are also included.

Changes

File(s) Change Summary
Maple2.Model/Metadata/FieldEntity/FieldEntity.cs Added BreakDefense and BreakTick integer properties to FieldVibrateEntity record.
Maple2.Model/Game/Field/FieldAccelerationStructure.cs Added GetVibrateEntity(string) method; updated entity construction, serialization, and deserialization to include BreakDefense and BreakTick.
Maple2.File.Ingest/Mapper/MapDataMapper.cs Set BreakDefense and BreakTick properties when constructing FieldVibrateEntity in ParseMapEntities.
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.Factory.cs Refined logic in GetInternal for field selection/creation, added handling for channelScale instance type, simplified helper function.
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.State.cs Added case for ApplyTargetType.RegionBuff in GetTargets method.
Maple2.Model/Enum/Skill.cs Renamed enum member Player3 to RegionBuff in ApplyTargetType.
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs Updated FieldActor instantiation, initialized FieldTick in Init, changed VibrateObjects to use DamageRecord and new vibration logic.
Maple2.Server.Game/Model/Field/Actor/FieldActor.cs Refactored to inherit from Actor<MapMetadata>, removed ObjectId, updated constructor and property overrides.
Maple2.Server.Game/Model/Field/Entity/FieldSkill.cs Changed call to Field.VibrateObjects to use DamageRecord instead of SkillRecord.
Maple2.Server.Game/PacketHandlers/VibrateHandler.cs Switched from creating new SkillRecord to retrieving existing one, now constructs DamageRecord for vibration, added logic for BreakDefense comparison.
Maple2.Server.Game/Packets/VibratePacket.cs Changed Attack method to accept DamageRecord instead of SkillRecord and updated field accesses accordingly.
Maple2.Server.Game/PacketHandlers/RequestCubeHandler.cs Set player.InBattle = true after handling lift-up object event.
Maple2.File.Ingest/Mapper/ItemMapper.cs Removed unused local variable itemExtractionData.
Maple2.Server.Game/Manager/Config/BuffManager.cs Added removal of buffs with zero or negative stack count during stack modification to avoid broadcasting invalid buffs.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant FieldManager
    participant FieldAccelerationStructure

    Client->>Server: Send Vibrate Request (with skill UID, entity ID)
    Server->>FieldManager: Retrieve SkillRecord by UID
    Server->>FieldManager: Construct DamageRecord from SkillRecord
    Server->>FieldAccelerationStructure: GetVibrateEntity(entityId)
    alt BreakDefense logic
        FieldAccelerationStructure-->>Server: Return FieldVibrateEntity
        Server->>Server: Compare BreakDefense with BrokenOffence
        Note right of Server: (TODO: Track broken state/respawn)
    end
    Server->>Client: Broadcast VibratePacket with DamageRecord
Loading

Possibly related PRs

  • AngeloTadeucci/Maple2#399: Refines GetInternal logic in FieldManager.Factory.cs for field selection/creation, similar to changes in this PR.
  • AngeloTadeucci/Maple2#243: Modifies field retrieval/creation logic in FieldManager.Factory.cs, directly related to instance management changes here.
  • AngeloTadeucci/Maple2#427: Involves changes to buff handling and ApplyTargetType enums, related to the addition of RegionBuff handling in this PR.

Suggested reviewers

  • AngeloTadeucci

Poem

A bunny hops through fields anew,
With break and tick, vibrations grew.
Actors now inherit lore,
Buffs and targets—so much more!
Fields refined, enums renamed,
Packets dance as skills are tamed.
In code we trust, the carrots bloom—
Another patch, a brighter room! 🥕


📜 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 34fe0b4 and 8290377.

📒 Files selected for processing (1)
  • Maple2.Server.Game/Manager/Config/BuffManager.cs (1 hunks)
🔇 Additional comments (1)
Maple2.Server.Game/Manager/Config/BuffManager.cs (1)

356-359: Good improvement for buff management.

This additional check ensures that buffs with zero or negative stack counts are properly removed rather than lingering with invalid state. This prevents potential inconsistencies between client and server buff states and avoids unnecessary network traffic by skipping broadcast updates for removed buffs.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 generate sequence diagram to generate a sequence diagram of the changes in 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: 3

🧹 Nitpick comments (6)
Maple2.File.Ingest/Mapper/MapDataMapper.cs (1)

138-147:

Details

❓ Verification inconclusive

Potential naming inconsistency between brokenDefence and BreakDefense.

IMS2Vibrate exposes brokenDefence (British spelling), but the downstream field record is named BreakDefense (US spelling).
If both spellings intentionally map the same concept that is fine; otherwise a typo in either the interface or the record could silently propagate incorrect data.


🏁 Script executed:

#!/usr/bin/env bash
# Verify property spellings across the codebase.
rg -n 'brokenDefence'
rg -n 'BreakDefense'

Length of output: 1035


Check British vs US spelling in brokenDefence → BreakDefense mapping
I see vibrate.brokenDefence (British spelling) is mapped to the US-spelled BreakDefense. If the upstream contract intentionally uses British spelling and you’re standardizing to US in your entity, that’s fine; otherwise consider aligning the spelling to avoid confusion.

  • File: Maple2.File.Ingest/Mapper/MapDataMapper.cs: line 144
Maple2.Server.Game/Model/Field/Actor/FieldActor.cs (1)

16-42: Avoid reallocating Transform & generate one PointPrism instance per actor.

  1. base(field, objectId, mapMetadata, npcMetadata) most likely already initialises Transform. Re-assigning a brand-new Transform() drops any data the base ctor prepared (e.g., position passed through parameters), and may break reference equality relied on elsewhere.

  2. Shape => new PointPrism(Position) allocates a fresh object on every call. If Shape is accessed from hot code (e.g., collision queries), consider caching the prism and updating its centre when Position mutates.

-        Transform = new Transform();
+        // Re-use the Transform created by the base Actor constructor
+        // (if the base does not create one, keep the assignment as is).

Optionally memoise the prism:

private readonly PointPrism prism = new(default);

public override IPrism Shape {
    get {
        prism.Position = Position;
        return prism;
    }
}
Maple2.Server.Game/PacketHandlers/VibrateHandler.cs (2)

24-30: motionPoint / attackPoint currently read but ignored

If these fields are trusted inputs (e.g., combo-step or damage-table lookup), silently discarding them opens the door for desync or soft-cheat scenarios.
Either (a) validate and persist them (see previous diff) or (b) remove the reads to avoid dead code.


52-56: TODO left behind – break-state tracking still missing

The comparison against BreakDefense is in place but no state change is recorded. Until implemented, cubes with low break-defense can never enter a “broken” state, despite meeting the condition.
Please implement or create a follow-up task to avoid logical dead ends.

Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.Factory.cs (1)

387-392: Non-instance maps choose the first field without health check

The same disposed-field issue exists here. Re-use the safety filter:

-                FieldManager? firstField = mapFields.Values.FirstOrDefault();
+                FieldManager? firstField = mapFields.Values
+                                                .FirstOrDefault(f => !f.Disposed);

Optionally, sort by Players.Count to balance capacity.

Maple2.Model/Game/Field/FieldAccelerationStructure.cs (1)

277-279: Linear search in GetVibrateEntity may not scale

FirstOrDefault is O(N); a busy map can host thousands of vibrate entities.
Storing a Dictionary<string, FieldVibrateEntity> keyed by Id.Id (populated together with vibrateEntities) would reduce look-ups to O(1) and avoid frame spikes when skills hit multiple cubes in quick succession.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b22bce6 and 0bd2f74.

📒 Files selected for processing (13)
  • Maple2.File.Ingest/Mapper/ItemMapper.cs (0 hunks)
  • Maple2.File.Ingest/Mapper/MapDataMapper.cs (1 hunks)
  • Maple2.Model/Enum/Skill.cs (1 hunks)
  • Maple2.Model/Game/Field/FieldAccelerationStructure.cs (5 hunks)
  • Maple2.Model/Metadata/FieldEntity/FieldEntity.cs (1 hunks)
  • Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.Factory.cs (3 hunks)
  • Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.State.cs (1 hunks)
  • Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (3 hunks)
  • Maple2.Server.Game/Model/Field/Actor/FieldActor.cs (2 hunks)
  • Maple2.Server.Game/Model/Field/Entity/FieldSkill.cs (2 hunks)
  • Maple2.Server.Game/PacketHandlers/RequestCubeHandler.cs (1 hunks)
  • Maple2.Server.Game/PacketHandlers/VibrateHandler.cs (2 hunks)
  • Maple2.Server.Game/Packets/VibratePacket.cs (1 hunks)
💤 Files with no reviewable changes (1)
  • Maple2.File.Ingest/Mapper/ItemMapper.cs
🧰 Additional context used
🧬 Code Graph Analysis (5)
Maple2.Server.Game/PacketHandlers/RequestCubeHandler.cs (2)
Maple2.Database/Storage/Game/GameStorage.User.cs (1)
  • Player (196-264)
Maple2.Model/Game/User/Player.cs (2)
  • Player (8-22)
  • Player (17-21)
Maple2.Server.Game/Model/Field/Entity/FieldSkill.cs (1)
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (1)
  • VibrateObjects (574-592)
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.Factory.cs (2)
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (2)
  • FieldManager (33-661)
  • FieldManager (85-110)
Maple2.Server.Game/GameServer.cs (1)
  • FieldManager (101-103)
Maple2.Model/Game/Field/FieldAccelerationStructure.cs (1)
Maple2.Server.Core/Helpers/DebugByteWriter.cs (1)
  • WriteInt (70-73)
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (4)
Maple2.Server.Game/Model/Field/Actor/FieldActor.cs (2)
  • FieldActor (16-45)
  • FieldActor (33-42)
Maple2.Server.Game/Manager/Config/BuffManager.cs (4)
  • NextLocalId (24-24)
  • List (218-218)
  • List (219-219)
  • List (601-605)
Maple2.Server.Game/Model/Skill/DamageRecord.cs (2)
  • DamageRecord (8-42)
  • DamageRecord (27-41)
Maple2.Model/Game/Field/FieldAccelerationStructure.cs (8)
  • List (158-164)
  • List (170-176)
  • List (217-223)
  • List (229-235)
  • List (241-247)
  • List (257-263)
  • List (269-275)
  • FieldVibrateEntity (277-279)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: format
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (9)
Maple2.Model/Enum/Skill.cs (1)

92-101:

Details

✅ Verification successful

Double-check external references after renaming Player3RegionBuff.

The numeric value (6) is unchanged, so packets/DB rows remain binary-compatible, but any code that still references the old ApplyTargetType.Player3 identifier will now fail to compile at best or, worse, be reflected as magic-number 6 literals at runtime.
Please run a quick search to confirm that no dangling symbol or hard-coded 6 slipped through.


🏁 Script executed:

#!/usr/bin/env bash
# Find any usage of the removed enum member or suspicious magic number.
rg -n --fixed-strings 'Player3' || true
rg -n 'ApplyTargetType\s*\.\s*6' || true

Length of output: 142


🏁 Script executed:

#!/usr/bin/env bash
# Display context around the remaining Player3 entry
sed -n '180,240p' Maple2.Model/Enum/Skill.cs

Length of output: 571


No dangling ApplyTargetType.Player3 references remain
I’ve searched for both Player3 and any magic-number 6 usages against ApplyTargetType and found none. The rename to RegionBuff is safe and requires no further changes.

Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.State.cs (1)

497-500: Confirm RegionBuff target selection logic.

The new case always returns all players irrespective of the caster type.
If an NPC casts a region-buff that is meant only for allies (or the caster’s faction), this may apply unintended buffs to hostile PCs.
Please review game-design intent and, if necessary, branch on caster as done for Friendly / Hostile.

Maple2.Server.Game/PacketHandlers/RequestCubeHandler.cs (1)

306-306: Mark player as in battle when lifting objects.

Setting the InBattle property to true when a player lifts an object is a good addition. This ensures that the battle state is properly tracked when players interact with liftable objects, which aligns with the PR objective for vibrate cubes that respond to combat actions.

Maple2.Model/Metadata/FieldEntity/FieldEntity.cs (1)

46-47: Added properties for vibration entity breaking mechanics.

The addition of BreakDefense and BreakTick properties to the FieldVibrateEntity record supports the PR objective of making vibrate cubes only respond to skills with sufficient breaking power. These properties provide the necessary data model to determine when an entity should vibrate based on skill break offense values.

Maple2.Server.Game/Model/Field/Entity/FieldSkill.cs (1)

176-176: Updated vibration logic to use damage record.

Changed from using record (SkillRecord) to damage (DamageRecord) when calling VibrateObjects, which correctly aligns with the updated signature in FieldManager. This change supports the new requirement that vibrate cubes only respond to skills with BrokenOffense > 0.

Maple2.Server.Game/Packets/VibratePacket.cs (1)

15-25: Updated Attack method to use DamageRecord.

The signature and implementation of the Attack method have been properly updated to use DamageRecord instead of SkillRecord. All the property accesses have been correctly updated to maintain functionality while supporting the new vibration mechanics based on break offense values.

Maple2.Model/Game/Field/FieldAccelerationStructure.cs (1)

571-579: New fields default to zero – verify serialization versioning

BreakDefense and BreakTick default to 0. When older saved maps (without these integers) are loaded, ReadEntity will still attempt to read the two ints, causing stream misalignment.

Ensure the file/packet format version is bumped or gated by a feature flag so older assets can still load safely.

Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (2)

93-93: Constructor parameter update is properly aligned with the FieldActor refactoring.

The constructor now passes a unique local ID generated by NextLocalId() to the FieldActor, which aligns with the changes made to the FieldActor class (now inheriting from Actor<MapMetadata>). This ensures each field actor has a properly initialized object ID.


119-119: FieldTick initialization is now explicit and correctly placed.

Setting FieldTick to the current environment tick count immediately after the field is initialized ensures consistent timing behavior from the start. This is good practice as it establishes a clear baseline for all time-dependent operations in the field.

Comment thread Maple2.Server.Game/PacketHandlers/VibrateHandler.cs
Comment thread Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs
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