-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from ethanmoffat/spell_casting
Implement selection/casting of spells by main player. Enforce SP limits.
- Loading branch information
Showing
37 changed files
with
814 additions
and
266 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -3,5 +3,7 @@ | |
public interface ISpellTargetable | ||
{ | ||
int ID { get; } | ||
|
||
int Index { get; } | ||
} | ||
} |
This file contains 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,83 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Map; | ||
using EOLib.Domain.NPC; | ||
using EOLib.IO; | ||
using EOLib.IO.Repositories; | ||
|
||
namespace EOLib.Domain.Spells | ||
{ | ||
[AutoMappedType] | ||
public class SpellCastValidationActions : ISpellCastValidationActions | ||
{ | ||
private readonly IPubFileProvider _pubFileProvider; | ||
private readonly ICurrentMapProvider _currentMapProvider; | ||
private readonly ICharacterProvider _characterProvider; | ||
|
||
public SpellCastValidationActions(IPubFileProvider pubFileProvider, | ||
ICurrentMapProvider currentMapProvider, | ||
ICharacterProvider characterProvider) | ||
{ | ||
_pubFileProvider = pubFileProvider; | ||
_currentMapProvider = currentMapProvider; | ||
_characterProvider = characterProvider; | ||
} | ||
|
||
public SpellCastValidationResult ValidateSpellCast(int spellId) | ||
{ | ||
var spellData = _pubFileProvider.ESFFile[spellId]; | ||
|
||
var stats = _characterProvider.MainCharacter.Stats; | ||
if (stats[CharacterStat.SP] - spellData.SP < 0) | ||
return SpellCastValidationResult.ExhaustedNoSp; | ||
if (stats[CharacterStat.TP] - spellData.TP < 0) | ||
return SpellCastValidationResult.ExhaustedNoTp; | ||
|
||
return SpellCastValidationResult.Ok; | ||
} | ||
|
||
public SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable spellTarget) | ||
{ | ||
var res = ValidateSpellCast(spellId); | ||
if (res != SpellCastValidationResult.Ok) | ||
return res; | ||
|
||
var spellData = _pubFileProvider.ESFFile[spellId]; | ||
|
||
if (spellTarget is INPC) | ||
{ | ||
if (spellData.TargetRestrict == SpellTargetRestrict.Friendly || | ||
spellData.Target != SpellTarget.Normal || | ||
spellData.Type != SpellType.Damage) | ||
return SpellCastValidationResult.WrongTargetType; | ||
|
||
var npcData = _pubFileProvider.ENFFile[spellTarget.ID]; | ||
|
||
if (npcData.Type != NPCType.Passive && npcData.Type != NPCType.Aggressive) | ||
return SpellCastValidationResult.CannotAttackNPC; | ||
} | ||
else if (spellTarget is ICharacter) | ||
{ | ||
if (spellData.TargetRestrict == SpellTargetRestrict.NPCOnly || | ||
spellData.Target != SpellTarget.Normal || | ||
(spellTarget == _characterProvider.MainCharacter && spellData.TargetRestrict != SpellTargetRestrict.Friendly) || | ||
(spellData.Type != SpellType.Heal && spellData.Type != SpellType.Damage) || | ||
(!_currentMapProvider.CurrentMap.Properties.PKAvailable && spellData.TargetRestrict == SpellTargetRestrict.Opponent)) | ||
return SpellCastValidationResult.WrongTargetType; | ||
} | ||
else | ||
{ | ||
return SpellCastValidationResult.WrongTargetType; | ||
} | ||
|
||
return SpellCastValidationResult.Ok; | ||
} | ||
} | ||
|
||
public interface ISpellCastValidationActions | ||
{ | ||
SpellCastValidationResult ValidateSpellCast(int spellId); | ||
|
||
SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable spellTarget); | ||
} | ||
} |
This file contains 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,11 @@ | ||
namespace EOLib.Domain.Spells | ||
{ | ||
public enum SpellCastValidationResult | ||
{ | ||
Ok, | ||
CannotAttackNPC, | ||
WrongTargetType, | ||
ExhaustedNoSp, | ||
ExhaustedNoTp, | ||
} | ||
} |
Oops, something went wrong.