// 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); } } } } } }
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; } } }
// 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); } } }
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); }
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); } }
// 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 }
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; }
/* * ------------------------------------------------------------------- * PRIVATE FIELDS * ------------------------------------------------------------------- */ private void Awake() { if (HeroControl == null) { HeroControl = FindObjectOfType <HeroController>(); } if (BasicStats == null) { BasicStats = GetComponent <BasicStatManager>(); } }
private float currATTKCooldown = 0; // Attack cooldown private void Awake() { currATTKCooldown = BasicATTKSpeed; if (BasicStats == null) { BasicStats = GetComponent <BasicStatManager>(); } if (Weapon != null) { Weapon.SetActive(false); } }
// 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); } } } }
// 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); } } } }
// 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!"); } }
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(); }
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); } }