public override CommandStub GenerateCommand(GameQuery_Command commandQuery) { Entity target = commandQuery.ArenaState.Player; return(new CommandStub_PrepareTargetedAttack(commandQuery.CommandEntity.EntityID, target.EntityID, target.Label, BodyPartLocation.TORSO)); }
private int?ResolveOptionDistance(GameQuery_Command commandQuery, Entity target) { switch (this.Option) { case DistanceOption.MELEE_RANGE: return(1); case DistanceOption.MY_LONGEST_RANGE: return(commandQuery.CommandEntity.TryGetSubEntities(SubEntitiesSelector.WEAPON) .Select(e => e.TryGetAttribute(EntityAttributeType.MAX_RANGE, e).Value) .Max()); case DistanceOption.MY_MEDIUM_RANGE: return(commandQuery.CommandEntity.TryGetSubEntities(SubEntitiesSelector.WEAPON) .Select(e => e.TryGetAttribute(EntityAttributeType.MAX_RANGE, e).Value) .Max() / 2); case DistanceOption.ENEMY_LONGEST_RANGE: return(target.TryGetSubEntities(SubEntitiesSelector.WEAPON) .Select(e => e.TryGetAttribute(EntityAttributeType.MAX_RANGE, e).Value) .Max()); default: throw new NotImplementedException(); } }
private static RogueSharp.Path GeneratePath(GameQuery_Command commandQuery, GameQuery_Position targetPos) { // TODO: Wow this is awkward!? var commandPos = commandQuery.CommandEntity.TryGetPosition(); var commandCell = commandQuery.ArenaState.ArenaMap.GetCell(commandPos.X, commandPos.Y); var targetCell = commandQuery.ArenaState.ArenaMap.GetCell(targetPos.X, targetPos.Y); return(commandQuery.ArenaState.ShortestPath(commandCell, targetCell)); }
public override CommandStub GenerateCommand(GameQuery_Command commandQuery) { Entity target = commandQuery.ArenaState.Player; var targetPos = target.TryGetPosition(); if (this.lastPath == null || !this.EnemyOnPath(targetPos)) { this.lastPath = Action_MoveTowardsEnemy.GeneratePath(commandQuery, targetPos); } return(this.MoveEventForPath(commandQuery, this.lastPath)); }
public override CommandStub GenerateCommand(GameQuery_Command commandQuery) { Entity target = commandQuery.FloorState.Player; // TODO: Wow this is awkward!? var commandPos = commandQuery.CommandEntity.TryGetPosition(); var commandCell = commandQuery.FloorState.FloorMap.GetCell(commandPos.X, commandPos.Y); var targetPos = target.TryGetPosition(); var targetCell = commandQuery.FloorState.FloorMap.GetCell(targetPos.X, targetPos.Y); var shortestPath = commandQuery.FloorState.ShortestPath(commandCell, targetCell); if (shortestPath == null) { return(null); } var myDist = shortestPath.Length; var currDist = myDist; int awayX = 0, awayY = 0; // TODO: This is incredibly, absurdly inefficient! However it's sure to be optimal in a one-move timeframe. for (int x = commandPos.X - 1; x < commandPos.X + 2; x++) { for (int y = commandPos.Y - 1; y < commandPos.Y + 2; y++) { if (commandQuery.FloorState.FloorMap.IsWalkable(x, y) && !(x == targetPos.X && y == targetPos.Y)) { var candidateCell = commandQuery.FloorState.FloorMap.GetCell(x, y); var path = commandQuery.FloorState.ShortestPath(candidateCell, targetCell); if (path == null) { return(null); } if (path.Length > currDist) { awayX = x; awayY = y; currDist = path.Length; } } } } if (currDist > myDist) { return(new CommandStub_MoveSingle(commandQuery.CommandEntity.EntityID, awayX - commandPos.X, awayY - commandPos.Y)); } else { return(null); } }
public void TryRegisterCommand(GameQuery_Command commandRequest) { CommandStub command = this.clauses.Where(r => r.ShouldTakeAction(commandRequest)) .Select(r => r.CommandForQuery(commandRequest)) .FirstOrDefault(); if (command != null) { commandRequest.RegisterCommand(command); } }
public override bool IsMet(GameQuery_Command commandQuery) { // TODO: This is gonna show up in a lot of conditions, and looks pretty janky. Entity target = commandQuery.ArenaState.Player; var targetPos = target.TryGetPosition(); var selfPos = commandQuery.CommandEntity.TryGetPosition(); // TODO: I don't really subscribe to Demeter, but this is a pretty long chain! var path = commandQuery.ArenaState.ArenaMap .GetCellsAlongLine(selfPos.X, selfPos.Y, targetPos.X, targetPos.Y); return(!path.Any(c => !c.IsWalkable)); }
private CommandStub MoveEventForPath(GameQuery_Command commandQuery, RogueSharp.Path path) { var commandPos = commandQuery.CommandEntity.TryGetPosition(); var nextCell = path.CurrentStep; if (path.CurrentStep != path.End) { path.StepForward(); } return(new CommandStub_MoveSingle(commandQuery.CommandEntity.EntityID, nextCell.X - commandPos.X, nextCell.Y - commandPos.Y)); }
public override CommandStub GenerateCommand(GameQuery_Command commandQuery) { Entity target = commandQuery.FloorState.Player; var targetPos = target.TryGetPosition(); // TODO: Lol wtf if (commandQuery.CommandEntity.TryGetPosition().Z != targetPos.Z) { return(new CommandStub_Delay(commandQuery.CommandEntity.EntityID, Config.ONE)); } if (this.lastPath == null || !this.EnemyOnPath(targetPos)) { this.lastPath = Action_MoveTowardsEnemy.GeneratePath(commandQuery, targetPos); } return(this.MoveEventForPath(commandQuery, this.lastPath)); }
public bool ShouldTakeAction(GameQuery_Command commandQuery) { if (!this.action.CanExecuteOn(commandQuery)) { return(false); } foreach (var c in this.conditions) { if (!c.IsMet(commandQuery)) { return(false); } } return(true); }
private void HandleQueryCommand(GameQuery_Command q) { if (this.Alerted) { this.activeBook.TryRegisterCommand(q); } else if (q.FloorState.Player != null && FloorState.DistanceBetweenEntities(this.Parent, q.FloorState.Player) <= this.Parent.TryGetAttribute(EntityAttributeType.DETECTION_RADIUS).Value) { q.FloorState.AlertAllAIs(); } else { var myPos = this.Parent.TryGetPosition(); if (myPos.X == this.PatrolStart.X && myPos.Y == this.PatrolStart.Y) { this.OnReturnLeg = false; } else if (myPos.X == this.PatrolEnd.X && myPos.Y == this.PatrolEnd.Y) { this.OnReturnLeg = true; } Cell myCell = q.FloorState.FloorMap.GetCell(myPos.X, myPos.Y); Path patrolPath; if (!this.OnReturnLeg) { patrolPath = q.FloorState.ShortestPath(myCell, this.PositionToCell(this.PatrolEnd, q.FloorState)); } else { patrolPath = q.FloorState.ShortestPath(myCell, this.PositionToCell(this.PatrolStart, q.FloorState)); } if (patrolPath != null) { q.RegisterCommand(this.MoveEventForPath(q, patrolPath)); } else { q.RegisterCommand(new CommandStub_Delay(this.Parent.EntityID, Config.ONE)); } } }
public override bool IsMet(GameQuery_Command commandQuery) { // TODO: This is gonna show up in a lot of conditions, and looks pretty janky. Entity target = commandQuery.FloorState.Player; // TODO: Smooth out this int? business! // It's an int? because some conditions (asking for WEAPON_RANGE on something which has no range, like a // MechSkeleton, but which does get turns) are nonsensical. int?optionDistance = this.ResolveOptionDistance(commandQuery, target); if (optionDistance == null) { return(true); } int currDist = FloorState.DistanceBetweenEntities(target, commandQuery.CommandEntity); switch (this.Operator) { case ComparisonOperator.EQUAL: return(currDist == optionDistance); case ComparisonOperator.LESS_THAN: return(currDist < optionDistance); case ComparisonOperator.LESS_THAN_EQUAL: return(currDist <= optionDistance); case ComparisonOperator.GREATER_THAN: return(currDist > optionDistance); case ComparisonOperator.GREATER_THAN_EQUAL: return(currDist >= optionDistance); default: throw new InvalidOperationException("Condition_Distance can't handle " + this.Operator); } }
public abstract CommandStub GenerateCommand(GameQuery_Command commandQuery);
public override bool CanExecuteOn(GameQuery_Command commandQuery) { return(commandQuery.CommandEntity.HasComponentOfType <Component_Skeleton>() && this.GenerateCommand(commandQuery) != null); }
public override CommandStub GenerateCommand(GameQuery_Command commandQuery) { var remainingAP = commandQuery.CommandEntity.TryGetAttribute(EntityAttributeType.CURRENT_AP).Value; return(new CommandStub_Delay(commandQuery.CommandEntity.EntityID, remainingAP)); }
public override bool CanExecuteOn(GameQuery_Command commandQuery) { return(commandQuery.CommandEntity.HasComponentOfType <Component_Skeleton>()); }
public override bool IsMet(GameQuery_Command commandQuery) { throw new NotImplementedException(); }
public abstract Boolean CanExecuteOn(GameQuery_Command commandQuery);
public override bool CanExecuteOn(GameQuery_Command commandQuery) { var equipped = commandQuery.CommandEntity.TryGetSubEntities(SubEntitiesSelector.EQUIPPED); return(equipped.Any(e => e.MatchesSelector(SubEntitiesSelector.WEAPON))); }
public CommandStub CommandForQuery(GameQuery_Command commandQuery) { return(this.action.GenerateCommand(commandQuery)); }
public abstract bool IsMet(GameQuery_Command commandQuery);
public override bool CanExecuteOn(GameQuery_Command commandQuery) { // Anything which takes actions must implicitly track time and be delayable, hence always true return(true); }