Ejemplo n.º 1
0
        /// <inheritdoc />
        protected override Task HandleMessage(IPeerSessionMessageContext <GameServerPacketPayload> context, ClientSetClickToMovePathRequestPayload payload, NetworkEntityGuid guid)
        {
            try
            {
                IMovementGenerator <GameObject> generator = MovementGenerator.RetrieveEntity(guid);

                IMovementData         movementData       = MovementDataMap.RetrieveEntity(guid);
                PathBasedMovementData changeMovementData = BuildPathData(payload, generator, movementData, guid);

                //If it doesn't have more one point reject it
                if (changeMovementData.MovementPath.Count < 2)
                {
                    return(Task.CompletedTask);
                }

                MovementDataMap.ReplaceObject(guid, changeMovementData);

                IActorRef playerActorRef = ActorReferenceMappable.RetrieveEntity(guid);

                Vector3 direction3D = (changeMovementData.MovementPath[1] - changeMovementData.MovementPath[0]);
                Vector2 direction2D = new Vector2(direction3D.x, direction3D.z).normalized;
                playerActorRef.TellSelf(new PlayerMovementStateChangedMessage(direction2D));

                //If the generator is running, we should use its initial position instead of the last movement data's position.
                MovementGenerator.ReplaceObject(guid, new PathMovementGenerator(changeMovementData));
            }
            catch (Exception e)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error($"Failed to update MovementData for GUID: {guid} Reason: {e.Message}");
                }

                throw;
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        //TODO: Support spell school definition. For heals might be a Dark heal or Holy heal or Nature heal.
        /// <summary>
        /// Applies a heal to the <see cref="entity"/> associated with the provided guid.
        /// Applies <see cref="healAmount"/> of the heal.
        /// </summary>
        /// <param name="entity">Entity to heal.</param>
        /// <param name="healAmount">The amount to heal.</param>
        /// <param name="healSourceEntity">The healing source entity.</param>
        protected void ApplyHeal([NotNull] NetworkEntityGuid entity, int healAmount, NetworkEntityGuid healSourceEntity = null)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (healAmount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(healAmount));
            }

            IActorRef actorRef = ActorReferenceMappable.RetrieveEntity(entity);

            if (healSourceEntity == null || healSourceEntity == NetworkEntityGuid.Empty)
            {
                actorRef.Tell(new HealEntityActorCurrentHealthMessage(healAmount));
            }
            else
            {
                IActorRef sourceRef = ActorReferenceMappable.RetrieveEntity(healSourceEntity);
                actorRef.Tell(new HealEntityActorCurrentHealthMessage(healAmount), sourceRef);
            }
        }