Esempio n. 1
0
        //Create a new enemy instance
        private void CreateEnemyInstance(string id)
        {
            if (id.Equals(NakamaServer.GetUserId()))
            {
                return;
            }
            var enemyInstance = (Enemy)EnemyScene.Instance();

            enemyInstance.Id = id;
            GetNode <Node2D>("Enemies").AddChild(enemyInstance);
        }
Esempio n. 2
0
        protected virtual async void UpdatePosition(Vector2 targetPosition)
        {
            Tween.InterpolateProperty(this, "position", Position, targetPosition, 0.5f);
            Tween.Start();
            var userPosition = new Dictionary <string, Vector2>
            {
                { Id, targetPosition }
            };

            var state = JsonConvert.SerializeObject(userPosition);

            await NakamaServer.SendMatchStateAsync(Controller.MatchId, 1, state);
        }
Esempio n. 3
0
        public override async void _Ready()
        {
            NakamaServer.InitNakamaClient(Host, Key);

            //Signals
            NakamaServer.Connected              += () => GetNode <Player>("Player").Id = NakamaServer.GetUserId();
            NakamaServer.MatchStateReceived     += NakamaServerOnMatchStateReceived;
            NakamaServer.ChannelMessageReceived += message => GD.Print(message.Content);
            NakamaServer.MatchPresenceReceived  += NakamaServerOnMatchPresenceReceived;


            await NakamaServer.AuthenticateAsync("*****@*****.**", "password");

            await NakamaServer.OpenConnectionAsync();

            //Join Match
            var initMatchRpc = await NakamaServer.CallRpcAsync("init_matches");

            GD.Print(initMatchRpc.Payload);

            var twoMatchRpc = await NakamaServer.CallRpcAsync("two_match");

            var twoMatch = await NakamaServer.JoinMatchAsync(twoMatchRpc.Payload);

            foreach (var presence in twoMatch.Presences)
            {
                if (presence.UserId.Equals(GetNode <Player>("Player").Id))
                {
                    return;
                }
                CreateEnemyInstance(presence.UserId);
            }
            MatchId = twoMatchRpc.Payload;

            #region Commented

            ////Send Match State
            //await NakamaServer.SendMatchStateAsync(twoMatch.Id, 1, "{\"Two Match\" : \"50,10\"}");

            ////Chat
            //await NakamaServer.JoinChatAsync("1vs1");
            //await NakamaServer.SendChatMsgAsync("1vs1" , "{\"msg\" : \"Hi\"}");



            ////Storage
            //await NakamaServer.StorageWriteAsync(new IApiWriteStorageObject[]{new WriteStorageObject()
            //{
            //    Collection = "Scores",
            //    Key = "1vs1",
            //    PermissionRead = (int) NakamaServer.ReadPermission.OwnerRead,
            //    PermissionWrite = (int) NakamaServer.WritePermission.OwnerWrite,
            //    Value = "{ \"Score\": 27 }",
            //    Version = ""
            //}});

            //var storageReadResult = await NakamaServer.StorageReadAsync(new IApiReadStorageObjectId[] {new StorageObjectId()
            //{
            //    Collection = "Scores",
            //    Key = "1vs1",
            //    UserId = NakamaServer.NakamaSession.UserId,
            //    Version = ""
            //}});
            //foreach (var storageObject in storageReadResult.Objects)
            //{
            //    GD.Print(storageObject.Value);
            //}

            ////Matchmaker
            //var matchmakerProperties = new MatchmakerProperties();
            //await NakamaServer.CreateMatchmakerAsync(matchmakerProperties); // Returns a ticket



            //NakamaServer.MatchmakerMatched += async matched =>
            //{
            //    GD.Print("This Is From matchmaker matched status");
            //    var matchmakerMatch = await NakamaServer.JoinMatchAsync(matched);
            //    await NakamaServer.SendMatchStateAsync(matchmakerMatch.Id, 2, "{\"Another World\":\"Cyprus Match\"}");
            //};
            #endregion
        }