/** * Basic constructor for User * * @param permissionLevel * The permission level of the user * @param branch * The branch of the military this user is playing for * @param team * The team that this user logs onto * @param username * The name of the user * @param unit * null for non-sub players * The GUID/NetworkID of the sub controlled by this player. */ public User(PermissionLevel permissionLevel, MilitaryBranch branch, int team, string username, string unit) { // Set the permission level MyPermissionLevel = permissionLevel; // Set the military branch MyBranch = branch; // Set the team TeamNumber = team; // Set the username Username = username; // Check if there is not an associated sub if (unit == null) { // If there is not // Set sub player to false SubPlayer = false; } else { // If there is an associated sub // Set sub player to true SubPlayer = true; // Record the GUID/NetworkID of the Sub SubUnit = unit; } }
public int GetUnitCost(MilitaryBranch type) { if (FootmanPrefab == null) { Debug.LogError("No Footman Prefab."); } switch (type) { case MilitaryBranch.Footman: return(FootmanPrefab.GetComponent <Unit>().UnitCost); break; case MilitaryBranch.Cavalry: return(CavalryPrefab.GetComponent <Unit>().UnitCost); break; case MilitaryBranch.Archer: return(ArcherPrefab.GetComponent <Unit>().UnitCost); break; case MilitaryBranch.Catapult: return(CatapultPrefab.GetComponent <Unit>().UnitCost); break; default: Debug.LogError("Invalid Miitary Branch"); return(-1); break; } }
/// <inheritdoc/> public string ToDelimitedString() { CultureInfo culture = CultureInfo.CurrentCulture; return(string.Format( culture, StringHelper.StringFormatSequence(0, 23, Configuration.FieldSeparator), Id, LivingDependency != null ? string.Join(Configuration.FieldRepeatSeparator, LivingDependency.Select(x => x.ToDelimitedString())) : null, LivingArrangement?.ToDelimitedString(), PatientPrimaryFacility != null ? string.Join(Configuration.FieldRepeatSeparator, PatientPrimaryFacility.Select(x => x.ToDelimitedString())) : null, PatientPrimaryCareProviderNameIdNo != null ? string.Join(Configuration.FieldRepeatSeparator, PatientPrimaryCareProviderNameIdNo.Select(x => x.ToDelimitedString())) : null, StudentIndicator?.ToDelimitedString(), Handicap?.ToDelimitedString(), LivingWillCode?.ToDelimitedString(), OrganDonorCode?.ToDelimitedString(), SeparateBill, DuplicatePatient != null ? string.Join(Configuration.FieldRepeatSeparator, DuplicatePatient.Select(x => x.ToDelimitedString())) : null, PublicityCode?.ToDelimitedString(), ProtectionIndicator, ProtectionIndicatorEffectiveDate.HasValue ? ProtectionIndicatorEffectiveDate.Value.ToString(Consts.DateFormatPrecisionDay, culture) : null, PlaceOfWorship != null ? string.Join(Configuration.FieldRepeatSeparator, PlaceOfWorship.Select(x => x.ToDelimitedString())) : null, AdvanceDirectiveCode != null ? string.Join(Configuration.FieldRepeatSeparator, AdvanceDirectiveCode.Select(x => x.ToDelimitedString())) : null, ImmunizationRegistryStatus?.ToDelimitedString(), ImmunizationRegistryStatusEffectiveDate.HasValue ? ImmunizationRegistryStatusEffectiveDate.Value.ToString(Consts.DateFormatPrecisionDay, culture) : null, PublicityCodeEffectiveDate.HasValue ? PublicityCodeEffectiveDate.Value.ToString(Consts.DateFormatPrecisionDay, culture) : null, MilitaryBranch?.ToDelimitedString(), MilitaryRankGrade?.ToDelimitedString(), MilitaryStatus?.ToDelimitedString(), AdvanceDirectiveLastVerifiedDate.HasValue ? AdvanceDirectiveLastVerifiedDate.Value.ToString(Consts.DateFormatPrecisionDay, culture) : null ).TrimEnd(Configuration.FieldSeparator.ToCharArray())); }
public static MilitaryRank.Branch.Rank GetRankByBranch(MilitaryBranch branch) { var ranks = new List <MilitaryRank.Branch.Rank>(); var mil = GetAllEx(); foreach (var b in mil.Branches.Where(x => x.Name == branch.ToString())) { ranks.AddRange(b.Ranks); } return(GetRank(ranks)); }
public static int GetMilHeight(MilitaryBranch branch = MilitaryBranch.USARMY) { var rv = AnimatorRandom.Rand.Next(2); if (rv == 0) { return(GetMilHeight(BiologicalSex.Female, branch)); } else { return(GetMilHeight(BiologicalSex.Male, branch)); } }
public static MilitaryUnit GetOneByServiceBranch(MilitaryBranch branch) { var choice = new MilitaryUnitService(branch, GetAllEx()); var hq = new MilitaryUnitAddressService(choice.Unit); if (!string.IsNullOrEmpty(hq?.MilUnit?.Address?.Name)) { choice.Unit.Address = GetBaseAddress(branch, hq.MilUnit.Address.Name); } return(choice.Unit); }
void getUser() { if (GameObject.Find("Canvas").GetComponent <UIMainController> () != null) { user = GameObject.Find("Canvas").GetComponent <UIMainController> ().GetUser(); } else { PermissionLevel pl = PermissionLevel.User; MilitaryBranch mb = MilitaryBranch.Navy; user = new User(pl, mb, 0, "admin", null); } }
public static int GetMilWeight(int height, DateTime birthdate, MilitaryBranch branch) { var rv = AnimatorRandom.Rand.Next(2); if (rv == 0) { return(GetMilWeight(height, birthdate, BiologicalSex.Female, branch)); } else { return(GetMilWeight(height, birthdate, BiologicalSex.Male, branch)); } }
public static int GetMilHeight(BiologicalSex sex, MilitaryBranch branch = MilitaryBranch.USARMY) { double mean; double std; double u1; double u2; double randStdNormal; double randNormal; int inches; int low = 60; int high = 80; if (sex == BiologicalSex.Female) { low = 58; high = 80; } if (branch == MilitaryBranch.USMC) { low = 58; high = 78; if (sex == BiologicalSex.Female) { high = 72; } } do { u1 = 1.0 - AnimatorRandom.Rand.NextDouble(); u2 = 1.0 - AnimatorRandom.Rand.NextDouble(); randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); if (sex == BiologicalSex.Male) { mean = 68.9; std = 2.84; } else { mean = 63.62; std = 2.52; } randNormal = mean + std + randStdNormal; inches = RoundDouble(randNormal); } while (inches < low || inches > high); return(inches); }
public Transform SpawnUnit(Cell cell, MilitaryBranch type, int playerNumner) { GameObject unit; if (FootmanPrefab == null) { Debug.LogError("No Footman Prefab."); } switch (type) { case MilitaryBranch.Footman: unit = Instantiate(FootmanPrefab); break; case MilitaryBranch.Cavalry: unit = Instantiate(CavalryPrefab); break; case MilitaryBranch.Archer: unit = Instantiate(ArcherPrefab); break; case MilitaryBranch.Catapult: unit = Instantiate(CatapultPrefab); break; default: Debug.LogError("Invalid Miitary Branch"); unit = Instantiate(FootmanPrefab); break; } if (!cell.IsTaken) { cell.IsTaken = true; unit.GetComponent <Unit>().Cell = cell; unit.transform.position = cell.gameObject.transform.position; unit.GetComponent <Unit>().PlayerNumber = playerNumner; Vector3 offset = new Vector3(0, 0, cell.GetComponent <Cell>().GetCellDimensions().z); unit.transform.position = cell.transform.position - offset; unit.transform.parent = UnitsParent; } //Unit gets snapped to the nearest cell else { Destroy(unit.gameObject); } //If the nearest cell is taken, the unit gets destroyed. return(unit.transform); }
public static AddressProfiles.AddressProfile GetBaseAddress(MilitaryBranch branch, string hq) { var a = new AddressProfiles.AddressProfile(); var raw = File.ReadAllText("config/military_bases.json"); var o = JsonConvert.DeserializeObject <MilitaryBases.BaseManager>(raw); var b = o.Branches.FirstOrDefault(x => x.Name == branch.ToString()); var myBase = b.Bases.FirstOrDefault(x => x.Name.Equals(hq, StringComparison.InvariantCultureIgnoreCase)); if (myBase == null) { myBase = o.Branches.FirstOrDefault(x => x.Name == branch.ToString())?.Bases.RandomElement(); } if (myBase == null) { return(null); } a.AddressType = "Base"; a.Name = myBase.Name; if (myBase.Streets.Any()) { a.Address1 = myBase.Streets.RandomElement(); } if (string.IsNullOrEmpty(a.Address1)) { a.Address1 = Address.GetStreetAddress(); } a.City = myBase.City; a.State = myBase.State; a.PostalCode = myBase.PostalCode; if (string.IsNullOrEmpty(a.State)) { a.State = Address.GetUSStateAbbreviation(); } if (string.IsNullOrEmpty(a.City)) { var cityAndZip = Address.GetCityAndZipFromStateAbbreviation(a.State); a.City = cityAndZip["City"]; a.PostalCode = cityAndZip["ZipCode"]; } return(a); }
public MilitaryUnitService(MilitaryBranch branch, MilitaryUnit units) { var unit = units.Sub.ToList().FirstOrDefault(x => x.Nick == branch.ToString()); this.Unit = units.Clone(); this.Unit.Sub = null; if (unit != null) { var currentUnit = unit.Clone(); var list = new List <MilitaryUnit.Unit>(); while (currentUnit != null) { if (currentUnit.Sub == null) { break; } currentUnit = GetUnit(currentUnit); list.Add(currentUnit); } list.Reverse(); List <MilitaryUnit.Unit> previous = null; foreach (var item in list) { if (previous == null) { previous = new List <MilitaryUnit.Unit>(); } previous = SetUnit(previous, new List <MilitaryUnit.Unit> { item }); } this.Unit.Sub = previous; } this.Unit.Country = units.Country; }
/** * Creates a new user and adds them to the specified team. * * @param permissionLevel * The permission level of the user * @param branch * The branch of the military this user is playing for * @param team * The team the user will be added to * @param username * The name the user wants to use * @param unitGuid * The string form of the Guid that represents the object. * * @return * True The user was added * False The was not created because the username already exists */ public static bool AddNewUser(PermissionLevel permissionLevel, MilitaryBranch branch, int team, string username, string unitGuid) { // Check if the username is used by that team if (Team.UsernameInUse(username)) { // If the username is already in use //Debug.Log ("Username in use"); // Return false because the user cannot be added. return(false); } object[] arguments = new object[5]; arguments[0] = permissionLevel; arguments[1] = branch; arguments[2] = team; arguments[3] = username; arguments[4] = unitGuid; GEvent e = EventFactory.CreateEvent(GEventType.PlayerJoinEvent, arguments); EventManager.Instance.AddEvent(e); //Debug.Log ("User Join event raised"); return(true); }
public UnitCreateEventArgs(Cell cell, MilitaryBranch unitType) { Cell = cell; UnitType = unitType; }
/** * Creates a new user and adds them to the specified team. * Calls other AddNewUser with unitGuid of null. * @param permissionLevel * The permission level of the user * @param branch * The branch of the military this user is playing for * @param team * The team the user will be added to * @param username * The name the user wants to use * @return * True The user was added * False The was not created because the username already exists */ public static bool AddNewUser(PermissionLevel permissionLevel, MilitaryBranch branch, int team, string username) { return(Team.AddNewUser(permissionLevel, branch, team, username, null)); }
public static IEnumerable <MilitaryUnit.Unit> GetAllByServiceBranch(MilitaryBranch branch) { var o = GetAllEx(); return(o.Sub.Where(x => x.Nick == branch.ToString())); }
//TODO: Update to reflect weight distribution statistics instead of even distribution within bounds public static int GetMilWeight(int height, DateTime birthdate, BiologicalSex sex, MilitaryBranch branch) { string input = File.ReadAllText("config/military_height_weight.json"); var hwChart = JsonConvert.DeserializeObject <MilitaryHeightWeight.MilitaryHeightWeightManager>(input); int age = DateTime.Now.Year - birthdate.Year; if (DateTime.Now.Month < birthdate.Month) { age -= 1; } if (DateTime.Now.Month == birthdate.Month && DateTime.Now.Day < birthdate.Day) { age -= 1; } int min; int max; if (branch == MilitaryBranch.USAF) { var b = hwChart.Branches.FirstOrDefault(x => x.Branch == "USAF"); var h = b.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } else if (branch == MilitaryBranch.USCG) { var b = hwChart.Branches.FirstOrDefault(x => x.Branch == "USCG"); var h = b.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } else if (branch == MilitaryBranch.USMC) { var b = hwChart.Branches.FirstOrDefault(x => x.Branch == "USMC"); if (sex == BiologicalSex.Male) { var s = b.Sexes.FirstOrDefault(x => x.Sex == "Male"); var h = s.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } else { var s = b.Sexes.FirstOrDefault(x => x.Sex == "Female"); var h = s.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } } else if (branch == MilitaryBranch.USN) { var b = hwChart.Branches.FirstOrDefault(x => x.Branch == "USN"); if (sex == BiologicalSex.Male) { var s = b.Sexes.FirstOrDefault(x => x.Sex == "Male"); var h = s.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } else { var s = b.Sexes.FirstOrDefault(x => x.Sex == "Female"); var h = s.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } } else { var b = hwChart.Branches.FirstOrDefault(x => x.Branch == "USARMY"); if (sex == BiologicalSex.Male) { var s = b.Sexes.FirstOrDefault(x => x.Sex == "Male"); if (age < 21) { var a = s.Ages.FirstOrDefault(x => x.Age == 17); var h = a.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } else if (age < 28) { var a = s.Ages.FirstOrDefault(x => x.Age == 21); var h = a.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } else if (age < 40) { var a = s.Ages.FirstOrDefault(x => x.Age == 28); var h = a.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } else { var a = s.Ages.FirstOrDefault(x => x.Age == 40); var h = a.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } } else { var s = b.Sexes.FirstOrDefault(x => x.Sex == "Female"); if (age < 21) { var a = s.Ages.FirstOrDefault(x => x.Age == 17); var h = a.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } else if (age < 28) { var a = s.Ages.FirstOrDefault(x => x.Age == 21); var h = a.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } else if (age < 40) { var a = s.Ages.FirstOrDefault(x => x.Age == 28); var h = a.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } else { var a = s.Ages.FirstOrDefault(x => x.Age == 40); var h = a.Heights.FirstOrDefault(x => x.Height == height); min = h.MinWeight; max = h.MaxWeight; } } } return(CalcMilWeight(min, max)); }