Skip to content

Commit

Permalink
2014-05-18
Browse files Browse the repository at this point in the history
  • Loading branch information
连天 committed May 18, 2014
1 parent 0ee2b95 commit 8ce57c9
Show file tree
Hide file tree
Showing 218 changed files with 14,905 additions and 454 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ private static Composite CreateAddRiftMarkers()
m.NameHash == 0 ||
m.NameHash == RiftGuardianHash ||
m.IsPointOfInterest || // Already matches POI hash
m.IsPortalExit ||
m.Position.ToVector2().DistanceSqr(ZetaDia.Me.Position.ToVector2()) <= 500 * 500)) && // within 500 yards
m.IsPortalExit)) &&
!KnownMarkers.Any(ml => ml.Position == m.Position && ml.MarkerNameHash == m.NameHash))
.OrderBy(m => m.IsPointOfInterest)
.ThenBy(m => m.Position.ToVector2().DistanceSqr(ZetaDia.Me.Position.ToVector2()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ private void RefreshActorInfo()
if (_objectiveObject == null)
{
// Portals are not the actual objective but at the marker location
_objectiveObject = ZetaDia.Actors.GetActorsOfType<DiaObject>(true).Where(o => o != null && o.IsValid && o is GizmoPortal
&& o.Position.Distance2D(_mapMarkerLastPosition) <= PathPrecision).OrderBy(o => o.Distance).FirstOrDefault();
_objectiveObject = ZetaDia.Actors.GetActorsOfType<DiaObject>(true)
.Where(o => o != null && o.IsValid && o is GizmoPortal
&& o.Position.Distance2DSqr(_mapMarkerLastPosition) <= 9f)
.OrderBy(o => o.Distance).FirstOrDefault();
}

}
Expand Down
2 changes: 1 addition & 1 deletion Bounty Compilation/Plugins/QuestTools/QuestTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace QuestTools
{
public class QuestTools
{
public static Version PluginVersion = new Version(2, 0, 74);
public static Version PluginVersion = new Version(2, 0, 76);

private static int _skipEventDuration = -1;
private static readonly Stopwatch SkipEventTimer = new Stopwatch();
Expand Down
2 changes: 1 addition & 1 deletion Bounty Compilation/Plugins/Trinity/Cache/CacheData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ internal static void Clear()
MonsterTypes.Clear();
Position.Clear();
SummonedByACDId.Clear();
TimeBoundAvoidance.RemoveWhere(aoe => aoe.Expires < DateTime.UtcNow);
UnitIsBurrowed.Clear();
UnitMaxHealth.Clear();
UnitMonsterAffix.Clear();
TimeBoundAvoidance.RemoveWhere(aoe => aoe.Expires < DateTime.UtcNow);
NavigationObstacles.RemoveWhere(o => o.Position.Distance2DSqr(Trinity.Player.Position) > 90f * 90f);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Trinity.Cache
{
public class ItemDroppedAppender : IDisposable
{
bool _headerChecked;
public ItemDroppedAppender()
{
_logItemQueue = new ConcurrentQueue<string>();
Expand All @@ -29,12 +30,16 @@ public ItemDroppedAppender()

private void CheckHeader()
{
if (_headerChecked)
return;

bool writeHeader = !File.Exists(_droppedItemLogPath);

if (writeHeader)
{
_logItemQueue.Enqueue("ActorSNO,GameBalanceID,Name,InternalName,DBBaseType,DBItemType,TBaseType,TItemType,Quality,Level,Pickup\n");
}
_headerChecked = true;
}
public void Dispose()
{
Expand Down
176 changes: 176 additions & 0 deletions Bounty Compilation/Plugins/Trinity/Cache/ItemStashSellAppender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Text;
using System.Threading;
using Trinity.Technicals;

namespace Trinity.Cache
{
public class ItemStashSellAppender : IDisposable
{
bool _headerChecked;
public ItemStashSellAppender()
{
_logItemQueue = new ConcurrentQueue<string>();

_itemLogPath = Path.Combine(FileManager.TrinityLogsPath, "StashSellSalvage.csv");

CheckHeader();

_queueThread = new Thread(QueueWorker)
{
Name = "StashSellSalvageWorker",
IsBackground = true,
Priority = ThreadPriority.Lowest
};
_queueThread.Start();

}

private void CheckHeader()
{
if (_headerChecked)
return;

bool writeHeader = !File.Exists(_itemLogPath);

if (writeHeader)
{
_logItemQueue.Enqueue("ActorSNO,Name,InternalName,DBBaseType,DBItemType,TBaseType,TItemType,Quality,Level,Action,Stats\n");
}
_headerChecked = true;
}
public void Dispose()
{
try
{
if (_queueThread != null)
_queueThread.Abort();
}
catch { }
_queueThread = null;
}

private readonly Mutex _mutex = new Mutex(false, "ItemStashedMutex");

private static ItemStashSellAppender _instance;
public static ItemStashSellAppender Instance { get { return _instance ?? (_instance = new ItemStashSellAppender()); } }

private StreamWriter _logWriter;
private FileStream _fileStream;

private readonly ConcurrentQueue<string> _logItemQueue;

private Thread _queueThread;
private readonly string _itemLogPath;

internal void AppendItem(CachedACDItem item, string action)
{
StringBuilder sb = new StringBuilder();

sb.Append(FormatCSVField(item.AcdItem.ActorSNO));
sb.Append(FormatCSVField(item.RealName));
sb.Append(FormatCSVField(item.InternalName));
sb.Append(FormatCSVField(item.DBBaseType.ToString()));
sb.Append(FormatCSVField(item.DBItemType.ToString()));
sb.Append(FormatCSVField(item.TrinityItemBaseType.ToString()));
sb.Append(FormatCSVField(item.TrinityItemType.ToString()));
sb.Append(FormatCSVField(item.Quality.ToString()));
sb.Append(FormatCSVField(item.Level));
sb.Append(FormatCSVField(action));
var stats = item.AcdItem.Stats.ToString();
stats = stats.Replace("\r\n\t", " ").Replace(" - ", ": ");
sb.Append(FormatCSVField(stats));
sb.Append("\n");

_logItemQueue.Enqueue(sb.ToString());

}

private void QueueWorker()
{
const int bufferSize = 65536;
const int maxAttempts = 50;

while (true)
{
try
{
CheckHeader();

if (_fileStream == null)
_fileStream = File.Open(_itemLogPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);

if (_logWriter == null)
_logWriter = new StreamWriter(_fileStream, Encoding.UTF8, bufferSize);

string queueItem;
while (_logItemQueue.TryDequeue(out queueItem))
{
bool success = false;
int attempts = 0;
while (!string.IsNullOrWhiteSpace(queueItem) && !success && attempts <= maxAttempts)
{
try
{
_mutex.WaitOne();

attempts++;
_logWriter.Write(queueItem);
_logWriter.Flush();
_fileStream.Flush();
success = true;
queueItem = "";

}
catch (Exception ex)
{
Logger.LogError("Error in StashSellSalvage QueueWorker: " + ex.Message);
}
finally
{
_mutex.ReleaseMutex();
}
}
}
}
catch (ThreadAbortException)
{
// ssh...
}
catch (Exception ex)
{
Logger.LogError("Error in StashSellSalvage QueueWorker: " + ex.Message);
}

Thread.Sleep(10);
}
}

private static string FormatCSVField(DateTime time)
{
return String.Format("\"{0:yyyy-MM-ddTHH:mm:ss.ffff}\",", time.ToLocalTime());
}

private static string FormatCSVField(string text)
{
return String.Format("\"{0}\",", text);
}

private static string FormatCSVField(int number)
{
return String.Format("\"{0}\",", number);
}

private static string FormatCSVField(double number)
{
return String.Format("\"{0:0}\",", number);
}

private static string FormatCSVField(bool value)
{
return String.Format("\"{0}\",", value);
}
}
}
Loading

0 comments on commit 8ce57c9

Please sign in to comment.