public Object CopyObject()
        {
            MonsterCommand newCommand = new MonsterCommand();
            newCommand.commandCode = commandCode;
            newCommand.counter = counter;

            newCommand.parameters = new Dictionary<String,String>();
            foreach(String tempKey in parameters.Keys.ToArray<String>())
            {
                newCommand.parameters.Add(tempKey, parameters[tempKey]);
            }

            return newCommand;
        }
        public static void executeUnequipCommand(Monster monster, MonsterCommand command, Quinoa quinoa)
        {
            String itemID = command.getParameter("itemID");
            Item itemToEquip = monster.inventory.getItem(itemID);

            //Find the slot that the item is equiped in
            ItemSlot equipSlot = ItemSlot.NULL;
            foreach (ItemSlot tempSlot in Enum.GetValues(typeof(ItemSlot)).Cast<ItemSlot>())
            {
                Item testItem = monster.inventory.getItem(tempSlot);
                if(testItem != null && testItem.ID.Equals(itemID))
                {
                    equipSlot = tempSlot;
                }
            }

            if(equipSlot != ItemSlot.NULL)
            {
                if(!monster.inventory.Full)
                {
                    Item newItem = (Item)itemToEquip.CopyObject();
                    monster.inventory.equipItem(null, equipSlot);
                    if(!monster.inventory.stackItem(newItem))
                    {
                        monster.inventory.addItem(newItem);
                    }

                    if(isPlayer(monster))
                    {
                        quinoa.getMessageManager().addMessage("Unequiped " + EnumUtil.EnumName<ItemClass>(newItem.itemClass) + ".");
                    }
                }
                else
                {
                    if(isPlayer(monster))
                    {
                        quinoa.getMessageManager().addMessage("No space to unequip that.");
                    }
                }
            }
        }
        public static void executePickupCommand(Monster monster, MonsterCommand command, Quinoa quinoa)
        {
            bool pickedUpAtLeastOneItem = false;
            Region region = quinoa.getCurrentRegionHeader().getRegion();
            foreach(Item tempItem in region.getItems())
            {
                if(tempItem.x == monster.x
                && tempItem.y == monster.y
                && !tempItem.ShouldBeRemoved)
                {
                    if(monster.inventory.stackItem(tempItem))
                    {
                        //Item stacked on current item
                        tempItem.RemoveObject();
                        pickedUpAtLeastOneItem = true;

                        if(isPlayer(monster))
                        {
                            quinoa.getMessageManager().addMessage("Got " + EnumUtil.EnumName<ItemClass>(tempItem.itemClass) + ".");
                        }
                    }
                    else
                    {
                        if(!monster.inventory.Full)
                        {
                            monster.inventory.addItem((Item)tempItem.CopyObject());
                            tempItem.RemoveObject();
                            pickedUpAtLeastOneItem = true;

                            if(isPlayer(monster))
                            {
                                quinoa.getMessageManager().addMessage("Got " + EnumUtil.EnumName<ItemClass>(tempItem.itemClass) + ".");
                            }
                        }
                        else
                        {
                            if(isPlayer(monster))
                            {
                                quinoa.getMessageManager().addMessage("Can't carry any more.");
                                pickedUpAtLeastOneItem = true;
                            }
                        }
                    }
                }
            }

            if(!pickedUpAtLeastOneItem)
            {
                if(isPlayer(monster))
                {
                    quinoa.getMessageManager().addMessage("Nothing to pick up there.");
                }
            }
        }
        public static void executeMoveCommand(Monster monster, MonsterCommand command, Quinoa quinoa)
        {
            Region region = quinoa.getCurrentRegionHeader().getRegion();
            Direction direction = (Direction) Enum.Parse(typeof(Direction), command.getParameter("direction"));
            monster.facing = direction;

            int newX = monster.x;
            int newY = monster.y;

            switch(direction)
            {
                case Direction.N: newY--; break;
                case Direction.NE: newY--; newX++; break;
                case Direction.NW: newY--; newX--; break;
                case Direction.S: newY++; break;
                case Direction.SE: newY++; newX++; break;
                case Direction.SW: newY++; newX--; break;
                case Direction.E: newX++; break;
                case Direction.W: newX--; break;
            }

            if(newX >= 0 && newX < region.getWidth()
            && newY >= 0 && newY < region.getHeight())
            {
                Terrain tmpTerrain = region.getTerrain(newX, newY);
                if (TerrainManager.allowsMonsterToPass(tmpTerrain, monster) && quinoa.getMonster(newX, newY) == null)
                {
                    monster.setPosition(newX, newY);
                    TerrainManager.step(region.getTerrain(newX, newY), newX, newY, region, quinoa);
                }
                else
                {
                    //Do nothing
                }
            }
            else
            {
                //out of bounds, but do not inform the player
            }
        }
        public static void executeItemVerbCommand(Monster monster, MonsterCommand command, Quinoa quinoa)
        {
            Item item = monster.inventory.getItem(command.getParameter("itemID"));
            ItemVerb verb = (ItemVerb)Enum.Parse(typeof(ItemVerb), command.getParameter("verb"));
            Region region = quinoa.getCurrentRegionHeader().getRegion();
            int x = Int32.Parse(command.getParameter("x"));
            int y = Int32.Parse(command.getParameter("y"));
            bool removeItem=false;
            if(item != null)
            {
                switch(verb)
                {
                    case ItemVerb.EAT:
                    foreach(ItemAttribute attribute in item.attributes)
                    {
                        if(attribute.type == ItemAttributeType.NUTRITION)
                        {
                            double nutrition = Double.Parse(attribute.parameter);
                            monster.stats.setCurrentHunger(monster.stats.getCurrentHunger() - nutrition);
                            if(monster.stats.getCurrentHunger() < 0)
                            {
                                monster.stats.setCurrentHunger(0.0);
                            }

                            if(isPlayer(monster))
                            {
                                quinoa.getMessageManager().addMessage("Ate " + EnumUtil.EnumName<ItemClass>(item.itemClass) + ".");
                            }
                        }

                        if(attribute.type == ItemAttributeType.HEALS)
                        {
                            double points = Double.Parse(attribute.parameter);
                            monster.stats.setCurrentHealth(monster.stats.getCurrentHealth() + points);
                            if(monster.stats.getCurrentHealth() > monster.stats.getMaxHP())
                            {
                                monster.stats.setCurrentHealth(monster.stats.getMaxHP());
                            }

                            if(isPlayer(monster))
                            {
                                if(points >= 0)
                                {
                                    quinoa.getMessageManager().addMessage("You feel better.");
                                }
                                else
                                {
                                    quinoa.getMessageManager().addMessage("You feel worse.");
                                }
                            }
                        }
                    }
                    removeItem = true;
                    break;

                    case ItemVerb.PLACE:
                    removeItem = MonsterActionManager.place(monster, item, x, y, region, quinoa);
                    break;

                    case ItemVerb.USE:
                    removeItem = use(monster, item, x, y, region, quinoa);
                    break;

                }

                if(removeItem)
                {
                    if(item.stackSize > 1)
                    {
                        item.stackSize = item.stackSize - 1;
                    }
                    else
                    {
                        item.RemoveObject();
                    }
                }
            }
            else
            {
                //Non-item verbs
                switch(verb)
                {
                    case ItemVerb.ACTIVATE:
                    MonsterActionManager.activate(monster, x, y, region, quinoa);
                    break;

                    case ItemVerb.TALK:
                    if(isPlayer(monster))
                    {
                        quinoa.getActions().talk(x, y);
                        quinoa.getActions().showDialog();
                    }
                    break;

                    case ItemVerb.LOOK:
                    if(isPlayer(monster))
                    {
                        quinoa.getActions().look(x, y);
                        quinoa.getActions().showDialog();
                    }
                    break;

                    case ItemVerb.TRADE:
                    if(isPlayer(monster))
                    {
                        quinoa.getActions().trade(x, y);
                    }
                    break;

                    case ItemVerb.SLEEP:
                    Item terrainItem = region.getItem(x, y);

                    if(terrainItem != null)
                    {
                        foreach(ItemAttribute ia in terrainItem.attributes)
                        {
                            if(ia.type == ItemAttributeType.SLEEPS_FOR)
                            {
                                int hours = Int32.Parse(ia.parameter.Split(new char[]{' '})[0]);
                                monster.setPosition(x, y);
                                monster.sleeping = Quinoa.TICKS_PER_SECOND * 60 * 60 * hours;
                                break;
                            }
                        }
                    }

                    if(TerrainManager.hasParameter(region.getTerrain(x, y), TerrainParameter.HAS_BED))
                    {
                        int hours = 4;
                        monster.setPosition(x, y);
                        monster.sleeping = Quinoa.TICKS_PER_SECOND * 60 * 60 * hours;
                    }
                    else
                    {
                        if(isPlayer(monster))
                        {
                            quinoa.getMessageManager().addMessage("You can't sleep there.");
                        }
                    }
                    break;
                }
            }
        }
        public static void executeEquipCommand(Monster monster, MonsterCommand command, Quinoa quinoa)
        {
            String itemID = command.getParameter("itemID");
            Item itemToEquip = monster.inventory.getItem(itemID);
            if(itemToEquip != null)
            {
                //check for a free slot
                ItemSlot freeSlot = ItemManager.getFreeItemSlot(monster, itemToEquip);
                if(freeSlot != ItemSlot.NULL)
                {
                    Item newItem = (Item)itemToEquip.CopyObject();
                    monster.inventory.removeItem(itemID);
                    monster.inventory.equipItem(newItem, freeSlot);

                    if(isPlayer(monster))
                    {
                        quinoa.getMessageManager().addMessage("Equiped " + EnumUtil.EnumName<ItemClass>(newItem.itemClass) + ".");
                    }
                }
                else
                {
                    if(isPlayer(monster))
                    {
                        quinoa.getMessageManager().addMessage("No space to equip that.");
                    }
                }
            }
        }
        public static void executeDropCommand(Monster monster, MonsterCommand command, Quinoa quinoa)
        {
            String itemID = command.getParameter("itemID");
            Item itemToDrop = monster.inventory.getItem(itemID);
            if(itemToDrop != null)
            {
                Item newItem = (Item)itemToDrop.CopyObject();
                newItem.itemState = ItemState.GROUND;
                newItem.setPosition(monster.x, monster.y);
                quinoa.getCurrentRegionHeader().getRegion().getItems().Add(newItem);
                monster.inventory.removeItem(itemID);
                monster.inventory.removedExpiredItems();

                if(isPlayer(monster))
                {
                    quinoa.getMessageManager().addMessage("Dropped " + itemToDrop.itemClass + ".");
                }
            }
        }
 public static void executeCommand(Monster monster, MonsterCommand command, Quinoa quinoa)
 {
     switch(command.commandCode)
     {
         case MonsterCommandCode.NULL: break; //do nothing
         case MonsterCommandCode.MOVE: executeMoveCommand(monster, command, quinoa); break;
         case MonsterCommandCode.ATTACK: executeAttackCommand(monster, command, quinoa); break;
         case MonsterCommandCode.PICKUP: executePickupCommand(monster, command, quinoa); break;
         case MonsterCommandCode.DROP: executeDropCommand(monster, command, quinoa); break;
         case MonsterCommandCode.EQUIP: executeEquipCommand(monster, command, quinoa); break;
         case MonsterCommandCode.UNEQUIP: executeUnequipCommand(monster, command, quinoa); break;
         case MonsterCommandCode.ITEM_VERB: executeItemVerbCommand(monster, command, quinoa); break;
         default: break; //do nothing
     }
 }
        public static void executeAttackCommand(Monster monster, MonsterCommand command, Quinoa quinoa)
        {
            Monster monsterToAttack = quinoa.getMonsterByID(command.getParameter("monsterID"));
            if(monsterToAttack != null)
            {
                if(quinoa.monsterIsAdjacent(monster.x, monster.y, monsterToAttack.ID))
                {
                    //Do a combat attack
                    MonsterActionManager.combat(monster, monsterToAttack, quinoa);

                    //Check for removal if not player
                    //Also check for kill
                    if(!monsterToAttack.ID.Equals(MonsterActionManager.PLAYER_ID) && !(monsterToAttack.stats.getCurrentHealth() > 1))
                    {
                        monsterToAttack.RemoveObject();
                        monsterKilled(monster, monsterToAttack, quinoa);
                    }

                }
                else
                {
                    //Attack misses automatically
                    if(monster.ID.Equals(MonsterActionManager.PLAYER_ID))
                    {
                        quinoa.getMessageManager().addMessage("You miss the " + EnumUtil.EnumName<MonsterCode>(monsterToAttack.monsterCode) + ".");
                    }
                }
            }
            else
            {
                //Monster cannot be found
                if(monster.ID.Equals(MonsterActionManager.PLAYER_ID))
                {
                    quinoa.getMessageManager().addMessage("You swing at nothing.");
                }
            }
        }
 public static void setUnequipCommand(Monster monster, String itemID)
 {
     MonsterCommand newCommand = new MonsterCommand();
     newCommand.commandCode = MonsterCommandCode.UNEQUIP;
     newCommand.counter = MonsterActionManager.getSpeed(monster)/2;
     newCommand.addParameter("itemID", itemID);
     monster.setCommand(newCommand);
 }
 public static void setPickupCommand(Monster monster)
 {
     MonsterCommand newCommand = new MonsterCommand();
     newCommand.commandCode = MonsterCommandCode.PICKUP;
     newCommand.counter = MonsterActionManager.getSpeed(monster)/4;
     monster.setCommand(newCommand);
 }
 public static void setNullCommand(Monster monster)
 {
     MonsterCommand newCommand = new MonsterCommand();
     newCommand.commandCode = MonsterCommandCode.NULL;
     newCommand.counter = 1;
     monster.setCommand(newCommand);
 }
 public static void setMoveCommand(Monster monster, Direction direction)
 {
     MonsterCommand newCommand = new MonsterCommand();
     newCommand.commandCode = MonsterCommandCode.MOVE;
     newCommand.counter = MonsterActionManager.getSpeed(monster);
     newCommand.addParameter("direction", EnumUtil.EnumName<Direction>(direction));
     monster.setCommand(newCommand);
 }
 public static void setItemVerbCommand(Monster monster, Item item, ItemVerb verb, int x, int y)
 {
     MonsterCommand newCommand = new MonsterCommand();
     newCommand.commandCode = MonsterCommandCode.ITEM_VERB;
     newCommand.counter = MonsterActionManager.getSpeed(monster);
     if(item != null)
     {
         newCommand.addParameter("itemID", item.ID);
     }
     else
     {
         newCommand.addParameter("itemID", "");
     }
     newCommand.addParameter("verb", EnumUtil.EnumName<ItemVerb>(verb));
     newCommand.addParameter("x", x+"");
     newCommand.addParameter("y", y+"");
     monster.setCommand(newCommand);
 }
 public static void setAttackCommand(Monster monster, String monsterID)
 {
     MonsterCommand newCommand = new MonsterCommand();
     newCommand.commandCode = MonsterCommandCode.ATTACK;
     newCommand.counter = MonsterActionManager.getSpeed(monster)/2;
     newCommand.addParameter("monsterID", monsterID);
     monster.setCommand(newCommand);
 }