Exemplo n.º 1
0
        private void Refresh(object state)
        {
            try
            {
                var scNotification         = false;
                var protectionNotification = false;
                var newBattle = false;

                var playerId = (string)state;

                var player = _messageManager.VisitNeighbor(playerId);

                var lastDefenseDateOld = BattleLogs.Where(b => b.Defender.PlayerId == TargetPlayerId)
                                         .Max(b => b.AttackDate);
                var lastDefenseDateNew = player.PlayerModel.BattleLogs.Where(b => b.Defender.PlayerId == TargetPlayerId)
                                         .Max(b => b.AttackDate);

                var newScUnitsCount = player.PlayerModel.DonatedTroops.SelectMany(kvp => kvp.Value)
                                      .Sum(kvp => kvp.Value);

                if (lastDefenseDateOld < lastDefenseDateNew)
                {
                    newBattle = true;
                }

                if (newScUnitsCount < ScUnitsNotificationCount)
                {
                    scNotification = true;
                }

                if (player.PlayerModel.ProtectedUntil != null)
                {
                    protectionNotification = true;
                }

                BattleLogs     = player.PlayerModel.BattleLogs.Where(b => b.Defender.PlayerId == TargetPlayerId).ToList();
                ScUnitsCount   = newScUnitsCount;
                ProtectedUntil = player.PlayerModel.ProtectedUntil;

                if (newBattle && (NotifyAlways || scNotification && NotifyOnSc || protectionNotification && NotifyOnProtection))
                {
                    Debug("Battle occurred");
                    OnBattleOccured(player);
                }
            }
            catch (Exception ex)
            {
                Log(ex);
            }
            finally
            {
                _timer = new Timer(Refresh, TargetPlayerId, TIMER_PERIOD, 0);
            }
        }
Exemplo n.º 2
0
        private void Refresh(object state)
        {
            var scNotification         = false;
            var protectionNotification = false;

            var playerId = (string)state;

            var player = _messageManager.VisitNeighbor(playerId);

            var lastDefenseDateOld = BattleLogs.Where(b => b.Defender.PlayerId == TargetPlayerId).Max(b => b.AttackDate);
            var lastDefenseDateNew = player.PlayerModel.BattleLogs.Where(b => b.Defender.PlayerId == TargetPlayerId).Max(b => b.AttackDate);

            if (lastDefenseDateOld == lastDefenseDateNew)
            {
                return;
            }

            var newScUnitsCount = player.PlayerModel.DonatedTroops.SelectMany(kvp => kvp.Value).Sum(kvp => kvp.Value);

            if (newScUnitsCount < ScUnitsNotificationCount)
            {
                scNotification = true;
            }

            if (player.PlayerModel.ProtectedUntil != null)
            {
                protectionNotification = true;
            }

            BattleLogs   = player.PlayerModel.BattleLogs.Where(b => b.Defender.PlayerId == TargetPlayerId).ToList();
            ScUnitsCount = newScUnitsCount;

            if (NotifyAlways || scNotification && NotifyOnSc || protectionNotification && NotifyOnProtection)
            {
                OnBattleOccured(player);
            }
        }