/// <summary>Makes the unit from string.</summary> /// <param name="name">The name.</param> /// <returns><see cref="Unit"/></returns> public static Unit MakeUnitFromString(string name) { Unit newUnit; switch (name) { case "Termagant Brood": newUnit = new Termagant(); break; case "Hive Tyrant": newUnit = new HiveTyrant(); break; case "Hive Guard": newUnit = new HiveGuard(); break; case "Lictor Brood": newUnit = new Lictor(); break; case "Zoanthrope Brood": newUnit = new Zoanthrope(); break; case "Venomthrope Brood": newUnit = new Venomthrope(); break; case "Haruspex": newUnit = new Haruspex(); break; case "Pyrovore Brood": newUnit = new Pyrovore(); break; case "Gargoyle Brood": newUnit = new Gargoyle(); break; case "Harpy": newUnit = new Harpy(); break; case "Hive Crone": newUnit = new HiveCrone(); break; case "Spore Mine Cluster": newUnit = new SporeMine(); break; case "Biovore Brood": newUnit = new Biovore(); break; case "Tyrannofex": newUnit = new Tyrannofex(); break; case "Deathleaper": newUnit = new Deathleaper(); break; case "Old One Eye": newUnit = new OldOneEye(); break; case "Hormagaunt Brood": newUnit = new Hormagaunt(); break; case "Ripper Swarm Brood": newUnit = new RipperSwarm(); break; default: // TODO: make better default newUnit = new Termagant(); break; } return(newUnit); }
/// <summary>Makes the unit from server data.</summary> /// <param name="unitType">Type of the unit.</param> /// <param name="size">The size.</param> /// <param name="unitID">The unit identifier.</param> /// <param name="context">The context.</param> /// <returns>A <see cref="EditUnitViewModel"/></returns> public ViewArmyManagerViewModel.UnitViewModel MakeUnitFromServerData(int unitType, int size, int unitID, ArmyDataContext context) { Unit newUnit; switch (unitType) { case 1: newUnit = new Termagant(); break; case 2: newUnit = new HiveTyrant(); break; case 3: newUnit = new HiveGuard(); break; case 4: newUnit = new Lictor(); break; case 5: newUnit = new Zoanthrope(); break; case 6: newUnit = new Venomthrope(); break; case 7: newUnit = new Haruspex(); break; case 8: newUnit = new Pyrovore(); break; case 9: newUnit = new Gargoyle(); break; case 10: newUnit = new Harpy(); break; case 11: newUnit = new HiveCrone(); break; case 12: newUnit = new SporeMine(); break; case 13: newUnit = new Biovore(); break; case 14: newUnit = new Tyrannofex(); break; case 15: newUnit = new Deathleaper(); break; case 16: newUnit = new OldOneEye(); break; case 17: newUnit = new Hormagaunt(); break; case 18: newUnit = new RipperSwarm(); break; default: newUnit = new Termagant(); break; } newUnit.CurrentSize = size; newUnit.UnitID = unitID; var listWargear = (from wargear in context.Engage_Unit_Wargears join names in context.Engage_WargearUpgrades on wargear.WargearID equals names.WargearID where wargear.UnitID == unitID select new { wargear.Amount, names.Wargear }) .ToDictionary(a => a.Wargear, a => a.Amount); foreach (var wargear in listWargear) { newUnit.SetWargear(wargear.Key, wargear.Value); } var listRules = from rules in context.Engage_Unit_Rules join names in context.Engage_RulesUpgrades on rules.RuleID equals names.RuleID where rules.UnitID == unitID select names.RuleName; foreach (var rule in listRules) { newUnit.SetUpgrade(rule); } var editUrl = this.ModuleContext.EditUrl( "UnitId", unitID.ToString(CultureInfo.InvariantCulture), "EditUnit"); var newUnitModel = new ViewArmyManagerViewModel.UnitViewModel(newUnit, editUrl); return(newUnitModel); }