Beispiel #1
0
 private void Destory()
 {
     Active = false;
     location.Tile.Level.Updateables.Remove(this);
     location.Tile.Drawables.Remove(this);
     animator.AbortFinishAsync();
     FinishImpact();
 }
Beispiel #2
0
        public override async Task <bool> MoveToAsync(ISpaceRouteElement newLocation)
        {
            if (location == newLocation)
            {
                throw new InvalidOperationException("Cannot move from space to itself.");
            }

            bool alreadyOnTile  = location?.Tile == newLocation.Tile;
            bool differentLevel = location?.Tile?.Level != newLocation?.Tile?.Level;

            if (animator.IsAnimating)
            {
                animator.AbortFinishAsync();
            }

            if (!newLocation.Tile.LayoutManager.TryGetSpace(this, newLocation.Space))
            {
                return(false);
            }


            //following line is done by animator itself
            //Position = newLocation.StayPoint;

            location?.Tile.LayoutManager.FreeSpace(this, location.Space);
            await animator.MoveToAsync(this, newLocation, false);


            if (!alreadyOnTile)
            {
                location?.Tile?.OnObjectLeft(this);

                if (differentLevel)
                {
                    location?.Tile?.Level?.Updateables.Remove(this);
                }
            }

            location = newLocation;

            if (!alreadyOnTile)
            {
                location?.Tile?.OnObjectEntered(this);

                if (differentLevel)
                {
                    location?.Tile?.Level?.Updateables.Add(this);
                }
            }
            //move following line before animation start in order to let creatures
            //move more consistently
            //location?.Tile.LayoutManager.FreeSpace(this, location.Space);
            return(true);
        }