Good progress this morning/last night!

Items and Item actions

I’ve added the ability to pick up, drop, and destroy Items.  There’s no concept of “inventory” yet, but you can interact with Items on the ground and in your hand.  The ContextualActionBar (CAB) shows the most appropriate Actions for a particular Item; e.g.:

  • The player moves onto a Cell with a dagger in it.  The CAB shows the dagger along with  “Pickup” and “Destroy” as the quick Action button choices.  The player clicks “pick up” and the dagger is moved into their hand…
  • The CAB now shows “Wield” and “Drop” as the two contextual actions, since the object is in the player’s hand.  If the player chooses “Drop” then it goes to the options above.
  • If the player instead chooses ‘Wield” then the actions change to “Unwield” and “Drop”.  “Drop” first performs an unwield action and then a drop action on the item (unless the unwield was blocked; e.g. via a curse).

Monsters also have their own contextual actions when the player selects one; e.g. ‘attack’.

Wield and Unwield Actions

I’ve added Action_WieldWeapon and Action_UnwieldWeapon.  While straightforward, these actions go through the standard event system as well; this will allow (for instance) me to easily add Debuffs which, when applied to the weapon or the player, disallow unwielding.  Picture “cursed weapons” in many roguelikes. This should all work automagically…

Here’s the entire Action_UnwieldWeapon class:

using Microsoft.Xna.Framework;
namespace Dungeon
{
    public class Action_UnwieldWeapon : Action
    {
        internal static Action_UnwieldWeapon Create(Actor actor)
        {
            // Obtain an Action from the object pool (or if none are in it, alloc a new one).
            Action_UnwieldWeapon action = ObjectPool.IsEmpty ? new Action_UnwieldWeapon() : ObjectPool.GetFreeObject();

            // Initialize fields in the newly obtained Action.
            action.Initialize(actor, null);

            return action;
        }

        static ObjectPool<Action_UnwieldWeapon> ObjectPool = new ObjectPool<Action_UnwieldWeapon>();

        // Return this Action to the Object Pool
        internal override void Release()
        {
            ObjectPool.Release(this);
        }

        public override void Perform(ActionInfo actionInfo)
        {
            // Notify the system that we're performing this Action; this allows other things to hook into it and modify/filter the event
            if (!FireEvent(actionInfo, EventType.StartUnwieldingWeapon))
                return;

            Item item = actionInfo.PerformingActor.WieldedWeapon;

            actionInfo.PerformingActor.WieldedWeapon = null;

            MessageMgr.AddMessage("You remove your " + item.ItemType.Name, Color.Yellow);
            ContextualActionBar.Show(item);

            // Notify the system that we've performed this Action.
            FireEvent(actionInfo, EventType.DoneUnwieldingWeapon);
        }
    }
}

Fixes

I mentioned in the last post that there were still some fixes to work through.  Among other things fixed were:

  • Not seeing CellsWithItemsOfInterest around the player when entering a level or resuming.
  • Go for nearest item in the list of CellsWithItemsOfInterest (sort by distance)
  • Although you can tap-to-move even with monsters around, you should stop MovingTo the first time you see a monster.
  • “explore” inadvertantly walked onto stairs.  Also fixed monsters and items appearing on stairs
  • When dropping an item, select the dropped item in the CAB.
  • Minor tweaks to events in turn sequence.  Going to need to graph these out, probably have some redunant checks in there…

Updated source: http://wanderlinggames.com/files/dungeon/dungeon-4-2-11.zip

Updated executable: http://wanderlinggames.com/files/dungeon/dungeonexe-4-2-11.zip

Advertisements