public AIPlayer CreateAIPlayer(GameEnums.EGameDifficultyMode difficultyMode, string name, Color color) { IAIBehaviour tier1AI = AIFactory.CreateInstance(m_DifficultyToAlgorithmMap[difficultyMode].tier1Algorithm); IAIBehaviour tier2AI = AIFactory.CreateInstance(m_DifficultyToAlgorithmMap[difficultyMode].tier2Algorithm); return(NonMonoObjectFactory <AIPlayer> .CreateInstance(() => new AIPlayer(name, color, GameEnums.EPlayerType.PLAYER_AI, tier1AI, tier2AI))); }
public void ChangeAI(IAIBehaviour ai) { if (ai != null) { unitAI = ai; } }
private static void ProcessCreatureAI(ref HashSet <NWCreature> creatures) { // Iterate backwards so we can remove the creature if it's no longer valid. for (int x = creatures.Count - 1; x >= 0; x--) { NWCreature creature = creatures.ElementAt(x); NWArea area = creature.Area; bool areaHasPCs = NWModule.Get().Players.Count(p => p.Area.Resref == area.Resref) > 0; // Is this creature invalid or dead? If so, remove it and move to the next one. if (!creature.IsValid || creature.IsDead) { creatures.Remove(creature); continue; } // Are there no players in the area? Is the creature being possessed? If so, don't execute AI this frame. Move to the next one. if (creature.IsPossessedFamiliar || creature.IsDMPossessed || !areaHasPCs) { continue; } string script = GetBehaviourScript(creature); if (string.IsNullOrWhiteSpace(script)) { continue; } IAIBehaviour behaviour = GetAIBehaviour(script); behaviour.OnProcessObject(creature); } }
private IAIBehaviour GetOrCreateAI(string type) { if (type.Equals(string.Empty, StringComparison.Ordinal)) { return(null); } if (_behaviourInstance != null && _behaviourInstance.GetType().Name.Split('.').Last() .Equals(type, StringComparison.Ordinal)) { return(_behaviourInstance); } Type t = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()).Where(p => typeof(IAIBehaviour).IsAssignableFrom(p) && p.IsClass) .FirstOrDefault(p => p.Name.Split('.').Last().Equals(type, StringComparison.Ordinal)); if (t == null) { Debug.LogError( $"[AI BEHAVIOUR ROOT] Cannot create {type} type behaviour class! Aborting AI composition"); behaviourType = ""; return(null); } _behaviourInstance = Activator.CreateInstance(t) as IAIBehaviour; return(_behaviourInstance); }
public void InitMinerBehaviour() { var viewReciver = GetComponent <UnitViewReciver>(); behaviour = new MinerBehaviour(); Container.Inject(behaviour); behaviour.Init(viewReciver.pysicItem, View); }
public static void RegisterAIBehaviour(MobileParty mb, IAIBehaviour behaviour) { if (!partyBehaviours.ContainsKey(mb)) { partyBehaviours.Add(mb, new List <IAIBehaviour>()); } partyBehaviours[mb].Add(behaviour); }
public bool IsCompatible(IAIBehaviour AIBehaviour, bool secondCall) { if (AIBehaviour is AttackClosestIfIdleForADayBehaviour) { return(false); } return(secondCall ? true : AIBehaviour.IsCompatible(this, true)); }
public bool IsCompatible(IAIBehaviour AIBehaviour, bool secondCall) { if (AIBehaviour is PatrolAroundClosestLestInterruptedAndSwitchBehaviour || AIBehaviour is HourlyPatrolAroundSpawnBehaviour) { return(false); } return(secondCall? true : AIBehaviour.IsCompatible(this, true)); }
public void Initialize(Action <GameObject> deathCallback) { this.deathCallback = deathCallback; Stat.Initialize(); MyEffectManager.UseTextEffect(); Dropper.Initialize(transform.parent, Stat.CurrentData.DropItemDatas, Stat.CurrentData.GoldData); PanelController.Initialize(); InitializeAttackSystems(); currentAI = GetComponent <IAIBehaviour>(); currentAI.Initialize(); }
private static void OnCreatureSpellCastAt() { string script = GetBehaviourScript(Object.OBJECT_SELF); if (string.IsNullOrWhiteSpace(script)) { return; } IAIBehaviour behaviour = GetAIBehaviour(script); behaviour.OnSpellCastAt(Object.OBJECT_SELF); }
private static void OnCreatureRested() { string script = GetBehaviourScript(NWGameObject.OBJECT_SELF); if (string.IsNullOrWhiteSpace(script)) { return; } IAIBehaviour behaviour = GetAIBehaviour(script); behaviour.OnRested(NWGameObject.OBJECT_SELF); }
private static void OnCreaturePhysicalAttacked() { string script = GetBehaviourScript(Object.OBJECT_SELF); if (string.IsNullOrWhiteSpace(script)) { return; } IAIBehaviour behaviour = GetAIBehaviour(script); behaviour.OnPhysicalAttacked(Object.OBJECT_SELF); }
private static void OnCreatureUserDefined() { string script = GetBehaviourScript(OBJECT_SELF); if (string.IsNullOrWhiteSpace(script)) { return; } IAIBehaviour behaviour = GetAIBehaviour(script); behaviour.OnUserDefined(OBJECT_SELF); }
private static void OnCreatureCombatRoundEnd() { NWCreature self = OBJECT_SELF; WeatherService.OnCombatRoundEnd(self); string script = GetBehaviourScript(OBJECT_SELF); if (string.IsNullOrWhiteSpace(script)) { return; } IAIBehaviour behaviour = GetAIBehaviour(script); behaviour.OnCombatRoundEnd(OBJECT_SELF); }
private static void RegisterAIBehaviours() { // Use reflection to get all of AI behaviour implementations. var classes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => typeof(IAIBehaviour).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract).ToArray(); foreach (var type in classes) { IAIBehaviour instance = Activator.CreateInstance(type) as IAIBehaviour; if (instance == null) { throw new NullReferenceException("Unable to activate instance of type: " + type); } _aiBehaviours.Add(type.Name, instance); } }
public void SpawnCreature(AIType aType, int aNum) { if (m_AIs == null) { m_AIs = new List <IAIBehaviour>(); } for (int i = 0; i < aNum; ++i) { GameObject gO = null; switch (aType) { case AIType.FLOATY_FRED: gO = Instantiate(m_FloaterPrefab); break; case AIType.SUICIDE_SAM: gO = Instantiate(m_RunnerPrefab); break; default: Debug.Log("BAD AITYPE, " + aType + ", creature not spawned"); return; } IAIBehaviour aIBehaviour = gO.GetComponent(typeof(IAIBehaviour)) as IAIBehaviour; //Object test = aIBehaviour as Object; if (aIBehaviour == null) { Debug.Log("creature not spawned with IAIBehaviour interface"); return; } if (m_AIs == null) { Debug.Log("list null!?"); return; } m_AIs.Add(aIBehaviour); aIBehaviour.AssignPlayerReference(m_GameController.GetPlayerReference()); aIBehaviour.Reset(); } }
private static void OnCreatureDeath() { NWCreature self = OBJECT_SELF; // Remove any custom object data from the cache. if (AppCache.CustomObjectData.ContainsKey(self.GlobalID)) { AppCache.CustomObjectData.Remove(self.GlobalID); } string script = GetBehaviourScript(OBJECT_SELF); if (string.IsNullOrWhiteSpace(script)) { return; } IAIBehaviour behaviour = GetAIBehaviour(script); behaviour.OnDeath(OBJECT_SELF); }
// Use this for initialization void Start() { foreach (MonoBehaviour mb in GetComponents <MonoBehaviour>()) { if (mb is IAIBehaviour && mb != null) { unitAI = (IAIBehaviour)mb; } } if (team != UnitManager.PLAYER_TEAM) { if (unitAI == null) { unitAI = gameObject.AddComponent <Defensive>(); } AIManager.Instance.AddUnit(this); } // gimme manna plox if (GetComponent <Mana>() == null) { gameObject.AddComponent <Mana>(); } }
public AIPlayer(string name, Color color, GameEnums.EPlayerType playerType, IAIBehaviour tier1AI, IAIBehaviour tier2AI) : base(name, color, playerType) { m_Tier1AI = tier1AI; m_Tier2AI = tier2AI; }
private static void OnCreatureSpawn() { NWCreature self = OBJECT_SELF; // Don't modify AI behaviour for DM-spawned creatures. if (GetLocalBool(self, "DM_SPAWNED") == true) { return; } string script = GetBehaviourScript(OBJECT_SELF); if (string.IsNullOrWhiteSpace(script)) { return; } IAIBehaviour ai = GetAIBehaviour(script); if (ai.IgnoreNWNEvents) { self.SetLocalInt("IGNORE_NWN_EVENTS", 1); } if (ai.IgnoreOnBlocked) { self.SetLocalInt("IGNORE_NWN_ON_BLOCKED_EVENT", 1); } if (ai.IgnoreOnCombatRoundEnd) { self.SetLocalInt("IGNORE_NWN_ON_COMBAT_ROUND_END_EVENT", 1); } if (ai.IgnoreOnConversation) { self.SetLocalInt("IGNORE_NWN_ON_CONVERSATION_EVENT", 1); } if (ai.IgnoreOnDamaged) { self.SetLocalInt("IGNORE_NWN_ON_DAMAGED_EVENT", 1); } if (ai.IgnoreOnDeath) { self.SetLocalInt("IGNORE_NWN_ON_DEATH_EVENT", 1); } if (ai.IgnoreOnDisturbed) { self.SetLocalInt("IGNORE_NWN_ON_DISTURBED_EVENT", 1); } if (ai.IgnoreOnHeartbeat) { self.SetLocalInt("IGNORE_NWN_ON_HEARTBEAT_EVENT", 1); } if (ai.IgnoreOnPerception) { self.SetLocalInt("IGNORE_NWN_ON_PERCEPTION_EVENT", 1); } if (ai.IgnoreOnPhysicalAttacked) { self.SetLocalInt("IGNORE_NWN_ON_PHYSICAL_ATTACKED_EVENT", 1); } if (ai.IgnoreOnRested) { self.SetLocalInt("IGNORE_NWN_ON_RESTED_EVENT", 1); } if (ai.IgnoreOnSpawn) { self.SetLocalInt("IGNORE_NWN_ON_SPAWN_EVENT", 1); } if (ai.IgnoreOnSpellCastAt) { self.SetLocalInt("IGNORE_NWN_ON_SPELL_CAST_AT_EVENT", 1); } if (ai.IgnoreOnUserDefined) { self.SetLocalInt("IGNORE_NWN_ON_USER_DEFINED_EVENT", 1); } _areaAICreatures[self.Area].Add(self); ai.OnSpawn(self); }
public void SetAIBehaviour(IAIBehaviour behaviour) { _behaviour = behaviour; }
void Awake() { behaviourTree = BehaviourDefinition.Build <Gatherer>(); behaviourTreeState = behaviourTree.Initialize(ref agent); }
void Awake() { // We need to create an FSM based on the graph definition. And initialize the state for the agent. fsm = BehaviourDefinition.Build <Gatherer>(); fsmRuntimeState = fsm.Initialize(ref agent); }