GetBestCanAfford() public method

Returns the most expensive item of that particular tag which still costs less or equal to the maximum
public GetBestCanAfford ( string tag, int maximum ) : InventoryItem
tag string
maximum int
return DRObjects.Items.Archetypes.Local.InventoryItem
示例#1
0
        /// <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;
        }
示例#2
0
        /// <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);
            }
        }
        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>
        /// 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();
        }
        /// <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);
                }
            }
        }