/// <summary> /// Handles the Hero's pickpocketing ability; call this method in the Game's update /// cycle (AFTER calling KeyboardManager.update()) /// </summary> /// <param name="hero">The main character</param> /// <param name="targets">List of characters in the scene; one that is in range is chosen randomly</param> public static void handlePickpocketing(Hero hero, List<Character> targets) { nullCheck(); if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.Pickpocket])) { if (hero.isPickpocketing()) { Item item = hero.stopPickpocket(); System.Diagnostics.Debug.WriteLine("Stole " + Enum.GetName(typeof(Item), item)); } else if (!hero.isPickpocketing()) { //naive search through a list of characters // We should probably do this on a per-room basis later, for efficiency. // And/or use some sort of "expanding circle" search. for(int i = 0; i < targets.Count; i++) { if (hero.inRangeAction(targets[i])) { hero.startPickpocket(targets[i]); break; } } } } }
/// <summary> /// Handles the Hero talking with Characters. Will be expanded later to "interact" with /// scenery as well. /// </summary> /// <param name="hero">The main character</param> /// <param name="targets">List of interactables in the scene</param> public static void handleInteractions(Hero hero, List<IInteractable> targets) { nullCheck(); if (!hero.isTalking()) { if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.Action])) { bool foundTarget = false; for (int i = 0; i < targets.Count; i++) { if (hero.inRangeAction(targets[i]) && hero.facing(targets[i])) { targets[i].onInteract(); foundTarget = true; break; } } if (!foundTarget) { hero.talkToSelf(); } } } else { if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.MoveNorth])) hero.dialogueChoiceMove(Direction.North); else if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.MoveSouth])) hero.dialogueChoiceMove(Direction.South); else if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.Action])) hero.dialogueConfirm(); else if (KeyboardManager.isKeyPressed(keyTypes[(int)KeyInputType.Cancel])) hero.dialogueCancel(); } }