コード例 #1
0
    // If trigger enabled over objects, accounts for objects inside of trigger that never call OnTriggerEnter
    void CheckOverlaps()
    {
        // If box not null use box, else if circle not null use circle overlap
        Collider2D[] overlaps = null;

        if (_boxCollider != null)
        {
            overlaps = Physics2D.OverlapBoxAll(transform.position, _boxCollider.size, transform.eulerAngles.z);
        }
        else if (_circleCollider != null)
        {
            overlaps = Physics2D.OverlapCircleAll(transform.position, _circleCollider.radius);
        }

        // Check if the overlapped object doesn't exist in the current list, if not then affect it
        if (overlaps != null)
        {
            foreach (Collider2D obj in overlaps)
            {
                foreach (GameObject affectedTags in Affected)
                {
                    if (obj.tag == affectedTags.tag)
                    {
                        BasicStatManager bs = obj.GetComponent <BasicStatManager>();

                        if (bs != null && !_overlapObjects.Contains(bs))
                        {
                            AffectObject(bs);
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
    protected override void GetTargets()
    {
        base.GetTargets();

        _abilityManager.BasicAttack.target = null;
        _abilityManager.Ability1.target    = null;

        // If returned object is valid set target for a1
        if (!_target)
        {
            _target = GetLowestTargetHealth();
        }

        // when target found ONLY STICK WITH TARGET UNTIL HP == MAX HP
        if (_target != null)
        {
            _abilityManager.Ability1.target = _target.gameObject;

            // LOCK
            if (_target.GetHP() >= _target.MaxHP)
            {
                _target = null;
            }
        }
    }
コード例 #3
0
    // Add effects onto the object
    void AffectObject(BasicStatManager otherObject)
    {
        if (otherObject != null)
        {
            foreach (Effect e in Effects)
            {
                // Add effect if it doesn't already exist, otherwise reset the effect timer
                Effect otherE = otherObject.FindEffect(e);

                if (otherE == null)
                {
                    // Set source object
                    e.source = gameObject;

                    otherObject.AddEffect(e);
                }
                else
                {
                    otherE.ResetEffect();
                }
            }

            if (!_overlapObjects.Contains(otherObject))
            {
                _overlapObjects.Add(otherObject);
            }
        }
    }
コード例 #4
0
    BasicStatManager GetLowestTargetHealth()
    {
        float            minHP          = float.MaxValue;
        BasicStatManager lowestHPObject = null;

        foreach (GameObject target in _targeter.GetTargets())
        {
            // If object tag is player and their distance is less than attack range,
            // return them [BASIC ATTACK IS ATTACK, A1 IS HEALING]

            // If ally within range then find lowest health one
            var bStat = target.GetComponent <BasicStatManager>();

            //if (bStat != null && CheckRange(_basicAttackRange.radius, target) && target.tag == PlayerPrefab.tag)
            //    return bStat;

            if (bStat != null && target.tag != PlayerPrefab.tag && CheckRange(_a1Range.radius, target) && bStat.GetHP() < minHP)
            {
                minHP          = bStat.GetHP() / bStat.MaxHP; // Set min hp
                lowestHPObject = bStat;
            }
        }

        return(lowestHPObject);
    }
コード例 #5
0
    protected override void Affect(GameObject target)
    {
        base.Affect(target);

        // Apply damage to the target
        if (basicStats == null)
        {
            basicStats = target.GetComponent <BasicStatManager>();
        }

        if (basicStats != null)
        {
            float dmg = Random.Range(DamageRange.x, DamageRange.y);

            // Crit chance
            if (Random.Range(0, 100) < CritChance)
            {
                dmg *= CritMultiplier;
            }

            // Incase we use Damage Over Time
            if (UseDeltaTime)
            {
                dmg *= Time.deltaTime;
            }

            basicStats.TakeDamage(dmg, IgnoreArmor);
        }
    }
コード例 #6
0
    // Update
    void OnHeroSwitch(GameObject hero, GameObject reciever = null)
    {
        _heroAbilities = hero.GetComponent <AbilityManager>();
        _heroStats     = hero.GetComponent <BasicStatManager>();

        // Setup ability ui
        if (_heroAbilities != null)
        {
            Ability1UI.Enable();
            Ability2UI.Enable();
            Ability1UI.SetUIElements(_heroAbilities.Ability1.AbilityName, _heroAbilities.Ability1.UISprite);
            Ability2UI.SetUIElements(_heroAbilities.Ability2.AbilityName, _heroAbilities.Ability2.UISprite);
        }
        else
        {
            Ability1UI.Disable();
            Ability2UI.Disable();
        }

        if (_heroStats != null)
        {
            HeroNameText.text = _heroStats.name;
        }
        // Move marker to current hero
    }
コード例 #7
0
    private Vector2 _aimPosition;      // Aim target position for ability

    // Use this for initialization
    public void Init(BasicStatManager parentStat)
    {
        _currCooldown          = 0;
        _currAbilityEnableTime = 0;
        _aiming        = false;
        _restingObject = null;
        CanUse         = true;

        BasicStats = parentStat;
    }
コード例 #8
0
    /*
     * -------------------------------------------------------------------
     *                          PRIVATE FIELDS
     * -------------------------------------------------------------------
     */

    private void Awake()
    {
        if (HeroControl == null)
        {
            HeroControl = FindObjectOfType <HeroController>();
        }
        if (BasicStats == null)
        {
            BasicStats = GetComponent <BasicStatManager>();
        }
    }
コード例 #9
0
    private float currATTKCooldown = 0;     // Attack cooldown

    private void Awake()
    {
        currATTKCooldown = BasicATTKSpeed;

        if (BasicStats == null)
        {
            BasicStats = GetComponent <BasicStatManager>();
        }

        if (Weapon != null)
        {
            Weapon.SetActive(false);
        }
    }
コード例 #10
0
    // Remove object from zone
    private void OnTriggerExit2D(Collider2D collision)
    {
        foreach (GameObject obj in Affected)
        {
            if (obj.tag == collision.tag)
            {
                BasicStatManager bStats = collision.gameObject.GetComponent <BasicStatManager>();

                if (bStats != null)
                {
                    _overlapObjects.Remove(bStats);
                }
            }
        }
    }
コード例 #11
0
    // Add Object to zone
    private void OnTriggerEnter2D(Collider2D collision)
    {
        foreach (GameObject obj in Affected)
        {
            if (obj.tag == collision.tag)
            {
                // Administer effect to all who trigger
                BasicStatManager bStats = collision.gameObject.GetComponent <BasicStatManager>();

                if (bStats != null)
                {
                    AffectObject(bStats);
                }
            }
        }
    }
コード例 #12
0
    // Move heroes to their position slots
    void ResetHeroPositions()
    {
        if (_heroPositionSlots.Length == Heroes.Count)
        {
            for (int i = 0; i < Heroes.Count; ++i)
            {
                Heroes[i].transform.position = _heroPositionSlots[i].position;
            }

            currentHero = Heroes[0];
        }
        else
        {
            Debug.LogError("HERO CONTROLLER ERROR: Hero count and position slots are different!");
        }
    }
コード例 #13
0
    private float _currSwapTime = 0;                   // Current swap time
    // Set up references
    void Awake()
    {
        // Get rigidbody
        _rb     = GetComponent <Rigidbody2D>();
        canMove = true;

        // Get Heroes from parent
        if (HeroParent != null)
        {
            Heroes         = new List <BasicStatManager>(HeroParent.GetComponentsInChildren <BasicStatManager>());
            currentHero    = Heroes[0];
            _currHeroIndex = 0;
        }

        _positionParentCCollider = HeroPositionParent.GetComponent <CircleCollider2D>();

        // Setup position points
        CreatePositionSlots();

        // Move heroes to each position
        ResetHeroPositions();
    }
コード例 #14
0
    void SwapHero()
    {
        if (InputUtility.GetAxisDown("HeroSwitch", true))
        {
            // Pop off front hero and insert them at back
            BasicStatManager front = Heroes[0];
            front.isResting = true;
            Heroes.RemoveAt(0);
            Heroes.Add(front);

            Heroes[0].isResting = false;

            EventManager.TriggerEvent("OnHeroSwitch", Heroes[0].gameObject);
        }
        if (InputUtility.GetAxisDown("HeroSwitch", false))
        {
            Heroes[0].isResting = true;
            BasicStatManager back = Heroes[Heroes.Count - 1];
            Heroes.RemoveAt(Heroes.Count - 1);
            Heroes.Insert(0, back);

            back.isResting = false;

            EventManager.TriggerEvent("OnHeroSwitch", Heroes[0].gameObject);
        }

        currentHero = Heroes[0];

        // Lerp all heroes to destination position (hero slot positions)
        for (int i = 0; i < Heroes.Count; ++i)
        {
            BasicStatManager hero = Heroes[i];
            //Debug.Log(hero.name + "SWITCHING HERO POSITION ");
            hero.gameObject.transform.position = Vector3.Lerp(hero.gameObject.transform.position, _heroPositionSlots[i].position, Time.deltaTime * SwapTime);
        }
    }