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 static void Load_Plot_Upgrades(string fileName) { // LOAD PLOT UPGRADES if (File.Exists(fileName)) { Stream strm = File.OpenRead(fileName); if (strm == null) { throw new IOException("Cannot open file for reading: " + fileName); } BinaryReader br = new BinaryReader(strm); int total = br.ReadInt32(); for (int i = 0; i < total; i++) { Plot_Upgrades up = Plot_Upgrades.Deserialize(br); Plot_Upgrades_Cache.Add(up); } // Load the upgrade data cache int pidTotal = br.ReadInt32(); for (int p = 0; p < pidTotal; p++) { PlotID pid = PlotID.Deserialize(br); int upgrTotal = br.ReadInt32(); for (int u = 0; u < upgrTotal; u++) { string upgrade = br.ReadString(); int kTotal = br.ReadInt32(); // Make sure we can add keys/values without issue. Setup_Upgrade_Data_Dict(pid, upgrade); for (int k = 0; k < kTotal; k++) { string key = br.ReadString(); int blen = br.ReadInt32(); byte[] value = br.ReadBytes(blen); //PLog.Info("[{0}][{1}] [{2}]: ({3}){4}", pid, upgrade, key, blen, Util.FormatByteArray(value)); if (!Plot_Upgrade_Data[pid][upgrade].ContainsKey(key)) { Plot_Upgrade_Data[pid][upgrade].Add(key, value); } else { Plot_Upgrade_Data[pid][upgrade][key] = value; } } } } strm.Close(); } }
public static void Serialize(BinaryWriter bw, PlotID id, List <string> list) { //PLog.Info("PlotUpgrades: {0} | Writing {1} plot upgrades", id, list.Count); id.Serialize(bw); bw.Write((int)list.Count); foreach (string str in list) { bw.Write(str); } }
private static void Setup_Upgrade_Data_Dict(PlotID pid, string upgradeName) { if (!Plot_Upgrade_Data.ContainsKey(pid)) { Plot_Upgrade_Data.Add(pid, new Dictionary <string, Dictionary <string, byte[]> >()); } if (!Plot_Upgrade_Data[pid].ContainsKey(upgradeName)) { Plot_Upgrade_Data[pid].Add(upgradeName, new Dictionary <string, byte[]>()); } }
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 static void Clear_Upgrade_Data(PlotID pid, string upgradeName) { if (!Plot_Upgrade_Data.ContainsKey(pid)) { return; } if (!Plot_Upgrade_Data[pid].ContainsKey(upgradeName)) { return; } Plot_Upgrade_Data[pid].Remove(upgradeName); }
public static void Write_Upgrade_Data_Value(PlotID pid, string upgradeName, string key, byte[] value) { Setup_Upgrade_Data_Dict(pid, upgradeName); if (!Plot_Upgrade_Data[pid][upgradeName].ContainsKey(key)) { Plot_Upgrade_Data[pid][upgradeName].Add(key, value); } else { Plot_Upgrade_Data[pid][upgradeName][key] = value; } //PLog.Info("SET => [{0}][{1}] [{2}]: ({3}){4}", pid, upgradeName, key, value.Length, Util.FormatByteArray(value)); }
public static Plot_Upgrades Deserialize(BinaryReader br) { PlotID id = PlotID.Deserialize(br); List <string> list = new List <string>(); int num = br.ReadInt32();//the number of upgrade strings this list has for (int i = 0; i < num; i++) { list.Add(br.ReadString()); } return(new Plot_Upgrades() { ID = id, upgrades = list }); }
private static void Save_Plot_Upgrades(string fileName) { string tempFile = String.Concat(fileName, ".tmp"); Stream strm = File.OpenWrite(tempFile); if (strm == null) { throw new IOException("Cannot open file for writing: " + fileName); } BinaryWriter bw = new BinaryWriter(strm); bw.Write((int)PlotUpgradeTracker.allTrackers.Count); foreach (PlotUpgradeTracker tracker in PlotUpgradeTracker.allTrackers) { tracker.Serialize(bw); } bw.Write((int)Plot_Upgrade_Data.Count); // Write all of the plot's upgrades' set data values foreach (var plot_kvp in Plot_Upgrade_Data) { PlotID plot = plot_kvp.Key; plot.Serialize(bw); bw.Write((int)plot_kvp.Value.Count); foreach (var upgr_kvp in plot_kvp.Value) { string upgrade = upgr_kvp.Key; bw.Write(upgrade); bw.Write((int)upgr_kvp.Value.Count); foreach (var kvp in upgr_kvp.Value) { bw.Write((string)kvp.Key); bw.Write((int)kvp.Value.Length); bw.Write(kvp.Value); } } } strm.Close(); File.Copy(tempFile, fileName, true); File.Delete(tempFile); }
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); }
public static bool Has_Upgrade_Data_Value(PlotID pid, string upgradeName, string key) { if (!Plot_Upgrade_Data.ContainsKey(pid)) { return(false); } if (!Plot_Upgrade_Data[pid].ContainsKey(upgradeName)) { return(false); } if (!Plot_Upgrade_Data[pid][upgradeName].ContainsKey(key)) { return(false); } return(Plot_Upgrade_Data[pid][upgradeName].ContainsKey(key)); }
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); }
public static byte[] Read_Upgrade_Data_Value(PlotID pid, string upgradeName, string key) { if (!Plot_Upgrade_Data.ContainsKey(pid)) { return(null); } if (!Plot_Upgrade_Data[pid].ContainsKey(upgradeName)) { return(null); } if (!Plot_Upgrade_Data[pid][upgradeName].ContainsKey(key)) { return(null); } byte[] buf = null; if (!Plot_Upgrade_Data[pid][upgradeName].TryGetValue(key, out buf)) { return(null); } return(buf); }
public Plot_Upgrade_Data(PlotID id, string upgrName) { pid = id; upgradeName = upgrName; }
public override bool Equals(object obj) { PlotID B = obj as PlotID; return(Matches(B.pos.Value)); }
public static void Write_Upgrade_Data_Value(PlotID pid, PlotUpgrade upgrade, string key, byte[] value) { Write_Upgrade_Data_Value(pid, upgrade.ID, key, value); }