public static ILocEntryResult EnterLoc(this ILoc loc, Player player) { if (loc is EntranceLoc entrance) { return(new OkResult()); } else if (loc is ExitLoc exit) { return(new ChoiceRequiredResult( "After you entered the room, you see a giant dragon sitting on a no less giant chest. What will you do?", new ChoiceOption("Rush at him (-5 health)", new OkResult(-5, 0)), new ChoiceOption("Cast a fireball (-3 mana)", new OkResult(0, -3), player.Mana >= 3) )); } else if (loc is MonsterLoc monster) { return(new OkResult(-2, 0, "Something massive jumps on you and you fall down. Your body is damaged, but your knife strikes immediately. Cave wolf is dead.")); } else if (loc is CampLoc camp) { return(new ChoiceRequiredResult( "You take a slow look at the place you just appeared in. Finally you drop your weapon down and decide to take a break. How do you decide to relax?", new ChoiceOption("Sleep (+1 health)", new OkResult(1, 0)), new ChoiceOption("Meditate (+1 mana)", new OkResult(0, 1)))); } else { throw new NotImplementedException(loc.GetType().ToString()); } }
private LocView InstantiateLoc(ILoc loc) { var prefab = GetLocViewPrefab(loc); var locView = Instantiate(prefab); return(locView); }
public Grid <(ILoc origLoc, T origValue)> SubGrid(ILoc startLoc, int rowLength, int colLength) { var(startRow, startCol) = startLoc.ToRowCol(); (ILoc originLoc, T origValue) MoveCell(ILoc loc) { var(r, c) = loc.ToRowCol(); var l = new Loc(startRow + r, startCol + c); return(l, this[l]); } if (startRow < 0) { startRow = 0; } if (startCol < 0) { startCol = 0; } if (startRow + rowLength > RowCount) { rowLength = RowCount - startRow; } if (startCol + colLength > ColCount) { colLength = ColCount - startCol; } var ret = new Grid <(ILoc, T)>(rowLength, colLength); Transfer(MoveCell, ret); return(ret); }
/// <summary> /// Create a 'loc equals' predicate /// </summary> public ILocEqualsPredicate CreateEquals(ILoc loc) { ILocEqualsPredicate x = new LocEqualsPredicate(); x.Loc = loc; return(x); }
/// <summary> /// Gets the groups containing this loc. /// </summary> private string GetGroups(ILoc loc) { var groups = railway.LocGroups.Where(x => x.Locs.ContainsId(loc.Id)).ToList(); if (groups.Count == 0) { return("-"); } return(string.Join(", ", groups.Select(x => x.Description).ToArray())); }
/// <summary> /// Loc setter /// </summary> private void SetIsElement(ILoc loc, bool isElement) { if (isElement) { Entity.Locs.Add(loc); } else { Entity.Locs.Remove(loc); } }
public T this[ILoc loc] { get { var(row, col) = loc.ToRowCol(); return(_cells[row, col]); } set { var(row, col) = loc.ToRowCol(); _cells[row, col] = value; } }
private void ConnectLocsRecursively(ILoc loc, Dictionary <ILoc, ILocView> locViews) { if (loc is ExitLoc) { return; } foreach (var l in loc.NextLocs) { ConnectLocs(locViews[loc].ToLocView(), locViews[l].ToLocView()); ConnectLocsRecursively(l, locViews); } }
/// <summary> /// Evaluate this predicate for the given loc. /// </summary> public override bool Evaluate(ILoc loc) { var includes = Includes; var excludes = Excludes; if (includes.IsEmpty && excludes.IsEmpty) { return(true); } if (includes.IsEmpty) { return(!excludes.Evaluate(loc)); } return(includes.Evaluate(loc) && !excludes.Evaluate(loc)); }
public static bool IsLocValid(this ILoc loc) { if (loc is ExitLoc) { return(true); } if (loc == null) { return(false); } if (loc.NextLocs == null || loc.NextLocs.Length == 0) { return(false); } return(loc.NextLocs.All(l => l.IsLocValid())); }
public Loc(ILoc loc, ILocState state) { Id = loc.Id; Description = loc.Description; Owner = loc.Owner; if (state != null) { Speed = state.Speed.Actual; SpeedText = state.GetSpeedText(); StateText = state.GetStateText(); IsAssigned = state.CurrentBlock.Actual != null; IsCurrentRouteDurationExceeded = state.IsCurrentRouteDurationExceeded; IsControlledAutomatically = state.ControlledAutomatically.Actual; Direction = state.Direction.Actual.ToString().ToLower(); HasPossibleDeadlock = state.PossibleDeadlock.Actual; } }
/// <summary> /// Try to resolve a loc by the given id. /// The loc is searched in the <see cref="Locs"/> set and the archived locs. /// </summary> internal bool TryResolveLoc(string id, out ILoc loc) { var locRef = Locs[id]; if (locRef != null) { if (locRef.TryResolve(out loc)) { return(true); } } var package = Package; if (package != null) { loc = package.GetLoc(id); return(loc != null); } loc = null; return(false); }
private LocView GetLocViewPrefab(ILoc loc) { if (loc is EntranceLoc) { return(entrancePrefab); } else if (loc is ExitLoc) { return(exitPrefab); } else if (loc is MonsterLoc) { return(monsterPrefab); } else if (loc is CampLoc) { return(campPrefab); } else { throw new NotImplementedException(loc.GetType().Name); } }
/// <summary> /// Evaluate this predicate for the given loc. /// </summary> public override bool Evaluate(ILoc loc) { var @group = Group; return((@group != null) && (loc != null) && @group.Locs.ContainsId(loc.Id)); }
private ILocView GetView(ILoc loc) { return(locViews[loc]); }
public static Distance Dist(this ILoc loc1, ILoc loc2) => new Distance((decimal)Sqrt(Sq(loc2.X - loc1.X) + Sq(loc2.Y - loc1.Y)));
public LocChangedMessage(ILoc loc, ILocState locState) { Type = TypLocChanged; Loc = new Loc(loc, locState); }
public override object Visit(ILoc entity, IRailway data) { data.Locs.Add(entity); return(null); }
public static DistanceSquared DistSq(this ILoc loc1, ILoc loc2) => new DistanceSquared(Sq(loc2.X - loc1.X) + Sq(loc2.Y - loc1.Y));
/// <summary> /// Evaluate this predicate for the given loc. /// </summary> public abstract bool Evaluate(ILoc loc);
/// <summary> /// Evaluate this predicate for the given loc. /// </summary> public override bool Evaluate(ILoc loc) { return(Predicates.All(x => x.Evaluate(loc))); }
/// <summary> /// Loc getter /// </summary> private bool IsElement(ILoc loc) { return(Entity.Locs.Contains(loc)); }
public override object Visit(ILoc entity, IPackage data) { data.Remove(entity); return(null); }
private void UpdateLoc(ILoc loc, LocStatus status) { var isHidden = !discoveredLocs.Contains(loc); view.UpdateLocView(GetView(loc), status, isHidden); }
/// <summary> /// Default ctor /// </summary> public LocEqualsMenuItem(ILoc loc, IRailway railway) { this.loc = loc; this.railway = railway; Text = loc.ToString(); }
/// <summary> /// Evaluate this predicate for the given loc. /// </summary> public override bool Evaluate(ILoc loc) { return((Loc != null) && (loc != null) && (Loc.Id == loc.Id)); }
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); } }
/// <summary> /// Evaluate this predicate for the given loc. /// </summary> public override bool Evaluate(ILoc loc) { return(true); // We can only seriously evaluate this at runtime. }
/// <summary> /// Evaluate this predicate for the given loc. /// </summary> public override bool Evaluate(ILoc loc) { return(loc.ChangeDirection == ChangeDirection.Allow); }
public virtual TReturn Visit(ILoc entity, TData data) { return(default(TReturn)); }