public override void OnLevelLoaded(LoadMode mode)
        {
            EconomyManager    em = Singleton <EconomyManager> .instance;
            DifficultyManager d  = Singleton <DifficultyManager> .instance;

            if (mode == LoadMode.NewGame)
            {
                int moneyToAdd = (d.InitialMoney.Value - 70) * 100000;
                em.AddResource(EconomyManager.Resource.LoanAmount, moneyToAdd, ItemClass.Service.None, ItemClass.SubService.None, ItemClass.Level.None);
            }

            if (mode == LoadMode.NewGame || mode == LoadMode.LoadGame)
            {
                for (int i = 0; i < 3; i++)
                {
                    EconomyManager.Bank     bank = em.m_properties.m_banks[i];
                    EconomyManager.LoanInfo li   = bank.m_loanOffers[0];

                    li.m_amount = (int)Math.Round(0.01f * li.m_amount * d.LoanMultiplier.Value);
                    li.m_length = (int)Math.Round(0.01f * li.m_length * d.LoanMultiplier.Value);

                    bank.m_loanOffers[0]       = li;
                    em.m_properties.m_banks[i] = bank;
                    //DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, bank.m_bankName);
                }
            }

            Achievements.Update();

            PrefabsManager.UpdatePrefabs(false);
        }
Exemple #2
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            EconomyManager    em = Singleton <EconomyManager> .instance;
            DifficultyManager d  = Singleton <DifficultyManager> .instance;

            if (mode == LoadMode.NewGame)
            {
                int moneyToAdd = (d.InitialMoney.Value - 70) * 100000;
                em.AddResource(EconomyManager.Resource.LoanAmount, moneyToAdd, ItemClass.Service.None, ItemClass.SubService.None, ItemClass.Level.None);
            }

            if (mode == LoadMode.NewGame || mode == LoadMode.LoadGame)
            {
                for (int i = 0; i < 3; i++)
                {
                    EconomyManager.Bank     bank = em.m_properties.m_banks[i];
                    EconomyManager.LoanInfo li   = bank.m_loanOffers[0];

                    int newAmount = (int)Math.Round(li.m_amount * 0.01f * d.LoanMultiplier.Value);
                    int newLength = (int)Math.Round(li.m_length * (1 + 0.01f * d.LoanMultiplier.Value) / 2f); // Halve the effect to prevent too long loan length.
                    Helper.ValueChangedMessage(bank.m_bankName, "Loan amount", li.m_amount, newAmount);
                    Helper.ValueChangedMessage(bank.m_bankName, "Loan length", li.m_length, newLength);
                    li.m_amount = newAmount;
                    li.m_length = newLength;

                    bank.m_loanOffers[0]       = li;
                    em.m_properties.m_banks[i] = bank;
                }
            }

            Achievements.Update();

            PrefabsManager.UpdatePrefabs(false);
            NetManager.UpdateSlopes(false);
        }
        public void OnClientMessage(ClientMessage msg)
        {
            string action = msg.GetString("action");

            switch (action)
            {
            case "gimme":
                economyManager.AddResource(
                    EconomyManager.Resource.RewardAmount,
                    msg.GetInt("amount"),
                    (ItemClass)ScriptableObject.CreateInstance("ItemClass"));
                break;

            case "payLoan": {
                var r = economyManager.PayLoanNow(msg.GetInt("id"));
                if (r == null)
                {
                    Log($"PayLoanNow returns null");
                }
                else
                {
                    Log($"PayLoanNow returns: {r}");
                }
                break;
            }

            //case "setBudget": {
            //		//TODO, also set tax rate
            //		//economyManager.SetBudget();
            //		break;
            //	}
            default:
                throw new ArgumentException($"Invalid method {action}");
            }
        }
        private void DeleteBuildingImpl(ref ushort buildingId, ref Building building)
        {
            if (building.Info.m_buildingAI.CheckBulldozing(buildingId, ref building) != ToolBase.ToolErrors.None)
            {
                return;
            }
            var buildingRefundAmount = building.GetRefundAmount(ref buildingId);

            if (buildingRefundAmount != 0)
            {
                economyManager.AddResource(EconomyManager.Resource.RefundAmount, buildingRefundAmount, building.Info.m_class);
            }
            building.DispatchAutobulldozeEffect(ref buildingId, nullAudioGroup);
            buildingManager.ReleaseBuilding(buildingId);
            if (ItemClass.GetPublicServiceIndex(building.Info.m_class.m_service) != -1)
            {
                coverageManager.CoverageUpdated(building.Info.m_class.m_service, building.Info.m_class.m_subService, building.Info.m_class.m_level);
            }
        }
Exemple #5
0
        public override long OnUpdateMoneyAmount(long internalMoneyAmount)
        {
            try
            {
                DistrictManager   DMinstance = Singleton <DistrictManager> .instance;
                Array8 <District> dm_array   = DMinstance.m_districts;
                District          d;

                Debugger.Write("\r\n== OnUpdateMoneyAmount ==");

                double sec_per_day     = 75600.0;             // for some reason
                double sec_per_week    = 7 * sec_per_day;
                double week_proportion = 0.0;
                int    export_earnings = 0;
                int    earnings_shown  = 0;

                if (dm_array == null)
                {
                    Debugger.Write("early return, dm_array is null");
                    return(internalMoneyAmount);
                }

                d = dm_array.m_buffer[0];

                if (!updated)
                {
                    updated  = true;
                    prevDate = this.managers.threading.simulationTime;
                    Debugger.Write("first run");
                }
                else
                {
                    System.DateTime newDate  = this.managers.threading.simulationTime;
                    System.TimeSpan timeDiff = newDate.Subtract(prevDate);
                    week_proportion = (((double)timeDiff.TotalSeconds) / sec_per_week);
                    if (week_proportion > 0.0)
                    {
                        Debugger.Write("proportion: " + week_proportion.ToString());
                        EconomyManager EM = Singleton <EconomyManager> .instance;
                        if (EM != null)
                        {
                            // add income
                            export_earnings = (int)ExpmHolder.get().CalculateIncome(d, week_proportion);
                            earnings_shown  = export_earnings / 100;
                            Debugger.Write("Total earnings: " + earnings_shown.ToString());
                            EM.AddResource(EconomyManager.Resource.PublicIncome,
                                           export_earnings,
                                           ItemClass.Service.None,
                                           ItemClass.SubService.None,
                                           ItemClass.Level.None);
                        }
                    }
                    else
                    {
                        Debugger.Write("week_proportion zero");
                    }
                    prevDate = newDate;
                }
            }
            catch (Exception ex)
            {
                // shouldn't happen, but if it does, start logging
                Debugger.Write("Exception " + ex.Message.ToString());
            }
            return(internalMoneyAmount);
        }