private void AddUnitToDeck(WargameUnit selectedUnit, Deck deck) { byte veterancy = (byte)selectedUnit.AvailableVeterancy[rnGesus.Next(selectedUnit.AvailableVeterancy.Count)]; if (selectedUnit.Transports.Count > 0) { WargameUnit transport = DrawCard(selectedUnit.Transports); if (transport.Transports.Count > 0) { WargameUnit superTransport = DrawCard(transport.Transports); deck.AddUnit(veterancy, (int)selectedUnit.UnitId, (int)transport.UnitId, (int)superTransport.UnitId); } else { deck.AddUnit(veterancy, (int)selectedUnit.UnitId, (int)transport.UnitId); } //AddedUnits[transport.UnitId] = AddedUnits[transport.UnitId] + 1; } else { deck.AddUnit(veterancy, (int)selectedUnit.UnitId); } //AddedUnits[selectedUnit.UnitId] = AddedUnits[selectedUnit.UnitId] + 1; }
private bool IsUnitValid(WargameUnit unit, Categories category) { return(unit.Category == category && (unit.Year >= deckRestrictions[category].MinYear && unit.Year <= deckRestrictions[category].MaxYear || fobRegex.IsMatch(unit.Name))); }
private List <WargameUnit> GetUnits(List <CollectionItemValueHolder> references) { var units = new List <WargameUnit>(); instanceIdToUnitId = GetInstanceIdToUnitIdMap(references); unitIdToUnit = new Dictionary <uint, WargameUnit>(); unitIdToTransports = new Dictionary <uint, List <uint> >(); unitUpgradeTree = new Dictionary <uint, uint>(); //<unit, next unit> BuildUnitUpgradeTree(); foreach (var reference in references) { NdfMap map = (NdfMap)reference.Value; var unit = GetUnit(map); uint unitId = (uint)((NdfUInt32)map.Key.Value).Value; unitIdToTransports[unitId] = GetTransportsIds(unit); var rawCategory = GetCategory(unit); Categories category = categories.ContainsKey(rawCategory) ? categories[rawCategory] : Categories.UNKNOWN; var modulesProperty = unit.PropertyValues.Where(p => p.Property.Name == "Modules").First(); var modules = (NdfCollection)modulesProperty.Value; var filteredList = modules.Where(m => ((NdfStringReference)((NdfString)((NdfMap)m.Value).Key.Value).Value).Value == "TypeUnit").First(); var tModuleSelector = ((NdfObjectReference)((MapValueHolder)((NdfMap)filteredList.Value).Value).Value).Instance; var defaultProperty = tModuleSelector.PropertyValues.Where(p => p.Property.Name == "Default").First(); var typeUnitModuleDescriptor = ((NdfObjectReference)defaultProperty.Value).Instance; var filtersProperty = typeUnitModuleDescriptor.PropertyValues.Where(p => p.Property.Name == "Filters").First(); var subCategoryLocalizationHash = "None"; if (filtersProperty.Value.GetType() == typeof(NdfMapList)) { subCategoryLocalizationHash = ((NdfCollection)((MapValueHolder)((NdfMap)((NdfMapList)filtersProperty.Value)[0].Value).Value).Value)[0].Value.ToString(); } Subcategories subcategory = subcategories.ContainsKey(subCategoryLocalizationHash) ? subcategories[subCategoryLocalizationHash] : Subcategories.NONE; var wUnit = new WargameUnit(unitId, GetNumberOfCards(unit), category, subcategory, GetYear(unit), GetCountry(unit), IsPrototype(unit), IsCommander(unit), GetName(unit)); wUnit.AvailableVeterancy.AddRange(GetAvailableVeterancy(unit)); List <Specializations> specs = GetAvailableSpecializations(unit); foreach (var spec in specs) { wUnit.Specializations.Add(spec); } units.Add(wUnit); unitIdToUnit[unitId] = wUnit; } foreach (var unit in units) { foreach (var transportId in unitIdToTransports[unit.UnitId]) { unit.Transports.Add(unitIdToUnit[transportId]); } } return(units); }
private void RemoveNavalTransports(WargameUnit unit) { unit.Transports.RemoveAll(t => t.Category == Categories.NAVAL); foreach (var transport in unit.Transports) { RemoveNavalTransports(transport); } }
private void CheckCardCount(WargameUnit selectedUnit) { WargameUnit referenceUnit = unitsAndTransports.Find(unit => unit.UnitId == selectedUnit.UnitId); if (AddedUnits[selectedUnit.UnitId] + 1 > referenceUnit.Cards) { Console.WriteLine("Exceeded."); } }
private List <WargameUnit> ShuffleUnits(List <WargameUnit> units) { List <WargameUnit> shuffledUnits = new List <WargameUnit>(units); for (int i = 0; i < 20 * shuffledUnits.Count; i++) { int indexA = rnGesus.Next(shuffledUnits.Count); int indexB = rnGesus.Next(shuffledUnits.Count); WargameUnit unit = shuffledUnits[indexA]; shuffledUnits[indexA] = shuffledUnits[indexB]; shuffledUnits[indexB] = unit; } return(shuffledUnits); }
static private void PrintUnits(List <WargameUnit> units, List <uint> unitsInDeck) { foreach (uint unitId in unitsInDeck) { WargameUnit wUnit = units.Find(unit => unit.UnitId == unitId); if (wUnit != null) { Console.WriteLine(wUnit.Name + ", " + wUnit.Category.ToString()); } else { Console.WriteLine(unitId + ": Not found in units..."); } } }
private bool HasNavalTransport(WargameUnit unit) { foreach (var transport in unit.Transports) { if (transport.Category == Categories.NAVAL) { return(true); } if (HasNavalTransport(transport)) { return(true); } } return(false); }
public WargameUnit DrawCard(List <WargameUnit> availableUnits) { double totalWeight = availableUnits.Sum(unit => unit.Weight); double chosen = rnGesus.NextDouble() * totalWeight; var enumerator = availableUnits.GetEnumerator(); while (chosen > 0 && enumerator.MoveNext()) { chosen -= enumerator.Current.Weight; } WargameUnit selectedUnit = enumerator.Current; //CheckCardCount(selectedUnit); selectedUnit.Cards--; CleanUpUnitPool(); return(selectedUnit); }
private void AddFob() { List <WargameUnit> fobs = unitPool[Categories.LOGISTICS].AvailableUnits.Where(unit => fobRegex.IsMatch(unit.Name)).ToList(); if (fobs.Count <= 0) { return; } WargameUnit fob = DrawCard(fobs); if (fob.Cards <= 0) { unitPool[Categories.LOGISTICS].AvailableUnits.RemoveAll(unit => unit.UnitId == fob.UnitId); } AddUnitToDeck(fob, deck); UpdateDeckCost(Categories.LOGISTICS, costMatrix); }
private void AddCommander() { List <WargameUnit> commanders = unitPool[Categories.LOGISTICS].AvailableUnits.Where(unit => unit.IsCommander).ToList(); if (commanders.Count == 0) { throw new Exception("No command unit available."); } WargameUnit commander = DrawCard(commanders); if (commander.Cards <= 0) { unitPool[Categories.LOGISTICS].AvailableUnits.RemoveAll(unit => unit.UnitId == commander.UnitId); } AddUnitToDeck(commander, deck); UpdateDeckCost(Categories.LOGISTICS, costMatrix); }
private bool IsTransportValid(WargameUnit transport, Categories category) { return(transport.Year >= deckRestrictions[category].MinTransportYear && transport.Year <= deckRestrictions[category].MaxTransportYear); }
public Deck GenerateDeck(Deck.DeckType type) { deck = new Deck(type); List <WargameUnit> units = LoadUnits(type); units = FilterInvalidUnits(units); units = FilterByDeckType(units, type); foreach (var unit in units) { RemoveNavalTransports(unit); } CategorizeUnitsAndApplyRestrictions(units); InitAddedUnits(units); InitCardCountChecker(type); foreach (var unitPoolCategory in unitPool) { InitUnitWeights(unitPoolCategory.Value.AvailableUnits); } int activationPoints = GetActivationPoints(type); costMatrix = database.GetCostMatrix(); UsedActivationPoints = 0; AddCommander(); AddCommander(); unitPool[Categories.LOGISTICS].AvailableUnits.RemoveAll(unit => unit.IsCommander); AddFob(); while (CanDrawAnotherCard()) { Categories category = ChooseCategory(); if (unitPool[category].AvailableUnits.Count == 0 || costMatrix[category].Count == 0 || costMatrix[category].First() + UsedActivationPoints > activationPoints) { unitPool.Remove(category); } else { WargameUnit selectedUnit = DrawCard(unitPool[category].AvailableUnits); AddUnitToDeck(selectedUnit, deck); UpdateDeckCost(category, costMatrix); } } List <WargameUnit> navalUnits = LoadUnits(type); navalUnits = FilterByDeckType(navalUnits, type); navalUnits = navalUnits.Where(unit => unit.Cards > 0 && unit.AvailableVeterancy.Count > 0 && unit.Specializations.Count > 0 && unit.Year > 1900 && (unit.Category == Categories.NAVAL || HasNavalTransport(unit))).ToList(); InitUnitWeights(navalUnits); foreach (var unit in navalUnits) { unit.Transports.RemoveAll(t => t.Category != Categories.NAVAL && !HasNavalTransport(t)); } while (navalUnits.Count > 0 && costMatrix[Categories.NAVAL].Count > 0) { WargameUnit navalUnit = DrawCard(navalUnits); AddUnitToDeck(navalUnit, deck); UpdateDeckCost(Categories.NAVAL, costMatrix); } return(deck); }