public void Reset() { Entity = EcsEntity.Null; Character = null; aiEntries = null; SpawnEntry = null; CombatEntity = null; searchTarget = null; aiTickRate = 0.1f; nextAiUpdate = Time.ElapsedTimeFloat + GameRandom.NextFloat(0, aiTickRate); target = EcsEntity.Null; }
public MapSpawnDatabaseInfo LoadSpawnInfo() { var mapSpawns = new MapSpawnDatabaseInfo(); mapSpawns.MapSpawnEntries = new Dictionary <string, List <MapSpawnEntry> >(); using var tr = new StreamReader(@"Data/MapSpawns.csv") as TextReader; using var csv = new CsvReader(tr, CultureInfo.CurrentCulture); var spawns = csv.GetRecords <CsvMapSpawnEntry>().ToList(); var entryCount = 0; foreach (var spawn in spawns) { if (string.IsNullOrWhiteSpace(spawn.Map) || spawn.Map.StartsWith("//") || spawn.Map.StartsWith("#")) { continue; } var entry = new MapSpawnEntry() { X = spawn.X, Y = spawn.Y, Width = spawn.Width, Height = spawn.Height, Count = spawn.Count, Class = spawn.Class, SpawnTime = spawn.SpawnTime, SpawnVariance = spawn.Variance }; if (!mapSpawns.MapSpawnEntries.ContainsKey(spawn.Map)) { mapSpawns.MapSpawnEntries.Add(spawn.Map, new List <MapSpawnEntry>()); } mapSpawns.MapSpawnEntries[spawn.Map].Add(entry); entryCount++; } ServerLogger.Log($"Loading map spawn sets: {entryCount}"); return(mapSpawns); }
public void Initialize(ref EcsEntity e, Character character, CombatEntity combat, MonsterDatabaseInfo monData, MonsterAiType type, MapSpawnEntry spawnEntry, string mapName) { Entity = e; Character = character; this.SpawnEntry = spawnEntry; CombatEntity = combat; MonsterBase = monData; aiType = type; SpawnMap = mapName; aiEntries = DataManager.GetAiStateMachine(aiType); nextAiUpdate = Time.ElapsedTimeFloat + 1f; if (Character.ClassId >= 4000 && SpawnEntry == null) { throw new Exception("Monster created without spawn entry"); //remove when arbitrary monster spawning is added } UpdateStats(); currentState = MonsterAiState.StateIdle; }
public EcsEntity CreateMonster(Map map, int classId, int x, int y, int width, int height, MapSpawnEntry spawnEntry) { var e = ecsWorld.AddAndReset <Character, CombatEntity, Monster>( out var ch, out var ce, out var m); var area = Area.CreateAroundPoint(new Position(x, y), width, height); area.ClipArea(map.MapBounds); Position p; if (width == 0 && height == 0 && x != 0 && y != 0) { p = new Position(x, y); } else { if (x == 0 && y == 0 && width == 0 && height == 0) { area = map.MapBounds; } if (!map.FindPositionInRange(area, out p)) { ServerLogger.LogWarning($"Failed to spawn {classId} on map {map.Name}, could not find spawn location around {x},{y}. Spawning randomly on map."); map.FindPositionInRange(map.MapBounds, out p); } } var mon = DataManager.GetMonsterById(classId); ch.Id = GetNextEntityId(); ch.ClassId = classId; ch.Entity = e; ch.Position = p; ch.MoveSpeed = mon.MoveSpeed; ch.Type = CharacterType.Monster; ch.FacingDirection = (Direction)GameRandom.Next(0, 7); ce.Entity = e; entityList.Add(ch.Id, e); ce.Init(ref e, ch); m.Initialize(ref e, ch, ce, mon, mon.AiType, spawnEntry, map.Name); //ServerLogger.Log("Entity spawned at position: " + ch.Position); return(e); }