コード例 #1
0
        /// <summary>
        /// Creates the item from its recipe
        /// </summary>
        /// <param name="recipeIndex"></param>
        /// <returns></returns>
        public IToolImpact Craft(int recipeIndex)
        {
            var impact = new ToolImpact();

            try
            {
                var recipe = EntityFactory.Config.Recipes[recipeIndex];

                IContainerEntity container;
                if (recipe.ContainerBlueprintId == 0)
                {
                    container = this;
                }
                else
                {
                    container = (Container)EntityState.PickedEntityLink.ResolveStatic(EntityFactory.LandscapeManager);

                    if (container == null)
                    {
                        return(impact);
                    }
                }

                // check if we have all ingredients
                foreach (var ingredient in recipe.Ingredients)
                {
                    var count = container.Slots().Where(s => s.Item.BluePrintId == ingredient.BlueprintId).Sum(s => s.ItemsCount);
                    if (count < ingredient.Count)
                    {
                        impact.Message = "Not enough ingerdients";
                        return(impact);
                    }
                }

                foreach (var ingredient in recipe.Ingredients)
                {
                    if (!container.TakeItems(ingredient.BlueprintId, ingredient.Count))
                    {
                        impact.Message = "Can't take items from the inventory";
                        return(impact);
                    }
                }

                var item = (Item)EntityFactory.CreateFromBluePrint(recipe.ResultBlueprintId);

                if (!container.PutItems(item, recipe.ResultCount))
                {
                    impact.Message = "Can't put item to the inventory";
                    return(impact);
                }

                impact.Success = true;
                return(impact);
            }
            catch (Exception x)
            {
                impact.Message = x.Message;
                return(impact);
            }
        }
コード例 #2
0
ファイル: SoulStone.cs プロジェクト: ErtyHackward/utopia
        /// <summary>
        /// Executes put operation
        /// Removes one item from the inventory and puts it into
        /// the world
        /// </summary>
        /// <param name="owner">entity that runs the operation</param>
        /// <returns></returns>
        public override IToolImpact Put(IDynamicEntity owner, Item worldDroppedItem = null)
        {
            //Is the player already binded to a soulstone ?
            var charEntity = owner as CharacterEntity;

            if (charEntity.BindedSoulStone != null)
            {
                IToolImpact impact = new ToolImpact();
                impact.Message = "You are already binded to a soulstone.";
                impact.Success = false;
                return(impact);
            }

            if (worldDroppedItem == null)
            {
                SoulStone clonedNewSoulstone = (SoulStone)this.Clone();
                clonedNewSoulstone.DynamicEntityOwnerID = charEntity.DynamicId;
                worldDroppedItem = clonedNewSoulstone as Item;
            }

            var putResult = base.Put(owner, worldDroppedItem);

            if (putResult.Success && worldDroppedItem != null)
            {
                //The soulStone has been placed into the world !
                //Bind this entity with the player.
                charEntity.BindedSoulStone = worldDroppedItem as SoulStone;
                DynamicEntityOwnerID       = charEntity.DynamicId;
            }

            return(putResult);
        }