/// <summary> /// Tells this behaviour that a certain action has happened. /// </summary> /// <param name="context"></param> /// <param name="type"></param> /// <param name="other"></param> public void CallAIBehaviour(Intelligence context, AIBehaviourType type, Collider other = null) { //First roll chance for if we are acting on this behaviour if (Random.value <= GetAIBehaviourChance(type)) { //Call the main code for this type of action RunAIBehaviour(context, type, other); //Check each sub behaviour to see if it needs to be run. foreach (SubAIBehaviour b in subAIBehaviours) { CallSubBehaviours(context, b, type, other); } } }
/// <summary> /// Checks a sub behaviour to see if it perfroms regular updates, and if it does call that behaviour on it. /// </summary> /// <param name="context"></param> /// <param name="b"></param> /// <param name="type"></param> /// <param name="other"></param> private void CallSubBehaviours(Intelligence context, SubAIBehaviour b, AIBehaviourType type, Collider other = null) { //Switch between all BehaviourTypes, check if they recieve regular updates, and call them if they do switch (type) { case AIBehaviourType.FixedGameUpdate: if (b.regularFixedUpdate) { b.behaviour.CallAIBehaviour(context, type, other); } return; case AIBehaviourType.GameUpdate: if (b.regularGameUdate) { b.behaviour.CallAIBehaviour(context, type, other); } return; case AIBehaviourType.TriggerEnter: if (b.regularTriggerEnter) { b.behaviour.CallAIBehaviour(context, type, other); } return; case AIBehaviourType.TriggerExit: if (b.regularTriggerExit) { b.behaviour.CallAIBehaviour(context, type, other); } return; case AIBehaviourType.TriggerStay: if (b.regularTriggerStay) { b.behaviour.CallAIBehaviour(context, type, other); } return; default: return; } }
/// <summary> /// Calls the correct behavoir based on the AIBehaviour type. /// </summary> /// <param name="type"></param> /// <param name="collider"></param> private void RunAIBehaviour(Intelligence context, AIBehaviourType type, Collider collider = null) { //Call the correct behaviour based on the type switch (type) { case AIBehaviourType.FixedGameUpdate: Behaviour_OnFixedGameUpdate(context); return; case AIBehaviourType.GameUpdate: Behaviour_OnGameUpdate(context); return; case AIBehaviourType.TriggerEnter: if (collider == null) { Debug.LogError("Invalid call in a AIBehaviour with Triggers."); } Behaviour_OnTriggerEnter(context, collider); return; case AIBehaviourType.TriggerExit: if (collider == null) { Debug.LogError("Invalid call in a AIBehaviour with Triggers."); } Behaviour_OnTriggerExit(context, collider); return; case AIBehaviourType.TriggerStay: if (collider == null) { Debug.LogError("Invalid call in a AIBehaviour with Triggers."); } Behaviour_OnTriggerStay(context, collider); return; default: return; } }
public void SetAIBehaviour(AIBehaviourType type) { switch (type) { // Sequence case AIBehaviourType.Sequence: if (sequenceBehaviour == null) { Debug.Log("Follow behaviour is null"); return; } currentActionIndex = 0; break; // FOllow case AIBehaviourType.Follow: if (targetObject == null) { Debug.Log("Sequence behaviour is null"); return; } waitTime = refreshTime; break; } behaviourType = type; time = 0; }
/// <summary> /// Returns the chance for this behaviour happening based on the type. /// </summary> /// <param name="type"></param> /// <returns></returns> private float GetAIBehaviourChance(AIBehaviourType type) { //Determine the correct behaviour chance based on the type. switch (type) { case AIBehaviourType.FixedGameUpdate: return(fixedGameUpdateChance); case AIBehaviourType.GameUpdate: return(gameUpdateChance); case AIBehaviourType.TriggerEnter: return(triggerEnterChance); case AIBehaviourType.TriggerExit: return(triggerExitChance); case AIBehaviourType.TriggerStay: return(triggerStayChance); default: return(1.0f); } }
static public List <KeyValuePair <BaseCharacter, int> > ProcessBehaviour(BaseCharacter bc, List <BaseCharacter> lbc) { List <KeyValuePair <BaseCharacter, int> > charsAndThreat = new List <KeyValuePair <BaseCharacter, int> >(); int randomNum = GamePlayUtility.Randomize(0, lbc.Count); AIBehaviourType Behaviour = (bc).Behaviour; if (lbc.Count != 0 && CombatProcessor.heroCharacters.Contains(lbc[0])) { foreach (var character in lbc) { int threat = character.returnTotalThreat(); float modifier = 1.3f; switch (Behaviour) { case AIBehaviourType.Neutral: break; case AIBehaviourType.Berserk: int maxSTR = lbc.Max(c => c.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.STR]); if (character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.STR] == maxSTR) { threat = (int)(modifier * threat); threat += 10; } break; case AIBehaviourType.Magic_Hater: if (character.CCC.equippedClass.classType == BaseClass.CLASSType.CASTER) { threat = (int)(modifier * threat); threat += 10; } break; case AIBehaviourType.Random: if (lbc.IndexOf(character) == randomNum) { threat = (int)(modifier * threat); threat += 10; } break; case AIBehaviourType.Challenger: int maxDEF = lbc.Max(c => c.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.DEF]); if (character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.DEF] == maxDEF) { threat = (int)(modifier * threat); threat += 10; } break; case AIBehaviourType.Coward: maxSTR = lbc.Max(c => c.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.STR]); if (character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.STR] == maxSTR) { threat = (int)((0.8f) * threat); threat -= 7; } break; case AIBehaviourType.Avenger: int maxKD = lbc.Max(c => BattleStats.getKDFromBattle(c)); if (BattleStats.getKDFromBattle(character) == maxKD) { threat = (int)((modifier) * threat); threat += 10; } break; case AIBehaviourType.Ambitious: int maxHP = lbc.Max(c => c.trueSTATChart().currentPassiveStats[(int)STATChart.ACTIVESTATS.HP]); if (character.trueSTATChart().currentPassiveStats[(int)STATChart.ACTIVESTATS.HP] == maxHP) { threat = (int)((modifier) * threat); threat += 10; } break; case AIBehaviourType.Finisher: int minHP = lbc.Min(c => c.trueSTATChart().currentPassiveStats[(int)STATChart.ACTIVESTATS.HP]); if (character.trueSTATChart().currentPassiveStats[(int)STATChart.ACTIVESTATS.HP] == minHP) { threat = (int)((modifier) * threat); threat += 10; } break; case AIBehaviourType.Intellect_Hater: int maxINT = lbc.Max(c => c.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.INT]); if (character.trueSTATChart().currentPassiveStats[(int)STATChart.PASSIVESTATS.INT] == maxINT) { threat = (int)(modifier * threat); threat += 10; } break; default: break; } charsAndThreat.Add(new KeyValuePair <BaseCharacter, int>(character, threat)); } } else { List <BaseCharacter> charactersThatNeedHealing = lbc.FindAll(h => h.NeedsHealing()); if (charactersThatNeedHealing.Count == 0) { //FILL SUPPORTLOGIC HERE LATER foreach (var character in lbc) { charsAndThreat.Add(new KeyValuePair <BaseCharacter, int>(character, GamePlayUtility.Randomize(0, 20))); } } else { foreach (var character in charactersThatNeedHealing) { charsAndThreat.Add(new KeyValuePair <BaseCharacter, int>(character, GamePlayUtility.Randomize(character.HealingRequired, character.HealingRequired * 2))); } } } return(charsAndThreat); }