Inheritance: InputManager
Beispiel #1
0
 public static Strategy[] GetStandardSet(int aiId, AIInputManager inputManager)
 {
     return(new Strategy[] {
         new StayOnStage(aiId, inputManager),
         new Wander(aiId, inputManager)
     });
 }
Beispiel #2
0
        void AddAI(GameObject player, AIInputManager inputManager, int level)
        {
            AIBase ai;

            if (level == 1)
            {
                ai = player.AddComponent <DumbAI>();
            }
            else if (level == 2)
            {
                ai = player.AddComponent <StrategyAI>();
            }
            else if (level == 3)
            {
                if (s2ai == null)
                {
                    InitS2();
                }
                return;
            }
            else
            {
                throw new System.ArgumentOutOfRangeException("level");
            }
            ai.inputManager = inputManager;
        }
Beispiel #3
0
 public Wander(int aiId, AIInputManager inputManager)
     : base(aiId, ActionGroup.Movement, inputManager)
 {
     // To start, we don't want to just stand still.
     // Initialized in main thread, so this is ok.
     if (UnityEngine.Random.value < .5f)
     {
         direction = Direction.Left;
     }
     else
     {
         direction = Direction.Right;
     }
 }
Beispiel #4
0
        public void TestStayOnStage()
        {
            var ai          = new S2AI(2, 1);
            var inp         = new AIInputManager();
            var keepWalking = new KeepWalking(0, inp);

            Strategy[] strategies =
            {
                new StayOnStage(0, inp),
                keepWalking
            };
            var player = new DummyPlayerSnapshotProvider();
            var env    = new AIEnvironment(
                new [] { 0 },
                new DummyGameSnapshotProvider(),
                new DummyStageSnapshotProvider(20),
                new [] { player }
                );

            ai.Ready(env, strategies);
            ai.BeginEvaluate();
            float min = 0, max = 0;

            for (int i = 0; i < 30; i++)
            {
                ai.ExecAndMoveNext();
                if (inp.IsControlActive(Control.Left))
                {
                    player.Move(-1);
                    keepWalking.direction = Control.Left;
                }
                else if (inp.IsControlActive(Control.Right))
                {
                    player.Move(1);
                    keepWalking.direction = Control.Right;
                }
                if (player.x < min)
                {
                    min = player.x;
                }
                if (player.x > max)
                {
                    max = player.x;
                }
                Thread.Sleep(25);
            }
            ai.Dispose();
            Debug.Assert(min <-7f && max> 7f);
        }
Beispiel #5
0
 public StayOnStage(int aiId, AIInputManager inputManager)
     : base(aiId, ActionGroup.Movement, inputManager)
 {
 }
Beispiel #6
0
        /// Initialize fields that other objects depend on.
        void Awake()
        {
            stateChangeListenerFactory = new StateChangeListenerFactory();
#if UNITY_EDITOR
            playDataLogger = new PlayDataLogger(Application.streamingAssetsPath + "/pdl.txt");
            stateChangeListenerFactory.Add(playDataLogger);
#endif
            sPlayerData = new List <ServerPlayerData>();
            Layers.Init();
            PlayersInitialized += players => {
                var aiStrategies = new List <Strategy>();
                var aiPlayerIds  = new List <int>();

                FindObjectOfType <EnableUI>().Enable();

                foreach (var player in players)
                {
                    IInputManager playerInputManager;
                    if (isClient && player.eId == cPlayerId)
                    {
                        playerInputManager = GetComponent <InputManager>();
                    }
                    else if (isServer && sPlayerData[player.eId].aiLevel > 0)
                    {
                        var aiim = new AIInputManager();
                        // TODO: Redo this function for S2AI.
                        AddAI(player.gameObject, aiim, sPlayerData[player.eId].aiLevel);
                        playerInputManager = aiim;

                        if (sPlayerData[player.eId].aiLevel == 3)
                        {
                            var aiCount = aiPlayerIds.Count;
                            var set     = StrategySets.GetStandardSet(aiCount, aiim);
                            aiStrategies.AddRange(set);
                            aiPlayerIds.Add(player.eId);
                        }
                    }
                    else
                    {
                        playerInputManager = NullInputManager.Instance;
                    }
                    player.GameControllerReady(this, playerInputManager);
                }

                if (s2ai != null)
                {
                    var env = new AIEnvironment(aiPlayerIds, this, this, players);
                    s2ai.Ready(env, aiStrategies);
                }
            };

            GameStarted += () => {
                foreach (var data in sPlayerData)
                {
                    var player = data.player;
                    player.RemoveModifier(ModId.CantAttack);
                    player.RemoveModifier(ModId.CantMove);
                    if (player.isLocalPlayer)
                    {
                        FindObjectOfType <CameraScroll>().playerToFollow = player;
                    }
                }
                if (s2ai != null)
                {
                    s2ai.BeginEvaluate();
                }
            };

            if (TransitionParams.gameType == GameType.Single)
            {
                spawnPrefabList = new JitList <GameObject>();
            }
            else
            {
                spawnPrefabList = NetworkManager.singleton.spawnPrefabs;
            }
            gameObjectPool = new GameObjectPool();

            Instance = this;
        }
Beispiel #7
0
 /// <param name="aiId">Provided by `GameController`.</param>
 /// <param name="actionGroupMask">
 ///   Only the lowest bit is considered currently.
 /// </param>
 public Strategy(int aiId, uint actionGroupMask, AIInputManager inputManager)
 {
     this.aiId            = aiId;
     this.actionGroupMask = actionGroupMask;
     this.inputManager    = inputManager;
 }
Beispiel #8
0
 public KeepWalking(int aiIndex, AIInputManager inputManager)
     : base(aiIndex, ActionGroup.Movement, inputManager)
 {
 }