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 override void OnVoxelsSelected(List <VoxelHandle> refs, InputManager.MouseButton button) { if (Command.Contains("Build/")) { if (Library.CreateZone(Command.Substring(6), World).HasValue(out var zone)) { World.AddZone(zone); zone.CompleteRoomImmediately(refs); } } if (Command.Contains("Spawn/")) { string type = Command.Substring(6); foreach (var vox in refs.Where(vox => vox.IsValid)) { if (vox.IsEmpty) { var offset = Vector3.Zero; if (Library.GetCraftable(type).HasValue(out var craftItem)) { offset = craftItem.SpawnOffset; } var body = EntityFactory.CreateEntity <GameComponent>(type, vox.WorldPosition + new Vector3(0.5f, 0.0f, 0.5f) + offset); if (body != null) { body.PropogateTransforms(); if (craftItem != null) { if (craftItem.AddToOwnedPool) { World.PlayerFaction.OwnedObjects.Add(body); } if (craftItem.Deconstructable) { body.Tags.Add("Deconstructable"); // Todo: Should not need to set tag every time item is created. Inherint? } } } } } } else if (Command.Contains("Resource/")) { string type = Command.Substring("Resource/".Length); foreach (var vox in refs.Where(vox => vox.IsValid)) { var body = World.ComponentManager.RootComponent.AddChild(new ResourceEntity(World.ComponentManager, new Resource(type), vox.WorldPosition + new Vector3(0.5f, 0.5f, 0.5f))); body.PropogateTransforms(); } } else if (Command.Contains("Rail/")) { string type = Command.Substring("Rail/".Length); var junction = new Rail.JunctionPiece { RailPiece = type, Orientation = Rail.PieceOrientation.North, Offset = Point.Zero }; foreach (var vox in refs.Where(vox => vox.IsValid)) { if (vox.IsEmpty) { var entity = new Rail.RailEntity(World.ComponentManager, vox, junction); World.ComponentManager.RootComponent.AddChild(entity); } } } else if (Command.Contains("Grass/")) { var type = Library.GetGrassType(Command.Substring(6)); if (type != null) { foreach (var vox in refs.Where(v => v.IsValid)) { var v = vox; if (!vox.IsEmpty) { v.GrassType = type.ID; v.GrassDecay = type.InitialDecayValue; } } } } else if (Command.Contains("Decal/")) { var type = Library.GetDecalType(Command.Substring(6)); if (type != null) { foreach (var vox in refs.Where(v => v.IsValid)) { var v = vox; if (!vox.IsEmpty) { v.DecalType = type.ID; } } } } else if (Command.Contains("Disease")) { foreach (var creature in World.EnumerateIntersectingObjects(VoxelHelpers.GetVoxelBoundingBox(refs), CollisionType.Both).OfType <Creature>()) { creature.Stats.AcquireDisease(DiseaseLibrary.GetRandomDisease()); } } else { foreach (var vox in refs.Where(vox => vox.IsValid)) { if (Command.Contains("Place/")) { string type = Command.Substring(6); var v = vox; if (Library.GetVoxelType(type).HasValue(out VoxelType vType)) { v.Type = vType; } v.QuickSetLiquid(LiquidType.None, 0); if (type == "Magic") { World.ComponentManager.RootComponent.AddChild( new DestroyOnTimer(World.ComponentManager, World.ChunkManager, vox) { DestroyTimer = new Timer(5.0f + MathFunctions.Rand(-0.5f, 0.5f), true) }); } } else { switch (Command) { case "Delete Block": { var v = vox; World.OnVoxelDestroyed(vox); v.Type = Library.EmptyVoxelType; v.QuickSetLiquid(LiquidType.None, 0); } break; case "Nuke Column": { for (var y = 1; y < World.WorldSizeInVoxels.Y; ++y) { var v = World.ChunkManager.CreateVoxelHandle(new GlobalVoxelCoordinate(vox.Coordinate.X, y, vox.Coordinate.Z)); v.Type = Library.EmptyVoxelType; v.QuickSetLiquid(LiquidType.None, 0); } } break; case "Kill Block": foreach (var selected in refs) { if (!selected.IsEmpty) { VoxelHelpers.KillVoxel(World, selected); } } break; case "Fill Water": { if (vox.IsEmpty) { var v = vox; v.QuickSetLiquid(LiquidType.Water, WaterManager.maxWaterLevel); } } break; case "Fill Lava": { if (vox.IsEmpty) { var v = vox; v.QuickSetLiquid(LiquidType.Lava, WaterManager.maxWaterLevel); } } break; case "Fire": { foreach (var flam2 in World.EnumerateIntersectingObjects(vox.GetBoundingBox(), CollisionType.Both).OfType <Flammable>()) { flam2.Heat = flam2.Flashpoint + 1; } } break; default: break; } } } } }
public bool Perform(Creature performer, GameComponent other, DwarfTime time, float bonus, Vector3 pos, string faction) { switch (Weapon.TriggerMode) { case Weapon.AttackTrigger.Timer: RechargeTimer.Update(time); if (!RechargeTimer.HasTriggered) { HasTriggered = false; return(false); } break; case Weapon.AttackTrigger.Animation: if (!performer.Sprite.AnimPlayer.HasValidAnimation() || performer.Sprite.AnimPlayer.CurrentFrame != Weapon.TriggerFrame) { HasTriggered = false; return(false); } break; } if (HasTriggered) { return(true); } HasTriggered = true; switch (Weapon.Mode) { case Weapon.AttackMode.Melee: case Weapon.AttackMode.Dogfight: { DoDamage(performer, other, bonus); break; } case Weapon.AttackMode.Area: { var box = new BoundingBox(performer.AI.Position - Vector3.One * Weapon.Range, performer.AI.Position + Vector3.One * Weapon.Range); foreach (var body in performer.World.EnumerateIntersectingObjects(box, CollisionType.Both).Where(b => b.IsRoot())) { if (body.GetRoot().GetComponent <CreatureAI>().HasValue(out var creature)) { if (creature.Faction == performer.Faction) { continue; } if (performer.World.Overworld.GetPolitics(creature.Faction.ParentFaction, performer.Faction.ParentFaction).GetCurrentRelationship() != Relationship.Hateful) { continue; } DoDamage(performer, body, bonus); } else { if (body.GetRoot().GetComponent <Health>().HasValue(out var health)) { DoDamage(performer, body, bonus); } continue; } } break; } case Weapon.AttackMode.Ranged: { PlayNoise(other.GlobalTransform.Translation); LaunchProjectile(pos, other.Position, other); var injury = DiseaseLibrary.GetRandomInjury(); if (MathFunctions.RandEvent(injury.LikelihoodOfSpread)) { if (other.GetRoot().GetComponent <Creature>().HasValue(out var creature)) { creature.Stats.AcquireDisease(injury); } } break; } } return(true); }
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); }