コード例 #1
0
ファイル: InheritCashScenario.cs プロジェクト: yakoder/NRaas
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            Household house = GetData <StoredNetWorthSimData>(Sim).Household;

            int iTotalWorth = GetData <StoredNetWorthSimData>(Sim).NetWorth;

            iTotalWorth -= GetValue <DebtOption, int>(house);

            SetValue <DebtOption, int>(house, 0);

            if (iTotalWorth <= 0)
            {
                IncStat("Inherit Cash: Poor");
                return(false);
            }

            Dictionary <SimDescription, float> inheritors = Deaths.GetInheritors(Sim, GetValue <InheritorsOption, ManagerDeath.Inheritors>(), true);

            float fTotal = 0f;

            foreach (KeyValuePair <SimDescription, float> fraction in inheritors)
            {
                fTotal += fraction.Value;
            }

            AddStat("Worth", iTotalWorth);
            AddStat("Inheritors", inheritors.Count);
            AddStat("Split", fTotal);

            bool simMatches = (Deaths.MatchesAlertLevel(Sim)) || (Money.MatchesAlertLevel(Sim));

            foreach (KeyValuePair <SimDescription, float> inheritor in inheritors)
            {
                int iInheritance = (int)(iTotalWorth * (inheritor.Value / fTotal));

                if (iInheritance <= 0)
                {
                    continue;
                }

                SimDescription child = inheritor.Key;
                if (child.Household == null)
                {
                    continue;
                }

                Money.AdjustFunds(child, "Inheritance", iInheritance);

                if ((simMatches) || (Deaths.MatchesAlertLevel(child)) || (Money.MatchesAlertLevel(child)))
                {
                    mInheritance.Add(child, iInheritance);
                }
            }

            return(mInheritance.Count > 0);
        }