Ejemplo n.º 1
0
    private void Awake()
    {
        if ( instance == null )
            instance = this;

        moveTileHost = this.gameObject.transform.FindChild("MoveTileHost").gameObject;
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        NetUI = MultiplayerUIScript;
        Server = this;
        GameSession = new MultiplayerGameSession();
        GeneralControl = NetworkObjects.GetComponent<MultiplayerGeneralControl>();
        MultiplayerSession = GetComponent<MultiplayerPrefs>();

        NetworkObjects.SetActive(false);
        ConnectionPanel.SetActive(true);

        NetworkTransport.Init();
        ConnectionConfig cc = new ConnectionConfig();
        reliableChannel = cc.AddChannel(QosType.ReliableSequenced);
        unreliableChannel = cc.AddChannel(QosType.Unreliable);
        stateUpdateChannel = cc.AddChannel(QosType.StateUpdate);
        
        HostTopology topo = new HostTopology(cc, MAX_CONNECTION);

        hostId = NetworkTransport.AddHost(topo, port, null); 

        messageText.text = "WAITING FOR OTHER PLAYER. YOUR IP IS " + SepakNetworkUtil.GetLocalIPAddress();


        isStarted = true;


        if(MultiplayerGameSession.NumberOfPlayers == 2)
        {
            Destroy(NetworkObjects.transform.Find("player1ai1").gameObject);
            Destroy(NetworkObjects.transform.Find("player2ai1").gameObject);
        }

    }
Ejemplo n.º 3
0
 // Start is called before the first frame update
 void Start()
 {
     kickController = transform.GetComponentInChildren <PlayerKickController>();
     server         = GameObject.Find("Server").GetComponent <PlayerHost>();
     animator       = GetComponent <Animator>();
     rb             = GetComponent <Rigidbody2D>();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 重写 OnTimeout 方法处理玩家超时。
        /// </summary>
        /// <returns>用于等待处理完成的 Task 对象</returns>
        protected override Task OnTimeout()
        {
            Game.AnnounceMessage($"{PlayerName} 面临严峻的局面,陷入了深深地沉思,忽然天空中出现了一道惊雷,将其雷了个外焦里嫩。");

            HealthPoint -= 1;
            PlayerHost.WriteWarningMessage($"操作超时,生命值减少 1 点,剩余生命值: {HealthPoint}");
            return(Task.CompletedTask);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 与另一个玩家交换所有卡牌
        /// </summary>
        /// <param name="target"></param>
        internal void ExchangeCards(SimpleGamePlayer target)
        {
            DealCards();
            target.DealCards();

            var cards = target._cards;

            target._cards = cards;
            _cards        = cards;

            PlayerHost.WriteMessage("卡牌已经交换");
        }
Ejemplo n.º 6
0
    // Start is called before the first frame update
    void Start()
    {
        Ball        = this;
        CurrentDest = CurrentDestination;
        CurrentDestinationSprite = CurrentDestination.GetComponent <SpriteRenderer>();
        server        = GameObject.Find("Server").GetComponent <PlayerHost>();
        rb            = GetComponent <Rigidbody2D>();
        _initialScale = 1;

        if (MultiplayerGameSession.NumberOfPlayers == 2)
        {
            TopPlayers.RemoveAt(1);
            BottomPlayers.RemoveAt(1);
        }
    }
Ejemplo n.º 7
0
    // Start is called before the first frame update
    void Start()
    {
        P1SpecialThreshold = Player1SpecialThreshold;
        P1SpecialButton    = Player1SpecialButton;

        server = GameObject.Find("Server").GetComponent <PlayerHost>();

        playersTransform         = new List <Transform>();
        playersTransformPosition = new List <Vector3>();
        int childCount = transform.childCount;

        for (int i = 0; i < childCount; i++)
        {
            Transform t = transform.GetChild(i);
            if (t.name.Contains("player"))
            {
                playersTransform.Add(t);
                playersTransformPosition.Add(t.position);

                if (t.name.Equals("player1ai2"))
                {
                    BottomTosser = t;
                }
                else if (t.name.Equals("player2ai2"))
                {
                    TopTosser = t;
                }
                else if (t.name.Equals("player2"))
                {
                    TopServer = t;
                }
                else if (t.name.Equals("player1"))
                {
                    BottomServer = t;
                }
            }
            else if (t.name.Equals("ball"))
            {
                Ball           = t;
                BallController = t.GetComponent <SepakBall>();
            }
        }
    }
Ejemplo n.º 8
0
    // Start is called before the first frame update
    void Start()
    {
        Instance = this;
        server = GameObject.Find("Server").GetComponent<PlayerHost>();

        int count = transform.childCount;
        for (int i = 0; i < count; i++)
        {
            var gObj = transform.GetChild(i).GetComponent<ButtonHostCountrySelect>();
            var gBtn = transform.GetChild(i).GetComponent<Button>();
            gObj.DeselectPlayer1();
            gObj.DeselectPlayer2();
            gBtn.onClick.AddListener(() =>
            {
                if (!ButtonSelectCountry.interactable)
                    return;

                if(SelectedPlayer1 != null)
                {
                    SelectedPlayer1.DeselectPlayer1();                    
                }
                SelectedPlayer1 = gObj;
                gObj.SelectPlayer1();

                server.SendPlayer1Selection(gObj.name);
               // Debug.Log(gObj.name);
            });
        }

        ButtonSelectCountry.onClick.AddListener(() =>
        {
            if(PlayerHost.MultiplayerSession.P1Country != null
            && SelectedPlayer1 != null && SelectedPlayer1.gameObject.activeInHierarchy)
            {
                PlayerHost.MultiplayerSession.P1Country = SelectedPlayer1.name;
                server.Send("P1LOCKIN|" + SelectedPlayer1.name, true);
                SelectedPlayer1.gameObject.SetActive(false);
                ButtonSelectCountry.interactable = false;
                ButtonSelectCountry.transform.GetChild(0).GetComponent<Text>().text = "WAITING FOR OTHER PLAYER";
            }
        });
    }
Ejemplo n.º 9
0
        /// <summary>
        /// 移除所有效果
        /// </summary>
        /// <param name="positive">是否只移除正面效果,还是只移除负面效果,或者都移除</param>
        internal void Purify(bool?positive = null)
        {
            foreach (var effect in Effects)
            {
                if (positive == false && effect is IPositiveEffect)
                {
                    continue;
                }

                if (positive == true && effect is INagativeEffect)
                {
                    continue;
                }

                if (Effects.RemoveEffect(effect))
                {
                    PlayerHost.WriteWarningMessage("您当前的 {0} 效果已经被解除", effect.Name);
                }
            }
        }
Ejemplo n.º 10
0
        protected virtual void Dispose(bool disposing)
        {
            unexpectedTermination = false;

            if (playerHost != null)
            {
                RemotingServices.Disconnect(playerHost);
                playerHost.Dispose();
                playerHost = null;
            }
            if (disposing)
            {
                playerTask = null;
            }
            if (startHostProcessTimer != null)
            {
                startHostProcessTimer.Dispose();
            }
            if (hostProcess != null)
            {
                hostProcess.Dispose();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 重写此方法进行游戏
        /// </summary>
        /// <param name="roundEvent">玩家回合事件信息</param>
        /// <param name="token">取消标识</param>
        /// <returns>用于等待玩家操作完成的 Task 对象</returns>
        protected override async Task PlayCard(PlayerRoundEvent roundEvent, CancellationToken token)
        {
            {
                var list = secretMessages;
                secretMessages = new ConcurrentBag <GameMessage>();
                foreach (var message in list)
                {
                    PlayerHost.WriteMessage(message, true);
                }
            }

            if ((bool?)roundEvent.DataBag.Confine == true)
            {
                Game.AnnounceMessage($"只见 {PlayerName} 动弹不得,什么也做不了。");
                PlayerHost.WriteMessage("您被禁锢一回合,无法出牌");
                return;
            }

            ActionPoint = 1;
            DealCards();


            await base.PlayCard(roundEvent, token);
        }
Ejemplo n.º 12
0
 protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnDetachedFromLogicalTree(e);
     PlayerHost?.Stop();
 }
Ejemplo n.º 13
0
        public IDisposable Play(MediaStreamInfo mediaStreamInfo, IPlaybackController playbackController)
        {
            //fix url
            var url = new Uri(mediaStreamInfo.url);

            if (url == null || !url.IsAbsoluteUri)
            {
                throw new Exception("Invalid playback url");
            }
            if (mediaStreamInfo.transport != MediaStreamInfo.Transport.Http)
            {
                if (String.Compare(url.Scheme, "rtsp", true) != 0)
                {
                    throw new Exception("Invalid playback url");
                }
            }
            else if (String.Compare(url.Scheme, "rtsp", true) != 0)
            {
                int defPort;
                if (String.Compare(url.Scheme, Uri.UriSchemeHttp, true) == 0)
                {
                    defPort = 80;
                }
                else if (String.Compare(url.Scheme, Uri.UriSchemeHttps, true) == 0)
                {
                    defPort = 443;
                }
                else
                {
                    throw new Exception("Invalid playback url");
                }
                var ub = new UriBuilder(url);
                ub.Scheme = "rtsp";
                if (ub.Port == -1)
                {
                    ub.Port = defPort;
                }
                url             = ub.Uri;
                mediaStreamInfo = new MediaStreamInfo(url.ToString(), mediaStreamInfo.transport, mediaStreamInfo.userNameToken);
            }

            var disposable = new SingleAssignmentDisposable();

            playerTask.mediaStreamInfo    = mediaStreamInfo;
            playerTask.playbackController = playbackController;
            if (playerHost != null)
            {
                playerHost.Dispose();
                RemotingServices.Disconnect(playerHost);
                playerHost = null;
            }

            playerHost = new PlayerHost(playerTask);
            RemotingServices.Marshal(playerHost);
            var ipcChannel        = AppHosting.SetupChannel();
            var hostControllerUri = RemotingServices.GetObjectUri(playerHost);
            var hostControllerUrl = ipcChannel.GetUrlsForUri(hostControllerUri).First();

            //start player host process
            var hostProcessArgs = new CommandLineArgs();
            var t = Uri.EscapeDataString(hostControllerUrl);

            hostProcessArgs.Add("controller-url", new List <string> {
                hostControllerUrl
            });

            var pi = new ProcessStartInfo()
            {
                FileName        = Assembly.GetExecutingAssembly().Location,
                UseShellExecute = false,
                Arguments       = String.Join(" ", hostProcessArgs.Format()),
            };

            pi.EnvironmentVariables["PATH"] = String.Join("; ", Bootstrapper.specialFolders.dlls.Select(sfd => sfd.directory.FullName).Append(pi.EnvironmentVariables["PATH"]));

            StartHostProcess(pi);
            return(Disposable.Create(() => {
                Dispose();
            }));
        }
Ejemplo n.º 14
0
 /// <summary>
 /// 禁锢玩家一个回合
 /// </summary>
 internal void Confine()
 {
     PlayerHost.WriteWarningMessage("您被禁锢一个回合");
     SetEffect(new ConfineEffect());
 }
Ejemplo n.º 15
0
 // Start is called before the first frame update
 void Start()
 {
     server = GameObject.Find("Server").GetComponent <PlayerHost>();
 }
Ejemplo n.º 16
0
 private void Stop()
 {
     PlayerHost.Stop();
     StopCommandExecuted?.Invoke(this, new EventArgs());
 }
Ejemplo n.º 17
0
		protected virtual void Dispose(bool disposing) {
			unexpectedTermination = false;

			if (playerHost != null) {
				RemotingServices.Disconnect(playerHost);
				playerHost.Dispose();
				playerHost = null;
			}
			if (disposing) {
				playerTask = null;
			}
			if (startHostProcessTimer != null)
				startHostProcessTimer.Dispose();
			if (hostProcess != null)
				hostProcess.Dispose();
		}
Ejemplo n.º 18
0
		public IDisposable Play(MediaStreamInfo mediaStreamInfo, IPlaybackController playbackController) {
			//fix url
			var url = new Uri(mediaStreamInfo.url);
			if (url == null || !url.IsAbsoluteUri) {
				throw new Exception("Invalid playback url");
			}
			if (mediaStreamInfo.transport != MediaStreamInfo.Transport.Http) {
				if (String.Compare(url.Scheme, "rtsp", true) != 0) {
					throw new Exception("Invalid playback url");
				}
			} else if (String.Compare(url.Scheme, "rtsp", true) != 0) {
				int defPort;
				if (String.Compare(url.Scheme, Uri.UriSchemeHttp, true) == 0) {
					defPort = 80;
				} else if (String.Compare(url.Scheme, Uri.UriSchemeHttps, true) == 0) {
					defPort = 443;
				} else {
					throw new Exception("Invalid playback url");
				}
				var ub = new UriBuilder(url);
				ub.Scheme = "rtsp";
				if (ub.Port == -1) {
					ub.Port = defPort;
				}
				url = ub.Uri;
				mediaStreamInfo = new MediaStreamInfo(url.ToString(), mediaStreamInfo.transport, mediaStreamInfo.userNameToken);
			}

			var disposable = new SingleAssignmentDisposable();
			playerTask.mediaStreamInfo = mediaStreamInfo;
			playerTask.playbackController = playbackController;
			if (playerHost != null) {
				playerHost.Dispose();
				RemotingServices.Disconnect(playerHost);
				playerHost = null;
			}

			playerHost = new PlayerHost(playerTask);
			RemotingServices.Marshal(playerHost);
			var ipcChannel = AppHosting.SetupChannel();
			var hostControllerUri = RemotingServices.GetObjectUri(playerHost);
			var hostControllerUrl = ipcChannel.GetUrlsForUri(hostControllerUri).First();

			//start player host process
			var hostProcessArgs = new CommandLineArgs();
			var t = Uri.EscapeDataString(hostControllerUrl);
			hostProcessArgs.Add("controller-url", new List<string> { hostControllerUrl });

			var pi = new ProcessStartInfo() {
				FileName = Assembly.GetExecutingAssembly().Location,
				UseShellExecute = false,
				Arguments = String.Join(" ", hostProcessArgs.Format()),
			};
			pi.EnvironmentVariables["PATH"] = String.Join("; ", Bootstrapper.specialFolders.dlls.Select(sfd => sfd.directory.FullName).Append(pi.EnvironmentVariables["PATH"]));

			StartHostProcess(pi);
			return Disposable.Create(() => {
				Dispose();
			});
		}
Ejemplo n.º 19
0
 /// <summary>
 /// 派生类重写此方法处理玩家操作超时。
 /// </summary>
 /// <returns>用于等待处理完成的 Task 对象</returns>
 protected virtual Task OnTimeout()
 {
     PlayerHost.WriteWarningMessage("操作超时。");
     Game.AnnounceMessage($"玩家 {PlayerName} 操作超时");
     return(Task.CompletedTask);
 }