Esempio n. 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);

		}
Esempio n. 2
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
			}

		}