public string DropItems() { CharacterRepository repo = new CharacterRepository(); string itemsDropped = "You Dropped:"; Random rand = new Random(); //defeated if (this.HP == 0) { foreach (Item item in this.Items) { repo.RemoveCharacterItem(item); repo.Save(); } itemsDropped = "You lost all of your items!"; Items.Clear(); } else if (Items.Count > 0) { int numItems = rand.Next(1, Items.Count) / 2; for (int n = 0; n < numItems; n++) { int itemToDrop = rand.Next(1, Items.Count); itemsDropped += "..." + Items[itemToDrop].Name; repo.RemoveCharacterItem(Items[itemToDrop]); Items.RemoveAt(itemToDrop); repo.Save(); } } SaveProgress(); return(itemsDropped); }
public MessagePacket UseItemOnEnemy(int itemIndex, Enemy enemy) { CharacterRepository repo = new CharacterRepository(); string strMessage = ""; int nAttackStrength; if (enemy.Weakness == this.Items[itemIndex].Name) { strMessage = "You discovered " + enemy.Name + "'s weakness!!"; nAttackStrength = enemy.HP; enemy.HP = enemy.HP - nAttackStrength; } else { strMessage = "Using " + this.Items[itemIndex].Name + " had no effect"; nAttackStrength = 0; } repo.RemoveCharacterItem(this.Items[itemIndex]); this.Items.RemoveAt(itemIndex); repo.Save(); return(new MessagePacket(strMessage, this.AttackImage, nAttackStrength)); }