/// <summary>
    /// Launch the attached GameObject at a target. Ex: a hero towards an enemy or vice versa.
    /// </summary>
    /// <param name="startPosition"> Start position of the propelled object</param>
    /// <param name="targetObj"> Target GameObject</param>
    /// <param name="targetID"> Target's partyID or battleID</param>
    public virtual void Propel(int battleID, Vector2 startPosition, GameObject targetObj, int targetID, BattleMode mode)
    {
        // Convert partyID to battleID if necessary
        selfID = gameObject.CompareTag("Hero_Battle") ? BattleMath.ConvertHeroID(battleID) : battleID;
        this.targetBattleID = targetID;

        // Set start position
        this.startPosition = startPosition;

        // Set target, and collicder if it exists
        target = targetObj;
        bool isOnGameObject = targetObj.TryGetComponent <Collider2D>(out targetCollider);

        if (!isOnGameObject)
        {
            targetCollider = targetObj.GetComponentInChildren <Collider2D>();
        }

        // Create a bullseye-like target at the location of the target (in case there is no collider)
        targetLastPosition = new Bounds(target.transform.position,
                                        new Vector2(BoundsMargin, BoundsMargin));

        // Action being performed by the Propel
        this.mode = mode;

        // Modify speed if Kick or Drill (other effects use override methods to add here)
        switch (mode)
        {
        case BattleMode.Blitz_Kick:
            propelSpeedModifier = KickSpeedModifier;
            break;

        case BattleMode.Tools_Drill:
            propelSpeedModifier = DrillSpeedModifier;
            break;

        default:
            propelSpeedModifier = 1f;
            break;
        }

        // Allow the Update() method to move this GameObject
        isPropelled = true;
    }
Example #2
0
    // Uses the selected item
    public void Click_UseButton()
    {
        if (selection == null)
        {
            return;
        }

        AudioManager.PlaySound(AudioClipName.UsePotion);

        // reference to hero and item
        InvItem    item = partyStash.Contents[(int)selection];
        BattleHero hero = BattleLoader.Party.Hero[BattleMath.ConvertHeroID(TurnCounter.CurrentID)];

        // check for full hp/mp, display message and do not use.
        int hp    = hero.HP;
        int hpMax = hero.HPMax;

        if (hp == hpMax && item.Type == InvType.Potion && item.Subtype == InvSubtype.Health)
        {
            previousMessage  = messageText.text;
            messageText.text = "You are already at full health.";
            messageTimer.Run();
            return;
        }
        int mp    = hero.MP;
        int mpMax = hero.MPMax;

        if (mp == mpMax && item.Type == InvType.Potion && item.Subtype == InvSubtype.Mana)
        {
            previousMessage  = messageText.text;
            messageText.text = "You are already at full mana.";
            messageTimer.Run();
            return;
        }

        // create negative damage for restorative item
        Damage damage = new Damage();

        switch (item.Type)
        {
        case InvType.Potion:

            int healing;
            switch (item.Subtype)
            {
            case InvSubtype.Health:
                switch (item.Name)
                {
                case InvNames.Potion_Health_Tiny:
                    healing = 25;
                    break;

                case InvNames.Potion_Health_Small:
                    healing = 75;
                    break;

                case InvNames.Potion_Health_Medium:
                    healing = 250;
                    break;

                case InvNames.Potion_Health_Large:
                    healing = 600;
                    break;

                case InvNames.Potion_Health_Huge:
                    healing = 2000;
                    break;

                case InvNames.Potion_Health_Epic:
                    healing = 100000;
                    break;

                default:
                    healing = 25;
                    break;
                }

                if (hp + healing > hpMax)
                {
                    healing = hpMax - hp;
                }

                // remove item from stash and queue healing in Damage
                partyStash.RemoveInvItem(item.Name, 1);
                damage.Add(-healing, false, true, false);         // amount, not crit, isItem, not MP
                break;

            case InvSubtype.Mana:
                switch (item.Name)
                {
                case InvNames.Potion_Mana_Tiny:
                    healing = 10;
                    break;

                case InvNames.Potion_Mana_Small:
                    healing = 20;
                    break;

                case InvNames.Potion_Mana_Medium:
                    healing = 50;
                    break;

                case InvNames.Potion_Mana_Large:
                    healing = 125;
                    break;

                case InvNames.Potion_Mana_Huge:
                    healing = 250;
                    break;

                case InvNames.Potion_Mana_Epic:
                    healing = 100000;
                    break;

                default:
                    healing = 10;
                    break;
                }

                if (mp + healing > mpMax)
                {
                    healing = mpMax - mp;
                }

                // remove item from stash and queue healing in Damage
                partyStash.RemoveInvItem(item.Name, 1);
                damage.Add(-healing, false, true, true);         // amount, not crit, isItem, is MP
                break;
            }
            break;

        default:
            damage.Add(null);
            break;
        }
        // disable ui once a choice is made
        uiEnabler.EnableUI(false);

        // Invoke a Player End Turn event
        // Use this event instead of triggering off a fight collision with enemy
        // TurnOver applies the damage queued in Damage
        turnInvoker.TurnOver(damage, TurnCounter.CurrentID);

        // Exit menu
        Destroy(gameObject);
    }