Exemplo n.º 1
0
    public void AddResourceAccelerate(BuildingIdentity id)
    {
        int costGem = MarketCalculator.GetResourceAccelerateCostGem(id.buildingType, this.GetBuildingObject(id).Level);

        this.m_PlayerModule.Consume(0, 0, 0, costGem);
        this.m_BuildingModule.AddResourceAccelerate(id);
    }
Exemplo n.º 2
0
    void OnClick()
    {
        if (!this.m_IsProcessClick)
        {
            AudioController.Play("ButtonClick");

            if (LogicController.Instance.PlayerData.CurrentStoreGold >= this.m_CostValue)
            {
                this.StartCoroutine("Wait");
                this.m_Cloud.FadeIn();
                LockScreen.Instance.DisableInput();
                BattleDirector.Instance.EndObserve();
                this.m_IsProcessClick = true;
            }
            else
            {
                int needGold = this.m_CostValue - LogicController.Instance.PlayerData.CurrentStoreGold;
                int costGem  = MarketCalculator.GetGoldCost(needGold);
                if (LogicController.Instance.PlayerData.CurrentStoreGem < costGem)
                {
                    UIErrorMessage.Instance.ErrorMessage(ClientStringConstants.NO_ENOUGH_GOLD_WARNING_MESSAGE);
                }
                else
                {
                    string costMessage = string.Format(StringConstants.PROMPT_RESOURCE_COST, needGold, StringConstants.RESOURCE_GOLD);
                    this.m_CostPrompt.ShowWindow(costGem, costMessage);
                    this.m_CostPrompt.Click            += BuyResource;
                    this.m_CostPrompt.WindowCloseEvent += CancelBuyResource;
                    this.m_IsProcessClick = true;
                }
            }
        }
    }
Exemplo n.º 3
0
    public void FinishProduceArmyInstantly(BuildingIdentity factoryID)
    {
        int remainingTime = this.GetBuildingObject(factoryID).ArmyProductsRemainingTime;
        int costGem       = MarketCalculator.GetProduceTimeCost(remainingTime);

        this.m_PlayerModule.Consume(0, 0, 0, costGem);
        this.m_BuildingModule.FinishArmyProduceInstantly(factoryID);
    }
Exemplo n.º 4
0
 public void FinishArmyUpgradeInstantly()
 {
     if (this.m_Data.ArmyUpgrade.HasValue)
     {
         this.m_CommunicationHelper.SendFinishUpgradeArmyInstantlyRequest(this.m_Data.ArmyUpgrade.Value,
                                                                          MarketCalculator.GetUpdateTimeCost(this.BuildingLogicData.ArmyUpgradeRemainingTime));
     }
     this.m_Data.ArmyUpgrade = null;
 }
Exemplo n.º 5
0
        public void Calculate_CalculateIntrestRate()
        {
            IMarketCalculator marketCalculator = new MarketCalculator();

            var availableMarket = marketCalculator.AvailableMarket(1000, TestData.MarketData);

            var intrestRate = marketCalculator.CalculateIntrestRate(availableMarket);

            Assert.AreEqual(0.070039999999999991, intrestRate);
        }
Exemplo n.º 6
0
        public void Calculate_BestAvailableFunds()
        {
            IMarketCalculator marketCalculator = new MarketCalculator();

            var availableMarket = marketCalculator.AvailableMarket(1000, TestData.MarketData);

            Assert.AreEqual(2, availableMarket.Count());

            Assert.AreEqual(0.069, availableMarket.ToArray()[0].Rate);
            Assert.AreEqual(0.071, availableMarket.ToArray()[1].Rate);
        }
Exemplo n.º 7
0
        public void Calculate_MonthlyRepaymentsExample()
        {
            var loan   = 1000.0;
            var rate   = 0.07004;
            var months = 36;

            IMarketCalculator marketCalculator = new MarketCalculator();

            var monthlyRepayment = marketCalculator.CalulateMonthlyRepayments(loan, rate, months);

            Assert.AreEqual(30.78, Math.Round(monthlyRepayment, 2));
        }
Exemplo n.º 8
0
        public void Calculate_TotalRepaymentsExample()
        {
            var loan   = 1000.0;
            var rate   = 0.07004;
            var months = 36;

            IMarketCalculator marketCalculator = new MarketCalculator();

            var monthlyRepayment = marketCalculator.CalulateMonthlyRepayments(loan, rate, months);

            var totalRepayments = marketCalculator.CalculateTotalRepayments(monthlyRepayment, 36);

            Assert.AreEqual(1108.10, Math.Round(totalRepayments, 2));
        }
Exemplo n.º 9
0
        public void Quote_Successfull()
        {
            var mockIMarketDataRepository = new Mock <IMarketDataRepository>();
            var marketCalculator          = new MarketCalculator();

            mockIMarketDataRepository.Setup(x => x.GetMarketData()).Returns(TestData.MarketData);

            IQuoteCalculator quoteCalculator = new QuoteCalculator(mockIMarketDataRepository.Object, marketCalculator);

            QuoteResult result = quoteCalculator.GetQuote(1000);

            Assert.AreEqual(QuoteResultCode.Success, result.QuoteResultCode);
            Assert.AreEqual(30.78, Math.Round(result.Quote.MonthlyRepayment, 2));
            Assert.AreEqual(7, Math.Round(result.Quote.Rate * 100, 1));
            Assert.AreEqual(1000, result.Quote.RequestedAmount);
            Assert.AreEqual(1108.1, Math.Round(result.Quote.TotalRepayment, 2));
        }
Exemplo n.º 10
0
    public void FinishProduceArmyInstantly(List <BuildingIdentity> camps)
    {
        List <ArmyIdentity> armies = new List <ArmyIdentity>();
        int costGem = MarketCalculator.GetProduceTimeCost(this.BuildingLogicData.ArmyProductsRemainingTime);

        if (this.m_Data.ProduceArmy != null)
        {
            foreach (KeyValuePair <ArmyType, List <ArmyIdentity> > armyList in this.m_Data.ProduceArmy)
            {
                armies.AddRange(armyList.Value);
            }
            this.m_Data.ProduceArmy.Clear();
        }
        this.m_AlreadyProduceArmyCapacity = 0;

        this.m_CommunicationHelper.SendFinishProduceArmyInstantlyRequest(armies, camps, costGem);
    }
Exemplo n.º 11
0
    public void FinishUpgradeArmyInstantly(BuildingIdentity laboratoryID)
    {
        BuildingLogicData data = this.GetBuildingObject(laboratoryID);

        if (data.ArmyUpgrade.HasValue)
        {
            ArmyType armyType      = data.ArmyUpgrade.Value;
            int      remainingTime = data.ArmyUpgradeRemainingTime;
            int      costGem       = MarketCalculator.GetUpdateTimeCost(remainingTime);
            this.m_PlayerModule.Consume(0, 0, 0, costGem);
            this.m_BuildingModule.FinishArmyUpgradeInstantly(laboratoryID);
            this.m_ArmyModule.FinishUpgrade(armyType);
            this.m_PlayerModule.UpgradeArmy(armyType);

            this.m_TaskModule.OnUpgradeArmy(armyType, this.m_PlayerModule.Data.GetArmyLevel(armyType));
        }
    }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            int exitCode   = 0;
            int loanAmount = 0;

            try
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("Not enough parameters - expected [market_file] [loan_amount]");
                }
                else if (!int.TryParse(args[1], out loanAmount))
                {
                    Console.WriteLine("Loan Amount must be a valid integer");
                }
                else
                {
                    var marketData = args[0];

                    if (!int.TryParse(args[1], out loanAmount))
                    {
                        Console.WriteLine("Loan Amount must be a valid integer");
                    }

                    IMarketCalculator     marketCalculator     = new MarketCalculator();
                    IMarketDataRepository marketDataRepository = new MarketDataRepository(marketData);
                    IQuoteCalculator      quoteCalculator      = new QuoteCalculator(marketDataRepository, marketCalculator);
                    IQuoteResultFormatter resultFormatter      = new QuoteResultFormatter();

                    var quoteResult = quoteCalculator.GetQuote(loanAmount);

                    Console.WriteLine(resultFormatter.Format(quoteResult));
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Oops! an error occured retrieving your quote");
                Console.WriteLine(exception.Message);
                exitCode = 1;
            }

            Console.ReadKey();

            Environment.Exit(exitCode);
        }
Exemplo n.º 13
0
    public void FinishBuildingUpgradeInstantly(BuildingIdentity id)
    {
        BuildingLogicData data = this.GetBuildingObject(id);

        if (data.AttachedBuilderEfficiency > 0)
        {
            int remainingTime = Mathf.CeilToInt(data.UpgradeRemainingWorkload / data.AttachedBuilderEfficiency);
            int costGem       = MarketCalculator.GetUpdateTimeCost(remainingTime);

            this.m_PlayerModule.Consume(0, 0, 0, costGem);
            this.m_BuildingModule.FinishBuildingUpgradeInstantly(id, costGem);

            if (data.Level == 0)
            {
                this.FinishBuildingConstruct(id);
            }
            else
            {
                this.FinishBuildingUpgrade(id);
            }
        }
    }
Exemplo n.º 14
0
    public void OnImmediatelyUpgrade()
    {
        if (this.BuildingLogicData.CurrentBuilidngState != BuildingEditorState.Update)
        {
            return;
        }
        int    costGem     = MarketCalculator.GetUpdateTimeCost(Mathf.CeilToInt((float)this.BuildingLogicData.UpgradeRemainingWorkload / this.BuildingLogicData.AttachedBuilderEfficiency));
        string costContext = string.Format(StringConstants.PROMPT_GEM_COST, costGem, StringConstants.COIN_GEM, this.BuildingLogicData.Name, this.BuildingLogicData.Level == 0 ? StringConstants.PROMPT_CONSTRUCT + StringConstants.QUESTION_MARK : StringConstants.PROMPT_UPGRADE + StringConstants.QUESTION_MARK);

        UIManager.Instance.UIWindowCostPrompt.ShowWindow(costGem, costContext, StringConstants.PROMPT_FINISH_INSTANTLY);
        UIManager.Instance.UIWindowCostPrompt.UnRegistDelegate();
        UIManager.Instance.UIWindowCostPrompt.Click += () =>
        {
            if (LogicController.Instance.PlayerData.CurrentStoreGem < costGem)
            {
                print("宝石不足,去商店");
                UIManager.Instance.UIWindowFocus = null;
                //UIManager.Instance.UIButtonShopping.GoShopping();
                UIManager.Instance.UISelectShopMenu.GoShopping();
            }
            else
            {
                if (this.BuildingLogicData.CurrentBuilidngState == BuildingEditorState.Update)
                {
                    print("立即完成升级");
                    this.CreateUpgradeFX();
                    LogicController.Instance.FinishBuildingUpgradeInstantly(this.BuildingLogicData.BuildingIdentity);
                    SceneManager.Instance.ConstructBuilding(this.BuildingLogicData, true);
                    UIManager.Instance.HidePopuBtnByCurrentSelect(true);
                    this.BuildingBehavior.enabled = false;
                    Destroy(this.gameObject);
                    SceneManager.Instance.PickableObjectCurrentSelect = null;
                }
            }
        };
    }
Exemplo n.º 15
0
 public void BuyFood(int food)
 {
     this.m_UserData.CurrentStoreFood += food;
     this.m_UserData.CurrentStoreGem  -= MarketCalculator.GetFoodCost(food);
 }
Exemplo n.º 16
0
 public void BuyGold(int gold)
 {
     this.m_UserData.CurrentStoreGold += gold;
     this.m_UserData.CurrentStoreGem  -= MarketCalculator.GetGoldCost(gold);
 }
Exemplo n.º 17
0
 public void BuyOil(int oil)
 {
     this.m_UserData.CurrentStoreOil += oil;
     this.m_UserData.CurrentStoreGem -= MarketCalculator.GetOilCost(oil);
 }