-
-
Notifications
You must be signed in to change notification settings - Fork 78
The cards a skill inflicts, which nothing read #2304
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/inflicted-cards
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
bd5f614
feat(combat): the cards a skill inflicts, which nothing read
denislauri1999 2aaa90b
test(combat): the wiring itself, not only the service behind it
denislauri1999 bca4068
test(combat): that the hit waits for the card, not just that it asks …
denislauri1999 4cb1dd6
test(combat): wait for the call instead of trusting a delay, and open…
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
29 changes: 29 additions & 0 deletions
29
src/NosCore.GameObject/Services/BattleService/IInflictedCardService.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 @@ | ||
| // __ _ __ __ ___ __ ___ ___ | ||
| // | \| |/__\ /' _/ / _//__\| _ \ __| | ||
| // | | ' | \/ |`._`.| \_| \/ | v / _| | ||
| // |_|\__|\__/ |___/ \__/\__/|_|_\___| | ||
| // | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using NosCore.Data.StaticEntities; | ||
| using NosCore.GameObject.Ecs.Interfaces; | ||
|
|
||
| namespace NosCore.GameObject.Services.BattleService; | ||
|
|
||
| /// <summary> | ||
| /// The cards a skill inflicts on what it hits: the poison of a poisoned arrow, the stun of Star | ||
| /// Attack, the rage of Hit of Rage. | ||
| /// | ||
| /// A skill does not carry the effect - it carries a BCard of type 25 saying "with N% chance, | ||
| /// apply Card number M". Card M is a real entry of <c>Card.dat</c>, with its own duration and its | ||
| /// own BCards. Without the step back from M to the Card, that reference goes nowhere, and it is | ||
| /// the most widespread effect in the game: 1344 of the skills declare one. | ||
| /// </summary> | ||
| public interface IInflictedCardService | ||
| { | ||
| /// <summary> | ||
| /// Rolls each type 25 BCard the skill declares and applies, or removes, the card it names. | ||
| /// </summary> | ||
| Task InflictAsync(IAliveEntity target, IAliveEntity? caster, IReadOnlyList<BCardDto> skillBCards); | ||
| } |
76 changes: 76 additions & 0 deletions
76
src/NosCore.GameObject/Services/BattleService/InflictedCardService.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,76 @@ | ||
| // __ _ __ __ ___ __ ___ ___ | ||
| // | \| |/__\ /' _/ / _//__\| _ \ __| | ||
| // | | ' | \/ |`._`.| \_| \/ | v / _| | ||
| // |_|\__|\__/ |___/ \__/\__/|_|_\___| | ||
| // | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using NosCore.Data.Enumerations.Buff; | ||
| using NosCore.Data.StaticEntities; | ||
| using NosCore.GameObject.Ecs.Interfaces; | ||
| using NosCore.GameObject.Infastructure; | ||
|
|
||
| namespace NosCore.GameObject.Services.BattleService; | ||
|
|
||
| // BCard type 25/11 and 25/12: FirstData is the percentage, SecondData the card id. The columns | ||
| // tell them apart - 32 distinct values on one side against 780 on the other, and an id does not | ||
| // repeat 717 times. | ||
| // | ||
| // Takes a target rather than a skill because the BCard does not say who receives the card; on a | ||
| // blow that has landed the entity that took the damage is the one it goes on. | ||
| public sealed class InflictedCardService( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. likely the code here should be in IBuffService |
||
| ICardCatalog cardCatalog, | ||
| IBuffService buffService, | ||
| IRandomProvider randomProvider) : IInflictedCardService, ISingletonService | ||
| { | ||
| public async Task InflictAsync(IAliveEntity target, IAliveEntity? caster, | ||
| IReadOnlyList<BCardDto> skillBCards) | ||
| { | ||
| for (var i = 0; i < skillBCards.Count; i++) | ||
| { | ||
| var bCard = skillBCards[i]; | ||
| if ((BCardType.CardType)bCard.Type != BCardType.CardType.Buff) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var subType = (AdditionalTypes.Buff)bCard.SubType; | ||
| if (subType is not (AdditionalTypes.Buff.ChanceCausing or AdditionalTypes.Buff.ChanceRemoving)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| if (!Rolls(bCard.FirstData)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var cardId = (short)bCard.SecondData; | ||
| if (subType == AdditionalTypes.Buff.ChanceRemoving) | ||
| { | ||
| await buffService.RemoveAsync(target, cardId).ConfigureAwait(false); | ||
| continue; | ||
| } | ||
|
|
||
| // One of the 1341 declarations names a card that is not in the file. It is skipped | ||
| // rather than thrown on: a single bad row in the client's data must not take a blow | ||
| // down with it. | ||
| var card = cardCatalog.GetCard(cardId); | ||
| if (card == null) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| await buffService | ||
| .ApplyAsync(target, card, cardCatalog.GetCardBCards(cardId), caster) | ||
| .ConfigureAwait(false); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The roll. <c>Next(0, 100)</c> yields 0 to 99, so "less than" makes 100 always succeed and 0 | ||
| /// never - which is what the file means, and 717 of the 1341 declarations say 100. | ||
| /// </summary> | ||
| private bool Rolls(int percent) => percent > 0 && randomProvider.Next(0, 100) < percent; | ||
| } | ||
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.
don't need example of which bcard number in the comments. Comments overall should only be to explain code that is too hard and in most of cases we shouldnt have hard code