public UnitTemplate(int id, string name, bool isTopLevel, SquadTemplate hqSquadTemplate, List <SquadTemplate> childSquads) { Id = id; Name = name; IsTopLevelUnit = isTopLevel; _childSquads = childSquads; HQSquad = hqSquadTemplate; }
public Dictionary <int, List <Squad> > GetSquadsByUnitId(IDbConnection connection, IReadOnlyDictionary <int, SquadTemplate> squadTemplateMap, IReadOnlyDictionary <int, List <WeaponSet> > squadWeaponSetMap, IReadOnlyDictionary <int, Ship> shipMap, List <Planet> planetList) { Dictionary <int, List <Squad> > squadMap = new Dictionary <int, List <Squad> >(); IDbCommand command = connection.CreateCommand(); command.CommandText = "SELECT * FROM Squad"; var reader = command.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); int squadTemplateId = reader.GetInt32(1); int parentUnitId = reader.GetInt32(2); string name = reader[3].ToString(); bool isInReserve = reader.GetBoolean(6); SquadTemplate template = squadTemplateMap[squadTemplateId]; Squad squad = new Squad(id, name, null, template, isInReserve); if (reader[4].GetType() != typeof(DBNull)) { Ship ship = shipMap[reader.GetInt32(4)]; squad.BoardedLocation = ship; } if (reader[5].GetType() != typeof(DBNull)) { Planet planet = planetList.First(p => p.Id == reader.GetInt32(5)); squad.Location = planet; } if (!squadMap.ContainsKey(parentUnitId)) { squadMap[parentUnitId] = new List <Squad>(); } if (squadWeaponSetMap.ContainsKey(id)) { squad.Loadout = squadWeaponSetMap[id]; } squadMap[parentUnitId].Add(squad); } return(squadMap); }
public UnitTemplate(int id, string name, bool isTopLevel, List <SquadTemplate> childSquads, List <UnitTemplate> childUnits) { Id = id; Name = name; IsTopLevelUnit = isTopLevel; _childUnits = childUnits; SquadTemplate hq = childSquads.FirstOrDefault(squad => (squad.SquadType & SquadTypes.HQ) > 0); if (hq != null) { HQSquad = hq; childSquads.Remove(hq); } _childSquads = childSquads; }
private Tuple <Dictionary <int, List <SquadTemplate> >, Dictionary <int, SquadTemplate> > GetSquadTemplatesById( IDbConnection connection, Dictionary <int, List <SquadTemplateElement> > elementMap, Dictionary <int, WeaponSet> weaponSetMap, Dictionary <int, List <SquadWeaponOption> > squadWeaponOptionMap, Dictionary <int, ArmorTemplate> armorTemplateMap) { Dictionary <int, SquadTemplate> squadTemplateMap = new Dictionary <int, SquadTemplate>(); Dictionary <int, List <SquadTemplate> > squadTemplatesByFactionId = new Dictionary <int, List <SquadTemplate> >(); IDbCommand command = connection.CreateCommand(); command.CommandText = "SELECT * FROM SquadTemplate"; var reader = command.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); int factionId = reader.GetInt32(1); string name = reader[2].ToString(); int defaultArmorId = reader.GetInt32(3); int defaultWeaponSetId = reader.GetInt32(4); int squadType = reader.GetInt32(5); ArmorTemplate defaultArmor = armorTemplateMap[defaultArmorId]; List <SquadWeaponOption> options = squadWeaponOptionMap.ContainsKey(id) ? squadWeaponOptionMap[id] : null; SquadTemplate squadTemplate = new SquadTemplate(id, name, weaponSetMap[defaultWeaponSetId], options, defaultArmor, elementMap[id], (SquadTypes)squadType); squadTemplateMap[id] = squadTemplate; if (!squadTemplatesByFactionId.ContainsKey(factionId)) { squadTemplatesByFactionId[factionId] = new List <SquadTemplate>(); } squadTemplatesByFactionId[factionId].Add(squadTemplate); } return(new Tuple <Dictionary <int, List <SquadTemplate> >, Dictionary <int, SquadTemplate> >(squadTemplatesByFactionId, squadTemplateMap)); }