public virtual void PlayDeathEffects() { if (deathSound.Length > 0) { GetComponent <AudioSource>().PlayOneShot(UtilRandom.RandomFromArray(deathSound) as AudioClip); } }
public override object Generate(ColumnModel model) { if (model is not RandomPatternModel specModel) { throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType + " inside generator " + GetType().Name); } var result = specModel.Template; while (true) { var regex = new Regex(UtilDataGeneration.SourceNameExpression); var match = regex.Match(result); if (!match.Success) { break; } var patternName = match.Groups[1].Value; var currentPattern = specModel.Patterns.ContainsKey(patternName) ? specModel.Patterns[patternName] : _defaultPatterns.ContainsKey(patternName) ? _defaultPatterns[patternName] : "ABC"; var c = UtilRandom.GetCharFromString(currentPattern, _rnd); result = regex.Replace(result, c.ToString(), 1); } return(result); }
public virtual void PlayGroundLandEffects() { float time = GameTime.time; if (time < nextGroundHitEffect) { return; } nextGroundHitEffect = time + 0.333f; if (footLandHardSound.Length > 0) { GetComponent <AudioSource>().PlayOneShot(UtilRandom.RandomFromArray(footLandHardSound) as AudioClip); } if (landGroundHardParticles) { landGroundHardParticles.Play(); } // Send the camera info about the footstep for rolling effect. PlayerCamera pc = Camera.main.GetComponent <PlayerCamera>(); if (pc) { pc.HitGround(); } }
public void RandomStringTest() { int length = 999; var str = UtilRandom.GetRandomString(length); str.Length.Should().Be(length); }
void HitGround(Collision collision) { // Don't play this effect too often or while dead. if (Time.time < nextGroundHitEffect || isDead) { return; } nextGroundHitEffect = Time.time + 0.25f; // Only play this effect if we hit the ground hard enough on the local Y axis. if ((warp * collision.relativeVelocity).y >= 5.0f) { // Play a different impact sound depending on hard / soft ground. AudioClip[] audioclips = isOnSoftGround ? footLandSoftSound : footLandHardSound; if (audioclips.Length > 0) { GetComponent <AudioSource>().PlayOneShot(UtilRandom.RandomFromArray(audioclips) as AudioClip); } ParticleSystem system = isOnSoftGround ? landGroundSoftParticles : landGroundHardParticles; system.Play(); // Send camera message we hit the ground so it can play a view punch effect. if (playerCamera) { playerCamera.HitGround(); } } }
private void Start() { if (UtilRandom.Bool(chance)) { OnFired(); } }
// Callback function invoked when the cooldown timer is finished. private void CooldownFinished(float secondsOverflow) { // Choose a random attack. AttackHandler attack = UtilRandom.GetRandomElement(attacks); // Execute the attack. attack(boss); }
public override object Generate(InlineSourceModel model) { if (model.Content == null || model.Content.Count == 0) { return("--ND--"); } return(UtilRandom.GetValueFromList(model.Content, Rnd)); }
private void Start() { ac = ServiceLocator.GetAudioController(); timer = new Timer(UtilRandom.RangeWithCenter( secondsBetweenSounds, secondsBetweenSoundsVariance), TimerFinished, true); timer.Run(); }
public void GetUnrepeatIntsTest() { for (int i = 0; i < 10000; i++) { var input = UtilRandom.GetString(100, UtilRandom.RandomCharType.Number); Regex.IsMatch(input, @"^\d{100}$").Should().BeTrue(input); } }
protected override void Instantiated(GameObject obj, float secondsOverflow) { float magnitude = UtilRandom.RangeWithCenter(valueCenter, valueRadius); float direction = UtilRandom.RangeWithCenter(directionCenter, directionRadius); Vector2 velocity = Angle.FromDegrees(direction).GetHeadingVector() * magnitude; obj.GetComponent <Velocity2D>().SetVelocity(velocity); }
private void Fire() { AudioClip clip = sounds.GetRandomElement(); ac.PlaySFX(clip); timer.SetSecondsTarget(clip.length + UtilRandom.RangeWithCenter( secondsBetweenSounds, secondsBetweenSoundsVariance)); }
public override object Generate(FileSourceModel model) { if (_content == null || _content.Count == 0) { LoadSource(model); } return(UtilRandom.GetValueFromList(_content, Rnd)); }
public override object Generate(ColumnModel model) { if (model is not IntegerRangeModel specModel) { throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType + " inside generator " + GetType().Name); } var result = UtilRandom.NextInteger(specModel.Min, specModel.Max, _rnd); return(result); }
private void Start() { oscillator.enabled = false; lerper.enabled = true; lerper.Completed += LerpFinish; damage.Add(data.damage); timerIdle = new Timer(UtilRandom.RangeWithCenter(data.secondsToIdle, data.secondsToIdleVariance), TimerIdleFinish, false); timerIdle.Run(); }
private void Start() { timerWarning = new Timer(data.secondsOfWarning, WarningFinish, false); timerIdle = new Timer(data.secondsOfIdling, IdleFinish, false); timerWarning.Run(); GameObject warning = Instantiate(data.prefabWarning, transform); warning.transform.position = transform.position + Vector3.up * warningHeight; // Set the destroy time for the floor spike warning. warning.GetComponent <MonoTimer>().SetSecondsTarget(data.secondsOfWarning); damage.Add(data.damage); heightToRise = UtilRandom.RangeWithCenter(data.heightToRise, data.heightToRiseVariance); }
public virtual void PlayJumpEffects() { float time = GameTime.time; if (time < nextJumpEffect) { return; } nextJumpEffect = time + 0.333f; if (jumpSound.Length > 0) { GetComponent <AudioSource>().PlayOneShot(UtilRandom.RandomFromArray(jumpSound) as AudioClip); } }
public override object Generate(ColumnModel model) { if (model is not TemplateModel specModel) { throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType + " inside generator " + GetType().Name); } if (string.IsNullOrEmpty(specModel.Template)) { specModel.Template = $"{{{GenerationInfo.Sources[0].Name}}}"; } var result = specModel.Template; if (_itemGenerators == null) { _itemGenerators = new Dictionary <string, GeneratorItemBase>(); } while (true) { var regex = new Regex(@"\{([\w\-|]+)\}"); var match = regex.Match(result); if (!match.Success) { break; } var patternName = match.Groups[1].Value; if (patternName.Contains("|")) { var sourceArray = patternName.Split('|'); patternName = UtilRandom.GetValueFromList(sourceArray, _rnd); _logger.LogInformation($"patternName: {patternName}"); } var sourceModel = GetSource(patternName); if (sourceModel == null) { return("--ND--"); } var itemGenerator = GetItemGenerator(_itemGenerators, sourceModel); var value = itemGenerator.Generate(sourceModel); result = regex.Replace(result, value.ToString(), 1); } return(result); }
void DoPlayerDeath(DeathType deathtype) { if (isDead) { return; } if (deathtype == DeathType.Pierce) { SetState(PlayerState.DeadImpaled); } else { SetState(PlayerState.Dead); } // Send HUD info so it can dim and red the screen. if (gameHUD) { gameHUD.DoPlayerDeath(deathtype); } // Used for allowing the camera to free rotate if we're falling forever. m_diedFromFall = deathtype == DeathType.Fall; /*if (deathtype != DeathType.Fall) * resetGravity(true);*/ // All sorts of different sounds depending on how we died! AudioClip[] sounds; if (deathtype == DeathType.Pierce) { sounds = deathSoundImpaled; } else if (deathtype == DeathType.Fall) { sounds = deathSoundFall; } else { sounds = deathSound; } if (sounds.Length > 0) { GetComponent <AudioSource>().PlayOneShot(UtilRandom.RandomFromArray(sounds) as AudioClip, 1.0f); } }
public override object Generate(ColumnModel model) { if (model is not RandomCharsModel specModel) { throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType + " inside generator " + GetType().Name); } var resultLength = UtilRandom.NextInteger(specModel.MinLength, specModel.MaxLength, _rnd); var sb = new StringBuilder(); for (var i = 0; i < resultLength; i++) { var c = UtilRandom.GetCharFromString(specModel.AllowedChars, _rnd); sb.Append(c); } return(sb.ToString()); }
// Populates the grid of cubes. private void PopulateGrid() { // Clicking the wrong cube will take points away. Action <AppendixCube> cubeCallback = (x) => x.Clicked += WrongCubeClicked; // Instantiate the grid of cubes. cubes = UtilInstantiate.GridOfRectTransforms <AppendixCube>( Tuning.gridWidth, Tuning.gridHeight, prefabCube, true, gridContainer, 0.5f, cubeCallback); if (cubes.Count != 0) { // Choose a random cube and make it the Appendix. AppendixCube appendix = UtilRandom.GetRandomElement(cubes); appendix.MakeIntoAppendix(); // Clicking the appendix won't take points away. appendix.Clicked -= WrongCubeClicked; // Clicking the appendix will win the game. appendix.Clicked += WinGame; } }
private void DoFootsteps() { // Play footstep effects based on how fast we're moving in our ground normalized plane. float speed = GetComponent <Rigidbody>().velocity.magnitude; if (speed < footStepMinSpeed) { return; } // Next time we play is based on our speed. float speedPerMaxSpeed = Mathf.Min(1.0f, speed / maxGroundSpeed); float nextFootStep = lastFootStep + Mathf.Max(footStepMinTime, footStepMaxTime * (1 - speedPerMaxSpeed)); if (Time.time >= nextFootStep) { lastFootStep = Time.time; swapfoot = !swapfoot; AudioClip[] audioclips = isOnSoftGround ? footStepSoftSound : footStepHardSound; // Hard or soft material sounds? AudioClip clip = UtilRandom.RandomFromArray(audioclips) as AudioClip; // Play softer/louder depending on current speed. float magnitude = 0.5f + speedPerMaxSpeed * 0.5f; if (clip != null) { GetComponent <AudioSource>().PlayOneShot(clip, magnitude); } ParticleSystem system = isOnSoftGround ? swapfoot ? hitGroundSoftRightParticles : hitGroundSoftLeftParticles : swapfoot ? hitGroundHardRightParticles : hitGroundHardLeftParticles; system.Play(); // Send the camera info about the footstep for rolling effect. if (playerCamera) { playerCamera.DoFootstep(magnitude, swapfoot); } } }
protected override void Instantiated(GameObject obj, float secondsOverflow) { obj.GetComponent <RootDamage>().Add(UtilRandom.RangeWithCenter(valueCenter, valueRadius)); }
public Sprite GetRandomElement() { return(UtilRandom.GetRandomElement(array)); }
public AudioClip GetRandomElement() { return(UtilRandom.GetRandomElement(array)); }
public Vector3 GetRandomFloorPosition() { return (UtilRandom.PositionBetweenTwoPoints(bottomLeft.position, bottomRight.position)); }
// Returns a random collection of items from the unclaimed list without removing them. // The index of each item returned will be different. public List <T> GetRandomElementsUniqueUnclaimed(int count) { return(UtilRandom.GetRandomElementsUnique(unclaimed, count)); }
// Returns a random element from the unclaimed list without removing it. public T GetRandomElementUnclaimed() { return(UtilRandom.GetRandomElement(unclaimed)); }
public Boss.Data GetRandomBoss() { return(UtilRandom.GetRandomElement(pool)); }
protected override void Instantiated(GameObject obj, float secondsOverflow) { obj.GetComponent <AngularVelocity2D>().SetAngularVelocity(UtilRandom.RangeWithCenter(valueCenter, valueRadius)); }