public IMovementGenerator <GameObject> Create(EntityAssociatedData <IMovementData> context) { //TODO: Another temporary hack if (context.EntityGuid.EntityType == EntityType.Creature || context.EntityGuid.EntityType == EntityType.GameObject) { if (context.Data is PositionChangeMovementData d) { if (d.Direction == Vector2.zero) { return(new IdleMovementGenerator(context.Data.InitialPosition)); } else { throw new InvalidOperationException($"Cannot create Creature/GameObject Movement for Type: {context.Data.GetType().Name} For Entity: {context.EntityGuid}"); } } if (context.Data is PathBasedMovementData pathData) { return(new PathMovementGenerator(pathData)); } } //TODO: redo all this of this garbage if (context.Data is PositionChangeMovementData pcmd) { return(new ClientCharacterControllerInputMovementGenerator(pcmd, BuildLazyControllerFactory(context))); } throw new NotSupportedException($"TODO: Encountered unsupported movement data: {context.Data.GetType().Name}"); }
private Lazy <CharacterController> BuildLazyControllerFactory([NotNull] EntityAssociatedData <IMovementData> context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return(new Lazy <CharacterController>(() => ControllerMappable.RetrieveEntity(context.EntityGuid))); }
public void HandleMovementUpdate(EntityAssociatedData <IMovementData> movementUpdate, bool forceHandleLocal = false) { if (!KnownEntities.isEntityKnown(movementUpdate.EntityGuid)) { if (Logger.IsInfoEnabled) { Logger.Info($"TODO: Received movement update too soon. Must enable deferred movement update queueing for entities that are about to spawn."); } return; } try { if (!forceHandleLocal) { //Cheap check, and we're on another thread so performance doesn't really matter if (movementUpdate.EntityGuid == PlayerDetails.LocalPlayerGuid) { if (movementUpdate.Data.isUserCreated) { return; //don't handle user created movement data about ourselves. It'll just make movement abit janky locally. } } } IMovementGenerator <GameObject> generator = MovementGeneratorFactory.Create(movementUpdate); //We just initialize this casually, the next update tick in Unity3D will start the movement generator, the old generator actually might be running right now //at the time this is set. MovementGeneratorMappable.ReplaceObject(movementUpdate.EntityGuid, generator); MovementDataMappable.ReplaceObject(movementUpdate.EntityGuid, movementUpdate.Data); } catch (Exception e) { string error = $"Failed to handle Movement Data for Entity: {movementUpdate.EntityGuid} Type: {movementUpdate.Data.GetType().Name} Error: {e.Message}"; if (Logger.IsErrorEnabled) { Logger.Error(error); } throw new InvalidOperationException(error, e); } }
/// <inheritdoc /> public TextChatEventArgs CreateChatData <TMessageType>([NotNull] EntityAssociatedData <TMessageType> incomingChatMessageEventData, [NotNull] string associatedEntityName) where TMessageType : ITextMessageContainable, IChatChannelRoutable { if (incomingChatMessageEventData == null) { throw new ArgumentNullException(nameof(incomingChatMessageEventData)); } if (associatedEntityName == null) { throw new ArgumentNullException(nameof(associatedEntityName)); } ChatChannelType messageType = incomingChatMessageEventData.Data.ChannelType; string renderableMessage = $"<color=#{ComputeColorFromChatType(messageType)}>{ComputeChannelText(messageType)} {associatedEntityName}: {incomingChatMessageEventData.Data.Message}</color>"; TextChatEventArgs args = new TextChatEventArgs(renderableMessage, incomingChatMessageEventData.EntityGuid, messageType); args.isFormattedText = true; return(args); }
private IMovementGenerator <GameObject> CreatePlayerMovementGenerator(EntityAssociatedData <IMovementData> context) { //TODO: redo all this of this garbage if (context.Data is PositionChangeMovementData pcmd) { //Warning, this following code is ONLY for client. To smooth out serverside corrections /*if (pcmd.Direction == Vector2.zero) * { * return new LocalClientInterpolatedCorrectionMovementGenerator(pcmd, BuildLazyControllerFactory(context), LocalPlayerDetails.LocalPlayerGuid != context.EntityGuid); * } * else * { * //The reason we use a lazy here is because we can't promise that the character controller exists AT ALL at this point sadly. * return new ClientCharacterControllerInputMovementGenerator(pcmd, BuildLazyControllerFactory(context), LocalPlayerDetails.LocalPlayerGuid != context.EntityGuid); * }*/ //The reason we use a lazy here is because we can't promise that the character controller exists AT ALL at this point sadly. return(new ClientCharacterControllerInputMovementGenerator(pcmd, BuildLazyControllerFactory(context), LocalPlayerDetails.LocalPlayerGuid != context.EntityGuid)); } throw new NotSupportedException($"TODO: Encountered unsupported movement data: {context.Data.GetType().Name}"); }
public IMovementGenerator <GameObject> Create(EntityAssociatedData <IMovementData> context) { switch (context.EntityGuid.EntityType) { case EntityType.None: break; case EntityType.Player: return(CreatePlayerMovementGenerator(context)); case EntityType.GameObject: //TODO: Support non-static GameObjects. return(new IdleMovementGenerator(context.Data.InitialPosition)); case EntityType.Creature: //TODO: Support non-static NPCs. return(CreateCreatureMovementGenerator(context)); default: throw new ArgumentOutOfRangeException(); } throw new NotSupportedException($"TODO: Encountered unsupported movement data: {context.Data.GetType().Name}"); }
private Lazy <CharacterController> BuildLazyControllerFactory(EntityAssociatedData <IMovementData> context) { return(new Lazy <CharacterController>(() => ControllerMappable.RetrieveEntity(context.EntityGuid))); }
private static IMovementGenerator <GameObject> CreateCreatureMovementGenerator(EntityAssociatedData <IMovementData> context) { if (context.Data is PositionChangeMovementData pcmd) { if (pcmd.Direction == Vector2.zero) { return(new IdleMovementGenerator(context.Data.InitialPosition)); } else { throw new InvalidOperationException($"Cannot move creatures via movement change like players!"); } } else if (context.Data is PathBasedMovementData pathData) { return(new PathMovementGenerator(pathData)); } throw new InvalidOperationException($"Recieved unhandled Movement Type: {context.Data.GetType().Name} for Creature: {context.EntityGuid}."); }
public PlayerTrackerTransformChangedEventArgs([NotNull] EntityAssociatedData <PlayerNetworkTrackerChangeUpdateRequest> changeInformation) { ChangeInformation = changeInformation ?? throw new ArgumentNullException(nameof(changeInformation)); }
public PlayerNetworkTrackerChangeUpdateEvent([NotNull] EntityAssociatedData <PlayerNetworkTrackerChangeUpdateRequest> playerTrackerUpdate) { PlayerTrackerUpdate = playerTrackerUpdate ?? throw new ArgumentNullException(nameof(playerTrackerUpdate)); }