private static void OnFrame(object sender, EventArgs eventArgs)
{
if (_done)
return;
// Wait for the next action
if (_nextAction >= DateTime.Now)
{
return;
}
var hangar = _directEve.GetItemHangar();
if (!hangar.IsReady)
{
_nextAction = DateTime.Now.AddMilliseconds(WaitMillis);
_directEve.ExecuteCommand(DirectCmd.OpenHangarFloor);
Log("Opening item hangar");
return;
}
var lpstore = _directEve.Windows.OfType<DirectLoyaltyPointStoreWindow>().FirstOrDefault();
if (lpstore == null)
{
_nextAction = DateTime.Now.AddMilliseconds(WaitMillis);
_directEve.ExecuteCommand(DirectCmd.OpenLpstore);
Log("Opening loyalty point store");
return;
}
// Wait for the amount of LP to change
if (_lastLoyaltyPoints == lpstore.LoyaltyPoints)
return;
// Do not expect it to be 0 (probably means its reloading)
if (lpstore.LoyaltyPoints == 0)
{
if (_loyaltyPointTimeout < DateTime.Now)
{
Log("It seems we have no loyalty points left");
_done = true;
return;
}
return;
}
_lastLoyaltyPoints = lpstore.LoyaltyPoints;
// Find the offer
var offer = lpstore.Offers.FirstOrDefault(o => o.TypeId.ToString() == _type || string.Compare(o.TypeName, _type, true) == 0);
if (offer == null)
{
Log("Can't find offer with type name/id: {0}!", _type);
_done = true;
return;
}
// Check LP
if (_lastLoyaltyPoints < offer.LoyaltyPointCost)
{
Log("Not enough loyalty points left");
_done = true;
return;
}
// Check ISK
if (_directEve.Me.Wealth < offer.IskCost)
{
Log("Not enough ISK left");
_done = true;
return;
}
// Check items
foreach (var requiredItem in offer.RequiredItems)
{
var item = hangar.Items.FirstOrDefault(i => i.TypeId == requiredItem.TypeId);
if (item == null || item.Quantity < requiredItem.Quantity)
{
Log("Missing {0}x {1}", requiredItem.Quantity, requiredItem.TypeName);
_done = true;
return;
}
}
// All passed, accept offer
Log("Accepting {0}", offer.TypeName);
offer.AcceptOffer();
// Set next action + loyalty point timeout
_nextAction = DateTime.Now.AddMilliseconds(WaitMillis);
_loyaltyPointTimeout = DateTime.Now.AddSeconds(10);
if (_quantity.HasValue)
{
_quantity = _quantity.Value - 1;
if (_quantity.Value <= 0)
{
Log("Quantity limit reached");
_done = true;
return;
}
}
}