public bool Perform(Creature performer, Vector3 pos, Voxel other, DwarfTime time, float bonus, string faction) { if (other == null) { return(false); } switch (TriggerMode) { case AttackTrigger.Timer: RechargeTimer.Update(time); if (!RechargeTimer.HasTriggered) { return(false); } break; case AttackTrigger.Animation: if (performer.Sprite.CurrentAnimation == null || performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame) { return(false); } break; } switch (Mode) { case AttackMode.Melee: { other.Health -= DamageAmount + bonus; PlayNoise(other.Position); if (HitParticles != "") { PlayState.ParticleManager.Trigger(HitParticles, other.Position, Color.White, 5); } if (HitAnimation != null) { HitAnimation.Reset(); HitAnimation.Play(); IndicatorManager.DrawIndicator(HitAnimation, other.Position + Vector3.One * 0.5f, 0.6f, 2.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f); } break; } case AttackMode.Ranged: { LaunchProjectile(pos, other.Position, faction); break; } } return(true); }
public bool PerformNoDamage(Creature performer, DwarfTime time, Vector3 pos) { switch (TriggerMode) { case AttackTrigger.Timer: RechargeTimer.Update(time); if (!RechargeTimer.HasTriggered) { HasTriggered = false; return(false); } break; case AttackTrigger.Animation: if (performer.Sprite.CurrentAnimation == null || performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame) { HasTriggered = false; return(false); } break; } if (Mode == AttackMode.Melee) { if (HitParticles != "") { performer.Manager.World.ParticleManager.Trigger(HitParticles, pos, Color.White, 5); } if (HitAnimation != null && !HasTriggered) { HitAnimation.Reset(); HitAnimation.Play(); IndicatorManager.DrawIndicator(HitAnimation.Clone(), pos, 10.0f, 1.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f); PlayNoise(pos); } } HasTriggered = true; return(true); }
public void PerformNoDamage(Creature performer, DwarfTime time, Vector3 pos) { switch (TriggerMode) { case AttackTrigger.Timer: RechargeTimer.Update(time); if (!RechargeTimer.HasTriggered) { return; } break; case AttackTrigger.Animation: if (performer.Sprite.CurrentAnimation == null || performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame) { return; } break; } if (Mode == AttackMode.Melee) { PlayNoise(pos); if (HitParticles != "") { PlayState.ParticleManager.Trigger(HitParticles, pos, Color.White, 5); } if (HitAnimation != null) { HitAnimation.Reset(); HitAnimation.Play(); IndicatorManager.DrawIndicator(HitAnimation, pos, 0.6f, 2.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f); } } }
public virtual void Update(DwarfTime time, VoxelSelector voxSelector, BodySelector bodySelector) { if (Recharges) { RechargeTimer.Update(time); } switch (Mode) { case SpellMode.Button: break; case SpellMode.Continuous: OnContinuousUpdate(time); break; case SpellMode.SelectEmptyVoxels: voxSelector.SelectionType = VoxelSelectionType.SelectEmpty; voxSelector.Enabled = true; bodySelector.Enabled = false; break; case SpellMode.SelectFilledVoxels: voxSelector.SelectionType = VoxelSelectionType.SelectFilled; voxSelector.Enabled = true; bodySelector.Enabled = false; break; case SpellMode.SelectEntities: bodySelector.Enabled = true; break; } if (!Recharges || RechargeTimer.HasTriggered) { World.ParticleManager.Trigger("star_particle", World.CursorLightPos + Vector3.Up * 0.5f, Color.White, 2); } }
public bool Perform(Creature performer, Body other, DwarfTime time, float bonus, Vector3 pos, string faction) { switch (TriggerMode) { case AttackTrigger.Timer: RechargeTimer.Update(time); if (!RechargeTimer.HasTriggered) { return(false); } break; case AttackTrigger.Animation: if (performer.Sprite.CurrentAnimation == null || performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame) { return(false); } break; } switch (Mode) { case AttackMode.Melee: case AttackMode.Dogfight: { Health health = other.GetRootComponent().GetChildrenOfType <Health>(true).FirstOrDefault(); if (health != null) { health.Damage(DamageAmount + bonus); } PlayNoise(other.GlobalTransform.Translation); if (HitParticles != "") { PlayState.ParticleManager.Trigger(HitParticles, other.LocalTransform.Translation, Color.White, 5); } if (HitAnimation != null) { HitAnimation.Reset(); HitAnimation.Play(); IndicatorManager.DrawIndicator(HitAnimation.Clone(), other.BoundingBox.Center(), 10.0f, 1.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f); } Physics physics = other as Physics; if (physics != null) { Vector3 force = other.Position - pos; if (force.LengthSquared() > 0.01f) { force.Normalize(); physics.ApplyForce(force * Knockback, 1.0f); } } break; } case AttackMode.Ranged: { PlayNoise(other.GlobalTransform.Translation); LaunchProjectile(pos, other.Position, other); break; } } return(true); }
public IEnumerable <Act.Status> Perform(Creature performer, Vector3 pos, Voxel other, DwarfTime time, float bonus, string faction) { while (true) { if (other == null) { yield return(Act.Status.Fail); yield break; } switch (TriggerMode) { case AttackTrigger.Timer: RechargeTimer.Update(time); if (!RechargeTimer.HasTriggered) { yield return(Act.Status.Running); continue; } break; case AttackTrigger.Animation: if (performer.Sprite.CurrentAnimation == null || performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame) { if (performer.Sprite.CurrentAnimation != null) { performer.Sprite.CurrentAnimation.Play(); } yield return(Act.Status.Running); continue; } break; } switch (Mode) { case AttackMode.Melee: { other.Health -= DamageAmount + bonus; PlayNoise(other.Position); if (HitParticles != "") { PlayState.ParticleManager.Trigger(HitParticles, other.Position, Color.White, 5); } if (HitAnimation != null) { HitAnimation.Reset(); HitAnimation.Play(); IndicatorManager.DrawIndicator(HitAnimation.Clone(), other.Position + Vector3.One * 0.5f, 10.0f, 1.0f, MathFunctions.RandVector2Circle() * 10, HitColor, MathFunctions.Rand() > 0.5f); } break; } case AttackMode.Ranged: { LaunchProjectile(pos, other.Position, null); break; } } yield return(Act.Status.Success); yield break; } }
public bool Perform(Creature performer, Body other, DwarfTime time, float bonus, Vector3 pos, string faction) { switch (TriggerMode) { case AttackTrigger.Timer: RechargeTimer.Update(time); if (!RechargeTimer.HasTriggered) { HasTriggered = false; return(false); } break; case AttackTrigger.Animation: if (!performer.Sprite.AnimPlayer.HasValidAnimation() || performer.Sprite.AnimPlayer.CurrentFrame != TriggerFrame) { HasTriggered = false; return(false); } break; } if (HasTriggered) { return(true); } HasTriggered = true; switch (Mode) { case AttackMode.Melee: case AttackMode.Dogfight: { var otherCreature = other.GetRoot().GetComponent <Creature>(); if (otherCreature != null && !String.IsNullOrEmpty(DiseaseToSpread)) { var disease = DiseaseLibrary.GetDisease(DiseaseToSpread); if (MathFunctions.RandEvent(disease.LikelihoodOfSpread)) { otherCreature.AcquireDisease(DiseaseToSpread); } } var health = other.GetRoot().EnumerateAll().OfType <Health>().FirstOrDefault(); if (health != null) { health.Damage(DamageAmount + bonus); var injury = DiseaseLibrary.GetRandomInjury(); if (MathFunctions.RandEvent(injury.LikelihoodOfSpread)) { var creature = other.GetRoot().GetComponent <Creature>(); if (creature != null) { creature.AcquireDisease(injury.Name); } } Vector3 knock = other.Position - performer.Physics.Position; knock.Normalize(); knock *= 0.2f; if (other.AnimationQueue.Count == 0) { other.AnimationQueue.Add(new KnockbackAnimation(0.15f, other.LocalTransform, knock)); } } PlayNoise(other.GlobalTransform.Translation); if (HitParticles != "") { performer.Manager.World.ParticleManager.Trigger(HitParticles, other.LocalTransform.Translation, Color.White, 5); } if (HitAnimation != null) { IndicatorManager.DrawIndicator(HitAnimation, other.BoundingBox.Center(), 10.0f, 1.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f); } Physics physics = other as Physics; if (physics != null) { Vector3 force = other.Position - pos; if (force.LengthSquared() > 0.01f) { force.Normalize(); physics.ApplyForce(force * Knockback, 1.0f); } } break; } case AttackMode.Ranged: { PlayNoise(other.GlobalTransform.Translation); LaunchProjectile(pos, other.Position, other); var injury = DiseaseLibrary.GetRandomInjury(); if (MathFunctions.RandEvent(injury.LikelihoodOfSpread)) { var creature = other.GetRoot().GetComponent <Creature>(); if (creature != null) { creature.AcquireDisease(injury.Name); } } break; } } return(true); }
public bool Perform(Creature performer, Body other, DwarfTime time, float bonus, Vector3 pos, string faction) { switch (TriggerMode) { case AttackTrigger.Timer: RechargeTimer.Update(time); if (!RechargeTimer.HasTriggered) { HasTriggered = false; return(false); } break; case AttackTrigger.Animation: if (!performer.Sprite.AnimPlayer.HasValidAnimation() || performer.Sprite.AnimPlayer.CurrentFrame != TriggerFrame) { HasTriggered = false; return(false); } break; } if (HasTriggered) { return(true); } HasTriggered = true; switch (Mode) { case AttackMode.Melee: case AttackMode.Dogfight: { DoDamage(performer, other, bonus); break; } case AttackMode.Area: { BoundingBox box = new BoundingBox(performer.AI.Position - Vector3.One * Range, performer.AI.Position + Vector3.One * Range); foreach (var body in performer.World.EnumerateIntersectingObjects(box, CollisionType.Both)) { var creature = body.GetRoot().GetComponent <CreatureAI>(); if (creature == null) { var health = body.GetRoot().GetComponent <Health>(); if (health != null) { DoDamage(performer, body, bonus); } continue; } if (creature.Faction == performer.Faction) { continue; } var alliance = performer.World.Diplomacy.GetPolitics(creature.Faction, performer.Faction).GetCurrentRelationship() != Relationship.Hateful; if (alliance) { continue; } DoDamage(performer, body, bonus); } break; } case AttackMode.Ranged: { PlayNoise(other.GlobalTransform.Translation); LaunchProjectile(pos, other.Position, other); var injury = DiseaseLibrary.GetRandomInjury(); if (MathFunctions.RandEvent(injury.LikelihoodOfSpread)) { var creature = other.GetRoot().GetComponent <Creature>(); if (creature != null) { creature.AcquireDisease(injury.Name); } } break; } } return(true); }
public IEnumerable <Act.Status> PerformOnVoxel(Creature performer, Vector3 pos, KillVoxelTask DigAct, DwarfTime time, float bonus, string faction) { while (true) { if (!DigAct.Voxel.IsValid) { yield return(Act.Status.Fail); yield break; } Drawer2D.DrawLoadBar(performer.World.Camera, DigAct.Voxel.WorldPosition + Vector3.One * 0.5f, Color.White, Color.Black, 32, 1, (float)DigAct.VoxelHealth / DigAct.Voxel.Type.StartingHealth); switch (TriggerMode) { case AttackTrigger.Timer: RechargeTimer.Update(time); if (!RechargeTimer.HasTriggered) { yield return(Act.Status.Running); continue; } break; case AttackTrigger.Animation: if (!performer.Sprite.AnimPlayer.HasValidAnimation() || performer.Sprite.AnimPlayer.CurrentFrame < TriggerFrame) { if (performer.Sprite.AnimPlayer.HasValidAnimation()) { performer.Sprite.AnimPlayer.Play(); } yield return(Act.Status.Running); continue; } break; } switch (Mode) { case AttackMode.Melee: { DigAct.VoxelHealth -= (DamageAmount + bonus); DigAct.Voxel.Type.HitSound.Play(DigAct.Voxel.WorldPosition); if (HitParticles != "") { performer.Manager.World.ParticleManager.Trigger(HitParticles, DigAct.Voxel.WorldPosition, Color.White, 5); } if (HitAnimation != null) { IndicatorManager.DrawIndicator(HitAnimation, DigAct.Voxel.WorldPosition + Vector3.One * 0.5f, 10.0f, 1.0f, MathFunctions.RandVector2Circle() * 10, HitColor, MathFunctions.Rand() > 0.5f); } break; } case AttackMode.Ranged: { throw new InvalidOperationException("Ranged attacks should never be used for digging."); //LaunchProjectile(pos, DigAct.GetTargetVoxel().WorldPosition, null); //break; } } yield return(Act.Status.Success); yield break; } }