/// <summary>
        /// Calculates effect radius and a list of agents to be affected. Ignores cheer limit.
        /// </summary>
        private async Task DoVictoryCheer()
        {
            try {
                var leadership = Agent.Main.Character?.GetSkillValue(DefaultSkills.Leadership) ?? 0;
                _effectRadius = (leadership * 1.5f).Clamp(100, 700);

                var agentList = Mission.GetAgentsInRange(Agent.Main.Position.AsVec2, _effectRadius)
                                .Where(x => x.IsMount == false)
                                .Where(x => x.Health > 0)
                                .Where(x => x.Character != null)
                                .Where(x => x.IsMainAgent == false)
                                .Where(x => x.Team.IsFriendOf(Agent.Main.Team))
                                .ToList();

                _common.ApplyCheerEffects(Agent.Main, _moraleChange);
                await Task.Delay(TimeSpan.FromSeconds(0.65));

                foreach (var a in agentList)
                {
                    _common.ApplyCheerEffects(a, _moraleChange);
                    await Task.Delay(MBRandom.RandomInt(0, 9));
                }
            } catch (Exception ex) {
                if (_config.Cheering.DebugMode)
                {
                    Helpers.Log(ex.Message);
                    Clipboard.SetText(ex.Message + "\n" + ex.StackTrace);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates morale changed. This one is stripped down for AI for performance reasons.
        /// </summary>
        private void Cheer()
        {
            _timerToEnableCheering = MBCommon.TimeType.Mission.GetTime() + MBRandom.RandomInt(4, 7);
            _canCheer = false;

            if (_config.AI.DisplayAnnouncement)
            {
                Helpers.Announce("{=lord_cheered}" + _strings.Lord.Cheered
                                 .Replace("$NAME$", _agent.Name)
                                 .Replace("$HISHERUPPER$", _agent.IsFemale ? "Her" : "His")
                                 .Replace("$HISHERLOWER$", _agent.IsFemale ? "her" : "his"),
                                 _agent.Character,
                                 new Dictionary <string, TextObject> {
                    { "NAME", new TextObject(_agent.Name) },
                    { "HISHERUPPER", new TextObject(_agent.IsFemale ? "Her" : "His") },
                    { "HISHERLOWER", new TextObject(_agent.IsFemale ? "her" : "his") }
                }
                                 );
            }

            int mCap = _config.AI.MaximumMoralePerAgent;

            _moraleChange = (int)Math.Round((_leadership / 15f).Clamp(mCap * -1, mCap));

            if (_config.Cheering.PreventNegativeMorale)
            {
                _moraleChange.Clamp(0, 100);
            }

            var friendlyAgentsList = _agentsInArea.Where(x => x.Team.IsFriendOf(_agent.Team));
            var enemyAgentsList    = _agentsInArea.Where(x => x.Team.IsEnemyOf(_agent.Team));

            var totalFriendlyMoraleApplied = 0;
            var totalEnemyMoraleApplied    = 0;

            foreach (var a in friendlyAgentsList)
            {
                _common.ApplyCheerEffects(a, _moraleChange);
                totalFriendlyMoraleApplied += _common.ApplyMoraleChange(a, _moraleChange, noNegativeMorale: _config.Cheering.PreventNegativeMorale);
            }

            if (_leadership >= _config.Cheering.EnemyMoraleLeadershipThreshold)
            {
                foreach (var a in enemyAgentsList)
                {
                    totalEnemyMoraleApplied += _common.ApplyMoraleChange(a, _moraleChange, true);
                    _common.ApplyCheerEffects(a, _moraleChange, false);
                    a.MakeVoice(SkinVoiceManager.VoiceType.Victory, SkinVoiceManager.CombatVoiceNetworkPredictionType.NoPrediction);
                }
            }

            _cheerAmount--;
        }