// Set Item Stack public void SetItemStack(ItemMeta itemMeta, int amount) { this.itemMeta = itemMeta; this.amount = amount; this.itemMeta = null; }
protected override void Start() { base.Start(); // HACK:: DEBUG DATA: items = new List <Item> { new Item(Item.Type.BEER_MUG) }; var meta = itemsMetaData; // var typeMap = itemsMetaData.GetType() foreach (var item in items) { itemMeta = meta.getMetaForItem(item) as ItemMeta; var button = Instantiate(itemButtonPrefab, inventoryContainer, true); if (itemMeta == null) { continue; } button.Icon = itemMeta.Icon; button.Label = itemMeta.Label; } }
void ItemAdded(ItemMeta item) { InventoryUIItem empty = Instantiate(itemContainer); empty.Item = item; empty.transform.SetParent(scrollViewContent); }
/// <summary> /// Initializes a new instance of the <see cref="Item"/> class. /// </summary> /// <param name="meta">Non-NULL instance of the <see cref="ItemMeta"/> that is represented by this instance.</param> /// <param name="itemServices">Non-NULL instance of <see cref="AggregatedItemServices"/> which are necessary for this <see cref="Item"/>.</param> protected Item(ItemMeta meta, AggregatedItemServices itemServices) { if (meta == null) { throw new ArgumentNullException(nameof(meta)); } this.ItemMergeStrategyHandler = itemServices.ItemMergeStrategyHandler; this.ItemSplitStrategyHandler = itemServices.ItemSplitStrategyHandler; this.itemFactory = itemServices.ItemFactory; this.RuntimeId = Guid.NewGuid(); this.Meta = meta; var(valid, errorMessage) = this.ValidateMeta(); if (valid == false) { throw new ArgumentException(errorMessage, nameof(meta)); } this.SingleWeight = this.Meta.DefaultWeight; this.Handle = this.Meta.Handle; this.DefaultDisplayName = this.Meta.DisplayName; this.Stackable = (this.Meta.Flags & ItemFlags.NotStackable) == 0; this.WeightChangable = (this.Meta.Flags & ItemFlags.WeightChangable) != 0; this.displayName = this.DefaultDisplayName; this.Amount = Math.Max(MinimalItemAmount, 1); }
protected void SetupItemTest() { this.DefaultRealMeta = new ItemMeta(ItemHandle, typeof(RealItem), ItemDisplayName, ItemWeight, ItemFlags); this.DefaultFakeMeta = new ItemMeta(FakeItemHandle, typeof(FakeItem), FakeItemDisplayName, FakeItemWeight, FakeItemFlags); this.DefaultActionMeta = new ItemMeta(ActionItemHandle, typeof(RealActionItem), ActionItemDisplayName, ActionItemWeight, ActionItemFlags); this.SetupDefaultServiceProvider(); }
public void SetItem(ItemMeta item, Button selectedElement) { this.item = item; this.selectedElement = selectedElement; itemName.text = item.name; moreInfo.text = item.moreInfo; action.text = item.action; useButton.onClick.AddListener(OnUseItem); }
/// <inheritdoc/> public int GetItemFitAmount(ItemMeta meta) { if (meta == null) { throw new ArgumentNullException(nameof(meta)); } return(this.GetItemFitAmount(meta.DefaultWeight)); }
private IItem BuildItemFromMeta(ItemMeta meta) { var factory = (ObjectFactory)this.serviceProvider.GetService(meta.Type); var item = (IItem)factory(this.serviceProvider, new[] { (object)meta }); item.Initialize(); return(item); }
public FakeItem(ItemMeta meta) { this.RuntimeId = Guid.NewGuid(); this.Meta = meta; this.DisplayName = meta.DisplayName; this.Amount = 1; this.Stackable = (this.Meta.Flags & ItemFlags.NotStackable) == 0; this.SingleWeight = this.Meta.DefaultWeight; }
public void ItemMetaConstructorSetsProperties() { var meta = new ItemMeta("testhandle", typeof(FakeItem), "FakeItem", 5, ItemFlags.NotStackable); meta.Handle.Should().Be("testhandle"); meta.Type.Should().Be(typeof(FakeItem)); meta.DisplayName.Should().Be("FakeItem"); meta.DefaultWeight.Should().Be(5); meta.Flags.Should().Be(ItemFlags.NotStackable); }
public void GetItemFitAmountWithMetaReturnsCorrectValue(int singleWeight, int capacity, int result) { var meta = new ItemMeta(this.DefaultRealMeta.Handle, this.DefaultRealMeta.Type, this.DefaultRealMeta.DisplayName, singleWeight); this.Inventory.SetCapacity(capacity); this.Inventory.Capacity.Should().Be(capacity); var amount = this.Inventory.GetItemFitAmount(meta); amount.Should().Be(result); }
protected void SetupDefaultServiceProvider() { this.RealMeta = this.DefaultRealMeta; this.FakeMeta = this.DefaultFakeMeta; this.ActionMeta = this.DefaultActionMeta; this.SetupServiceProvider(this.DefaultRealMeta, this.DefaultFakeMeta, this.DefaultActionMeta); this.Item = (Item)this.ItemFactory.CreateItem(this.DefaultRealMeta, 1); this.FakeItem = (FakeItem)this.ItemFactory.CreateItem(this.DefaultFakeMeta, 1); this.ActionItem = (RealActionItem)this.ItemFactory.CreateItem(this.DefaultActionMeta, 1); }
public void PassingMetaWithWrongTypeThrowsException() { var meta = new ItemMeta(ItemHandle, typeof(FakeItem), ItemDisplayName, ItemWeight, ItemFlags); Action act = () => new RealItem(meta, this.ItemServices); act.Should().Throw<ArgumentException>() .Where(x => x.Message.Contains("mismatch") && x.Message.Contains("type") && x.Message.Contains("meta")); }
public void Consume(ItemMeta item) { GameObject toSpawn = Instantiate(Resources.Load <GameObject>(Path.Combine("Consumables", item.info))); if (item.isModifier) { toSpawn.GetComponent <IConsumable>().Consume(stats); } else { toSpawn.GetComponent <IConsumable>().Consume(); } }
/// <inheritdoc /> public bool DoesItemFit(ItemMeta meta, int amount = 1) { if (meta == null) { throw new ArgumentNullException(nameof(meta)); } if (amount < 1) { throw new ArgumentOutOfRangeException(nameof(amount), $"The given {nameof(amount)} has to be 1 or higher"); } var neededSpace = meta.DefaultWeight * amount; return(this.AvailableCapacity >= neededSpace); }
public ItemMeta Build() { var meta = new ItemMeta { CustomModelData = this.CustomModelData, Name = this.Name, Lore = this.Lore, Durability = this.Durability, Unbreakable = this.Unbreakable, Enchantments = new ReadOnlyDictionary <EnchantmentType, Enchantment>(new Dictionary <EnchantmentType, Enchantment>(this.enchantments)), StoredEnchantments = new ReadOnlyDictionary <EnchantmentType, Enchantment>(new Dictionary <EnchantmentType, Enchantment>(this.storedEnchantments)), CanDestroy = new ReadOnlyCollection <string>(new List <string>(this.canDestroy)) }; return(meta); }
public void Setup() { this.serviceProviderMock = new Mock <IServiceProvider>(); this.itemRegistry = new ItemRegistry(); this.defaultMeta = InventoryUtils.CreateItemMeta(DefaultItemHandle, typeof(FakeItem), "Fake Item"); this.nonStackableDefaultMeta = InventoryUtils.CreateItemMeta(DefaultNonStackableItemHandle, typeof(FakeItem), "Fake Item", flags: ItemFlags.NotStackable); this.itemRegistry.AddItemMeta(this.defaultMeta); this.itemRegistry.AddItemMeta(this.nonStackableDefaultMeta); this.itemRegistry.ValidateAndCacheItemMeta(); this.AddItemResolveToServiceProvider <FakeItem>(); this.itemFactory = new ItemFactory(this.itemRegistry, this.serviceProviderMock.Object); }
public void Equip(ItemMeta toEquip) { if (EquippedWeapon) { stats.RemoveStatBonuses(EquippedWeapon.GetComponent <IWeapon>().Stats); Destroy(hand.transform.GetChild(0).gameObject); } EquippedWeapon = Instantiate( Resources.Load <GameObject>(Path.Combine("Weapons", toEquip.info)), hand.transform.position, hand.transform.rotation ); EquippedWeapon.GetComponent <IWeapon>().Stats = toEquip.stats; EquippedWeapon.GetComponent <IProjectileLauncher>()?.SetProjectileSpawnPoint(projectileSpawnPoint); EquippedWeapon.transform.SetParent(hand.transform); stats.AddStatBonuses(toEquip.stats); Debug.Log(EquippedWeapon); }
/// <inheritdoc/> public IItem CreateItem(ItemMeta meta, int amount) { if (meta == null) { throw new ArgumentNullException(nameof(meta)); } if (amount <= 0) { throw new ArgumentOutOfRangeException(nameof(amount), "Item amount has to be 1 or higher"); } if ((meta.Flags & ItemFlags.NotStackable) != 0 && amount > 1) { throw new ItemNotStackableException(); } return(this.SetupItemPostCreate(this.BuildItemFromMeta(meta), amount)); }
protected void TearDownItemTest() { this.ServiceProvider = null; this.ServiceCollection = null; this.ItemFactory = null; this.ItemRegistry = null; this.RealMeta = null; this.FakeMeta = null; this.ActionMeta = null; this.Item = null; this.FakeItem = null; this.Inventory = null; this.InventoryFactoryMock = null; this.ItemFactoryMock = null; this.ItemMergeStrategyHandlerMock = null; this.ItemSplitStrategyHandlerMock = null; }
public void SetItemMeta(string key, ItemAttributeObject attributeObj = null) { if (meta != null) { Destroy(meta); } var obj = Instantiate(ItemManager.Instance.GetItem(key), transform); meta = obj.GetComponent <ItemMeta>(); var image = GetComponentInChildren <Image>(); if (image == null) { return; } image.sprite = meta.icon; }
/// <inheritdoc/> public ICollection <IItem> CreateItems(ItemMeta meta, int amount) { if (meta == null) { throw new ArgumentNullException(nameof(meta)); } if ((meta.Flags & ItemFlags.NotStackable) == 0) { return(new List <IItem> { this.CreateItem(meta, amount), }); } var items = new List <IItem>(); for (int i = 0; i < amount; i++) { items.Add(this.CreateItem(meta, 1)); } return(items); }
public void WriteItemStack(ItemStack value) { value ??= new ItemStack(0, 0) { Present = true }; WriteBoolean(value.Present); if (value.Present) { var item = value.GetItem(); WriteVarInt(item.Id); WriteByte((sbyte)value.Count); NbtWriter writer = new(this, string.Empty); ItemMeta meta = value.ItemMeta; if (meta.HasTags()) { writer.WriteByte("Unbreakable", meta.Unbreakable ? 1 : 0); if (meta.Durability > 0) { writer.WriteInt("Damage", meta.Durability); } if (meta.CustomModelData > 0) { writer.WriteInt("CustomModelData", meta.CustomModelData); } if (meta.CanDestroy is not null) { writer.BeginList("CanDestroy", NbtTagType.String, meta.CanDestroy.Count); foreach (var block in meta.CanDestroy) { writer.WriteString(block); } writer.EndList(); } if (meta.Name is not null) { writer.BeginCompound("display"); writer.WriteString("Name", JsonConvert.SerializeObject(new List <ChatMessage> { (ChatMessage)meta.Name })); if (meta.Lore is not null) { writer.BeginList("Lore", NbtTagType.String, meta.Lore.Count); foreach (var lore in meta.Lore) { writer.WriteString(JsonConvert.SerializeObject(new List <ChatMessage> { (ChatMessage)lore })); } writer.EndList(); } writer.EndCompound(); } else if (meta.Lore is not null) { writer.BeginCompound("display"); writer.BeginList("Lore", NbtTagType.String, meta.Lore.Count); foreach (var lore in meta.Lore) { writer.WriteString(JsonConvert.SerializeObject(new List <ChatMessage> { (ChatMessage)lore })); } writer.EndList(); writer.EndCompound(); } } writer.WriteString("id", item.UnlocalizedName); writer.WriteByte("Count", (byte)value.Count); writer.EndCompound(); writer.Finish(); } }
public void Init(ItemMeta meta, Sprite sprite) { this.meta = meta; this.sprite = sprite; }
public void AddItemMeta(ItemMeta meta) { this.itemMetas.Add(meta); }
private void Awake() { itemData = MockItemData.items.Find(x => x.Id == Id); Name = itemData.Name; }
public async void AvailableItemEquipped() { var itemMetaId = "Test_AvailableItemEquipped"; var itemSlot = "Test_AvailableItemEquipped"; var classMetaId = "Test_AvailableItemEquipped"; var playerId = "Test_AvailableItemEquipped"; // Create test class meta if it doesn't exist. var classMeta = await new ClassMeta(classMetaId).LoadAsync(); if (classMeta == null) { classMeta = new ClassMeta(classMetaId); await classMeta.InsertAsync(); } // Create test item meta if it doesn't exist. var itemMeta = await new ItemMeta(itemMetaId).LoadAsync(); if (itemMeta == null) { itemMeta = new ItemMeta(itemMetaId); itemMeta.ClassMetaId = classMetaId; itemMeta.EquipmentSlot = itemSlot; await itemMeta.InsertAsync(); } // Create test player with a character and item. var player = await Helpers.CreateTestPlayer(playerId); var character = new Character(classMetaId); player.Characters.Add(character); var item = new Item(itemMetaId); player.AddItem(item); await player.ReplaceAsync(); // Auth player. var sessionToken = Helpers.GetSessionToken(playerId); // Mock data. var data = JToken.Parse($@"{{ 'PlayerId':'{playerId}', 'SessionToken':'{sessionToken}', 'CharacterId':'{character.Id}', 'ItemId':'{item.Id}' }}"); // Execute controller. var controller = new EquipItemController(); var responseToken = await controller.HandleHttpRequestAsync(data); // Assert controller response status is OK. Assert.Equal(responseToken["Status"], JStatus.Ok.JToken["Status"]); // Make sure item is equiped. player = await player.LoadAsync(); Assert.True(player.GetItemById(item.Id).IsOwnedByCharacter); Assert.True(player.GetItemById(item.Id).OwningCharacterId == character.Id); }
public WaterItem(ItemMeta meta, AggregatedItemServices itemServices) : base(meta, itemServices) { }
public static void AddItem(ItemMeta item) { Debug.Log($"Event exists? {OnAddItem != null} | Item: {item}"); OnAddItem(item); }
public ItemMeta(ItemMeta item) : this(item.stats, item.info, item.name, item.type, item.moreInfo, item.action, item.isModifier) { }