/// <summary> /// Gets if an item can be used with a specific hand /// </summary> /// <param name="hand">Hand to check</param> /// <returns>True if can be used with the specified hand</returns> public bool CanUseWithHand(HeroHand hand) { switch (hand) { case HeroHand.Primary: return((Slot & BodySlot.Primary) == BodySlot.Primary); case HeroHand.Secondary: return((Slot & BodySlot.Secondary) == BodySlot.Secondary); } // Slot == BodySlot.Primary | BodySlot.Secondary return(true); }
/// <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 } }
/// <summary> /// Add a time penality to a hand /// </summary> /// <param name="hand">Hand</param> /// <param name="duration">Duration</param> public void AddHandPenality(HeroHand hand, TimeSpan duration) { HandPenality[(int)hand] = DateTime.Now + duration; }
/// <summary> /// Gets the last action result /// </summary> /// <param name="hand">Hand</param> /// <returns></returns> public HandAction GetLastActionResult(HeroHand hand) { return HandActions[(int)hand]; }
/// <summary> /// Returns the last attack /// </summary> /// <param name="hand">Hand of the attack</param> /// <returns>Attack result</returns> public Attack GetLastAttack(HeroHand hand) { return Attacks[(int)hand]; }
/// <summary> /// Can use the hand /// </summary> /// <param name="hand">Hand to attack</param> /// <returns>True if the specified hand can be used</returns> public bool CanUseHand(HeroHand hand) { if (IsDead || IsUnconscious) return false; // Check the item in the other hand Item item = GetInventoryItem(hand == HeroHand.Primary ? InventoryPosition.Secondary : InventoryPosition.Primary); if (item != null && item.TwoHanded) return false; return HandPenality[(int)hand] < DateTime.Now; }