public void AddFloor(FloorState floor) { this.floors.Add(floor); if (this.floors[floor.Level] != floor) { throw new NotImplementedException("can't have multiple of same floor"); } }
public static int DistanceBetweenEntities(Entity a, Entity b) { var aPos = a.TryGetPosition(); var bPos = b.TryGetPosition(); if (aPos.Z != bPos.Z) { return(Int16.MaxValue); } return(FloorState.DistanceBetweenPositions(aPos.X, aPos.Y, bPos.X, bPos.Y)); }
private static bool InScanRangeOfPlayer(Entity player, Entity aiEntity, Cell possiblePosition) { if (player != null) { var scanRange = aiEntity.TryGetAttribute(EntityAttributeType.SCAN_REQUIRED_RADIUS).Value; var playerPos = player.TryGetPosition(); var dist = FloorState.DistanceBetweenPositions(playerPos.X, playerPos.Y, possiblePosition.X, possiblePosition.Y); return(dist <= scanRange); } else { return(false); } }
private static FloorState BuildArena(DungeonState dungeon, int width, int height, string mapID, IEnumerable <Entity> entities, int level) { if (!seedsToMaps.ContainsKey(mapID)) { var map = Map.Create(new RogueSharp.MapCreation.RandomRoomsMapCreationStrategy <Map>(width, height, 2000, 9, 5, new DotNetRandom(Int32.Parse(mapID)))); var pathFinder = new PathFinder(map); seedsToMaps[mapID] = new Tuple <IMap, PathFinder>(map, pathFinder); } var mapEntities = new List <Entity>(); foreach (var e in entities) { mapEntities.Add(e); } FloorState floorState = new FloorState(dungeon, mapEntities, mapID, seedsToMaps[mapID].Item1, seedsToMaps[mapID].Item2, level); var openCells = floorState.FloorMap.GetAllCells().Where(c => c.IsWalkable).ToList(); var placementRand = new DotNetRandom(Int32.Parse(mapID)); foreach (var e in mapEntities) { while (!e.HasComponentOfType <Component_Position>()) { var cell = openCells[placementRand.Next(openCells.Count - 1)]; Component_AI ai = e.GetComponentOfType <Component_AI>(); if (ai != null && !FloorBuilder.InScanRangeOfPlayer(floorState.Player, e, cell)) { floorState.PlaceEntityNear(e, cell.X, cell.Y); ai.DeterminePatrolPath(floorState, placementRand); } else if (ai == null) { floorState.PlaceEntityNear(e, cell.X, cell.Y); } } } return(floorState); }
// TODO: Whoops, I designed the stubs badly. I should swap the resolution function to the stub classes. public void ResolveStub(CommandStub stub) { var cmdPos = this.ResolveEID(stub.CommandEID).GetComponentOfType <Component_Position>(); var gameEvent = stub.ReifyStub(this.floors[cmdPos.Z]); // TODO: LOL you should resolve against the floor it's on! if (gameEvent != null && gameEvent.CommandEntity == this.nextCommandEntity) { gameEvent.CommandEntity.HandleEvent(gameEvent); if (gameEvent.ShouldLog) { this.DungeonLog.Add(gameEvent.LogMessage); } this.executedCommands.Add(gameEvent); } else if (gameEvent != null) { Log.ErrorLine("Can't resolve stub " + stub + " against entity " + gameEvent.CommandEntity + " as next Entity is " + this.nextCommandEntity); } else { throw new NullReferenceException("Stub " + stub + " reified to null; instead, return a delay!"); } // Hacky if (this.nextCommandEntity == this.Player) { foreach (var ai in this.DungeonEntities.Where(e => e.HasComponentOfType <Component_AI>())) { if (!ai.GetComponentOfType <Component_AI>().Scanned&& FloorState.DistanceBetweenEntities(this.Player, ai) <= ai.TryGetAttribute(EntityAttributeType.SCAN_REQUIRED_RADIUS).Value) { ai.GetComponentOfType <Component_AI>().Scanned = true; this.DungeonLog.Add("Scanned " + ai.Label + "!"); } } } this.ForwardToNextAction(); }