public void Can_cast_new_being() { IBeing newRat = director.BuildNewBeing("flame rat"); Assert.That(newRat, Is.Not.Null); Assert.That(newRat.Foreground, Is.EqualTo(Color.Red)); }
public virtual void SetUp() { Basis.ConnectIDGenerator(); Engine.Cosmogenesis("bang", __factory); _gameState = new GameState { Map = new CompoundMap { BeingMap = new BeingMap(), RotMap = new RotMap(), SpaceMap = CreateSmallTestMap(), ItemMap = new ItemMap(), }, }; _inQ = new Queue <AsciiKey>(); __messager.GetNextKeyPress() .Returns((ci) => _inQ.Count > 0 ? _inQ.Dequeue() : new AsciiKey { Key = Keys.None }); __messager.IsInputReady() .Returns((ci) => _inQ.Count > 0); _strategy = new BeingStrategy_UserInput(_gameState); SourceMe.InjectProperties(_strategy); __being = Substitute.For <IBeing>(); __being.IsPlayer = true; }
public Command Use_Pick_Item(AsciiKey press, IBeing being) { if (press.Key == Keys.Escape) { return(CancelMultiStep("cancelled.")); } var selectedIndex = AlphaIndexOfKeyPress(press); if (selectedIndex < 0 || being.Inventory.Count() <= selectedIndex) { return(SameStep($"The key [{PressRep(press)}] does not match an inventory item. Pick another.")); } var item = being.Inventory.ElementAt(selectedIndex); if (!item.IsUsable) { return(SameStep($"The {Describer.Describe(item)} is not a usable item. Pick another.")); } thisUsedItem = item; return(NextStepIs( Use_Has_Item, $"Direction to use the {Describer.Describe(thisUsedItem)}, or [a-z?] to choose item: ", being)); }
private Command Use_Has_Item(AsciiKey press, IBeing being) { var dir = DirectionOf(press); if (dir != CmdDirection.None) { priorUsedItem = thisUsedItem; thisUsedItem = null; return(FinishedCommand(CmdAction.Use, dir, priorUsedItem)); } //1.+: 'Use' inventory suggesting uses? if (press.Key == Keys.OemQuestion) { return(ShowInventory(being, i => i.IsUsable)); } if (press.Key == Keys.Escape) { return(CancelMultiStep("cancelled.")); } if ('a' <= press.Character && press.Character <= 'z') { return(Use_Pick_Item(press, being)); } WriteLine($"The key [{PressRep(press)}] does not match an inventory item or a direction. Pick another."); return(commandIncomplete); // Some of this needs to end up in Action system // var targetPoint = PointInDirection(Player.Point, direction); // WriteLine(direction.ToString()); // _usingItem.ApplyTo(Map[targetPoint], this, direction); // the magic }
public static void Main() { string input; List <IBeing> allBeings = new List <IBeing>(); while ((input = Console.ReadLine()) != "End") { var beingInfo = input.Split(); IBeing being = null; if (beingInfo.Length > 2) { being = new Citizen(beingInfo[0], int.Parse(beingInfo[1]), beingInfo[2]); } else { being = new Robot(beingInfo[0], beingInfo[1]); } allBeings.Add(being); } string lastDigits = Console.ReadLine(); var fakes = allBeings.Where(b => b.Id.EndsWith(lastDigits)).ToList(); fakes.ForEach(b => Console.WriteLine(b.Id)); }
public Command Use(IBeing being) { //0.2: Next, usability in context? Or good enough? var inv_usables = being.Inventory.Where(i => i.IsUsable).ToList(); //var reach_usables = actor.ReachableItems().Where(i => i.IsUsable).ToList(); if (inv_usables.Count == 0) { return(CancelMultiStep("Nothing usable on me.")); } thisUsedItem ??= priorUsedItem ?? being.WieldedTool; if (thisUsedItem == null) { if (!Messager.IsInputReady()) { ShowInventory(being, i => i.IsUsable); } return(NextStepIs(Use_Pick_Item, "Use item: ", being)); } return(NextStepIs( Use_Has_Item, $"Direction to use the {Describer.Describe(thisUsedItem)}, or [a-z?] to choose item: ", being)); }
/// <summary> /// This allows messages to adapt based on the Being involved and /// what messages have already been seen, how many times, et c. /// </summary> public void Message(IBeing being, MessageEnum messageKey) { Guard.Against(messageKey == MessageEnum.Unset, "Must set message key"); if (!being.IsPlayer) { return; } switch (messageKey) { case MessageEnum.BarehandRotDamage: if (FirstTimeFor(messageKey)) { //0.2 promote to alert WriteLine("I tear a chunk off the ground. It fights back--burns my hands."); WriteLine("The stuff withers away from where I grab it."); } else { WriteLine("I hit it, and the stuff withers."); } break; case MessageEnum.RotDamageSpreads: WriteLine("The damage I did to this stuff spreads outward. Good."); break; default: var need_message_for_key = $"Must code message for key [{messageKey}]."; WriteLine(need_message_for_key); throw new Exception(need_message_for_key); } }
public void WriteLineIfPlayer(IBeing being, string message) { if (being.IsPlayer) { WriteLine(message); } }
public bool CanActorSeeTarget(IBeing being, Coord target) { //FINISH: one FOV and one Pathfinder per map //FieldOfView fov = new FieldOfView(Map); //fov.ComputeFov(actor.Point, actor.Awareness, true); //return fov.IsInFov(target); return(false); }
// may belong elsewhere soon public IBeing FindBeing(string entityWanted) { IBeing being = null; // Phase 2: ? being = SocialRegister.FindBeing(entityWanted); return(being); }
public Command Consume(IBeing being) { //1.+: food on ground, on adjacent plant, drink from pool... var inv_consumables = being.Inventory.Where(i => i.IsIngestible).ToList(); return((inv_consumables.Count == 0) ? CancelMultiStep("Nothing to eat or drink on me.") : NextStepIs(Consume_main, "Consume (inventory letter or ? to show inventory): ", being)); }
public void WriteYaml(IEmitter emitter, object value, Type type) { IBeing being = (IBeing)value; emitter.Emit(new MappingStart(null, null, false, MappingStyle.Block)); BeingCreator.Being_ToYaml(emitter, being); emitter.Emit(new MappingEnd()); }
public void Can_cast_NPC() { var reg = SourceMe.The <SocialRegister>(); reg.LoadRegister(); IBeing kellet = director.FindBeing("Kellet Benison"); Assert.That(kellet, Is.Not.Null); Assert.That(kellet.Foreground, Is.EqualTo(Color.AliceBlue)); }
public object ReadYaml(IParser parser, Type type) { //if (!Debugger.IsAttached) Debugger.Launch(); parser.Consume <MappingStart>(); IBeing being = BeingCreator.Being_FromYaml(parser); parser.Consume <MappingEnd>(); return(being); }
public Command Wield(IBeing being) { var wieldables = being.Inventory.ToList(); if (wieldables.Count == 0) { return(CancelMultiStep("Nothing to wield.")); } return(NextStepIs(Wield_main, "Wield (inventory letter or ? to show inventory): ", being)); }
/// <summary> /// The BeingStrategy_UserInput builds a Command based on keyboard input. /// It may take thousands of Update() callbacks before a Command /// other than CommandIncomplete is returned. /// </summary> public Command GetCommand(IBeing being) { var press = Messager.GetNextKeyPress(); // Most of the time, we'll have no human input, hence no command. if (press.Key == Keys.None) { return(commandIncomplete); } // Most commands take multiple keystrokes to resolve. // When that's true, we've stored the next step to take for when // we have the next keystroke(s) to get us closer to a Command. if (IsAssemblingCommand) { return(nextStep(press, being)); } // Otherwise, if we've got a direction key, do that var dir = DirectionOf(press); if (dir != CmdDirection.None) { return(Direction(being, dir)); } // Or dispatch the beginning of another Command switch (press.Key) { case Keys.C: return(Consume(being)); case Keys.D: return(Drop(being)); case Keys.H: return(Help()); case Keys.I: return(Inventory(being)); case Keys.S: return(SaveGame()); case Keys.U: return(Use(being)); case Keys.W: return(Wield(being)); case Keys.OemComma: return(PickUp(being)); default: if (press.Character != default(char)) { WriteLine($"Command [{press.Character}] is unknown."); } return(commandIncomplete); } }
public void DispatchCommand(IBeing being) { switch (being.StrategyStyle) { case StrategyStyle.UserInput: Strat_UserInput.GiveCommand(being); break; default: throw new Exception($"Need to learn how to dispatch command for strategy [{being.StrategyStyle}]."); } }
/// <summary> 0.2: Currently, grab the topmost. Later, choose. </summary> public Command PickUp(IBeing being) { var items = gameState.Map.ItemMap.GetItems(being.GetPosition()); var topItem = items.LastOrDefault(); if (topItem == null) { return(CancelMultiStep("Nothing to pick up here.")); } return(FinishedCommand(CmdAction.PickUp, CmdDirection.None, topItem)); }
public bool CommandBeing(IBeing being, Command command) { return(command.Action switch { CmdAction.Consume => Do_Consume(being, command), CmdAction.Direction => Do_Direction(being, command.Direction), CmdAction.Drop => Do_Drop(being, command), CmdAction.PickUp => Do_PickUp(being, command), CmdAction.Use => Do_Usable(being, command), CmdAction.Wait => Do_Wait(being, command), CmdAction.Wield => Do_Wield(being, command.Item), _ => throw new Exception($"Not ready to for Command {command.Action}."), });
public SocialRegister Register_FromYaml(IParser parser, IBeingCreator creator) { parser.Consume <MappingStart>(); var register = new SocialRegister(creator); while (parser.TryConsume <Scalar>(out var evt) && evt.Value == "Being") { parser.Consume <MappingStart>(); IBeing being = creator.Being_FromYaml(parser); parser.Consume <MappingEnd>(); register.WellKnownBeings[being.Name] = being; } parser.Consume <MappingEnd>(); return(register); }
private Command Direction(IBeing being, CmdDirection dir) { var newPosition = Controls.CoordInDirection(being.GetPosition(), dir); var targetRot = gameState.Map.RotMap.GetItem(newPosition); if (targetRot != null) { //0.1.STORY increase impact--this is an early landmark in the story if (!Story.HasClearedRot) { rotDirection = dir; Messager.WriteLine("The filth covering the ground sets my teeth on edge. I'm growling."); return(NextStepIs(Direction_decide_to_Clear_Rot, "Am I going after this stuff bare-handed? ", being)); } } return(FinishedCommand(CmdAction.Direction, dir)); }
public Command Drop_main(AsciiKey press, IBeing being) { if (press.Key == Keys.Escape) { return(CancelMultiStep("Drop cancelled.")); } if (press.Character == '?') { return(ShowInventory(being, i => true)); } var item = ItemInInventoryLocation(press, being); if (item == null) { return(SameStep($"Nothing in inventory slot {press.Character}.")); } return(FinishedCommand(CmdAction.Drop, CmdDirection.None, item)); }
public void LoadRegister(IBeing ourHero) { AddTownsfolk("Jeromi Kandering"); AddTownsfolk("Carol Embreya"); AddTownsfolk("Bock Merrital"); AddTownsfolk("Caben Merrital"); AddTownsfolk("Runcel Longwalk"); AddTownsfolk("Kellet Benison"); AddTownsfolk("Gervandik"); AddTownsfolk("Merotta Carrier"); AddTownsfolk("Belo Freitan"); AddTownsfolk("Kuvven Turtler"); AddTownsfolk("Helmai Preston"); AddTownsfolk("Matchel Dariley"); AddTownsfolk("Pal Ketterit"); AddTownsfolk("Kuez Bell"); //0.1: Needs to load NPCs from file WellKnownBeings[ourHero.Name] = ourHero; }
public Command Wield_main(AsciiKey press, IBeing being) { if (press.Key == Keys.Escape) { return(CancelMultiStep("Wield cancelled.")); } //0.2: Perhaps only 'likely' wields by default? if (press.Key == Keys.OemQuestion) { return(ShowInventory(being, i => true)); } var item = ItemInInventoryLocation(press, being); if (item == null) { return(SameStep($"Nothing in inventory slot {press.Character}.")); } return(FinishedCommand(CmdAction.Wield, CmdDirection.None, item)); }
public void GiveCommand(IBeing being) { void DeliverCommandFromInput() { var cmd = GetCommand(being); if (cmd.Action == CmdAction.Incomplete) { return; } var actionWasTaken = Controls.CommandBeing(being, cmd); if (actionWasTaken) { nextStep = null; GameMode.PopEngineMode(); } } GameMode.PushEngineMode(EngineMode.PlayerTurn, DeliverCommandFromInput); DeliverCommandFromInput(); }
public void CheckActorAtCoordEvent(IBeing being, Coord position) { ////0.1.MAP fix load of map-based events //if (Map.LocationMessages.ContainsKey(tile.Point)) //{ // var message = Map.LocationMessages[tile.Point]; // foreach (var line in message) // Output.WriteLine(line); // Map.LocationMessages.Remove(tile.Point); //} //if (Map.LocationEventEntries.ContainsKey(tile.Point)) //{ // var entries = Map.LocationEventEntries[tile.Point]; // foreach (var entry in entries) // { // //CommandQueue.Enqueue(entry.Command); // } //} //0.3 may unify those collections and loops, may restructure flow }
public Command Direction_decide_to_Clear_Rot(AsciiKey press, IBeing being) { // Decision mechanic: hit 'y', or travel in a direction // towards rot (in which case, the decision direction will // be the attack direction, even if different from the original // direction). Any other response cancels move/attack. bool affirm = press.Key == Keys.Y; if (!affirm) { var dir = DirectionOf(press); if (dir != CmdDirection.None) { var dirCoord = Controls.CoordInDirection(being.GetPosition(), dir); var dirRot = gameState.Map.RotMap.GetItem(dirCoord); affirm = (dirRot != null); if (affirm) { rotDirection = dir; } } } if (affirm) { Story.HasClearedRot = true; WriteLine("Yes. Now."); Log.Info("Decided to clear Rot."); return(FinishedCommand(CmdAction.Direction, rotDirection)); } else { return(CancelMultiStep("Not yet.")); } }
public Command Consume_main(AsciiKey press, IBeing being) { if (press.Key == Keys.Escape) { return(CancelMultiStep("cancelled.")); } if (press.Character == '?') { return(ShowInventory <IIngestible>(being)); } var item = ItemInInventoryLocation(press, being); if (item == null) { return(SameStep($"Nothing in inventory slot {press.Character}.")); } if (!item.IsIngestible) { return(SameStep($"I can't eat or drink {Describer.Describe(item, DescMods.Article)}.")); } return(FinishedCommand(CmdAction.Consume, CmdDirection.None, item)); }
public virtual void TearDown() { _inQ = null; _strategy = null; __being = null; }
public void Attack(IBeing target) { target.TakeDamage(this.GetAttackDamage()); }