Exemplo n.º 1
0
        /// <summary>
        /// Equips/Swaps the equipment.  This will check the types of equipment to send that Item and its stat to the player.
        /// </summary>
        public void UseEquipment(Item usedItem)
        {
            // Get the Character_Manager component.
            Character_Manager character = Character_Helper.GetPlayerManager().GetComponent <Character_Manager> ();

            // Get the Equipment component.
            Equipment equipment = character.GetComponentInChildren <Equipment> ();
            // Create a temp variable for our item that is swapped out by whatever we are currently equipping.
            Item swappedItem = null;

            // IF we have a weapon item,
            // ELSE IF we have a armour item,
            // ELSE IF we have a ring item,
            // ELSE IF we have a bracelet item,
            // ELSE we dont have an item to equip and we made an error somewhere as we should of not been in here.  One of the IF statements SHOULD work.
            if (usedItem.Type == "Weapon")
            {
                // Set the new weapon to the player while returning the old weapon (if the player wielded one).
                swappedItem = equipment.EquipWeapon(usedItem);
            }
            else if (usedItem.Type == "Armour")
            {
                // Set the new Armour to the player while returning the old Armour (if the player wearing one).
                swappedItem = equipment.EquipArmour(usedItem);
            }
            else if (usedItem.Type == "Ring")
            {
                // Set the new Ring to the player while returning the old Ring (if the player wearing one).
                swappedItem = equipment.EquipRing(usedItem);
            }
            else if (usedItem.Type == "Bracelet")
            {
                // Set the new Bracelet to the player while returning the old Bracelet (if the player wearing one).
                swappedItem = equipment.EquipBracelet(usedItem);
            }
            else
            {
                // Nothing we can equip so lets leave.
                Debug.Log("We entered the UseEquipment method but didnt equip anything.  Something isnt right with the labeling of the Types.");
                return;
            }

            // Loop the amount of times we have inventory spaces.
            for (int i = 0; i < defaultSlotAmount + extraInventorySlots; i++)
            {
                // IF the IDs match.
                if (items [i].ID == usedItem.ID)
                {
                    // IF we have an item being swapped out.
                    if (swappedItem != null)
                    {
                        // Add the swapped out equipped item to the inventory.
                        AddItem(swappedItem.ID, 1);
                    }
                    // Play the Pickup Sound.
                    Grid_Helper.soundManager.PlaySound(usedItem.UsedSound);
                    // Do not show the tooltip.
                    Grid_Helper.tooltip.DeactivateItemTooltip();
                    // Clear the inventory slot.
                    ClearSlotInInventory(i, slots [i].GetComponentInChildren <Item_Data> ().gameObject);
                    // Since we found a match lets get out of this loop.
                    break;
                }
            }
        }
Exemplo n.º 2
0
 public void OnEndDrag(PointerEventData data)
 {
     if (data.button == PointerEventData.InputButton.Left)
     {
         // IF we are not hovering the mouse over the inventory then drop the item on the ground.
         if (data.hovered.Count == 0)
         {
             // Spawn the item from it being thrown out of the inventory.
             Vector3 charPosition     = Character_Manager.GetPlayer().transform.position;
             Vector3 clickPosition    = new Vector3(data.position.x, data.position.y);
             Camera  camera           = Camera.main;
             Vector3 clickMapPosition = camera.ScreenToWorldPoint(clickPosition);
             print("Character position: " + charPosition.ToString());
             print("Mouse position: " + clickMapPosition.ToString());
             float xDiff = clickMapPosition.x - charPosition.x;
             float yDiff = clickMapPosition.y - charPosition.y;
             if (System.Math.Abs(xDiff) >= System.Math.Abs(yDiff))
             {
                 if (xDiff >= 0)
                 {
                     Grid.helper.SpawnObjectNextToPlayer(Grid.setup.GetGameObjectPrefab(item.Title), Character_Manager.GetPlayer().transform.position, Quaternion.identity, Character_Manager.GetPlayer(), RADIUS, true);
                 }
                 else
                 {
                     Grid.helper.SpawnObjectNextToPlayer(Grid.setup.GetGameObjectPrefab(item.Title), Character_Manager.GetPlayer().transform.position, Quaternion.identity, Character_Manager.GetPlayer(), -1 * RADIUS, true);
                 }
             }
             else
             {
                 if (yDiff >= 0)
                 {
                     Grid.helper.SpawnObjectNextToPlayer(Grid.setup.GetGameObjectPrefab(item.Title), Character_Manager.GetPlayer().transform.position, Quaternion.identity, Character_Manager.GetPlayer(), RADIUS, false);
                 }
                 else
                 {
                     Grid.helper.SpawnObjectNextToPlayer(Grid.setup.GetGameObjectPrefab(item.Title), Character_Manager.GetPlayer().transform.position, Quaternion.identity, Character_Manager.GetPlayer(), -1 * RADIUS, false);
                 }
             }
             // GameObject goItem = Grid.helper.SpawnObjectToLeftOfPlayer (Grid.setup.GetGameObjectPrefab (item.Title), Character_Manager.GetPlayer ().transform.position, Quaternion.identity, Character_Manager.GetPlayer (), RADIUS);
             // Launch the item in a random direction.
             // Grid.helper.LaunchItemAwayFromPosition (goItem, Character_Manager.GetPlayer ().transform.position);
             // Clear the old slot.
             GetComponentInParent <Inventory>().items [slotNumber] = new Item();
             // Destroy this gameobject.
             Destroy(this.gameObject);
             // We done so lets GTFO of here.
             return;
         }
         // IF we actually are dragging an item.
         if (item != null)
         {
             // Set this items parent back to the original slot.
             this.transform.SetParent(GetComponentInParent <Inventory>().slots [slotNumber].transform);
             // Set its local position back to 0 so it can be centered in the slot.
             this.transform.localPosition = Vector2.zero;
             // Make sure the scale is set properly to 1.
             this.transform.localScale = Vector2.one;
             // Allow us to block raycast again.
             canvasGroup.blocksRaycasts = true;
         }
     }
 }
Exemplo n.º 3
0
        public void OnPointerUp(PointerEventData data)
        {
            // IF we Right Click so we can USE or EQUIP an item.
            if (item != null && data.button == PointerEventData.InputButton.Right && !data.dragging)
            {
                // Get the Player_Manager component.
                Player_Manager player = Character_Manager.GetPlayerManager().GetComponent <Player_Manager> ();
                // IF this item is a consumable,
                if (item.Type == "Consumable")
                {
                    // Add "usage" attributes associated with this item.  At this current time if you are looking at the demo we only add HP.
                    player.AddHealth((float)item.RestoreHP);
                    // Play the Pickup Sound.
                    Grid.soundManager.PlaySound(item.UsedSound);
                    if (amount - 1 == 0)
                    {
                        // Clear the old slot.
                        GetComponentInParent <Inventory>().items [slotNumber] = new Item();
                        // Destroy this gameobject as it holds no item.
                        Destroy(gameObject);
                        // Do not show the tooltip.
                        Grid.tooltip.Deactivate();
                        return;
                    }
                    --amount;
                    GetComponentInParent <Inventory>().slots [slotNumber].GetComponentInChildren <Text> ().text = amount.ToString();
                    return;
                }
                // IF this item is a piece of equipment, such as a Weapon, Armour, Ring or a Bracelet.
                if (item.Type == "Weapon" || item.Type == "Armour" || item.Type == "Ring" || item.Type == "Bracelet")
                {
                    // Get the Equipment component.
                    Equipment equipment = player.GetComponentInChildren <Equipment> ();
                    // Play the Pickup Sound.
                    Grid.soundManager.PlaySound(item.UsedSound);
                    Item swappedItem = null;
                    if (item.Type == "Weapon")
                    {
                        // Set the new weapon to the player while returning the old weapon (if the player wielded one).
                        swappedItem = equipment.EquipWeapon(item);
                    }
                    else if (item.Type == "Armour")
                    {
                        // Set the new Armour to the player while returning the old Armour (if the player wearing one).
                        swappedItem = equipment.EquipArmour(item);
                    }
                    else if (item.Type == "Ring")
                    {
                        // Set the new Ring to the player while returning the old Ring (if the player wearing one).
                        swappedItem = equipment.EquipRing(item);
                    }
                    else if (item.Type == "Bracelet")
                    {
                        // Set the new Bracelet to the player while returning the old Bracelet (if the player wearing one).
                        swappedItem = equipment.EquipBracelet(item);
                    }

                    // Remove this item from this List of Items.
                    GetComponentInParent <Inventory>().items [slotNumber] = new Item();
                    // IF we have an item being swapped out.
                    if (swappedItem != null)
                    {
                        // Add the swapped out equipped item to the inventory.
                        GetComponentInParent <Inventory>().AddItem(swappedItem.ID, 1);
                    }
                    // Do not show the tooltip.
                    Grid.tooltip.Deactivate();
                    // Destroy this item in the inventory list.
                    Destroy(gameObject);
                }
            }
        }
Exemplo n.º 4
0
 void OnEnable()
 {
     // Add this to our List.
     Character_Manager.Register(this);
 }
Exemplo n.º 5
0
 void OnDisable()
 {
     // Remove from our List.
     Character_Manager.Unregister(this);
 }
Exemplo n.º 6
0
 void Awake()
 {
     characterManager = GetComponentInParent <Character_Manager> ();
     Load();
 }
Exemplo n.º 7
0
 public void OnEndDrag(PointerEventData data)
 {
     if (data.button == PointerEventData.InputButton.Left)
     {
         // IF we are not hovering the mouse over the inventory then drop the item on the ground.
         if (data.hovered.Count == 0)
         {
             // Spawn the item from it being thrown out of the inventory.
             GameObject goItem = Grid.helper.SpawnObject(Grid.setup.GetGameObjectPrefab(item.Title), Character_Manager.GetPlayer().transform.position, Quaternion.identity, Character_Manager.GetPlayer(), RADIUS);
             // Launch the item in a random direction.
             Grid.helper.LaunchItemAwayFromPosition(goItem, Character_Manager.GetPlayer().transform.position);
             // Clear the old slot.
             GetComponentInParent <Inventory>().items [slotNumber] = new Item();
             // Destroy this gameobject.
             Destroy(this.gameObject);
             // We done so lets GTFO of here.
             return;
         }
         // IF we actually are dragging an item.
         if (item != null)
         {
             // Set this items parent back to the original slot.
             this.transform.SetParent(GetComponentInParent <Inventory>().slots [slotNumber].transform);
             // Set its local position back to 0 so it can be centered in the slot.
             this.transform.localPosition = Vector2.zero;
             // Make sure the scale is set properly to 1.
             this.transform.localScale = Vector2.one;
             // Allow us to block raycast again.
             canvasGroup.blocksRaycasts = true;
         }
     }
 }
Exemplo n.º 8
0
 // Use this for initialization
 void Start()
 {
     playerRenderer = Character_Manager.GetPlayer().GetComponent <SpriteRenderer>();
     objectRenderer = GetComponent <SpriteRenderer>();
 }
Exemplo n.º 9
0
 void Start()
 {
     //Fetch the Input Field component from the GameObject
     inputField       = GetComponent <InputField>();
     characterManager = Character_Helper.GetPlayerManager().GetComponent <Character_Manager>();
 }
Exemplo n.º 10
0
        void OnTriggerEnter2D(Collider2D coll)
        {
            // Whatever is colliding with us, let us check for the player.
            // IF the colliding GameObject has a Character Manager.
            if (coll.GetComponentInParent <Character_Manager> () == null)
            {
                // We leave as the only thing that can destroy environmental things will be the player.
                return;
            }
            // IF our Character is a Hero/Player.
            if (coll.GetComponentInParent <Character_Manager> ().characterType != CharacterType.Hero)
            {
                // We leave as the only things we want to destroy the environment is the player.
            }
            // A Character exists so lets get the main parent incase we need to traverse downward to find other scripts/components.
            Character_Manager characterManager = coll.GetComponentInParent <Character_Manager> ();
            // So now that we have a Player_Manager lets scope down the children and find the Equipment script.
            Equipment equipment = characterManager.GetComponentInChildren <Equipment> ();
            // Lets get the current weapon's subType we are wielding.
            string subType = equipment.GetWeapon().SubType;

            // Loop the amount of times we have subTypes.
            for (int k = 0; k < subTypesThatDestroy.Length; k++)
            {
                // IF we have a matching subTypeThatDestroy and subType.
                if (subTypesThatDestroy [k] == subType)
                {
                    // Reduce the numberOfHits (really this is just a simulation of HP in a nutshell but not really health per say).
                    // IF you didnt want to do just flat amount of hits you can always set up a higher variable for numberOfHits and apply the damage the player has in their Character_Stats to apply damage here.
                    // Normally though these type of destroyables are # of flat hits then they go bye bye.  You can also do flat amounts and base the damage done to these destroyables based on the "Rarity" or "Damage" of the item,
                    // so like :
                    // int rarity = GetIntBasedOnRarity(equipment.GetWeapon().Rarity) // There isnt a method GetIntBasedOnRarity() but you get the idea that Common = 1, Rare = 2, Epic = 3, etc.
                    // numberOfHits -= rarity;
                    // or
                    // numberOfHits -= equipment.GetWeapon().Damage;  // Remember we labeled the SubType so if you wanted to set damage to this item and not have it effect other types we can.

                    // Reduce the number of hits.
                    numberOfHits -= 1;
                    // IF numberOfHits is less than or equal to zero.
                    // ELSE we still have numberOfHits left.
                    if (numberOfHits <= 0)
                    {
                        // Loop the amount of times we have locations to spawn our destroy effects.
                        for (int i = 0; i < afterDestroyEffectLocations.Length; i++)
                        {
                            // Create our Destroy Effect at one of our locations specified.
                            Instantiate(afterDestroyEffects, afterDestroyEffectLocations [i].transform.position, Quaternion.identity);
                        }
                        // Check and see if there is a State_Handler script.
                        Grid_Helper.helper.CheckState(isPlaced, gameObject);
                    }
                    else
                    {
                        // We are not getting destroyed but since we are taking "damage" we need to display to the player that something is happening to this GameObject.
                        // If not the player can swing a sword/shovel/axe on a bush/dirt hole/tree and with no indicator that player will probably not try it again which can result in bad experience for the player.
                        // Now, there are MANY ways to handle this, you can run a coroutine and alter the colors to show contact that something is happening OR you can spawn like "poof" leaves/rubble/wood chippings/clouds.
                        // What we do in the demo is we take the "poof" effect and leave the variable hitEffects for this as I have created sprites for this purpose.  IF you are lacking sprites to display this effect I would recommend using the color effect.

                        // Loop the amount of times we have locations to spawn our effects.
                        for (int i = 0; i < hitEffectLocations.Length; i++)
                        {
                            // Create our Effect at one of our locations specified.
                            Instantiate(hitEffects, hitEffectLocations [i].transform.position, Quaternion.identity);
                        }
                    }
                    // We found a match for our SubType so it cannot match with anything else.
                    return;
                }
            }
        }
Exemplo n.º 11
0
 void ChangePlayerMovement(bool isMovable)
 {
     // Change the player variable for movement purposes.
     Character_Manager.GetPlayerManager().GetComponent <Player_Manager>().CanMove = isMovable;
 }
Exemplo n.º 12
0
 void Start()
 {
     // Attempt to get this character manager script.
     characterManager = GetComponentInParent <Character_Manager> ();
     requestManager   = GetComponentInParent <PathRequestManager>();
 }