Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
 public void ChangeAI(IAIBehaviour ai)
 {
     if (ai != null)
     {
         unitAI = ai;
     }
 }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
    public void InitMinerBehaviour()
    {
        var viewReciver = GetComponent <UnitViewReciver>();

        behaviour = new MinerBehaviour();
        Container.Inject(behaviour);
        behaviour.Init(viewReciver.pysicItem, View);
    }
Ejemplo n.º 6
0
 public static void RegisterAIBehaviour(MobileParty mb, IAIBehaviour behaviour)
 {
     if (!partyBehaviours.ContainsKey(mb))
     {
         partyBehaviours.Add(mb, new List <IAIBehaviour>());
     }
     partyBehaviours[mb].Add(behaviour);
 }
Ejemplo n.º 7
0
 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));
 }
Ejemplo n.º 9
0
    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();
    }
Ejemplo n.º 10
0
        private static void OnCreatureSpellCastAt()
        {
            string script = GetBehaviourScript(Object.OBJECT_SELF);

            if (string.IsNullOrWhiteSpace(script))
            {
                return;
            }
            IAIBehaviour behaviour = GetAIBehaviour(script);

            behaviour.OnSpellCastAt(Object.OBJECT_SELF);
        }
Ejemplo n.º 11
0
        private static void OnCreatureRested()
        {
            string script = GetBehaviourScript(NWGameObject.OBJECT_SELF);

            if (string.IsNullOrWhiteSpace(script))
            {
                return;
            }
            IAIBehaviour behaviour = GetAIBehaviour(script);

            behaviour.OnRested(NWGameObject.OBJECT_SELF);
        }
Ejemplo n.º 12
0
        private static void OnCreaturePhysicalAttacked()
        {
            string script = GetBehaviourScript(Object.OBJECT_SELF);

            if (string.IsNullOrWhiteSpace(script))
            {
                return;
            }
            IAIBehaviour behaviour = GetAIBehaviour(script);

            behaviour.OnPhysicalAttacked(Object.OBJECT_SELF);
        }
Ejemplo n.º 13
0
        private static void OnCreatureUserDefined()
        {
            string script = GetBehaviourScript(OBJECT_SELF);

            if (string.IsNullOrWhiteSpace(script))
            {
                return;
            }
            IAIBehaviour behaviour = GetAIBehaviour(script);

            behaviour.OnUserDefined(OBJECT_SELF);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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);
            }
        }
Ejemplo n.º 16
0
    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();
        }
    }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
 // 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>();
     }
 }
Ejemplo n.º 19
0
 public AIPlayer(string name, Color color, GameEnums.EPlayerType playerType, IAIBehaviour tier1AI, IAIBehaviour tier2AI) :
     base(name, color, playerType)
 {
     m_Tier1AI = tier1AI;
     m_Tier2AI = tier2AI;
 }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
 public void SetAIBehaviour(IAIBehaviour behaviour)
 {
     _behaviour = behaviour;
 }
Ejemplo n.º 22
0
 void Awake()
 {
     behaviourTree      = BehaviourDefinition.Build <Gatherer>();
     behaviourTreeState = behaviourTree.Initialize(ref agent);
 }
Ejemplo n.º 23
0
 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);
 }