Exemplo n.º 1
0
        }         // end Update function

        // Attempts to pick up a resource for the character.
        public void PickupResource(Resource resource, int amount)
        {
            // Check if picking up this resource will put the character overweight.
            if ((ResourceWeight + resource.WeightValue) * amount <= MaxWeight)
            {
                // Check if there is enough room for this resource.
                if (m_resourceList.TotalSize + resource.SizeValue <= MaxInventory)
                {
                    // Add the resource.
                    m_resourceList.AddResource(resource, amount);

                    // Get the resource's position.
                    Vector3 tmp = transform.localPosition;
                    // Change the z to make tiles work.
                    tmp.z = -0.01f;
                    TileDictionary.RemoveResource(TileManager.ToPixels(tmp));
                }                 // end if size
                else
                {
                    print("Pickup failed. Max inventory capacity reached.");
                }         // end else size
            }             // end if weight
            else
            {
                print("Pickup failed. Max inventory weight reached.");
            }     // end else weight
        }         // end PickupResource function
Exemplo n.º 2
0
        }         // end TransferCurrency function

        // Transfers a resource to another character.
        public void TransferResource(GameObject other, Resource resource)
        {
            // Check if the resource object exists.
            if (resource == null)
            {
                // Simply return.
                return;
            }

            // Get the resource list script attached the other character object.
            ResourceList otherResourceScript = other.GetComponent <ResourceList>();
            // Get the character script attached the other character object.
            Character otherCharacterScript = other.GetComponent <Character>();
            // Get the resource list script attached the character this is attached to.
            ResourceList charResourceScript = this.gameObject.GetComponent <ResourceList>();

            // Check if the script objects exists.
            if (otherResourceScript == null || charResourceScript == null || otherCharacterScript == null)
            {
                print("NULL");
                // Simply return.
                return;
            }

            // Check if the other character recieving this resource will put the character overweight.
            if (otherResourceScript.TotalWeight + resource.WeightValue <= otherCharacterScript.MaxWeight)
            {
                // Check if there is enough room for this resource.
                if (otherResourceScript.TotalSize + resource.SizeValue <= otherCharacterScript.MaxInventory)
                {
                    // Add the resource to the other character.
                    otherResourceScript.AddResource(resource, 1);

                    // Remove the resource from the character this is attached to.
                    charResourceScript.RemoveResource(resource);
                }                 // end if size
                else
                {
                    print("Transfer failed. Their max inventory capacity reached.");
                }         // end else size
            }             // end if weight
            else
            {
                print("WEIGHT: " + otherResourceScript.TotalWeight);
                print("MAX WEIGHT: " + otherCharacterScript.MaxWeight);
                print("THIS MAX WEIGHT: " + this.MaxWeight);
                print("ALLY MAX WEIGHT: " + m_allyScript[0].gameObject.GetComponent <Character>().MaxWeight);
                print("Transfer failed. Their max inventory weight reached.");
            }     // end else weight
        }         // end TransferGold function