protected override void OnUpdate()
        {
            for (var i = 0; i < createPlayerData.Length; i++)
            {
                var requests   = createPlayerData.CreatePlayerRequests[i].Requests;
                var responders = createPlayerData.CreatePlayerResponders[i].ResponsesToSend;

                foreach (var request in requests)
                {
                    if (PlayerLifecycleConfig.CreatePlayerEntityTemplate == null)
                    {
                        throw new InvalidOperationException(Errors.PlayerEntityTemplateNotFound);
                    }

                    var playerEntity = PlayerLifecycleConfig.CreatePlayerEntityTemplate(request.CallerAttributeSet,
                                                                                        request.Payload.Position);
                    createPlayerData.CreateEntitySender[i].RequestsToSend.Add(new WorldCommands.CreateEntity.Request
                    {
                        Entity = playerEntity
                    });

                    responders.Add(
                        PlayerCreator.CreatePlayer.Response.CreateResponse(request, new CreatePlayerResponseType()));
                }
            }
        }
Esempio n. 2
0
        protected override void OnUpdate()
        {
            for (var i = 0; i < createPlayerData.Length; i++)
            {
                var requests           = createPlayerData.CreatePlayerRequests[i].Requests;
                var createEntitySender = createPlayerData.CreateEntitySender[i];

                foreach (var request in requests)
                {
                    if (PlayerLifecycleConfig.CreatePlayerEntityTemplate == null)
                    {
                        throw new InvalidOperationException(Errors.PlayerEntityTemplateNotFound);
                    }

                    var playerEntity = PlayerLifecycleConfig.CreatePlayerEntityTemplate(request.CallerAttributeSet,
                                                                                        request.Payload.Position);
                    createEntitySender.RequestsToSend.Add(WorldCommands.CreateEntity.CreateRequest
                                                          (
                                                              playerEntity,
                                                              context: new PlayerCreationRequestContext
                    {
                        createPlayerRequest = request
                    }
                                                          ));
                }
            }

            for (var i = 0; i < entityCreationResponseData.Length; ++i)
            {
                var entityCreationResponses = entityCreationResponseData.CreateEntityResponses[i];
                var responder = entityCreationResponseData.CreatePlayerResponders[i];

                foreach (var receivedResponse in entityCreationResponses.Responses)
                {
                    if (!(receivedResponse.Context is PlayerCreationRequestContext requestContext))
                    {
                        // Ignore non-player entity creation requests
                        continue;
                    }

                    var op = receivedResponse.Op;

                    if (op.StatusCode != StatusCode.Success || !op.EntityId.HasValue)
                    {
                        responder.ResponsesToSend.Add(PlayerCreator.CreatePlayer
                                                      .CreateResponseFailure(requestContext.createPlayerRequest,
                                                                             $"Failed to create player: \"{op.Message}\""));

                        continue;
                    }

                    responder.ResponsesToSend.Add(PlayerCreator.CreatePlayer
                                                  .CreateResponse(requestContext.createPlayerRequest, new CreatePlayerResponseType
                    {
                        CreatedEntityId = op.EntityId.Value
                    }));
                }
            }
        }
Esempio n. 3
0
        protected override void OnUpdate()
        {
            for (var i = 0; i < data.Length; i++)
            {
                var requests = data.CreatePlayerRequests[i].Buffer;

                foreach (var request in requests)
                {
                    if (PlayerLifecycleConfig.CreatePlayerEntityTemplate == null)
                    {
                        throw new InvalidOperationException(Errors.PlayerEntityTemplateNotFound);
                    }

                    var playerEntity = PlayerLifecycleConfig.CreatePlayerEntityTemplate(request.CallerAttributeSet,
                                                                                        request.RawRequest.Position);
                    data.WorldCommandSenders[i].SendCreateEntityRequest(playerEntity);
                }
            }
        }