-
Notifications
You must be signed in to change notification settings - Fork 165
Fix Issue #43 - Prevent MP loss when casting spell while swimming #142
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
Closed
crkellen
wants to merge
5
commits into
TurningWheel:barony-next
from
crkellen:issue-43-StopSwimCasting
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c76e21e
Merge pull request #5 from TurningWheel/barony-next
bd92840
Merge remote-tracking branch 'main/barony-next' into barony-next
45f2e02
- Removed checks in 'castSpell()' to determine if Caster is swimming
a743525
+ Added checks in 'castSpellInit()' to determine if Caster is swimming
9f7fc7d
+ Added checks in 'castSpell()' to determine if Caster is swimming, b…
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,39 @@ void castSpellInit(Uint32 caster_uid, spell_t* spell) | |
| return; | ||
| } | ||
|
|
||
| // Check to make sure the Caster is not swimming | ||
| // If the Caster is not a Magic Trap, they could potentially be in a water tile | ||
| // TODO: Currently only Players can swim, this must be expanded if that changes (caster->behavior != &actMagicTrap) | ||
| if ( player >= 0 ) // TODOR: Bad check, ambiguious | ||
| { | ||
| bool bIsCasterLevitating = isLevitating(stat); // If levitating, they can cast | ||
| bool bIsCasterWaterWalking = false; // If water walking, they can cast | ||
|
|
||
| if ( stat->shoes != nullptr ) | ||
| { | ||
| if ( stat->shoes->type == IRON_BOOTS_WATERWALKING ) | ||
| { | ||
| bIsCasterWaterWalking = true; | ||
| } | ||
| } | ||
|
|
||
| // If both cases are false, the Caster could potentially be swimming | ||
| if ( bIsCasterLevitating != true && bIsCasterWaterWalking != true ) | ||
|
Contributor
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.
|
||
| { | ||
| if ( players[player] && players[player]->entity ) | ||
| { | ||
| int x = std::min<int>(std::max<int>(0, floor(caster->x / 16)), map.width - 1); | ||
| int y = std::min<int>(std::max<int>(0, floor(caster->y / 16)), map.height - 1); | ||
| if ( animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] ) | ||
| { | ||
| // The Caster is in a water tile, so must be swimming | ||
| messagePlayer(player, language[410]); // "Cannot cast spells while swimming!" | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ( stat->EFFECTS[EFF_PARALYZED] ) | ||
| { | ||
| return; | ||
|
|
@@ -204,6 +237,39 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool | |
| } | ||
| } | ||
|
|
||
| // Check to make sure the Caster did not start swimming after starting the cast | ||
| // If the Caster is not a Magic Trap, they could potentially be in a water tile | ||
| // TODO: Currently only Players can swim, this must be expanded if that changes (caster->behavior != &actMagicTrap) | ||
| if ( player >= 0 ) // TODOR: Bad check, ambiguious | ||
| { | ||
| bool bIsCasterLevitating = isLevitating(stat); // If levitating, they can cast | ||
| bool bIsCasterWaterWalking = false; // If water walking, they can cast | ||
|
|
||
| if ( stat->shoes != nullptr ) | ||
| { | ||
| if ( stat->shoes->type == IRON_BOOTS_WATERWALKING ) | ||
| { | ||
| bIsCasterWaterWalking = true; | ||
| } | ||
| } | ||
|
|
||
| // If both cases are false, the Caster could potentially be swimming | ||
| if ( bIsCasterLevitating != true && bIsCasterWaterWalking != true ) | ||
| { | ||
| if ( players[player] && players[player]->entity ) | ||
| { | ||
| int x = std::min<int>(std::max<int>(0, floor(caster->x / 16)), map.width - 1); | ||
| int y = std::min<int>(std::max<int>(0, floor(caster->y / 16)), map.height - 1); | ||
| if ( animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]] ) | ||
| { | ||
| // The Caster is in a water tile, so must be swimming | ||
| messagePlayer(player, language[410]); // "Cannot cast spells while swimming!" | ||
| return nullptr; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bool newbie = false; | ||
| if ( !using_magicstaff && !trap) | ||
| { | ||
|
|
@@ -261,49 +327,6 @@ Entity* castSpell(Uint32 caster_uid, spell_t* spell, bool using_magicstaff, bool | |
| } | ||
| } | ||
|
|
||
| //Check if the bugger is levitating. | ||
| bool levitating = false; | ||
| if (!trap) | ||
| { | ||
| levitating = isLevitating(stat); | ||
| } | ||
|
|
||
| //Water walking boots | ||
| bool waterwalkingboots = false; | ||
| if (!trap) | ||
| { | ||
| if (stat->shoes != NULL) | ||
| if (stat->shoes->type == IRON_BOOTS_WATERWALKING ) | ||
| { | ||
| waterwalkingboots = true; | ||
| } | ||
| } | ||
|
|
||
| node_t* node2; //For traversing the map looking for...liquids? | ||
| //Check if swimming. | ||
| if (!waterwalkingboots && !levitating && !trap && player >= 0) | ||
| { | ||
| bool swimming = false; | ||
| if (players[player] && players[player]->entity) | ||
| { | ||
| int x = std::min<int>(std::max<int>(0, floor(caster->x / 16)), map.width - 1); | ||
| int y = std::min<int>(std::max<int>(0, floor(caster->y / 16)), map.height - 1); | ||
| if (animatedtiles[map.tiles[y * MAPLAYERS + x * MAPLAYERS * map.height]]) | ||
| { | ||
| swimming = true; | ||
| } | ||
| } | ||
| if (swimming) | ||
| { | ||
| //Can't cast spells while swimming if not levitating or water walking. | ||
| if (player >= 0) | ||
| { | ||
| messagePlayer(player, language[410]); | ||
| } | ||
| return nullptr; | ||
| } | ||
| } | ||
|
|
||
| //Right. First, grab the root element, which is what determines the delivery system. | ||
| //spellElement_t *element = (spellElement_t *)spell->elements->first->element; | ||
| spellElement_t* element = (spellElement_t*)node->element; | ||
|
|
||
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.
There's a lot of conditions here which are duplicated (not only in here but in
actplayer.cpp,acthudweapon.cpp, which should probably be factored out to reduce the duplication and the amount of code that needs to be changed should additional conditions for swimming be added.