This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e746d62
commit f9dbd57
Showing
7 changed files
with
125 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Dalamud.Game.ClientState.Objects.Types; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace RotationSolver.Data; | ||
|
||
internal class ObjectListDelay<T> : IEnumerable<T> where T : GameObject | ||
{ | ||
IEnumerable<T> _list = new T[0]; | ||
Func<(float min, float max)> _getRange; | ||
SortedList<uint, DateTime> _revealTime = new SortedList<uint, DateTime>(); | ||
Random _ran = new Random(DateTime.Now.Millisecond); | ||
|
||
public ObjectListDelay(Func<(float min, float max)> getRange) | ||
{ | ||
_getRange = getRange; | ||
} | ||
|
||
public void Delay(IEnumerable<T> originData) | ||
{ | ||
var outList= new List<T>(originData.Count()); | ||
var revealTime = new SortedList<uint, DateTime>(); | ||
var now = DateTime.Now; | ||
|
||
foreach (var item in originData) | ||
{ | ||
if(!_revealTime.TryGetValue(item.ObjectId, out var time)) | ||
{ | ||
var range = _getRange(); | ||
var delaySecond = range.min + (float)_ran.NextDouble() * (range.max - range.min); | ||
time = now + new TimeSpan(0, 0, 0, 0, (int)(delaySecond * 1000)); | ||
} | ||
revealTime.Add(item.ObjectId, time); | ||
|
||
if (time > now) | ||
{ | ||
outList.Add(item); | ||
} | ||
} | ||
|
||
_revealTime = revealTime; | ||
} | ||
|
||
|
||
public IEnumerator<T> GetEnumerator() => _list.GetEnumerator(); | ||
IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator(); | ||
} |
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