-
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.
Reduce character SP when attaccking or casting spells
- Loading branch information
1 parent
aab32ba
commit d9f835b
Showing
6 changed files
with
92 additions
and
59 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
71 changes: 71 additions & 0 deletions
71
EndlessClient/HUD/Controls/PeriodicStatUpdaterComponent.cs
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,71 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using EndlessClient.GameExecution; | ||
using EOLib.Domain.Character; | ||
using Microsoft.Xna.Framework; | ||
using Optional; | ||
|
||
namespace EndlessClient.HUD.Controls | ||
{ | ||
public class PeriodicStatUpdaterComponent : GameComponent | ||
{ | ||
private readonly IEndlessGameProvider _gameProvider; | ||
private readonly ICharacterRepository _characterRepository; | ||
|
||
private DateTime _lastUsageUpdateTime; | ||
private Option<Stopwatch> _lastSpUpdateTime; | ||
|
||
public PeriodicStatUpdaterComponent(IEndlessGameProvider gameProvider, | ||
ICharacterRepository characterRepository) | ||
: base((Game)gameProvider.Game) | ||
{ | ||
_gameProvider = gameProvider; | ||
_characterRepository = characterRepository; | ||
_lastUsageUpdateTime = DateTime.Now; | ||
_lastSpUpdateTime = Option.None<Stopwatch>(); | ||
} | ||
|
||
public override void Initialize() | ||
{ | ||
if (!_gameProvider.Game.Components.Contains(this)) | ||
_gameProvider.Game.Components.Add(this); | ||
|
||
base.Initialize(); | ||
} | ||
|
||
public override void Update(GameTime gameTime) | ||
{ | ||
var stats = _characterRepository.MainCharacter.Stats; | ||
|
||
if ((DateTime.Now - _lastUsageUpdateTime).TotalMinutes >= 1) | ||
{ | ||
stats = stats.WithNewStat(CharacterStat.Usage, stats.Stats[CharacterStat.Usage] + 1); | ||
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithStats(stats); | ||
_lastUsageUpdateTime = DateTime.Now; | ||
} | ||
|
||
if (stats[CharacterStat.SP] < stats[CharacterStat.MaxSP]) | ||
{ | ||
_lastSpUpdateTime.Match( | ||
some: t => | ||
{ | ||
// this seems close to 2 but is probably based on level and/or one of the stats | ||
if (t.ElapsedMilliseconds > 2000) | ||
{ | ||
var sp = Math.Min(stats[CharacterStat.SP] + 2, stats[CharacterStat.MaxSP]); | ||
stats = stats.WithNewStat(CharacterStat.SP, sp); | ||
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithStats(stats); | ||
|
||
if (stats[CharacterStat.SP] == stats[CharacterStat.MaxSP]) | ||
_lastSpUpdateTime = Option.None<Stopwatch>(); | ||
else | ||
_lastSpUpdateTime = Option.Some(Stopwatch.StartNew()); | ||
} | ||
}, | ||
none: () => _lastSpUpdateTime = Option.Some(Stopwatch.StartNew())); | ||
} | ||
|
||
base.Update(gameTime); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.