示例#1
0
        /// <summary>
        /// Registers this item in the server's database of items.Should be called during the afterAddingBaseTypes callback.
        /// </summary>
        /// <param name="items">The server's item database (a Dictionary object). Will be passed to the afterAddingBaseTypes callback method.</param>
        public void registerItem(Dictionary <string, ItemTypesServer.ItemTypeRaw> items)
        {
            if (enabled)
            {
                Pipliz.Log.Write("{0}: Attempting to register item {1}", NAMESPACE == null ? "" : NAMESPACE, this.Name);
                // add itself as a drop unless told otherwise
                if (dropsSelf)
                {
                    Drops.Add(new DropItem(this.ID));
                }
                // handle rotation
                if (this.isRotatable)
                {
                    Rotate(items);
                    Pipliz.Log.Write("{0}: Registering rotated variants of type {1}", NAMESPACE == null ? "" : NAMESPACE, this.Name);
                    this.XM.registerItem(items);
                    this.XP.registerItem(items);
                    this.ZP.registerItem(items);
                    this.ZM.registerItem(items);
                }
                // handle masking
                if (maskItem != null)
                {
                    Pipliz.Log.Write("{0}: Attempting to mask item {1} with {2}.", NAMESPACE == null ? "" : NAMESPACE, this.ID, this.Name);
                    // Masking is being used, see if there is an existing item to mask.
                    if (items.ContainsKey(this.ID))
                    {
                        // It exists, merge values.
                        ItemTypesServer.ItemTypeRaw originalItem;
                        if (items.TryGetValue(this.ID, out originalItem))
                        {
                            // Successfully retrieved item, overwrite its properties which are explicity specified in this object.
                            itemAsJSON(originalItem.description);
                            Pipliz.Log.Write("{0}: Masking complete.", NAMESPACE == null ? "" : NAMESPACE);
                        }
                        else
                        {
                            // Item exists, but we can't retrieve it.
                            Pipliz.Log.Write("{0}: Masking failed, item {1} exists but we could not retrieve it. Overwriting instead.", NAMESPACE == null ? "" : NAMESPACE, this.ID);
                            // Remove existing item.
                            UtilityFunctions.tryRemoveItem(this.ID);
                            // Add this item.
                            items.Add(this.ID, thisItemRaw);
                        }
                    }
                    else
                    {
                        // Item did not already exist, let's add it.
                        Pipliz.Log.Write("{0}: Masking was enabled, but masked item was not found. Adding {1} as a new item with ID {2}", NAMESPACE == null ? "" : NAMESPACE, this.Name, this.ID);
                        items.Add(this.ID, thisItemRaw);
                    }
                }
                else
                {
                    // masking NOT used
                    Pipliz.Log.Write("{0}: Registering block {1} to ID {2}", NAMESPACE == null ? "" : NAMESPACE, this.Name, this.ID);
                    if (items.ContainsKey(this.ID))
                    {
                        // Item already exists, do we overwrite?
                        if (overwrite)
                        {
                            Pipliz.Log.Write("{0}: Item {1} already exists, overwriting item entry.", NAMESPACE == null ? "" : NAMESPACE, this.ID);
                            // Remove existing item.
                            UtilityFunctions.tryRemoveItem(this.ID);
                            // Add this item.
                            items.Add(this.ID, thisItemRaw);
                        }
                        else
                        {
                            // Do nothing, it already exists and we're neither masking nor overwriting.
                            Pipliz.Log.Write("{0}: Item {1} already exists, registration is not necessary and is being aborted.", NAMESPACE == null ? "" : NAMESPACE, this.ID);
                        }
                    }
                    else
                    {
                        // Item does not already exist, add it.
                        items.Add(this.ID, thisItemRaw);
                    }
                }

                Pipliz.Log.Write("{0}: Block {1} registration complete.", NAMESPACE == null ? "" : NAMESPACE, this.Name);
            }
            else
            {
                Pipliz.Log.Write("{0}: Block {1} has been disabled, and will NOT be registered.", NAMESPACE == null ? "" : NAMESPACE, this.Name);
            }
        }
        /// <summary>
        /// Does all the work of adding this recipe to the server's database. Should be called in the AfterItemTypesDefined callback.
        /// </summary>
        public void addRecipeToLimitType()
        {
            if (enabled)
            {
                try
                {
                    // First remove any recipes we are replacing.
                    foreach (string deleteMe in Replaces)
                    {
                        Pipliz.Log.Write("{0}: Recipe {1} is marked as replacing {2}, attempting to comply.", NAMESPACE == null ? "" : NAMESPACE, this.Name, deleteMe);
                        UtilityFunctions.tryRemoveRecipe(deleteMe);
                    }

                    // Convert shell references into actual InventoryItem objects.
                    foreach (ItemShell I in Results)
                    {
                        if (Variables.itemsMaster == null)
                        {
                            Pipliz.Log.WriteError("{0}.SimpleRecipe.addRecipeToLimitType() has reached a critical error: 'Variables.itemsMaster' is not yet available. Recipe: {1}", NAMESPACE == null ? "" : NAMESPACE, this.Name);
                        }
                        else
                        {
                            string useKey = I.asSimpleItem == null ? I.strItemkey : I.asSimpleItem.ID;
                            if (Variables.itemsMaster.ContainsKey(useKey))
                            {
                                realResults.Add(new InventoryItem(useKey, I.intAmount));
                            }
                            else
                            {
                                Pipliz.Log.WriteError("{0}: A problem occurred adding recipe RESULT {1} to recipe {2}, the item key was not found.", NAMESPACE == null ? "" : NAMESPACE, I.strItemkey, this.Name);
                            }
                        }
                    }
                    foreach (ItemShell I in Requirements)
                    {
                        if (Variables.itemsMaster == null)
                        {
                            Pipliz.Log.WriteError("{0}.SimpleRecipe.addRecipeToLimitType() has reached a critical error: 'Variables.itemsMaster' is not yet available. Recipe: {1}", NAMESPACE == null ? "" : NAMESPACE, this.Name);
                        }
                        else
                        {
                            string useKey = I.asSimpleItem == null ? I.strItemkey : I.asSimpleItem.ID;
                            if (Variables.itemsMaster.ContainsKey(useKey))
                            {
                                realRequirements.Add(new InventoryItem(useKey, I.intAmount));
                            }
                            else
                            {
                                Pipliz.Log.WriteError("{0}: A problem occurred adding recipe REQUIREMENT {1} to recipe {2}, the item key was not found.", NAMESPACE == null ? "" : NAMESPACE, I.strItemkey, this.Name);
                            }
                        }
                    }

                    // Build actual Recipe object.
                    Recipe thisRecipe = new Recipe(this.fullName, this.realRequirements, this.realResults, this.defaultLimit, this.isOptional, this.defaultPriority);

                    // Commence registering it.
                    Pipliz.Log.Write("{0}: Attempting to register recipe {1}", NAMESPACE == null ? "" : NAMESPACE, thisRecipe.Name);
                    if (this.limitType != null)
                    {
                        if (isOptional)
                        {
                            Pipliz.Log.Write("{0}: Attempting to register optional limit type recipe {1}", NAMESPACE == null ? "" : NAMESPACE, thisRecipe.Name);
                            RecipeStorage.AddOptionalLimitTypeRecipe(limitType, thisRecipe);
                        }
                        else
                        {
                            Pipliz.Log.Write("{0}: Attempting to register default limit type recipe {1}", NAMESPACE == null ? "" : NAMESPACE, thisRecipe.Name);
                            RecipeStorage.AddDefaultLimitTypeRecipe(limitType, thisRecipe);
                        }
                    }

                    if (userCraftable)
                    {
                        Recipe playerRecipe = new Recipe("player." + this.Name, this.realRequirements, this.realResults, this.defaultLimit, this.isOptional);
                        Pipliz.Log.Write("{0}: Attempting to register default player type recipe {1}", NAMESPACE == null ? "" : NAMESPACE, playerRecipe.Name);
                        RecipePlayer.AddDefaultRecipe(playerRecipe);
                    }
                }
                catch (Exception ex)
                {
                    Pipliz.Log.WriteError("{0}: Error adding recipe: {1}", NAMESPACE == null ? "" : NAMESPACE, ex.Message);
                }
            }
            else
            {
                Pipliz.Log.Write("{0}: Recipe {1} has been disabled and will NOT be registered.", NAMESPACE == null ? "" : NAMESPACE, this.Name);
            }
        }