public void saveInventory() { List <ItemAbstract> items = new List <ItemAbstract>(); foreach (string key in inventory.Keys) { ItemAbstract item = ItemDefinitions.stringToItem(key); for (int i = 0; i < inventory[key]; i++) { items.Add(item); } } ItemDefinitions.saveItems(uniqueId, ItemDefinitions.itemsToString(items)); /* * string invSlotLabel = uniqueId + "InventorySlotLabel[Weapon]"; * for (int i = 0; i < WeaponItem.numWeaponTypes; i++) * { * string currLabel = invSlotLabel + i.ToString(); * print("Saving weapon item: " + i + " and num = " + numOfEachWeapItem[i]); * UnityEngine.PlayerPrefs.SetInt(currLabel, numOfEachWeapItem[i]); * } * invSlotLabel = uniqueId + "InventorySlotLabel[Engine]"; * for (int i = 0; i < EngineItem.numEngineTypes; i++) * { * string currLabel = invSlotLabel + i.ToString(); * print("Saving engine item: " + i + " and num = " + numOfEachEngItem[i]); * UnityEngine.PlayerPrefs.SetInt(currLabel, numOfEachEngItem[i]); * } */ }
private void ItemDefinitions_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { foreach (var item in e.NewItems) { if (item is CommandBarItemDefinition itemDefinition) { if (ExcludedCommandDefinitions.Any( x => x.GetType() == itemDefinition.CommandDefinition.GetType())) { ItemDefinitions.Remove(itemDefinition); continue; } if (!itemDefinition.Group.Items.Contains(itemDefinition)) { itemDefinition.Group.Items.AddSorted(itemDefinition, new SortOrderComparer <CommandBarDefinitionBase>()); } } } } if (e.OldItems != null) { foreach (var item in e.OldItems) { if (item is CommandBarItemDefinition itemDefinition) { itemDefinition.Group.Items.Remove(itemDefinition); } } } }
private void ItemGroupDefinitions_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { foreach (var item in e.NewItems) { if (item is CommandBarGroupDefinition groupDefinition) { var items = ItemDefinitions.Where(x => x.Group == groupDefinition); foreach (var itemDefinition in items) { if (!groupDefinition.Items.Contains(itemDefinition)) { groupDefinition.Items.AddSorted(itemDefinition, new SortOrderComparer <CommandBarDefinitionBase>()); } } } } } if (e.OldItems != null) { foreach (var item in e.OldItems) { if (item is CommandBarGroupDefinition groupDefinition) { groupDefinition.Parent.ContainedGroups.Remove(groupDefinition); groupDefinition.Items.Clear(); } } } }
static void drawToolTip(ref Item hoveredItem) { // replace the hoveredItem with a wrapper class which allows us to // control Item.getExtraSpaceNeededForTooltipSpecialIcons if (hoveredItem != null) { // The "Trimmed Lucky Purple Shorts" from Major Lewis's quest are not an actual clothing item if (hoveredItem.Category == 0 && hoveredItem.ParentSheetIndex == 71) { hoveredItem = ShimTrimmedLuckPurpleShorts; } } if (ItemDefinitions.GetEffect(hoveredItem, out IEffect effect)) { if (hoveredItem is Clothing clothing) { clothingDrawWrapper.Assign(clothing, effect); hoveredItem = clothingDrawWrapper; } else if (hoveredItem is StardewValley.Objects.Hat hat) { hatDrawWrapper.Assign(hat, effect); hoveredItem = hatDrawWrapper; } } }
// Use this for initialization void Start() { gameObject.AddComponent <TargetFinder>(); faction = ShipDefinitions.stringToFaction(gameObject.tag); // bad guys use red lasers, good guys use blue? if (faction == ShipDefinitions.Faction.Enemy) { color1 = Color.red; color2 = Color.yellow; } if (testItem != "") { ItemAbstract testThing = ItemDefinitions.stringToItem(testItem); applyBuff(testThing); } /* * GameObject firingSprite = GameObject.Find("GameLogic") * .GetComponent<PrefabHost>().getFiringSpriteObject(); * firingSprite.transform.parent = gameObject.transform; * firingSprite.transform.position = new Vector3( * gameObject.transform.position.x, * gameObject.transform.position.y - 0.07f, * gameObject.transform.position.z); * firingSprite.GetComponent<FiringSprite>() * .setSprite(faction, "crown"); */ timer = GameObject.Find("GameLogic").GetComponent <Timer>(); timer.addTimer(this.GetInstanceID()); }
// Use this for initialization void Start() { ShipDefinitions.Faction faction = ShipDefinitions.stringToFaction(gameObject.tag); projectile = GameObject.Find("GameLogic").GetComponent <PrefabHost>().getMissileObject(); projectile.GetComponent <HomingMissile>().setDamage(20); projectile.GetComponent <HomingMissile>().setLifetime(25); if (testItem != "") { ItemAbstract testThing = ItemDefinitions.stringToItem(testItem); applyBuff(testThing); } /* * GameObject firingSprite = GameObject.Find("GameLogic") * .GetComponent<PrefabHost>().getFiringSpriteObject(); * firingSprite.transform.parent = gameObject.transform; * firingSprite.transform.position = new Vector3( * gameObject.transform.position.x, * gameObject.transform.position.y - 0.07f, * gameObject.transform.position.z); * firingSprite.GetComponent<FiringSprite>() * .setSprite(faction, "crown"); */ timer = GameObject.Find("GameLogic").GetComponent <Timer>(); timer.addTimer(this.GetInstanceID()); timer.addTimer(this.GetInstanceID() + 1); }
public void OnDrop(PointerEventData eventData) { Debug.Log("onDrop is called"); if (!draggedObject) { // check if slot has an item already GameObject obj = GameObject.Instantiate(dragHandler.draggedObject.gameObject); obj.GetComponent <IconHandler>().setNum(1); // check if slot has an item already obj.transform.SetParent(transform); dragHandler.draggedObject.GetComponent <IconHandler>() .decOne(); ItemAbstract item = ItemDefinitions.stringToItem( draggedObject.GetComponent <ItemBasic>().itemString); transform.parent.GetComponent <ShipModSlotHandler>().setShipItem(item); //dragHandler.draggedObject.transform.SetParent(transform); print("obj: " + draggedObject.GetComponent <ItemBasic>().itemString); print("item: " + item.getType()); ShipDefinitions.ShipEntity entity = ShipDefinitions.loadShip(transform.parent.GetComponent <ShipModSlotHandler>().thisEntity.uniqueId); print("ship: " + entity.uniqueId); print("currentItems: " + ItemDefinitions.itemsToString(entity.items)); entity.items.Add(item); print("newCurrentItems: " + ItemDefinitions.itemsToString(entity.items)); ShipDefinitions.saveShip(entity); } }
// reduce quantity, remove from list if none are left public void removeItem(ItemAbstract item) { /* * if (WeaponItem.isWeaponType(item.getType())) * { * if (numOfEachWeapItem[ItemDefinitions.itemToInt(item)] == 0) * return; * numOfEachWeapItem[ItemDefinitions.itemToInt(item)] -= 1; * } * else if (EngineItem.isEngineType(item.getType())) * { * if (numOfEachEngItem[ItemDefinitions.itemToInt(item)] == 0) * return; * numOfEachEngItem[ItemDefinitions.itemToInt(item)] -= 1; * } */ inventory[ItemDefinitions.itemToString(item)]--; inventoryDisplay.GetComponent <ItemListHandler>(). removeItem(item); if (item.getTier() > 3) { if (blueprintDisplay != null) { blueprintDisplay.GetComponent <ItemListHandler>(). removeItem(item); } } }
public static void saveShip(ShipEntity entity) { PlayerPrefs.SetString("TSSE[ShipEntity][" + entity.uniqueId + "]", shipToString(entity)); PlayerPrefs.SetString("TSSEList[Item][" + entity.uniqueId + "]", ItemDefinitions.itemsToString(entity.items)); //GameObject.Find("GameLogic").GetComponent<GameEventHandler>().printThing( // "TSSEList[Item][" + entity.uniqueId + "]"); }
public void destroy() { int cost = ItemDefinitions.getScrapCost(item); inventory.removeItem(item); inventory.addCurrency(cost); inventory.updateCurrency(); // something with scrap lol }
static int getDescriptionWidth(int __result, Item __instance) { // increase the width so that effect descriptions stay on one line and do not break if (ItemDefinitions.GetEffect(__instance, out IEffect effect)) { return(Math.Max(__result, EffectHelper.getDescriptionWidth(effect))); } return(__result); }
public static bool isBlueprintApplied(ItemAbstract item) { int applied = PlayerPrefs.GetInt("TSSEList[Blueprint][" + ItemDefinitions.itemToString(item) + "]"); if (applied == 1) { return(true); } return(false); }
// reduce quantity if present, otherwise remove item public void removeItem(ItemAbstract item) { if (mode == "blueprint") { item = ItemAbstract.newItem(item.getType(), item.getTier() - 3); } // like in addItem, first we search for the item string itemText = ItemDefinitions.itemToString(item); print("removing item: " + itemText); if (iconsMode) { for (int i = 0; i < transform.GetChild(0).childCount; i++) { ItemBasic indexItem = transform.GetChild(0).GetChild(i).GetComponent <ItemBasic>(); string labelItemText = indexItem.itemString; // if it matches, we found it if (labelItemText == itemText) { transform.GetChild(0).GetChild(i). GetComponent <IconHandler>().decOne(); return; } } } else { for (int i = 0; i < transform.GetChild(0).childCount; i++) { UnityEngine.UI.Text indexItem = transform.GetChild(0).GetChild(i).GetChild(0). GetComponent <UnityEngine.UI.Text>(); string labelItemText = indexItem.text.Substring(0, indexItem.text.Length - 4); int numItems = int.Parse(indexItem.text.Substring(indexItem.text.Length - 2, 1)); // if it matches, we found it if (labelItemText == itemText) { // first figure out how many we now have int x = numItems; x--; // we have none left, so remove this item if (x == 0) { GameObject.Destroy(indexItem.transform.parent.gameObject); return; } // refresh the label indexItem.text = itemText + " (" + x + ")"; return; } } } }
void Awake() { if (Singleton != null && Singleton != this) { Destroy(gameObject); return; } Singleton = this; DontDestroyOnLoad(gameObject); }
private static void AddDefinition(Item item, ItemDefinitions definitions) { var definition = new ItemRecord { ID = item.ID, Name = item.Name, ParentID = item.ParentID, TemplateID = item.TemplateID, }; definitions.Add(item.ID, definition); }
private static void AddItems <T>(Shop shop, ShopMenu shopMenu, List <T> items) { foreach (var item in items) { if (ItemDefinitions.GetExtInfo(item, out ExtItemInfo extInfo) && extInfo.SellingCondition.IsFulfilled(shop)) { Item saleItem = CreateItemInstance(item); shopMenu.forSale.Add(saleItem); shopMenu.itemPriceAndStock.Add(saleItem, new int[] { extInfo.Price, 1 }); } } }
public void reloadItems() { print(engines + " " + weapons + " " + engineBlueprints + " " + weaponBlueprints); inventoryDisplay.GetComponent <ItemListHandler>().removeAllItems(); foreach (string key in inventory.Keys) { if (inventory[key] <= 0) { continue; } ItemAbstract item = ItemDefinitions.stringToItem(key); print(key + "->" + item.getType() + ":" + item.getTier()); if (item.getType() == "Error") { continue; } if (WeaponItem.isWeaponType(item.getType())) { if (item.getTier() < 4) { if (weapons) { addNumItems(item, inventory[key]); } } else { if (weaponBlueprints) { addNumItems(item, inventory[key]); } } } else if (EngineItem.isEngineType(item.getType())) { if (item.getTier() < 4) { if (engines) { addNumItems(item, inventory[key]); } } else { if (engineBlueprints) { addNumItems(item, inventory[key]); } } } } }
private void LoadSingleItemPrefab(string name, ItemTypes type, string prefabName) { GameObject go = Resources.Load(PrefabsFolderPath + prefabName) as GameObject; var itemDefinition = new ItemDefinition( name, type, go ); itemDefinition.Sprite = go.GetComponent <SpriteRenderer>().sprite; ItemDefinitions.Add(type, itemDefinition); }
private string GetItemPath(ItemDefinitions definitions, Guid itemId) { if (itemId == Guid.Empty) { return(""); } var definition = definitions[itemId]; var itemName = definition.Name; var parenItemPath = GetItemPath(definitions, definition.ParentID); return($"{parenItemPath}/{itemName}"); }
public void itemSelected(ItemAbstract newItem) { item = newItem; if (blueprints.findItem(item)) { int scrap = PlayerPrefs.GetInt("score"); if (ItemDefinitions.getScrapCost(item) <= scrap) { enable(); return; } } disable(); }
public void exit() { List <ItemAbstract> playerItems = playerItemList.getAllItems(); ItemDefinitions.saveItems("Player", ItemDefinitions.itemsToString(playerItems)); List <ItemAbstract> merchantItems = merchantItemList.getAllItems(); ItemDefinitions.saveItems(merchantId, ItemDefinitions.itemsToString(merchantItems)); playerInventory.saveCurrency(); merchantInventory.saveCurrency(); loadPreviousLevel(); }
// if an item is selected, keep track of it public void itemSelected(GameObject obj) { ItemAbstract item; if (!iconsMode) { UnityEngine.UI.Text indexItem = obj.transform.GetChild(0). GetComponent <UnityEngine.UI.Text>(); item = ItemDefinitions.stringToItem( indexItem.text.Substring(0, indexItem.text.Length - 4)); } else { item = ItemDefinitions.stringToItem( obj.GetComponent <ItemBasic>().itemString); } if (itemImage != null) { GameObject imgObj = itemImage; UnityEngine.UI.Image img = null; if (imgObj != null) { img = imgObj.GetComponent <UnityEngine.UI.Image>(); } if (img != null) { img.sprite = getImage(item); } } if (panel1 != null) { panel1.GetComponent <UnityEngine.UI.Text>() .text = ItemDefinitions.getDesc(item); } if (panel2 != null) { panel2.GetComponent <UnityEngine.UI.Text>() .text = ItemDefinitions.getSpec(item); } if (alchemizeButton != null) { alchemizeButton.GetComponent <AlchemizeButton>() .itemSelected(item); } selectedItem = obj; }
public void clearInventory() { inventory = new Dictionary <string, int>(); for (int i = 0; i < WeaponItem.numWeaponTypes; i++) { ItemAbstract item = ItemDefinitions.intToItem(i); inventory[ItemDefinitions.itemToString(item)] = 0; } for (int i = 0; i < EngineItem.numEngineTypes; i++) { ItemAbstract item = ItemDefinitions.intToItem(i + WeaponItem.numWeaponTypes); inventory[ItemDefinitions.itemToString(item)] = 0; } inventoryDisplay.GetComponent <ItemListHandler>().removeAllItems(); }
public void alchemize() { if (blueprints.findItem(item)) { int scrap = PlayerPrefs.GetInt("score"); int cost = ItemDefinitions.getScrapCost(item); if (cost <= scrap) { inventory.addItem(item); inventory.addCurrency(-cost); inventory.updateCurrency(); } //print("you alchemized an item!"); // something with scrap lol } }
public static ShipEntity loadShip(string uniqueId) { //GameObject.Find("GameLogic").GetComponent<GameEventHandler>().printThing(uniqueId); ShipEntity entity = stringtoShip( PlayerPrefs.GetString("TSSE[ShipEntity][" + uniqueId + "]")); entity.uniqueId = uniqueId; if (entity.shipType == ShipType.None) { return(entity); } entity.items = ItemDefinitions.stringToItems( PlayerPrefs.GetString("TSSEList[Item][" + entity.uniqueId + "]")); GameObject.Find("GameLogic").GetComponent <GameEventHandler>().printThing( ItemDefinitions.itemsToString(entity.items)); return(entity); }
// do we have the item? maybeeee public bool findItem(ItemAbstract item) { /* * if(WeaponItem.isWeaponType(item.getType())) * { * return (numOfEachWeapItem[ItemDefinitions.itemToInt(item)] != 0); * } * else if(EngineItem.isEngineType(item.getType())) * { * return (numOfEachEngItem[ItemDefinitions.itemToInt(item)] != 0); * } */ if (inventory[ItemDefinitions.itemToString(item)] > 0) { return(true); } return(false); }
public List <ItemAbstract> getAllItems() { List <ItemAbstract> retItems = new List <ItemAbstract>(); for (int i = 0; i < transform.GetChild(0).childCount; i++) { UnityEngine.UI.Text indexItem = transform.GetChild(0).GetChild(i).GetChild(0). GetComponent <UnityEngine.UI.Text>(); string labelItemText = indexItem.text.Substring(0, indexItem.text.Length - 4); int numItems = int.Parse(indexItem.text.Substring(indexItem.text.Length - 2, 1)); ItemAbstract item = ItemDefinitions.stringToItem(labelItemText); for (int j = 0; j < numItems; j++) { retItems.Add(item); } } return(retItems); }
public void Execute() { Assert.ArgumentNotNullOrEmpty(ConnectionString, nameof(ConnectionString)); Assert.ArgumentNotNullOrEmpty(DatabaseName, nameof(DatabaseName)); Assert.ArgumentNotNullOrEmpty(OutputDirectory, nameof(OutputDirectory)); Assert.ArgumentCondition(Directory.Exists(OutputDirectory), nameof(OutputDirectory), $"The specified directory does not exist: {OutputDirectory}"); Assert.ArgumentCondition(Try(() => new SqlConnectionStringBuilder(ConnectionString)), nameof(ConnectionString), "$The specified connection string"); using (var definitionsWriter = File.OpenWrite(Path.Combine(OutputDirectory, $"{DatabaseName}.items.dat"))) { var definitions = new ItemDefinitions(); var itemsSharedData = new ItemsSharedData(); var itemsLanguagesData = new ItemsLanguagesData(); var context = ItemManager.Initialize(ConnectionString); var counter = 0; Console.WriteLine("Processing items..."); foreach (var item in GetItems(context)) { // definition AddDefinition(item, definitions); // shared fields AddShared(item, itemsSharedData); // unversioned and versioned-1 fields AddLanguages(item, itemsLanguagesData); Console.WriteLine($"{++counter:D5}. {GetItemPath(definitions, item.ID)}"); } Console.WriteLine("Serializing..."); Serializer.Serialize(definitionsWriter, new ItemsData { Definitions = definitions, SharedData = itemsSharedData, LanguageData = itemsLanguagesData }); } }
public bool findItem(ItemAbstract item) { //if (mode == "blueprint") //item = ItemAbstract.newItem(item.getType(), item.getTier() - 3); // First, convert item to a string string itemText = ItemDefinitions.itemToString(item); // Now, search through items we have for a matching one // It's in the format "ObjectName (x)", so we trim the (x) part if (!iconsMode) { for (int i = 0; i < transform.GetChild(0).childCount; i++) { UnityEngine.UI.Text indexItem = transform.GetChild(0).GetChild(i).GetChild(0). GetComponent <UnityEngine.UI.Text>(); string labelItemText = indexItem.text.Substring(0, indexItem.text.Length - 4); int numItems = int.Parse(indexItem.text.Substring(indexItem.text.Length - 2, 1)); // if this is the item: if (labelItemText == itemText) { return(true); } } } else { for (int i = 0; i < transform.GetChild(0).childCount; i++) { ItemBasic indexItem = transform.GetChild(0).GetChild(i).GetComponent <ItemBasic>(); string labelItemText = indexItem.itemString; int numItems = indexItem.itemQuantity; // if this is the item: if (labelItemText == itemText) { return(true); } } } return(false); }
static void ValidateCraft(TailoringMenu __instance) { // TODO: HUD message is displayed behind tailoring menu -> store once and show when tailoring menu gets closed if (__instance.craftResultDisplay.item != null && ItemDefinitions.GetExtInfo(__instance.craftResultDisplay.item, out ExtItemInfo extInfo)) { if (extInfo.IsCraftingDisabled) { if (extInfo.SoldBy != Shop.None) { // display a hint after closing the menu where the player might buy the item TailoringPatches.AddTailoringMessage($"Hm, that did not quite work out. Maybe {extInfo.SoldBy.GetShopReferral()} sells something similar.", __instance.craftResultDisplay.item); } // indicate to the player that this is an invalid recipe now int itemId = __instance.craftResultDisplay.item.parentSheetIndex; __instance.craftResultDisplay.item = null; craftStateFieldInfo.SetValue(__instance, CraftState.InvalidRecipe); craftDisplayedDescriptionFieldInfo.SetValue(__instance, Game1.content.LoadString("Strings\\UI:Tailor_InvalidRecipe")); // delete the recipe, so that the player cannot craft the item __instance._tailoringRecipes.RemoveAll(x => x.CraftedItemID == itemId); } } }