|
1 | 1 | using EddiDataDefinitions; |
2 | 2 | using System; |
3 | 3 | using System.Collections.Generic; |
| 4 | +using System.Linq; |
4 | 5 | using Utilities; |
5 | 6 |
|
6 | 7 | namespace EddiEvents |
@@ -60,5 +61,56 @@ public BountyAwardedEvent(DateTime timestamp, string target, string target_local |
60 | 61 | this.rewards = rewards; |
61 | 62 | this.shared = shared; |
62 | 63 | } |
| 64 | + |
| 65 | + public static bool Handle ( DateTime timestamp, string line, IDictionary<string, object> data, ref List<Event> events, bool fromLogLoad ) |
| 66 | + { |
| 67 | + var target = JsonParsing.getString(data, "Target"); |
| 68 | + var target_localised = JsonParsing.getString( data, "Target_Localised" ); |
| 69 | + var victimName = JsonParsing.getString(data, "PilotName_Localised"); |
| 70 | + var victimFaction = EventParsing.FactionName(data, "VictimFaction"); |
| 71 | + |
| 72 | + data.TryGetValue( "SharedWithOthers", out var val ); |
| 73 | + var shared = val != null && (long)val == 1; |
| 74 | + |
| 75 | + long reward; |
| 76 | + var rewards = new List<Reward>(); |
| 77 | + |
| 78 | + if ( data.ContainsKey( "Reward" ) ) |
| 79 | + { |
| 80 | + // Old-style |
| 81 | + reward = JsonParsing.getLong( data, "Reward" ); |
| 82 | + if ( reward == 0 ) |
| 83 | + { |
| 84 | + // 0-credit reward; ignore |
| 85 | + return true; |
| 86 | + } |
| 87 | + var factionName = EventParsing.FactionName(data, "Faction"); |
| 88 | + rewards.Add( new Reward( factionName, reward ) ); |
| 89 | + } |
| 90 | + else |
| 91 | + { |
| 92 | + reward = JsonParsing.getLong( data, "TotalReward" ); |
| 93 | + if ( reward == 0 ) |
| 94 | + { |
| 95 | + // 0-credit reward; ignore |
| 96 | + return true; |
| 97 | + } |
| 98 | + // Obtain list of rewards |
| 99 | + data.TryGetValue( "Rewards", out val ); |
| 100 | + var rewardsData = (List<object>)val; |
| 101 | + if ( rewardsData != null ) |
| 102 | + { |
| 103 | + foreach ( var rewardData in rewardsData.Cast<IDictionary<string, object>>() ) |
| 104 | + { |
| 105 | + var factionName = EventParsing.FactionName(rewardData, "Faction"); |
| 106 | + var factionReward = JsonParsing.getLong( rewardData, "Reward" ); |
| 107 | + rewards.Add( new Reward( factionName, factionReward ) ); |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + events.Add( new BountyAwardedEvent( timestamp, target, target_localised, victimName, victimFaction, reward, rewards, shared ) { raw = line, fromLoad = fromLogLoad } ); |
| 113 | + return true; |
| 114 | + } |
63 | 115 | } |
64 | 116 | } |
0 commit comments