public void GetItemFromPoolIfBetter(Creature character, ItemLocationEnum setLocation) { //account for items only being assigned finger, but creatures having left and right fingers ItemLocationEnum tempLoc = setLocation; if (setLocation == ItemLocationEnum.LeftFinger || setLocation == ItemLocationEnum.RightFinger) { tempLoc = ItemLocationEnum.Finger; } var myList = ItemPool.Where(a => a.Location == tempLoc) .ToList(); // If no items in the list, return... if (!myList.Any()) { return; } var currentItem = character.GetItemByLocation(setLocation); if (currentItem == null) { // If no item in the slot then put on the first in the list Item item = myList.FirstOrDefault(); character.AddItem(setLocation, item.Id); ItemPool.Remove(item); return; } foreach (var item in myList) { if (item.Value > currentItem.Value) { // Put on the new item, which drops the one back to the pool var droppedItem = character.AddItem(setLocation, item.Id); // Remove the item just put on from the pool ItemPool.Remove(item); if (droppedItem != null) { // Add the dropped item to the pool ItemPool.Add(droppedItem); } } } }
//creates a new set of monsters on every round public void setMonsters() { Dataset.Clear(); var dataset = MonstersViewModel.Instance.Dataset; var tempDataset = new List <Creature>(); int dateSeed = DateTime.Now.Millisecond; Random rand = new Random(dateSeed); foreach (var data in dataset) { if (data.Type == 1) // just Monsters { Creature newOne = new Creature(); //makes sure that the actual data is not changed newOne.Update(data); tempDataset.Add(newOne); } } //create the monsters for the current round for (int i = 0; i < 6; i++) { int Round = round; if (round > 20) { Round = 20; } int index = rand.Next(tempDataset.Count); Creature monster = new Creature(); monster.Update(tempDataset[index]);//get a random monster type then update the data for the current round monster.Id = Guid.NewGuid().ToString(); monster.Alive = true; monster.Level = Round; monster.XP = lp[Round].XP; monster.Attack = lp[Round].Attack; monster.Defense = lp[Round].Defense; monster.Speed = lp[Round].Speed; monster.MaxHealth = rand.Next(1, 11) * Round; if (round == 1) { monster.MaxHealth = 1;//round 1 monsters are freebies monster.XP = 100; } monster.CurrHealth = monster.MaxHealth; // Load items var myItemViewModel = ItemsViewModel.Instance; var items = myItemViewModel.Dataset; //check itemcount and assign random items to monster int itemCount = 0; while (itemCount < 3) { var item = items[rand.Next(items.Count)]; var itemLocation = item.Location; if (item.Location == ItemLocationEnum.Finger)//watch out for the finger { itemLocation = ItemLocationEnum.RightFinger; } //if that location is available fill it, otherwise try again if (monster.GetItemByLocation(itemLocation) == null) { monster.AddItem(itemLocation, item.Id); itemCount++; } } //load unique drop var uItem = items[rand.Next(items.Count)]; monster.UniqueItem = uItem.Id; Dataset.Add(monster); } }