Пример #1
0
        public static void Postfix(ref float __result, Clan clan, StatExplainer explanation)
        {
            var refContainer = new RefContainer <float>(__result);

            MercenaryContractCampaignEvents.Instance.OnCalculateInfluenceChange(refContainer, clan, explanation);
            __result = refContainer.Value;
        }
        private void OnCalculateInfluenceChange(RefContainer <float> influence, Clan clan, StatExplainer explanation)
        {
            if (clan.IsUnderMercenaryService && !IsContributingToWar(clan))
            {
                var penalty = MercenarySettings.Instance.InfluencePenalty;

                influence.Value += penalty;
                // Null check is critical, explanation can be null sometimes.
                explanation?.AddLine(GameTexts.FindText("str_mercenary_contract_not_contributing_to_war", null).ToString(), penalty);
            }
        }
Пример #3
0
        public void StateIsLeavedImmediatelyOnSuddenExpiration()
        {
            FSM <int>          F = new FSM <int>("");
            RefContainer <int> x = new RefContainer <int>();

            F.Add(1)
            .Expires(1)
            .GoesTo(2);
            F.Add(2)
            .GoesTo(3)
            .Expires(1)
            .OnLeave(() => x.Value += 15);
            F.Add(3)
            .OnEnter(() => x.Value *= 2);

            F.CurrentState = 1;
            F.Process(0f);

            F.Process(1.5f);
            F.Process(3f);

            Assert.AreEqual(3, F.CurrentState);
            Assert.AreEqual(30, x.Value);
        }
Пример #4
0
        public void OnEnterAndOnLeaveHandlers()
        {
            FSM <int>          F = new FSM <int>("");
            RefContainer <int> x = new RefContainer <int>();

            F.Add(1)
            .Expires(5)
            .GoesTo(2)
            .OnLeave(() => x.Value += 15);
            F.Add(2)
            .OnEnter(() => x.Value *= 2);

            F.CurrentState = 1;
            F.Process(0f);

            F.Process(5.1f);
            Assert.AreEqual(30, x.Value);
            F.Process(5.2f);
            Assert.AreEqual(30, x.Value);
            F.Process(5.3f);
            Assert.AreEqual(30, x.Value);
            F.Process(5.4f);
            Assert.AreEqual(30, x.Value);
        }
 internal void OnCalculateInfluenceChange(RefContainer <float> influence, Clan clan, StatExplainer explainer)
 {
     _calculateInfluenceChange.Invoke(influence, clan, explainer);
 }