public static DODInstance AddRare(DODGroup group, Item src) { // Make a copy of the rare Item StoredItem = DupeItem(src); // Log the fact that we're about to move the item into storage LogHelper lh = new LogHelper("RareTemplateCreation.log", false, true); lh.Log(LogType.Item, StoredItem); lh.Finish(); // Store the copy away StoredItem.MoveItemToIntStorage(); // Instance the DOD on this copy DODInstance di = new DODInstance(StoredItem); // Add a new DOD instance based on the item passed m_DODInst.Add(di); // Add a reference to our active group group.DODInst.Add(di); return(di); }
// Expire the rare public void Expire() { // Log this deletion before we lose all the associated data :P LogHelper lh = new LogHelper("RareExpiration.log", false, true); lh.Log(LogType.Item, this.RareTemplate, string.Format("{0}", this.Name)); lh.Finish(); // Delete the "in storage" rare this.RareTemplate.Delete(); // Find it in the group lists + remove for (int i = 0; i < RareFactory.DODGroup.Count; i++) { DODGroup dg = (DODGroup)RareFactory.DODGroup[i]; for (int ir = 0; ir < dg.DODInst.Count; ir++) { if (((DODInstance)dg.DODInst[ir]) == this) { // There should never be more than one of these right? dg.DODInst.RemoveAt(ir); break; } } } // Find it in the main rare list + remove for (int i = 0; i < RareFactory.DODInst.Count; i++) { DODInstance di = (DODInstance)RareFactory.DODInst[i]; if (di == this) { // There should never be more than one of these right? RareFactory.DODInst.RemoveAt(i); break; } } }
private static Item _AcquireRare(short iRarity, string sGroupName) { try { // Make sure the RareFactory is available. Send a message back instead of a rare if it is not. ArrayList matches = new ArrayList(); if (m_Available) { // Search the DODInstance definitions // for ones matching this type of object for (int i = 0; i < m_DODGroup.Count; i++) { DODGroup dg = (DODGroup)m_DODGroup[i]; // Validate group name if (sGroupName != "") { bool match = false; // Parse the group name. If it contains commas, we need to split by comma if (sGroupName.Contains(",")) { // Multiple group names string[] gnames = sGroupName.Split(','); for (int gi = 0; gi < gnames.Length; gi++) { if (gnames[gi].ToLower() == dg.Name.ToLower()) { match = true; } } } else { // Single group name if (sGroupName.ToLower() == dg.Name.ToLower()) { match = true; } } if (match == false) { continue; // next group } } for (int di = 0; di < dg.DODInst.Count; di++) { DODInstance dinst = (DODInstance)dg.DODInst[di]; if (dinst.Valid) { if (dg.Rarity == iRarity) { if (dinst.RareTemplate == null) { try { throw new ApplicationException("AcquireRare: dinst.RareTemplate == null"); } catch (Exception ex) { LogHelper.LogException(ex); } } matches.Add(dinst); } } } } } // the boobie prize if (!m_Available || matches.Count == 0) { return(new Rocks()); } // Choose one of these types randomly // and generate the object (also dynamically // fills the object's strings) return(GenerateDODObject((DODInstance)matches[Utility.Random(matches.Count)])); } catch (Exception ex) { // failsafe LogHelper.LogException(ex); return(new Rocks()); } }
private static short FactoryLoad() { m_DODInst = new ArrayList(); m_DODGroup = new ArrayList(); string filePath = Path.Combine("Saves/AngelIsland", "RareFactory.dat"); if (!File.Exists(filePath)) { Console.WriteLine("FactoryLoad() : RareFactory.dat does not exist, assuming new factory"); return(1); // Assume new factory } using (FileStream sr = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (!sr.CanRead) { Console.WriteLine("FactoryLoad() : {0} is not readable but exists!!", filePath); return(0); } // This is the stream reader we will read our binary DOD data with BinaryFileReader bfr = new BinaryFileReader(new BinaryReader(sr)); bfr.Seek(0, SeekOrigin.Begin); try { // Just in case we change the save format sometime! short version = ((GenericReader)bfr).ReadShort(); int numtoload = ((GenericReader)bfr).ReadShort(); Console.WriteLine("FactoryLoad() : Loading {0} Dynamic Object Definition{1}...", numtoload, (numtoload != 1 ? "s" : "")); // Instance the DODs with the bfr pointer (the object constructor handles in file input) for (int i = 0; i < numtoload; i++) { m_DODInst.Add(new DODInstance(bfr)); } numtoload = ((GenericReader)bfr).ReadShort(); Console.WriteLine("FactoryLoad() : Loading {0} DOD Group{1}...", numtoload, (numtoload != 1 ? "s" : "")); for (int i = 0; i < numtoload; i++) { DODGroup dg = new DODGroup(bfr); // Save this group list m_DODGroup.Add(dg); } } catch (Exception e) { Console.WriteLine("FactoryLoad() : Caught exception trying to load DODs : {0}", e); LogHelper.LogException(e); } bfr.Close(); } // 'using' closes sr Console.WriteLine("FactoryLoad() : Complete."); return(1); }
public static DODInstance AddRare(DODGroup group, Item src) { // Make a copy of the rare Item StoredItem = DupeItem(src); // Log the fact that we're about to move the item into storage LogHelper lh = new LogHelper("RareTemplateCreation.log", false, true); lh.Log(LogType.Item, StoredItem); lh.Finish(); // Store the copy away StoredItem.MoveItemToIntStorage(); // Instance the DOD on this copy DODInstance di = new DODInstance(StoredItem); // Add a new DOD instance based on the item passed m_DODInst.Add(di); // Add a reference to our active group group.DODInst.Add(di); return di; }
private static short FactoryLoad() { m_DODInst = new ArrayList(); m_DODGroup = new ArrayList(); string filePath = Path.Combine("Saves/AngelIsland", "RareFactory.dat"); if (!File.Exists(filePath)) { Console.WriteLine("FactoryLoad() : RareFactory.dat does not exist, assuming new factory"); return 1; // Assume new factory } using (FileStream sr = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (!sr.CanRead) { Console.WriteLine("FactoryLoad() : {0} is not readable but exists!!", filePath); return 0; } // This is the stream reader we will read our binary DOD data with BinaryFileReader bfr = new BinaryFileReader(new BinaryReader(sr)); bfr.Seek(0, SeekOrigin.Begin); try { // Just in case we change the save format sometime! short version = ((GenericReader)bfr).ReadShort(); int numtoload = ((GenericReader)bfr).ReadShort(); Console.WriteLine("FactoryLoad() : Loading {0} Dynamic Object Definition{1}...", numtoload, (numtoload != 1 ? "s" : "")); // Instance the DODs with the bfr pointer (the object constructor handles in file input) for (int i = 0; i < numtoload; i++) m_DODInst.Add(new DODInstance(bfr)); numtoload = ((GenericReader)bfr).ReadShort(); Console.WriteLine("FactoryLoad() : Loading {0} DOD Group{1}...", numtoload, (numtoload != 1 ? "s" : "")); for (int i = 0; i < numtoload; i++) { DODGroup dg = new DODGroup(bfr); // Save this group list m_DODGroup.Add(dg); } } catch (Exception e) { Console.WriteLine("FactoryLoad() : Caught exception trying to load DODs : {0}", e); LogHelper.LogException(e); } bfr.Close(); } // 'using' closes sr Console.WriteLine("FactoryLoad() : Complete."); return 1; }