-
-
Notifications
You must be signed in to change notification settings - Fork 78
Skills with a CELL pattern hit their pattern, not a single target #2289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
denislauri1999
wants to merge
4
commits into
NosCoreIO:master
Choose a base branch
from
denislauri1999:pr/skill-cell-patterns
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9b4a4da
feat(battle): skills with a CELL pattern hit their pattern, not one t…
denislauri1999 56f02fb
chore: cut the comments
denislauri1999 8a6092b
fix(battle): a pattern longer than thirty cells continues in COST
denislauri1999 3799d1e
refactor(skill): CELL goes through the parser onto the skill row
denislauri1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4,155 changes: 4,155 additions & 0 deletions
4,155
src/NosCore.Database/Migrations/20260826123844_AddSkillCellPattern.Designer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/NosCore.Database/Migrations/20260826123844_AddSkillCellPattern.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using Microsoft.EntityFrameworkCore.Migrations; | ||
|
|
||
| #nullable disable | ||
|
|
||
| namespace NosCore.Database.Migrations | ||
| { | ||
| /// <inheritdoc /> | ||
| public partial class AddSkillCellPattern : Migration | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override void Up(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.AddColumn<string>( | ||
| name: "CellPattern", | ||
| table: "Skill", | ||
| type: "character varying(512)", | ||
| maxLength: 512, | ||
| nullable: true); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override void Down(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.DropColumn( | ||
| name: "CellPattern", | ||
| table: "Skill"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/NosCore.GameObject/Services/BattleService/SkillCells.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // __ _ __ __ ___ __ ___ ___ | ||
| // | \| |/__\ /' _/ / _//__\| _ \ __| | ||
| // | | ' | \/ |`._`.| \_| \/ | v / _| | ||
| // |_|\__|\__/ |___/ \__/\__/|_|_\___| | ||
| // | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
|
|
||
| namespace NosCore.GameObject.Services.BattleService; | ||
|
|
||
| // A skill's cell pattern, rotated towards the target. | ||
| // | ||
| // 67 of the 68 skills with a CELL section declare AOE with radius zero, because the area IS | ||
| // the pattern. Reading the radius makes them hit a single target and nothing says so. | ||
| // | ||
| // Rotation is by the angle to the target, exact on the cardinals and rounded on the | ||
| // diagonals, where a one-cell row can come out as a staircase with a gap at its side. | ||
| public static class SkillCells | ||
| { | ||
| // A malformed value yields null rather than throwing: the pattern decides who a skill hits. | ||
| public static sbyte[]? Parse(string? pattern) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(pattern)) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var parts = pattern.Split(','); | ||
|
|
||
| // Pairs, so an odd count is a broken row, not a pattern with a spare coordinate. | ||
| if (parts.Length == 0 || parts.Length % 2 != 0) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var cells = new sbyte[parts.Length]; | ||
| for (var i = 0; i < parts.Length; i++) | ||
| { | ||
| if (!sbyte.TryParse(parts[i], NumberStyles.Integer, CultureInfo.InvariantCulture, | ||
| out cells[i])) | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| return cells; | ||
| } | ||
|
|
||
| // The absolute cells hit. Caster and target on one cell leaves no direction: kept facing north. | ||
| public static HashSet<(short X, short Y)> Resolve(sbyte[] pattern, short casterX, | ||
| short casterY, short targetX, short targetY) | ||
| { | ||
| var cells = new HashSet<(short, short)>(pattern.Length / 2); | ||
|
|
||
| double dx = targetX - casterX; | ||
| double dy = targetY - casterY; | ||
| var len = Math.Sqrt((dx * dx) + (dy * dy)); | ||
|
|
||
| // At zero distance there is no direction: north, as authored. | ||
| double ux = 0, uy = -1; | ||
| if (len > 0.0001) | ||
| { | ||
| ux = dx / len; | ||
| uy = dy / len; | ||
| } | ||
|
|
||
| // Authored basis is right = (1,0), forward = (0,-1); forward maps onto (ux, uy) and right | ||
| // onto (-uy, ux). | ||
| foreach (var (cx, cy) in Pairs(pattern)) | ||
| { | ||
| double right = cx; | ||
| double forward = -cy; | ||
|
|
||
| var x = (right * -uy) + (forward * ux); | ||
| var y = (right * ux) + (forward * uy); | ||
|
|
||
| cells.Add(((short)(casterX + Math.Round(x, MidpointRounding.AwayFromZero)), | ||
| (short)(casterY + Math.Round(y, MidpointRounding.AwayFromZero)))); | ||
| } | ||
|
|
||
| return cells; | ||
| } | ||
|
|
||
| private static IEnumerable<(sbyte X, sbyte Y)> Pairs(sbyte[] pattern) | ||
| { | ||
| for (var i = 0; i + 1 < pattern.Length; i += 2) | ||
| { | ||
| yield return (pattern[i], pattern[i + 1]); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Discard the complete pattern after an invalid triple.
If a later
CELLorCOSTtriple is malformed,ReadTriplesreturnsfalseafter it appends earlier pairs.ReadCellPatternthen serializes those pairs at Line 195. This creates a truncated area pattern instead of the required null fallback.Make the parse result distinguish an invalid field from a zero terminator. Return
nullfor the full pattern when any triple is invalid. Add a test with valid pairs followed by an invalid field.🤖 Prompt for AI Agents
Source: Linters/SAST tools