public void HandleLocEntryResult(ILoc loc, ILocEntryResult result, Player player) { if (result is ChoiceRequiredResult choiceRequired) { view.ChooseOption(choiceRequired, o => { HandleLocEntryResult(loc, o.Result, player); }); return; } DeactivateLocs(); CurrentLoc = loc; discoveredLocs.Add(loc); activeLocs.Add(loc); UpdateLoc(loc, LocStatus.Current); view.MovePlayer(GetView(loc)); if (result is OkResult okResult) { if (okResult.DeltaHealth != 0) { player.Health += okResult.DeltaHealth; view.SetHealth(player.Health, okResult.DeltaHealth); } if (okResult.DeltaMana != 0) { player.Mana += okResult.DeltaMana; view.SetMana(player.Mana, okResult.DeltaMana); } if (player.Health <= 0) { deadPlayers.Add(player); DeactivateLocs(); view.ShowDeath(); return; } else if (!string.IsNullOrEmpty(okResult.Text)) { view.ShowPopup(okResult.Text); } } if (loc is ExitLoc) { IsWin = true; view.ShowWin(); return; } foreach (var l in loc.NextLocs) { UpdateLoc(l, LocStatus.Active); view.SetLocAction(GetView(l), () => { var r = l.EnterLoc(player); HandleLocEntryResult(l, r, player); }); activeLocs.Add(l); } }
public ChoiceOption(string text, ILocEntryResult result, bool isAvailable = true) { Text = text; Result = result; IsAvailable = isAvailable; }