public async Task <IActionResult> PutLandPlot(int id, LandPlotRequest landPlotRequest) { LandPlot landPlot = landPlotRequest.LandPlot; string token = landPlotRequest.token; if (!Security.TokenIsValid(token)) { return(StatusCode(401)); } if (id != landPlot.Id) { return(BadRequest()); } _context.Entry(landPlot).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LandPlotExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public UpgradeHolder(LandPlot plot, HashSet <LandPlot.Upgrade> upgrades, int duration) { this.plot = plot; this.Spawned = DateTime.UtcNow; this.upgrades = new HashSet <LandPlot.Upgrade>(upgrades); this.Duration = duration; }
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); }
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); }
private void Start() { // Determine our ID if (!ID.Valid) { for (int i = 0; i < LandPlot.allPlots.Count; i++) { LandPlot plot = LandPlot.allPlots[i]; if (plot.gameObject == base.gameObject) { this.plot = plot; this.ID = new PlotID(plot); break; } } } if (plot == null) { throw new ArgumentNullException("Cannot locate LandPlot to apply upgrades!"); } // Apply all of our custom upgrades to the plot foreach (IUpgrade upgrade in upgrades) { upgrade.Apply(plot.gameObject); } }
private void Handle_Land_Plot_Destroyed() { LandPlot plot = base.gameObject.GetComponent <LandPlot>(); LandPlot.Id ID = plot ? plot.id : LandPlot.Id.NONE; object return_value = new object(); SiscosHooks.call(HOOK_ID.Destroyed_Land_Plot, plot, ref return_value, new object[] { ID }); }
internal static Sisco_Return Ext_Demolish_Plot_Upgrade(ref object sender, ref object[] args, ref object return_value) { #if !SR_VANILLA LandPlot.Id kind = Get_Plot_ID_From_Upgrades_UI_Class(sender); LandPlotUI ui = sender as LandPlotUI; LandPlot plot = ui.Get_LandPlot(); return(new Sisco_Return(SiscosHooks.call(HOOK_ID.Demolished_Land_Plot, plot, ref return_value, new object[] { kind }))); #else return(null); #endif }
static void Postfix(LandPlot __instance) { var g = __instance.gameObject; foreach (var upgrade in LandPlotUpgradeRegistry.moddedUpgraders) { if (upgrade.Item2 == __instance.typeId && !g.GetComponent(upgrade.Item1)) { g.AddComponent(upgrade.Item1); } } }
private static Sisco_Return onPlot_Demolished(ref object sender, ref object[] args, ref object return_value) { LandPlot.Id ID = (LandPlot.Id)args[0]; LandPlot plot = sender as LandPlot; PlotID id = new PlotID(plot); //SLog.Debug("Plot({0}){1} Demolished", ID, id); var track = plot.gameObject.GetComponent <PlotUpgradeTracker>(); track.Remove_All(); return(null); }
public async Task <ActionResult <LandPlot> > PostLandPlot(LandPlotRequest landPlotRequest) { LandPlot landPlot = landPlotRequest.LandPlot; string token = landPlotRequest.token; if (!Security.TokenIsValid(token)) { return(StatusCode(401)); } _context.LandPlots.Add(landPlot); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLandPlot", new { id = landPlot.Id }, landPlot)); }
// Methods protected override void Build() { // Get GameObjects Prefab = PrefabUtils.CopyPrefab(BaseItem); Prefab.name = NamePrefix + Name; GameObject uiAct = Prefab.transform.Find("techActivator/triggerActivate").gameObject; // Load Components LandPlot plot = Prefab.GetComponent <LandPlot>(); UIActivator activator = uiAct.GetComponent <UIActivator>(); // Setup Components plot.typeId = ID; activator.uiPrefab = UIPrefab ?? activator.uiPrefab; }
private static Sisco_Return onPlot_Loaded_Upgrades(ref object sender, ref object[] args, ref object return_value) { LandPlot plot = (LandPlot)sender; PlotID id = new PlotID(plot); Plot_Upgrades cached = Plot_Upgrades_Cache.FirstOrDefault(o => o.ID.Equals(id)); if (cached != null) { var track = plot.gameObject.AddComponent <PlotUpgradeTracker>(); track.Load(plot, cached); Plot_Upgrades_Cache.Remove(cached); } return(null); }
internal void Load(LandPlot pl, Plot_Upgrades up) { this.plot = pl; this.ID = new PlotID(plot); foreach (string upgradeName in up.upgrades) { PlotUpgrade upgrade = (PlotUpgrade)Upgrades.Get_Upgrade(Upgrade_Type.PLOT_UPGRADE, upgradeName); if (upgrade != null) { this.upgrades.Add(upgrade); } else { upgrades_missing.Add(upgradeName); } } }
/// <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); }
/// <summary> /// Removes the upgrades effects from the LandPlot /// </summary> public void Remove(LandPlot plot) { Remove(false, plot); }
static void Prefix() { if (Levels.IsLevel(Levels.WORLD) && SRInput.Instance.GetInputMode() == SRInput.InputMode.DEFAULT) { DateTime currentTime = DateTime.UtcNow; SceneContext sceneContext = SRSingleton <SceneContext> .Instance; Transform playerLoc = SceneContext.Instance.Player.transform; PlayerState playerState = SceneContext.Instance.PlayerState; RewardData reward; if (rewardsQueue.TryDequeue(out reward)) { switch (reward.action) { case "sound": break; case "inventory_bomb": Ammo ammo = playerState.Ammo; foreach (Slot s in (Slot[])Traverse.Create(ammo).Property("Slots").GetValue()) { if (s == null) { continue; } for (int i = 0; i < s.count; i++) { spawnObject(s.id, playerLoc); } } ammo.Clear(); break; case "meteor_shower": break; case "downgrade_plot": int duration; int.TryParse(reward.args[0], out duration); int numPlots; int.TryParse(reward.args[1], out numPlots); bool removeAllWalls; bool.TryParse(reward.args[2], out removeAllWalls); delayedDowngrades.Add(new DelayedDowngrade(numPlots, duration, removeAllWalls)); break; case "spawn_object": int objectID; int.TryParse(reward.args[0], out objectID); int ammount; int.TryParse(reward.args[1], out ammount); if (Enum.IsDefined(typeof(Identifiable.Id), objectID)) { Identifiable.Id obj = (Identifiable.Id)objectID; for (int i = 0; i < ammount; i++) { spawnObject(obj, playerLoc); } } else { Debug.LogError("Could not spawn in object with the ID of " + objectID + ". INVALID ID!"); } break; case "push_player": float pushMin = 0.1f; float.TryParse(reward.args[0], out pushMin); float pushMax = 0.3f; float.TryParse(reward.args[1], out pushMax); if (push) { pushData.left += 8; } else { push = true; pushData = new PushData(pushMin, pushMax, currentTime, 250); } break; case "adjust_money": int amountToAdjust; int.TryParse(reward.args[0], out amountToAdjust); if (amountToAdjust < 0) { if (playerState.GetCurrency() < amountToAdjust) { amountToAdjust = playerState.GetCurrency(); } playerState.SpendCurrency(amountToAdjust); } else { playerState.AddCurrency(amountToAdjust); } break; case "shoot_gun": WeaponVacuum vacuum = sceneContext.Player.GetComponentInChildren <WeaponVacuum>(); Traverse.Create(vacuum).Method("Expel", new HashSet <GameObject>()).GetValue(); break; case "day_night": float hour = sceneContext.TimeDirector.CurrHour(); if (hour > 6 && hour < 18) { sceneContext.TimeDirector.FastForwardTo(sceneContext.TimeDirector.GetHourAfter(0, 18f)); } else { sceneContext.TimeDirector.FastForwardTo(sceneContext.TimeDirector.GetNextDawn()); } break; case "stat_edit": string type = reward.args[0]; string action = reward.args[1]; int amount; int.TryParse(reward.args[2], out amount); if (type.Equals("health")) { switch (action) { case "add": playerState.SetHealth(Math.Min(playerState.GetCurrHealth() + amount, playerState.GetMaxHealth())); break; case "sub": playerState.SetHealth(Math.Max(playerState.GetCurrHealth() - amount, 1)); break; case "max": playerState.SetHealth(playerState.GetMaxHealth()); break; case "set": playerState.SetHealth(amount); break; } } else if (type.Equals("energy")) { switch (action) { case "add": playerState.SetEnergy(Math.Min(playerState.GetCurrEnergy() + amount, playerState.GetMaxEnergy())); break; case "sub": playerState.SetEnergy(Math.Max(playerState.GetCurrEnergy() - amount, 0)); break; case "max": playerState.SetEnergy(playerState.GetMaxEnergy()); break; case "set": playerState.SetEnergy(amount); break; } } else if (type.Equals("rads")) { switch (action) { case "add": playerState.SetRad(playerState.GetCurrRad() + amount); break; case "sub": playerState.SetRad(Math.Max(playerState.GetCurrRad() - amount, 0)); break; case "set": playerState.SetRad(amount); break; } } break; } } for (int i = plotsEdited.Count - 1; i >= 0; i--) { UpgradeHolder plot = plotsEdited[i]; if ((currentTime - plot.Spawned).TotalMilliseconds > plot.Duration) { plotsEdited.RemoveAt(i); plot.Reset(); } } if (push) { try { sceneContext.Player.transform.position += pushData.push; } catch { Debug.LogError("PLAYER (or related) IS NULL! Unable to push the player!"); } if ((currentTime - pushData.startTime).TotalMilliseconds > pushData.duration) { pushData.left--; if (pushData.left == 0) { push = false; } else { pushData.startTime = currentTime; pushData.nextPush(); } } } for (int i = delayedDowngrades.Count - 1; i >= 0; i--) { DelayedDowngrade dd = delayedDowngrades[i]; List <LandPlotModel> validplots = new List <LandPlotModel>(); //this.GetComponentInParent<Region>(); int corralPlots = 0; foreach (LandPlotModel plot in sceneContext.GameModel.AllLandPlots().Values) { if (plot.typeId == LandPlot.Id.CORRAL) { corralPlots++; if (Vector3.Distance(sceneContext.Player.transform.position, ((GameObject)Traverse.Create(plot).Field("gameObj").GetValue()).transform.position) < 100) { validplots.Add(plot); } } } if (corralPlots != 0 && validplots.Count == 0) { continue; } delayedDowngrades.RemoveAt(i); while (validplots.Count > 0 && dd.numPlots != 0) { LandPlotModel plotModel = validplots.ToArray()[UnityEngine.Random.Range(0, validplots.Count())]; validplots.Remove(plotModel); dd.numPlots--; LandPlot plot = ((GameObject)Traverse.Create(plotModel).Field("gameObj").GetValue()).GetComponentInChildren <LandPlot>(); HashSet <LandPlot.Upgrade> upgrades = new HashSet <LandPlot.Upgrade>(); foreach (PlotUpgrader component in plot.GetComponents <PlotUpgrader>()) { if (component is AirNetUpgrader && plot.HasUpgrade(LandPlot.Upgrade.AIR_NET)) { upgrades.Add(LandPlot.Upgrade.AIR_NET); foreach (GameObject airNet in ((AirNetUpgrader)component).airNets) { airNet.SetActive(false); } } else if (component is SolarShieldUpgrader && plot.HasUpgrade(LandPlot.Upgrade.SOLAR_SHIELD)) { upgrades.Add(LandPlot.Upgrade.SOLAR_SHIELD); foreach (GameObject shield in ((SolarShieldUpgrader)component).shields) { shield.SetActive(false); } } else if (component is WallUpgrader && plot.HasUpgrade(LandPlot.Upgrade.WALLS)) { upgrades.Add(LandPlot.Upgrade.WALLS); ((WallUpgrader)component).standardWalls.SetActive(!dd.removeAllWalls); ((WallUpgrader)component).upgradeWalls.SetActive(false); } plotsEdited.Add(new UpgradeHolder(plot, upgrades, dd.duration * 1000)); } } } } }
public bool Matches(LandPlot plot) { Vector3 plot_pos = plot.gameObject.transform.position; return(this.Matches(plot_pos)); }
public PlotID(LandPlot plot) { pos = plot.gameObject.transform.position; }