예제 #1
0
        private static Sisco_Return onSpawn_PlotUpgrades_Kiosk(ref object sender, ref object[] args, ref object return_value)
        {
            LandPlot.Id kind = (LandPlot.Id)args[0];
#if !SR_VANILLA
            LandPlotUI         kiosk   = sender as LandPlotUI;
            LandPlot           plot    = kiosk.Get_LandPlot();
            PlotUpgradeTracker tracker = plot.GetComponent <PlotUpgradeTracker>();
            if (tracker == null)
            {
                tracker = plot.gameObject.AddComponent <PlotUpgradeTracker>();
            }


            GameObject panel = return_value as GameObject;
            var        ui    = panel.GetComponent <PurchaseUI>();

            foreach (PlotUpgrade up in ALL[Upgrade_Type.PLOT_UPGRADE].Values)
            {
                if (up.Kind != kind)
                {
                    continue;
                }
                bool can_buy = up.CanBuy(tracker);
                ui.AddButton(new PurchaseUI.Purchasable(up.Name, up.Sprite, up.PreviewSprite, up.Description, up.Cost, new PediaDirector.Id?(), new UnityAction(() => { up.Purchase(kiosk.gameObject); }), can_buy));
            }
#endif
            return(null);
        }
예제 #2
0
        public static bool TryPurchase(LandPlotUI kiosk, PlotUpgrade upgrade)
        {
#if !SR_VANILLA
            LandPlot           plot    = kiosk.Get_LandPlot();
            PlotUpgradeTracker tracker = plot.GetComponent <PlotUpgradeTracker>();

            if (tracker.HasUpgrade(upgrade))
            {
                kiosk.Error("e.already_has_upgrade");
            }
            else if (Player.Currency >= upgrade.Cost)
            {
                Sound.Play(SoundId.PURCHASED_PLOT_UPGRADE);
                Player.SpendCurrency(upgrade.Cost, false);
                tracker.Add(upgrade);
                kiosk.Close();
                return(true);
            }
            else
            {
                Sound.Play(SoundId.ERROR);
                kiosk.Error("e.insuf_coins");
            }
#endif
            return(false);
        }
예제 #3
0
        protected bool PrereqsMet(PlotUpgradeTracker obj)
        {
            foreach (PlotUpgrade up in prereqs)
            {
                if (!up.IsBought(obj))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #4
0
 public bool CanBuy(PlotUpgradeTracker plot)
 {
     if (!PrereqsMet(plot))
     {
         return(false);
     }
     if (plot.HasUpgrade(this))
     {
         return(false);
     }
     if (can_buy_func != null)
     {
         return(can_buy_func());
     }
     return(true);
 }
예제 #5
0
        /// <summary>
        /// Removes the upgrades effects from the LandPlot
        /// </summary>
        public void Remove(bool ignore_tracker, LandPlot plot)
        {
            PlotID pID = new PlotID(plot);

            // Clear any save data this upgrade might have set for this plot.
            Upgrades.Clear_Upgrade_Data(pID, this.ID);
            if (!ignore_tracker)
            {
                // Remove the upgrade from this plot's tracker.
                PlotUpgradeTracker tracker = plot.GetComponent <PlotUpgradeTracker>();
                if (tracker == null)
                {
                    SLog.Warn("Failed to remove upgrade from plot {0}. Cannot find PlotUpgradeTracker!", pID);
                }
                else
                {
                    tracker.Remove_Upgrade(this);
                }
            }
            // Call the upgrades cleanup logic.
            removal_function?.Invoke(plot);
        }
예제 #6
0
 /// <summary>
 /// Returns <c>true</c> if the plot has this upgrade.
 /// </summary>
 public bool IsBought(PlotUpgradeTracker obj)
 {
     return(false);
 }