示例#1
0
        /// <summary>
        /// Flips the reactions to correspond with the castle shape.
        /// </summary>
        /// <param name="reactions">Reactions.</param>
        /// <param name="hero">Hero.</param>
        public void flipReactions(Reaction[,] reactions, Hero hero)
        {
            int x = (int)Origo.x;
            int y = (int)Origo.y;

            int[,] shape = Shapes.GetShape(ShapeType);

            for (int fy = 0; fy < shape.GetLength(0); fy++)
            {
                for (int fx = 0; fx < shape.GetLength(1); fx++)
                {
                    int dxx = x + Shapes.dx[fx];
                    int dyy = y + Shapes.dy[fy];

                    if (shape[fx, fy] == 1)
                    {
                        reactions[dxx, dyy] = new CastleReact(this, new Point(dxx, dyy));
                    }
                }
            }
            if (hero != null)
            {
                CastleReact react = (CastleReact)reactions[x, y];
                react.PreReaction = new HeroMeetReact(hero, new Point(x, y));
            }
        }
示例#2
0
 /// <summary>
 /// Changes owner of castle to Player whose turn it is
 /// </summary>
 /// <param name="cr">CastleReact</param>
 public void changeCastleOwner(CastleReact cr, Player player, Hero hero)
 {
     cr.Castle.Player.Castle.Remove(cr.Castle);
     cr.Castle.Player            = player;
     cr.Castle.Town.Owner        = player;
     cr.Castle.Town.VisitingHero = hero;
     player.Castle.Add(cr.Castle);
 }
示例#3
0
    /// <summary>
    /// Called upon ended walk, flips the reactions in fromposition and toposition
    /// </summary>
    /// <param name="end">end position</param>
    public void UpdateReact(Point end)
    {
        Point start = startPosition;

        if (!start.Equals(end))
        {
            // Remove hero from town if he walked out of it
            if (reactions[start.x, start.y].GetType().Equals(typeof(CastleReact)))
            {
                CastleReact cr = (CastleReact)reactions[start.x, start.y];
                cr.Castle.Town.VisitingHero  = null;
                cr.Castle.Town.VisitingUnits = new UnitTree();
            }

            // If destination has reaction, set prereact
            if (reactions[end.x, end.y] != null)
            {
                // if you came from a prereact
                if (!reactions[start.x, start.y].GetType().Equals(typeof(HeroMeetReact)))
                {
                    reactions[end.x, end.y].PreReaction = reactions[start.x, start.y].PreReaction;
                }
                else
                {
                    reactions[end.x, end.y].PreReaction = reactions[start.x, start.y];
                }
                reactions[end.x, end.y].PreReaction.Pos = new Point(end.x, end.y);
            }
            // Else, set destination reaction to the heroreaction, and make the tile a triggertile
            else
            {
                // if you came from a prereact
                if (!reactions[start.x, start.y].GetType().Equals(typeof(HeroMeetReact)))
                {
                    reactions[end.x, end.y] = reactions[start.x, start.y].PreReaction;
                }
                else
                {
                    reactions[end.x, end.y] = reactions[start.x, start.y];
                }
                reactions[end.x, end.y].Pos = new Point(end.x, end.y);

                canWalk[end.x, end.y] = MapMaker.TRIGGER;
            }

            // If from position didn't have prereact, flip canwalk and remove
            if (reactions[start.x, start.y].GetType().Equals(typeof(HeroMeetReact)))
            {
                canWalk[start.x, start.y]   = MapMaker.CANWALK;
                reactions[start.x, start.y] = null;
            }
            // Else, remove the prereact
            else
            {
                reactions[start.x, start.y].PreReaction = null;
            }
        }
    }
示例#4
0
 /// <summary>
 /// Makes the reaction.
 /// </summary>
 /// <returns>The reaction.</returns>
 public override Reaction makeReaction()
 {
     return(Reaction = new CastleReact(this, Origo));
 }
示例#5
0
    /// <summary>
    /// Performs the actual reaction:
    /// </summary>
    /// <param name="end"></param>
    private void react(Point end)
    {
        int   x     = end.x;
        int   y     = end.y;
        Point start = startPosition;

        bool heroNotDead = true;

        // If tile is threatened, perform the additional reaction before the main one
        if (reactions[x, y].HasPreReact())
        {
            // If reaction is castleReact, trigger castleReact instead of preReact if enemy castle
            if (reactions[x, y].GetType() == typeof(CastleReact))
            {
                CastleReact cr = (CastleReact)reactions[x, y];
                if (!cr.Castle.Player.equals(activePlayer))
                {
                    reactions[x, y].React(activeHero);
                    curReaction = reactions[x, y];
                }
                else
                {
                    reactions[x, y].PreReact(activeHero);
                    curReaction = reactions[x, y];
                }
            }
            else
            {
                reactions[x, y].PreReact(activeHero);
                curReaction = reactions[x, y];
            }
            Debug.Log(reactions[x, y].PreReaction + " - prereact");
        }
        // Perform main reaction if there is not a preReaction
        else if (reactions[x, y].React(activeHero))
        {
            Debug.Log(reactions[x, y] + " - react");
            //bool react = reactions[x, y].React(activeHero);

            if (reactions[x, y].GetType().Equals(typeof(ResourceReaction)))
            {
                // TODO visually remove picked up resource
            }
            else if (reactions[x, y].GetType().Equals(typeof(ArtifactReaction)))
            {
                // TODO visually remove picked up artifact
            }
            else if (reactions[x, y].GetType().Equals(typeof(CastleReact)))
            {
                // TODO change owner of defenseless castle visually
                CastleReact cr = (CastleReact)reactions[x, y];
                cr.Castle.changeCastleOwner(cr, gameManager.Players[gameManager.WhoseTurn], gameManager.activeHero);
            }
            else if (reactions[x, y].GetType().Equals(typeof(DwellingReact)))
            {
                // TODO visually dwelling has been captured
            }
            else if (reactions[x, y].GetType().Equals(typeof(ResourceBuildingReaction)))
            {
                // TODO visually resourceBuilding has been captured
            }
        }
        else
        {
            curReaction = reactions[x, y];
        }
    }