public List <SmithingItem> GetAllSmithingItems() { List <SmithingItem> smithingItems = new List <SmithingItem>(); SqlDataReader reader = null; using (SqlConnection _conn = new SqlConnection(connectionString)) { _conn.Open(); SqlCommand cmd = new SqlCommand("GetAllSmithingItems", _conn); cmd.CommandType = CommandType.StoredProcedure; reader = cmd.ExecuteReader(); while (reader.Read()) { int id = Convert.ToInt32(reader["SmithingItemID"]); string name = Convert.ToString(reader["Name"]); int isBar = Convert.ToInt32(reader["IsBar"]); int value = Convert.ToInt32(reader["Value"]); string description = Convert.ToString(reader["Description"]); bool isBarBool = false; if (isBar == 1) { isBarBool = true; } SmithingItem smithingItem = new SmithingItem(id, name, isBarBool, value, description); smithingItems.Add(smithingItem); } } return(smithingItems); }
public Character SmithBar(Character character, string oreName) { bool removedOre = false; //Loop trough all the smithing items of a character to see if it matches with the ore from the method parameter foreach (SmithingItem mySmithingItem in character.mySmithingItems) { if (mySmithingItem.Name == oreName) { if (mySmithingItem.Amount > 0) { //Withdraw this ore from the players inventory. mySmithingItem.AddToAmount(-1); removedOre = true; } } } if (removedOre) { bool addedBar = false; SmithingItem smithingItemToAdd = new SmithingItem(); //Add cooked fish to characters inventory string smithingToAdd = oreName.Replace("ore", "bar"); //Checks if we already have this item so we can increase the amount by one foreach (SmithingItem mySmithingItems in character.mySmithingItems) { //we allready have the item if (mySmithingItems.Name == smithingToAdd && addedBar == false) { mySmithingItems.AddToAmount(1); addedBar = true; character.SmithingExperience += 190; } } //we don't have this item yet if (addedBar == false) { foreach (SmithingItem allSmithingItems in smithingItemContainerRepository.GetAllSmithingItems()) { if (smithingToAdd == allSmithingItems.Name) { smithingItemToAdd = allSmithingItems; smithingItemToAdd.Amount = 1; character.mySmithingItems.Add(smithingItemToAdd); character.SmithingExperience += 190; } } } } return(character); }
public void SmithBar_SmithIronBar_ReturnIronBarName() { //arange SmithingItem smithingItem = new SmithingItem(); smithingItem.Name = "Iron ore"; smithingItem.Amount = 1; character.mySmithingItems.Add(smithingItem); character.SmithingExperience += 50; string smithingItemInInventory = ""; //act smithingLogic.SmithBar(character, "Iron ore"); foreach (SmithingItem mySmithingItem in character.mySmithingItems) { if (mySmithingItem.Amount > 0) { smithingItemInInventory = mySmithingItem.Name; } } //assert Assert.That(smithingItemInInventory, Is.EqualTo("Iron bar")); }