private void AddToInvasionPostQueue(WarframeInvasion invasion, bool notifyClient, bool invasionHasExpired) { if (!_invasionMessagePostQueue.Any(x => x.WarframeEvent.GUID == invasion.GUID)) { _invasionMessagePostQueue.Add(new MessageQueueElement <WarframeInvasion>(invasion, notifyClient, invasionHasExpired)); } }
public static string DiscordMessage(this WarframeInvasion invasion, bool isNotification) { MissionInfo attackerInfo = invasion.AttackerDetails; MissionInfo defenderInfo = invasion.DefenderDetails; //Check the invasion type - Invasions will have a reward from both factions but Outbreaks only have a reward from the defending faction. //Check if there is a credit reward; reward can only either be a credit reward or loot reward var defenderAllianceRewardMessage = new StringBuilder(); if (invasion.Type == InvasionType.INVASION) { if (attackerInfo.Credits > 0) { defenderAllianceRewardMessage.Append($"{invasion.AttackerDetails.Credits.ToString()}cr"); } else { defenderAllianceRewardMessage.Append(attackerInfo.RewardQuantity > 1 ? attackerInfo.RewardQuantity + "x" : string.Empty); defenderAllianceRewardMessage.Append(invasion.AttackerDetails.Reward); } } var attackerAllianceRewardMessage = new StringBuilder(); if (defenderInfo.Credits > 0) { attackerAllianceRewardMessage.Append($"{invasion.DefenderDetails.Credits.ToString()}cr"); } else { attackerAllianceRewardMessage.Append(defenderInfo.RewardQuantity > 1 ? defenderInfo.RewardQuantity + "x" : string.Empty); attackerAllianceRewardMessage.Append(invasion.DefenderDetails.Reward); } var winningFaction = (System.Math.Abs(invasion.Progress) / invasion.Progress) > 0 ? defenderInfo.Faction : attackerInfo.Faction; string changeRateSign = (invasion.ChangeRate < 0 ? "-" : "+"); var returnMessage = new StringBuilder(); if (!isNotification) { returnMessage.AppendLine(invasion.DestinationName); returnMessage.AppendLine($"{defenderInfo.Faction} vs {attackerInfo.Faction}"); returnMessage.AppendLine($"{(defenderInfo.Faction != Faction.INFESTATION ? ($"{defenderAllianceRewardMessage} / ") : string.Empty)}{attackerAllianceRewardMessage}"); //Toggle between estimated end time and invasion change rate //if (DateTime.Now.Minute % 2 == 0) //Invasion Progression returnMessage.AppendLine($"{string.Format("{0:0.00}", System.Math.Abs(invasion.Progress * 100.0f))}% ({changeRateSign + string.Format("{0:0.00}", invasion.ChangeRate * 100.0f)} p/hr){(defenderInfo.Faction != Faction.INFESTATION ? " (" + winningFaction + ")" : string.Empty)}"); var minutesRemaining = invasion.GetMinutesRemaining(); var daysRemaining = TimeSpan.FromMinutes(minutesRemaining).TotalDays; if (minutesRemaining > 0) { if (daysRemaining < 60) { returnMessage.Append($"Est. {invasion.EstimatedEndTime:HH:mm} ({(invasion.GetMinutesRemaining() > 0 ? ParseMinutesAsTime(invasion.GetMinutesRemaining(), 2) : "<1m")})"); //returnMessage.Append($"Est. {invasion.EstimatedEndTime:HH:mm} ({invasion.GetMinutesRemaining() > 0 ? ParseMinutesAsTime(invasion.GetMinutesRemaining(), 2) : < 1m)"}); } else { returnMessage.Append("Est. ∞"); } } } else { returnMessage.AppendLine("New Invasion"); returnMessage.AppendLine($"{defenderInfo.Faction} vs {attackerInfo.Faction}"); returnMessage.Append($"{(defenderInfo.Faction != Faction.INFESTATION ? ($"{defenderAllianceRewardMessage} / ") : string.Empty)}{attackerAllianceRewardMessage}"); } return(returnMessage.ToString()); }
public IEnumerable <WarframeInvasion> GetInvasions() { JObject worldState = _scraper.WorldState; var resultInvasions = new List <WarframeInvasion>(); //Find Invasions foreach (var jsonInvasion in worldState["Invasions"]) { WarframeInvasion currentInvasion = _invasionsList.Find(x => x.GUID == jsonInvasion["_id"]["$oid"].ToString()); if (currentInvasion == null) { var id = jsonInvasion["_id"]["$oid"].ToString(); var loc = jsonInvasion["Node"].ToString(); var attackerCountables = new JArray(); var defenderCountables = new JArray(); JToken attackerCountablesInfo = jsonInvasion["AttackerReward"]; JToken defenderCountablesInfo = jsonInvasion["DefenderReward"]; var attackerCredits = 0; var defenderCredits = 0; var attackersGiveReward = !attackerCountablesInfo.IsNullOrEmpty(); var defendersGiveReward = !defenderCountablesInfo.IsNullOrEmpty(); if (defendersGiveReward) { if (!defenderCountablesInfo["countedItems"].IsNullOrEmpty()) { defenderCountables = (JArray)(jsonInvasion["DefenderReward"]["countedItems"]); } if (!defenderCountablesInfo["credits"].IsNullOrEmpty()) { defenderCredits = int.Parse((jsonInvasion["DefenderReward"]["credits"]).ToString()); } } if (attackersGiveReward) { if (!attackerCountablesInfo["countedItems"].IsNullOrEmpty()) { attackerCountables = (JArray)(jsonInvasion["AttackerReward"]["countedItems"]); } if (!attackerCountablesInfo["credits"].IsNullOrEmpty()) { attackerCredits = int.Parse((jsonInvasion["AttackerReward"]["credits"]).ToString()); } } var attackerRewardStr = string.Empty; var defenderRewardStr = string.Empty; var nodeName = string.Empty; using (var unit = new UnitOfWork(new WarframeDataContext())) { attackerRewardStr = (attackersGiveReward ? unit.WarframeItems.GetItemName(attackerCountables[0]["ItemType"].ToString()) : ""); defenderRewardStr = (defendersGiveReward ? unit.WarframeItems.GetItemName(defenderCountables[0]["ItemType"].ToString()) : ""); nodeName = unit.WFSolarNodes.GetNodeName(loc); } //Store mission information in variables so that we don't have to keep parsing the JSON var attackerRewardParam = string.Empty; if (attackersGiveReward) { attackerRewardParam = attackerCountables[0]["ItemType"].ToString(); } var defenderRewardParam = string.Empty; if (defendersGiveReward) { defenderRewardParam = defenderCountables[0]["ItemType"].ToString(); } var attackerRewardQuantityParam = attackersGiveReward ? (attackerCountables[0]["ItemCount"] != null ? int.Parse(attackerCountables[0]["ItemCount"].ToString()) : 1) : 0; var defenderRewardQuantityParam = defendersGiveReward ? (defenderCountables[0]["ItemCount"] != null ? int.Parse(defenderCountables[0]["ItemCount"].ToString()) : 1) : 0; var goal = int.Parse(jsonInvasion["Goal"].ToString()); var progress = int.Parse(jsonInvasion["Count"].ToString()); if (System.Math.Abs(progress) < goal) { //Check attacker conditions if (RewardIsNotIgnored(attackerCredits, itemURI: (attackerRewardParam ?? string.Empty).ToString(), itemQuantity: attackerRewardQuantityParam) //Check defender conditions || RewardIsNotIgnored(defenderCredits, itemURI: (defenderRewardParam ?? string.Empty).ToString(), itemQuantity: defenderRewardQuantityParam)) { //Mission Info corresponds to the faction to fight against. //JSON file has currently removed mission levels and mission types from the JSON file. var attackerInfo = new MissionInfo(jsonInvasion["AttackerMissionInfo"]["faction"].ToString(), string.Empty, attackerCredits, string.IsNullOrEmpty(attackerRewardStr) ? string.Empty : attackerRewardStr, attackerRewardQuantityParam, 0, 0, false); var defenderInfo = new MissionInfo(jsonInvasion["DefenderMissionInfo"]["faction"].ToString(), string.Empty, defenderCredits, string.IsNullOrEmpty(defenderRewardStr) ? string.Empty : defenderRewardStr, defenderRewardQuantityParam, 0, 0, false); var secondsUntilStart = long.Parse(jsonInvasion["Activation"]["$date"]["$numberLong"].ToString()) - (long.Parse(worldState["Time"].ToString()) * TIME_TO_LONG_MULTIPLIER); var startTime = DateTime.Now.AddMilliseconds(secondsUntilStart); currentInvasion = new WarframeInvasion(attackerInfo, defenderInfo, id, nodeName, startTime, int.Parse(jsonInvasion["Goal"].ToString())); _invasionsList.Add(currentInvasion); } } } _invasionsList.RemoveAll(x => x.IsExpired()); if (currentInvasion != null && !currentInvasion.IsExpired()) { currentInvasion.UpdateProgress(int.Parse(jsonInvasion["Count"].ToString())); resultInvasions.Add(currentInvasion); } } #if DEBUG //Rewards expired because of expiration or lack of rewards Console.WriteLine($"{worldState["Invasions"].Count() - _invasionsList.Count} Invasion(s) were discarded"); #endif return(_invasionsList); }