public NetworkObjectVisibilityChangeEventPayload Build([NotNull] IReadOnlyCollection <NetworkEntityGuid> joining, [NotNull] IReadOnlyCollection <NetworkEntityGuid> leaving) { if (joining == null) { throw new ArgumentNullException(nameof(joining)); } if (leaving == null) { throw new ArgumentNullException(nameof(leaving)); } if (joining.Count == 0 && leaving.Count == 0) { throw new InvalidOperationException($"Cannot build interest change packet when changes are empty."); } //Arrange packet data EntityCreationData[] creationDatas = joining .Select(j => new EntityCreationData(j, MovementMapper[j], BuildInitialDataFieldValues(j))) .ToArray(); NetworkObjectVisibilityChangeEventPayload changePayload = new NetworkObjectVisibilityChangeEventPayload(creationDatas, leaving.ToArray()); return(changePayload); }
/// <inheritdoc /> public void Send([NotNull] EntityVisibilityChangeContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } NetworkObjectVisibilityChangeEventPayload changeEventPayload = BuildPayload(context.InterestCollection); IPeerPayloadSendService <GameServerPacketPayload> sendService = RetrieveSendService(context.EntityGuid); sendService.SendMessage(changeEventPayload, DeliveryMethod.ReliableOrdered) .ConfigureAwait(false); }
private NetworkObjectVisibilityChangeEventPayload BuildPayload([NotNull] IReadonlyInterestCollection interestCollection) { if (interestCollection == null) { throw new ArgumentNullException(nameof(interestCollection)); } //TODO: Provide movement mappable InterestChangedPacketBuilder changedPacketBuilder = new InterestChangedPacketBuilder(MovementDataMappable, EntityDataMapper, FieldUpdateFactory); //We delegate the packet building to the packet builder. But we still need to send it. //Sending is async so it can be fired off and not awaited, we won't want to await it NetworkObjectVisibilityChangeEventPayload changeEventPayload = changedPacketBuilder.Build(interestCollection.QueuedJoiningEntities, interestCollection.QueuedLeavingEntities); return(changeEventPayload); }