Exemple #1
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="owner">Entity who thrown the item</param>
		/// <param name="item">Item</param>
		/// <param name="location">Start location</param>
		/// <param name="speed">Time in ms taken to cross a block</param>
		/// <param name="distance">How many block the item have to fly before falling on the ground</param>
		public ThrownItem(Entity owner, Item item, DungeonLocation location, TimeSpan speed, int distance)
		{
			Caster = owner;
			Item = item;
			Location = new DungeonLocation(location);
			Speed = speed;
			Distance = distance;
		}
		/// <summary>
		/// Copy constructor
		/// </summary>
		/// <param name="loc">Location</param>
		public DungeonLocation(DungeonLocation loc)
		{
			if (loc == null)
				return;

			Maze = loc.Maze;
			Coordinate = loc.Coordinate;
			Position = loc.Position;
			Direction = loc.Direction;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="dungeon"></param>
		/// <param name="maze"></param>
		/// <param name="coordinate"></param>
		public DungeonLocationForm(Dungeon dungeon, DungeonLocation location)
		{
			InitializeComponent();

			DungeonControl.Dungeon = dungeon;
			DungeonControl.Target = location;
			DungeonControl.GlControlBox.Click += new EventHandler(DungeonControl_Click);
			DungeonControl.GlControlBox.DoubleClick += new EventHandler(GlControlBox_DoubleClick);

			DirectionBox.Items.AddRange(Enum.GetNames(typeof(CardinalPoint)));
			GroundPositionBox.Items.AddRange(Enum.GetNames(typeof(SquarePosition)));

			Init();
		}
Exemple #4
0
		/// <summary>
		/// Initialize the team
		/// </summary>
		/// <returns>True on success</returns>
		public bool Init()
		{

			// Set initial location
			if (Location == null)
			{
				Location = new DungeonLocation();
				Teleport(GameScreen.Dungeon.StartLocation);
				Location.Direction = GameScreen.Dungeon.StartLocation.Direction;
			}
			else
			{
				Teleport(Location);
			}

			// Select the first hero
			SelectedHero = Heroes[0];

			return true;
		}
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public override bool Load(XmlNode xml)
        {
            if (xml == null || xml.Name != Tag)
            {
                return(false);
            }

            IsVisible = xml.Attributes["visible"] != null?bool.Parse(xml.Attributes["visible"].Value) : false;

            TeleportTeam = xml.Attributes["team"] != null?bool.Parse(xml.Attributes["team"].Value) : false;

            TeleportItems = xml.Attributes["items"] != null?bool.Parse(xml.Attributes["items"].Value) : false;

            TeleportMonsters = xml.Attributes["monster"] != null?bool.Parse(xml.Attributes["monster"].Value) : false;

            Reusable = xml.Attributes["resuable"] != null?bool.Parse(xml.Attributes["reusable"].Value) : false;

            foreach (XmlNode node in xml)
            {
                switch (node.Name.ToLower())
                {
                case "target":
                {
                    Target = new DungeonLocation();
                    Target.Load(node);
                }
                break;

                default:
                {
                    base.Load(node);
                }
                break;
                }
            }

            return(true);
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public override bool Load(XmlNode xml)
        {
            if (xml == null || xml.Name != Tag)
            {
                return(false);
            }

            IsHidden = xml.Attributes["hidden"] != null?bool.Parse(xml.Attributes["hidden"].Value) : false;

            Difficulty = xml.Attributes["difficulty"] != null?int.Parse(xml.Attributes["difficulty"].Value) : 0;

            foreach (XmlNode node in xml)
            {
                switch (node.Name.ToLower())
                {
                case "target":
                {
                    Target = new DungeonLocation(node);
                }
                break;

                case "damage":
                {
                    Damage.Load(node);
                }
                break;

                default:
                {
                    base.Load(node);
                }
                break;
                }
            }

            return(true);
        }
Exemple #7
0
        /// <summary>
        /// Teleport the team to a new location, but don't change direction
        /// </summary>
        /// <param name="location">Location in the dungeon</param>
        /// <returns>True if teleportion is ok, or false if M. Spoke failed !</returns>
        public bool Teleport(DungeonLocation location, Dungeon dungeon)
        {
            if (dungeon == null || location == null)
            {
                return(false);
            }

            // Destination maze
            Maze maze = dungeon.GetMaze(location.Maze);

            if (maze == null)
            {
                return(false);
            }

            Maze = maze;

            // Leave current square
            if (Square != null)
            {
                Square.OnTeamLeave();
            }

            // Change location
            Location.Coordinate = location.Coordinate;
            Location.Maze       = Maze.Name;
            Location.Direction  = location.Direction;


            // New block
            Square = Maze.GetSquare(location.Coordinate);

            // Enter new block
            Square.OnTeamEnter();

            return(true);
        }
Exemple #8
0
		/// <summary>
		/// Checks map between monster and teh team to see if can throw projectiles
		/// </summary>
		/// <param name="target">Target location</param>
		/// <returns>True if possible</returns>
		public bool CanDoRangeAttack(DungeonLocation target)
		{
			// Not in the same maze
			if (target.Maze != Location.Maze)
				return false;

			// x or y lined
			if (target.Coordinate.X == Location.Coordinate.X)
			{
				return true;
			}
			else if (target.Coordinate.Y == Location.Coordinate.Y)
			{
				return true;
			}
			else
				return false;

		}
Exemple #9
0
		/// <summary>
		/// Try to move closer to the target while remaining in the square
		/// </summary>
		/// <param name="target">Target point</param>
		/// <returns>True if can get closer</returns>
		public bool IsNear(DungeonLocation target)
		{
			if (target == null)
				throw new ArgumentNullException("target");

			if (Location.Maze != target.Maze)
				return false;

			Point dist = new Point(Location.Coordinate.X - target.Coordinate.X, Location.Coordinate.Y - target.Coordinate.Y);

			return Math.Abs(dist.X) < 5 || Math.Abs(dist.Y) < 5;
		}
		/// <summary>
		/// FAce to a given location
		/// </summary>
		/// <param name="target"></param>
		public void FaceTo(DungeonLocation target)
		{
			if (target == null)
				throw new ArgumentNullException("target");

		}
Exemple #11
0
		/// <summary>
		/// Can the monster detect a presence near him
		/// </summary>
		/// <param name="location">Location to detect</param>
		/// <returns>True if the monster can fell the location</returns>
		public bool CanDetect(DungeonLocation location)
		{
			if (location == null)
				return false;

			// Not in the same maze
			if (Location.Maze != location.Maze)
				return false;

			// Not in sight zone
			if (!DetectionZone.Contains(location.Coordinate))
				return false;


			return true;
		}
Exemple #12
0
		/// <summary>
		/// Default constructor
		/// </summary>
		public Dungeon()
		{
			Mazes = new Dictionary<string, Maze>();
			StartLocation = new DungeonLocation();
		}
Exemple #13
0
		/// <summary>
		/// Defines a square at a given location
		/// </summary>
		/// <param name="target">Location in the dungeon</param>
		/// <param name="square">Square handle</param>
		/// <returns>True on success</returns>
		public bool SetSquare(DungeonLocation target, Square square)
		{
			if (target == null || square == null)
				return false;

			Maze maze = GetMaze(target.Maze);
			if (maze == null)
				return false;

			return maze.SetSquare(target.Coordinate, square);
		}
Exemple #14
0
		/// <summary>
		/// Teleport the team to a new location, but don't change direction
		/// </summary>
		/// <param name="location">Location in the dungeon</param>
		/// <returns>True if teleportion is ok, or false if M. Spoke failed !</returns>
		public bool Teleport(DungeonLocation location, Dungeon dungeon)
		{
			if (dungeon == null || location == null)
				return false;

			// Destination maze
			Maze maze = dungeon.GetMaze(location.Maze);
			if (maze == null)
				return false;

			Maze = maze;

			// Leave current square
			if (Square != null)
				Square.OnTeamLeave();

			// Change location
			Location.Coordinate = location.Coordinate;
			Location.Maze = Maze.Name;
			Location.Direction = location.Direction;


			// New block
			Square = Maze.GetSquare(location.Coordinate);

			// Enter new block
			Square.OnTeamEnter();

			return true;
		}
Exemple #15
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="striker">Striker entity</param>
        /// <param name="Attacked">Attacked entity</param>
        /// <param name="item">Item used as a weapon. Use null for a hand attack</param>
        /// http://nwn2.wikia.com/wiki/Attack_sequence
        public Attack(Entity striker, Entity target, Item item)
        {
            Team team = GameScreen.Team;

            Time    = DateTime.Now;
            Striker = striker;
            Target  = target;
            Item    = item;

            if (striker == null || target == null)
            {
                return;
            }

            // Ranged attack ?
            DungeonLocation from = null;
            DungeonLocation to   = null;

            if (striker is Hero)
            {
                from = team.Location;
            }
            else
            {
                from = ((Monster)striker).Location;
            }

            if (target is Hero)
            {
                to = team.Location;
            }
            else
            {
                to = ((Monster)target).Location;
            }

            Range = (int)Math.Sqrt((from.Coordinate.Y - to.Coordinate.Y) * (from.Coordinate.Y - to.Coordinate.Y) +
                                   (from.Coordinate.X - to.Coordinate.X) * (from.Coordinate.X - to.Coordinate.X));

            // Attack roll
            int attackdie = Dice.GetD20(1);

            // Critical fail ?
            if (attackdie == 1)
            {
                attackdie = -100000;
            }

            // Critical Hit ?
            if (attackdie == 20)
            {
                attackdie = 100000;
            }


            // Base attack bonus
            int baseattackbonus = 0;
            int modifier        = 0;                            // modifier
            int sizemodifier    = 0;                            // Size modifier
            int rangepenality   = 0;                            // Range penality


            if (striker is Hero)
            {
                baseattackbonus = ((Hero)striker).BaseAttackBonus;
            }
            else if (striker is Monster)
            {
                Monster monster = striker as Monster;
                //sizemodifier = (int)monster.Size;
            }


            // Range penality
            if (RangedAttack)
            {
                modifier = striker.Dexterity.Modifier;

                //TODO : Add range penality
            }
            else
            {
                modifier = striker.Strength.Modifier;
            }

            // Attack bonus
            int attackbonus = baseattackbonus + modifier + sizemodifier + rangepenality;

            if (target.ArmorClass > attackdie + attackbonus)
            {
                return;
            }


            if (item != null)
            {
                Hit = item.Damage.Roll();
            }
            else
            {
                Dice dice = new Dice(1, 4, 0);
                Hit = dice.Roll();
            }

            if (IsAHit)
            {
                Target.Hit(this);
            }
        }
Exemple #16
0
		/// <summary>
		/// Returns if two locations are facing each others
		/// </summary>
		/// <param name="from">From location</param>
		/// <param name="target">Target direction</param>
		/// <returns>True if locations face each others</returns>
		static public bool IsFacing(DungeonLocation from, DungeonLocation target)
		{
			Point delta = new Point(target.Coordinate.X - from.Coordinate.X, target.Coordinate.Y - from.Coordinate.Y);
			
			switch (from.Direction)
			{
				case CardinalPoint.North:
					return target.Direction == CardinalPoint.South;

				case CardinalPoint.South:
					return target.Direction == CardinalPoint.North;
	
				case CardinalPoint.West:
					return target.Direction == CardinalPoint.East;
				
				case CardinalPoint.East:
					return target.Direction == CardinalPoint.West;
			}

			return false;
		}
Exemple #17
0
		/// <summary>
		/// Returns the direction in which an entity should face to look at.
		/// </summary>
		/// <param name="from">From location</param>
		/// <param name="target">Target direction</param>
		/// <returns>Direction to face to</returns>
		static public CardinalPoint SeekDirection(DungeonLocation from, DungeonLocation target)
		{
			Point delta = new Point(target.Coordinate.X - from.Coordinate.X, target.Coordinate.Y - from.Coordinate.Y);


			// Move west
			if (delta.X < 0)
			{
				if (delta.Y > 0)
					if (target.Direction == CardinalPoint.North)
						return CardinalPoint.South;
					else
						return CardinalPoint.West;
				else if (delta.Y < 0)
					if (target.Direction == CardinalPoint.South)
						return CardinalPoint.North;
					else
						return CardinalPoint.West;
				else
					return CardinalPoint.West;
			}

			// Move east
			else if (delta.X > 0)
			{
				if (delta.Y > 0)
					if (target.Direction == CardinalPoint.North)
						return CardinalPoint.South;
					else
						return CardinalPoint.East;
				else if (delta.Y < 0)
					if (target.Direction == CardinalPoint.South)
						return CardinalPoint.North;
					else
						return CardinalPoint.East;
				else
					return CardinalPoint.East;
			}

			if (delta.Y > 0)
				return CardinalPoint.South;
			else if (delta.Y < 0)
				return CardinalPoint.North;

			return CardinalPoint.North;
		}
Exemple #18
0
 /// <summary>
 /// Teleports the team into the current dungeon
 /// </summary>
 /// <param name="location">Location in the dungeon</param>
 /// <returns>True if teleportion is ok, or false if M. Spoke failed !</returns>
 public bool Teleport(DungeonLocation location)
 {
     return(Teleport(location, GameScreen.Dungeon));
 }
Exemple #19
0
        /// <summary>
        /// Teleport to a new maze
        /// </summary>
        /// <param name="name">Name of the maze</param>
        /// <returns>True on success</returns>
        public bool Teleport(string name)
        {
            DungeonLocation loc = new DungeonLocation(name, Location.Coordinate);

            return(Teleport(loc));
        }
Exemple #20
0
		/// <summary>
		/// Checks if the monster can do close combat with the target
		/// </summary>
		/// <param name="target">Target location</param>
		/// <returns>True if possible</returns>
		public bool CanDoCloseAttack(DungeonLocation target)
		{
			// Not in the same maze
			if (target.Maze != Location.Maze)
				return false;

			// If can get closer to the target
			if (CanGetCloserTo(target))
				return false;

			// Find the distance
			Point dist = new Point(target.Coordinate.X - Location.Coordinate.X, target.Coordinate.Y - Location.Coordinate.Y);

			// Close to the target (up, down or left, right)
			return (dist.X == 0 && Math.Abs(dist.Y) == 1) ||
					(Math.Abs(dist.X) == 1 && dist.Y == 0);
		}
Exemple #21
0
		/// <summary>
		/// Teleport to a new maze
		/// </summary>
		/// <param name="name">Name of the maze</param>
		/// <returns>True on success</returns>
		public bool Teleport(string name)
		{
			DungeonLocation loc = new DungeonLocation(name, Location.Coordinate);
			return Teleport(loc);
		}
Exemple #22
0
		/// <summary>
		/// Draw the maze
		/// </summary>
		/// <param name="batch">SpriteBatch to use</param>
		/// <param name="location">Location to display from</param>
		/// <see cref="http://eob.wikispaces.com/eob.vmp"/>
		public void Draw(SpriteBatch batch, DungeonLocation location)
		{
			if (WallTileset == null)
				return;

			// Clear the spritebatch
			batch.End();
			Display.PushScissor(new Rectangle(0, 0, 352, 240));
			batch.Begin();


			//
			// 
			//
			ViewField pov = new ViewField(this, location);


			// TODO Backdrop
			// The background is assumed to be x-flipped when party.x & party.y & party.direction = 1.
			// I.e. all kind of moves and rotations from the current position will result in the background being x-flipped.
			bool flipbackdrop = ((location.Coordinate.X + location.Coordinate.Y + (int)location.Direction) & 1) == 0;
			SpriteEffects effect = flipbackdrop ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
			batch.DrawTile(WallTileset, 0, Point.Empty, Color.White, 0.0f, effect, 0.0f);

			// maze block draw order
			// A E B D C
			// F J G I H
			//   K M L
			//   N ^ O

			#region row -3
			DrawSquare(batch, pov, ViewFieldPosition.A, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.E, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.B, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.D, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.C, location.Direction);
			#endregion

			#region row -2
			DrawSquare(batch, pov, ViewFieldPosition.F, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.J, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.G, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.I, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.H, location.Direction);
			#endregion

			#region row -1
			DrawSquare(batch, pov, ViewFieldPosition.K, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.M, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.L, location.Direction);
			#endregion

			#region row 0
			DrawSquare(batch, pov, ViewFieldPosition.N, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.Team, location.Direction);
			DrawSquare(batch, pov, ViewFieldPosition.O, location.Direction);
			#endregion


			// Clear the spritebatch
			batch.End();
			Display.PopScissor();
			batch.Begin();

		}
Exemple #23
0
		/// <summary>
		/// Teleports the team into the current dungeon
		/// </summary>
		/// <param name="location">Location in the dungeon</param>
		/// <returns>True if teleportion is ok, or false if M. Spoke failed !</returns>
		public bool Teleport(DungeonLocation location)
		{
			return Teleport(location, GameScreen.Dungeon);
		}
Exemple #24
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="maze">Maze handle</param>
		/// <param name="location">View's location</param>
		public ViewField(Maze maze, DungeonLocation location)
		{
			Maze = maze;
			Blocks = new Square[16];


			// Cone of vision : 15 blocks + 1 block for the Point of View
			//
			//    ABCDE
			//    FGHIJ
			//     KLM
			//     N^O
			//
			// ^ => Point of view
			switch (location.Direction)
			{
				#region North
				case CardinalPoint.North:
				{
					Blocks[0] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y - 3));
					Blocks[1] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y - 3));
					Blocks[2] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y - 3));
					Blocks[3] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y - 3));
					Blocks[4] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y - 3));

					Blocks[5] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y - 2));
					Blocks[6] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y - 2));
					Blocks[7] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y - 2));
					Blocks[8] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y - 2));
					Blocks[9] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y - 2));

					Blocks[10] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y - 1));
					Blocks[11] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y - 1));
					Blocks[12] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y - 1));

					Blocks[13] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y));
					Blocks[15] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y));

				}
				break;
				#endregion

				#region South
				case CardinalPoint.South:
				{
					Blocks[0] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y + 3));
					Blocks[1] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y + 3));
					Blocks[2] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y + 3));
					Blocks[3] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y + 3));
					Blocks[4] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y + 3));

					Blocks[5] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y + 2));
					Blocks[6] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y + 2));
					Blocks[7] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y + 2));
					Blocks[8] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y + 2));
					Blocks[9] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y + 2));

					Blocks[10] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y + 1));
					Blocks[11] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y + 1));
					Blocks[12] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y + 1));

					Blocks[13] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y));
					Blocks[15] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y));
				}
				break;
				#endregion

				#region East
				case CardinalPoint.East:
				{
					Blocks[0] = maze.GetSquare(new Point(location.Coordinate.X + 3, location.Coordinate.Y - 2));
					Blocks[1] = maze.GetSquare(new Point(location.Coordinate.X + 3, location.Coordinate.Y - 1));
					Blocks[2] = maze.GetSquare(new Point(location.Coordinate.X + 3, location.Coordinate.Y));
					Blocks[3] = maze.GetSquare(new Point(location.Coordinate.X + 3, location.Coordinate.Y + 1));
					Blocks[4] = maze.GetSquare(new Point(location.Coordinate.X + 3, location.Coordinate.Y + 2));

					Blocks[5] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y - 2));
					Blocks[6] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y - 1));
					Blocks[7] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y));
					Blocks[8] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y + 1));
					Blocks[9] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y + 2));

					Blocks[10] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y - 1));
					Blocks[11] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y));
					Blocks[12] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y + 1));

					Blocks[13] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y - 1));
					Blocks[15] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y + 1));
				}
				break;
				#endregion

				#region West
				case CardinalPoint.West:
				{
					Blocks[0] = maze.GetSquare(new Point(location.Coordinate.X - 3, location.Coordinate.Y + 2));
					Blocks[1] = maze.GetSquare(new Point(location.Coordinate.X - 3, location.Coordinate.Y + 1));
					Blocks[2] = maze.GetSquare(new Point(location.Coordinate.X - 3, location.Coordinate.Y));
					Blocks[3] = maze.GetSquare(new Point(location.Coordinate.X - 3, location.Coordinate.Y - 1));
					Blocks[4] = maze.GetSquare(new Point(location.Coordinate.X - 3, location.Coordinate.Y - 2));

					Blocks[5] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y + 2));
					Blocks[6] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y + 1));
					Blocks[7] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y));
					Blocks[8] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y - 1));
					Blocks[9] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y - 2));

					Blocks[10] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y + 1));
					Blocks[11] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y));
					Blocks[12] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y - 1));

					Blocks[13] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y + 1));
					Blocks[15] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y - 1));
				}
				break;
				#endregion
			}

			// Team's position
			Blocks[14] = maze.GetSquare(location.Coordinate);
		}
Exemple #25
0
		/// <summary>
		/// Clears the dungeon
		/// </summary>
		public void Clear()
		{
			foreach (Maze maze in Mazes.Values)
				maze.Dispose();
			Mazes.Clear();

			StartLocation = new DungeonLocation(StartLocation);
		}
Exemple #26
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="xml"></param>
		/// <returns></returns>
		public override bool Load(XmlNode xml)
		{
			if (xml == null || xml.Name != Tag)
				return false;

			IsVisible = xml.Attributes["visible"] != null ? bool.Parse(xml.Attributes["visible"].Value) : false;
			TeleportTeam = xml.Attributes["team"] != null ? bool.Parse(xml.Attributes["team"].Value) : false;
			TeleportItems = xml.Attributes["items"] != null ? bool.Parse(xml.Attributes["items"].Value) : false;
			TeleportMonsters = xml.Attributes["monster"] != null ? bool.Parse(xml.Attributes["monster"].Value) : false;
			Reusable = xml.Attributes["resuable"] != null ? bool.Parse(xml.Attributes["reusable"].Value) : false;

			foreach (XmlNode node in xml)
			{
				switch (node.Name.ToLower())
				{
					case "target":
					{
						Target = new DungeonLocation();
						Target.Load(node);
					}
					break;

					default:
					{
						base.Load(node);
					}
					break;
				}

			}

			return true;
		}
Exemple #27
0
		/// <summary>
		/// Loads a <see cref="Dungeon"/>
		/// </summary>
		/// <param name="xml"></param>
		/// <returns>True on success</returns>
		public bool Load(XmlNode xml)
		{
			if (xml == null || xml.Name != Tag)
			{
				Trace.WriteLine("[Dungeon] Expecting \"" + XmlTag + "\" in node header, found \"" + xml.Name + "\" when loading Dungeon.");
				return false;
			}

			Name = xml.Attributes["name"].Value;

			foreach (XmlNode node in xml)
			{
				if (node.NodeType == XmlNodeType.Comment)
					continue;


				switch (node.Name.ToLower())
				{
					case Item.Tag:
					{
						ItemTileSetName = node.Attributes["tileset"].Value;
					}
					break;

					case Maze.Tag:
					{
						string name = node.Attributes["name"].Value;
						Maze maze = new Maze(this);
						maze.Name = name;
						Mazes[name] = maze;
						maze.Load(node);
					}
					break;

					case "start":
					{
						StartLocation = new DungeonLocation(node);
					}
					break;


					case "note":
					{
						Note = node.InnerText;
					}
					break;
				}


			}

			return true;
		}
Exemple #28
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override DungeonLocation[] GetTargets()
        {
            DungeonLocation[] target = new DungeonLocation[] { Target };

            return(target);
        }
Exemple #29
0
		/// <summary>
		/// Hero attack with his hands
		/// </summary>
		/// <param name="hand">Attacking hand</param>
		public void UseHand(HeroHand hand)
		{
			// No action possible
			if (!CanUseHand(hand))
				return;

			Team team = GameScreen.Team;

			// Find the entity in front of the hero
			Entity target = team.GetFrontEntity(team.GetHeroGroundPosition(this));


			// Which item is used for the attack
			Item item = GetInventoryItem(hand == HeroHand.Primary ? InventoryPosition.Primary : InventoryPosition.Secondary);
			CardinalPoint side = Compass.GetOppositeDirection(team.Direction);

			// Hand attack
			if (item == null)
			{
				if (team.IsHeroInFront(this))
				{
					if (team.FrontSquare != null)
						team.FrontSquare.OnBash(side, item);
					else
						Attacks[(int)hand] = new Attack(this, target, null);
				}
				else
					HandActions[(int)hand] = new HandAction(ActionResult.CantReach);

				AddHandPenality(hand, TimeSpan.FromMilliseconds(250));
				return;
			}



			// Use item
			DungeonLocation loc = new DungeonLocation(team.Location);
			loc.Position = team.GetHeroGroundPosition(this);
			switch (item.Type)
			{

				#region Ammo
				case ItemType.Ammo:
				{
					// throw ammo
					team.Maze.ThrownItems.Add(new ThrownItem(this, item, loc, TimeSpan.FromSeconds(0.25), int.MaxValue));

					// Empty hand
					SetInventoryItem(hand == HeroHand.Primary ? InventoryPosition.Primary : InventoryPosition.Secondary, null);
				}
				break;
				#endregion


				#region Scroll
				case ItemType.Scroll:
				break;
				#endregion


				#region Wand
				case ItemType.Wand:
				break;
				#endregion


				#region Weapon
				case ItemType.Weapon:
				{
					// Belt weapon
					if (item.Slot == BodySlot.Belt)
					{
					}

					// Weapon use quiver
					else if (item.UseQuiver)
					{
						if (Quiver > 0)
						{
							team.Maze.ThrownItems.Add(
								new ThrownItem(this, ResourceManager.CreateAsset<Item>("Arrow"),
								loc, TimeSpan.FromSeconds(0.25), int.MaxValue));
							Quiver--;
						}
						else
							HandActions[(int)hand] = new HandAction(ActionResult.NoAmmo);

						AddHandPenality(hand, TimeSpan.FromMilliseconds(500));
					}

					else
					{
						// Check is the weapon can reach the target
						if (team.IsHeroInFront(this) && item.Range == 0)
						{
							// Attack front monster
							if (target != null)
							{
								Attacks[(int)hand] = new Attack(this, target, item);
							}
							else if (team.FrontSquare != null)
								team.FrontSquare.OnHack(side, item);
							else
								Attacks[(int)hand] = new Attack(this, target, item);
						}
						else
							HandActions[(int)hand] = new HandAction(ActionResult.CantReach);

						AddHandPenality(hand, item.AttackSpeed);
					}
				}
				break;
				#endregion


				#region Holy symbol or book
				case ItemType.HolySymbol:
				case ItemType.Book:
				{
					GameScreen.SpellBook.Open(this, item);

					//Spell spell = ResourceManager.CreateAsset<Spell>("CreateFood");
					//spell.Init();
					//spell.Script.Instance.OnCast(spell, this);
				}
				break;
				#endregion
			}

		}
Exemple #30
0
		/// <summary>
		/// Gets if the monster can see the given location
		/// </summary>
		/// <returns>True if the point is in range of sight</returns>
		public bool CanSee(DungeonLocation location)
		{
			if (location == null)
				return false;

			// Not in the same maze
			if (Location.Maze != location.Maze)
				return false;

			// Not in sight zone
			if (!SightZone.Contains(location.Coordinate))
				return false;

			// Check in straight line
			Point vector = new Point(Location.Coordinate.X - location.Coordinate.X, Location.Coordinate.Y - location.Coordinate.Y);
			while (!vector.IsEmpty)
			{
				if (vector.X > 0)
					vector.X--;
				else if (vector.X < 0)
					vector.X++;

				if (vector.Y > 0)
					vector.Y--;
				else if (vector.Y < 0)
					vector.Y++;

				Square block = Maze.GetSquare(new Point(location.Coordinate.X + vector.X, Location.Coordinate.Y + vector.Y));
				if (block.IsWall)
					return false;
			}


			// Location is visible
			return true;
		}
Exemple #31
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="maze">Maze handle</param>
        /// <param name="location">View's location</param>
        public ViewField(Maze maze, DungeonLocation location)
        {
            Maze   = maze;
            Blocks = new Square[16];


            // Cone of vision : 15 blocks + 1 block for the Point of View
            //
            //    ABCDE
            //    FGHIJ
            //     KLM
            //     N^O
            //
            // ^ => Point of view
            switch (location.Direction)
            {
                #region North
            case CardinalPoint.North:
            {
                Blocks[0] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y - 3));
                Blocks[1] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y - 3));
                Blocks[2] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y - 3));
                Blocks[3] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y - 3));
                Blocks[4] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y - 3));

                Blocks[5] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y - 2));
                Blocks[6] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y - 2));
                Blocks[7] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y - 2));
                Blocks[8] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y - 2));
                Blocks[9] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y - 2));

                Blocks[10] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y - 1));
                Blocks[11] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y - 1));
                Blocks[12] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y - 1));

                Blocks[13] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y));
                Blocks[15] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y));
            }
            break;
                #endregion

                #region South
            case CardinalPoint.South:
            {
                Blocks[0] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y + 3));
                Blocks[1] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y + 3));
                Blocks[2] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y + 3));
                Blocks[3] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y + 3));
                Blocks[4] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y + 3));

                Blocks[5] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y + 2));
                Blocks[6] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y + 2));
                Blocks[7] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y + 2));
                Blocks[8] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y + 2));
                Blocks[9] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y + 2));

                Blocks[10] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y + 1));
                Blocks[11] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y + 1));
                Blocks[12] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y + 1));

                Blocks[13] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y));
                Blocks[15] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y));
            }
            break;
                #endregion

                #region East
            case CardinalPoint.East:
            {
                Blocks[0] = maze.GetSquare(new Point(location.Coordinate.X + 3, location.Coordinate.Y - 2));
                Blocks[1] = maze.GetSquare(new Point(location.Coordinate.X + 3, location.Coordinate.Y - 1));
                Blocks[2] = maze.GetSquare(new Point(location.Coordinate.X + 3, location.Coordinate.Y));
                Blocks[3] = maze.GetSquare(new Point(location.Coordinate.X + 3, location.Coordinate.Y + 1));
                Blocks[4] = maze.GetSquare(new Point(location.Coordinate.X + 3, location.Coordinate.Y + 2));

                Blocks[5] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y - 2));
                Blocks[6] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y - 1));
                Blocks[7] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y));
                Blocks[8] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y + 1));
                Blocks[9] = maze.GetSquare(new Point(location.Coordinate.X + 2, location.Coordinate.Y + 2));

                Blocks[10] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y - 1));
                Blocks[11] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y));
                Blocks[12] = maze.GetSquare(new Point(location.Coordinate.X + 1, location.Coordinate.Y + 1));

                Blocks[13] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y - 1));
                Blocks[15] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y + 1));
            }
            break;
                #endregion

                #region West
            case CardinalPoint.West:
            {
                Blocks[0] = maze.GetSquare(new Point(location.Coordinate.X - 3, location.Coordinate.Y + 2));
                Blocks[1] = maze.GetSquare(new Point(location.Coordinate.X - 3, location.Coordinate.Y + 1));
                Blocks[2] = maze.GetSquare(new Point(location.Coordinate.X - 3, location.Coordinate.Y));
                Blocks[3] = maze.GetSquare(new Point(location.Coordinate.X - 3, location.Coordinate.Y - 1));
                Blocks[4] = maze.GetSquare(new Point(location.Coordinate.X - 3, location.Coordinate.Y - 2));

                Blocks[5] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y + 2));
                Blocks[6] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y + 1));
                Blocks[7] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y));
                Blocks[8] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y - 1));
                Blocks[9] = maze.GetSquare(new Point(location.Coordinate.X - 2, location.Coordinate.Y - 2));

                Blocks[10] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y + 1));
                Blocks[11] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y));
                Blocks[12] = maze.GetSquare(new Point(location.Coordinate.X - 1, location.Coordinate.Y - 1));

                Blocks[13] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y + 1));
                Blocks[15] = maze.GetSquare(new Point(location.Coordinate.X, location.Coordinate.Y - 1));
            }
            break;
                #endregion
            }

            // Team's position
            Blocks[14] = maze.GetSquare(location.Coordinate);
        }
Exemple #32
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="node"></param>
		/// <returns></returns>
		public override bool Load(XmlNode xml)
		{
			if (xml == null || xml.Name != Tag)
				return false;

			Type = xml.Attributes["type"] != null ? (StairType)Enum.Parse(typeof(StairType), xml.Attributes["type"].Value) : StairType.Up;

			foreach (XmlNode node in xml)
			{
				switch (node.Name.ToLower())
				{
					case "target":
					{
						Target = new DungeonLocation();
						Target.Load(node);
					}
					break;

					default:
					{
						base.Load(node);
					}
					break;
				}

			}

			return true;
		}
Exemple #33
0
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public override DungeonLocation[] GetTargets()
		{
			DungeonLocation[] target = new DungeonLocation[] { Target };

			return target;
		}
Exemple #34
0
        /// <summary>
        /// Returns the direction in which an entity should face to look at.
        /// </summary>
        /// <param name="from">From location</param>
        /// <param name="target">Target direction</param>
        /// <returns>Direction to face to</returns>
        static public CardinalPoint SeekDirection(DungeonLocation from, DungeonLocation target)
        {
            Point delta = new Point(target.Coordinate.X - from.Coordinate.X, target.Coordinate.Y - from.Coordinate.Y);


            // Move west
            if (delta.X < 0)
            {
                if (delta.Y > 0)
                {
                    if (target.Direction == CardinalPoint.North)
                    {
                        return(CardinalPoint.South);
                    }
                    else
                    {
                        return(CardinalPoint.West);
                    }
                }
                else if (delta.Y < 0)
                {
                    if (target.Direction == CardinalPoint.South)
                    {
                        return(CardinalPoint.North);
                    }
                    else
                    {
                        return(CardinalPoint.West);
                    }
                }
                else
                {
                    return(CardinalPoint.West);
                }
            }

            // Move east
            else if (delta.X > 0)
            {
                if (delta.Y > 0)
                {
                    if (target.Direction == CardinalPoint.North)
                    {
                        return(CardinalPoint.South);
                    }
                    else
                    {
                        return(CardinalPoint.East);
                    }
                }
                else if (delta.Y < 0)
                {
                    if (target.Direction == CardinalPoint.South)
                    {
                        return(CardinalPoint.North);
                    }
                    else
                    {
                        return(CardinalPoint.East);
                    }
                }
                else
                {
                    return(CardinalPoint.East);
                }
            }

            if (delta.Y > 0)
            {
                return(CardinalPoint.South);
            }
            else if (delta.Y < 0)
            {
                return(CardinalPoint.North);
            }

            return(CardinalPoint.North);
        }
		/// <summary>
		/// Facing a given location
		/// </summary>
		/// <param name="location">Location to check</param>
		/// <returns>True if facing, or false</returns>
		public bool IsFacing(DungeonLocation location)
		{
			Point offset = new Point(location.Coordinate.X - Coordinate.X, location.Coordinate.Y - Coordinate.Y);

			switch (Direction)
			{
				case CardinalPoint.North:
				{
					if (offset.X <= 0 && offset.Y <= 0)
					return true;
				}
				break;
				case CardinalPoint.South:
				{
					if (offset.X >= 0 && offset.Y >= 0)
						return true;
				}
				break;
				case CardinalPoint.West:
				{
					if (offset.X <= 0 && offset.Y >= 0)
						return true;
				}
				break;
				case CardinalPoint.East:
				{
					if (offset.X >= 0 && offset.Y <= 0)
						return true;
				}
				break;
			}

			return false;
		}
Exemple #36
0
		/// <summary>
		/// Try to move closer to the target while remaining in the square
		/// </summary>
		/// <param name="target">Target point</param>
		/// <returns>True if can get closer</returns>
		public bool CanGetCloserTo(DungeonLocation target)
		{
			if (target == null)
				return false;

			// Monster is alone in the square
			if (Position == SquarePosition.Center)
				return false;

			Point dist = new Point(Location.Coordinate.X - target.Coordinate.X, Location.Coordinate.Y - target.Coordinate.Y);

			switch (Position)
			{
				#region North west
				case SquarePosition.NorthWest:
				{

					// 
					if (dist.X < 0)
					{
						if (Square.Monsters[(int)SquarePosition.SouthEast] == null || Square.Monsters[(int)SquarePosition.SouthWest] == null)
							return true;
					}
					//
					else if (dist.X > 0)
					{
					}

					// Above
					if (dist.Y > 0)
					{
					}

					// Below
					else if (dist.Y < 0)
					{
						if (Square.GetMonster(SquarePosition.SouthWest) == null || Square.GetMonster(SquarePosition.SouthEast) == null)
							return true;
					}
				}
				break;
				#endregion

				#region North east
				case SquarePosition.NorthEast:
				{

					// Right
					if (dist.X < 0)
					{
					}

					// Left
					else if (dist.X > 0)
					{
						if (Square.GetMonster(SquarePosition.NorthWest) == null || Square.GetMonster(SquarePosition.SouthWest) == null)
							return true;
					}

					// Below
					if (dist.Y < 0)
					{
						if (Square.Monsters[(int)SquarePosition.SouthEast] == null || Square.Monsters[(int)SquarePosition.SouthWest] == null)
							return true;
					}
					else if (dist.Y > 0)
					{
					}
				}
				break;
				#endregion

				#region South west
				case SquarePosition.SouthWest:
				{
					// Right
					if (dist.X < 0)
					{
						if (Square.GetMonster(SquarePosition.SouthEast) == null || Square.GetMonster(SquarePosition.NorthEast) == null)
							return true;
					}

					// Left
					else if (dist.X > 0)
					{
					}

					// Above
					if (dist.Y > 0)
					{
						if (Square.GetMonster(SquarePosition.NorthWest) == null || Square.GetMonster(SquarePosition.NorthEast) == null)
							return true;
					}

					// Below
					else if (dist.Y < 0)
					{
					}
				}
				break;
				#endregion

				#region South east
				case SquarePosition.SouthEast:
				{

					// Left
					if (dist.X > 0)
					{
						// No monster in SW
						if (Square.GetMonster(SquarePosition.SouthWest) == null || Square.GetMonster(SquarePosition.NorthWest) == null)
							return true;
					}

					// Right
					else if (dist.X < 0)
					{
					}


					// Below
					if (dist.Y < 0)
					{
					}

					// Above
					else if (dist.Y > 0)
					{
						if (Square.GetMonster(SquarePosition.NorthEast) == null || Square.GetMonster(SquarePosition.NorthWest) == null)
							return true;
					}
				}
				break;
				#endregion
			}


			return false;
		}
Exemple #37
0
		/// <summary>
		/// Update the Team status
		/// </summary>
		/// <param name="time">Time passed since the last call to the last update.</param>
		/// <param name="hasFocus">Put it true if Game Screen is focused</param>
		/// <param name="isCovered">Put it true if Game Screen has something over it</param>
		public override void Update(GameTime time, bool hasFocus, bool isCovered)
		{

			#region Dialog

			if (Dialog != null)
			{
				if (Dialog.Quit)
					Dialog = null;
				else
				{
					Dialog.Update(time);
					return;
				}
			}

			#endregion


			//	Team.HasMoved = false;


			#region Keyboard

			// Bye bye
			if (Keyboard.IsNewKeyPress(Keys.Escape))
			{
				ScreenManager.AddScreen(new MainMenu());
				ExitScreen();
				return;
			}


			// AutoMap
			if (Keyboard.IsNewKeyPress(Keys.Tab))
			{
				ScreenManager.AddScreen(new AutoMap(Batch));
			}


			// Debug
			if (Keyboard.IsNewKeyPress(Keys.Space))
				Debug = !Debug;

			// Save team
			if (Keyboard.IsNewKeyPress(Keys.J))
			{
				SaveGameSlot(0);
			}

			// Load team
			if (Dialog != null && Keyboard.IsNewKeyPress(Keys.L))
			{
				OpenCampPanel();
				((CampDialog)Dialog).AddWindow(new Gui.CampWindows.LoadGameWindow(Dialog as CampDialog));
			}

			if (Team.Location == null)
				return;


			#region Change maze
			for (int i = 0; i < 12; i++)
			{
				if (Keyboard.IsNewKeyPress(Keys.F1 + i))
				{
					int id = i + 1;
					string lvl = "0" + id.ToString();
					lvl = "Catacomb - " + lvl.Substring(lvl.Length - 2, 2);

					if (Team.Teleport(lvl))
						GameMessage.AddMessage("Loading " + lvl + ":" + Team.Maze.Description);

					break;
				}
			}

			// Test maze
			if (Keyboard.IsNewKeyPress(Keys.T))
			{
				if (Team.Teleport("test"))
					GameMessage.AddMessage("Loading maze test", GameColors.Blue);
			}

			// Forest maze
			if (Keyboard.IsNewKeyPress(Keys.F))
			{
				if (Team.Teleport("Forest"))
					GameMessage.AddMessage("Loading maze forest", Color.Blue);
			}

			#endregion


			#region Team move & managment

			//// Display inventory
			//if (Keyboard.IsNewKeyPress(InputScheme["Inventory"]))
			//{
			//	if (Interface == TeamInterface.Inventory)
			//		Interface = TeamInterface.Main;
			//	else
			//		Interface = TeamInterface.Inventory;
			//}


			// Turn left
			if (Keyboard.IsNewKeyPress(InputScheme["TurnLeft"]))
				Team.Location.Direction = Compass.Rotate(Team.Location.Direction, CompassRotation.Rotate270);


			// Turn right
			if (Keyboard.IsNewKeyPress(InputScheme["TurnRight"]))
				Team.Location.Direction = Compass.Rotate(Team.Location.Direction, CompassRotation.Rotate90);


			// Move forward
			if (Keyboard.IsNewKeyPress(InputScheme["MoveForward"]))
				Team.Walk(0, -1);


			// Move backward
			if (Keyboard.IsNewKeyPress(InputScheme["MoveBackward"]))
				Team.Walk(0, 1);


			// Strafe left
			if (Keyboard.IsNewKeyPress(InputScheme["StrafeLeft"]))
				Team.Walk(-1, 0);

			// Strafe right
			if (Keyboard.IsNewKeyPress(InputScheme["StrafeRight"]))
				Team.Walk(1, 0);

			//// Select Hero
			//for (int i = 0; i < Team.HeroCount; i++)
			//{
			//	Keys key = InputScheme[string.Format("SelectHero{0}", i + 1)];
			//             if (Keyboard.IsNewKeyPress(key))
			//	{
			//		if (Team.SelectedHero == Team.Heroes[i] && Interface != TeamInterface.Inventory)
			//		{
			//			Interface = TeamInterface.Inventory;
			//			Keyboard.ConsumeNewKeyPress(key);
			//		}
			//		else if (Team.SelectedHero != Team.Heroes[i])
			//		{
			//			Team.SelectedHero = Team.Heroes[i];
			//			//Keyboard.ConsumeNewKeyPress(key);
			//		}
			//	}
			//}



			#endregion


			#endregion


			SquarePosition groundpos = SquarePosition.NorthEast;
			Point mousePos = Mouse.Location;

			// Get the square at team position
			Square square = Team.Maze.GetSquare(Team.Location.Coordinate);


			#region Mouse

			#region Left mouse button
			if (Mouse.IsNewButtonDown(MouseButtons.Left) && Dialog == null)
			{

				#region Direction buttons
				// Turn left
				if (InterfaceCoord.TurnLeft.Contains(mousePos))
					Team.Location.Direction = Compass.Rotate(Team.Location.Direction, CompassRotation.Rotate270);

				// Move Forward
				else if (InterfaceCoord.MoveForward.Contains(mousePos))
					Team.Walk(0, -1);

				// Turn right
				else if (InterfaceCoord.TurnRight.Contains(mousePos))
					Team.Location.Direction = Compass.Rotate(Team.Location.Direction, CompassRotation.Rotate90);

				// Move left
				else if (InterfaceCoord.MoveLeft.Contains(mousePos))
					Team.Walk(-1, 0);

				// Backward
				else if (InterfaceCoord.MoveBackward.Contains(mousePos))
				{
					if (!Team.Walk(0, 1))
						GameMessage.BuildMessage(1);
				}
				// Move right
				else if (InterfaceCoord.MoveRight.Contains(mousePos))
				{
					if (!Team.Walk(1, 0))
						GameMessage.BuildMessage(1);
				}
				#endregion

				#region Camp button
				else if (DisplayCoordinates.CampButton.Contains(mousePos))
				{
					OpenCampPanel();
				}
				#endregion


				#region Gather item on the ground Left

				// Team's feet
				else if (DisplayCoordinates.LeftFeetTeam.Contains(mousePos))
				{
					switch (Team.Direction)
					{
						case CardinalPoint.North:
						groundpos = SquarePosition.NorthWest;
						break;
						case CardinalPoint.East:
						groundpos = SquarePosition.NorthEast;
						break;
						case CardinalPoint.South:
						groundpos = SquarePosition.SouthEast;
						break;
						case CardinalPoint.West:
						groundpos = SquarePosition.SouthWest;
						break;
					}
					if (Team.ItemInHand != null)
					{
						if (square.DropItem(groundpos, Team.ItemInHand))
							Team.SetItemInHand(null);
					}
					else
					{
						Team.SetItemInHand(square.CollectItem(groundpos));
					}
				}

				// In front of the team
				else if (!Team.FrontSquare.IsWall && DisplayCoordinates.LeftFrontTeamGround.Contains(mousePos))
				{
					// Ground position
					switch (Team.Location.Direction)
					{
						case CardinalPoint.North:
						groundpos = SquarePosition.SouthWest;
						break;
						case CardinalPoint.East:
						groundpos = SquarePosition.NorthWest;
						break;
						case CardinalPoint.South:
						groundpos = SquarePosition.NorthEast;
						break;
						case CardinalPoint.West:
						groundpos = SquarePosition.SouthEast;
						break;
					}


					if (Team.ItemInHand != null)
					{
						if (Team.FrontSquare.DropItem(groundpos, Team.ItemInHand))
							Team.SetItemInHand(null);
					}
					else
						Team.SetItemInHand(Team.FrontSquare.CollectItem(groundpos));
				}


				#endregion

				#region Gather item on the ground right
				else if (DisplayCoordinates.RightFeetTeam.Contains(mousePos))
				{
					switch (Team.Location.Direction)
					{
						case CardinalPoint.North:
						groundpos = SquarePosition.NorthEast;
						break;
						case CardinalPoint.East:
						groundpos = SquarePosition.SouthEast;
						break;
						case CardinalPoint.South:
						groundpos = SquarePosition.SouthWest;
						break;
						case CardinalPoint.West:
						groundpos = SquarePosition.NorthWest;
						break;
					}

					if (Team.ItemInHand != null)
					{
						if (square.DropItem(groundpos, Team.ItemInHand))
							Team.SetItemInHand(null);
					}
					else
					{
						Team.SetItemInHand(square.CollectItem(groundpos));
						//if (ItemInHand != null)
						//    AddMessage(Language.BuildMessage(2, ItemInHand.Name));

					}
				}

				// In front of the team
				else if (!Team.FrontSquare.IsWall && DisplayCoordinates.RightFrontTeamGround.Contains(mousePos))
				{

					// Ground position
					switch (Team.Location.Direction)
					{
						case CardinalPoint.North:
						groundpos = SquarePosition.SouthEast;
						break;
						case CardinalPoint.East:
						groundpos = SquarePosition.SouthWest;
						break;
						case CardinalPoint.South:
						groundpos = SquarePosition.NorthWest;
						break;
						case CardinalPoint.West:
						groundpos = SquarePosition.NorthEast;
						break;
					}


					if (Team.ItemInHand != null)
					{
						if (Team.FrontSquare.DropItem(groundpos, Team.ItemInHand))
							Team.SetItemInHand(null);
					}
					else
					{
						Team.SetItemInHand(Team.FrontSquare.CollectItem(groundpos));
						//if (ItemInHand != null)
						//    AddMessage(Language.BuildMessage(2, ItemInHand.Name));
					}
				}

				#endregion

				#region Action to process on the front square

				// Click on the square in front of the team
				else if (DisplayCoordinates.FrontSquare.Contains(mousePos))
				{
					// On no action on the front wall
					if (!Team.FrontSquare.OnClick(mousePos, Team.FrontWallSide, MouseButtons.Left))
					{
						#region Throw an object in the left side
						if (DisplayCoordinates.ThrowLeft.Contains(mousePos) && Team.ItemInHand != null)
						{
							DungeonLocation loc = new DungeonLocation(Team.Location);
							switch (Team.Location.Direction)
							{
								case CardinalPoint.North:
								loc.Position = SquarePosition.SouthWest;
								break;
								case CardinalPoint.East:
								loc.Position = SquarePosition.NorthWest;
								break;
								case CardinalPoint.South:
								loc.Position = SquarePosition.NorthEast;
								break;
								case CardinalPoint.West:
								loc.Position = SquarePosition.SouthEast;
								break;
							}
							Team.Maze.ThrownItems.Add(new ThrownItem(Team.SelectedHero, Team.ItemInHand, loc, TimeSpan.FromSeconds(0.25), 4));
							Team.SetItemInHand(null);
						}
						#endregion

						#region Throw an object in the right side
						else if (DisplayCoordinates.ThrowRight.Contains(mousePos) && Team.ItemInHand != null)
						{

							DungeonLocation loc = new DungeonLocation(Team.Location);

							switch (Team.Location.Direction)
							{
								case CardinalPoint.North:
								loc.Position = SquarePosition.SouthEast;
								break;
								case CardinalPoint.East:
								loc.Position = SquarePosition.SouthWest;
								break;
								case CardinalPoint.South:
								loc.Position = SquarePosition.NorthWest;
								break;
								case CardinalPoint.West:
								loc.Position = SquarePosition.NorthEast;
								break;
							}

							Team.Maze.ThrownItems.Add(new ThrownItem(Team.SelectedHero, Team.ItemInHand, loc, TimeSpan.FromSeconds(0.25), 4));
							Team.SetItemInHand(null);
						}
						#endregion
					}
				}
				#endregion
			}

			#endregion

			#region Right mouse button

			else if (Mouse.IsNewButtonDown(MouseButtons.Right))
			{
				#region Alcove
				//if (DisplayCoordinates.Alcove.Contains(mousePos) && Team.FrontSquare.IsWall)
				//{
				//    Team.SelectedHero.AddToInventory(Team.FrontSquare.CollectItemFromSide(Team.FrontWallSide));
				//}
				#endregion

				#region Gather item on the ground Left

				// Team's feet
				if (DisplayCoordinates.LeftFeetTeam.Contains(mousePos))
				{
					switch (Team.Direction)
					{
						case CardinalPoint.North:
						groundpos = SquarePosition.NorthWest;
						break;
						case CardinalPoint.East:
						groundpos = SquarePosition.NorthEast;
						break;
						case CardinalPoint.South:
						groundpos = SquarePosition.SouthEast;
						break;
						case CardinalPoint.West:
						groundpos = SquarePosition.SouthWest;
						break;
					}
					if (Team.ItemInHand == null)
					{
						Item item = square.CollectItem(groundpos);
						if (item != null)
						{
							if (Team.SelectedHero.AddToInventory(item))
								GameMessage.BuildMessage(2, item.Name);
							else
								square.DropItem(groundpos, item);
						}
					}
				}

				// In front of the team
				else if (DisplayCoordinates.LeftFrontTeamGround.Contains(mousePos) && !Team.FrontSquare.IsWall)
				{
					// Ground position
					switch (Team.Location.Direction)
					{
						case CardinalPoint.North:
						groundpos = SquarePosition.SouthWest;
						break;
						case CardinalPoint.East:
						groundpos = SquarePosition.NorthWest;
						break;
						case CardinalPoint.South:
						groundpos = SquarePosition.NorthEast;
						break;
						case CardinalPoint.West:
						groundpos = SquarePosition.SouthEast;
						break;
					}

					if (Team.ItemInHand == null)
					{
						Item item = Team.FrontSquare.CollectItem(groundpos);

						if (item != null)
						{
							if (Team.SelectedHero.AddToInventory(item))
								GameMessage.BuildMessage(2, item.Name);
							else
								Team.FrontSquare.DropItem(groundpos, item);
						}
					}
				}


				#endregion

				#region Gather item on the ground right
				else if (DisplayCoordinates.RightFeetTeam.Contains(mousePos))
				{
					switch (Team.Location.Direction)
					{
						case CardinalPoint.North:
						groundpos = SquarePosition.NorthEast;
						break;
						case CardinalPoint.East:
						groundpos = SquarePosition.SouthEast;
						break;
						case CardinalPoint.South:
						groundpos = SquarePosition.SouthWest;
						break;
						case CardinalPoint.West:
						groundpos = SquarePosition.NorthWest;
						break;
					}

					if (Team.ItemInHand == null)
					{
						Item item = square.CollectItem(groundpos);
						if (item != null)
						{
							if (Team.SelectedHero.AddToInventory(item))
								GameMessage.BuildMessage(2, item.Name);
							else
								square.DropItem(groundpos, item);
						}
					}
				}

				// In front of the team
				else if (DisplayCoordinates.RightFrontTeamGround.Contains(mousePos) && !Team.FrontSquare.IsWall)
				{

					// Ground position
					switch (Team.Location.Direction)
					{
						case CardinalPoint.North:
						groundpos = SquarePosition.SouthEast;
						break;
						case CardinalPoint.East:
						groundpos = SquarePosition.SouthWest;
						break;
						case CardinalPoint.South:
						groundpos = SquarePosition.NorthWest;
						break;
						case CardinalPoint.West:
						groundpos = SquarePosition.NorthEast;
						break;
					}

					if (Team.ItemInHand == null)
					{
						Item item = Team.FrontSquare.CollectItem(groundpos);
						if (item != null)
						{
							if (Team.SelectedHero.AddToInventory(item))
								GameMessage.BuildMessage(2, item.Name);
							else
								Team.FrontSquare.DropItem(groundpos, item);
						}
					}
				}

				#endregion

				#region Action to process on the front square
				// Click on the square in front of the team
				else if (DisplayCoordinates.FrontSquare.Contains(mousePos))
				{
					// On no action on the front wall
					if (!Team.FrontSquare.OnClick(mousePos, Team.FrontWallSide, MouseButtons.Right))
					{
					}
				}
				#endregion

			}

			#endregion

			#endregion


			#region Interface actions
			switch (Interface)
			{
				case TeamInterface.Inventory:
				{
					UpdateInventory(time);
				}
				break;

				case TeamInterface.Statistic:
				{
					UpdateStatistics(time);
				}
				break;

				default:
				{
					UpdateMain(time);
					//#region Left mouse button action


					//// Left mouse button down
					//if (Mouse.IsNewButtonDown(MouseButtons.Left) && Dialog == null)
					//{

					//	Item item = null;

					//	// Update each hero interface
					//	for (int id = 0; id < 6; id++)
					//	{
					//		// Get the hero
					//		Hero hero = Team.Heroes[id];
					//		if (hero == null)
					//			continue;

					//		#region Select hero
					//		if (InterfaceCoord.SelectHero[id].Contains(mousePos))
					//			Team.SelectedHero = hero;
					//		#endregion

					//		#region Swap hero
					//		if (InterfaceCoord.HeroFace[id].Contains(mousePos))
					//		{
					//			Team.SelectedHero = hero;
					//			HeroToSwap = null;
					//			Interface = TeamInterface.Inventory;
					//		}
					//		#endregion

					//		#region Take object in primary hand
					//		if (InterfaceCoord.PrimaryHand[id].Contains(mousePos)) // && hero.CanUseHand(HeroHand.Primary))
					//		{
					//			item = hero.GetInventoryItem(InventoryPosition.Primary);

					//			if (Team.ItemInHand != null && ((Team.ItemInHand.Slot & BodySlot.Primary) == BodySlot.Primary))
					//			{
					//				Item swap = Team.ItemInHand;
					//				Team.SetItemInHand(hero.GetInventoryItem(InventoryPosition.Primary));
					//				hero.SetInventoryItem(InventoryPosition.Primary, swap);
					//			}
					//			else if (Team.ItemInHand == null && item != null)
					//			{
					//				Team.SetItemInHand(item);
					//				hero.SetInventoryItem(InventoryPosition.Primary, null);
					//			}
					//		}
					//		#endregion

					//		#region Take object in secondary hand
					//		if (InterfaceCoord.SecondaryHand[id].Contains(mousePos)) // && hero.CanUseHand(HeroHand.Secondary))
					//		{
					//			item = hero.GetInventoryItem(InventoryPosition.Secondary);

					//			if (Team.ItemInHand != null && ((Team.ItemInHand.Slot & BodySlot.Secondary) == BodySlot.Secondary))
					//			{
					//				Item swap = Team.ItemInHand;
					//				Team.SetItemInHand(hero.GetInventoryItem(InventoryPosition.Secondary));
					//				hero.SetInventoryItem(InventoryPosition.Secondary, swap);

					//			}
					//			else if (Team.ItemInHand == null && item != null)
					//			{
					//				Team.SetItemInHand(item);
					//				hero.SetInventoryItem(InventoryPosition.Secondary, null);
					//			}
					//		}
					//		#endregion
					//	}


					//}

					//#endregion

					//#region Right mouse button action

					//// Right mouse button down
					//if (Mouse.IsNewButtonDown(MouseButtons.Right) && Dialog == null)
					//{

					//	// Update each hero interface
					//	for (int id = 0; id < 6; id++)
					//	{
					//		// Get the hero
					//		Hero hero = Team.Heroes[id];
					//		if (hero == null)
					//			continue;


					//		#region Swap hero
					//		if (InterfaceCoord.SelectHero[id].Contains(mousePos))
					//		{
					//			if (HeroToSwap == null)
					//			{
					//				HeroToSwap = hero;
					//			}
					//			else
					//			{
					//				Team.Heroes[(int)Team.GetHeroPosition(HeroToSwap)] = hero;
					//				Team.Heroes[id] = HeroToSwap;


					//				HeroToSwap = null;
					//			}
					//		}
					//		#endregion

					//		#region Show Hero inventory
					//		if (InterfaceCoord.HeroFace[id].Contains(mousePos))
					//		{
					//			Team.SelectedHero = hero;
					//			Interface = TeamInterface.Inventory;
					//		}
					//		#endregion

					//		#region Use object in primary hand
					//		if (InterfaceCoord.PrimaryHand[id].Contains(mousePos) && hero.CanUseHand(HeroHand.Primary))
					//			hero.UseHand(HeroHand.Primary);

					//		#endregion

					//		#region Use object in secondary hand
					//		if (InterfaceCoord.SecondaryHand[id].Contains(mousePos) && hero.CanUseHand(HeroHand.Secondary))
					//			hero.UseHand(HeroHand.Secondary);
					//		#endregion
					//	}
					//}
					//#endregion
				}
				break;
			}
			#endregion


			#region Heros update

			// Update all heroes
			foreach (Hero hero in Team.Heroes)
			{
				if (hero != null)
					hero.Update(time);
			}
			#endregion


			#region Spell window

			SpellBook.Update(time);

			#endregion


			// Update messages
			GameMessage.Update(time);


			// Update the dungeon
			Dungeon.Update(time);


			if (Team.CanMove && Team.Square != null)
				Team.Square.OnTeamStand();
		}
Exemple #38
0
		/// <summary>
		/// Moves closer to the target while remaining in the square
		/// </summary>
		/// <param name="target">Target point</param>
		public void GetCloserTo(DungeonLocation target)
		{
			// Can we get closer ?
			if (!CanGetCloserTo(target))
				return;


			Point dist = new Point(Location.Coordinate.X - target.Coordinate.X, Location.Coordinate.Y - target.Coordinate.Y);

			switch (Position)
			{
				#region North west
				case SquarePosition.NorthWest:
				{
					// 
					if (dist.X < 0)
					{
						if (Square.Monsters[(int)SquarePosition.SouthEast] == null)
							Teleport(Square, SquarePosition.SouthEast);

						else if (Square.Monsters[(int)SquarePosition.SouthWest] == null)
							Teleport(Square, SquarePosition.SouthWest);
					}
					//
					else if (dist.X > 0)
					{
					}

					// Above
					if (dist.Y > 0)
					{
					}

					// Below
					else if (dist.Y < 0)
					{
						if (Square.GetMonster(SquarePosition.SouthWest) == null)
							Teleport(Square, SquarePosition.SouthWest);

						else if (Square.GetMonster(SquarePosition.SouthEast) == null)
							Teleport(Square, SquarePosition.SouthEast);
					}
				}
				break;
				#endregion

				#region North east
				case SquarePosition.NorthEast:
				{
					// Right
					if (dist.X < 0)
					{
					}

					// Left
					else if (dist.X > 0)
					{
						if (Square.GetMonster(SquarePosition.NorthWest) == null)
							Teleport(Square, SquarePosition.NorthWest);
						else if (Square.GetMonster(SquarePosition.SouthWest) == null)
							Teleport(Square, SquarePosition.SouthWest);
					}


					// Below
					if (dist.Y < 0)
					{
						if (Square.Monsters[(int)SquarePosition.SouthEast] == null)
							Teleport(Square, SquarePosition.SouthEast);

						else if (Square.Monsters[(int)SquarePosition.SouthWest] == null)
							Teleport(Square, SquarePosition.SouthWest);
					}
					else if (dist.Y > 0)
					{
					}
				}
				break;
				#endregion

				#region South west
				case SquarePosition.SouthWest:
				{

					// Right
					if (dist.X < 0)
					{
						if (Square.GetMonster(SquarePosition.SouthEast) == null)
							Teleport(Square, SquarePosition.SouthEast);
						else if (Square.GetMonster(SquarePosition.NorthEast) == null)
							Teleport(Square, SquarePosition.NorthEast);
					}

					// Left
					else if (dist.X > 0)
					{
					}

					// Above
					if (dist.Y > 0)
					{
						if (Square.GetMonster(SquarePosition.NorthWest) == null)
							Teleport(Square, SquarePosition.NorthWest);
						else if (Square.GetMonster(SquarePosition.NorthEast) == null)
							Teleport(Square, SquarePosition.NorthEast);
					}

					// Below
					else if (dist.Y < 0)
					{
					}
				}
				break;
				#endregion

				#region South east
				case SquarePosition.SouthEast:
				{

					// Left
					if (dist.X > 0)
					{
						// No monster in SW
						if (Square.GetMonster(SquarePosition.SouthWest) == null)
							Teleport(Square, SquarePosition.SouthWest);

						// No monster in NW
						if (Square.GetMonster(SquarePosition.NorthWest) == null)
							Teleport(Square, SquarePosition.NorthWest);
					}

					// Right
					else if (dist.X < 0)
					{
					}


					// Below
					if (dist.Y < 0)
					{
					}

					// Above
					else if (dist.Y > 0)
					{
						if (Square.GetMonster(SquarePosition.NorthEast) == null)
							Teleport(Square, SquarePosition.NorthEast);

						else if (Square.GetMonster(SquarePosition.NorthWest) == null)
							Teleport(Square, SquarePosition.NorthWest);
					}
				}
				break;
				#endregion
			}


		}
Exemple #39
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public Dungeon()
 {
     Mazes         = new Dictionary <string, Maze>();
     StartLocation = new DungeonLocation();
 }
Exemple #40
0
		///// <summary>
		///// Loads a team party
		///// </summary>
		///// <param name="filename">File name to load</param>
		///// <returns>True if loaded</returns>
		//public bool LoadParty()
		//{
		//    return true;
		//}


		/// <summary>
		/// Loads a party
		/// </summary>
		/// <param name="filename">Xml data</param>
		/// <returns>True if team successfuly loaded, otherwise false</returns>
		public bool Load(XmlNode xml)
		{
			if (xml == null || xml.Name.ToLower() != "team")
				return false;


			// Clear the team
			for (int i = 0; i < Heroes.Count; i++)
				Heroes[i] = null;


			foreach (XmlNode node in xml)
			{
				if (node.NodeType == XmlNodeType.Comment)
					continue;


				switch (node.Name.ToLower())
				{
					//case "dungeon":
					//{
					//    Dungeon = ResourceManager.CreateAsset<Dungeon>(node.Attributes["name"].Value);
					//    //Dungeon.Team = this;
					//}
					//break;

					case "location":
					{
						Location = new DungeonLocation(node);
					}
					break;


					case "position":
					{
						HeroPosition position = (HeroPosition)Enum.Parse(typeof(HeroPosition), node.Attributes["slot"].Value, true);
						Hero hero = new Hero();
						hero.Load(node.FirstChild);
						AddHero(hero, position);
					}
					break;

					case "message":
					{
						GameMessage.AddMessage(node.Attributes["text"].Value, Color.FromArgb(int.Parse(node.Attributes["A"].Value), int.Parse(node.Attributes["R"].Value), int.Parse(node.Attributes["G"].Value), int.Parse(node.Attributes["B"].Value)));
					}
					break;
				}
			}


			SelectedHero = Heroes[0];
			return true;
		}