public void AcquireDisease(string disease) { if (Immunities.Any(immunity => immunity.Disease == disease)) { return; } bool hasDisease = false; foreach (var buff in Buffs) { Disease diseaseBuff = buff as Disease; if (diseaseBuff != null) { hasDisease = hasDisease || diseaseBuff.Name == disease; } } if (!hasDisease) { var buff = DiseaseLibrary.GetDisease(disease).Clone(); AddBuff(buff); if (!(buff as Disease).IsInjury) { Immunities.Add(new Disease.Immunity() { Disease = disease }); } } }
public override void Update(DwarfTime time, Creature creature) { float hungerChange = creature.Stats.Hunger.CurrentValue - LastHunger; LastHunger = creature.Stats.Hunger.CurrentValue; switch (Type) { case HealType.Food: FoodValueUntilHealed -= hungerChange; if (FoodValueUntilHealed > 0) { DoDamage(DwarfTime.Dt, creature); } else { EffectTime.Reset(0); } break; case HealType.Sleep: if (!creature.Stats.IsAsleep) { DoDamage(DwarfTime.Dt, creature); } else { EffectTime.Reset(0); } break; case HealType.Time: DoDamage(DwarfTime.Dt, creature); break; } if (IsContagious) { SpreadTimer.Update(time); if (SpreadTimer.HasTriggered && MathFunctions.RandEvent(LikelihoodOfSpread)) { foreach (CreatureAI other in creature.Faction.Minions) { if (other == creature.AI) { continue; } if ((other.Position - creature.AI.Position).LengthSquared() > 2) { continue; } other.Creature.Stats.AcquireDisease(DiseaseLibrary.GetDisease(Name)); } } } base.Update(time, creature); }
public void DoDamage(Creature performer, GameComponent other, float bonus) { if (!String.IsNullOrEmpty(Weapon.DiseaseToSpread)) { if (other.GetRoot().GetComponent <Creature>().HasValue(out var otherCreature)) { var disease = DiseaseLibrary.GetDisease(Weapon.DiseaseToSpread); if (disease != null) { if (MathFunctions.RandEvent(disease.LikelihoodOfSpread)) { otherCreature.Stats.AcquireDisease(disease); } } } } var health = other.GetRoot().EnumerateAll().OfType <Health>().FirstOrDefault(); if (health != null) { health.Damage(Weapon.DamageAmount + bonus); var injury = DiseaseLibrary.GetRandomInjury(); if (MathFunctions.RandEvent(injury.LikelihoodOfSpread)) { if (other.GetRoot().GetComponent <Creature>().HasValue(out var creature)) { creature.Stats.AcquireDisease(injury); } } 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)); } } else { other.GetRoot().Die(); } PlayNoise(other.GlobalTransform.Translation); if (Weapon.HitParticles != "") { performer.Manager.World.ParticleManager.Trigger(Weapon.HitParticles, other.LocalTransform.Translation, Color.White, 5); if (Weapon.ShootLaser) { performer.Manager.World.ParticleManager.TriggerRay(Weapon.HitParticles, performer.AI.Position, other.LocalTransform.Translation); } } if (Weapon.HitAnimation != null) { IndicatorManager.DrawIndicator(Weapon.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 - performer.AI.Position; if (force.LengthSquared() > 0.01f) { force.Normalize(); physics.ApplyForce(force * Weapon.Knockback, 1.0f); } } }
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); }