diff --git a/Barotrauma/Content/Characters/Human/human.xml b/Barotrauma/Content/Characters/Human/human.xml index aaa479462..1d45173db 100644 --- a/Barotrauma/Content/Characters/Human/human.xml +++ b/Barotrauma/Content/Characters/Human/human.xml @@ -85,7 +85,7 @@ - + diff --git a/Barotrauma/Content/Characters/Human/humanhusk.xml b/Barotrauma/Content/Characters/Human/humanhusk.xml index 01cdef7c9..29b52fdce 100644 --- a/Barotrauma/Content/Characters/Human/humanhusk.xml +++ b/Barotrauma/Content/Characters/Human/humanhusk.xml @@ -14,7 +14,7 @@ impacttolerance="7.5"> - + @@ -93,7 +93,7 @@ - + diff --git a/Barotrauma/Content/Characters/Husk/husk.xml b/Barotrauma/Content/Characters/Husk/husk.xml index 4ddbfeaa4..179d8dbbe 100644 --- a/Barotrauma/Content/Characters/Husk/husk.xml +++ b/Barotrauma/Content/Characters/Husk/husk.xml @@ -94,9 +94,9 @@ - + - + diff --git a/Barotrauma/Content/Characters/Mantis/mantis.xml b/Barotrauma/Content/Characters/Mantis/mantis.xml index 45ab41fab..419f3a6f4 100644 --- a/Barotrauma/Content/Characters/Mantis/mantis.xml +++ b/Barotrauma/Content/Characters/Mantis/mantis.xml @@ -14,6 +14,7 @@ attackpriorityrooms="50.0" attackpriorityweaker="60" attackprioritystronger="-70" + eatpriority="65" attackcooldown="1.0" sight="0.5" hearing="1.0" @@ -31,7 +32,7 @@ - + diff --git a/Barotrauma/Source/Characters/AI/EnemyAIController.cs b/Barotrauma/Source/Characters/AI/EnemyAIController.cs index f414de4f5..05138ced0 100644 --- a/Barotrauma/Source/Characters/AI/EnemyAIController.cs +++ b/Barotrauma/Source/Characters/AI/EnemyAIController.cs @@ -80,6 +80,7 @@ namespace Barotrauma attackHumans = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackhumans", "attackpriorityhumans") / 100.0f; attackWeaker = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackweaker", "attackpriorityweaker") / 100.0f; attackStronger = ToolBox.GetAttributeFloat(aiElement, 0.0f, "attackstronger", "attackprioritystronger") / 100.0f; + eatDeadPriority = ToolBox.GetAttributeFloat(aiElement, "eatpriority", 0.0f) / 100.0f; combatStrength = ToolBox.GetAttributeFloat(aiElement, "combatstrength", 1.0f); @@ -171,7 +172,7 @@ namespace Barotrauma UpdateAttack(deltaTime); break; case AIState.Eat: - + UpdateEating(deltaTime); break; case AIState.Escape: run = true; @@ -417,7 +418,7 @@ namespace Barotrauma } } - private void UpdateEat(float deltaTime) + private void UpdateEating(float deltaTime) { if (selectedAiTarget == null) { @@ -425,11 +426,59 @@ namespace Barotrauma return; } - var head = Character.AnimController.GetLimb(LimbType.Head); - if (head == null) head = Character.AnimController.MainLimb; + Limb mouthLimb = Array.Find(Character.AnimController.Limbs, l => l != null && l.MouthPos.HasValue); + if (mouthLimb == null) mouthLimb = Character.AnimController.GetLimb(LimbType.Head); + + if (mouthLimb == null) + { + DebugConsole.ThrowError("Character \"" + Character.SpeciesName + "\" failed to eat a target (a head or a limb with a mouthpos required)"); + state = AIState.None; + return; + } + + Vector2 mouthPos = mouthLimb.SimPosition; + if (mouthLimb.MouthPos.HasValue) + { + float cos = (float)Math.Cos(mouthLimb.Rotation); + float sin = (float)Math.Sin(mouthLimb.Rotation); + + mouthPos += new Vector2( + mouthLimb.MouthPos.Value.X * cos - mouthLimb.MouthPos.Value.Y * sin, + mouthLimb.MouthPos.Value.X * sin + mouthLimb.MouthPos.Value.Y * cos); + } + Vector2 attackSimPosition = Character.Submarine == null ? ConvertUnits.ToSimUnits(selectedAiTarget.WorldPosition) : selectedAiTarget.SimPosition; - steeringManager.SteeringSeek(attackSimPosition - (head.SimPosition - SimPosition), 3); + steeringManager.SteeringSeek(attackSimPosition + (mouthPos - SimPosition), 3); + + Vector2 limbDiff = attackSimPosition - mouthPos; + float limbDist = limbDiff.Length(); + if (limbDist < 1.0f) + { + Character targetCharacter = selectedAiTarget.Entity as Character; + //targetCharacter.AnimController.MainLimb.body.ApplyForce(-limbDiff * targetCharacter.AnimController.Mass * (float)(Math.Sin(Timing.TotalTime)+1.0f)); + + targetCharacter.AnimController.MainLimb.MoveToPos( + mouthPos, + (float)(Math.Sin(Timing.TotalTime) + 10.0f)); + steeringManager.SteeringManual(deltaTime, limbDiff); + + Character.AnimController.Collider.ApplyForce(limbDiff * mouthLimb.Mass * 50.0f, mouthPos); + mouthLimb.body.ApplyForce(limbDiff * mouthLimb.Mass * 50.0f * (float)(Math.Sin(Timing.TotalTime) + 1.0f)); + //eatingLimb.pullJoint.Enabled = true; + //eatingLimb.pullJoint.WorldAnchorB = attackSimPosition; + + if (Rand.Range(0.0f, 60.0f) < 1.0f) + { + targetCharacter.AnimController.MainLimb.AddDamage(targetCharacter.SimPosition, DamageType.None, Rand.Range(10.0f, 25.0f), 10.0f, false); + } + } + else if (limbDist < 2.0f) + { + steeringManager.SteeringManual(deltaTime, limbDiff); + Character.AnimController.Collider.ApplyForce(limbDiff * mouthLimb.Mass * 50.0f, mouthPos); + + } } //goes through all the AItargets, evaluates how preferable it is to attack the target, diff --git a/Barotrauma/Source/Characters/Animation/Ragdoll.cs b/Barotrauma/Source/Characters/Animation/Ragdoll.cs index 426b196db..b1d50472c 100644 --- a/Barotrauma/Source/Characters/Animation/Ragdoll.cs +++ b/Barotrauma/Source/Characters/Animation/Ragdoll.cs @@ -502,9 +502,9 @@ namespace Barotrauma { Limb limb = (Limb)f1.Body.UserData; - if (impact > 3.0f && limb.HitSound != null && limb.soundTimer <= 0.0f) + if (impact > 3.0f && limb.HitSound != null && limb.SoundTimer <= 0.0f) { - limb.soundTimer = Limb.SoundInterval; + limb.SoundTimer = Limb.SoundInterval; limb.HitSound.Play(volume, impact * 100.0f, limb.WorldPosition); } } @@ -675,6 +675,8 @@ namespace Barotrauma foreach (Limb limb in Limbs) { if (limb == null || limb.IsSevered) continue; + + limb.Dir = Dir; if (limb.sprite != null) { @@ -683,12 +685,13 @@ namespace Barotrauma limb.sprite.Origin = spriteOrigin; } - limb.Dir = Dir; - - /*if (limb.LightSource != null) + + if (limb.MouthPos.HasValue) { - limb.LightSource.FlipX(); - }*/ + limb.MouthPos = new Vector2( + -limb.MouthPos.Value.X, + limb.MouthPos.Value.Y); + } if (limb.pullJoint != null) {