public ActionAnimationPlaying(GameState gameState, ActionInformation actionInformation, Tile tile)
     : base(gameState)
 {
     _actionInformation = actionInformation;
     _stateName = "ActorAnimationPlaying" + _num++;
     _script = _actionInformation.Script(tile);
     InputProcessor = new NoInputProcessor();
 }
Пример #2
0
        public override IList<DamageResult> CalculateDamages(Level level, Tile targeted)
        {
            if (targeted.ActorInTile == null)
                return DamageResult.Empty;

            var damageResult = new DamageResult() {DamageType = DamageType.Physical};
            damageResult.AffectedActor = targeted.ActorInTile;
            damageResult.DamageReduced = 0;
            damageResult.NetDamage = 250;

            return new List<DamageResult>() {damageResult};
        }
Пример #3
0
 public static TileSelector EnemyTileSelector(Level level, Tile currentTile, int myTeam, int maxRange)
 {
     var candidateTileList = level.Tiles.Where(x => x.ActorInTile != null && x.ActorInTile.Team != myTeam).ToList();
     var tileList = new List<Tile>();
     foreach (var tile in candidateTileList)
     {
         if (Math.Abs(currentTile.XCoord - tile.XCoord) + Math.Abs(currentTile.YCoord - tile.YCoord) <= maxRange)
         {
             tileList.Add(tile);
         }
     }
     return new TileSelector(tileList);
 }
Пример #4
0
        public static TileSelector CircularSelector(Level level, Tile currentTile, int radius)
        {
            var selector = new TileSelector();
            for (int i = -radius; i <= radius; i++)
            {
                for (int j = -radius; j <= radius; j++)
                {
                    if (Math.Abs(i) + Math.Abs(j) <= radius)
                    {
                        Tile t = level.GetTileAt(currentTile.XCoord + j, currentTile.YCoord + i);
                        if (t != null)
                            selector.AddValidTile(t);
                    }
                }
            }

            return selector;
        }
Пример #5
0
        private ActionAnimationScript ShootFireballAction(Level level, AbilityDetails abilityDetails, Tile selectedTile)
        {
            // calculate damages
            var damageList = abilityDetails.CalculateDamages(level, selectedTile);

            // animation
            CurrentAnimation = ActorAnimationManager.Make("cacoshoot", ActorId);
            CurrentAnimation.OnComplete = Idle;

            var tilebox = selectedTile.CreateBoundingBox();
            var average = tilebox.Min + (tilebox.Max - tilebox.Min) / 2.0f;
            Vector3 target = new Vector3(average.X, tilebox.Max.Y + Height / 2.0f, average.Z);
            BoundingBox targetBoundingBox = new BoundingBox(target - new Vector3(20, 20, 20), target + new Vector3(20, 20, 20));
            Vector3 source = new Vector3(Position.X, Position.Y + Height / 3.0f, Position.Z);
            var direction = target - source;
            var velocity = Vector3.Normalize(direction) * 5.0f;
            var cacoFireball = ActorSpawnMethods.GetSpawnMethod(ActorType.CacoFireball).Invoke(source, velocity);
            var spawnEvent = new ActorEvent(DoomEventType.SpawnActor, cacoFireball);
            var soundEvent = new SoundEvent(DoomEventType.PlaySound, FireballShootSound);

            var script = new ActionAnimationScriptBuilder().Name(ActorId + "shootFireball")
                .Segment()
                    .OnStart(() =>
                    {
                        FacePoint(selectedTile.GetTopCenter(), false);
                        MessagingSystem.DispatchEvent(spawnEvent, ActorId);
                        MessagingSystem.DispatchEvent(soundEvent, ActorId);
                    })
                    .EndCondition(() => targetBoundingBox.Contains(cacoFireball.Position) == ContainmentType.Contains)
                    .OnComplete(() =>
                    {
                        ApplyAndDisplayDamages(damageList);
                        cacoFireball.Die();
                    })
                .Segment()
                    .EndOnEvent(DoomEventType.AnimationEnd, cacoFireball.ActorId)
                    .OnComplete(() =>
                        MessagingSystem.DispatchEvent(new DespawnActorEvent(DoomEventType.DespawnActor, cacoFireball), ActorId)
                        )
                .Build();

            return script;
        }
Пример #6
0
        public static IList<Tile> CalculateAStarPath(Tile start, Tile goal, Level level, ActorBase actor)
        {
            if (start == null || goal == null)
                return null;
            if (goal.ActorInTile != null)
                return null;

            var path = new List<Tile>();
            var nodes = new Node[level.Length,level.Width];
            for (int x = 0; x < level.Length; x++)
            {
                for (int y = 0; y < level.Width; y++)
                {
                    nodes[x, y] = new Node(x, y);
                }
            }

            return CalculatePath(start, goal, level, nodes, actor);
        }
        public override IList<DamageResult> CalculateDamages(Level level, Tile targeted)
        {
            if (targeted.ActorInTile == null)
                return DamageResult.Empty;
            var damageResults = new List<DamageResult>();

            var aoe = TileSelectorHelper.CircularSelector(level, targeted, radius).ValidTiles();
            foreach (var tile in aoe)
            {
                if (tile.ActorInTile != null)
                {
                    var damageResult = new DamageResult() {DamageType = DamageType.Physical};
                    damageResult.AffectedActor = targeted.ActorInTile;
                    damageResult.DamageReduced = 0;
                    damageResult.NetDamage = 250;
                }
            }

            return damageResults;
        }
Пример #8
0
        public static Level CreateLevel(ContentManager contentManager, LevelData levelData)
        {
            InitializeDictionary();

            var level = new Level(levelData.TilesLong, levelData.TilesWide);
            for (int i = 0; i < level.Width; i++)
            {
                for (int j = 0; j < level.Length; j++)
                {
                    int index = i*level.Length + j;

                    var tileData = levelData.TileDatas[index];
                    var topTexture = contentManager.Load<Texture2D>(tileData.TopTextureName);
                    var northTexture = contentManager.Load<Texture2D>(tileData.NorthTextureName);
                    var southTexture = contentManager.Load<Texture2D>(tileData.SouthTextureName);
                    var eastTexture = contentManager.Load<Texture2D>(tileData.EastTextureName);
                    var westTexture = contentManager.Load<Texture2D>(tileData.WestTextureName);
                    var tileTextures = new TileTextures(topTexture, northTexture, southTexture, eastTexture, westTexture);
                    Vector3 tilePosition = new Vector3(j * 64.0f, tileData.VisualHeight, i * 64.0f);
                    var tile = new Tile(tileTextures, tilePosition, tileData.VisualHeight, j, i, tileData.YPosition);
                    level.Tiles[index] = tile;
                }
            }

            foreach (var info in levelData.ActorInfos)
            {
                var actor = MakeActor(info, levelData.TileDatas, levelData.TilesLong);
                actor.Team = info.Team;
                level.Actors.Add(actor);
                var tile = level.Tiles.Single(t => t.XCoord == info.TileX && t.YCoord == info.TileY);
                tile.SetActor(actor);
            }

            level.BackgroundImage = contentManager.Load<Texture2D>(levelData.BackgroundTextureName);

            return level;
        }
Пример #9
0
        public static TileSelector StandardMovementTileSelector(Level level, Tile currentTile, ActorBase actor)
        {
            var selector = new TileSelector();
            int movementRange = actor.CurrentStats.MovementRange;
            for (int i = -movementRange; i <= movementRange; i++)
            {
                for (int j = -movementRange; j <= movementRange; j++)
                {
                    if (Math.Abs(i) + Math.Abs(j) <= movementRange)
                    {
                        Tile t = level.GetTileAt(currentTile.XCoord + j, currentTile.YCoord + i);
                        if (t != null && t.ActorInTile == null)
                        {
                            if (AStar.CalculateAStarPath(currentTile, t, level, actor) != null)
                            {
                                selector.AddValidTile(t);
                            }
                        }
                    }
                }
            }

            return selector;
        }
Пример #10
0
 public static int DistanceBetweenTiles(Tile tile1, Tile tile2)
 {
     return Math.Abs(tile1.XCoord - tile2.XCoord) + Math.Abs(tile1.YCoord - tile2.YCoord);
 }
Пример #11
0
 public abstract IList<DamageResult> CalculateDamages(Level level, Tile targeted);
Пример #12
0
        private static IList<Tile> CalculatePath(Tile start, Tile goal, Level level, Node[,] nodes, ActorBase actor)
        {
            nodes[start.XCoord, start.YCoord].Cost = 0;
            nodes[start.XCoord, start.YCoord].Depth = 0;
            var open = new List<Node>();
            var closed = new List<Node>();
            var path = new List<Tile>();
            int depth = 0;

            open.Add(nodes[start.XCoord, start.YCoord]);

            while (depth < MaximumSearchDistance && (open.Count != 0))
            {
                Node current = open[0];
                if (current == nodes[goal.XCoord, goal.YCoord])
                {
                    break;
                }

                open.RemoveAt(0);
                closed.Add(current);
                for (int x = -1; x <= 1; x++)
                {
                    for (int y = -1; y <= 1; y++)
                    {
                        if (x == 0 && y == 0) continue;
                        if (x != 0 && y != 0) continue;

                        int candidateX = x + current.X;
                        int candidateY = y + current.Y;

                        if (CanMoveToTile(actor, level, start.XCoord, start.YCoord, current.X, current.Y, candidateX, candidateY))
                        {
                            float nextStepCost = current.Cost +
                                                 CalculateMovementCost(actor, level, current.X, current.Y, candidateX,
                                                                       candidateY);
                            Node neighbor = nodes[candidateX, candidateY];
                            if (nextStepCost < neighbor.Cost)
                            {
                                if (open.Contains(neighbor))
                                {
                                    open.Remove(neighbor);
                                }
                                if (closed.Contains(neighbor))
                                {
                                    closed.Remove(neighbor);
                                }
                            }

                            if (!open.Contains(neighbor) && !closed.Contains(neighbor))
                            {
                                neighbor.Cost = nextStepCost;
                                neighbor.Heuristic = GetHeuristicCost(actor, level.GetTileAt(candidateX, candidateY),
                                                                      goal);
                                depth = Math.Max(depth, neighbor.SetParent(current));
                                open.Add(neighbor);
                                open = open.OrderBy(o => o.TotalCost()).ToList();
                            }

                        }
                    }
                }
            }

            if (nodes[goal.XCoord, goal.YCoord].Parent == null) return null;
            Node target = nodes[goal.XCoord, goal.YCoord];
            while (target != nodes[start.XCoord, start.YCoord])
            {
                path.Insert(0, level.GetTileAt(target.X, target.Y));
                target = target.Parent;
            }
            path.Insert(0, start);
            if (path.Count > actor.CurrentStats.MovementRange + 1) return null;

            return path;
        }
Пример #13
0
 public static TileSelector SingleTile(Tile tile)
 {
     return new TileSelector(new List<Tile>() { tile });
 }
Пример #14
0
 public void AddValidTile(Tile tile)
 {
     _validTiles.Add(tile);
 }
Пример #15
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (IsConfirming)
            {

            }
            else
            {
                Tile hoveredTile = GameState.FindHighlightedTile();
                if (hoveredTile != _hoveredTile)
                {
                    if (_hoveredTile != null)
                    {
                        _hoveredTile.Tint = _actionInformation.AbilityRange.IsTileValid(_hoveredTile)
                                                ? GetTint(_actionInformation.ActionType, false)
                                                : DefaultTint;
                    }
                    _hoveredTile = hoveredTile;
                    if (_hoveredTile != null)
                    {
                        _hoveredTile.Tint = GetTint(_actionInformation.ActionType, true);
                    }
                }
            }
            GameState.SquidInputManager.Update(gameTime);
            GameState.Desktop.Update();
        }
Пример #16
0
 public void SwitchToConfirming()
 {
     IsConfirming = true;
     _targetedTile = GameState.FindHighlightedTile();
     _targetedAoe = _actionInformation.AbilityAreaOfEffect(_targetedTile);
     var validTiles = _targetedAoe.ValidTiles();
     foreach (var aoeTile in validTiles)
     {
         aoeTile.Tint = GetTint(_actionInformation.ActionType, true);
     }
 }
Пример #17
0
 private void AIDecisionComplete(ActionInformation actionInformation, Tile targetTile)
 {
     Func<IState> state = () =>
         new ActionAnimationPlaying(GameState, actionInformation, targetTile);
     NextState = new StateTransition(state);
 }
Пример #18
0
        protected virtual ActionAnimationScript MoveToTileAction(Tile goalTile, Level level)
        {
            IList<Tile> path = AStar.CalculateAStarPath(level.GetTileOfActor(this), goalTile, level, this);

            var script = MoveToTileScript.MakeScript(path, this);

            return script;
        }
Пример #19
0
 public void SnapToTile(Tile tile)
 {
     Position = tile.GetTopCenter();
 }
Пример #20
0
 public bool IsTileValid(Tile tile)
 {
     return _validTiles.Contains(tile);
 }
Пример #21
0
 private static float GetHeuristicCost(ActorBase actor, Tile tile, Tile goal)
 {
     return Math.Abs(tile.XCoord - goal.XCoord) + Math.Abs(tile.YCoord - goal.YCoord);
 }