public override IEnumerable <RunStatus> Execute(object context) { BTAIContext ctx = context as BTAIContext; var tc = ctx.Entity.GetComponent <ThingComp>(); var tcc = ctx.Entity.GetComponent <ThingControlComp>(); // only attack if not blocked there. List <Entity> col = tc.DetectCollisions(ctx.Entity, tc.FacingDirection); foreach (Entity e in col) { var tc2 = e.GetComponent <ThingComp>(); if (tc2.Faction != tc.Faction && tc2.Faction != Faction.NEUTRAL) { IsAttacking = true; tcc.TargetMove = tc.FacingDirection; tcc.DeltaTimeBetweenMoves = this.DeltaTimeBetweenMoves; // TODO color set! and health decrease values parameterize. Level.Current.Subtitles.Show(3, AttackStrings[RandomMath.RandomIntBetween(0, AttackStrings.Length - 1)], 3.5f, tc.Color); ctx.Entity.GetComponent <HealthComp>().DecreaseHealth(RandomMath.RandomBetween(1f, 3f)); yield return(RunStatus.Success); yield break; } } yield return(RunStatus.Failure); }
protected override void OnUpdate(ref UpdateParams p) { base.OnUpdate(ref p); if (TargetMove.LengthSquared() > 0) { if (CollidesWhenThisMoves(Level.Current.hero, TargetMove)) { if (Level.Current.Subtitles.Children.Count <= 4 && Level.Current.hero.Health > 0f) { Level.Current.Sound.PlayRandomCombatSound(0.2f, 0.3f); Level.Current.Subtitles.Show(3, "(Red:) " + attackString[RandomMath.RandomIntBetween(0, attackString.Length - 1)], 3.5f, Color.IndianRed); var damage = RandomMath.RandomBetween(MinDamage, MaxDamage); HurtBehavior.Apply(Level.Current.hero, damage, MaxDamage); Level.Current.hero.Health -= damage; } } } }
public void TriggerAttack() { var k = ParentThing as Knight; if (!IsAttacking) { k.ChasingHero.SatisfiedRange = 11f; // more range allowed during attack if (Level.Current.Subtitles.Children.Count <= 2) { Level.Current.Subtitles.Show(0, attackString[RandomMath.RandomIntBetween(0, attackString.Length - 1)], 1.5f); } IsAttacking = true; CurrentAttackDuration = 0f; } else { // if already attacking, allow more range with new attack if (k.ChasingHero.SatisfiedRange < 23f) { k.ChasingHero.SatisfiedRange++; } CurrentAttackDuration = 0f; } }
public void PlayRandomCombatSound(float volumeMin, float volumeMax) { int n = RandomMath.RandomIntBetween(1, 6); Play(n, RandomMath.RandomBetween(volumeMin, volumeMax)); }