Husk infections, manually attacking when controlling a creature

This commit is contained in:
Regalis
2016-08-26 20:52:44 +03:00
parent 3d2d06d2e5
commit e2885a912d
19 changed files with 586 additions and 84 deletions

View File

@@ -93,6 +93,7 @@
<Compile Include="Source\Characters\CharacterInfo.cs" />
<Compile Include="Source\Characters\AI\ISteerable.cs" />
<Compile Include="Source\Characters\DelayedEffect.cs" />
<Compile Include="Source\Characters\HuskInfection.cs" />
<Compile Include="Source\Characters\Jobs\Job.cs" />
<Compile Include="Source\Characters\Jobs\JobPrefab.cs" />
<Compile Include="Source\Characters\AI\SteeringManager.cs" />
@@ -391,6 +392,14 @@
<Content Include="Content\Characters\Human\head8[black].png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\humanhusk.xml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\huskappendage.xml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Characters\Human\torso[black].png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@@ -482,6 +491,7 @@
</Content>
<Content Include="Content\InfoTexts.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
<Content Include="Content\Items\Artifacts\alientools.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8" ?>
<Character name ="human" humanoid="true" genders="true" maleheadid="1,8" femaleheadid="1,7" needsair="false" doesbleed="false">
<name firstname="Content/Characters/Human/[GENDER]firstnames.txt" lastname="Content/Characters/Human/lastnames.txt" />
<ragdoll headposition="134" torsoposition="108"
stepsize="42.0, 12.0"
walkanimspeed="4.58"
movementlerp="0.4"
legtorque="15.0"
thightorque="-5.0"
walkspeed="2.0"
swimspeed="2.0">
<!-- head -->
<limb id = "0" radius="13" mass = "6" type="Head" attackpriority="2" impacttolerance="5.0">
<sprite texture="Content/Characters/Human/[GENDER]head[HEADID].png" sourcerect="1,1,37,38" depth="0.04" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/damagedhead.png" sourcerect="1,1,37,38" origin="0.5,0.5"/>
</limb>
<!-- body -->
<limb id = "1" radius="14" height="21" mass = "20" type="Torso" attackpriority="3" impacttolerance="10.0">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="0,0,29,58" depth="0.05" origin="0.5,0.6"/>
<damagedsprite texture="Content/Characters/Human/damagedtorso.png" sourcerect="0,0,29,58" origin="0.5,0.6"/>
</limb>
<limb id = "12" radius="13" mass = "20" type="Waist" impacttolerance="10.0">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="0,0,32,29" depth="0.045" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/damagedlegs.png" sourcerect="0,0,32,29" origin="0.5,0.5"/>
</limb>
<!-- left arm -->
<limb id = "2" radius="8" height="20" mass="3" type="LeftArm">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="30,2,17,39" depth="0.15" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/damagedtorso.png" sourcerect="30,2,17,39" origin="0.5,0.5"/>
</limb>
<limb id = "3" radius="6" height="26" mass="3" type="LeftHand" pullpos="0.0,-18.0">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="49,2,13,47" depth="0.16" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/damagedtorso.png" sourcerect="49,2,13,47" origin="0.5,0.5"/>
</limb>
<!-- right arm -->
<limb id = "4" radius="8" height="20" mass="3" type="RightArm">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="30,2,17,39" depth="0.01" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/damagedtorso.png" sourcerect="30,2,17,39" origin="0.5,0.5"/>
</limb>
<limb id = "5" radius="6" height="26" mass ="3" type="RightHand" pullpos="0.0,-18.0">
<sprite texture="Content/Characters/Human/[GENDER]torso.png" sourcerect="49,2,13,47" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/damagedtorso.png" sourcerect="49,2,13,47" origin="0.5,0.5"/>
</limb>
<!-- left leg -->
<limb id = "6" radius="10" height="30" mass = "8" type="LeftThigh">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="0,32,26,48" depth="0.15" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/damagedlegs.png" sourcerect="0,32,26,48" origin="0.5,0.5"/>
</limb>
<limb id = "7" radius="6" height="39" mass = "5" type="LeftLeg">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="32,0,22,50" depth="0.16" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/damagedlegs.png" sourcerect="32,0,22,50" origin="0.5,0.5"/>
</limb>
<limb id = "8" radius="5" height="13" mass = "2" type ="LeftFoot" flip="true" pullpos="-5.0,0.0">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="35,53,16,25" depth="0.14" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/damagedlegs.png" sourcerect="35,53,16,25" origin="0.5,0.5"/>
<sound file ="Content/step.ogg"/>
</limb>
<!-- right leg -->
<limb id = "9" radius="10" height="30" mass = "8" type="RightThigh">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="0,32,26,48" depth="0.11" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="0,32,26,48" origin="0.5,0.5"/>
</limb>
<limb id = "10" radius="6" height="39" mass = "5" type="RightLeg">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="32,0,22,50" depth="0.12" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="32,0,22,50" origin="0.5,0.5"/>
</limb>
<limb id = "11" radius="5" height="13" mass = "2" type ="RightFoot" flip="true" pullpos="-5.0,0.0">
<sprite texture="Content/Characters/Human/[GENDER]legs.png" sourcerect="35,53,16,25" origin="0.5,0.5"/>
<damagedsprite texture="Content/Characters/Human/damagedlegs.png" sourcerect="35,53,16,25" origin="0.5,0.5"/>
<sound file ="Content/step.ogg"/>
</limb>
<limb id = "13" width="10" height="30" mass = "6" attackpriority="2" flip="true" impacttolerance="5.0" pullpos="0.0,25.0">
<sprite texture="Content/Characters/Husk/DivingSuit.png" sourcerect="110,76,18,52" depth="0.5" origin="0.5,0.5"/>
<attack range="70" duration="0.1" bleedingdamage="3" damage="10" stun="0.5" torque="-50" damagetype="slash" targetforce="10">
<StatusEffect type="OnUse" target="Character" HuskInfectionState="0.01" disabledeltatime="true"/>
<StatusEffect type="OnUse" target="This" Health="20.0" disabledeltatime="true"/>
</attack>
</limb>
<!-- head to body -->
<joint limb1="0" limb1anchor="0,-7" limb2="1" limb2anchor="-1,26" lowerlimit="-90" upperlimit="45"/>
<joint limb1="1" limb1anchor="0,-17" limb2="12" limb2anchor="0,7" lowerlimit="-10" upperlimit="10"/>
<!-- body to left arm -->
<joint limb1="1" limb1anchor="-3,14" limb2="2" limb2anchor="0,12"/>
<joint limb1="2" limb1anchor="0,-16" limb2="3" limb2anchor="-2,19" lowerlimit="5" upperlimit="170"/>
<!-- body to right arm -->
<joint limb1="1" limb1anchor="-3,14" limb2="4" limb2anchor="0,12"/>
<joint limb1="4" limb1anchor="0,-16" limb2="5" limb2anchor="-2,19" lowerlimit="5" upperlimit="170"/>
<!-- body to left leg -->
<joint limb1="12" limb1anchor="0,-1" limb2="6" limb2anchor="0,14" lowerlimit="-30" upperlimit="120"/>
<joint limb1="6" limb1anchor="0,-15" limb2="7" limb2anchor="0,20" lowerlimit="-120" upperlimit="0"/>
<joint limb1="7" limb1anchor="-3,-21" limb2="8" limb2anchor="5,7" lowerlimit="20" upperlimit="90"/>
<!-- body to right leg -->
<joint limb1="12" limb1anchor="0,-1" limb2="9" limb2anchor="0,14" lowerlimit="-30" upperlimit="120"/>
<joint limb1="9" limb1anchor="0,-15" limb2="10" limb2anchor="0,20" lowerlimit="-120" upperlimit="0"/>
<joint limb1="10" limb1anchor="-3,-21" limb2="11" limb2anchor="5,7" lowerlimit="20" upperlimit="90"/>
<joint limb1="1" limb1anchor="25,10" limb2="13" limb2anchor="25,0" lowerlimit="-40" upperlimit="0"/>
</ragdoll>
<ai attackhumans="500" attackrooms="5.0" attackweaker="50" attackstronger="-30"
sight="0.5" hearing="1.0"
attackcooldown="5.0"/>
</Character>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<huskappendage>
<!-- spike/tentacle thingy -->
<limb id = "13" width="10" height="30" mass = "6" attackpriority="2" flip="true" impacttolerance="5.0" pullpos="0.0,25.0">
<sprite texture="Content/Characters/Husk/DivingSuit.png" sourcerect="110,76,18,52" depth="0.5" origin="0.5,0.5"/>
<attack range="70" duration="0.1" bleedingdamage="0.5" damage="10" stun="0.5" torque="-50" damagetype="slash" targetforce="10">
<StatusEffect type="OnUse" target="Character" HuskInfectionState="0.01"/>
<StatusEffect type="OnUse" target="This" Health="10.0" disabledeltatime="true"/>
</attack>
</limb>
<joint limb1="1" limb1anchor="25,10" limb2="13" limb2anchor="25,0" lowerlimit="-40" upperlimit="0"/>
</huskappendage>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -23,7 +23,7 @@
<!-- spike/tentacle thingy -->
<limb id = "13" width="10" height="30" mass = "6" attackpriority="2" impacttolerance="5.0" flip="true" pullpos="0.0,25.0">
<sprite texture="Content/Characters/Husk/DivingSuit.png" sourcerect="110,76,18,52" depth="0.05" origin="0.5,0.5"/>
<attack range="70" duration="0.2" bleedingdamage="3" damage="10" stun="0.5" torque="-50" damagetype="slash" targetforce="10">
<attack range="70" duration="0.2" bleedingdamage="0.5" damage="10" stun="0.5" torque="-50" damagetype="slash" targetforce="10">
<StatusEffect type="OnUse" target="Character" HuskInfectionState="0.01" disabledeltatime="true"/>
<StatusEffect type="OnUse" target="This" Health="1.0" disabledeltatime="true"/>
</attack>

View File

@@ -21,4 +21,15 @@
<Self_CauseOfDeath.Burn>You have burned to death.</Self_CauseOfDeath.Burn>
<Self_CauseOfDeath.Disconnected>You have been disconnected from the server.</Self_CauseOfDeath.Disconnected>
<HuskDormant>Your throat feels sore</HuskDormant>
<HuskDormant>Your feel feverish</HuskDormant>
<HuskDormant>It feels as if something was stuck in your throat</HuskDormant>
<HuskDormant>Your muscles are aching</HuskDormant>
<HuskCantSpeak>You feel something moving in your throat. You try to scream but no sound comes out.</HuskCantSpeak>
<HuskActivate>A strange chitinous appendage bursts out from your mouth. Use it to inject eggs into a living body by pressing [Attack]!</HuskActivate>
</infotexts>

View File

@@ -10,6 +10,8 @@ namespace Barotrauma
public enum AiState { None, Attack, GoTo, Escape }
public enum SteeringState { Wander, Seek, Escape }
public bool Enabled;
public readonly Character Character;
protected AiState state;
@@ -51,6 +53,8 @@ namespace Barotrauma
public AIController (Character c)
{
Character = c;
Enabled = true;
}
public virtual void DebugDraw(SpriteBatch spriteBatch) { }

View File

@@ -49,7 +49,7 @@ namespace Barotrauma
if (isDead || health <= 0.0f) return;
if (Controlled == this) return;
if (Controlled == this || !aiController.Enabled) return;
if (soundTimer > 0)
{
@@ -117,6 +117,12 @@ namespace Barotrauma
aiController.FillNetworkData(message);
return true;
case NetworkEventType.EntityUpdate:
message.Write(Controlled == this);
if (Controlled == this)
{
return base.FillNetworkData(type, message, data);
}
message.Write(AnimController.Dir > 0.0f);
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -1.0f, 1.0f), -1.0f, 1.0f, 4);
@@ -215,6 +221,15 @@ namespace Barotrauma
case NetworkEventType.EntityUpdate:
if (sendingTime <= LastNetworkUpdate) return false;
bool playerControlled = message.ReadBoolean();
if (playerControlled)
{
aiController.Enabled = false;
return base.ReadNetworkData(type, message, sendingTime, out data);
}
aiController.Enabled = true;
Vector2 targetMovement = Vector2.Zero, pos = Vector2.Zero;
bool targetDir = false,inSub = false;

View File

@@ -30,8 +30,8 @@ namespace Barotrauma
protected float strongestImpact;
float headPosition, headAngle;
float torsoPosition, torsoAngle;
public float headPosition, headAngle;
public float torsoPosition, torsoAngle;
protected double onFloorTimer;
@@ -231,8 +231,7 @@ namespace Barotrauma
byte ID = Convert.ToByte(subElement.Attribute("id").Value);
Limb limb = new Limb(character, subElement, scale);
limb.body.FarseerBody.OnCollision += OnLimbCollision;
Limbs[ID] = limb;
@@ -240,38 +239,7 @@ namespace Barotrauma
if (!limbDictionary.ContainsKey(limb.type)) limbDictionary.Add(limb.type, limb);
break;
case "joint":
Byte limb1ID = Convert.ToByte(subElement.Attribute("limb1").Value);
Byte limb2ID = Convert.ToByte(subElement.Attribute("limb2").Value);
Vector2 limb1Pos = ToolBox.GetAttributeVector2(subElement, "limb1anchor", Vector2.Zero) * scale;
limb1Pos = ConvertUnits.ToSimUnits(limb1Pos);
Vector2 limb2Pos = ToolBox.GetAttributeVector2(subElement, "limb2anchor", Vector2.Zero) * scale;
limb2Pos = ConvertUnits.ToSimUnits(limb2Pos);
RevoluteJoint joint = new RevoluteJoint(Limbs[limb1ID].body.FarseerBody, Limbs[limb2ID].body.FarseerBody, limb1Pos, limb2Pos);
joint.CollideConnected = false;
if (subElement.Attribute("lowerlimit")!=null)
{
joint.LimitEnabled = true;
joint.LowerLimit = float.Parse(subElement.Attribute("lowerlimit").Value) * ((float)Math.PI / 180.0f);
joint.UpperLimit = float.Parse(subElement.Attribute("upperlimit").Value) * ((float)Math.PI / 180.0f);
}
joint.MotorEnabled = true;
joint.MaxMotorTorque = 0.25f;
GameMain.World.AddJoint(joint);
for (int i = 0; i < limbJoints.Length; i++ )
{
if (limbJoints[i] != null) continue;
limbJoints[i] = joint;
break;
}
AddJoint(subElement, scale);
break;
}
@@ -308,6 +276,58 @@ namespace Barotrauma
FindLowestLimb();
}
public void AddJoint(XElement subElement, float scale = 1.0f)
{
byte limb1ID = Convert.ToByte(subElement.Attribute("limb1").Value);
byte limb2ID = Convert.ToByte(subElement.Attribute("limb2").Value);
Vector2 limb1Pos = ToolBox.GetAttributeVector2(subElement, "limb1anchor", Vector2.Zero) * scale;
limb1Pos = ConvertUnits.ToSimUnits(limb1Pos);
Vector2 limb2Pos = ToolBox.GetAttributeVector2(subElement, "limb2anchor", Vector2.Zero) * scale;
limb2Pos = ConvertUnits.ToSimUnits(limb2Pos);
RevoluteJoint joint = new RevoluteJoint(Limbs[limb1ID].body.FarseerBody, Limbs[limb2ID].body.FarseerBody, limb1Pos, limb2Pos);
joint.CollideConnected = false;
if (subElement.Attribute("lowerlimit") != null)
{
joint.LimitEnabled = true;
joint.LowerLimit = float.Parse(subElement.Attribute("lowerlimit").Value) * ((float)Math.PI / 180.0f);
joint.UpperLimit = float.Parse(subElement.Attribute("upperlimit").Value) * ((float)Math.PI / 180.0f);
}
joint.MotorEnabled = true;
joint.MaxMotorTorque = 0.25f;
GameMain.World.AddJoint(joint);
for (int i = 0; i < limbJoints.Length; i++)
{
if (limbJoints[i] != null) continue;
limbJoints[i] = joint;
return;
}
Array.Resize(ref limbJoints, limbJoints.Length + 1);
limbJoints[limbJoints.Length - 1] = joint;
}
public void AddLimb(Limb limb)
{
limb.body.FarseerBody.OnCollision += OnLimbCollision;
Array.Resize(ref Limbs, Limbs.Length + 1);
Limbs[Limbs.Length-1] = limb;
Mass += limb.Mass;
if (!limbDictionary.ContainsKey(limb.type)) limbDictionary.Add(limb.type, limb);
}
public bool OnLimbCollision(Fixture f1, Fixture f2, Contact contact)
{

View File

@@ -136,22 +136,24 @@ namespace Barotrauma
{
sound.Play(1.0f, 500.0f, worldPosition);
}
var attackResult = target.AddDamage(attacker, worldPosition, this, deltaTime, playSound);
var effectType = attackResult.Damage > 0.0f ? ActionType.OnUse : ActionType.OnFailure;
foreach (StatusEffect effect in statusEffects)
{
if (effect.Targets.HasFlag(StatusEffect.TargetType.This) && attacker is Character)
{
effect.Apply(ActionType.OnUse, deltaTime, (Character)attacker, (Character)attacker);
effect.Apply(effectType, deltaTime, (Character)attacker, (Character)attacker);
}
if (effect.Targets.HasFlag(StatusEffect.TargetType.Character) && target is Character)
{
effect.Apply(ActionType.OnUse, deltaTime, (Character)target, (Character)target);
}
effect.Apply(effectType, deltaTime, (Character)target, (Character)target);
}
}
return target.AddDamage(attacker, worldPosition, this, deltaTime, playSound);
return attackResult;
}
}
}

View File

@@ -112,6 +112,8 @@ namespace Barotrauma
//which AIstate each sound is for
private AIController.AiState[] soundStates;
private float attackCoolDown;
public Entity ViewTarget
{
get;
@@ -248,6 +250,7 @@ namespace Barotrauma
public bool NeedsAir
{
get { return needsAir; }
set { needsAir = value; }
}
public float Oxygen
@@ -298,6 +301,38 @@ namespace Barotrauma
}
}
public HuskInfection huskInfection;
public float HuskInfectionState
{
get
{
return huskInfection == null ? 0.0f : huskInfection.IncubationTimer;
}
set
{
if (ConfigPath != humanConfigFile) return;
if (value <= 0.0f)
{
if (huskInfection != null && huskInfection.State == HuskInfection.InfectionState.Active) return;
huskInfection = null;
}
else
{
if (huskInfection == null) huskInfection = new HuskInfection(this);
huskInfection.IncubationTimer = MathHelper.Clamp(value, 0.0f, 1.0f);
}
}
}
public bool CanSpeak
{
get
{
return !IsUnconscious && Stun <= 0.0f && (huskInfection == null || huskInfection.CanSpeak);
}
}
public bool DoesBleed
{
get;
@@ -310,7 +345,6 @@ namespace Barotrauma
private set;
}
public float PressureTimer
{
get;
@@ -474,13 +508,17 @@ namespace Barotrauma
Properties = ObjectProperty.GetProperties(this);
if (file == humanConfigFile)
if (file == humanConfigFile && characterInfo == null)
{
Info = characterInfo == null ? new CharacterInfo(file) : characterInfo;
Info = new CharacterInfo(file);
}
Info = characterInfo;
XDocument doc = ToolBox.TryLoadXml(file);
if (doc == null || doc.Root == null) return;
SpeciesName = ToolBox.GetAttributeString(doc.Root, "name", "Unknown");
@@ -696,6 +734,49 @@ namespace Barotrauma
}
}
if (attackCoolDown >0.0f)
{
attackCoolDown -= deltaTime;
}
else if (IsKeyDown(InputType.Attack))
{
var attackLimb = AnimController.Limbs.FirstOrDefault(l => l.attack != null);
if (attackLimb != null)
{
Vector2 attackPos =
attackLimb.SimPosition + Vector2.Normalize(cursorPosition - attackLimb.Position) * ConvertUnits.ToSimUnits(attackLimb.attack.Range);
var body = Submarine.PickBody(
attackLimb.SimPosition,
attackPos,
AnimController.Limbs.Select(l => l.body.FarseerBody).ToList(),
Physics.CollisionCharacter | Physics.CollisionWall);
IDamageable attackTarget = null;
if (body != null)
{
if (body.UserData is IDamageable)
{
attackTarget = (IDamageable)body.UserData;
}
else if (body.UserData is Limb)
{
attackTarget = ((Limb)body.UserData).character;
}
attackPos = Submarine.LastPickedPosition;
}
attackLimb.UpdateAttack(deltaTime, attackPos, attackTarget);
if (attackLimb.AttackTimer > attackLimb.attack.Duration)
{
attackLimb.AttackTimer = 0.0f;
attackCoolDown = 1.0f;
}
}
}
for (int i = 0; i < selectedItems.Length; i++ )
{
if (selectedItems[i] == null) continue;
@@ -859,7 +940,7 @@ namespace Barotrauma
foreach (Limb limb in selectedCharacter.AnimController.Limbs)
{
limb.pullJoint.Enabled = false;
if (limb.pullJoint != null) limb.pullJoint.Enabled = false;
}
selectedCharacter = null;
@@ -923,7 +1004,6 @@ namespace Barotrauma
}
}
if (!LockHands)
{
//find the closest item if selectkey has been hit, or if the Character is being
@@ -1014,9 +1094,9 @@ namespace Barotrauma
// new Character(NewCharacterQueue.Dequeue(), Vector2.Zero);
//}
foreach (Character c in CharacterList)
for (int i = 0; i<CharacterList.Count; i++)
{
c.Update(cam, deltaTime);
CharacterList[i].Update(cam, deltaTime);
}
}
@@ -1039,6 +1119,8 @@ namespace Barotrauma
}
}
if (huskInfection != null) huskInfection.Update(deltaTime, this);
if (isDead) return;
if (networkUpdateSent)
@@ -1084,7 +1166,7 @@ namespace Barotrauma
Lights.LightManager.ViewTarget = this;
CharacterHUD.Update(deltaTime, this);
}
if (IsUnconscious)
{
UpdateUnconscious(deltaTime);
@@ -1096,7 +1178,12 @@ namespace Barotrauma
ControlLocalPlayer(deltaTime, cam);
}
if (controlled == this || !(this is AICharacter)) Control(deltaTime, cam);
if (controlled == this ||
!(this is AICharacter) ||
!((AICharacter)this).AIController.Enabled)
{
Control(deltaTime, cam);
}
if (selectedCharacter != null && AnimController.Anim == AnimController.Animation.CPR)
{
@@ -1323,10 +1410,18 @@ namespace Barotrauma
if (GameMain.NetworkMember != null && controlled != this) return;
}
Vector2 centerOfMass = AnimController.GetCenterOfMass();
health = minHealth;
BreakJoints();
Kill(CauseOfDeath.Pressure, isNetworkMessage);
}
public void BreakJoints()
{
Vector2 centerOfMass = AnimController.GetCenterOfMass();
foreach (Limb limb in AnimController.Limbs)
{
limb.AddDamage(limb.SimPosition, DamageType.Blunt, 500.0f, 0.0f, false);
@@ -1334,28 +1429,27 @@ namespace Barotrauma
Vector2 diff = centerOfMass - limb.SimPosition;
if (diff == Vector2.Zero) continue;
limb.body.ApplyLinearImpulse(diff * 10.0f);
// limb.Damage = 100.0f;
// limb.Damage = 100.0f;
}
SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.RefLimb.body);
for (int i = 0; i < 10; i++)
{
Particle p = GameMain.ParticleManager.CreateParticle("waterblood",
ConvertUnits.ToDisplayUnits(centerOfMass) + Rand.Vector(5.0f),
Rand.Vector(10.0f));
if (p!=null) p.Size *= 2.0f;
if (p != null) p.Size *= 2.0f;
GameMain.ParticleManager.CreateParticle("bubbles",
ConvertUnits.ToDisplayUnits(centerOfMass) + Rand.Vector(5.0f),
new Vector2(Rand.Range(-50f, 50f), Rand.Range(-100f,50f)));
new Vector2(Rand.Range(-50f, 50f), Rand.Range(-100f, 50f)));
}
foreach (var joint in AnimController.limbJoints)
{
joint.LimitEnabled = false;
}
Kill(CauseOfDeath.Pressure, isNetworkMessage);
}
public void Kill(CauseOfDeath causeOfDeath, bool isNetworkMessage = false)
@@ -1495,16 +1589,6 @@ namespace Barotrauma
message.WriteRangedSingle(health, minHealth, maxHealth, 8);
//if (health > 0.0f)
//{
// message.Write(Math.Max((byte)((health / maxHealth) * 255.0f), (byte)1));
//}
//else
//{
// message.Write((byte)0);
// message.WriteRangedInteger(0, Enum.GetValues(typeof(CauseOfDeath)).Length-1, (int)lastAttackCauseOfDeath);
//}
if (AnimController.StunTimer <= 0.0f && bleeding <= 0.0f && oxygen > 99.0f)
{
message.Write(true);
@@ -1519,6 +1603,12 @@ namespace Barotrauma
bleeding = MathHelper.Clamp(bleeding, 0.0f, 5.0f);
message.WriteRangedSingle(bleeding, 0.0f, 5.0f, 8);
message.Write(huskInfection != null);
if (huskInfection!=null)
{
message.WriteRangedSingle(HuskInfectionState, 0.0f, 1.0f, 4);
}
}
return true;
@@ -1536,8 +1626,15 @@ namespace Barotrauma
message.Write(keys[(int)InputType.Run].Held);
message.Write(((HumanoidAnimController)AnimController).Crouching);
if (AnimController.Limbs.Any(l => l.attack != null))
{
message.Write(keys[(int)InputType.Attack].Held);
}
if (AnimController is HumanoidAnimController)
{
message.Write(((HumanoidAnimController)AnimController).Crouching);
}
if (secondaryHeld)
{
@@ -1587,7 +1684,6 @@ namespace Barotrauma
public override bool ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data)
{
Enabled = true;
data = null;
if (GameMain.Server != null && type != NetworkEventType.InventoryUpdate)
@@ -1729,13 +1825,20 @@ namespace Barotrauma
Oxygen = message.ReadRangedSingle(-100.0f,100.0f, 8);
Bleeding = message.ReadRangedSingle(0.0f, 5.0f, 8);
if (message.ReadBoolean())
{
HuskInfectionState = message.ReadRangedSingle(0.0f, 1.0f, 4);
}
break;
case NetworkEventType.EntityUpdate:
Enabled = true;
Vector2 relativeCursorPos = Vector2.Zero;
bool actionKeyState, secondaryKeyState;
bool leftKeyState, rightKeyState, upKeyState, downKeyState;
bool runState, crouchState;
bool runState, crouchState = false, attackState = false;
try
{
@@ -1750,7 +1853,16 @@ namespace Barotrauma
downKeyState = message.ReadBoolean();
runState = message.ReadBoolean();
crouchState = message.ReadBoolean();
if (AnimController.Limbs.Any(l => l.attack != null))
{
attackState = message.ReadBoolean();
}
if (AnimController is HumanoidAnimController)
{
crouchState = message.ReadBoolean();
}
}
catch (Exception e)
@@ -1769,6 +1881,9 @@ namespace Barotrauma
keys[(int)InputType.Aim].Held = secondaryKeyState;
keys[(int)InputType.Aim].SetState(false, secondaryKeyState);
keys[(int)InputType.Attack].Held = attackState;
keys[(int)InputType.Attack].SetState(false, attackState);
if (sendingTime <= LastNetworkUpdate) return false;
keys[(int)InputType.Left].Held = leftKeyState;

View File

@@ -197,6 +197,7 @@ namespace Barotrauma
if (Character.Controlled != null)
{
Character.Controlled.Kill(Character.Controlled.CauseOfDeath);
Character.Controlled = null;
}
return true;
};

View File

@@ -0,0 +1,186 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Barotrauma
{
class HuskInfection
{
public enum InfectionState
{
Dormant, Transition, Active
}
const float IncubationDuration = 300.0f;
private InfectionState state;
private float incubationTimer;
public float IncubationTimer
{
get { return incubationTimer; }
set
{
incubationTimer = MathHelper.Clamp(value, 0.0f, 1.0f);
}
}
public InfectionState State
{
get { return state; }
}
public bool CanSpeak
{
get { return IncubationTimer < 0.5f; }
}
public HuskInfection(Character character)
{
character.OnDeath += CharacterDead;
}
public void Update(float deltaTime, Character character)
{
if (IncubationTimer < 0.5f)
{
UpdateDormantState(deltaTime, character);
}
else if (IncubationTimer < 1.0f)
{
UpdateTransitionState(deltaTime, character);
}
else
{
UpdateActiveState(deltaTime, character);
}
}
private void UpdateDormantState(float deltaTime, Character character)
{
float prevTimer = IncubationTimer;
state = InfectionState.Dormant;
IncubationTimer += 100* deltaTime / IncubationDuration;
if (Character.Controlled != character) return;
if (prevTimer % 0.1f > 0.05f && IncubationTimer % 0.1f < 0.05f)
{
GUI.AddMessage(InfoTextManager.GetInfoText("HuskDormant"), Color.Red, 4.0f);
}
}
private void UpdateTransitionState(float deltaTime, Character character)
{
IncubationTimer += deltaTime*10.0f/ IncubationDuration;
if (state == InfectionState.Dormant && Character.Controlled == character)
{
new GUIMessageBox("", InfoTextManager.GetInfoText("HuskCantSpeak"));
}
state = InfectionState.Transition;
}
private void UpdateActiveState(float deltaTime, Character character)
{
if (state != InfectionState.Active)
{
if (Character.Controlled==character) new GUIMessageBox("", InfoTextManager.GetInfoText("HuskActivate"));
ActivateHusk(character);
state = InfectionState.Active;
}
character.AddDamage(CauseOfDeath.Damage, 0.5f*deltaTime, null);
if (character.AnimController.limbJoints[0].LimitEnabled &&
(character.AnimController.CurrentHull == null ||
character.AnimController.CurrentHull.LethalPressure > 50.0f))
{
character.BreakJoints();
character.AnimController.limbJoints.Last().LimitEnabled = true;
}
}
private void ActivateHusk(Character character)
{
character.NeedsAir = false;
AttachHuskAppendage(character);
}
private void AttachHuskAppendage(Character character)
{
XDocument doc = ToolBox.TryLoadXml(Path.Combine("Content", "Characters", "Human", "huskappendage.xml"));
if (doc == null || doc.Root == null) return;
var limbElement = doc.Root.Element("limb");
if (limbElement == null)
{
DebugConsole.ThrowError("Error in huskappendage.xml - limb element not found");
return;
}
var jointElement = doc.Root.Element("joint");
if (jointElement == null)
{
DebugConsole.ThrowError("Error in huskappendage.xml - joint element not found");
return;
}
character.StartStun(0.5f);
if (character.AnimController.Dir < 1.0f)
{
character.AnimController.Flip();
}
var torso = character.AnimController.GetLimb(LimbType.Torso);
torso.body.SetTransform(torso.SimPosition, 0.0f);
var newLimb = new Limb(character, limbElement);
newLimb.body.Submarine = character.Submarine;
newLimb.body.SetTransform(torso.SimPosition, 0.0f);
character.AnimController.AddLimb(newLimb);
character.AnimController.AddJoint(jointElement);
}
private void CharacterDead(Character character, CauseOfDeath causeOfDeath)
{
var husk = Character.Create(
Path.Combine("Content", "Characters", "Human", "humanhusk.xml"),
character.WorldPosition,
character.Info,
false, true);
foreach (Limb limb in husk.AnimController.Limbs)
{
if (limb.type == LimbType.None)
{
limb.body.SetTransform(character.SimPosition, 0.0f);
continue;
}
var matchingLimb = character.AnimController.GetLimb(limb.type);
limb.body.SetTransform(matchingLimb.SimPosition, matchingLimb.Rotation);
}
for (int i = 0; i < character.Inventory.Items.Length; i++)
{
if (character.Inventory.Items[i] == null) continue;
husk.Inventory.TryPutItem(character.Inventory.Items[i], i, false, true);
}
character.Enabled = false;
husk.SpawnedMidRound = true;
}
}
}

View File

@@ -499,12 +499,10 @@ namespace Barotrauma
float dist = ConvertUnits.ToDisplayUnits(Vector2.Distance(SimPosition, attackPosition));
AttackTimer += deltaTime;
body.ApplyTorque(Mass * character.AnimController.Dir * attack.Torque);
if (dist < attack.Range * 0.5f)
{
AttackTimer += deltaTime;
body.ApplyTorque(Mass * character.AnimController.Dir * attack.Torque);
if (AttackTimer >= attack.Duration && damageTarget != null)
{
attack.DoDamage(character, damageTarget, WorldPosition, 1.0f, (soundTimer <= 0.0f));
@@ -520,7 +518,6 @@ namespace Barotrauma
body.ApplyLinearImpulse(Mass * attack.Force *
Vector2.Normalize(attackPosition - SimPosition), pos);
}
}
public void Draw(SpriteBatch spriteBatch)

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
@@ -51,6 +52,11 @@ namespace Barotrauma
string text = infoList[Rand.Int(infoList.Count)];
foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
{
text = text.Replace("[" + inputType.ToString() + "]", GameMain.Config.KeyBind(inputType).ToString());
}
if (Submarine.MainSub != null) text = text.Replace("[sub]", Submarine.MainSub.Name);
if (GameMain.GameSession != null && GameMain.GameSession.Map != null)
{

View File

@@ -383,6 +383,12 @@ namespace Barotrauma
{
new GUITextBlock(new Rectangle(x, y, 100, 20), inputNames[i]+": ", GUI.Style, settingsFrame);
var keyBox = new GUITextBox(new Rectangle(x + 100, y, 120, 15), GUI.Style, settingsFrame);
if (keyMapping[i]==null)
{
keyMapping[i] = new KeyOrMouse(Keys.D1);
}
keyBox.Text = keyMapping[i].ToString();
keyBox.UserData = i;
keyBox.OnSelected += KeyBoxSelected;

View File

@@ -1623,7 +1623,7 @@ namespace Barotrauma.Networking
public void SendCharacterSpawnMessage(Character character, List<NetConnection> recipients = null)
{
if (recipients == null || !recipients.Any()) return;
if (recipients != null && !recipients.Any()) return;
NetOutgoingMessage message = server.CreateMessage();
message.Write((byte)PacketTypes.NewCharacter);

View File

@@ -340,15 +340,12 @@ namespace Barotrauma.Networking
{
if (gameStarted && Screen.Selected == GameMain.GameScreen)
{
chatMsgBox.Visible = Character.Controlled == null ||
(!Character.Controlled.IsUnconscious && Character.Controlled.Stun <= 0.0f);
chatMsgBox.Visible = Character.Controlled == null || Character.Controlled.CanSpeak;
inGameHUD.Update(deltaTime);
GameMain.GameSession.CrewManager.Update(deltaTime);
//if (crewFrameOpen) crewFrame.Update(deltaTime);
if (Character.Controlled == null || Character.Controlled.IsDead)
{
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;

View File

@@ -10,6 +10,7 @@ namespace Barotrauma
Use,
Aim,
Up, Down, Left, Right,
Attack,
Run, Crouch,
Chat, CrewOrders
}