public RemoteHostBotController(BotEntity botEntityPrefab, TileMapInfo tileMapInfo, BulletEntity bulletPrefab,
                                       SoundManager soundManager, GameSignalingClient gameSignalingClient,
                                       MeleeAttackEntity meleeAttackEntity, EventSystemWatcher eventSystemWatcher)
        {
            var botEntity = Object.Instantiate(botEntityPrefab);

            tileMapInfo.EnemyTankTransform = botEntity.transform;
            botEntity.gameObject.layer     = LayerMask.NameToLayer("EnemyBot");
            botEntity.transform.position   = tileMapInfo.GetPlayer1StartPosition();
            var botEntityAnimation = botEntity.GetComponent <BotEntityAnimation>();
            MeleeAttackApplication meleeAttackApplication = new MeleeAttackApplication(meleeAttackEntity, soundManager);
            var gun = new Gun(
                soundManager,
                new BulletEntityCreator(bulletPrefab, LayerMask.NameToLayer("EnemyBullet")),
                true
                );

            botApplication = new BotApplication.BotApplication(
                botEntity, botEntityAnimation, tileMapInfo, eventSystemWatcher, gun,
                meleeAttackApplication, true
                );

            gameSignalingClient.ReceivedClientReceiveSignalData += data =>
            {
                if (data.commandApplyTarget == MatchType.Host)
                {
                    new BotCommandsTransformerService().FromCommandData(data.commandData, botApplication);
                }
            };
        }
 public ClientBotCommandsHook(IBotCommands botCommands, GameSignalingClient gameSignalingClient)
 {
     this.botCommands         = botCommands;
     this.gameSignalingClient = gameSignalingClient;
     gameSignalingClient.ReceivedClientReceiveSignalData += data =>
     {
         if (data.commandApplyTarget == MatchType.Host)
         {
             return;
         }
         if (semaphores.TryRemove(data.commandData.id, out var semaphore))
         {
             semaphore.Release();
         }
     };
 }
        public ClientBotController(BotEntity botEntityPrefab, TileMapInfo tileMapInfo, BulletEntity bulletPrefab,
                                   CameraFollower cameraFollower, PlayerHpPresenter playerHpPresenter, RunButtonEvent runButtonEvent,
                                   ScriptText scriptText, ErrorMsg errorMsg, SoundManager soundManager,
                                   GameSignalingClient gameSignalingClient,
                                   MeleeAttackEntity meleeAttackEntity, ProcessScrollViewPresenter processScrollViewPresenter,
                                   EventSystemWatcher eventSystemWatcher)
        {
            this.errorMsg          = errorMsg;
            this.playerHpPresenter = playerHpPresenter;
            var botEntity = Object.Instantiate(botEntityPrefab);

            tileMapInfo.PlayerTankTransform = botEntity.transform;
            botEntity.gameObject.layer      = LayerMask.NameToLayer("PlayerBot");
            cameraFollower.SetPlayerPosition(botEntity.transform);
            var botEntityAnimation = botEntity.GetComponent <BotEntityAnimation>();

            botEntity.transform.position = tileMapInfo.GetPlayer2StartPosition();
            MeleeAttackApplication meleeAttackApplication = new MeleeAttackApplication(meleeAttackEntity, soundManager);
            var gun = new Gun(
                soundManager,
                new BulletEntityCreator(bulletPrefab, LayerMask.NameToLayer("PlayerBullet")),
                false
                );

            botApplication = new BotApplication.BotApplication(
                botEntity, botEntityAnimation, tileMapInfo, eventSystemWatcher, gun,
                meleeAttackApplication, true
                );
            var hookBotApplication = new ClientBotCommandsHook(botApplication, gameSignalingClient);

            javaScriptEngine = new JavaScriptEngine.JavaScriptEngine(hookBotApplication);
            runButtonEvent.AddClickEvent(async() =>
            {
                var tokenSource = new CancellationTokenSource();
                var token       = tokenSource.Token;
                var panel       =
                    processScrollViewPresenter.AddProcessPanel(
                        () => { tokenSource.Cancel(); });
                var task = javaScriptEngine.ExecuteJS(scriptText.GetScriptText(), token, panel.ProcessId);
                await task;
                panel.Dispose();
            });
        }
Beispiel #4
0
        public ClientMultiPlayGame(PlayGameInitData playGameInitData, MultiGameInfo multiGameInfo)
        {
            gameSignalingClient = new GameSignalingClient(multiGameInfo.myTcpClient);
            gameSignalingClient.ReceivedBattleResult += CheckDeath;

            var playerMeleeAttackEntity = Object.Instantiate(playGameInitData.meleeAttackPrefab);

            playerMeleeAttackEntity.gameObject.layer = LayerMask.NameToLayer("PlayerBullet");

            var enemyMeleeAttackEntity = Object.Instantiate(playGameInitData.meleeAttackPrefab);

            enemyMeleeAttackEntity.gameObject.layer = LayerMask.NameToLayer("EnemyBullet");

            playerBotController = new ClientBotController(
                playGameInitData.botEntityPrefab2P,
                playGameInitData.tileMapInfo,
                playGameInitData.bulletPrefab,
                playGameInitData.cameraFollower,
                playGameInitData.playerHpPresenter,
                playGameInitData.runButtonEvent,
                playGameInitData.scriptText,
                playGameInitData.errorMsg,
                playGameInitData.soundManager,
                gameSignalingClient,
                playerMeleeAttackEntity,
                playGameInitData.processScrollViewPresenter,
                playGameInitData.eventSystemWatcher
                );
            enemyBotController = new RemoteHostBotController(
                playGameInitData.botEntityPrefab,
                playGameInitData.tileMapInfo,
                playGameInitData.bulletPrefab,
                playGameInitData.soundManager,
                gameSignalingClient,
                enemyMeleeAttackEntity,
                playGameInitData.eventSystemWatcher
                );
            gameSignalingClient.ReceivedClientPos += playerBotController.SetPos;
            gameSignalingClient.ReceivedHostPos   += enemyBotController.SetPos;
        }
Beispiel #5
0
 void CreateGameSignaling(MyTcpClient myTcpClient, MatchType matchType)
 {
     if (MatchType.Client == matchType)
     {
         matchedClientFlag   = true;
         gameSignalingClient = new GameSignalingClient(myTcpClient);
         gameSignalingClient.ReceivedClientReceiveSignalData += (obj) =>
         {
             //   Debug.Log("ClientReceived:" + Enum.GetName(typeof(BattleResult), obj.battleResult));
             //   Debug.Log("ClientReceived:" + Enum.GetName(typeof(CommandKind), obj.commandData.kind));
         };
     }
     else
     {
         matchedHostFlag   = true;
         gameSignalingHost = new GameSignalingHost(myTcpClient, StageKind.Stage1);
         gameSignalingHost.ReceivedHostReceiveSignalData += (obj) =>
         {
             //  Debug.Log("HostReceived:" + Enum.GetName(typeof(CommandKind), obj.clientCommandData.kind));
         };
     }
 }