Exemple #1
0
        void OnCollisionEnter2D(Collision2D coll)
        {
            // IF the chest is already opened.
            if (GetComponent <SpriteRenderer> ().sprite == openChest)
            {
                // We leave
                return;
            }
            Character_Manager charaManager = coll.gameObject.GetComponentInParent <Character_Manager> ();

            // IF the colliding gameobject isnt the Hero/Player.
            if (charaManager.characterType != CharacterType.Hero)
            {
                // We leave.
                return;
            }
            // Grab the Key script.
            Key key = charaManager.GetComponentInChildren <Key> ();

            // IF the player does not have any keys AND this chest requires a key to open.
            if (key.GetKeys(ckc.name) == 0 && requireKeyToOpen)
            {
                return;
            }
            // The prerequisites have been met so lets reduce the key by 1, open the chest and shoot the item from the chest.
            // IF this chest required a key to open.
            if (ckc.consume)
            {
                // Remove a key.
                key.AddSubtractKeys(ckc.name, -1);
            }
            // Open the Chest.
            OpenChest(coll.gameObject);
        }
Exemple #2
0
        /// <summary>
        /// Uses the consumable.  Since our type is a consumable we will use it and reduce it by 1 but if its amount is 0 after usage we remove it from the inventory.
        /// </summary>
        public void UseConsumable(Item usedItem)
        {
            // Get the Character_Manager component.
            Character_Manager character = Character_Helper.GetPlayerManager().GetComponent <Character_Manager> ();

            // Loop the amount of inventory spaces we have.
            for (int i = 0; i < defaultSlotAmount + extraInventorySlots; i++)
            {
                // IF the IDs match.
                if (items [i].ID == usedItem.ID)
                {
                    // Play the Pickup Sound.
                    Grid_Helper.soundManager.PlaySound(usedItem.UsedSound);
                    // Add "usage" attributes associated with this item.  At this current time if you are looking at the demo we only add HP.
                    character.GetComponentInChildren <Character_Stats> ().AddHealth((float)usedItem.RestoreHP);

                    // Remove the item from our inventory.
                    RemoveItemFromInventory(usedItem.ID, 1);
                    // Do not show the tooltip.
                    Grid_Helper.tooltip.DeactivateItemTooltip();
                    // Leave this loop because we can only use 1 item at a time so we are done.
                    return;
                }
            }
        }
 void Awake()
 {
     // Get the Character Manager component.
     characterManager = Character_Helper.GetPlayerManager().GetComponent <Character_Manager> ();
     // Get the characters stats as we use that to potentially alter movement.
     charStats = characterManager.GetComponentInChildren <Character_Stats> ();
     // Get the Rigidbody2D Component.
     rb = GetComponent <Rigidbody2D> ();
 }
Exemple #4
0
 void Start()
 {
     // Get the Character Manager.
     characterManager = GetComponent <Character_Manager> ();
     // Get the Character Stats component.
     charStats = characterManager.GetComponentInChildren <Character_Stats> ();
     // Get the Transform componenet.
     _transform = characterManager.GetComponent <Transform> ();
 }
Exemple #5
0
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            // Reference the Character Manager.
            Character_Manager charManager = animator.GetComponentInParent <Character_Manager> ();

            // Get our player Renderer.
            playerRenderer = charManager.characterEntity.GetComponent <SpriteRenderer> ();
            // Get our weapon.
            Item meleeWeapon = Character_Helper.GetPlayerManager().GetComponentInChildren <Equipment> ().GetWeapon();


            // Now we need to know which way we are facing to position the weapon.
            weaponGameObject = Instantiate(Grid_Helper.setup.GetGameObjectPrefab(meleeWeapon.WeaponSlug), charManager.GetMeleeLocation(animator.GetInteger("Direction")));
            // Get our weapon Renderer.
            weaponRenderer = weaponGameObject.GetComponent <SpriteRenderer> ();
            // Set the layer of the character entity.
            weaponRenderer.sortingLayerName = playerRenderer.sortingLayerName;
            // Set the owner to this weapon.
            weaponGameObject.GetComponent <Owner> ().owner = animator.gameObject;
            // Set the damage to this weapon by putting the Item's damage as the parameter.
            weaponGameObject.GetComponent <Owner> ().damage = charManager.GetComponentInChildren <Character_Stats> ().GetCurrentDamage();


//			// IF this is NOT a full body sprite and we are going into the children to find a body reference.
//			if (playerRenderer == null) {
//				// Cache the Transform of the player.
//				Transform charTransform = charManager.characterEntity.transform;
//				// Loop the amount of children we have.
//				for (int x = 0; x < charTransform.childCount; x++) {
//					// IF the tag of the child gameobject is Body
//					if (charTransform.GetChild (x).tag == "Body") {
//						// Get the Sprite Renderer for the body reference.
//						playerRenderer = charTransform.GetChild (x).GetComponent <SpriteRenderer> ();
//						// Leave.
//						break;
//					}
//				}
//			}

            // Set the order layer it needs to be in.
            // IF the weapon should be displayed behind of the player,
            // ELSE the weapon should be displayed infront the player.
            if (animator.GetInteger("Direction") == 1)
            {
                // Set the weapon behind the player.
                weaponRenderer.sortingOrder = playerRenderer.sortingOrder - sortOrderGap;
            }
            else
            {
                // Set the weapon infront of the player.
                weaponRenderer.sortingOrder = playerRenderer.sortingOrder + sortOrderGap;
            }
            // Play the attack sound (if there is one).
            Grid_Helper.soundManager.PlaySound(meleeWeapon.AttackSound);
        }
 void Awake()
 {
     // Get the Characters Manager component.
     characterManager = Character_Helper.GetPlayerManager().GetComponent <Character_Manager> ();
     // Get the characters stats as we use that to potentially alter movement.
     charStats = characterManager.GetComponentInChildren <Character_Stats> ();
     // Get the Rigidbody2D Component.
     rb = GetComponent <Rigidbody2D> ();
     // Set the horizontalFirst to false as nothing is being pressed.
     firstKeyPressed = false;
     horizontalFirst = false;
     verticalFirst   = false;
 }
Exemple #7
0
        /// <summary>
        /// Handles the action of the type of items.
        /// </summary>
        private void HandleTypes(Character_Manager playerManager)
        {
            // IF we pick up a Key,
            // ELSE IF we pick up a Bomb,
            // ELSE IF we pick up a type of Currency,
            // ELSE IF we pick up a stat increase Item,
            // ELSE IF *tbc*
            if (type == "Key")
            {
                // Get the Key script.
                Key key = playerManager.GetComponentInChildren <Key> ();
                // Add to the keys.
                key.AddSubtractKeys(title, amount);
            }
            else if (type == "Bomb")
            {
                // Get the Bombs script.
                Bombs bombs = playerManager.GetComponentInChildren <Bombs> ();
                // Add to the bombs.
                bombs.AddBombs(subType, amount);
            }
            else if (type == "Currency")
            {
                // Get the Money script.
                Money money = playerManager.GetComponentInChildren <Money> ();
                // Add to the currency.
                money.AddMoney(currency, amount);
            }
            else if (type == "Stat Increase")
            {
                // Get the Character Stats (or any data structure if you choose to make your own or use another Asset),
                Character_Stats charStats = playerManager.GetComponentInChildren <Character_Stats> ();
                // Then Add to the stats.
                charStats.IncreaseMaxHealth(bonusHealth);
//				charStats.IncreaseMaxMana (bonusMana);
//				charStats.IncreaseBaseDamage (bonusDamage);
//				charStats.IncreaseBaseMoveSpeed (bonusMoveSpeed);
            }
        }
Exemple #8
0
 void Update()
 {
     // IF there isn't a character manager active on the scene.
     if (characterManager == null)
     {
         // Get the Character Manager GameObject.
         characterManager = Character_Helper.GetPlayerManager().GetComponent <Character_Manager>();
         return;
     }
     // IF there isn't a Character_Stats (or any script you want that holds your characters data) for your characters data.
     if (charStats == null)
     {
         // Get your Character_Stats.
         charStats = characterManager.GetComponentInChildren <Character_Stats> ();
         return;
     }
     // Display your hearts.
     DisplayHearts();
 }
 /// <summary>
 /// Loop and see what we can damage based on CharacterType.
 /// </summary>
 public void DamageCharacterTypeLoop(Transform original, Character_Manager otherChar, CharacterType[] damageTheseTypes,
                                     float damage, float joltAmount)
 {
     // Loop through all the Character Types this GameObject collides with to see if we are allowed to damage them.
     for (int i = 0; i < damageTheseTypes.Length; i++)
     {
         // IF the colliding objects characterType matches one of the types that can take damage OR the selection
         // is an ALL choice.
         if (otherChar.characterType == damageTheseTypes [i] || damageTheseTypes[i] == CharacterType.All)
         {
             // Check for Immunity.
             Immunity_Time _ITS = otherChar.characterEntity.GetComponentInParent <Immunity_Time> ();
             // IF the colliding object has the Immunity_Time script,
             // ELSE just damage the target.
             if (_ITS != null)
             {
                 // IF we are Vulnerable.
                 if (_ITS.GetVulnerability())
                 {
                     // We passed the prerequisites to do damage... Yay!
                     otherChar.TakeDamage(damage, original, joltAmount);
                     // IF the Character dies while taking damage.
                     if (otherChar.GetComponentInChildren <Character_Stats> ().CurrentHealth <= 0f)
                     {
                         // We just leave as there is no need to alter the Change Vulnerability.
                         return;
                     }
                     // Since there is a Immunity_Time script on the colliding object we need to make sure we set the
                     // vulnerability of the colliding gameobject to false;
                     _ITS.ChangeVulnerability(false);
                 }
             }
             else
             {
                 // We passed the prerequisites to do damage... Yay!.
                 otherChar.TakeDamage(damage, original, joltAmount);
             }
             // Found 1 so we return.
             return;
         }
     }
 }
Exemple #10
0
        private void CollideDamage(GameObject coll)
        {
            // IF YOU HAVE ANOTHER SCRIPT IN WHICH YOU DO NOT CARE ABOUT USING CHARACTER_MANAGER
            // THEN MAKE SURE TO LOOK FOR THE SCRIPT HERE AND MAKE A CHECK IF IT HAS IT.

            // Grab the Character_Manager Component from the colliding object.
            Character_Manager otherChar = coll.GetComponentInParent <Character_Manager> ();

            // IF there is NOT a Character_Manager component.
            if (otherChar == null)
            {
                // We return because we only care about damaging a gameobject that has the Character_Manager
                // Component.
                return;
            }
            // IF the colliding GameObject's Character_Manager characterEntity is NOT the same as the
            // GameObject we are colliding with.
            if (!otherChar.characterEntity.Equals(coll.gameObject))
            {
                // We leave as we are damaging something that isn't a piece of the Entity.
                // Example would be 2 people clashing swords, Yes both swords are part of the Entity and
                // children of that entity BUT it ISN'T the Entity so we do not care.
                return;
            }

            // Since we have a Character_Manager lets get the Character_Stats script.
            Character_Stats charStats = otherChar.GetComponentInChildren <Character_Stats> ();

            // IF there is not a script to hold the stats of this Character.
            if (charStats == null)
            {
                // Then there is nothing we can damage we are attacking a Character but this character is
                // statless so its like a town friendly NPC.
                return;
            }

            // Play a sound.
            Grid_Helper.soundManager.PlaySound(collisionSound);
            // Lets go into our loop and see if we can damage anything.
            Grid_Helper.helper.DamageCharacterTypeLoop(transform, otherChar, damageTheseTypes, damage, joltAmount);
        }
Exemple #11
0
        private void CollideDamage(GameObject coll)
        {
            // Grab the Character_Manager Component from the colliding object.
            Character_Manager otherChar = coll.GetComponentInParent <Character_Manager> ();

            // IF there is NOT a Character_Manager component.
            if (otherChar == null)
            {
                // We return because we only care about damaging a gameobject that has the Character_Manager Component.
                return;
            }
            // IF the Character_Managers characterEntity is NOT the same as the GameObject we are colliding with.
            if (!otherChar.characterEntity.Equals(coll.gameObject))
            {
                // We leave as we are damaging something that isn't a piece of the Entity.
                // Example would be 2 people clashing swords, Yes both swords are part of the Entity and
                // children of that entity BUT it ISN'T the Entity so we do not care.
                return;
            }

            // Since we have a Character_Manager lets get the Character_Stats script.
            Character_Stats charStats = otherChar.GetComponentInChildren <Character_Stats> ();

            // IF there is not a script to hold the stats of this Character.
            if (charStats == null)
            {
                // Then there is nothing we can damage we are attacking a Character but this character is statless so its like a town friendly NPC.
                return;
            }

            // Loop through all the Character Types this GameObject collides with to see if we are allowed to damage them.
            for (int i = 0; i < damageTheseTypes.Length; i++)
            {
                // IF the colliding objects characterType matches one of the types that can take damage OR the selection is an ALL choice.
                if (otherChar.characterType == damageTheseTypes [i] || damageTheseTypes[i] == CharacterType.All)
                {
                    // Check for Immunity.
                    Immunity_Time _ITS = coll.GetComponentInParent <Immunity_Time> ();
                    // IF the colliding object has the Immunity_Time script,
                    // ELSE just damage the target.
                    if (_ITS != null)
                    {
                        // IF we are Vulnerable.
                        if (_ITS.GetVulnerability())
                        {
                            // We passed the prerequisites to do damage... Yay!
                            DamageCharacter(otherChar);
                            // IF the player dies while taking damage.
                            if (charStats.CurrentHealth <= 0f)
                            {
                                // We just leave as there is no need to alter the Change Vulnerability.
                                return;
                            }
                            // Since there is a Immunity_Time script on the colliding object we need to make sure we set the vulnerability of the colliding gameobject to false;
                            _ITS.ChangeVulnerability(false);
                        }
                    }
                    else
                    {
                        // We passed the prerequisites to do damage... Yay!.
                        DamageCharacter(otherChar);
                    }
                    // Found 1 so we return.
                    return;
                }
            }
        }
Exemple #12
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;
                }
            }
        }
 /// <summary>
 /// Go to next 'location'.
 /// </summary>
 private IEnumerator GoToNextLocation()
 {
     // While everything is true!!!!
     while (true)
     {
         // WHILE the current position has not reached the next position.
         while (_transform.position != Locations [_locationIndex].position)
         {
             // IF this is a Character,
             // ELSE its just a random object so lets move to the next point with no interruptions.
             if (characterManager != null)
             {
                 // IF this Entity has stats.
                 if (characterManager.GetComponentInChildren <Character_Stats> () != null)
                 {
                     // Set its movement speed based on the stats.
                     Speed = characterManager.GetComponentInChildren <Character_Stats> ().CurrentMoveSpeed;
                 }
                 // IF this character can move.
                 if (characterManager.canMove)
                 {
                     // Move towards the next point.
                     _transform.position = Vector2.MoveTowards(_transform.position, Locations [_locationIndex].position, Speed * Time.deltaTime);
                 }
             }
             else
             {
                 // Move towards the next point.
                 _transform.position = Vector2.MoveTowards(_transform.position, Locations [_locationIndex].position, Speed * Time.deltaTime);
             }
             yield return(null);
         }
         // IF we are moving forward in the array,
         // ELSE we are moving backwards in the array.
         if (forward)
         {
             // Increase the index.
             _locationIndex++;
         }
         else
         {
             // Decrease the index.
             _locationIndex--;
         }
         // IF we are at the end of the array,
         // ELSE IF we are at the start of the array.
         if ((_locationIndex + 1 == Locations.Length))
         {
             // IF we want to loop back to the beginning,
             // ELSE we move backwards through the array.
             if (loop)
             {
                 // Go to the start.
                 _locationIndex = 0;
             }
             else
             {
                 // Time to move backwards in the array.
                 forward = false;
             }
         }
         else if ((_locationIndex == 0))
         {
             // Time to move forward in the array.
             forward = true;
         }
         // Wait somewhere inbetween the min and max time.
         yield return(new WaitForSeconds(Random.Range(WaitTimeMin, WaitTimeMax)));
     }
 }
Exemple #14
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;
                }
            }
        }