private async void OnEvent_ChatMessage(ChatType chatType, string msg, Player player) { try { switch (msg) { case "/votereward": { _traceSource.TraceInformation("{0} is trying to claim a voting reward.", player); if (await DoesPlayerHaveReward(player)) { _traceSource.TraceInformation("{0} has a voting reward to claim; show reward to player.", player); //--- find reward level int rewardLevel = 0; ItemStacks rewardList = new ItemStacks(); for (var idx = 0; idx < _config.VotingRewards.Count; idx++) { var reward = _config.VotingRewards[idx]; if (playerVotes >= reward.MinVotesNeeded) { if (!_config.Cumulative) { rewardList.Clear(); } rewardList.AddStacks(reward.Rewards); } } var rewardItems = rewardList.ToEleonArray(); var itemExchangeInfo = await player.DoItemExchange("Voting Reward", "Remember to vote everyday. Enjoy!", "Close", rewardItems); _traceSource.TraceInformation("{0} has closed the voting reward UI.", player); if (!rewardItems.AreTheSame(itemExchangeInfo.items)) { _traceSource.TraceInformation("{0} took at least some of the voting reward.", player); await MarkRewardClaimed(player); _traceSource.TraceInformation("{0} claimed a voting reward.", player); } else { _traceSource.TraceInformation("{0} didn't claim any reward items.", player); } } else { await MarkRewardClaimed(player); _traceSource.TraceInformation("No unclaimed voting reward found for {0}.", player); await player.SendAlarmMessage("No unclaimed voting reward found."); } } break; } } catch (Exception ex) { _traceSource.TraceEvent(TraceEventType.Error, 1, ex.ToString()); } }
private void OnFactionRewardTimer_Elapsed(object sender, ElapsedEventArgs e) { _traceSource.TraceInformation("Entering OnFactionRewardTimer_Elapsed"); var ownersWhoGotSomething = new HashSet <int>(); lock (_saveState) { foreach (var factionEntitySet in _saveState.FactionIdToEntityIds) { var ownerId = factionEntitySet.Key; // 'Public' faction doesn't get rewards if (ownerId != 0) { var itemStacks = new ItemStacks(); foreach (var entityId in factionEntitySet.Value) { itemStacks.AddStacks(_config.EntityIdToRewards[entityId]); } if (itemStacks.Count != 0) { if (!_saveState.FactionIdToRewards.ContainsKey(ownerId)) { _saveState.FactionIdToRewards[ownerId] = itemStacks; } else { _saveState.FactionIdToRewards[ownerId].AddStacks(itemStacks); } ownersWhoGotSomething.Add(ownerId); } } } } // Tell online players about it var onlinePlayersById = _gameServerConnection.GetOnlinePlayers(); lock (onlinePlayersById) { lock (_saveState) { foreach (var playerId in onlinePlayersById.Keys) { var player = onlinePlayersById[playerId]; int ownerId = GetOwnerIdForReward(player); if (ownerId != 0 && ownersWhoGotSomething.Contains(ownerId)) { player.SendAttentionMessage("Added income!"); } } // save state before exiting _saveState.Save(k_saveStateFilePath); } } _traceSource.TraceInformation("Exiting OnFactionRewardTimer_Elapsed"); }