Esempio n. 1
0
    //Searches for the best available slot in the slot array.  (One that already has the specified item)
    public SlotScript FindBestAvailableSlot(ResourceReferenceWithStack pendingObjectToCheck)
    {
        if (slotArray != null)
        {
            for (int y = slotArray.GetLength(0) - 1; y >= 0; y--)
            {
                //Check for a stackable slot.
                for (int x = 0; x < slotArray.GetLength(1); x++)
                {
                    //Define the object in the slot.
                    ResourceReferenceWithStack objectAssigned = slotArray[y, x].GetCurrentlyAssigned();
                    //Check to make sure objectAssigned is not null.
                    if (objectAssigned != null)
                    {
                        //Check to make sure the item is the same.
                        if (objectAssigned.uiSlotContent.itemType == pendingObjectToCheck.uiSlotContent.itemType)
                        {
                            if (objectAssigned.uiSlotContent.localGroupID == pendingObjectToCheck.uiSlotContent.localGroupID)
                            {
                                //Since the slot fits all requirements, return the slot.
                                return(slotArray [y, x]);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            Debug.Log("Slot array is null and initialized status is " + initialized);
        }

        return(null);
    }
Esempio n. 2
0
 public void PickupItem(GameObject item)
 {
     if (playerInventory == null)
     {
         playerInventory = CurrentLevelVariableManagement.GetMainInventoryReference().GetComponent <InventoryFunctions> ();
     }
     //This does not check the resourcereference property of the attached script as a comparison, only the tag.  Consider changing later.
     if (item.CompareTag("ExpNodule"))
     {
         transform.parent.gameObject.GetComponent <PlayerHealthPanelManager> ().OnExperienceNodulePickedUp();
         Destroy(item);
     }
     else if (item.CompareTag("Coin"))
     {
         transform.parent.gameObject.GetComponent <PlayerHealthPanelManager> ().OnCoinPickedUp(1);
         Destroy(item);
     }
     else
     {
         ResourceReferenceWithStack pendingObject = item.GetComponent <DroppedItemProperties> ().localResourceReference;
         if (!playerInventory.AssignNewItemToBestSlot(pendingObject))
         {
             Debug.LogError("ERROR WHEN ASSIGNING OBJECT");
         }
         else
         {
             Destroy(item);
         }
     }
 }
Esempio n. 3
0
    public ResourceReferenceWithStack DeAssignItemFromMouseControl()
    {
        ResourceReferenceWithStack toReturn = itemInControlByMouse;

        itemInControlByMouse = null;
        SetCursorTexture(false);
        return(toReturn);
    }
Esempio n. 4
0
    //Assigns a new item to the best possible slot.
    public bool AssignNewItemToBestSlot(ResourceReferenceWithStack item)
    {
        //Has to be here for the return statement
        bool successfullyAssigned = false;

        //Make sure that the prerequisites are met.
        if (initialized && item != null)
        {
            SlotScript bestAvailableSlot = FindBestAvailableSlot(item);

            if (bestAvailableSlot != null)
            {
                //Set successfully assigned.
                successfullyAssigned = true;
                //Add the new stack to the current item stack.
                bestAvailableSlot.ModifyCurrentItemStack(item.stack);
                Debug.Log("Assigned " + item.uiSlotContent.itemScreenName + " to slot with items of same type.");
                //Check whether an objective has been completed
                CurrentLevelVariableManagement.GetMainObjectiveManager().OnNewItemAddedToPlayerInventory();
            }
            else
            {
                Debug.Log("Could not stack item: Attempting to add to an empty slot");
                bestAvailableSlot = FindBestAvailableNullSlot();
                if (bestAvailableSlot != null)
                {
                    successfullyAssigned = true;
                    bestAvailableSlot.AssignNewItem(item);
                    //Update the hotbar item.
                    CurrentLevelVariableManagement.GetLevelUIReference().transform.Find("Hotbar").GetComponent <HotbarManager> ().UpdateSelectedItem();
                    //Check whether an objective has been completed
                    CurrentLevelVariableManagement.GetMainObjectiveManager().OnNewItemAddedToPlayerInventory();
                }
                else
                {
                    Debug.LogError("No slots are empty!");
                }
            }
        }
        else
        {
            if (initialized == false && item == null)
            {
                Debug.LogError("Not initialized and item is null");
            }
            else if (initialized == false)
            {
                Debug.LogError("Not initialized");
            }
            else
            {
                Debug.LogError("Item is null");
            }
        }

        return(successfullyAssigned);
    }
Esempio n. 5
0
    public virtual ResourceReferenceWithStack DeAssignItem()
    {
        ResourceReferenceWithStack toReturn = currentlyAssigned;

        currentlyAssigned = null;
        childIcon.sprite  = null;
        childIcon.enabled = false;
        UpdateStackIndicator();
        return(toReturn);
    }
Esempio n. 6
0
 //Used for checking UIResourceReference classes for equality.
 public static bool CheckUIResourceReferencesForEquality(ResourceReferenceWithStack object1, ResourceReferenceWithStack object2)
 {
     if (object1.uiSlotContent.itemType == object2.uiSlotContent.itemType)
     {
         if (object1.uiSlotContent.localGroupID == object2.uiSlotContent.localGroupID)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 7
0
    public override ResourceReferenceWithStack DeAssignItem()
    {
        ResourceReferenceWithStack toReturn = currentlyAssigned;

        currentlyAssigned = null;
        childIcon.sprite  = null;
        childIcon.enabled = false;
        UpdateStackIndicator();
        //Update the selected hotbar item (when it is de-assigned completely).
        masterHotbarManager.UpdateSelectedItem();
        return(toReturn);
    }
Esempio n. 8
0
 public void AssignItemToMouseControl(ResourceReferenceWithStack assignment)
 {
     if (assignment.stack != 0)
     {
         itemInControlByMouse = assignment;
         SetCursorTexture(true);
     }
     else
     {
         Debug.LogError("Could not assign item with 0 stack!");
     }
 }
Esempio n. 9
0
 //Should be called by PurchasePanelManager.
 public void DefinePanelItem(ResourceReferenceWithStack item, int requiredCost)
 {
     if (item != null && item.stack != 0)
     {
         heldItem = item;
         //Get sprite without pivot point.
         currentItemIcon.sprite = ScriptingUtilities.GetSpriteWithoutPivotPoint(item.uiSlotContent.itemIcon);
         cost.text = requiredCost.ToString();
     }
     else
     {
         Debug.LogError("Cannot define panel item to be null or have a stack of 0!!");
     }
 }
Esempio n. 10
0
    /******************************* ASSIGNING *******************************/

    public virtual void AssignNewItem(ResourceReferenceWithStack itemToAssign)
    {
        if (itemToAssign.stack != 0)
        {
            Sprite itemWithoutPivotPoint = ScriptingUtilities.GetSpriteWithoutPivotPoint(itemToAssign.uiSlotContent.itemIcon);
            childIcon.enabled = true;
            currentlyAssigned = itemToAssign;
            childIcon.sprite  = itemWithoutPivotPoint;
            UpdateStackIndicator();
        }
        else
        {
            Debug.LogError("Could not assign item with 0 stack!");
        }
    }
Esempio n. 11
0
    public void ResetPendingCombinationSequence()
    {
        if (assigner1 != null)
        {
            assigner1.DisableCombinationPending();
        }

        if (assigner2 != null)
        {
            assigner2.DisableCombinationPending();
        }

        pendingCombinationIngredient1 = null;
        assigner1 = null;
        pendingCombinationIngredient2 = null;
        assigner2 = null;
    }
Esempio n. 12
0
    public void AddIngredient(ResourceReferenceWithStack ingredient, SlotScript assigner)
    {
        if (pendingCombinationIngredient1 == null)
        {
            pendingCombinationIngredient1 = ingredient;
            assigner1 = assigner;
            assigner1.SetCombinationPending();
            Debug.Log("Added ingredient 1: " + pendingCombinationIngredient1.uiSlotContent.itemScreenName);
        }
        else
        {
            pendingCombinationIngredient2 = ingredient;
            assigner2 = assigner;

            Debug.Log("Added ingredient 2: " + pendingCombinationIngredient2.uiSlotContent.itemScreenName);

            ManageCombination();
        }
    }
Esempio n. 13
0
    //Used to instantiate a dropped item.
    public static GameObject InstantiateDroppedItem(ResourceReferenceWithStack itemReference, Transform initialPosition, float xForce)
    {
        GameObject basicDrop = Resources.Load("Prefabs/Items/Other/BasicDrop") as GameObject;

        GameObject createdObject = (GameObject)(Instantiate(basicDrop,
                                                            initialPosition.position,
                                                            Quaternion.identity));

        //Give the object the spriterenderer.
        createdObject.transform.Find("SpriteAnimation").GetComponent <SpriteRenderer> ().sprite = itemReference.uiSlotContent.itemIcon;
        //Add the object info to the created object.
        createdObject.AddComponent <DroppedItemProperties> ();
        //Drop one of the items.
        createdObject.GetComponent <DroppedItemProperties> ().localResourceReference = new ResourceReferenceWithStack(itemReference.uiSlotContent, 1);
        //Give the rigidbody a bit of initial velocity.
        createdObject.GetComponent <Rigidbody2D> ().AddForce(new Vector2(xForce, 0));
        createdObject.transform.position = initialPosition.position + new Vector3(Mathf.Sign(xForce), 0, 0);
        //Initialize the droppd item.
        createdObject.GetComponent <DroppedItemProperties> ().Initialize();

        return(createdObject);
    }
Esempio n. 14
0
    //Used to determine whether the player has a required item.
    public SlotScript CheckForCertainInventoryItem(ResourceReferenceWithStack pendingObjectToCheck)
    {
        if (slotArray != null)
        {
            for (int y = slotArray.GetLength(0) - 1; y >= 0; y--)
            {
                //Check for a stackable slot.
                for (int x = 0; x < slotArray.GetLength(1); x++)
                {
                    //Define the item that is in the specified slot.
                    ResourceReferenceWithStack objectAssigned = slotArray[y, x].GetCurrentlyAssigned();
                    //Check whether the assigned object is null.
                    if (objectAssigned != null)
                    {
                        //Check to make sure the item types are the same.
                        if (objectAssigned.uiSlotContent.itemType == pendingObjectToCheck.uiSlotContent.itemType)
                        {
                            //Check to see that the IDs are the same.
                            if (objectAssigned.uiSlotContent.localGroupID == pendingObjectToCheck.uiSlotContent.localGroupID)
                            {
                                //Check to see that the stacks are greater or equal to one another.
                                if (objectAssigned.stack >= pendingObjectToCheck.stack)
                                {
                                    //Since the slot fits all requirements, return the slot.
                                    return(slotArray [y, x]);
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        {
            Debug.Log("Slot array is null");
        }

        return(null);
    }
Esempio n. 15
0
    //Called from the public AddIngredient function.
    void ManageCombination()
    {
        // Check the createdIngredientArray to see whether the ResourceReference components match.
        ResourceReference[] createdIngredientResourceReferenceArray =
        {
            pendingCombinationIngredient1.uiSlotContent,
            pendingCombinationIngredient2.uiSlotContent
        };

        //For every combination in the database.
        for (int i = 0; i < ResourceDatabase.masterItemCombinationList.Count; i++)
        {
            //Convert the two database ingredients in use into an array.
            ResourceReference[] combinationDatabaseItemRequirements =
            {
                ResourceDatabase.masterItemCombinationList[i].ingredients[0].uiSlotContent,
                ResourceDatabase.masterItemCombinationList[i].ingredients[1].uiSlotContent
            };

            //Check whether the local and database arrays are equal.
            if (ScriptingUtilities.CheckArraysForEquality(createdIngredientResourceReferenceArray, combinationDatabaseItemRequirements))
            {
                //Create an integer array that defines the stack of each local item.
                int[] createdIngredientStackArray =
                {
                    pendingCombinationIngredient1.stack,
                    pendingCombinationIngredient2.stack
                };
                //Create an integer array that defines the stack of each database ingredient.
                int[] combinationDatabaseStackRequirements =
                {
                    ResourceDatabase.masterItemCombinationList[i].ingredients[0].stack,
                    ResourceDatabase.masterItemCombinationList[i].ingredients[1].stack
                };

                //Determine whether the stacks satisfy the minimum requirement.
                if (
                    createdIngredientStackArray[0] >= combinationDatabaseStackRequirements[0] && createdIngredientStackArray[1] >= combinationDatabaseStackRequirements[1]
                    )
                {
                    int maxPossibleItemStack = DetermineMaxPossibleStackOfItem(combinationDatabaseStackRequirements, createdIngredientStackArray);
                    if (maxPossibleItemStack != 0)
                    {
                        assigner1.ModifyCurrentItemStack(-1 * maxPossibleItemStack * combinationDatabaseStackRequirements[0]);
                        Debug.Log("Deducted " + maxPossibleItemStack * combinationDatabaseStackRequirements[0] + " from assigner 1.");
                        assigner2.ModifyCurrentItemStack(-1 * maxPossibleItemStack * combinationDatabaseStackRequirements[1]);
                        Debug.Log("Deducted " + maxPossibleItemStack * combinationDatabaseStackRequirements[1] + " from assigner 2, stack is now.");

                        ResourceReferenceWithStack finalProduct = new ResourceReferenceWithStack(ResourceDatabase.masterItemCombinationList[i].product.uiSlotContent, ResourceDatabase.masterItemCombinationList[i].product.stack * maxPossibleItemStack);
                        AssignItemToMouseControl(finalProduct);
                        ResetPendingCombinationSequence();
                    }
                    else
                    {
                        Debug.Log("Max possible item stack was 0");
                    }
                    return;
                }
                else
                {
                    Debug.LogError("Stack did not satisfy the minimum number required.");
                    return;
                }
            }

            if (i == ResourceDatabase.masterItemCombinationList.Count - 1)
            {
                Debug.LogError("Combination ingredients not found");
                ResetPendingCombinationSequence();
            }
        }
    }
Esempio n. 16
0
    public static void InitializeDatabase()
    {
        /******************************************* ITEMS *******************************************/
        //Tools
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.GameTool, "Wooden Sword", "A weak sword, but useful for survival.", 0, "Weapons/Wooden/WoodenSword/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.GameTool, "Wooden Hatchet", "A weak axe made for strong choppers.", 1, "Weapons/Wooden/WoodenHatchet/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.GameTool, "Wooden Pickaxe", "A weak axe to gather ore and rock.", 2, "Weapons/Wooden/WoodenPickaxe/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.GameTool, "Wooden Bow", "A weak bow, useful for long range attacks.", 3, "Weapons/Wooden/WoodenBow/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.GameTool, "Diamond Sword", "A strong monster-chopping sword.", 4, "Weapons/Diamond/DiamondSword/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.GameTool, "Spear", "A tough caveman implement", 5, "Weapons/Other/Spear/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.GameTool, "Mace", "A weapon that strikes fear into the hearts of all", 6, "Weapons/Other/Mace/"));

        //Crafting materials
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.CraftingMaterial, "Wood", "A vital material for any player", 0, "Items/Wood/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.CraftingMaterial, "Wood Plank", "A vital wood refinement", 1, "Items/Wood/"));

        //Ores
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Ore, "Coal", "Useful for crafting arrow tips", 0, "Items/Ores/Coal/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Ore, "Diamond", "A tough material useful in epic battles", 1, "Items/Ores/Diamond/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Ore, "Emerald", "A pretty green gem", 2, "Items/Ores/Emerald/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Ore, "Gold", "A weak but easily enchantable item.", 3, "Items/Ores/Gold/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Ore, "Ruby", "A nice red gem", 4, "Items/Ores/Ruby/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Ore, "Silver", "A good material for strong weapons", 5, "Items/Ores/Silver/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Ore, "Iron", "A dull yet tough metal.", 6, "Items/Ores/Iron/"));

        //Food
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Food, "Apple", "A yummy snack.", 0, "Items/Food/Apple/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Food, "Sprout", "The start of a new beginning", 1, "Items/Food/Sprout/"));

        //Ship Parts
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.ShipPart, "Subsidiary Reactor Core", "A required part of the time machine", 0, "Items/ShipParts/"));

        //Other
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Other, "ExpNodule", "", 0, "Items/Other/ExpNodule/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Other, "Fire", "A life changing implement of cavemen", 1, "Items/Other/Fire/"));
        masterItemList.Add(new ResourceReference(ResourceReference.ItemType.Other, "Coin", "", 2, "Items/Other/Coin/"));

        /******************************************* RACES *******************************************/
        //Gatherer
        ResourceReferenceWithStack[] maceFighterInitialItems = new ResourceReferenceWithStack[] {
            new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Mace"), 1)
        };
        gameProfessions.Add(new Profession("Professions/Mace Fighter/", "Mace Fighter", 0, maceFighterInitialItems));

        //Hunter
        ResourceReferenceWithStack[] spearFighterInitialItems = new ResourceReferenceWithStack[] {
            new ResourceReferenceWithStack(GetItemByParameter("Spear"), 1)
        };
        gameProfessions.Add(new Profession("Professions/Spear Fighter/", "Spear Fighter", 1, spearFighterInitialItems));

        /******************************************* COMBINATIONS *******************************************/
        //Wooden Sword
        masterItemCombinationList.Add(new ItemCombination(new ResourceReferenceWithStack[] {
            new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Wood"), 1),
            new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Wood"), 1)
        },
                                                          new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Wood Plank"), 1)));

        //Diamond Sword
        masterItemCombinationList.Add(new ItemCombination(new ResourceReferenceWithStack[] {
            new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Wood Plank"), 3),
            new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Diamond"), 2)
        },
                                                          new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Diamond Sword"), 1)));

        //Fire
        masterItemCombinationList.Add(new ItemCombination(new ResourceReferenceWithStack[] {
            new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Wood"), 5),
            new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Coal"), 2)
        },
                                                          new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Fire"), 1)));
    }
Esempio n. 17
0
 public ResourceReferenceWithStackAndPrice(ResourceReferenceWithStack ctorMainContentReference, int ctorPrice)
 {
     mainContentReference = ctorMainContentReference;
     price = ctorPrice;
 }
Esempio n. 18
0
 public ItemCombination(ResourceReferenceWithStack[] ctorIngredients, ResourceReferenceWithStack ctorProduct)
 {
     ingredients = ctorIngredients;
     product     = ctorProduct;
 }