コード例 #1
0
 public override void onRemoved(Cell c)
 {
     foreach (Tower t in towersEffected)
     {
         t.Effects.RemoveAll(delegate(Effect e)
         {
             return e.type == "damageboost";
         });
     }
 }
コード例 #2
0
 public override void onRemoved(Cell c)
 {
     foreach (Tower t in towersEffected)
     {
         if (t.hasEffect("rangeboost"))
         {
             lock (t.Effects)
             {
                 Effect e = t.getEffect("rangeboost");
                 t.Effects.Remove(e);
             }
         }
     }
 }
コード例 #3
0
 public RangeBoostEffect(Entity e, Cell c)
     : base(e, int.MaxValue)
 {
     type = "rangeboost";
     controlCell = c;
 }
コード例 #4
0
 private void addNeighborToCell(Cell c, Cell neighbor)
 {
     if (neighbor != null && c != null)
     {
         if (neighbor.Player == c.Player && neighbor.Passable)
         {
             if(!c.Neighbors.ContainsKey(neighbor))
             {
                 lock(c.Neighbors)
                     c.Neighbors.Add(neighbor, true);
             }
         }
     }
 }
コード例 #5
0
        public void setupCellNeighbors(Cell c)
        {
            addNeighborToCell(c, findCellByIndex(c.Index + UP));
            addNeighborToCell(findCellByIndex(c.Index + UP), c);

            addNeighborToCell(c, findCellByIndex(c.Index + LEFT));
            addNeighborToCell(findCellByIndex(c.Index + LEFT), c);

            addNeighborToCell(c, findCellByIndex(c.Index + RIGHT));
            addNeighborToCell(findCellByIndex(c.Index + RIGHT), c);

            addNeighborToCell(c, findCellByIndex(c.Index + DOWN));
            addNeighborToCell(findCellByIndex(c.Index + DOWN), c);

            if (c.Up != null && c.Left != null)
            {
                if (c.Up.Player == c.Player && c.Left.Player == c.Player && c.Up.Passable && c.Left.Passable)
                {
                    addNeighborToCell(c, findCellByIndex(c.Index + UPL));
                    addNeighborToCell(findCellByIndex(c.Index + UPL), c);
                }
            }
            if (c.Up != null && c.Right != null)
            {
                if (c.Up.Player == c.Player && c.Right.Player == c.Player && c.Up.Passable && c.Right.Passable)
                {
                    addNeighborToCell(c, findCellByIndex(c.Index + UPR));
                    addNeighborToCell(findCellByIndex(c.Index + UPR), c);
                }
            }
            if (c.Down != null && c.Left != null)
            {
                if (c.Down.Player == c.Player && c.Left.Player == c.Player && c.Down.Passable && c.Left.Passable)
                {
                    addNeighborToCell(c, findCellByIndex(c.Index + DOWNL));
                    addNeighborToCell(findCellByIndex(c.Index + DOWNL), c);
                }
            }
            if (c.Down != null && c.Right != null)
            {
                if (c.Down.Player == c.Player && c.Right.Player == c.Player && c.Down.Passable && c.Right.Passable)
                {
                    addNeighborToCell(c, findCellByIndex(c.Index + DOWNR));
                    addNeighborToCell(findCellByIndex(c.Index + DOWNR), c);
                }
            }
        }
コード例 #6
0
        public override void onPlaced(Cell c)
        {
            towerCell = c;

            base.onPlaced(c);
        }
コード例 #7
0
        public static Path getPath(Cell start, List<Cell> targets)
        {
            Stopwatch sw = Stopwatch.StartNew();
            Path empty = new Path();

            List<Cell> openList = new List<Cell>();
            List<Cell> closedList = new List<Cell>();

            Boolean foundTarget = false;
            Cell currentNode = start;

            Dictionary<Cell, Cell> parentCells = new Dictionary<Cell, Cell>();
            parentCells.Add(start, null);
            openList.Add(start);

            while (!foundTarget)
            {
                if (sw.ElapsedMilliseconds > 80)
                {
                    Console.WriteLine("Taking too long for: " + start.Index);
                    Console.WriteLine("Openlist: " + openList.Count);
                    Console.WriteLine("Closedlist: " + closedList.Count);
                    return empty;
                }

                // If the openlist has no cells return an empty path
                if (openList.Count == 0)
                    return empty;

                // sort the open list
                openList.RemoveAll(delegate(Cell c) { return c == null; });
                openList.Sort(delegate(Cell c1, Cell c2) { return c1.F.CompareTo(c2.F); });

                // grab the first cell w/ lowest f score
                currentNode = openList[0];

                if (targets.Contains(currentNode))
                {
                    // We found the target node
                    Path path = new Path();

                    foundTarget = true;
                    Cell pathNode = currentNode;
                    while(parentCells[pathNode] != null)
                    {
                        path.Push(pathNode);
                        pathNode = parentCells[pathNode];
                    }
                    return path;
                }

                openList.Remove(currentNode);
                closedList.Add(currentNode);

                lock (currentNode.Neighbors)
                {
                    foreach (KeyValuePair<Cell, Boolean> neighbor in currentNode.Neighbors)
                    {
                        if (neighbor.Value && neighbor.Key.Passable)
                        {
                            if (!closedList.Contains(neighbor.Key) && !openList.Contains(neighbor.Key))
                            {
                                parentCells.Add(neighbor.Key, currentNode);
                                neighbor.Key.G = parentCells[neighbor.Key].G + getDistance(currentNode, neighbor.Key);
                                neighbor.Key.H = getClosestTarget(targets, neighbor.Key.Center);
                                neighbor.Key.F = neighbor.Key.G + neighbor.Key.H;
                                openList.Add(neighbor.Key);
                            }
                        }
                    }
                }
            }

            return empty;
        }
コード例 #8
0
 public static float getDistance(Cell a, Cell b)
 {
     return Math.Abs(a.Position.X - b.Position.X) + Math.Abs(a.Position.Y - b.Position.Y);
 }
コード例 #9
0
 public virtual void onRemoved(Cell c)
 {
 }
コード例 #10
0
 public virtual void onPlaced(Cell c)
 {
     Cell = c;
     Player.Game.Context.Broadcast(Messages.GAME_TOWER_RATE, Cell.Index, EffectedFireRate);
     Player.Game.Context.Broadcast(Messages.GAME_TOWER_DAMAGE, Cell.Index, EffectedDamage);
 }
コード例 #11
0
 public float getDistance(Cell c)
 {
     return Math.Abs(Center.X - c.Center.X) + Math.Abs(Center.Y - c.Center.Y);
 }
コード例 #12
0
ファイル: Game.cs プロジェクト: behindcurtain3/schismTDserver
        public void removeTower(Player p, Cell c, Boolean update = false)
        {
            c.Tower.onRemoved(c);

            lock (p.Towers)
                p.Towers.Remove(c.Tower);

            if(update)
                mCtx.Broadcast(Messages.GAME_TOWER_REMOVE, c.Index);
        }
コード例 #13
0
ファイル: Game.cs プロジェクト: behindcurtain3/schismTDserver
        public void addTower(Player p, Cell c)
        {
            lock (p.Towers)
                p.Towers.Add(c.Tower);

            mCtx.Broadcast(Messages.GAME_TOWER_PLACE, c.Index, c.Tower.Type, c.Tower.Range);

            c.Tower.onPlaced(c);

            // Each spell tower levels up the chi blast
            if (c.Tower.Type == Tower.SPELL)
                p.ChiBlastUses++;

            // update stats
            switch (c.Tower.Type)
            {
                case Tower.BASIC:
                    Stats.Basic++;
                    break;
                case Tower.RAPID_FIRE:
                    Stats.RapidFire++;
                    break;
                case Tower.SNIPER:
                    Stats.Sniper++;
                    break;
                case Tower.PULSE:
                    Stats.Pulse++;
                    break;
                case Tower.SLOW:
                    Stats.Slow++;
                    break;
                case Tower.SPELL:
                    Stats.Spell++;
                    break;
                case Tower.DAMAGE_BOOST:
                    Stats.DamageBoost++;
                    break;
                case Tower.RANGE_BOOST:
                    Stats.RangeBoost++;
                    break;
                case Tower.RATE_BOOST:
                    Stats.FireRateBoost++;
                    break;
            }
        }
コード例 #14
0
ファイル: Game.cs プロジェクト: behindcurtain3/schismTDserver
        private void invalidTower(Player p, Cell c, int x, int y)
        {
            if (c != null)
            {
                c.Passable = true;

                if (c.Up != null && c.Left != null)
                {
                    lock (c.Up.Neighbors)
                        if (c.Up.Neighbors.ContainsKey(c.Left))
                            c.Up.Neighbors[c.Left] = true;
                    lock (c.Left.Neighbors)
                        if (c.Left.Neighbors.ContainsKey(c.Up))
                            c.Left.Neighbors[c.Up] = true;
                }
                if (c.Up != null && c.Right != null)
                {
                    lock (c.Up.Neighbors)
                        if (c.Up.Neighbors.ContainsKey(c.Right))
                            c.Up.Neighbors[c.Right] = true;
                    lock (c.Right.Neighbors)
                        if (c.Right.Neighbors.ContainsKey(c.Up))
                             c.Right.Neighbors[c.Up] = true;
                }
                if (c.Down != null && c.Right != null)
                {
                    lock (c.Down.Neighbors)
                        if (c.Down.Neighbors.ContainsKey(c.Right))
                            c.Down.Neighbors[c.Right] = true;
                    lock (c.Right.Neighbors)
                        if (c.Right.Neighbors.ContainsKey(c.Down))
                            c.Right.Neighbors[c.Down] = true;
                }
                if (c.Down != null && c.Left != null)
                {
                    lock (c.Down.Neighbors)
                        if (c.Down.Neighbors.ContainsKey(c.Left))
                            c.Down.Neighbors[c.Left] = true;
                    lock (c.Left.Neighbors)
                        if (c.Left.Neighbors.ContainsKey(c.Down))
                            c.Left.Neighbors[c.Down] = true;
                }
            }

            p.Send(Messages.GAME_TOWER_INVALID, x, y);
        }