示例#1
0
		/// <summary>
		/// Default constructor
		/// </summary>
		public Hero()
		{
			Professions = new List<Profession>();
			LearnedSpells = new List<string>();
			ClericSpells = new List<Spell>[6]
			{
				new List<Spell>(),
				new List<Spell>(),
				new List<Spell>(),
				new List<Spell>(),
				new List<Spell>(),
				new List<Spell>(),
			};
			MageSpells = new List<Spell>[6]
			{
				new List<Spell>(),
				new List<Spell>(),
				new List<Spell>(),
				new List<Spell>(),
				new List<Spell>(),
				new List<Spell>(),
			};

			IsDisposed = false;

			Head = -1;
			Inventory = new Item[26];
			BackPack = new Item[14];
			WaistPack = new Item[3];
			Attacks = new Attack[2];
			HandActions = new HandAction[2];
			HandActions[0] = new HandAction(ActionResult.Ok);
			HandActions[1] = new HandAction(ActionResult.Ok);
			HandPenality = new DateTime[2];
			HandPenality[0] = DateTime.Now;
			HandPenality[1] = DateTime.Now;

			Food = (byte)Game.Random.Next(80, 100);

		}
示例#2
0
		/// <summary>
		/// Attack the entity
		/// </summary>
		/// <param name="attack">Attack</param>
		public abstract void Hit(Attack attack);
示例#3
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
			}

		}
示例#4
0
		/// <summary>
		/// Attack the entity
		/// </summary>
		/// <param name="attack">Attack</param>
		public override void Hit(Attack attack)
		{
			if (attack == null)
				return;

			LastAttack = attack;
			if (LastAttack.IsAMiss)
				return;

			HitPoint.Current -= LastAttack.Hit;
		}
示例#5
0
        /// <summary>
        /// Update the flying item
        /// </summary>
        /// <param name="time">Game time</param>
        /// <param name="maze">Maze where the flying item is</param>
        /// <returns>True if the blocked or false if nothing happened</rereturns>
        public bool Update(GameTime time, Maze maze)
        {
            // Item can't move any more
            if (Distance == 0)
            {
                return(true);
            }

            LastUpdate += time.ElapsedGameTime;

            if (LastUpdate > Speed)
            {
                LastUpdate -= Speed;

                // Find the next block according to the direction
                Point dst = Point.Empty;
                switch (Location.Direction)
                {
                case CardinalPoint.North:
                    dst = new Point(Location.Coordinate.X, Location.Coordinate.Y - 1);
                    break;

                case CardinalPoint.East:
                    dst = new Point(Location.Coordinate.X + 1, Location.Coordinate.Y);
                    break;

                case CardinalPoint.South:
                    dst = new Point(Location.Coordinate.X, Location.Coordinate.Y + 1);
                    break;

                case CardinalPoint.West:
                    dst = new Point(Location.Coordinate.X - 1, Location.Coordinate.Y);
                    break;
                }


                // Blocked by a wall, fall before the block
                Square square = maze.GetSquare(dst);


                // Can item pass through a door ?
                if (square.Actor != null && square.Actor is Door)
                {
                    Door door = square.Actor as Door;
                    if (!door.CanItemsPassThrough(Item))
                    {
                        Distance = 0;
                    }
                }


                // Wall is blocking
                else if (square.IsBlocking)
                {
                    Distance = 0;
                }


                // Blocked by an obstacle, but fall on the block
                if ((square.Actor != null && square.Actor.CanPassThrough) || square.MonsterCount > 0)
                {
                    Location.Coordinate = dst;

                    SquarePosition gp = Location.Position;
                    switch (Location.Direction)
                    {
                    case CardinalPoint.North:
                        if (gp == SquarePosition.NorthEast || gp == SquarePosition.SouthEast)
                        {
                            Location.Position = SquarePosition.SouthEast;
                        }
                        else
                        {
                            Location.Position = SquarePosition.SouthWest;
                        }
                        break;

                    case CardinalPoint.South:
                        if (gp == SquarePosition.NorthEast || gp == SquarePosition.SouthEast)
                        {
                            Location.Position = SquarePosition.NorthEast;
                        }
                        else
                        {
                            Location.Position = SquarePosition.NorthWest;
                        }
                        break;

                    case CardinalPoint.West:
                        if (gp == SquarePosition.NorthEast || gp == SquarePosition.NorthWest)
                        {
                            Location.Position = SquarePosition.NorthEast;
                        }
                        else
                        {
                            Location.Position = SquarePosition.SouthEast;
                        }
                        break;

                    case CardinalPoint.East:
                        if (gp == SquarePosition.NorthEast || gp == SquarePosition.NorthWest)
                        {
                            Location.Position = SquarePosition.NorthWest;
                        }
                        else
                        {
                            Location.Position = SquarePosition.SouthWest;
                        }
                        break;
                    }


                    // Get monster and hit it
                    if (square.MonsterCount > 0)
                    {
                        Monster[] monsters = maze.GetSquare(Location.Coordinate).Monsters;
                        foreach (Monster monster in monsters)
                        {
                            if (monster != null)
                            {
                                Attack attack = new Attack(Caster, monster, Item);
                                if (attack.IsAHit)
                                {
                                    Distance = 0;
                                }
                            }
                        }
                    }
                    return(true);
                }



                // Drop the item at good ground position
                if (Distance == 0)
                {
                    SquarePosition gp = Location.Position;
                    switch (Location.Direction)
                    {
                    case CardinalPoint.North:
                        if (gp == SquarePosition.NorthEast || gp == SquarePosition.SouthEast)
                        {
                            Location.Position = SquarePosition.NorthEast;
                        }
                        else
                        {
                            Location.Position = SquarePosition.NorthWest;
                        }
                        break;

                    case CardinalPoint.South:
                        if (gp == SquarePosition.NorthEast || gp == SquarePosition.SouthEast)
                        {
                            Location.Position = SquarePosition.SouthEast;
                        }
                        else
                        {
                            Location.Position = SquarePosition.SouthWest;
                        }
                        break;

                    case CardinalPoint.West:
                        if (gp == SquarePosition.NorthEast || gp == SquarePosition.NorthWest)
                        {
                            Location.Position = SquarePosition.NorthWest;
                        }
                        else
                        {
                            Location.Position = SquarePosition.SouthWest;
                        }
                        break;

                    case CardinalPoint.East:
                        if (gp == SquarePosition.NorthEast || gp == SquarePosition.NorthWest)
                        {
                            Location.Position = SquarePosition.NorthEast;
                        }
                        else
                        {
                            Location.Position = SquarePosition.SouthEast;
                        }
                        break;
                    }

                    return(true);
                }
                else
                {
                    Distance--;
                    Location.Coordinate = dst;
                }
            }

            return(false);
        }
示例#6
0
		/// <summary>
		/// Attack the entity
		/// </summary>
		/// <param name="attack">Attack handle</param>
		public override void Hit(Attack attack)
		{
			if (attack == null)
				return;

			LastAttack = attack;
			if (LastAttack.IsAMiss)
				return;

			HitPoint.Current -= LastAttack.Hit;

			LastHit = DateTime.Now;

			OnHit();

			// Reward the team for having killed the entity
			if (IsDead && attack.Striker is Hero)
			{
				GameScreen.Team.AddExperience(Reward);
			}
		}
示例#7
0
		/// <summary>
		/// Update the flying item
		/// </summary>
		/// <param name="time">Game time</param>
		/// <param name="maze">Maze where the flying item is</param>
		/// <returns>True if the blocked or false if nothing happened</rereturns>
		public bool Update(GameTime time, Maze maze)
		{
			// Item can't move any more
			if (Distance == 0)
				return true;
			
			LastUpdate += time.ElapsedGameTime;

			if (LastUpdate > Speed)
			{
				LastUpdate -= Speed;

				// Find the next block according to the direction
				Point dst = Point.Empty;
				switch (Location.Direction)
				{
					case CardinalPoint.North:
					dst = new Point(Location.Coordinate.X, Location.Coordinate.Y - 1);
					break;
					case CardinalPoint.East:
					dst = new Point(Location.Coordinate.X + 1, Location.Coordinate.Y);
					break;
					case CardinalPoint.South:
					dst = new Point(Location.Coordinate.X, Location.Coordinate.Y + 1);
					break;
					case CardinalPoint.West:
					dst = new Point(Location.Coordinate.X - 1, Location.Coordinate.Y);
					break;
				}


				// Blocked by a wall, fall before the block
				Square square =  maze.GetSquare(dst);


				// Can item pass through a door ?
				if (square.Actor != null && square.Actor is Door)
				{
					Door door = square.Actor as Door;
					if (!door.CanItemsPassThrough(Item))
					{
						Distance = 0;
					}
				}
				

				// Wall is blocking
				else if (square.IsBlocking)
				{
					Distance = 0;
				}


				// Blocked by an obstacle, but fall on the block
				if ((square.Actor != null && square.Actor.CanPassThrough) || square.MonsterCount > 0)
				{
					Location.Coordinate = dst;

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


					// Get monster and hit it
					if (square.MonsterCount > 0)
					{
						Monster[] monsters = maze.GetSquare(Location.Coordinate).Monsters;
						foreach(Monster monster in monsters)
							if (monster != null)
							{
								Attack attack = new Attack(Caster, monster, Item);
								if (attack.IsAHit)
									Distance = 0;
							}
					}
					return true;
				}




				// Drop the item at good ground position
				if (Distance == 0)
				{
					SquarePosition gp = Location.Position;
					switch (Location.Direction)
					{
						case CardinalPoint.North:
						if (gp == SquarePosition.NorthEast || gp == SquarePosition.SouthEast)
							Location.Position = SquarePosition.NorthEast;
						else
							Location.Position = SquarePosition.NorthWest;
						break;
						case CardinalPoint.South:
						if (gp == SquarePosition.NorthEast || gp == SquarePosition.SouthEast)
							Location.Position = SquarePosition.SouthEast;
						else
							Location.Position = SquarePosition.SouthWest;
						break;
						case CardinalPoint.West:
						if (gp == SquarePosition.NorthEast || gp == SquarePosition.NorthWest)
							Location.Position = SquarePosition.NorthWest;
						else
							Location.Position = SquarePosition.SouthWest;
						break;
						case CardinalPoint.East:
						if (gp == SquarePosition.NorthEast || gp == SquarePosition.NorthWest)
							Location.Position = SquarePosition.NorthEast;
						else
							Location.Position = SquarePosition.SouthEast;
						break;
					}

					return true;
				}
				else
				{
					Distance--;
					Location.Coordinate = dst;
				}
			}

			return false;
		}
示例#8
0
 /// <summary>
 /// Attack the entity
 /// </summary>
 /// <param name="attack">Attack</param>
 public abstract void Hit(Attack attack);