public Menu(Player player) { Player = player; AddAction(new ActAction("Items", () => { SubActions.Add(new ItemMenu(Player)); return(InputResult.None); })); AddAction(new ActAction("Stats", () => { SubActions.Add(new MessageBox("Not implemented.", InputResult.Close)); return(InputResult.None); })); AddAction(new ActAction("Fusion", () => { SubActions.Add(new MessageBox("Not implemented.", InputResult.Close)); return(InputResult.None); })); }
public override bool TryParse() { if (!base.TryParse()) { return(false); } // contexts and steps Contexts.Clear(); Steps.Clear(); ReportNodeType[] childNodes = Node.ReportNode; if (childNodes != null) { foreach (ReportNodeType node in childNodes) { // try to add as a step report StepReport step = Steps.TryParseAndAdd(node, this.Node); if (step != null) { AllStepsEnumerator.Add(step); AllStepsEnumerator.Merge(step.AllStepsEnumerator); continue; } // try to add as a context report ContextReport context = Contexts.TryParseAndAdd(node, this.Node); if (context != null) { AllStepsEnumerator.Merge(context.AllStepsEnumerator); continue; } // try to add as an action iteration ActionIterationReport actionIteration = ActionIterations.TryParseAndAdd(node, this.Node); if (actionIteration != null) { AllStepsEnumerator.Merge(actionIteration.AllStepsEnumerator); continue; } // try to add as a sub-action ActionReport subAction = SubActions.TryParseAndAdd(node, this.Node); if (subAction != null) { AllStepsEnumerator.Merge(subAction.AllStepsEnumerator); continue; } } // update duration for the last step since it is the end of the action StepReport lastStep = ((TestReport)OwnerTest).LastStep; if (lastStep != null) { TimeSpan ts = lastStep.StartTime - StartTime; lastStep.UpdateDuration(DurationSeconds - (decimal)ts.TotalSeconds); } } return(true); }
private void Populate() { var memory = Player.Memory; string combineString; combineString = GetCombineString(memory, Items); if (Items.All(x => x is Potion)) //All items are potions -> mix { AddAction(new ActAction($"Mix {combineString}", () => { return(InputResult.None); })); } if (Items.Count(x => x is Device) == 1 && Selections.Count >= 2) { var device = (Device)Items.First(x => x is Device); var nonDevices = Items.Where(x => x != device); if (device.CanUse(Player, nonDevices)) { AddAction(new ActAction($"Use {memory.GetName(device)} on {GetCombineString(memory, nonDevices)}", () => { device.MachineEffect(Player, nonDevices); return(Selections.Any(x => x.Item.Destroyed) ? InputResult.Close : InputResult.None); })); } } if (Items.Any(x => x is Potion) && Selections.Count == 2) //2 items, of which one is a potion -> dip { var potion = (Potion)Items.First(x => x is Potion); var nonPotion = Items.First(x => !(x is Potion)); AddAction(new ActAction($"Dip {memory.GetName(nonPotion)} into {memory.GetName(potion)}", () => { potion.DipEffect(Player, nonPotion); return(Selections.Any(x => x.Item.Destroyed) ? InputResult.Close : InputResult.None); })); } /*AddAction(new ActAction($"Combine {combineString}", () => * { * return InputResult.None; * }));*/ if (Selections.Count == 2) { AddAction(new ActAction($"Swap {combineString}", () => { return(InputResult.None); })); } AddAction(new ActAction($"Dispose {combineString}", () => { foreach (var item in Items) { item.Destroy(); } SubActions.Add(new MessageBox($"Threw {combineString} away.", InputResult.Close)); return(Items.Any(x => x.Destroyed) ? InputResult.Close : InputResult.None); })); }
/** * Checks if this action can interrupt. The combination can * interrupt if the first action can. */ public override bool CanInterrupt() { if (SubActions != null) { return(SubActions.CanInterrupt()); } else { return(false); } }
public override void HandleInput(SceneGame scene) { base.HandleInput(scene); NearestItemTicks++; if (SubActions.Count > 0) { HandleSubActions(scene); return; } if (scene.InputState.IsKeyPressed(Keys.Tab) || scene.InputState.IsButtonPressed(Buttons.RightStick)) { GameSpeedToggle = !GameSpeedToggle; } if (scene.InputState.IsButtonPressed(Buttons.RightTrigger)) { CurrentWeaponIndex = PositiveMod(CurrentWeaponIndex + 1, Weapon.PresetWeaponList.Length); Player.Weapon = Weapon.PresetWeaponList[CurrentWeaponIndex]; } else if (scene.InputState.IsButtonPressed(Buttons.RightShoulder)) { CurrentWeaponIndex = PositiveMod(CurrentWeaponIndex - 1, Weapon.PresetWeaponList.Length); Player.Weapon = Weapon.PresetWeaponList[CurrentWeaponIndex]; } if ((scene.InputState.IsKeyPressed(Keys.Enter)) || (scene.InputState.IsButtonPressed(Buttons.Start))) { //SubActions.Add(new Pause()); SubActions.Add(new Menu(Player)); return; } Player.Controls.ResetHeld(); Player.Controls.Update(scene); DroppedItem nearest = null; if (Player.NearbyItems.Any()) { nearest = Player.GetNearestItem(); } if (nearest != NearestItem) { NearestItem = nearest; NearestItemTicks = 0; } }
/** * Called to make the action do its stuff. It calls all its * subactions. */ public override void Act() { // Check if we have anything to do if (SubActions == null) { return; } // Run the first action in the list SubActions.Act(); // Then consume it if its done if (SubActions.IsComplete()) { // TODO: Is this needed in C# compared to C++? Action temp = SubActions; SubActions = SubActions.Next; //delete temp; } }
private void Populate() { var memory = Player.Memory; AddAction(new ActAction($"Examine {memory.GetName(Item)}", () => { StringBuilder description = new StringBuilder(memory.GetDescription(Item)); SubActions.Add(new MessageBox(description.ToString(), InputResult.Close)); return(InputResult.None); })); if (Item is IEdible edible && edible.CanEat(Player)) { AddAction(new ActAction($"Eat {memory.GetName(Item)}", () => { edible.EatEffect(Player); return(Item.Destroyed ? InputResult.Close : InputResult.None); })); } if (Item is Weapon weapon) { AddAction(new ActAction($"Equip {memory.GetName(Item)}", () => { Player.Weapon = weapon; return(InputResult.Close); })); } if (Item is Potion potion) { AddAction(new ActAction($"Quaff {memory.GetName(Item)}", () => { potion.DrinkEffect(Player); return(Item.Destroyed ? InputResult.Close : InputResult.None); })); } AddAction(new ActAction($"Dispose {memory.GetName(Item)}", () => { Item.Destroy(); SubActions.Add(new MessageBox($"Threw {memory.GetName(Item)} away.", InputResult.Close)); return(Item.Destroyed ? InputResult.Close : InputResult.None); })); }
public override void HandleInput(SceneGame scene) { base.HandleInput(scene); if (SubActions.Count > 0) { HandleSubActions(scene); if (SubActions.Count == 0) { Refresh(); } return; } if (Player.InventoryChanged) { Refresh(); } bool up = (scene.InputState.IsKeyPressed(Keys.W, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.LeftThumbstickUp, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.DPadUp, 20, 5)); bool down = (scene.InputState.IsKeyPressed(Keys.S, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.LeftThumbstickDown, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.DPadDown, 20, 5)); bool left = (scene.InputState.IsKeyPressed(Keys.A, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.LeftThumbstickLeft, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.DPadLeft, 20, 5)); bool right = (scene.InputState.IsKeyPressed(Keys.D, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.LeftThumbstickRight, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.DPadRight, 20, 5)); bool confirm = (scene.InputState.IsKeyPressed(Keys.Enter)) || (scene.InputState.IsButtonPressed(Buttons.A)); bool combine = (scene.InputState.IsKeyPressed(Keys.LeftShift, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.Y, 20, 5)); bool cancel = (scene.InputState.IsKeyPressed(Keys.Escape)) || (scene.InputState.IsButtonPressed(Buttons.B)); bool cancelRepeat = (scene.InputState.IsKeyPressed(Keys.Escape, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.B, 20, 5)); if (up) { Selection.Index--; } else if (down) { Selection.Index++; } else if (left) { Selection.SubIndex--; } else if (right) { Selection.SubIndex++; } else if (Items.Count > 0 && confirm) { var combinedSelections = CombineSelections.Concat(new[] { Selection }).Distinct(); if (combinedSelections.Count() > 1) { SubActions.Add(new ActCombine(Player, combinedSelections)); } else { SubActions.Add(new ActItem(Player, Selection)); } } else if (Items.Count > 0 && combine) { if (!CombineSelections.Contains(Selection)) { CombineSelections.Add(Selection); } else //Otherwise try to add one more item out of the stack { for (int i = 0; i < Selection.Stack.Count; i++) { var selection = new ItemSelection(this, Selection.Index, i); if (!CombineSelections.Contains(selection)) { CombineSelections.Add(selection); break; } } } } else if (cancel && !CombineSelections.Any()) { Result = InputResult.Close; } else if (cancelRepeat && CombineSelections.Any()) { CombineSelections.RemoveAt(CombineSelections.Count - 1); } }
public AuthorizedAction(string name, string subAction) : this(name) { SubActions.Add(new AuthorizedAction(subAction)); }