// Adds an InvItem, given an InvName, quantity, and whether it is to persist at zero public virtual void AddInvItem(InvNames name, int quantity, bool persist = false) { // If the item isn't already there, create a new item and add it to the inventory if (!names.Contains(name)) { contents.Add(InvData.MakeNewInvItem(name, persist)); contents[contents.Count - 1].Quantity = quantity; names.Add(name); SortInventory(); } else { // If the Inventory already contains this items, just increase the quantity // If a quantity of -1 is passed, the quantity "increases" to "Unlimited" if (quantity < 0) { contents[names.IndexOf(name)].Quantity = -1; // -1 for "Unlimited" } else { // If quantity is already -1, leave it at -1, but add quantity if >= 0 if (contents[names.IndexOf(name)].Quantity >= 0) { contents[names.IndexOf(name)].Quantity += quantity; } } } }
/* * Market.UpdateMarketGroups(); * Market.UpdateMarketValues(); * //Market.UpdateRegionMarket(999); * Market.UpdateRegionMarket(10000030); * List<long> orderIDs = Market.GetOrdersForTypeAndRegion(34, 10000030); * Market.MarketOrder order = Market.GetOrder(orderIDs[0]); * Sovereignty.UpdateStructures(); * Sovereignty.Structure str = Sovereignty.GetStructure(1035629924); * Sovereignty.UpdateMap(); * Sovereignty.Map map = Sovereignty.GetMap(30000721); */ public static void pathTest() { // Will only work after loading successful. DateTime s = DateTime.Now; SolarSystem start = SolarSystem.GetSystem(30002510); List <int> path = start.FindPath(30000142, true); if (path == null) { System.Diagnostics.Debug.WriteLine("Path not found."); } else { System.Diagnostics.Debug.WriteLine(path.Count + " jumps."); foreach (int systemID in path) { //SolarSystem system = SolarSystem.getSystem(systemID); System.Diagnostics.Debug.WriteLine(systemID + ": " + InvNames.GetName(systemID)); } } DateTime f = DateTime.Now; TimeSpan ts = f - s; System.Diagnostics.Debug.WriteLine("Path test took: " + ts.TotalMilliseconds + " ms"); }
// Gives all inventory items mentioned in InvNames the statistics of a tiny health potion. // Used only in case of a read error. void SetInvDataDefaultValues() { invStatData.Clear(); foreach (InvNames name in InvNames.GetValues(typeof(InvNames))) { invStatData.Add(name, new InvItem(InvNames.Potion_Health_Tiny, "default fullname", "default description", Resources.Load <Sprite>(@"Sprites\InvItems\Potion\Health\" + name.ToString()), 1, 0, 0, InvType.Potion, InvSubtype.Health, EquipSlots.none, 1)); } }
// Retrieve a reference to an item, but do not remove it. public InvItem GetItem(InvNames name) { if (names.Contains(name)) { return(contents[names.IndexOf(name)]); } else { return(null); } }
private void PopulateOrders(int typeID, int regionID) { List <Market.MarketOrder> orders; if (regionID > 0) { orders = Market.GetOrdersForTypeAndRegion(typeID, regionID); } else if (regionID == 0) { // No region selected, leave empty. return; } else { // All regions selected orders = Market.GetOrdersForType(typeID); } string[] selCols = new string[4]; string[] buyCols = new string[6]; foreach (Market.MarketOrder order in orders) { TimeSpan expiresIn = new TimeSpan(order.duration, 0, 0, 0) - (DateTime.Now - order.issued); string expireStr = expiresIn.Days.ToString() + "D " + expiresIn.Hours.ToString() + "H " + expiresIn.Minutes.ToString() + "M " + expiresIn.Seconds.ToString() + "S"; string locationStr = InvNames.GetName((int)order.location_id); if (locationStr == null) { // Get structure name. // TO-DO: locationStr = "Structure: " + order.location_id.ToString(); } if (order.is_buy_order) { buyCols[0] = order.volume_remain.ToString(); buyCols[1] = order.price.ToString("N2"); buyCols[2] = locationStr; buyCols[3] = order.range; buyCols[4] = order.min_volume.ToString(); buyCols[5] = expireStr; ListViewItem item = new ListViewItem(buyCols); marketBuyersList.Items.Add(item); } else { selCols[0] = order.volume_remain.ToString(); selCols[1] = order.price.ToString("N2"); selCols[2] = locationStr; selCols[3] = expireStr; ListViewItem item = new ListViewItem(selCols); marketSellersList.Items.Add(item); } } }
// Override for Inventory.RemoveInvItem(). Empties the relevant slot, then base.RemoveInvItem() public override void RemoveInvItem(InvNames name, int quantity) { EquipSlots removeSlot = InvData.Data[name].Slot; if (slots.ContainsKey(removeSlot)) { slots.Remove(removeSlot); base.RemoveInvItem(name, quantity); } else { Debug.Log(removeSlot.ToString() + " slot is empty."); } }
// Override for Inventory.AddInvItem(). Assigns the item to the slot, then base.AddInvItem() public override void AddInvItem(InvNames name, int quantity, bool persist = false) { EquipSlots addSlot = InvData.Data[name].Slot; if (slots.ContainsKey(addSlot)) { Debug.Log(addSlot.ToString() + " slot already occupied."); } else { slots.Add(addSlot, name); base.AddInvItem(name, quantity, persist); } }
public InvItem(InvNames name, string fullName, string description, Sprite sprite, int id, int price, int quantity, InvType type, InvSubtype subtype, EquipSlots slot, int rank, bool persist = false) { Name = name; FullName = fullName; Description = description; Sprite = sprite; ID = id; Price = price; Quantity = quantity; Type = type; Subtype = subtype; Slot = slot; Rank = rank; PersistAtZero = persist; }
/// <summary> /// Sets the panel's display /// </summary> /// <param name="item">The InvItem in SHop.Stock that the panel represents</param> /// <param name="held">The quantity held in the partyStash</param> public void SetPanel(InvItem item, int held) { // Use info from the InvItem in Shop.Stock to store locally itemName = item.Name; icon.sprite = item.Sprite; nameText.text = item.FullName; descriptionText.text = item.Description; cost = item.Price; stock = item.Quantity; // Use provided int as the number held by the party this.held = held; // Update the display with stored variables RefreshPanel(); }
/// <summary> /// Alter BattleStats when equipping an item. /// Also called when using for tomes. /// All items have BattleStats. /// </summary> /// <param name="name">the item to equip as an InvNames</param> public void Equip(InvNames name) { // First: Calculate new stats // retrieve bstats of item to remove, if one exists. If not, remains null. BattleStats remove = null; InvItem returnToStashItem = null; // compare kind of equip item to all the equipped items foreach (InvItem item in Equipment.Contents) { if (item.Slot == InvData.Data[name].Slot) { remove = ((InvEqItem)InvData.Data[item.Name]).BStats; returnToStashItem = item; break; } } // retrieve bstats of item to add BattleStats add = (InvData.Data[name] as InvEqItem).BStats; // Reduce hero stats by the remove InvItem (if not null). Increase by the add InvItem. BStats.Equip(add, remove); // Second: move items from inventories // remove 1 of EQUIPPED item from partyStash if (BattleLoader.Party.Inventory.ContainsItem(name)) { BattleLoader.Party.Inventory.RemoveInvItem(name, 1); } // remove UNEQUIPPED item from Equipment, add 1 to partyStash if (returnToStashItem != null) { Equipment.RemoveInvItem(returnToStashItem.Name, 1); BattleLoader.Party.Inventory.AddInvItem(returnToStashItem.Name, 1); } // add EQUIPPED item to hero's Equipment Equipment.AddInvItem(name, 1); }
/// <summary> /// Creates a *new* InvItem, using only InvNames. Anything other than a potion has a BattleStats /// included, and thus is also an InvEqItem. If the item is to remain in the inventory even when /// at zero quantity, pass in persist=true. This occurs for the Shop inventory when out-of-stock. /// /// This method is necessary, otherwise all inventories will reference only one of each kind of /// item, stored here. /// </summary> /// <param name="name">InvNames name of the item to be created.</param> /// <param name="persist">Whether the InvItem will persist in the Inventory at Quantity = 0.</param> /// <returns></returns> public static InvItem MakeNewInvItem(InvNames name, bool persist = false) { // Potions do not require BattleStats, and are not InvEqItems. if (Data[name].Type == InvType.Potion) { InvItem orig = InvData.Data[name]; InvItem newItem = new InvItem(name, orig.FullName, orig.Description, orig.Sprite, orig.ID, orig.Price, orig.Quantity, orig.Type, orig.Subtype, orig.Slot, orig.Rank, persist); return(newItem); } else { // InvEqItem includes tomes and equipment. InvEqItem orig = (InvEqItem)InvData.Data[name]; InvEqItem newItem = new InvEqItem(name, orig.FullName, orig.Description, orig.Sprite, orig.ID, orig.Price, orig.Quantity, orig.Type, orig.Subtype, orig.Slot, orig.Rank, orig.BStats, persist); return(newItem); } }
// Removes an InvItem from the Inventory, given a name and a quantity. public virtual void RemoveInvItem(InvNames name, int quantity) { // Only proceed if the item exists in the inventory if (names.Contains(name)) { // Find the index of the InvItem by referencing names int index = names.IndexOf(name); InvItem invItem = contents[index]; // If existing quantity is -1, it is unlimited, and cannot be deducted from. // Only remove or deduct if 0 or greater if (invItem.Quantity < 0) { // The quantity doesn't change when < 0 } else { // If the deduction of quantity would result in a zero or less Quantity if (invItem.Quantity - quantity <= 0) { if (invItem.PersistAtZero) { // The item persists, and the (shop) inventory has quantity of the item invItem.Quantity = 0; } else { // Fully remove item from the inventory, because it becomes 0 or less. contents.RemoveAt(index); names.RemoveAt(index); } } else { // Deduct from inventory, but leave a remainder of 1+ behind invItem.Quantity -= quantity; } } // No sort is required because the order only changes when adding. } }
// Provides the index of an item in both contents and names public int IndexOfItem(InvNames name) { return(names.IndexOf(name)); }
// Whether or not the Inventory contains an item. Returns true even if Quantity = 0. public bool ContainsItem(InvNames name) { return(names.Contains(name)); }
/// <summary> /// Reads configuration data from a file. If the file read fails, the constructor contains /// default values for each kind of configuration data /// REFACTOR: Break this into three different constructors /// </summary> public ConfigData(ConfigDataType type) { // Read and save configuration data from file StreamReader input = null; // Three kinds of ConfigData switch (type) { case ConfigDataType.EnemyData: #region EnemyData try { // Create stream reader input input = File.OpenText(Path.Combine( Application.streamingAssetsPath, EnemyDataFileName)); // Populate StatNames from header row string currentLine = input.ReadLine(); string[] names = currentLine.Split(','); BattleStatNames[] statHeader = new BattleStatNames[names.Length]; // Validate the header row before importing BattleStats validate = new BattleStats(); for (int i = 1; i < names.Length; i++) { statHeader[i] = (BattleStatNames)Enum.Parse(typeof(BattleStatNames), names[i]); if (!validate.ValidateOrder(i - 1, statHeader[i])) { errorMessage = "Headers do not match BattleStats.\nUsing default settings."; Debug.Log(errorMessage); SetEnemyStatDataDefaultValues(); break; } } // Only procede forward if there is no error with the headers if (errorMessage == null) { // Populate values for enemyData currentLine = input.ReadLine(); while (currentLine != null) { // Parse current line into name and stat values string[] tokens = currentLine.Split(','); EnemyName enemyName = (EnemyName)Enum.Parse( typeof(EnemyName), tokens[0]); int[] intTokens = new int[tokens.Length - 1]; for (int i = 0; i < tokens.Length - 1; i++) { int bStat; intTokens[i] = int.TryParse(tokens[i + 1], out bStat) ? bStat : 0; } // import the array of ints into a new BattleStats BattleStats battleStats = new BattleStats(); battleStats.Import(intTokens); // add to enemyStatData enemyStatData.Add(enemyName, battleStats); // queue next line in csv currentLine = input.ReadLine(); } } } catch (Exception e) { // send the error to the console for debugging Debug.Log(e); errorMessage = "Problem loading file. \nUsing default settings.\n"; Debug.Log(errorMessage); SetEnemyStatDataDefaultValues(); } finally { // close files that were opened if (input != null) { input.Close(); } } break; // end of EnemyData #endregion EnemyData case ConfigDataType.InvData: #region InvData try { // create stream reader input input = File.OpenText(Path.Combine( Application.streamingAssetsPath, InvDataFileName)); // populate StatNames from header row string currentLine = input.ReadLine(); string[] headings = currentLine.Split(','); BattleStatNames[] statHeader = new BattleStatNames[headings.Length]; // Validate the header row before importing // 0 name, 1 fullname, 2 description, 3 id, 4 price, 5 type, 6 subtype, 7 slot, // 8 rank, 9+ Battlestats BattleStats validate = new BattleStats(); for (int i = 9; i < headings.Length; i++) { statHeader[i] = (BattleStatNames)Enum.Parse(typeof(BattleStatNames), headings[i]); if (!validate.ValidateOrder(i - 9, statHeader[i])) { errorMessage = "Headers do not match BattleStats.\nUsing default settings."; Debug.Log(errorMessage); SetInvDataDefaultValues(); break; } } // only procede forward if there is no error with the headers if (errorMessage == null) { // populate values for enemyData currentLine = input.ReadLine(); while (currentLine != null) { // parse current line into name and stat values // 0 name, 1 fullname, 2 description, 3 id, 4 price, 5 type, 6 subtype, 7 slot, 8 rank // 0 name string[] tokens = currentLine.Split(','); InvNames invName = (InvNames)Enum.Parse( typeof(InvNames), tokens[0]); // 1 fullname string fullName = tokens[1]; // 2 description string description = tokens[2]; // 3 id int id = int.Parse(tokens[3]); // 4 price int price = int.Parse(tokens[4]); // 5 type InvType invType = (InvType)Enum.Parse( typeof(InvType), tokens[5]); // 6 subtype InvSubtype invSubtype = (InvSubtype)Enum.Parse( typeof(InvSubtype), tokens[6]); Sprite sprite = Resources.Load <Sprite>(@"Sprites\InvItems\" + invType.ToString() + @"\" + invSubtype.ToString() + @"\" + invName.ToString()); // 7 slot EquipSlots slot = (EquipSlots)Enum.Parse( typeof(EquipSlots), tokens[7]); // 8 rank int rank = int.Parse(tokens[8]); // BattleStats is only included for InvEqItems (equipment and tomes) // This is an InvEqItem if (invType == InvType.Tome || invType == InvType.Weapon || invType == InvType.Armor) { // 9+ BattleStats int[] intTokens = new int[tokens.Length - 9]; for (int i = 0; i < tokens.Length - 9; i++) { int bStat; intTokens[i] = int.TryParse(tokens[i + 9], out bStat) ? bStat : 0; } // import the array of ints into a new BattleStats BattleStats battleStats = new BattleStats(); battleStats.Import(intTokens); // create a new InvEqItem InvEqItem item = new InvEqItem(invName, fullName, description, sprite, id, price, 0, invType, invSubtype, slot, rank, battleStats); // add to invStatData invStatData.Add(invName, item); } // else it is a potion, so add a regular InvItem else { // create a new InvEqItem InvItem item = new InvItem(invName, fullName, description, sprite, id, price, 0, invType, invSubtype, slot, rank); // add to invStatData invStatData.Add(invName, item); } // queue next line in csv currentLine = input.ReadLine(); } } } catch (Exception e) { // send the error to the console for debugging Debug.Log(e); errorMessage = "Problem loading file. \nUsing default settings.\n"; Debug.Log(errorMessage); SetInvDataDefaultValues(); } finally { // close files that were opened if (input != null) { input.Close(); } } break; #endregion InvData case ConfigDataType.AbilityData: #region AbilityData try { // create stream reader input input = File.OpenText(Path.Combine( Application.streamingAssetsPath, AbilityDataFileName)); // populate StatNames from header row string currentLine = input.ReadLine(); string[] headings = currentLine.Split(','); // ignoring the header row // populate values for abilityData currentLine = input.ReadLine(); while (currentLine != null) { // parse current line into name and stat values // 0 name, 1 isPhysical, 2 mp, 3 noReduction, 4 modifier, // 5 noMiss, 6 hitOverride, 7 noCrit // 0 name string[] tokens = currentLine.Split(','); BattleMode name = (BattleMode)Enum.Parse( typeof(BattleMode), tokens[0]); // 1 isPhyical bool isPhysical = bool.Parse(tokens[1].ToLower()); // 2 mp int?mp = null; if (int.TryParse(tokens[2], out int num)) { mp = num; } else { mp = null; } // 3 noReduction bool noReduction = bool.Parse(tokens[3].ToLower()); // 4 modifier float modifier = float.Parse(tokens[4]); // 5 noMiss bool noMiss = bool.Parse(tokens[5].ToLower()); // 6 hitOverride int?hitOverride = null; if (int.TryParse(tokens[6], out int num2)) { hitOverride = num2; } else { hitOverride = null; } // 7 noCrit bool noCrit = bool.Parse(tokens[7].ToLower()); // create a new battleAbility BattleAbility ability = new BattleAbility(name, isPhysical, mp, noReduction, modifier, noMiss, hitOverride, noCrit); // add to invStatData abilityStatData.Add(name, ability); // queue next line in csv currentLine = input.ReadLine(); } } catch (Exception e) { // send the error to the console for debugging Debug.Log(e); errorMessage = "Problem loading file. \nUsing default settings.\n"; Debug.Log(errorMessage); SetAbilityDataDefaultValues(); } finally { // close files that were opened if (input != null) { input.Close(); } } break; #endregion AbilityData default: break; } }
public InvEqItem(InvNames name, string fullName, string description, Sprite sprite, int id, int price, int quantity, InvType type, InvSubtype subtype, EquipSlots slot, int rank, BattleStats stats, bool persist = false) : base(name, fullName, description, sprite, id, price, quantity, type, subtype, slot, rank, persist) { BStats = stats; }