Exemplo n.º 1
0
        public MapItem CreateItem(int itemID,string name,string description, string graphic, int value  
            ,bool equippable,int armourRating, int damageRating, string damageType,string category,string equippableLocation,
            int woundPotential, int stunAmount,bool stackable,int effect, int effectPower,bool isRanged)
        {
            InventoryItem item = null;

            if (effect == -1)
            {
                item = new InventoryItem();
            }
            else
            {
                item = new ConsumableItem();
            }

            item.Description = description;

            string chosenGraphic = String.Empty;

            //Does graphic contain multiple choices?
            if (graphic.Contains(","))
            {
                //yes, lets split it
                var graphics = graphic.Split(',');

                //use random to determine which one we want
                chosenGraphic = graphics[GameState.Random.Next(graphics.Length)];

                item.Graphic = SpriteManager.GetSprite((LocalSpriteName)Enum.Parse(typeof(LocalSpriteName), chosenGraphic));
            }
            else
            {
                //nope
                item.Graphic = SpriteManager.GetSprite((LocalSpriteName)Enum.Parse(typeof(LocalSpriteName), graphic));
            }

            item.InInventory = false;
            item.InternalName = name;
            item.IsEquippable = equippable;
            item.IsEquipped = false;
            item.MayContainItems = true;
            item.Name = name;
            item.Category = (InventoryCategory) Enum.Parse(typeof(InventoryCategory), category);
            item.BaseValue = value;
            item.ArmourRating = armourRating;
            item.DamageDice = damageRating;
            item.StunAmount = stunAmount;
            item.WoundPotential = woundPotential;
            item.WeaponType = damageType;
            item.Stackable = stackable;
            item.TotalAmount = 1;
            item.IsRanged = isRanged;

            if (effect != -1)
            {
                (item as ConsumableItem).Effects = (ConsumableEffect) effect;
                (item as ConsumableItem).EffectPower = effectPower;
            }

            if (!String.IsNullOrEmpty(equippableLocation))
            {
                item.EquippableLocation = (EquipmentLocation)Enum.Parse(typeof(EquipmentLocation), equippableLocation);
            }

            return item;
        }
        public bool HandleClick(int x, int y, Objects.Enums.MouseActionEnum mouseAction, out DRObjects.Enums.ActionType? actionType, out DRObjects.Enums.InternalActionEnum? internalActionType, out object[] args, out MapItem itm, out DRObjects.MapCoordinate coord, out bool destroy)
        {
            actionType = null;
            internalActionType = null;
            args = null;
            coord = null;
            destroy = false;
            itm = null;

            //Clicked on a context menu item?
            foreach (var contextMenu in contextMenuChoices)
            {
                if (contextMenu.Rect.Contains(x, y))
                {
                    //Yes. Perform the action
                    //this.selectedItem.PerformAction(contextMenu.Action, this.CurrentActor, contextMenu.Args);
                    actionType = contextMenu.Action;
                    args = contextMenu.Args;
                    itm = selectedItem;
                }
            }

            //remove the contextual menu
            this.contextMenu = new Rectangle(0, 0, 0, 0);
            contextMenuChoices = new List<ContextMenuItem>();
            selectedItem = null;

            for (int i=0; i < categories.Count; i++)
            {
                if (categories[i].Contains(x, y))
                {
                    //Change category!
                    this.ChosenCategory = i;

                    //remove the contextual menu
                    contextMenu = new Rectangle(0, 0, 0, 0);
                    contextMenuChoices = new List<ContextMenuItem>();
                    selectedItem = null;

                    //Handled. Naught else
                    return true;
                }
            }

            //Have we clicked on an item ?
            List<InventoryItemRectangle> allItemBoxes = new List<InventoryItemRectangle>();
            allItemBoxes.AddRange(row1Items);
            allItemBoxes.AddRange(row2Items);
            allItemBoxes.AddRange(row3Items);

            foreach (InventoryItemRectangle rect in allItemBoxes)
            {
                if (rect.Rect.Contains(x, y))
                {
                    //remove the contextual menu
                    contextMenu = new Rectangle(0, 0, 0, 0);
                    contextMenuChoices = new List<ContextMenuItem>();
                    selectedItem = null;

                    //Does it contain an item?
                    if (rect.Item != null)
                    {
                        //Yes - open contextual menu
                        contextMenu = new Rectangle(x+15, y+15, 0, 0);
                        selectedItem = rect.Item;

                        foreach (var action in rect.Item.GetPossibleActions(this.CurrentActor))
                        {
                            AddContextMenuItem(action, new object[0] { }, content);
                        }

                        //done
                        return true;
                    }
                    else
                    {
                        return true; //Empty box
                    }

                }
            }

            //Have we clicked on an equipped item?
            foreach (EquippedItemRectangle rect in equipmentRectangles)
            {
                if (rect.Rect.Contains(x, y))
                {
                    //remove the contextual menu
                    contextMenu = new Rectangle(0, 0, 0, 0);
                    contextMenuChoices = new List<ContextMenuItem>();
                    selectedItem = null;

                    //Does it contain an item?
                    if (rect.InventoryItem != null)
                    {
                        //Yes - open contextual menu
                        contextMenu = new Rectangle(x + 15, y + 15, 0, 0);
                        selectedItem = rect.InventoryItem;

                        foreach (var action in rect.InventoryItem.GetPossibleActions(this.CurrentActor))
                        {
                            AddContextMenuItem(action, new object[0] { }, content);
                        }

                        //done
                        return true;
                    }
                    else
                    {
                        return true; //Empty box
                    }
                }
            }

            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates an animal actor, together with it's Map Character from it's parameters
        /// </summary>
        /// <returns></returns>
        public static Actor GenerateAnimal(AnimalData data)
        {
            //Load the race data
            data.RaceData = ActorGeneration.ReadRaceData(data.RaceID);

            Actor actor = new Actor();

            actor.Anatomy = ActorGeneration.GenerateAnatomy("human");
            actor.Attributes = new SkillsAndAttributes();
            actor.Attributes.Actor = actor;
            ActorGeneration.GenerateAttributes(data.RaceData.RaceName,ActorProfession.WARRIOR,GameState.Random.Next(data.MinLevel,data.MaxLevel),actor);

            actor.Attributes.Health = actor.Anatomy;
            actor.Attributes.HandToHand = GameState.Random.Next(data.MinLevel, data.MaxLevel);
            actor.Attributes.Evasion = GameState.Random.Next(data.MinLevel, data.MaxLevel);

            actor.EnemyData = new EnemyData();
            actor.EnemyData.EnemyLineOfSight = data.LineOfSight;
            actor.EnemyData.Intelligent = false;
            actor.EnemyData.Profession = ActorProfession.WARRIOR;
            actor.EnemyData.EnemyName = data.Name;

            actor.Gender = Gender.U;
            actor.Inventory = new ActorInventory();

            //Meat.
            if (data.MeatAmount > 0)
            {
                //Create some meat
                ConsumableItem meat = new ConsumableItem();
                meat.ArmourRating = 0;
                meat.BaseValue = 50;
                meat.Category = InventoryCategory.SUPPLY;
                meat.Description = "The meat of a " + data.Name;
                meat.EffectPower = 1;
                meat.Effects = ConsumableEffect.FEED;
                meat.Graphic = SpriteManager.GetSprite(LocalSpriteName.STEAK);
                meat.InternalName = "meat";
                meat.IsEquippable = false;
                meat.InInventory = true;
                meat.IsEquipped = false;
                meat.MayContainItems = true;
                meat.Name = data.Name + " meat";
                meat.Stackable = true;
                meat.TotalAmount = data.MeatAmount;

                actor.Inventory.Inventory.Add(meat.Category, meat);
            }

            //Hide
            if (data.HideAmount > 0)
            {
                //Create a hide
                InventoryItem hide = new InventoryItem();
                hide.ArmourRating = 0;
                hide.BaseValue = data.HideValue;
                hide.Category = InventoryCategory.LOOT;
                hide.Description = "The hide of a " + data.Name;
                hide.Graphic = SpriteManager.GetSprite(LocalSpriteName.HIDE);
                hide.InInventory = true;
                hide.InternalName = "hide";
                hide.IsEquippable = false;
                hide.IsEquipped = false;
                hide.MayContainItems = true;
                hide.Name = data.Name + " hide";
                hide.Stackable = true;
                hide.TotalAmount = data.HideAmount;

                actor.Inventory.Inventory.Add(hide.Category, hide);
            }

            actor.IsAggressive = data.IsAggressive;
            actor.IsAlive = true;
            actor.IsAnimal = true;
            actor.IsDomesticatedAnimal = data.Domesticated;
            actor.IsPlayerCharacter = false;
            actor.IsStunned = false;
            actor.Name = data.Name;
            actor.UnarmedDamageDice = data.DamageDice;
            actor.UniqueId = Guid.NewGuid();

            LocalCharacter lc = new LocalCharacter();
            lc.Actor = actor;
            lc.Description = data.Name;

            //Pick a graphic
            string graphic = data.GraphicsList[GameState.Random.Next(data.GraphicsList.Length)];

            lc.Graphic = (SpriteManager.GetSprite((LocalSpriteName) Enum.Parse(typeof(LocalSpriteName),graphic)));

            lc.InternalName = data.Name;
            lc.IsStunned = false;
            lc.LineOfSightRange = data.LineOfSight;
            lc.MayContainItems = false;
            lc.Name = data.Name;

            actor.MapCharacter = lc;

            return actor;
        }