public ArrayList GetHooks (HookType hookType, HookDir dir, HookAction action, Type type, string member)
		{
			if (dir == HookDir.Read)
				return FindHook (ReaderHooks, hookType, action, type, member);
			else
				return FindHook (WriterHooks, hookType, action, type, member);
		}
Ejemplo n.º 2
0
        public IDisposable Register(ShortcutKey shortcutKey, Action<IntPtr> action, Func<bool> canExecute)
        {
            var hook = new HookAction(shortcutKey, action, canExecute);
            this._hookActions.Add(hook);

            return Disposable.Create(() => this._hookActions.Remove(hook));
        }
Ejemplo n.º 3
0
        public IDisposable Register(Func <ShortcutKey> getShortcutKey, Action <IntPtr> action, Func <ShortcutKeyPressedEventArgs, bool> canExecute)
        {
            var hook = new HookAction(getShortcutKey, action, canExecute);

            this._hookActions.Add(hook);

            return(Disposable.Create(() => this._hookActions.Remove(hook)));
        }
Ejemplo n.º 4
0
        public IDisposable Register(ShortcutKey shortcutKey, Action <IntPtr> action, Func <bool> canExecute)
        {
            var hook = new HookAction(shortcutKey, action, canExecute);

            this._hookActions.Add(hook);

            return(Disposable.Create(() => this._hookActions.Remove(hook)));
        }
Ejemplo n.º 5
0
        private ArrayList FindHook(Hook[] hooks, HookType hookType, HookAction action, Type type, string member)
        {
            ArrayList arrayList = new ArrayList();

            if (hooks == null)
            {
                return(arrayList);
            }
            foreach (Hook hook in hooks)
            {
                if (action != HookAction.InsertBefore || (hook.InsertBefore != null && !(hook.InsertBefore == string.Empty)))
                {
                    if (action != HookAction.InsertAfter || (hook.InsertAfter != null && !(hook.InsertAfter == string.Empty)))
                    {
                        if (action != HookAction.Replace || (hook.Replace != null && !(hook.Replace == string.Empty)))
                        {
                            if (hook.HookType == hookType)
                            {
                                if (hook.Select != null)
                                {
                                    if (hook.Select.TypeName != null && hook.Select.TypeName != string.Empty && hook.Select.TypeName != type.FullName)
                                    {
                                        goto IL_1DD;
                                    }
                                    if (hook.Select.TypeMember != null && hook.Select.TypeMember != string.Empty && hook.Select.TypeMember != member)
                                    {
                                        goto IL_1DD;
                                    }
                                    if (hook.Select.TypeAttributes != null && hook.Select.TypeAttributes.Length > 0)
                                    {
                                        object[] customAttributes = type.GetCustomAttributes(true);
                                        bool     flag             = false;
                                        foreach (object obj in customAttributes)
                                        {
                                            if (Array.IndexOf <string>(hook.Select.TypeAttributes, obj.GetType().FullName) != -1)
                                            {
                                                flag = true;
                                                break;
                                            }
                                        }
                                        if (!flag)
                                        {
                                            goto IL_1DD;
                                        }
                                    }
                                }
                                arrayList.Add(hook);
                            }
                        }
                    }
                }
                IL_1DD :;
            }
            return(arrayList);
        }
 public ArrayList GetHooks(HookType hookType, HookDir dir, HookAction action, Type type, string member)
 {
     if (dir == HookDir.Read)
     {
         return(FindHook(ReaderHooks, hookType, action, type, member));
     }
     else
     {
         return(FindHook(WriterHooks, hookType, action, type, member));
     }
 }
Ejemplo n.º 7
0
 public ArrayList GetHooks(HookType hookType, XmlMappingAccess dir, HookAction action, Type type, string member)
 {
     if ((dir & XmlMappingAccess.Read) != XmlMappingAccess.None)
     {
         return(this.FindHook(this.ReaderHooks, hookType, action, type, member));
     }
     if ((dir & XmlMappingAccess.Write) != XmlMappingAccess.None)
     {
         return(this.FindHook(this.WriterHooks, hookType, action, type, member));
     }
     throw new Exception("INTERNAL ERROR");
 }
Ejemplo n.º 8
0
 public string GetCode(HookAction action)
 {
     if (action == HookAction.InsertBefore)
     {
         return(this.InsertBefore);
     }
     if (action == HookAction.InsertAfter)
     {
         return(this.InsertAfter);
     }
     return(this.Replace);
 }
 public string GetCode(HookAction action)
 {
     if (action == HookAction.InsertBefore)
     {
         return(InsertBefore);
     }
     else if (action == HookAction.InsertAfter)
     {
         return(InsertAfter);
     }
     else
     {
         return(Replace);
     }
 }
		ArrayList FindHook (Hook[] hooks, HookType hookType, HookAction action, Type type, string member)
		{
			ArrayList foundHooks = new ArrayList ();
			if (hooks == null) return foundHooks;
	
			foreach (Hook hook in hooks)
			{
				if (action == HookAction.InsertBefore && (hook.InsertBefore == null || hook.InsertBefore == ""))
					continue;
				else if (action == HookAction.InsertAfter && (hook.InsertAfter == null || hook.InsertAfter == ""))
					continue;
				else if (action == HookAction.Replace && (hook.Replace == null || hook.Replace == ""))
					continue;
					
				if (hook.HookType != hookType)
					continue;
					
				if (hook.Select != null)
				{
					if (hook.Select.TypeName != null && hook.Select.TypeName != "")
						if (hook.Select.TypeName != type.FullName) continue;
		
					if (hook.Select.TypeMember != null && hook.Select.TypeMember != "")
						if (hook.Select.TypeMember != member) continue;
						
					if (hook.Select.TypeAttributes != null && hook.Select.TypeAttributes.Length > 0)
					{
						object[] ats = type.GetCustomAttributes (true);
						bool found = false;
						foreach (object at in ats)
							if (Array.IndexOf (hook.Select.TypeAttributes, at.GetType().FullName) != -1) { found = true; break; }
						if (!found) continue;
					}
				}
				foundHooks.Add (hook);
			}
			return foundHooks;
		}
        ArrayList FindHook(Hook[] hooks, HookType hookType, HookAction action, Type type, string member)
        {
            ArrayList foundHooks = new ArrayList();

            if (hooks == null)
            {
                return(foundHooks);
            }

            foreach (Hook hook in hooks)
            {
                if (action == HookAction.InsertBefore && (hook.InsertBefore == null || hook.InsertBefore == ""))
                {
                    continue;
                }
                else if (action == HookAction.InsertAfter && (hook.InsertAfter == null || hook.InsertAfter == ""))
                {
                    continue;
                }
                else if (action == HookAction.Replace && (hook.Replace == null || hook.Replace == ""))
                {
                    continue;
                }

                if (hook.HookType != hookType)
                {
                    continue;
                }

                if (hook.Select != null)
                {
                    if (hook.Select.TypeName != null && hook.Select.TypeName != "")
                    {
                        if (hook.Select.TypeName != type.FullName)
                        {
                            continue;
                        }
                    }

                    if (hook.Select.TypeMember != null && hook.Select.TypeMember != "")
                    {
                        if (hook.Select.TypeMember != member)
                        {
                            continue;
                        }
                    }

                    if (hook.Select.TypeAttributes != null && hook.Select.TypeAttributes.Length > 0)
                    {
                        object[] ats   = type.GetCustomAttributes(true);
                        bool     found = false;
                        foreach (object at in ats)
                        {
                            if (Array.IndexOf(hook.Select.TypeAttributes, at.GetType().FullName) != -1)
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            continue;
                        }
                    }
                }
                foundHooks.Add(hook);
            }
            return(foundHooks);
        }
 public void Hook <T>(HookPoint <T> hookPoint, HookOrder order, HookAction <T> callback)
 {
     HookBase(hookPoint, order, callback);
 }
 public void Hook <T>(HookPoint <T> hookPoint, HookAction <T> callback)
 {
     Hook <T>(hookPoint, HookOrder.NORMAL, callback);
 }
		public ArrayList GetHooks (HookType hookType, XmlMappingAccess dir, HookAction action, Type type, string member)
		{
			if ((dir & XmlMappingAccess.Read) != 0)
				return FindHook (ReaderHooks, hookType, action, type, member);
			if ((dir & XmlMappingAccess.Write) != 0)
				return FindHook (WriterHooks, hookType, action, type, member);
			else
				throw new Exception ("INTERNAL ERROR");
		}
Ejemplo n.º 15
0
        // ReSharper disable once CyclomaticComplexity
        public Option <ICommand> HandleKeyInput(int key)
        {
            Player player = Game.Player;
            Weapon weapon = player.Equipment.PrimaryWeapon;

            switch (InputMapping.GetNormalInput(key))
            {
                //case NormalInput.None:
                //    return null;

                #region Movement Keys
            case NormalInput.MoveW:
                return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.W)));

            case NormalInput.MoveS:
                return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.S)));

            case NormalInput.MoveN:
                return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.N)));

            case NormalInput.MoveE:
                return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.E)));

            case NormalInput.MoveNW:
                return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.NW)));

            case NormalInput.MoveNE:
                return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.NE)));

            case NormalInput.MoveSW:
                return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.SW)));

            case NormalInput.MoveSE:
                return(Option.Some <ICommand>(new MoveCommand(player, player.Loc + Direction.SE)));

            case NormalInput.Wait:
                return(Option.Some <ICommand>(new WaitCommand(player)));

                #endregion

            case NormalInput.Get:
                return(Option.Some <ICommand>(new PickupCommand(player, Game.Map.GetStack(player.Loc))));

            case NormalInput.Throw:
                // TODO: Add ability to throw without wielding
                if (weapon == null)
                {
                    Game.MessageHandler.AddMessage("Nothing to throw.");
                    return(Option.None <ICommand>());
                }

                IAction thrown = weapon.Throw();
                Game.StateHandler.PushState(new TargettingState(
                                                player,
                                                thrown.Area,
                                                returnTarget =>
                {
                    Game.MessageHandler.AddMessage($"You throw a {weapon}.");

                    // Switch to offhand weapon if possible.
                    player.Equipment.PrimaryWeapon = player.Equipment.OffhandWeapon;

                    // Drop the item on the map.
                    // TODO: Add possibility of weapon stuck / breaking
                    // TODO: Handle case of multiple thrown at once?
                    Loc[] enumerable = returnTarget as Loc[] ?? returnTarget.ToArray();
                    Loc point        = enumerable[0];
                    weapon.Loc       = point;
                    Game.Map.AddItem(weapon);

                    return(new DelayActionCommand(player, thrown, enumerable));
                }));
                return(Option.None <ICommand>());

            case NormalInput.ChangeLevel:
                return(Option.Some <ICommand>(new ChangeLevelCommand(Game.Map.TryChangeLocation(player))));

            case NormalInput.OpenApply:
                Game.StateHandler.PushState(ApplyState.Instance);
                return(Option.None <ICommand>());

            case NormalInput.OpenDrop:
                Game.StateHandler.PushState(DropState.Instance);
                return(Option.None <ICommand>());

            case NormalInput.OpenEquip:
                Game.StateHandler.PushState(EquipState.Instance);
                return(Option.None <ICommand>());

            case NormalInput.OpenInventory:
                Game.StateHandler.PushState(InventoryState.Instance);
                return(Option.None <ICommand>());

            case NormalInput.OpenUnequip:
                Game.StateHandler.PushState(UnequipState.Instance);
                return(Option.None <ICommand>());

            case NormalInput.AutoExplore:
                Game.StateHandler.PushState(AutoexploreState.Instance);
                return(Option.None <ICommand>());

            case NormalInput.OpenMenu:
                Game.Exit();
                return(Option.None <ICommand>());
            }

            // HACK: debugging commands
            if (key == Terminal.TK_Q)
            {
                // NOTE: Movement occurs after the hook is used. This means that using the hook
                // to pull enemies will often give the Player a first hit on enemies, but using
                // the hook to escape will give enemies an "attack of opportunity".
                IAction hookAction = new HookAction(10);
                Game.StateHandler.PushState(new TargettingState(
                                                player,
                                                hookAction.Area,
                                                returnTarget => new DelayActionCommand(player, hookAction, returnTarget)));
                return(Option.None <ICommand>());
            }

            // TODO: Create a debug menu for test commands
            if (key == Terminal.TK_GRAVE)
            {
                Game.EventScheduler.Clear();
                Game.NewGame();
                return(Option.Some <ICommand>(new WaitCommand(player)));
            }

            // TODO: Use weapon's attack sequence if equipped???
            IAction action = player.GetBasicAttack();
            if (key == Terminal.TK_Z)
            {
                action = weapon?.AttackLeft() ?? player.GetBasicAttack();
            }
            else if (key == Terminal.TK_X)
            {
                action = weapon?.AttackRight() ?? player.GetBasicAttack();
            }
            else if (Terminal.Check(Terminal.TK_SHIFT))
            {
                // TODO: Change to an arbitrary facing
                // TODO: Should attacks update facing?
                player.Facing = player.Facing.Right();
                Game.Map.Refresh();
                return(Option.None <ICommand>());
            }

            if (Terminal.Check(Terminal.TK_SHIFT))
            {
                Game.StateHandler.PushState(new TargettingState(
                                                player,
                                                action.Area,
                                                target => new DelayActionCommand(player, action, target)));
                return(Option.None <ICommand>());
            }
            else
            {
                (int dx, int dy) = player.Facing;
                IEnumerable <Loc> target = action.Area.GetTilesInRange(
                    player,
                    player.Loc + player.Facing);
                return(Option.Some <ICommand>(new DelayActionCommand(player, action, target)));
            }
        }
Ejemplo n.º 16
0
		bool GenerateHooks (HookType hookType, HookDir dir, Type type, string member, HookAction action)
		{
			if (_config == null) return false;
			ArrayList hooks = _config.GetHooks (hookType, dir, action, type, null);
			if (hooks.Count == 0) return false;			
			foreach (Hook hook in hooks)
			{
				string code = hook.GetCode (action);
				foreach (DictionaryEntry de in _hookVariables)
					code = code.Replace ((string)de.Key, (string)de.Value);
				WriteMultilineCode (code);
			}
			return true;
		}
		public string GetCode (HookAction action)
		{
			if (action == HookAction.InsertBefore)
				return InsertBefore;
			else if (action == HookAction.InsertAfter)
				return InsertAfter;
			else
				return Replace;
		}