static void Update_Creature(Creature c) { c.message.Clear(); //Monsters shouldn't need to keep messages string action = c.mind.DecideAction(currentLevel, c); //Decide action #region Perform Action #region Move Actions List<String> actionList = new List<String>(); actionList.Add("Move 1"); actionList.Add("Move 2"); actionList.Add("Move 3"); actionList.Add("Move 4"); actionList.Add("Move 5"); actionList.Add("Move 6"); actionList.Add("Move 7"); actionList.Add("Move 8"); actionList.Add("Move 9"); for (int k = 0; k <= 8; k++) { if (action == actionList[k]) { c.Move(currentLevel, k + 1); } } actionList.Clear(); #endregion #region Item Management Actions if (action == "Pick Up") { currentLevel = c.PickUp(currentLevel); } if (action == "Unwield") c.Unwield(); if (action.StartsWith("Wield")) { while (action.StartsWith("Wield")) action = action.Remove(0, 6); //Clip everything but the index Weapon targetItem = (Weapon)c.inventory[int.Parse(action)]; c.Wield(targetItem); } if (action == "Remove") c.RemoveAll(); if (action.StartsWith("Wear")) { while (action.StartsWith("Wear")) action = action.Remove(0, 5); //Clip everything but the index Armor targetItem = (Armor)c.inventory[int.Parse(action)]; c.Wear(targetItem); } if (action.StartsWith("Eat")) //If it starts with "Eat" { action = action.Remove(0, 4); //Clip everything but the index Item targetItem = c.inventory[int.Parse(action)]; c.Eat(currentLevel, targetItem); //Eat the given item } #endregion #region Melee Attack if (action.StartsWith("Attack")) { action = action.Remove(0, 7); currentLevel = c.MeleeAttack(currentLevel, Direction.Parse(action)); } #endregion #endregion }
static bool Update_Move(Creature c, Directions dir) { bool peacefulAdjacent = false; //Whether the adjacent creature, if any, is peaceful foreach (Creature d in currentLevel.creatures) { if (d is QuestGiver && d.pos == c.pos.AdjacentVector(dir)) { QuestGiver qG = (QuestGiver)d; bool haveItem = false; peacefulAdjacent = true; c.message.Add("You chat with the " + d.name + "."); int inventoryCount = c.inventory.Count; //Bluh foreach for (int itemIndex = 0; itemIndex < inventoryCount; itemIndex++) { Item item = c.inventory[itemIndex]; //There, foreach simulated if (item.name == qG.wantObject) { haveItem = true; c.message.Add(CapitalizeFirst(d.name) + ": I see you have a " + qG.wantObject + ". Trade for a " + qG.giveObject + "? (y/n)"); Draw(); //Draw this to the screen if (Update_GetKey() == "y") { d.inventory.Add(item); //Give away the wanted item c.inventory.Remove(item); int cInventoryCount = c.inventory.Count; //Bluh foreach for (itemIndex = 0; itemIndex < cInventoryCount; itemIndex++) { Item cItem = d.inventory[itemIndex]; c.inventory.Add(cItem); //Recieve giveObject d.inventory.Remove(cItem); } foreach (Item cItem in d.inventory) { if (cItem.name == qG.giveObject) { c.inventory.Add(cItem); } } qG.CycleWantGiveItem(content.items); //Cycle what s/he wants and what he will give c.message.Add(CapitalizeFirst(d.name) + ": You trade your items."); } else { c.message.Add(CapitalizeFirst(d.name) + ": Too bad. Come back if you change your mind."); } break; } } if (!haveItem) //If we don't have the item { c.message.Add(CapitalizeFirst(d.name) + ": Hello adventurer. If you bring me a " + qG.wantObject + ", I'll give you a " + qG.giveObject + "."); } return true; //Talking is not a free action } } if (!peacefulAdjacent) { if (c.CanAttackMelee(currentLevel, dir) && !peacefulAdjacent) { currentLevel = c.MeleeAttack(currentLevel, dir); return true; } else if (!currentLevel.MoveWillBeBlocked(0, dir)) { bool moved = c.Move(currentLevel, (int)dir); Update_MapEdge(c); //Check for hitting map edge return moved; } } return false; }