public override void Execute() { if (CurrentBehaviour != null) { Transform playerTransform = Target.transform; Behaviour aiBehaviour = current; float dist = Vector2.Distance(playerTransform.position, transform.position); if (CurrentBehaviour.GetType() == typeof(Aggro) && dist <= activeRange) { CurrentBehaviour.Execute(playerTransform.position); } else if (CurrentBehaviour.GetType() == typeof(Patrol) && dist <= activeRange) { CurrentBehaviour.Execute(patrolPath); if (Vector2.Distance(patrolPath, transform.position) <= relativeRange) { patrolPath = GenerateRandom(Camera.main); CurrentBehaviour.Execute(patrolPath, cooldownTimer.GetDownTime()); if (dist <= activeRange) { CurrentBehaviour = new Aggro("aggro", this, activeRange, attackRange); } } } } }
public void Damaged(GameObject playerObject, float damage) { if (!enemyActive) { return; } Player player = playerObject.GetComponent <Player>(); Aggro playerAggro = _playersInside.Find(x => x.player == player); if (playerAggro != null) // player is already in list { // just add the aggro playerAggro.AddAggro(damage * _aggroPerDamage); } else { // add to list _playersInside.Add(new Aggro(player)); _playersInside[_playersInside.Count - 1].AddAggro(damage * _aggroPerDamage); _playersInside[_playersInside.Count - 1].SetAsSeen(); CalculateHighestAggro(); } // not sure why this is here 9/12/20 foreach (Aggro p in _playersInside) { if (player == p.player) { // player already being tracked return; } } }
private void Awake() { // x defecto _currentState = EnemyStates.Idle; aggroState = GetComponent <Aggro>(); idleState = GetComponent <Idle>(); }
void CalculateHighestAggro() { if (_playersInside.Count == 0) { return; } float highestVal = -1; int highestIndex = -1; foreach (Aggro playerAggro in _playersInside) { if (playerAggro.aggro > highestVal) { highestIndex = _playersInside.IndexOf(playerAggro); } } currentTarget = _playersInside[highestIndex]; }
private void FixedUpdate() { if (!enemyActive) { return; } for (int i = 0; i < _playersInside.Count; i++) { if (!_playersInside[i].hasSeenInLOS) { RaycastHit hit; if (Physics.Raycast(transform.position, (_playersInside[i].player.transform.position - transform.position).normalized, out hit, Mathf.Infinity, ~playerMask) && hit.transform.tag == "Player") { _playersInside[i].SetAsSeen(); if (currentTarget.player == null) // this is the first player { currentTarget = _playersInside[0]; // make them the current target } } } } // turn to face player if (currentTarget.player != null) { Vector3 dir = (currentTarget.player.transform.position - transform.position).normalized; dir.y = 0; // keep it horizontal if (dir != Vector3.zero) { Quaternion rot = Quaternion.LookRotation(dir); transform.rotation = Quaternion.Slerp(transform.rotation, rot, _rotationSpeed); } } }
private void OnTriggerEnter(Collider other) { Aggro newTarget = other.GetComponent <Aggro>(); // Null Check if (newTarget == null) { return; } if (Target == null) { Target = newTarget; } else { if (Target.GetValue() < newTarget.GetValue()) { Target = newTarget; } } }
public void OnAggroEnter(Collider other) { if (other.tag != "Player") { return; } Player player = other.gameObject.GetComponent <Player>(); // start following player if not already in foreach (Aggro p in _playersInside) { if (player.GetInstanceID() == p.player.GetInstanceID()) { // player already being tracked return; } } // add the player to tracking _playersInside.Add(new Aggro(player)); // if in line of sight, start tracking RaycastHit hit; if (Physics.Raycast(transform.position, (other.transform.position - transform.position).normalized, out hit, Mathf.Infinity, ~playerMask) && hit.transform.tag == "Player") { if (_playersInside.Count == 1) // this is the first player { currentTarget = _playersInside[0]; // make them the current target } _playersInside[_playersInside.Count - 1].SetAsSeen(); } }
private void OnTriggerExit(Collider other) { Target = null; }
static Weights() { ItemCache = new SimpleCache <float> { MaxAge = MinCaching }; LongCache = new SimpleCache <float> { MaxAge = 3000 }; InvertedPrefix = "[i]"; CustomPrefix = "[c]"; PItems = new List <Item>(); PItems.AddRange( new List <Item> { new Item( "killable", "AA Killable", 20, false, t => t.Health < ObjectManager.Player.GetAutoAttackDamage(t, true) ? 1 : 0, "Checks if target is killable with one auto attack."), new Item( "attack-damage", "Attack Damage", 15, false, delegate(Obj_AI_Hero t) { var ad = t.FlatPhysicalDamageMod; var infinity = LongCache.GetOrAdd( "infinity-edge-" + t.ChampionName, () => ItemData.Infinity_Edge.GetItem().IsOwned(t) ? 2.5f : 2); ad += ad / 100 * (t.Crit * 100) * (infinity ?? 1f); var averageArmor = LongCache.GetOrAdd( "average-armor", delegate { return(HeroManager.Allies.Select(a => a.Armor).DefaultIfEmpty(0).Average() * t.PercentArmorPenetrationMod - t.FlatArmorPenetrationMod); }); return(ad * (100 / (100 + (averageArmor ?? 0))) * (1f / ObjectManager.Player.AttackDelay)); }, "AD + Pen + Crit + Speed = Higher Weight"), new Item( "ability-power", "Ability Power", 15, false, delegate(Obj_AI_Hero t) { var averageMr = LongCache.GetOrAdd( "average-magic-resist", delegate { return (HeroManager.Allies.Select(a => a.SpellBlock).DefaultIfEmpty(0).Average() * t.PercentMagicPenetrationMod - t.FlatMagicPenetrationMod); }); return(t.FlatMagicDamageMod * (100 / (100 + (averageMr ?? 0)))); }, "AP + Pen = Higher Weight"), new Item( "low-resists", "Resists", 0, true, t => ObjectManager.Player.FlatPhysicalDamageMod >= ObjectManager.Player.FlatMagicDamageMod ? t.Armor : t.SpellBlock, "Low Armor / Magic-Resist = Higher Weight"), new Item("low-health", "Health", 20, true, t => t.Health, "Low Health = Higher Weight"), new Item( "short-distance-player", "Distance to Player", 5, true, t => t.Distance(ObjectManager.Player), "Close to Player = Higher Weight"), new Item( "short-distance-cursor", "Distance to Cursor", 0, true, t => t.Distance(Game.CursorPos), "Close to Cursor = Higher Weight"), new Item( "crowd-control", "Crowd Control", 0, false, delegate(Obj_AI_Hero t) { var buffs = t.Buffs.Where( x => x.Type == BuffType.Charm || x.Type == BuffType.Knockback || x.Type == BuffType.Suppression || x.Type == BuffType.Fear || x.Type == BuffType.Taunt || x.Type == BuffType.Stun || x.Type == BuffType.Slow || x.Type == BuffType.Silence || x.Type == BuffType.Snare || x.Type == BuffType.Polymorph).ToList(); return(buffs.Any() ? buffs.Select(x => x.EndTime).DefaultIfEmpty(0).Max() : 0); }, "Checks if the target suffers from any form of crowd control."), new Item( "gold", "Acquired Gold", 0, false, t => (t.MinionsKilled + t.NeutralMinionsKilled) * 27.35f + t.ChampionsKilled * 300f + t.Assists * 85f, "Calculates the approx. amount of Gold."), new Item( "team-focus", "Team Focus", 0, false, t => Aggro.Items.Where(a => a.Value.Target.Hero.NetworkId == t.NetworkId) .Select(a => a.Value.Value) .DefaultIfEmpty(0) .Sum(), "Checks who your allies are targeting."), new Item( "focus-me", "Focus Me", 0, false, delegate(Obj_AI_Hero t) { var entry = Aggro.GetSenderTargetItem(t, ObjectManager.Player); return(entry != null ? entry.Value : 0); }, "Checks who is targeting you.") }); }
protected override void Awake() { base.Awake(); aggroScript = GetComponentInChildren <Aggro>(); }
private void FixedUpdate() { aggro = (Aggro)GameObject.Find("_GM").GetComponent <_GM_Script>().aggro; }
private void Start() { aggro = Aggro.NONE; state = EnemyState.NONE; flashOn = false; }
public SeekingAggroAIState(AbstractEnemyAI stateMachine, Aggro target) : base(stateMachine) { stateMachine.navigation.SeekQueen(); this.target = target; }
// Use this for initialization void Start() { origin = transform.position; navAgent = gameObject.GetComponent<NavMeshAgent>(); aggro = gameObject.GetComponent<Aggro> (); }
public override void OnInspectorGUI() { serializedObject.Update(); //base.OnInspectorGUI(); statsDisplay = EditorGUILayout.Foldout(statsDisplay, "Stats"); if (statsDisplay) { EditorGUILayout.BeginVertical("box"); enemy.maxHealthPoints = EditorGUILayout.FloatField("Max HP", enemy.maxHealthPoints); EditorGUILayout.PropertyField(attackDmg); EditorGUILayout.PropertyField(defencePwr); EditorGUILayout.PropertyField(normalSpeed); EditorGUILayout.PropertyField(chaseSpeed); EditorGUILayout.PropertyField(lockedSpeed); EditorGUILayout.PropertyField(turnSpeed); EditorGUILayout.PropertyField(paralysisRes); EditorGUILayout.PropertyField(burnRes); EditorGUILayout.PropertyField(breakRes); EditorGUILayout.PropertyField(recoveryRate); EditorGUILayout.EndVertical(); } enemy.AttackType = (Enemy.RhythmAttackType)EditorGUILayout.EnumPopup("Attack Mode", enemy.AttackType); enemy.attackDamageType = (Character.TypeOfDamage)EditorGUILayout.EnumPopup("Damage Type", enemy.attackDamageType); if (enemy.AttackType == Enemy.RhythmAttackType.NOTES) { EditorGUILayout.BeginVertical("box"); EditorGUILayout.PropertyField(attackPeriodList, true); EditorGUILayout.PropertyField(waitToAttackPeriodList, true); EditorGUILayout.EndVertical(); } else { EditorGUILayout.BeginVertical("box"); enemy.beatsToAttack = EditorGUILayout.IntField("Beats To Attack", enemy.beatsToAttack); EditorGUILayout.EndVertical(); } HasTargetPriority = EditorGUILayout.Toggle("Has Target Priority", HasTargetPriority); if (HasTargetPriority) { EditorGUILayout.BeginVertical("box"); enemy.priorities[0] = (Enemy.PriorityTarget)EditorGUILayout.EnumPopup("Primary Target", firstTarget); enemy.priorities[1] = (Enemy.PriorityTarget)EditorGUILayout.EnumPopup("Secondary Target", enemy.priorities[1]); enemy.priorities[2] = (Enemy.PriorityTarget)EditorGUILayout.EnumPopup("Third Target", enemy.priorities[2]); enemy.priorities[3] = (Enemy.PriorityTarget)EditorGUILayout.EnumPopup("Fourth Target", enemy.priorities[3]); EditorGUILayout.EndVertical(); firstTarget = enemy.priorities[0]; } else { enemy.priorities[0] = Enemy.PriorityTarget.NONE; } aggro = (Aggro)EditorGUILayout.EnumPopup("Aggro", aggro); if (aggro != previousTier) { switch (aggro) { case Aggro.TIER1: aggroLvl = Random.Range(1, 20); previousTier = aggro; break; case Aggro.TIER2: aggroLvl = Random.Range(20, 50); previousTier = aggro; break; case Aggro.TIER3: aggroLvl = Random.Range(50, 80); previousTier = aggro; break; case Aggro.TIER4: aggroLvl = Random.Range(80, 100); previousTier = aggro; break; case Aggro.BOSS: aggroLvl = 100; previousTier = aggro; break; } enemy.aggro = aggroLvl; } //EditorGUILayout.HelpBox(enemy.aggro.ToString(), MessageType.None); enemy.lockPosition = (Transform)EditorGUILayout.ObjectField("Player Lock Position", enemy.lockPosition, typeof(Transform), true); serializedObject.ApplyModifiedProperties(); }
public virtual void AddTarget(GameObject obj) { Aggro aggro = new Aggro(); targets.Add(obj, aggro); }
void OnEnable() { aggro = (Aggro)target; }