Example #1
0
        protected override Event Persist()
        {
            if (Result.Resolution != EventResolutionType.Commit)
            {
                return(this);
            }

            Result.Deltas.Add(new Delta {
                Actor = _actor, Key = "NewBackground", Value = movement.Destination.ImageUrl, Targets = repo.Get(Result)
            });
            LocationMutator.GoToPosition(movement);
            if (movement.Origin == null)
            {
                return(this);
            }

            LocationMutator.RemovePlayerFromScene(movement);

            if (!movement.Origin.Players.Any())
            {
                LocationMutator.RemoveEmptyScene(movement);
            }
            else
            {
                var e = new LeaveLocationEvent(movement.Traveler, movement.Origin.Id, serviceProvider);
                Engine.Instance.Push(e);
            }

            return(this);
        }
Example #2
0
        protected override ReadonlyEvent Resolve()
        {
            movement = new Movement();
            //TODO: Currently, the mutator is accessed in Resolve. It is supposed to only change things and therefor be accessed in Persist.
            //Setting of these values is not a write operation, but it involves logic that should not be inside the Process for Changing Location.
            //So thats a problem...
            LocationMutator.SetTraveler(_actor, movement);
            LocationMutator.SetOrigin(movement);
            LocationMutator.SetDestination(_destinationId, movement);

            //TODO: Currently, we detect login by saying that we have no origin, so it must be logon.
            //Maybe we should make this its own event?
            if (movement.Origin == null)
            {
                Result.Message = string.Format("{0} has logged into the location {1}", _actor.Name, movement.Destination.Name);
                Result.Deltas.Add(new Delta {
                    Actor = _actor, Key = "PlayerLoggedIn", Value = movement.Destination.Name.ToString(), Targets = repo.Get(Result)
                });
                SetStandardResult();
                return(this);
            }

            if (CanGoToPosition(movement))
            {
                SetStandardResult();
                Result.Message = GenerateMessageString();
            }
            else
            {
                movement.Destination.RemovePlayer(movement.Traveler);
                Result.Message    = string.Format("{0} is not allowed to go to {1} from this location.", _actor.Name, movement.Destination.Name);
                Result.Resolution = EventResolutionType.Rollback;
            }

            return(this);
        }