For creating inventory items
Inheritance: IItemFactoryManager
Beispiel #1
0
        /// <summary>
        /// Creates an item from its category and its internal name
        /// </summary>
        /// <param name="category"></param>
        /// <param name="internalName"></param>
        /// <returns></returns>
        public MapItem CreateItem(string category, int itemID)
        {
            IItemFactoryManager mgr = null;
            switch (category.ToLower())
            {
                case "mundaneitem":
                    mgr = new MundaneItemsManager();
                    break;
                case "mundaneitems":
                    mgr = new MundaneItemsManager();
                    break;
                case "tile":
                    mgr = new TilesManager();
                    break;
                case "tiles":
                    mgr = new TilesManager();
                    break;
                case "toggleitems":
                    mgr = new ToggleItemsManager();
                    break;
                case "toggleitem":
                    mgr = new ToggleItemsManager();
                    break;
                case "enemies":
                    mgr = new EnemyManager();
                    break;
                case "inventoryitems":
                    mgr = new InventoryItemManager();
                    break;
                default:
                    throw new NotImplementedException("The category : " + category + " could not be found");
            }

            return mgr.CreateItem(itemID);
        }
        /// <summary>
        /// Generates a set of equipped items, not exceeding the total cost. If actor profession is not passed, will assume a balanced warrior, otherwise will emphasise on the profession
        /// </summary>
        /// <returns></returns>
        public static Dictionary<EquipmentLocation, InventoryItem> GenerateEquippedItems(int totalCost, ActorProfession? profession = null)
        {
            Dictionary<EquipmentLocation, InventoryItem> equipped = new Dictionary<EquipmentLocation, InventoryItem>();

            //Decide what percentage to spend on the weapon, the rest will be armour
            int weaponPercentage = 3 + GameState.Random.Next(8);

            if (profession.HasValue && profession.Value == ActorProfession.BRUTE)
            {
                //Spend more on weapons, and less on armour
                weaponPercentage += 2;
            }
            else if (profession.HasValue && profession.Value == ActorProfession.DEFENDER)
            {
                //Spend less on weapon, and more on armour
                weaponPercentage -= 2;
            }

            InventoryItemManager mgr = new InventoryItemManager();

            int moneyLeft = totalCost;

            int moneyForWeapon = moneyLeft * weaponPercentage / 10;

            //If it's a ranged user, give him a ranged one instead of a WEAPON

            InventoryItem weapon = null;

            if (profession.HasValue && profession.Value == ActorProfession.RANGED)
            {
                weapon = mgr.GetBestCanAfford("BOW", moneyForWeapon);

                if (weapon != null)
                {
                    //Equip it
                    equipped.Add(EquipmentLocation.BOW, weapon);
                    //And reduce the value
                    moneyLeft -= weapon.BaseValue;
                }

                //We'll also need a hand to hand weapon
                moneyForWeapon /= 3; //Buy one a third of the price

            }

            if (moneyLeft > moneyForWeapon)
            {

                //Buy the weapon
                weapon = mgr.GetBestCanAfford("WEAPON", moneyForWeapon);

                if (weapon != null)
                {
                    //Equip it
                    equipped.Add(EquipmentLocation.WEAPON, weapon);
                    //And reduce the value
                    moneyLeft -= weapon.BaseValue;
                }
            }

            //Now let's buy the rest of the items. For now let's divide everything equally and try to get everyything at least
            int moneyForEachPiece = moneyLeft / 4;

            //Try to buy an armour piece for each part
            //Shield
            var shield = mgr.GetBestCanAfford("SHIELD", moneyForEachPiece);

            if (shield != null)
            {
                //Equip it
                equipped.Add(EquipmentLocation.SHIELD, shield);
                //And reduce the value
                moneyLeft -= shield.BaseValue;
            }

            //Helm
            var helm = mgr.GetBestCanAfford("HELM", moneyForEachPiece);

            if (helm != null)
            {
                equipped.Add(EquipmentLocation.HEAD, helm);

                moneyLeft -= helm.BaseValue;
            }

            var bodyArmour = mgr.GetBestCanAfford("BODY ARMOUR", moneyForEachPiece);

            if (bodyArmour != null)
            {
                equipped.Add(EquipmentLocation.BODY, bodyArmour);
                moneyLeft -= bodyArmour.BaseValue;
            }

            var legs = mgr.GetBestCanAfford("LEGS", moneyForEachPiece);

            if (legs != null)
            {
                equipped.Add(EquipmentLocation.LEGS, legs);
                moneyLeft -= legs.BaseValue;
            }

            //Now that we presumably have one of each, let's buy something better

            //To do this, let's start with a divisor of 3.
            //We see if we can buy three better items.
            //Then we look at what we can do with the rest divided by 2
            //Then we look at what we can do with the rest divided by 1
            //And if that doesn't work, we 'lose' the rest

            for (int divisor = 3; divisor > 0; divisor--)
            {
                int moneyToSpend = moneyLeft / divisor;

                for (int i = 0; i < divisor; i++)
                {
                    var item = mgr.GetBestCanAfford("Armour", moneyToSpend);

                    if (item == null)
                    {
                        continue;
                    }

                    InventoryItem previousItem = null;

                    //Do we have something else already?
                    if (equipped.ContainsKey(item.EquippableLocation.Value))
                    {
                        previousItem = equipped[item.EquippableLocation.Value];

                        //Does one cost more than the other ?
                        if (item.BaseValue >= previousItem.BaseValue)
                        {
                            //Swap them
                            equipped.Remove(item.EquippableLocation.Value);
                            equipped.Add(item.EquippableLocation.Value, item);

                            //And fix the total amount of money
                            moneyLeft += previousItem.BaseValue;
                            moneyLeft -= item.BaseValue;

                            moneyToSpend = moneyLeft / divisor;
                        }
                    }
                    else
                    {
                        equipped.Add(item.EquippableLocation.Value, item);
                        moneyLeft -= item.BaseValue;

                        moneyToSpend = moneyLeft / divisor;
                    }

                }
            }

            //Do we still have any cash?
            if (moneyLeft > 0)
            {
                //Pick up some form of jewelry
                var item = mgr.GetBestCanAfford("ring", moneyLeft);

                if (item != null)
                {
                    equipped.Add(EquipmentLocation.RING1, item);
                }

            }

            //Equip them
            foreach (var value in equipped.Values)
            {
                value.IsEquipped = true;
                value.InInventory = true;
            }

            return equipped;
        }
        /// <summary>
        /// Updates the Vendor's stock to brand new stock
        /// </summary>
        /// <param name="actor"></param>
        public void UpdateVendorStock(Actor actor)
        {
            //First see how much money they have to buy stuff with.
            //Money to buy stuff = SUM (Base Values of old stock Inventory Items) + Money on Hand - 1000

            int totalMoney = actor.VendorDetails.Stock.GetAllObjects().Sum(s => s.BaseValue) + actor.VendorDetails.Money - 1000;

            //Generate the stuff
            InventoryItemManager iim = new InventoryItemManager();

            actor.VendorDetails.Stock = new GroupedList<InventoryItem>();
            actor.VendorDetails.GenerationTime = new DivineRightDateTime(GameState.UniverseTime);

            switch (actor.VendorDetails.VendorType)
            {
                case VendorType.GENERAL:
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.ARMOUR.ToString(), totalMoney / 4))
                    {
                        inv.InInventory = true;
                        actor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.LOOT.ToString(), totalMoney / 4))
                    {
                        inv.InInventory = true;
                        actor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.WEAPON.ToString(), totalMoney / 4))
                    {
                        inv.InInventory = true;
                        actor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.SUPPLY.ToString(), totalMoney / 4))
                    {
                        inv.InInventory = true;
                        actor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    break;
                case VendorType.SMITH:
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.ARMOUR.ToString(), totalMoney / 2))
                    {
                        inv.InInventory = true;
                        actor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.WEAPON.ToString(), totalMoney / 2))
                    {
                        inv.InInventory = true;
                        actor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    break;
                case VendorType.TRADER:
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.LOOT.ToString(), totalMoney))
                    {
                        inv.InInventory = true;
                        actor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    break;
                case VendorType.TAVERN:
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.SUPPLY.ToString(), totalMoney))
                    {
                        inv.InInventory = true;
                        actor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    break;
            }

            actor.VendorDetails.Money = 1000;
        }
        /// <summary>
        /// Generates a vendor, adds the vendor details to the actor being created
        /// </summary>
        /// <param name="newActor"></param>
        /// <param name="actor"></param>
        public void GenerateVendor(Actor newActor, MapletActor actor)
        {
            newActor.VendorDetails = new VendorDetails();
            newActor.VendorDetails.VendorType = actor.VendorType.Value;
            newActor.VendorDetails.VendorLevel = actor.VendorLevel ?? 1;
            newActor.VendorDetails.GenerationTime = new DivineRightDateTime(GameState.UniverseTime);

            //Generate the stuff
            InventoryItemManager iim = new InventoryItemManager();

            int maxCategorySize = 1000 * newActor.VendorDetails.VendorLevel;

            newActor.VendorDetails.Stock = new GroupedList<InventoryItem>();

            switch (newActor.VendorDetails.VendorType)
            {
                case VendorType.GENERAL:
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.SUPPLY.ToString(), (int)(maxCategorySize * 0.75)))
                    {
                        inv.InInventory = true;
                        newActor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.LOOT.ToString(), (int)(maxCategorySize * 0.75)))
                    {
                        inv.InInventory = true;
                        newActor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.ARMOUR.ToString(), (int)(maxCategorySize * 0.75)))
                    {
                        inv.InInventory = true;
                        newActor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.WEAPON.ToString(), (int)(maxCategorySize * 0.75)))
                    {
                        inv.InInventory = true;
                        newActor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    break;
                case VendorType.SMITH:
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.ARMOUR.ToString(), (int)(maxCategorySize * 1.5)))
                    {
                        inv.InInventory = true;
                        newActor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.WEAPON.ToString(), (int)(maxCategorySize * 1.5)))
                    {
                        inv.InInventory = true;
                        newActor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    break;
                case VendorType.TRADER:
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.LOOT.ToString(), maxCategorySize * 3))
                    {
                        inv.InInventory = true;
                        newActor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    break;
                case VendorType.TAVERN:
                    foreach (InventoryItem inv in iim.GetItemsWithAMaxValue(InventoryCategory.SUPPLY.ToString(), maxCategorySize))
                    {
                        inv.InInventory = true;
                        newActor.VendorDetails.Stock.Add(inv.Category, inv);
                    }
                    break;
            }

            newActor.VendorDetails.Money = 1000;
        }
        /// <summary>
        /// Get a blessing for this particular actor, and apply it.
        /// </summary>
        /// <param name="actor"></param>
        public static void GetAndApplyBlessing(Actor actor, out LogFeedback logFeedback)
        {
            //Determine how much skill they have
            int effectiveSkill = actor.Attributes.GetSkill(SkillName.RITUALIST) + actor.Attributes.Char - 5;

            effectiveSkill = effectiveSkill > 1 ? effectiveSkill : 1; //at least 1

            //Get a random number from 0 to effectiveskill * 2
            int randomNumber = GameState.Random.Next(0, effectiveSkill * 2);

            //Grab this number and pick the Blessing with the right enum. if we're too big then go for the biggest value

            BlessingType[] blessings = (BlessingType[])Enum.GetValues(typeof(BlessingType));

            if (randomNumber >= blessings.Length)
            {
                randomNumber = blessings.Length;
            }

            //And your blessing is....

            BlessingType blessing = blessings[randomNumber];

            //Now let's see what type of blessing it is

            InventoryItemManager iim = new InventoryItemManager();

            Effect effect = new Effect();
            logFeedback = null;
            switch (blessing)
            {
                case BlessingType.AGIL_1:
                    //Apply +1 agility for 4 times the effective skill
                    effect.EffectAmount = 1;
                    effect.Name = EffectName.AGIL;
                    effect.MinutesLeft = 4 * effectiveSkill;
                    effect.EffectDisappeared = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "The effect of the blessing disappears");
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel different. Good different");
                    break;
                case BlessingType.AGIL_2:
                    effect.EffectAmount = 2;
                    effect.Name = EffectName.AGIL;
                    effect.MinutesLeft = 4 * effectiveSkill;
                    effect.EffectDisappeared = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "The effect of the blessing disappears");
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel different. Good different");
                    break;
                case BlessingType.ARMOUR:
                    {
                        //Spawn a piece of armour worth 50 * effective skill
                        var inventoryItem = iim.GetBestCanAfford("ARMOUR", 50 * effectiveSkill);
                        if (inventoryItem != null)
                        {
                            inventoryItem.InInventory = true;
                            actor.Inventory.Inventory.Add(inventoryItem.Category, inventoryItem);
                            logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "Your have been given a gift...");
                        }
                        else
                        {
                            logFeedback = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkRed, "Your prayers have not been answered");
                        }
                    }
                    break;
                case BlessingType.BRAWN_1:
                    effect.EffectAmount = 1;
                    effect.Name = EffectName.BRAWN;
                    effect.MinutesLeft = 4 * effectiveSkill;
                    effect.EffectDisappeared = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "The effect of the blessing disappears");
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel different. Good different");
                    break;
                case BlessingType.BRAWN_2:
                    effect.EffectAmount = 2;
                    effect.Name = EffectName.BRAWN;
                    effect.MinutesLeft = 4 * effectiveSkill;
                    effect.EffectDisappeared = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "The effect of the blessing disappears");
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel different. Good different");
                    break;
                case BlessingType.CHAR_1:
                    effect.EffectAmount = 1;
                    effect.Name = EffectName.CHAR;
                    effect.MinutesLeft = 4 * effectiveSkill;
                    effect.EffectDisappeared = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "The effect of the blessing disappears");
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel different. Good different");
                    break;
                case BlessingType.CHAR_2:
                    effect.EffectAmount = 2;
                    effect.Name = EffectName.CHAR;
                    effect.MinutesLeft = 4 * effectiveSkill;
                    effect.EffectDisappeared = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "The effect of the blessing disappears");
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel different. Good different");
                    break;
                case BlessingType.DEFENCE:
                    //TODO LATER
                    break;
                case BlessingType.EXPERIENCE:
                    //Increase the skill in Rituals by a 10 times (fixed)
                    for (int i = 0; i < 10; i++)
                    {
                        actor.Attributes.IncreaseSkill(SkillName.RITUALIST);
                    }
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "Nothing happens, but you feel smarter for having tried");
                    break;
                case BlessingType.EXPLORE:
                    //Explore the entire map
                    for (int x = 0; x < GameState.LocalMap.localGameMap.GetLength(0); x++)
                    {
                        for (int y = 0; y < GameState.LocalMap.localGameMap.GetLength(1); y++)
                        {
                            if (GameState.LocalMap.localGameMap[x, y, 0] != null)
                            {
                                GameState.LocalMap.localGameMap[x, y, 0].WasVisited = true;
                            }
                        }
                    }
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You have been granted knowledge on the structure of this level");
                    break;
                case BlessingType.FEEDING:
                    //A slap-up meal
                    actor.FeedingLevel = FeedingLevel.STUFFED;
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel very full...");
                    break;
                case BlessingType.HEALING:
                    //Heal the user for as many rounds as effective skill
                    HealthCheckManager.HealCharacter(actor, effectiveSkill);
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel your wounds knit together");
                    break;
                case BlessingType.INTEL_1:
                    effect.EffectAmount = 1;
                    effect.Name = EffectName.INTEL;
                    effect.MinutesLeft = 4 * effectiveSkill;
                    effect.EffectDisappeared = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "The effect of the blessing disappears");
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel different. Good different");
                    break;
                case BlessingType.INTEL_2:
                    effect.EffectAmount = 2;
                    effect.Name = EffectName.INTEL;
                    effect.MinutesLeft = 4 * effectiveSkill;
                    effect.EffectDisappeared = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "The effect of the blessing disappears");
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel different. Good different");
                    break;
                case BlessingType.KILL:
                    //Go through the map and slaughter a total amount of enemies equal to effective skill
                    for (int i = 0; i < effectiveSkill; i++)
                    {
                        var deadActor = GameState.LocalMap.Actors.Where(a => a.IsAggressive && a.IsActive && a.IsAlive && !a.IsPlayerCharacter).FirstOrDefault();

                        if (deadActor != null)
                        {
                            CombatManager.KillCharacter(deadActor);
                        }
                    }
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "A sprit of death travels through the location and slaughters a number of your enemies");
                    break;
                case BlessingType.LOOT:
                    {
                        //Spawn a piece of loot worth 50 * effective skill
                        var inventoryItem = iim.GetBestCanAfford("LOOT", 50 * effectiveSkill);
                        if (inventoryItem != null)
                        {
                            inventoryItem.InInventory = true;
                            actor.Inventory.Inventory.Add(inventoryItem.Category, inventoryItem);
                            logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "Your have been given a gift...");
                        }
                        else
                        {
                            logFeedback = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkRed, "Your prayers have not been answered");
                        }
                    }
                    break;
                case BlessingType.PERC_1:
                    effect.EffectAmount = 1;
                    effect.Name = EffectName.PERC;
                    effect.MinutesLeft = 4 * effectiveSkill;
                    effect.EffectDisappeared = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "The effect of the blessing disappears");
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel different. Good different");
                    break;
                case BlessingType.PERC_2:
                    effect.EffectAmount = 2;
                    effect.Name = EffectName.PERC;
                    effect.MinutesLeft = 4 * effectiveSkill;
                    effect.EffectDisappeared = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "The effect of the blessing disappears");
                    logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "You feel different. Good different");
                    break;
                case BlessingType.WEAPON:
                    {
                        //Spawn a piece of loot worth 50 * effective skill
                        var inventoryItem = iim.GetBestCanAfford("WEAPON", 50 * effectiveSkill);
                        if (inventoryItem != null)
                        {
                            inventoryItem.InInventory = true;
                            actor.Inventory.Inventory.Add(inventoryItem.Category, inventoryItem);
                            logFeedback = new LogFeedback(InterfaceSpriteName.SUN, Color.ForestGreen, "Your have been given a gift...");
                        }
                        else
                        {
                            logFeedback = new LogFeedback(InterfaceSpriteName.MOON, Color.DarkRed, "Your prayers have not been answered");
                        }
                    }
                    break;
            }

            if (effect != null)
            {
                //Apply it
                EffectsManager.PerformEffect(actor, effect);
            }
        }
        /// <summary>
        /// Creates and puts a particular room in a particular rectangle
        /// </summary>
        /// <param name="roomType"></param>
        /// <param name="rect"></param>
        /// <param name="circle">When the room is a Summoning Room, there's the circle</param>
        private static void PutRoom(MapBlock[,] map, int tileID, int level, DungeonRoomType roomType, Rectangle rect, out SummoningCircle circle)
        {
            circle = null;

            string tagName = roomType.ToString().ToLower().Replace("_", " ") + " room";

            LocalMapXMLParser parser = new LocalMapXMLParser();
            var maplet = parser.ParseMapletFromTag(tagName);

            //Change the width and height to match the rectangle we're fitting it in
            //Leave a rim of 1
            maplet.SizeX = rect.Width - 2;
            maplet.SizeY = rect.Height - 2;

            LocalMapGenerator lmg = new LocalMapGenerator();

            Actor[] actors = null;
            MapletActorWanderArea[] areas = null;
            MapletPatrolPoint[] patrolRoutes = null;
            MapletFootpathNode[] footpathNodes = null;

            var gennedMap = lmg.GenerateMap(tileID, null, maplet, false, "", OwningFactions.UNDEAD, out actors, out areas, out patrolRoutes, out footpathNodes);

            //Is this a summoning room?
            if (roomType == DungeonRoomType.SUMMONING)
            {
                //Go through each map block and see if we find a summoning circle
                for (int x = 0; x < gennedMap.GetLength(0); x++)
                {
                    for (int y = 0; y < gennedMap.GetLength(1); y++)
                    {
                        var block = gennedMap[x, y];
                        if (block.GetTopMapItem() != null && block.GetTopMapItem().GetType().Equals(typeof(SummoningCircle)))
                        {
                            circle = block.GetTopMapItem() as SummoningCircle;
                        }
                    }
                }
            }

            if (roomType == DungeonRoomType.COMBAT_PIT)
            {
                int docLevel = (int) level/4;
                docLevel = docLevel < 1 ? 1 : docLevel;
                docLevel = docLevel > 5 ? 5 : docLevel;
                //Generate a combat manual - Level [1..5] will be determined by floor of Dungeon Level /4
                CombatManual cm = new CombatManual(SpecialAttacksGenerator.GenerateSpecialAttack(docLevel));

                //Now place it, somewhere (or at least try 50 times)
                for(int i=0; i < 50; i++)
                {
                    MapBlock randomBlock = gennedMap[GameState.Random.Next(gennedMap.GetLength(0)), GameState.Random.Next(gennedMap.GetLength(1))];

                    if (randomBlock.MayContainItems)
                    {
                        randomBlock.ForcePutItemOnBlock(cm);
                        break;
                    }
                }
            }

            //Do we have any treasure chests?
            for (int x = 0; x < gennedMap.GetLength(0); x++)
            {
                for (int y = 0; y < gennedMap.GetLength(1); y++)
                {
                    var block = gennedMap[x, y];
                    if (block.GetTopMapItem() != null && block.GetTopMapItem().GetType().Equals(typeof(TreasureChest)))
                    {
                        TreasureChest chest = block.GetTopMapItem() as TreasureChest;

                        InventoryItemManager iim = new InventoryItemManager();

                        //Fill em up
                        chest.Contents = iim.FillTreasureChest((InventoryCategory[])Enum.GetValues(typeof(InventoryCategory)), 300 + (50 * level));
                    }
                }
            }

            //Now fit one into the other
            lmg.JoinMaps(map, gennedMap, rect.X + 1, rect.Y + 1);
        }
        /// <summary>
        /// Generates loot for treasure rooms. We will have LOOT_MULTIPLIER of loot multiplied by tierNumber
        /// </summary>
        public void GenerateLoot(MapBlock[,] blocks, int tierNumber)
        {
            //Determine the maximum total value we want to generate
            int totalValue = tierNumber * LOOT_MULTIPLIER;

            InventoryItemManager mgr = new InventoryItemManager();
            var items = mgr.GetItemsWithAMaxValue(null, totalValue);

            //Put the items on the map
            foreach (var item in items)
            {
                //Find a random point. Try 50 times
                for (int attempts = 0; attempts < 50; attempts++)
                {
                    var chosenBlock = blocks[GameState.Random.Next(blocks.GetLength(0)), GameState.Random.Next(blocks.GetLength(1))];

                    if (chosenBlock.MayContainItems)
                    {
                        //Put it in
                        chosenBlock.ForcePutItemOnBlock(item);
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Performs the action and handles feedback
        /// </summary>
        /// <param name="?"></param>
        public void PerformAction(MapCoordinate coord, MapItem item, DRObjects.Enums.ActionType actionType, object[] args)
        {
            //remove any viewtiletext components or contextmenu components
            for (int i = 0; i < interfaceComponents.Count; i++)
            {
                var type = interfaceComponents[i].GetType();
                if (type.Equals(typeof(ViewTileTextComponent)) || type.Equals(typeof(ContextMenuComponent)))
                {
                    //delete
                    interfaceComponents.RemoveAt(i);
                    i--;
                }
            }

            ActionFeedback[] fb = UserInterfaceManager.PerformAction(coord, item, actionType, args);

            //go through all the feedback

            for (int i = 0; i < fb.Length; i++)
            {
                ActionFeedback feedback = fb[i];

                if (feedback == null)
                {
                    continue;
                }

                if (feedback.GetType().Equals(typeof(AttackFeedback)))
                {
                    AttackFeedback af = feedback as AttackFeedback;

                    var combatAf = CombatManager.Attack(af.Attacker, af.Defender, AttackLocation.CHEST); //always attack the chest

                    var tempFBList = fb.ToList();
                    tempFBList.AddRange(combatAf);

                    fb = tempFBList.ToArray();

                }
                else if (feedback.GetType().Equals(typeof(OpenInterfaceFeedback)))
                {
                    OpenInterfaceFeedback oif= feedback as OpenInterfaceFeedback;

                    //Generate one
                    if (oif.Interface.GetType() == typeof(CombatManualInterface))
                    {
                        var cmi = oif.Interface as CombatManualInterface;

                        CombatManualComponent cmc = new CombatManualComponent(GraphicsDevice.Viewport.Width / 2 - 200, GraphicsDevice.Viewport.Height / 2 - 150, cmi.Manual);

                        interfaceComponents.Add(cmc);
                    }
                    else if (oif.Interface.GetType() == typeof(ThrowItemInterface))
                    {
                        var tii = oif.Interface as ThrowItemInterface;

                        //Do we have LoS to that point?
                        if (GameState.LocalMap.HasDirectPath(GameState.PlayerCharacter.MapCharacter.Coordinate,tii.Coordinate))
                        {
                            ThrowItemComponent tic = new ThrowItemComponent(Mouse.GetState().X, Mouse.GetState().Y, tii.Coordinate, GameState.PlayerCharacter);
                            interfaceComponents.Add(tic);
                        }
                        else
                        {
                            var tempFBList = fb.ToList();
                            tempFBList.Add(new TextFeedback("You can't see there"));

                            fb = tempFBList.ToArray();
                        }
                    }
                }
                else
                if (feedback.GetType().Equals(typeof(TextFeedback)))
                {
                    MouseState mouse = Mouse.GetState();

                    //Display it
                    interfaceComponents.Add(new ViewTileTextComponent(mouse.X + 15, mouse.Y, (feedback as TextFeedback).Text));
                }
                else if (feedback.GetType().Equals(typeof(LogFeedback)))
                {
                    GameState.NewLog.Add(feedback as LogFeedback);
                }
                else if (feedback.GetType().Equals(typeof(InterfaceToggleFeedback)))
                {
                    InterfaceToggleFeedback iop = feedback as InterfaceToggleFeedback;

                    if (iop.InterfaceComponent == InternalActionEnum.OPEN_ATTACK && iop.Open)
                    {
                        //Open the attack interface for a particular actor. If one is not open already
                        //Identify the actor in question
                        var actorMapItem = iop.Argument as LocalCharacter;

                        //Locate the actual actor
                        Actor actor = GameState.LocalMap.Actors.Where(lm => lm.MapCharacter == actorMapItem).FirstOrDefault(); //Yep, it's a pointer equals

                        bool openAlready = false;

                        //Do we have one open already?
                        foreach (AttackActorComponent aac in interfaceComponents.Where(ic => ic.GetType().Equals(typeof(AttackActorComponent))))
                        {
                            if (aac.TargetActor.Equals(actor))
                            {
                                openAlready = true;
                                break;
                            }
                        }

                        if (!openAlready)
                        {
                            //Open it. Otherwise don't do anything
                            interfaceComponents.Add(new AttackActorComponent(150, 150, GameState.PlayerCharacter, actor) { Visible = true });
                        }

                    }
                    else if (iop.InterfaceComponent == InternalActionEnum.OPEN_ATTACK && !iop.Open)
                    {
                        //Close it
                        var actor = iop.Argument as Actor;

                        AttackActorComponent component = null;

                        foreach (AttackActorComponent aac in interfaceComponents.Where(ic => ic.GetType().Equals(typeof(AttackActorComponent))))
                        {
                            if (aac.TargetActor.Equals(actor))
                            {
                                component = aac;
                            }
                        }

                        //Did we have a match?
                        if (component != null)
                        {
                            //remove it
                            interfaceComponents.Remove(component);
                        }

                    }
                    else if (iop.InterfaceComponent == InternalActionEnum.OPEN_TRADE && iop.Open)
                    {
                        //Open trade
                        var arguments = iop.Argument as object[];

                        TradeDisplayComponent tdc = new TradeDisplayComponent(100, 100, arguments[1] as Actor, arguments[0] as Actor);

                        interfaceComponents.Add(tdc);
                    }
                    else if (iop.InterfaceComponent == InternalActionEnum.OPEN_LOOT)
                    {
                        //Open Loot
                        TreasureChest lootContainer = (iop.Argument as object[])[0] as TreasureChest;

                        LootComponent lc = new LootComponent(100, 100, lootContainer);

                        interfaceComponents.Add(lc);
                    }
                }
                else if (feedback.GetType().Equals(typeof(CreateEventFeedback)))
                {
                    CreateEventFeedback eventFeedback = feedback as CreateEventFeedback;

                    var gameEvent = EventHandlingManager.CreateEvent(eventFeedback.EventName);

                    //Create the actual control
                    interfaceComponents.Add(new DecisionPopupComponent(PlayableWidth / 2 - 150, PlayableHeight / 2 - 150, gameEvent));

                }
                else if (feedback.GetType().Equals(typeof(ReceiveEffectFeedback)))
                {
                    ReceiveEffectFeedback recFeed = feedback as ReceiveEffectFeedback;

                    EffectsManager.PerformEffect(recFeed.Effect.Actor, recFeed.Effect);
                }
                else if (feedback.GetType().Equals(typeof(ReceiveBlessingFeedback)))
                {
                    ReceiveBlessingFeedback blessFeedback = feedback as ReceiveBlessingFeedback;

                    LogFeedback lg = null;

                    //Bless him!
                    //Later we're going to want to do this properly so other characters can get blessed too
                    BlessingManager.GetAndApplyBlessing(GameState.PlayerCharacter, out lg);

                    if (lg != null)
                    {
                        //Log it
                        GameState.NewLog.Add(lg);
                    }
                }
                else if (feedback.GetType().Equals(typeof(ReceiveItemFeedback)))
                {
                    ReceiveItemFeedback receiveFeedback = feedback as ReceiveItemFeedback;

                    //Determine which item we're going to generate
                    InventoryItemManager iim = new InventoryItemManager();

                    InventoryItem itm = iim.GetBestCanAfford(receiveFeedback.Category.ToString(), receiveFeedback.MaxValue);

                    if (itm != null)
                    {
                        itm.InInventory = true;

                        GameState.PlayerCharacter.Inventory.Inventory.Add(itm.Category, itm);

                        GameState.NewLog.Add(new LogFeedback(InterfaceSpriteName.SUN, Color.DarkGreen, "You throw in your offering. You then see something glimmer and take it out"));
                    }
                    else
                    {
                        GameState.NewLog.Add(new LogFeedback(InterfaceSpriteName.MOON, Color.DarkBlue, "You throw in your offering. Nothing appears to be there. Hmm..."));
                    }

                }
                else if (feedback.GetType().Equals(typeof(LocationChangeFeedback)))
                {
                    //Remove settlement button and interface
                    var locDetails = this.interfaceComponents.Where(ic => ic.GetType().Equals(typeof(LocationDetailsComponent))).FirstOrDefault();

                    if (locDetails != null)
                    {
                        this.interfaceComponents.Remove(locDetails);
                    }

                    var button = this.menuButtons.Where(mb => (mb as AutoSizeGameButton).Action == InternalActionEnum.TOGGLE_SETTLEMENT).FirstOrDefault();

                    if (button != null)
                    {
                        this.menuButtons.Remove(button);
                    }

                    LocationChangeFeedback lce = feedback as LocationChangeFeedback;

                    if (lce.Location != null)
                    {
                        LoadLocation(lce.Location);

                        if (lce.Location is Settlement)
                        {

                            //Makde the components visible
                            LocationDetailsComponent ldc = new LocationDetailsComponent(GameState.LocalMap.Location as Settlement, PlayableWidth - 170, 0);
                            ldc.Visible = true;
                            interfaceComponents.Add(ldc);
                            menuButtons.Add(new AutoSizeGameButton(" Settlement ", this.game.Content, InternalActionEnum.TOGGLE_SETTLEMENT, new object[] { }, 270, GraphicsDevice.Viewport.Height - 35));
                            Window_ClientSizeChanged(null, null); //button is in the wrong position for some reason
                        }

                        GameState.LocalMap.IsGlobalMap = false;
                    }
                    else if (lce.VisitMainMap)
                    {
                        //If it's a bandit camp or a site, update the values of the members
                        if (GameState.LocalMap.Location as MapSite != null || GameState.LocalMap.Location as BanditCamp != null)
                        {
                            if (GameState.LocalMap.Location as BanditCamp != null)
                            {
                                var banditCamp = GameState.LocalMap.Location as BanditCamp;

                                banditCamp.BanditTotal = GameState.LocalMap.Actors.Count(a => a.IsActive && a.IsAlive && !a.IsPlayerCharacter
                                    && a.EnemyData != null && a.EnemyData.Profession == ActorProfession.WARRIOR);

                                //Has it been cleared?
                                if (banditCamp.BanditTotal == 0)
                                {
                                    //Find the item
                                    var campItem = GameState.GlobalMap.CampItems.FirstOrDefault(ci => ci.Camp == (GameState.LocalMap.Location as BanditCamp));

                                    if (campItem != null)
                                    {
                                        campItem.IsActive = false;

                                        GameState.GlobalMap.CampItems.Remove(campItem);

                                        //Also find the coordinate of the camp, grab a circle around it and remove the owner
                                        var mapblocks = GameState.GlobalMap.GetBlocksAroundPoint(campItem.Coordinate, WorldGenerationManager.BANDIT_CLAIMING_RADIUS);

                                        foreach (var block in mapblocks)
                                        {
                                            var tile = (block.Tile as GlobalTile);

                                            //Owned by bandit
                                            if (tile.Owner == 50)
                                            {
                                                tile.RemoveOwner();
                                            }
                                        }

                                        //Yes. Let's clear the camp
                                        GameState.NewLog.Add(new LogFeedback(InterfaceSpriteName.SWORD, Color.Black, "You drive the bandits away from the camp"));
                                    }

                                }

                            }
                            else if (GameState.LocalMap.Location as MapSite != null)
                            {
                                var site = GameState.LocalMap.Location as MapSite;

                                site.SiteData.ActorCounts.Clear();

                                foreach (var actorProfession in (ActorProfession[])Enum.GetValues(typeof(ActorProfession)))
                                {
                                    int count = GameState.LocalMap.Actors.Count(a => a.IsActive && a.IsAlive && !a.IsPlayerCharacter
                                    && a.EnemyData != null && a.EnemyData.Profession == actorProfession);

                                    site.SiteData.ActorCounts.Add(actorProfession, count);
                                }

                                if (site.SiteData.ActorCounts[ActorProfession.WARRIOR] == 0)
                                {
                                    //Out of warriors, abandon it. We'll decide who really owns it later
                                    site.SiteData.OwnerChanged = true;
                                    site.SiteData.MapRegenerationRequired = true;
                                    site.SiteData.Owners = OwningFactions.ABANDONED;
                                    site.SiteData.ActorCounts = new Dictionary<ActorProfession, int>();
                                }
                            }
                        }
                        //Serialise the old map
                        GameState.LocalMap.SerialiseLocalMap();

                        //Clear the stored location items
                        GameState.LocalMap.Location = null;

                        LoadGlobalMap(GameState.PlayerCharacter.GlobalCoordinates);

                        GameState.LocalMap.IsGlobalMap = true;

                    }
                    else if (lce.RandomEncounter != null)
                    {
                        //Get the biome
                        LoadRandomEncounter(lce.RandomEncounter.Value);
                    }
                }
                else if (feedback.GetType().Equals(typeof(DropItemFeedback)))
                {
                    DropItemFeedback dif = feedback as DropItemFeedback;

                    //Drop the item underneath the player
                    GameState.LocalMap.GetBlockAtCoordinate(dif.ItemToDrop.Coordinate).PutItemUnderneathOnBlock(dif.ItemToDrop);

                    //Remove from inventory
                    dif.ItemToDrop.InInventory = false;

                    GameState.PlayerCharacter.Inventory.Inventory.Remove(dif.ItemToDrop.Category, dif.ItemToDrop);
                }
                else if (feedback.GetType().Equals(typeof(TimePassFeedback)))
                {
                    TimePassFeedback tpf = feedback as TimePassFeedback;

                    //Move time forth
                    GameState.IncrementGameTime(DRTimeComponent.MINUTE, tpf.TimePassInMinutes);

                    //Is the character dead?
                    if (!GameState.PlayerCharacter.IsAlive)
                    {
                        var gameEvent = EventHandlingManager.CreateEvent("Hunger Death");

                        //Create the actual control
                        interfaceComponents.Add(new DecisionPopupComponent(PlayableWidth / 2 - 150, PlayableHeight / 2 - 150, gameEvent));
                    }
                }
                else if (feedback.GetType().Equals(typeof(VisitedBlockFeedback)))
                {
                    VisitedBlockFeedback vbf = feedback as VisitedBlockFeedback;

                    //Visit a region equal to the line of sight of the player character -
                    var blocks = GameState.LocalMap.GetBlocksAroundPoint(vbf.Coordinate, GameState.PlayerCharacter.LineOfSight);

                    //Only do the ones which can be ray traced
                    foreach (var block in RayTracingHelper.RayTraceForExploration(blocks, GameState.PlayerCharacter.MapCharacter.Coordinate))
                    {
                        block.WasVisited = true;
                    }
                }
                else if (feedback.GetType().Equals(typeof(DescendDungeonFeedback)))
                {
                    DescendDungeonFeedback ddf = feedback as DescendDungeonFeedback;

                    (GameState.LocalMap.Location as Dungeon).DifficultyLevel++;

                    this.LoadLocation(GameState.LocalMap.Location, true);
                }

            }

            //Update the log control
            log.UpdateLog();
        }
        public override void Initialize()
        {
            base.Initialize();
            if (parameters.Length == 0)
            {
                TestFunctions.PrepareFileTestMap();
            }
            else if (parameters[0].ToString().Equals("Village"))
            {
                //TestFunctions.ParseXML();
                TestFunctions.GenerateSettlement();

                InventoryItemManager mgr = new InventoryItemManager();

                for (int i = 0; i < 500; i++)
                {
                    var block = GameState.LocalMap.GetBlockAtCoordinate(new MapCoordinate(GameState.Random.Next(GameState.LocalMap.localGameMap.GetLength(0)), GameState.Random.Next(GameState.LocalMap.localGameMap.GetLength(1)), 0, MapType.LOCAL));

                    if (block.MayContainItems)
                    {
                        var item = mgr.CreateItem(DatabaseHandling.GetItemIdFromTag(Archetype.INVENTORYITEMS, "loot")) as InventoryItem;
                        item.Coordinate = new MapCoordinate(block.Tile.Coordinate);
                        block.ForcePutItemOnBlock(item);
                    }
                }

                //Create the new character stuff
                MultiDecisionComponent mdc = new MultiDecisionComponent(PlayableWidth / 2 - 250, 150, CharacterCreation.GenerateCharacterCreation());
                mdc.Visible = true;

                interfaceComponents.Add(mdc);

                GameState.LocalMap.IsGlobalMap = false;

            }
            else if (parameters[0].ToString().Equals("Continue"))
            {
                GameState.LoadGame();
            }
            else if (parameters[0].ToString().Equals("WorldMap"))
            {
                //Load from the world map
                var worldMap = GameState.GlobalMap.globalGameMap;

                List<MapBlock> collapsedMap = new List<MapBlock>();

                foreach (var block in worldMap)
                {
                    collapsedMap.Add(block);
                }

                GameState.LocalMap = new LocalMap(GameState.GlobalMap.globalGameMap.GetLength(0), GameState.GlobalMap.globalGameMap.GetLength(1), 1, 0);

                //Go through each of them, add them to the local map
                GameState.LocalMap.AddToLocalMap(collapsedMap.ToArray());

                //Let's start the player off at the first capital
                var coordinate = GameState.GlobalMap.WorldSettlements.Where(w => w.IsCapital).Select(w => w.Coordinate).FirstOrDefault();

                //Create the player character. For now randomly. Later we'll start at a capital
                MapItem player = new MapItem();
                player.Coordinate = new MapCoordinate(coordinate);
                player.Description = "The player character";
                player.Graphic = SpriteManager.GetSprite(LocalSpriteName.PLAYERCHAR_MALE);
                player.InternalName = "Player Char";
                player.MayContainItems = false;
                player.Name = "Player";

                MapBlock playerBlock = GameState.LocalMap.GetBlockAtCoordinate(player.Coordinate);
                playerBlock.PutItemOnBlock(player);

                GameState.PlayerCharacter = new Actor();
                GameState.PlayerCharacter.MapCharacter = player;
                GameState.PlayerCharacter.IsPlayerCharacter = true;

                GameState.PlayerCharacter.Attributes = ActorGeneration.GenerateAttributes("human", DRObjects.ActorHandling.CharacterSheet.Enums.ActorProfession.WARRIOR, 10, GameState.PlayerCharacter);
                GameState.PlayerCharacter.Anatomy = ActorGeneration.GenerateAnatomy("human");

                GameState.PlayerCharacter.Attributes.Health = GameState.PlayerCharacter.Anatomy;

                GameState.PlayerCharacter.Inventory.EquippedItems = ActorGeneration.GenerateEquippedItems(250); //give him 250 worth of stuff

                foreach (var item in GameState.PlayerCharacter.Inventory.EquippedItems.Values)
                {
                    GameState.PlayerCharacter.Inventory.Inventory.Add(item.Category, item);
                }

                GameState.LocalMap.Actors.Add(GameState.PlayerCharacter);

                //What attributes do we want?
                MultiDecisionComponent mdc = new MultiDecisionComponent(PlayableWidth / 2 - 250, 150, CharacterCreation.GenerateCharacterCreation());
                mdc.Visible = true;

                interfaceComponents.Add(mdc);

                GameState.LocalMap.IsGlobalMap = true;

            }
            else if (parameters[0].ToString().Equals("Camp"))
            {

                TestFunctions.ParseXML();
            }
            else
            {
                TestFunctions.GenerateDungeon();

                //Give him random stats so he won't completly suck
                CharacterCreation.ProcessParameters(CharacterCreation.GenerateRandom());

                //Also give him a bow of some sort
                InventoryItemManager iim = new InventoryItemManager();

                InventoryItem item = iim.GetBestCanAfford("WEAPON", 500);

                GameState.PlayerCharacter.SpecialAttacks[0] = SpecialAttacksGenerator.GenerateSpecialAttack(1);
                GameState.PlayerCharacter.SpecialAttacks[1] = SpecialAttacksGenerator.GenerateSpecialAttack(2);
                GameState.PlayerCharacter.SpecialAttacks[2] = SpecialAttacksGenerator.GenerateSpecialAttack(3);

                GameState.PlayerCharacter.SpecialAttacks[1].TimeOutLeft = 5;

              //  GameState.PlayerCharacter.SpecialAttacks[3] = SpecialAttacksGenerator.GenerateSpecialAttack(4);
               // GameState.PlayerCharacter.SpecialAttacks[4] = SpecialAttacksGenerator.GenerateSpecialAttack(5);

                item.InInventory = true;

                //Give them a bunch of potions at random
                for (int i = 0; i < 5; i++ )
                {
                    var potionType = (PotionType[])Enum.GetValues(typeof(PotionType));
                    var potion = potionType.GetRandom();
                    var p = new Potion(potion);

                    p.InInventory = true;

                    GameState.PlayerCharacter.Inventory.Inventory.Add(p.Category, p);
                }

                GameState.PlayerCharacter.Inventory.Inventory.Add(item.Category, item);

            }

            //Add the health control
            HealthDisplayComponent hdc = new HealthDisplayComponent(50, 50, GameState.LocalMap.Actors.Where(a => a.IsPlayerCharacter).FirstOrDefault());
            hdc.Visible = false;
            interfaceComponents.Add(hdc);

            CharacterSheetComponent csc = new CharacterSheetComponent(50, 50, GameState.LocalMap.Actors.Where(a => a.IsPlayerCharacter).FirstOrDefault());
            csc.Visible = false;
            interfaceComponents.Add(csc);

            InventoryDisplayComponent ivt = new InventoryDisplayComponent(50, 50, GameState.LocalMap.Actors.Where(a => a.IsPlayerCharacter).FirstOrDefault());
            ivt.Visible = false;
            interfaceComponents.Add(ivt);

            TextLogComponent tlc = new TextLogComponent(10, GraphicsDevice.Viewport.Height - 50, GameState.NewLog);
            tlc.Visible = true;
            interfaceComponents.Add(tlc);

            log = tlc;

            AdventureDisplayComponent tdc = new AdventureDisplayComponent(GraphicsDevice.Viewport.Width / 2 - 100, 0);
            interfaceComponents.Add(tdc);

            var cemetry = SpriteManager.GetSprite(InterfaceSpriteName.DEAD);

            //Create the menu buttons
            menuButtons.Add(new AutoSizeGameButton("  Health  ", this.game.Content, InternalActionEnum.OPEN_HEALTH, new object[] { }, 50, GraphicsDevice.Viewport.Height - 35));
            menuButtons.Add(new AutoSizeGameButton(" Attributes ", this.game.Content, InternalActionEnum.OPEN_ATTRIBUTES, new object[] { }, 150, GraphicsDevice.Viewport.Height - 35));

            if (GameState.LocalMap.Location as Settlement != null)
            {
                menuButtons.Add(new AutoSizeGameButton(" Settlement ", this.game.Content, InternalActionEnum.TOGGLE_SETTLEMENT, new object[] { }, 270, GraphicsDevice.Viewport.Height - 35));
                LocationDetailsComponent ldc = new LocationDetailsComponent(GameState.LocalMap.Location as Settlement, PlayableWidth - 170, 0);
                ldc.Visible = true;
                interfaceComponents.Add(ldc);
            }

            menuButtons.Add(new AutoSizeGameButton(" Inventory ", this.game.Content, InternalActionEnum.OPEN_INVENTORY, new object[] { }, 350, GraphicsDevice.Viewport.Height - 35));

            //Invoke a size change
            Window_ClientSizeChanged(null, null);
        }
        /// <summary>
        /// Generates the particular Game Multi Event for character creation 
        /// </summary>
        /// <returns></returns>
        public static GameMultiEvent GenerateCharacterCreation()
        {
            var book = SpriteManager.GetSprite(InterfaceSpriteName.BOOK);

            GameMultiEvent gme = new GameMultiEvent();
            gme.EventName = "GENERATE_CHARACTER";
            gme.Image = book;
            gme.Title = "The Avatar is born";
            gme.Text = "And thus, world was done\nHumans forget their maker.\nAvatar will come";

            List<MultiEventChoice> choices = new List<MultiEventChoice>();
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "GEN",
                    Text = "Little is known about their early life",
                });
            choices.Add(new MultiEventChoice()
            {
                ChoiceName = "RANDOM",
                Text = "Nothing is known about their early life"
            });

            gme.Choices = choices.ToArray();

            GameMultiEvent next = new GameMultiEvent();

            gme.Choices[0].NextChoice = next;

            next.Image = book;
            next.Title = "The form of the Avatar";
            next.Text = "Avatar takes form\nAs a human has been born\nA perfect human";

            choices = new List<MultiEventChoice>();
            choices.Add(new MultiEventChoice()
            {
                ChoiceName = "MALE",
                Text = "The Male form was Chosen"
            });
            choices.Add(new MultiEventChoice()
            {
                ChoiceName = "FEMALE",
                Text = "The Female form was Chosen"
            }
            );

            next.Choices = choices.ToArray();

            next = new GameMultiEvent();

            foreach (var choice in choices)
            {
                choice.NextChoice = next;
            }

            next.Image = book;
            next.Title = "The Family of the Avatar";
            next.Text = "Common Family\nFew riches,little greatness\nCommon Beginnings";

            choices = new List<MultiEventChoice>();
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "MERCHANTS",
                    Text = "A family of Merchants"
                });
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "CLERICS",
                    Text = "A family of Clerics"
                });
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "EXPLORERS",
                    Text = "A family of Explorers"
                });
            next.Choices = choices.ToArray();

            next = new GameMultiEvent();

            foreach (var choice in choices)
            {
                choice.NextChoice = next;
            }

            next.Image = book;
            next.Title = "The Avatar's Nature";
            next.Text = "And Avatar grew.\nA special little human\nAnd brilliance was theirs";

            choices = new List<MultiEventChoice>();
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "INTEL",
                    Text = "As the Wisdom of Dragon's was theirs"
                });
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "AGIL",
                    Text = "As Grace and Speed was theirs"
                });
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "CHAR",
                    Text = "As a tongue of gold was theirs"
                });
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "BRAWN",
                    Text = "As the strenght of many men was theirs"
                });

            next.Choices = choices.ToArray();

            next = new GameMultiEvent();

            foreach (var choice in choices)
            {
                choice.NextChoice = next;
            }

            next.Image = book;
            next.Title = "The Avatar fights";
            next.Text = "And Avatar Grew\nIn militia was drafted\nExcelled amongst other men";

            choices = new List<MultiEventChoice>();
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "LEADER",
                    Text = "as the Leader of men"
                });
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "HEALING",
                    Text = "as their healer"
                });
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "PERSUATION",
                    Text = "as their persuader"
                });

            next.Choices = choices.ToArray();
            next = new GameMultiEvent();

            foreach (var choice in choices)
            {
                choice.NextChoice = next;
            }

            next.Image = book;
            next.Title = "And it begins";
            next.EventName = "GENERATE_CHARACTER";
            next.Text = "True god spoke to them\nAnd they left their parents' house\nWith blessing and gift";

            choices = new List<MultiEventChoice>();

            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "SWORD",
                    Text = "A sword to smite the nonbelievers"
                });
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "ARMOUR",
                    Text = "Armour to protect against the heretic"
                });
            choices.Add(new MultiEventChoice()
                {
                    ChoiceName = "MONEY",
                    Text = "Money to sway the hearts of lesser men"
                });

            next.Choices = choices.ToArray();

            //Give them the items everyone starts with
            InventoryItemManager iim = new InventoryItemManager();

            var food = iim.GetItemsWithAMaxValue("SUPPLY", 150);

            foreach (var foodItem in food)
            {
                GameState.PlayerCharacter.Inventory.Inventory.Add(InventoryCategory.SUPPLY, foodItem as InventoryItem);
                (foodItem as InventoryItem).InInventory = true;
            }
            return gme;
        }
        /// <summary>
        /// Processes the Parameters and updates the main character in the right manner
        /// </summary>
        /// <param name="mainCharacter"></param>
        /// <param name="choicesMade"></param>
        public static void ProcessParameters(List<string> choicesMade)
        {
            Actor mainCharacter = GameState.PlayerCharacter;

            foreach (var choice in choicesMade)
            {
                if (String.Equals(choice, "RANDOM", StringComparison.InvariantCultureIgnoreCase))
                {
                    ProcessParameters(GenerateRandom());
                    return; //Generate a random set instead
                }
                else if (String.Equals(choice, "GEN", StringComparison.InvariantCultureIgnoreCase))
                {
                    //do nothing
                }
                else if (String.Equals(choice, "MALE", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Gender = Gender.M;
                    mainCharacter.MapCharacter.Graphic = SpriteManager.GetSprite(LocalSpriteName.PLAYERCHAR_MALE);
                }
                else if (String.Equals(choice, "FEMALE", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Gender = Gender.F;
                    mainCharacter.MapCharacter.Graphic = SpriteManager.GetSprite(LocalSpriteName.PLAYERCHAR_FEMALE);
                }
                else if (String.Equals(choice, "MERCHANTS", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Skills.Add(SkillName.HAGGLER, new ActorSkill(SkillName.HAGGLER) { SkillLevel = 5 });
                }
                else if (String.Equals(choice, "CLERICS", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Skills.Add(SkillName.RITUALIST, new ActorSkill(SkillName.RITUALIST) { SkillLevel = 5 });
                }
                else if (String.Equals(choice, "EXPLORERS", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Skills.Add(SkillName.EXPLORER, new ActorSkill(SkillName.EXPLORER) { SkillLevel = 5 });
                }
                else if (String.Equals(choice, "INTEL", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Intel = mainCharacter.Attributes.Intel + 2;
                }
                else if (String.Equals(choice, "AGIL", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Agil = mainCharacter.Attributes.Agil + 2;
                }
                else if (String.Equals(choice, "BRAWN", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Brawn = mainCharacter.Attributes.Brawn + 2;
                }
                else if (String.Equals(choice, "CHAR", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Char = mainCharacter.Attributes.Char + 2;
                }
                else if (String.Equals(choice, "LEADER", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Skills.Add(SkillName.LEADER, new ActorSkill(SkillName.LEADER) { SkillLevel = 5 });
                }
                else if (String.Equals(choice, "HEALING", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Skills.Add(SkillName.HEALER, new ActorSkill(SkillName.HEALER) { SkillLevel = 5 });
                }
                else if (String.Equals(choice, "PERSUATION", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Skills.Add(SkillName.PERSUADER, new ActorSkill(SkillName.PERSUADER) { SkillLevel = 5 });
                }

                else if (String.Equals(choice, "SWORD", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Skills.Add(SkillName.FIGHTER, new ActorSkill(SkillName.FIGHTER) { SkillLevel = 5 });
                    mainCharacter.Attributes.Skills.Add(SkillName.DODGER, new ActorSkill(SkillName.DODGER) { SkillLevel = 5 });
                    mainCharacter.Attributes.Skills.Add(SkillName.BLOCKER, new ActorSkill(SkillName.BLOCKER) { SkillLevel = 5 });
                    mainCharacter.Attributes.Skills.Add(SkillName.SWORDFIGHTER, new ActorSkill(SkillName.SWORDFIGHTER) { SkillLevel = 5 });
                    mainCharacter.Attributes.Skills.Add(SkillName.ARMOUR_USER, new ActorSkill(SkillName.ARMOUR_USER) { SkillLevel = 5 });

                    //Give him a nice sword
                    InventoryItemManager iim = new InventoryItemManager();

                    var sword = iim.GetBestCanAfford("Sword", 500);

                    mainCharacter.Inventory.Inventory.Add(sword.Category, sword);
                    sword.InInventory = true;
                }
                else if (String.Equals(choice, "ARMOUR", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Skills.Add(SkillName.FIGHTER, new ActorSkill(SkillName.FIGHTER) { SkillLevel = 5 });
                    mainCharacter.Attributes.Skills.Add(SkillName.DODGER, new ActorSkill(SkillName.DODGER) { SkillLevel = 5 });
                    mainCharacter.Attributes.Skills.Add(SkillName.BLOCKER, new ActorSkill(SkillName.BLOCKER) { SkillLevel = 5 });
                    mainCharacter.Attributes.Skills.Add(SkillName.ARMOUR_USER, new ActorSkill(SkillName.ARMOUR_USER) { SkillLevel = 7 });

                    //Give him nice chest armour
                    InventoryItemManager iim = new InventoryItemManager();

                    var armour = iim.GetBestCanAfford("Body Armour", 500);

                    mainCharacter.Inventory.Inventory.Add(armour.Category, armour);
                    armour.InInventory = true;
                }
                else if (String.Equals(choice, "MONEY", StringComparison.InvariantCultureIgnoreCase))
                {
                    mainCharacter.Attributes.Skills.Add(SkillName.FIGHTER, new ActorSkill(SkillName.FIGHTER) { SkillLevel = 5 });
                    mainCharacter.Attributes.Skills.Add(SkillName.DODGER, new ActorSkill(SkillName.DODGER) { SkillLevel = 5 });
                    mainCharacter.Attributes.Skills.Add(SkillName.BLOCKER, new ActorSkill(SkillName.BLOCKER) { SkillLevel = 5 });
                    mainCharacter.Attributes.Skills.Add(SkillName.ARMOUR_USER, new ActorSkill(SkillName.ARMOUR_USER) { SkillLevel = 5 });

                    //Give him moneh!
                    mainCharacter.Inventory.TotalMoney += 700;
                }
                else
                {
                    throw new NotImplementedException("No code for choice " + choice);
                }
            }
        }