public Age GetNextAge() { if (_ageRandomizer.TotalWeight <= 0) { return(new Age()); } return(_ageRandomizer.NextWithReplacement()); }
public Race GetNextRace() { if (_raceRandomizer.TotalWeight <= 0) { return(new Race()); } return(_raceRandomizer.NextWithReplacement()); }
public Alignment GetNextAlignment() { if (_alignmentRandomizer.TotalWeight <= 0) { return(new Alignment()); } return(_alignmentRandomizer.NextWithReplacement()); }
public Occupation GetNextOccupation() { if (_occupationRandomizer.TotalWeight <= 0) { return(new Occupation()); } return(_occupationRandomizer.NextWithReplacement()); }
public Bond GetNextBond() { if (_bondsRandomizer.TotalWeight <= 0) { return(new Bond()); } return(_bondsRandomizer.NextWithReplacement()); }
public Secret GetNextSecret() { if (_secretsRandomizer.TotalWeight <= 0) { return(new Secret()); } return(_secretsRandomizer.NextWithReplacement()); }
public Hook GetNextHook() { if (_hooksRandomizer.TotalWeight <= 0) { return(new Hook()); } return(_hooksRandomizer.NextWithReplacement()); }
public Want GetNextWant() { if (_wantsRandomizer.TotalWeight <= 0) { return(new Want()); } return(_wantsRandomizer.NextWithReplacement()); }
public PersonalityTrait GetNextPersonalityTrait() { if (_persTraitRandomizer.TotalWeight <= 0) { return(new PersonalityTrait()); } return(_persTraitRandomizer.NextWithReplacement()); }
public PhysicalTrait GetNextPhysicalTrait() { if (_physTraitRandomizer.TotalWeight <= 0) { return(new PhysicalTrait()); } return(_physTraitRandomizer.NextWithReplacement()); }
public Gender GetNextGender() { if (_genderRandomizer.TotalWeight <= 0) { return(new Gender()); } return(_genderRandomizer.NextWithReplacement()); }
public Item GetNextItem() { if (_itemRandomizer.TotalWeight <= 0) { return(new Item()); } return(_itemRandomizer.NextWithReplacement()); }
public LastName GetNextLastName(string gender = null, string race = null) { if (_lastNameRandomizer.TotalWeight <= 0) { return(new LastName()); } var nextName = GetSatisfiedRestriction(_lastNameRandomizer, _lastNameRandomizer.NextWithReplacement(), gender, race); return(nextName); }
private static T GetSatisfiedRestriction <T>(IWeightedRandomizer <T> randomizer, T next, string gender, string race, int count = 0) where T : RestrictedValue { if (string.IsNullOrWhiteSpace(gender) && string.IsNullOrWhiteSpace(race)) { return(next); } if (count < GiveUp) { var inOrEmptyGender = InOrEmpty(next.RestrictedToGender, gender); var inOrEmptyRace = InOrEmpty(next.RestrictedToRace, race); if (!inOrEmptyGender || !inOrEmptyRace) { next = randomizer.NextWithReplacement(); return(GetSatisfiedRestriction(randomizer, next, gender, race, ++count)); } } return(next); }
protected virtual void ProcessWound(BodyHitComponent bodyHit, int pedEntity) { SendDebug($"{WeaponClass} processing"); if (bodyHit == null || bodyHit.DamagedPart == BodyParts.NOTHING) { DefaultAction?.Invoke(pedEntity); return; } var woundedPed = EcsWorld.GetComponent <WoundedPedComponent>(pedEntity); if (woundedPed == null) { return; } switch (bodyHit.DamagedPart) { case BodyParts.HEAD: if (woundedPed.ThisPed.IsWearingHelmet && Random.IsTrueWithProbability(HelmetSafeChance)) { SendMessage("Helmet saved your head", pedEntity, NotifyLevels.WARNING); return; } HeadActions?.NextWithReplacement()(pedEntity); break; case BodyParts.NECK: NeckActions?.NextWithReplacement()(pedEntity); break; case BodyParts.UPPER_BODY: if (!CheckArmorPenetration(woundedPed, pedEntity)) { SendMessage("Armor saved your chest", pedEntity, NotifyLevels.WARNING); CreatePain(pedEntity, ArmorDamage / 5f); return; } UpperBodyActions?.NextWithReplacement()(pedEntity); break; case BodyParts.LOWER_BODY: if (!CheckArmorPenetration(woundedPed, pedEntity)) { SendMessage("Armor saved your lower body", pedEntity, NotifyLevels.WARNING); CreatePain(pedEntity, ArmorDamage / 5f); return; } LowerBodyActions?.NextWithReplacement()(pedEntity); break; case BodyParts.ARM: ArmActions?.NextWithReplacement()(pedEntity); break; case BodyParts.LEG: LegActions?.NextWithReplacement()(pedEntity); break; case BodyParts.NOTHING: break; default: throw new ArgumentOutOfRangeException(); } }
private static void TestSpeed(IWeightedRandomizer <int> randomizer, bool displayText) { GCLatencyMode oldLatencyMode = GCSettings.LatencyMode; try { //Prevent garbage collection during tests GCSettings.LatencyMode = GCLatencyMode.LowLatency; const int numIterations = 10000; Stopwatch timer = new Stopwatch(); if (displayText) { Console.WriteLine("Testing {0}", randomizer.GetType().Name); Console.WriteLine("--------------------------------"); } //NextWithReplacement()/1000 randomizer.Clear(); timer.Reset(); timer.Start(); for (int i = 1; i <= numIterations; i++) { randomizer.Add(i, i); } for (int i = 1; i <= numIterations / 1000; i++) { randomizer.NextWithReplacement(); } timer.Stop(); GC.Collect(); if (displayText) { Console.WriteLine("Add()x{0} + NextWithReplacement()x{1}: {2} ms", numIterations, numIterations / 1000, timer.ElapsedMilliseconds); } //NextWithReplacement() randomizer.Clear(); timer.Reset(); timer.Start(); for (int i = 1; i <= numIterations; i++) { randomizer.Add(i, i); } for (int i = 1; i <= numIterations; i++) { randomizer.NextWithReplacement(); } timer.Stop(); GC.Collect(); if (displayText) { Console.WriteLine("Add()x{0} + NextWithReplacement()x{1}: {2} ms", numIterations, numIterations, timer.ElapsedMilliseconds); } //NextWithReplacement() * 10 randomizer.Clear(); timer.Reset(); timer.Start(); for (int i = 1; i <= numIterations; i++) { randomizer.Add(i, i); } for (int i = 1; i <= 10 * numIterations; i++) { randomizer.NextWithReplacement(); } timer.Stop(); GC.Collect(); if (displayText) { Console.WriteLine("Add()x{0} + NextWithReplacement()x{1}: {2} ms", numIterations, 10 * numIterations, timer.ElapsedMilliseconds); } //NextWithReplacement() (interleaved) randomizer.Clear(); timer.Reset(); timer.Start(); for (int i = 1; i <= numIterations; i++) { randomizer.Add(i, i); randomizer.NextWithReplacement(); } timer.Stop(); GC.Collect(); if (displayText) { Console.WriteLine("( Add() + NextWithReplacement() )x{0} (interleaved): {1} ms", numIterations, timer.ElapsedMilliseconds); } //NextWithRemoval() randomizer.Clear(); timer.Reset(); timer.Start(); for (int i = 1; i <= numIterations; i++) { randomizer.Add(i, i); } for (int i = 1; i <= numIterations; i++) { randomizer.NextWithRemoval(); } timer.Stop(); GC.Collect(); if (displayText) { Console.WriteLine("Add()x{0} + NextWithRemoval()x{1}: {2} ms", numIterations, numIterations, timer.ElapsedMilliseconds); Console.WriteLine(); Console.WriteLine(); } } //end try finally { // ALWAYS set the latency mode back GCSettings.LatencyMode = oldLatencyMode; } }
private void ProcessWound(BodyPartWasHitEvent bodyHit, int pedEntity) { if (bodyHit == null || bodyHit.DamagedPart == BodyParts.NOTHING) { SendMessage("BodyHit is null " + (bodyHit == null), pedEntity, NotifyLevels.DEBUG); DefaultAction?.Invoke(pedEntity); return; } var woundedPed = EcsWorld.GetComponent <WoundedPedComponent>(pedEntity); if (woundedPed == null) { return; } switch (bodyHit.DamagedPart) { case BodyParts.HEAD: if (woundedPed.ThisPed.IsWearingHelmet && Random.IsTrueWithProbability(HelmetSafeChance)) { SendMessage(Locale.Data.HelmetSavedYourHead, pedEntity, NotifyLevels.WARNING); return; } HeadActions?.NextWithReplacement()(pedEntity); break; case BodyParts.NECK: NeckActions?.NextWithReplacement()(pedEntity); break; case BodyParts.UPPER_BODY: if (!CheckArmorPenetration(woundedPed, pedEntity)) { SendMessage(Locale.Data.ArmorSavedYourChest, pedEntity, NotifyLevels.WARNING); CreatePain(pedEntity, ArmorDamage / 5f); return; } UpperBodyActions?.NextWithReplacement()(pedEntity); break; case BodyParts.LOWER_BODY: if (!CheckArmorPenetration(woundedPed, pedEntity)) { SendMessage(Locale.Data.ArmorSavedYourLowerBody, pedEntity, NotifyLevels.WARNING); CreatePain(pedEntity, ArmorDamage / 5f); return; } LowerBodyActions?.NextWithReplacement()(pedEntity); break; case BodyParts.ARM: ArmActions?.NextWithReplacement()(pedEntity); break; case BodyParts.LEG: LegActions?.NextWithReplacement()(pedEntity); break; case BodyParts.NOTHING: break; default: throw new ArgumentOutOfRangeException(); } }