public void Shop_SellSeveralIdenticalItems() { CraftingChoice randomSword = listCraftingChoices[UnityEngine.Random.Range(0, listCraftingChoices.Count)]; UsableItem sword = GetUsableItemByCraftingChoice(randomSword); //Add between 5 to 10 items int randomItemNumber = UnityEngine.Random.Range(5, 10); for (int i = 0; i < randomItemNumber; i++) { AddItemInInventory(shopAgent.agentInventory, randomSword); agentShopSubSystem.SubmitToShop(shopAgent, sword); } List <UsableItem> shop = agentShopSubSystem.GetShopItems(shopAgent); Assert.NotNull(shop, "Empty shop"); //Check the number of items in the shop AgentData aData = agentShopSubSystem.GetShop(shopAgent); Assert.NotNull(aData, "Empty AgentData"); Assert.AreEqual(randomItemNumber, aData.GetStock(sword), "Wrong stock in AgentData"); Assert.AreEqual(randomItemNumber, agentShopSubSystem.GetNumber(shopAgent, sword.itemDetails), "Wrong stock in AgentShopSubSystem"); //Check price int basePrice = GetPriceByItemName(sword.itemDetails.itemName); Assert.AreEqual(basePrice, agentShopSubSystem.GetPrice(shopAgent, sword.itemDetails)); }
public void Shop_SetPriceItem() { //Submit a sword to the shop CraftingChoice randomSword = listCraftingChoices[UnityEngine.Random.Range(0, listCraftingChoices.Count)]; UsableItem sword = AddItemInInventory(shopAgent.agentInventory, randomSword); agentShopSubSystem.SubmitToShop(shopAgent, sword); //Check default price int basePrice = GetPriceByItemName(sword.itemDetails.itemName); Assert.AreEqual(basePrice, agentShopSubSystem.GetPrice(shopAgent, sword.itemDetails)); //Increase Price int randomPositiveIncrement = UnityEngine.Random.Range(1, 50); agentShopSubSystem.SetCurrentPrice(shopAgent, 0, randomPositiveIncrement); Assert.AreEqual(basePrice + randomPositiveIncrement, agentShopSubSystem.GetPrice(shopAgent, sword.itemDetails), "Item : " + sword.ToString() + " - randomPositiveIncrement : " + randomPositiveIncrement); //Decrease Price int randomNegativeIncrement = UnityEngine.Random.Range(-50, -1); agentShopSubSystem.SetCurrentPrice(shopAgent, 0, randomNegativeIncrement); Assert.AreEqual(basePrice + randomPositiveIncrement + randomNegativeIncrement, agentShopSubSystem.GetPrice(shopAgent, sword.itemDetails)); }
public void Shop_PurchaseItem() { //To be able to buy any sword because some swords cost more than the default start money adventurerAgent.wallet.EarnMoney(1000); //ShopAgent sells a sword CraftingChoice randomSword = listCraftingChoices[UnityEngine.Random.Range(0, listCraftingChoices.Count)]; UsableItem sword = AddItemInInventory(shopAgent.agentInventory, randomSword); agentShopSubSystem.SubmitToShop(shopAgent, sword); //Adventurer buy the sword agentShopSubSystem.PurchaseItem(shopAgent, sword.itemDetails, adventurerAgent.wallet, adventurerAgent.inventory); //Check if no more sword in the ShopAgent inventory List <UsableItem> shop = agentShopSubSystem.GetShopItems(shopAgent); Assert.IsEmpty(shop, "Should have an empty shop"); Assert.AreEqual(0, shop.Count); Assert.AreEqual(0, agentShopSubSystem.GetNumber(shopAgent, sword.itemDetails)); //Check if adventurer agent get the sword equipped Assert.True(adventurerAgent.adventurerInventory.agentInventory.ContainsItem(sword)); Assert.AreEqual(sword, adventurerAgent.adventurerInventory.EquipedItem); //Check wallet of the agents int priceSword = GetPriceByItemName(sword.itemDetails.itemName); Assert.AreEqual(adventurerAgent.wallet.startMoney + 1000 - priceSword, adventurerAgent.wallet.Money, "Current adventurerAgent money should be StartMoney - PriceSword"); Assert.AreEqual(shopAgent.wallet.startMoney + priceSword, shopAgent.wallet.Money, "Current shopAgent money should be StartMoney + PriceSword"); }
/// <summary> /// Add an Item in the agent inventory /// </summary> public UsableItem AddItemInInventory(AgentInventory inventory, CraftingChoice choice) { UsableItem itemToAdd = GetUsableItemByCraftingChoice(choice); inventory.AddItem(itemToAdd); return(itemToAdd); }
public void Shop_TrytoSellItemNotInStock() { CraftingChoice randomSword = listCraftingChoices[UnityEngine.Random.Range(0, listCraftingChoices.Count)]; UsableItem sword = GetUsableItemByCraftingChoice(randomSword); //Should not working agentShopSubSystem.SubmitToShop(shopAgent, sword); List <UsableItem> shop = agentShopSubSystem.GetShopItems(shopAgent); Assert.IsEmpty(shop, "Should have an empty shop"); Assert.AreEqual(0, shop.Count); Assert.AreEqual(0, agentShopSubSystem.GetNumber(shopAgent, sword.itemDetails)); }
/// <summary> /// Return UsableItem with a CraftingChoice /// </summary> public UsableItem GetUsableItemByCraftingChoice(CraftingChoice craftingChoice) { String nameToCheck = ""; switch (craftingChoice) { case CraftingChoice.BeginnerSword: nameToCheck = "Beginner Sword"; break; case CraftingChoice.IntermediateSword: nameToCheck = "Intermediate Sword"; break; case CraftingChoice.AdvancedSword: nameToCheck = "Advanced Sword"; break; case CraftingChoice.EpicSword: nameToCheck = "Epic Sword"; break; case CraftingChoice.MasterSword: nameToCheck = "Master Sword"; break; case CraftingChoice.UltimateSwordOfPower: nameToCheck = "Ultimate Sword"; break; default: Debug.Log("Wrong craftingChoice : " + craftingChoice); break; } List <BaseItemPrices> basePrices = shopCraftingSystemBehaviour.system.shopSubSubSystem.basePrices; foreach (BaseItemPrices item in basePrices) { if (item.item.itemDetails.itemName == nameToCheck) { return(item.item); } } Debug.Log("Not found the item : " + nameToCheck); return(null); }
public void Craft_HasRequest() { //No request by default Assert.False(craftingSubSystem.HasRequest(shopAgent), "Agent has resource request(s) by default"); //Give resources to craft GiveResources(); //Make the craft CraftingChoice randomSword = listCraftingChoices[UnityEngine.Random.Range(0, listCraftingChoices.Count)]; craftingSubSystem.MakeRequest(shopAgent, (int)randomSword); //Check the craft Assert.True(craftingSubSystem.HasRequest(shopAgent)); }
public void Craft_CraftingRequest() { //Give resources to craft GiveResources(); CraftingChoice randomSword = listCraftingChoices[UnityEngine.Random.Range(0, listCraftingChoices.Count)]; craftingSubSystem.MakeRequest(shopAgent, (int)randomSword); Dictionary <ShopAgent, CraftingRequest> shopRequest = craftingSubSystem.GetShopRequests(); CraftingRequest craftingRequest = shopRequest[shopAgent]; Assert.AreEqual(0, craftingRequest.CraftingTime); Assert.AreEqual(3, craftingRequest.CraftingRequirements.timeToCreation); UsableItem craftedItem = GetUsableItemByCraftingChoice(randomSword); Assert.AreEqual(craftedItem, craftingRequest.CraftingRequirements.resultingItem); }
public void Config_SetResourceRequirements() { List <CraftingMap> defaultListRequirements = shopCraftingSystemBehaviour.system.craftingSubSubSystem.craftingRequirement; List <CraftingMap> newListRequirements = new List <CraftingMap>(); foreach (CraftingMap craftingMap in defaultListRequirements) { CraftingChoice newCraftingChoice = craftingMap.choice; UsableItem newResultingItem = craftingMap.resource.resultingItem; float newTimeToCreation = craftingMap.resource.timeToCreation; List <ResourceRequirement> newResourcesRequirements = new List <ResourceRequirement>(); foreach (ResourceRequirement resourceRequirement in craftingMap.resource.resourcesRequirements) { CraftingResources newType = resourceRequirement.type; int newNumber = UnityEngine.Random.Range(1, 10); newResourcesRequirements.Add(new ResourceRequirement(newType, newNumber)); } CraftingRequirements newCraftingRequirements = new CraftingRequirements { resultingItem = newResultingItem, timeToCreation = newTimeToCreation, resourcesRequirements = newResourcesRequirements }; CraftingMap newCraftingMap = new CraftingMap { choice = newCraftingChoice, resource = newCraftingRequirements }; newListRequirements.Add(newCraftingMap); } configSystem.SetResourceRequirements(newListRequirements); Assert.AreEqual(shopCraftingSystemBehaviour.system.craftingSubSubSystem.craftingRequirement, newListRequirements); Assert.AreNotEqual(defaultListRequirements, newListRequirements); }
public void Shop_SellOneItem() { CraftingChoice randomSword = listCraftingChoices[UnityEngine.Random.Range(0, listCraftingChoices.Count)]; //Add sword to the inventory UsableItem sword = AddItemInInventory(shopAgent.agentInventory, randomSword); //Submit it into the shop agentShopSubSystem.SubmitToShop(shopAgent, sword); List <UsableItem> shop = agentShopSubSystem.GetShopItems(shopAgent); Assert.NotNull(shop, "Empty shop"); //Check number Assert.AreEqual(1, shop.Count); Assert.AreEqual(1, agentShopSubSystem.GetNumber(shopAgent, sword.itemDetails)); //check price int basePrice = GetPriceByItemName(sword.itemDetails.itemName); Assert.AreEqual(basePrice, agentShopSubSystem.GetPrice(shopAgent, sword.itemDetails)); }