public static bool ShouldMuffleSound(Character listener, Vector2 soundWorldPos, float range, Hull hullGuess)
        {
            if (listener == null)
            {
                return(false);
            }

            float          lowpassHFGain  = 1.0f;
            AnimController animController = listener.AnimController;

            if (animController.HeadInWater)
            {
                lowpassHFGain = 0.2f;
            }
            lowpassHFGain *= Character.Controlled.LowPassMultiplier;
            if (lowpassHFGain < 0.5f)
            {
                return(true);
            }

            Hull targetHull = Hull.FindHull(soundWorldPos, hullGuess, true);

            if (listener.CurrentHull == null || targetHull == null)
            {
                return(listener.CurrentHull != targetHull);
            }
            Vector2 soundPos = soundWorldPos;

            if (targetHull.Submarine != null)
            {
                soundPos += -targetHull.Submarine.WorldPosition + targetHull.Submarine.HiddenSubPosition;
            }
            return(listener.CurrentHull.GetApproximateDistance(listener.Position, soundPos, targetHull, range) > range);
        }
Exemple #2
0
        partial void ImplodeFX()
        {
            Vector2 centerOfMass = AnimController.GetCenterOfMass();

            SoundPlayer.PlaySound("implode", 1.0f, 150.0f, WorldPosition);

            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;
                }

                GameMain.ParticleManager.CreateParticle("bubbles",
                                                        ConvertUnits.ToDisplayUnits(centerOfMass) + Rand.Vector(5.0f),
                                                        new Vector2(Rand.Range(-50f, 50f), Rand.Range(-100f, 50f)));

                GameMain.ParticleManager.CreateParticle("gib",
                                                        WorldPosition + Rand.Vector(Rand.Range(0.0f, 50.0f)),
                                                        Rand.Range(0.0f, MathHelper.TwoPi),
                                                        Rand.Range(200.0f, 700.0f), null);
            }

            for (int i = 0; i < 30; i++)
            {
                GameMain.ParticleManager.CreateParticle("heavygib",
                                                        WorldPosition + Rand.Vector(Rand.Range(0.0f, 50.0f)),
                                                        Rand.Range(0.0f, MathHelper.TwoPi),
                                                        Rand.Range(50.0f, 500.0f), null);
            }
        }
Exemple #3
0
        private void ReadStatus(IReadMessage msg)
        {
            bool isDead = msg.ReadBoolean();

            if (isDead)
            {
                CauseOfDeathType causeOfDeathType       = (CauseOfDeathType)msg.ReadRangedInteger(0, Enum.GetValues(typeof(CauseOfDeathType)).Length - 1);
                AfflictionPrefab causeOfDeathAffliction = null;
                if (causeOfDeathType == CauseOfDeathType.Affliction)
                {
                    string afflictionName = msg.ReadString();
                    if (!AfflictionPrefab.Prefabs.ContainsKey(afflictionName))
                    {
                        string errorMsg = $"Error in CharacterNetworking.ReadStatus: affliction not found ({afflictionName})";
                        causeOfDeathType = CauseOfDeathType.Unknown;
                        GameAnalyticsManager.AddErrorEventOnce("CharacterNetworking.ReadStatus:AfflictionIndexOutOfBounts", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
                    }
                    else
                    {
                        causeOfDeathAffliction = AfflictionPrefab.Prefabs[afflictionName];
                    }
                }

                byte severedLimbCount = msg.ReadByte();
                if (!IsDead)
                {
                    if (causeOfDeathType == CauseOfDeathType.Pressure)
                    {
                        Implode(true);
                    }
                    else
                    {
                        Kill(causeOfDeathType, causeOfDeathAffliction?.Instantiate(1.0f), true);
                    }
                }

                for (int i = 0; i < severedLimbCount; i++)
                {
                    int severedJointIndex = msg.ReadByte();
                    if (severedJointIndex < 0 || severedJointIndex >= AnimController.LimbJoints.Length)
                    {
                        string errorMsg = $"Error in CharacterNetworking.ReadStatus: severed joint index out of bounds (index: {severedJointIndex}, joint count: {AnimController.LimbJoints.Length})";
                        GameAnalyticsManager.AddErrorEventOnce("CharacterNetworking.ReadStatus:JointIndexOutOfBounts", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
                    }
                    else
                    {
                        AnimController.SeverLimbJoint(AnimController.LimbJoints[severedJointIndex]);
                    }
                }
            }
            else
            {
                if (IsDead)
                {
                    Revive();
                }
                CharacterHealth.ClientRead(msg);
            }
        }
Exemple #4
0
        public void Draw(SpriteBatch spriteBatch)
        {
            if (!Enabled)
            {
                return;
            }

            AnimController.Draw(spriteBatch);
        }
Exemple #5
0
        public void Draw(SpriteBatch spriteBatch, Camera cam)
        {
            if (!Enabled)
            {
                return;
            }

            AnimController.Draw(spriteBatch, cam);
        }
Exemple #6
0
        public static void Update(float deltaTime)
        {
            UpdateMusic(deltaTime);

            if (startUpSound != null && !GameMain.SoundManager.IsPlaying(startUpSound))
            {
                startUpSound.Dispose();
                startUpSound = null;
            }

            //stop water sounds if no sub is loaded
            if (Submarine.MainSub == null || Screen.Selected != GameMain.GameScreen)
            {
                for (int i = 0; i < waterAmbienceChannels.Length; i++)
                {
                    if (waterAmbienceChannels[i] == null)
                    {
                        continue;
                    }
                    waterAmbienceChannels[i].Dispose();
                    waterAmbienceChannels[i] = null;
                }
                for (int i = 0; i < FlowSounds.Count; i++)
                {
                    if (flowSoundChannels[i] == null)
                    {
                        continue;
                    }
                    flowSoundChannels[i].Dispose();
                    flowSoundChannels[i] = null;
                }
                return;
            }

            float ambienceVolume = 0.8f;

            if (Character.Controlled != null)
            {
                AnimController animController = Character.Controlled.AnimController;
                if (animController.HeadInWater)
                {
                    ambienceVolume  = 1.0f;
                    ambienceVolume += animController.Limbs[0].LinearVelocity.Length();
                }
            }

            UpdateWaterAmbience(ambienceVolume);
            UpdateWaterFlowSounds(deltaTime);
            UpdateRandomAmbience(deltaTime);
            UpdateFireSounds(deltaTime);
        }
        private void ReadStatus(NetBuffer msg)
        {
            bool isDead = msg.ReadBoolean();

            if (isDead)
            {
                CauseOfDeathType causeOfDeathType       = (CauseOfDeathType)msg.ReadRangedInteger(0, Enum.GetValues(typeof(CauseOfDeathType)).Length - 1);
                AfflictionPrefab causeOfDeathAffliction = null;
                if (causeOfDeathType == CauseOfDeathType.Affliction)
                {
                    int afflictionIndex = msg.ReadRangedInteger(0, AfflictionPrefab.List.Count - 1);
                    causeOfDeathAffliction = AfflictionPrefab.List[afflictionIndex];
                }

                byte severedLimbCount = msg.ReadByte();
                if (!IsDead)
                {
                    if (causeOfDeathType == CauseOfDeathType.Pressure)
                    {
                        Implode(true);
                    }
                    else
                    {
                        Kill(causeOfDeathType, causeOfDeathAffliction, true);
                    }
                }

                for (int i = 0; i < severedLimbCount; i++)
                {
                    int severedJointIndex = msg.ReadByte();
                    AnimController.SeverLimbJoint(AnimController.LimbJoints[severedJointIndex]);
                }
            }
            else
            {
                if (IsDead)
                {
                    Revive();
                }

                CharacterHealth.ClientRead(msg);

                bool ragdolled = msg.ReadBoolean();
                IsRagdolled = ragdolled;
            }
        }
Exemple #8
0
        public static void Update(float deltaTime)
        {
            UpdateMusic(deltaTime);

            if (startDrone != null && !startDrone.IsPlaying)
            {
                startDrone.Remove();
                startDrone = null;
            }

            //stop submarine ambient sounds if no sub is loaded
            if (Submarine.MainSub == null)
            {
                for (int i = 0; i < waterAmbienceIndexes.Length; i++)
                {
                    if (waterAmbienceIndexes[i] <= 0)
                    {
                        continue;
                    }

                    SoundManager.Stop(waterAmbienceIndexes[i]);
                    waterAmbienceIndexes[i] = 0;
                }
                return;
            }

            float ambienceVolume = 0.8f;
            float lowpassHFGain  = 1.0f;

            if (Character.Controlled != null)
            {
                AnimController animController = Character.Controlled.AnimController;
                if (animController.HeadInWater)
                {
                    ambienceVolume  = 1.0f;
                    ambienceVolume += animController.Limbs[0].LinearVelocity.Length();

                    lowpassHFGain = 0.2f;
                }

                lowpassHFGain *= Character.Controlled.LowPassMultiplier;
            }

            //how fast the sub is moving, scaled to 0.0 -> 1.0
            float movementSoundVolume = 0.0f;

            foreach (Submarine sub in Submarine.Loaded)
            {
                float movementFactor = (sub.Velocity == Vector2.Zero) ? 0.0f : sub.Velocity.Length() / 10.0f;
                movementFactor = MathHelper.Clamp(movementFactor, 0.0f, 1.0f);

                if (Character.Controlled == null || Character.Controlled.Submarine != sub)
                {
                    float dist = Vector2.Distance(GameMain.GameScreen.Cam.WorldViewCenter, sub.WorldPosition);
                    movementFactor = movementFactor / Math.Max(dist / 1000.0f, 1.0f);
                }

                movementSoundVolume = Math.Max(movementSoundVolume, movementFactor);
            }

            if (ambientSoundTimer > 0.0f)
            {
                ambientSoundTimer -= (float)Timing.Step;
            }
            else
            {
                PlaySound(
                    "ambient",
                    Rand.Range(0.5f, 1.0f),
                    1000.0f,
                    new Vector2(Sound.CameraPos.X, Sound.CameraPos.Y) + Rand.Vector(100.0f));

                ambientSoundTimer = Rand.Range(ambientSoundInterval.X, ambientSoundInterval.Y);
            }

            SoundManager.LowPassHFGain = lowpassHFGain;
            waterAmbienceIndexes[0]    = waterAmbiences[0].Loop(waterAmbienceIndexes[0], ambienceVolume * (1.0f - movementSoundVolume));
            waterAmbienceIndexes[1]    = waterAmbiences[1].Loop(waterAmbienceIndexes[1], ambienceVolume * movementSoundVolume);
        }
        private void ReadStatus(NetBuffer msg)
        {
            bool isDead = msg.ReadBoolean();

            if (isDead)
            {
                causeOfDeath = (CauseOfDeath)msg.ReadByte();
                byte severedLimbCount = msg.ReadByte();
                if (!IsDead)
                {
                    if (causeOfDeath == CauseOfDeath.Pressure)
                    {
                        Implode(true);
                    }
                    else
                    {
                        Kill(causeOfDeath, true);
                    }
                }

                for (int i = 0; i < severedLimbCount; i++)
                {
                    int severedJointIndex = msg.ReadByte();
                    AnimController.SeverLimbJoint(AnimController.LimbJoints[severedJointIndex]);
                }
            }
            else
            {
                this.isDead = false;

                health = msg.ReadRangedSingle(minHealth, maxHealth, 8);

                bool lowOxygen = msg.ReadBoolean();
                if (lowOxygen)
                {
                    Oxygen = msg.ReadRangedSingle(-100.0f, 100.0f, 8);
                }
                else
                {
                    Oxygen = 100.0f;
                }

                bool isBleeding = msg.ReadBoolean();
                if (isBleeding)
                {
                    bleeding = msg.ReadRangedSingle(0.0f, 5.0f, 8);
                }
                else
                {
                    bleeding = 0.0f;
                }

                bool stunned = msg.ReadBoolean();
                if (stunned)
                {
                    float newStunTimer = msg.ReadRangedSingle(0.0f, 60.0f, 8);
                    SetStun(newStunTimer, true, true);
                }
                else
                {
                    SetStun(0.0f, true, true);
                }

                bool ragdolled = msg.ReadBoolean();
                IsRagdolled = ragdolled;

                bool huskInfected = msg.ReadBoolean();
                if (huskInfected)
                {
                    HuskInfectionState = Math.Max(HuskInfectionState, 0.01f);
                }
                else
                {
                    HuskInfectionState = 0.0f;
                }
            }
        }
Exemple #10
0
        public virtual void DrawFront(SpriteBatch spriteBatch, Camera cam)
        {
            if (!Enabled)
            {
                return;
            }

            if (GameMain.DebugDraw)
            {
                AnimController.DebugDraw(spriteBatch);

                if (aiTarget != null)
                {
                    aiTarget.Draw(spriteBatch);
                }
            }

            /*if (memPos != null && memPos.Count > 0 && controlled == this)
             * {
             *  PosInfo serverPos = memPos.Last();
             *  Vector2 remoteVec = ConvertUnits.ToDisplayUnits(serverPos.Position);
             *  if (Submarine != null)
             *  {
             *      remoteVec += Submarine.DrawPosition;
             *  }
             *  remoteVec.Y = -remoteVec.Y;
             *
             *  PosInfo localPos = memLocalPos.Find(m => m.ID == serverPos.ID);
             *  int mpind = memLocalPos.FindIndex(lp => lp.ID == localPos.ID);
             *  PosInfo localPos1 = mpind > 0 ? memLocalPos[mpind - 1] : null;
             *  PosInfo localPos2 = mpind < memLocalPos.Count-1 ? memLocalPos[mpind + 1] : null;
             *
             *  Vector2 localVec = ConvertUnits.ToDisplayUnits(localPos.Position);
             *  Vector2 localVec1 = localPos1 != null ? ConvertUnits.ToDisplayUnits(((PosInfo)localPos1).Position) : Vector2.Zero;
             *  Vector2 localVec2 = localPos2 != null ? ConvertUnits.ToDisplayUnits(((PosInfo)localPos2).Position) : Vector2.Zero;
             *  if (Submarine != null)
             *  {
             *      localVec += Submarine.DrawPosition;
             *      localVec1 += Submarine.DrawPosition;
             *      localVec2 += Submarine.DrawPosition;
             *  }
             *  localVec.Y = -localVec.Y;
             *  localVec1.Y = -localVec1.Y;
             *  localVec2.Y = -localVec2.Y;
             *
             *  //GUI.DrawLine(spriteBatch, remoteVec, localVec, Color.Yellow, 0, 10);
             *  if (localPos1 != null) GUI.DrawLine(spriteBatch, remoteVec, localVec1, Color.Lime, 0, 2);
             *  if (localPos2 != null) GUI.DrawLine(spriteBatch, remoteVec + Vector2.One, localVec2 + Vector2.One, Color.Red, 0, 2);
             * }
             *
             * Vector2 mouseDrawPos = CursorWorldPosition;
             * mouseDrawPos.Y = -mouseDrawPos.Y;
             * GUI.DrawLine(spriteBatch, mouseDrawPos - new Vector2(0, 5), mouseDrawPos + new Vector2(0, 5), Color.Red, 0, 10);
             *
             * Vector2 closestItemPos = closestItem != null ? closestItem.DrawPosition : Vector2.Zero;
             * closestItemPos.Y = -closestItemPos.Y;
             * GUI.DrawLine(spriteBatch, closestItemPos - new Vector2(0, 5), closestItemPos + new Vector2(0, 5), Color.Lime, 0, 10);*/

            if (this == controlled || GUI.DisableHUD)
            {
                return;
            }

            Vector2 pos = DrawPosition;

            pos.Y = -pos.Y;

            if (speechBubbleTimer > 0.0f)
            {
                GUI.SpeechBubbleIcon.Draw(spriteBatch, pos - Vector2.UnitY * 100.0f,
                                          speechBubbleColor * Math.Min(speechBubbleTimer, 1.0f), 0.0f,
                                          Math.Min((float)speechBubbleTimer, 1.0f));
            }

            if (this == controlled)
            {
                return;
            }

            if (info != null)
            {
                Vector2 namePos   = new Vector2(pos.X, pos.Y - 110.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom;
                Color   nameColor = Color.White;

                if (Character.Controlled != null && TeamID != Character.Controlled.TeamID)
                {
                    nameColor = Color.Red;
                }
                GUI.Font.DrawString(spriteBatch, Info.Name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f);
                GUI.Font.DrawString(spriteBatch, Info.Name, namePos, nameColor, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f);

                if (GameMain.DebugDraw)
                {
                    GUI.Font.DrawString(spriteBatch, ID.ToString(), namePos - new Vector2(0.0f, 20.0f), Color.White);
                }
            }

            if (isDead)
            {
                return;
            }

            if (health < maxHealth * 0.98f)
            {
                Vector2 healthBarPos = new Vector2(pos.X - 50, DrawPosition.Y + 100.0f);

                GUI.DrawProgressBar(spriteBatch, healthBarPos, new Vector2(100.0f, 15.0f), health / maxHealth, Color.Lerp(Color.Red, Color.Green, health / maxHealth) * 0.8f);
            }
        }
Exemple #11
0
        public virtual void DrawFront(SpriteBatch spriteBatch, Camera cam)
        {
            if (!Enabled)
            {
                return;
            }

            if (GameMain.DebugDraw)
            {
                AnimController.DebugDraw(spriteBatch);

                if (aiTarget != null)
                {
                    aiTarget.Draw(spriteBatch);
                }
            }

            if (GUI.DisableHUD)
            {
                return;
            }

            Vector2 pos = DrawPosition;

            pos.Y += hudInfoHeight;

            if (CurrentHull != null && DrawPosition.Y > CurrentHull.WorldRect.Y - 130.0f)
            {
                float lowerAmount = DrawPosition.Y - (CurrentHull.WorldRect.Y - 130.0f);
                hudInfoHeight = MathHelper.Lerp(hudInfoHeight, 100.0f - lowerAmount, 0.1f);
                hudInfoHeight = Math.Max(hudInfoHeight, 20.0f);
            }
            else
            {
                hudInfoHeight = MathHelper.Lerp(hudInfoHeight, 100.0f, 0.1f);
            }

            pos.Y = -pos.Y;

            if (speechBubbleTimer > 0.0f)
            {
                GUI.SpeechBubbleIcon.Draw(spriteBatch, pos - Vector2.UnitY * 30,
                                          speechBubbleColor * Math.Min(speechBubbleTimer, 1.0f), 0.0f,
                                          Math.Min(speechBubbleTimer, 1.0f));
            }

            if (this == controlled)
            {
                if (DebugDrawInteract)
                {
                    Vector2 cursorPos = cam.ScreenToWorld(PlayerInput.MousePosition);
                    cursorPos.Y = -cursorPos.Y;
                    foreach (Item item in debugInteractablesAtCursor)
                    {
                        GUI.DrawLine(spriteBatch, cursorPos,
                                     new Vector2(item.DrawPosition.X, -item.DrawPosition.Y), Color.LightGreen, width: 4);
                    }
                    foreach (Item item in debugInteractablesInRange)
                    {
                        GUI.DrawLine(spriteBatch, new Vector2(DrawPosition.X, -DrawPosition.Y),
                                     new Vector2(item.DrawPosition.X, -item.DrawPosition.Y), Color.White * 0.1f, width: 4);
                    }
                    foreach (Pair <Item, float> item in debugInteractablesNearCursor)
                    {
                        GUI.DrawLine(spriteBatch,
                                     cursorPos,
                                     new Vector2(item.First.DrawPosition.X, -item.First.DrawPosition.Y),
                                     ToolBox.GradientLerp(item.Second, Color.Red, Color.Orange, Color.Green), width: 2);
                    }
                }
                return;
            }

            float hoverRange   = 300.0f;
            float fadeOutRange = 200.0f;
            float cursorDist   = Vector2.Distance(WorldPosition, cam.ScreenToWorld(PlayerInput.MousePosition));
            float hudInfoAlpha = MathHelper.Clamp(1.0f - (cursorDist - (hoverRange - fadeOutRange)) / fadeOutRange, 0.2f, 1.0f);

            if (!GUI.DisableCharacterNames && hudInfoVisible && info != null &&
                (controlled == null || this != controlled.focusedCharacter))
            {
                string name = Info.DisplayName;
                if (controlled == null && name != Info.Name)
                {
                    name += " " + TextManager.Get("Disguised");
                }

                Vector2 namePos = new Vector2(pos.X, pos.Y - 10.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(name) * 0.5f / cam.Zoom;

                Vector2 screenSize   = new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
                Vector2 viewportSize = new Vector2(cam.WorldView.Width, cam.WorldView.Height);
                namePos.X -= cam.WorldView.X; namePos.Y += cam.WorldView.Y;
                namePos   *= screenSize / viewportSize;
                namePos.X  = (float)Math.Floor(namePos.X); namePos.Y = (float)Math.Floor(namePos.Y);
                namePos   *= viewportSize / screenSize;
                namePos.X += cam.WorldView.X; namePos.Y -= cam.WorldView.Y;

                Color nameColor = Color.White;
                if (Controlled != null && TeamID != Controlled.TeamID)
                {
                    nameColor = TeamID == TeamType.FriendlyNPC ? Color.SkyBlue : Color.Red;
                }
                GUI.Font.DrawString(spriteBatch, name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f);
                GUI.Font.DrawString(spriteBatch, name, namePos, nameColor * hudInfoAlpha, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f);

                if (GameMain.DebugDraw)
                {
                    GUI.Font.DrawString(spriteBatch, ID.ToString(), namePos - new Vector2(0.0f, 20.0f), Color.White);
                }
            }

            if (IsDead)
            {
                return;
            }

            if (Vitality < MaxVitality * 0.98f && hudInfoVisible)
            {
                Vector2 healthBarPos = new Vector2(pos.X - 50, -pos.Y);
                GUI.DrawProgressBar(spriteBatch, healthBarPos, new Vector2(100.0f, 15.0f),
                                    Vitality / MaxVitality,
                                    Color.Lerp(Color.Red, Color.Green, Vitality / MaxVitality) * 0.8f * hudInfoAlpha,
                                    new Color(0.5f, 0.57f, 0.6f, 1.0f) * hudInfoAlpha);
            }
        }
Exemple #12
0
        public virtual void DrawFront(SpriteBatch spriteBatch, Camera cam)
        {
            if (!Enabled)
            {
                return;
            }

            if (GameMain.DebugDraw)
            {
                AnimController.DebugDraw(spriteBatch);

                if (aiTarget != null)
                {
                    aiTarget.Draw(spriteBatch);
                }
            }

            if (GUI.DisableHUD)
            {
                return;
            }

            Vector2 pos = DrawPosition;

            pos.Y = -pos.Y;

            if (speechBubbleTimer > 0.0f)
            {
                GUI.SpeechBubbleIcon.Draw(spriteBatch, pos - Vector2.UnitY * 100.0f,
                                          speechBubbleColor * Math.Min(speechBubbleTimer, 1.0f), 0.0f,
                                          Math.Min(speechBubbleTimer, 1.0f));
            }

            if (this == controlled)
            {
                return;
            }

            float hoverRange   = 300.0f;
            float fadeOutRange = 200.0f;
            float cursorDist   = Vector2.Distance(WorldPosition, cam.ScreenToWorld(PlayerInput.MousePosition));
            float hudInfoAlpha = MathHelper.Clamp(1.0f - (cursorDist - (hoverRange - fadeOutRange)) / fadeOutRange, 0.2f, 1.0f);

            if (hudInfoVisible && info != null)
            {
                string name = Info.DisplayName;
                if (controlled == null && name != Info.Name)
                {
                    name += " " + TextManager.Get("Disguised");
                }

                Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom;

                Vector2 screenSize   = new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
                Vector2 viewportSize = new Vector2(cam.WorldView.Width, cam.WorldView.Height);
                namePos.X -= cam.WorldView.X; namePos.Y += cam.WorldView.Y;
                namePos   *= screenSize / viewportSize;
                namePos.X  = (float)Math.Floor(namePos.X); namePos.Y = (float)Math.Floor(namePos.Y);
                namePos   *= viewportSize / screenSize;
                namePos.X += cam.WorldView.X; namePos.Y -= cam.WorldView.Y;

                Color nameColor = Color.White;
                if (Controlled != null && TeamID != Controlled.TeamID)
                {
                    nameColor = Color.Red;
                }
                GUI.Font.DrawString(spriteBatch, name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f);
                GUI.Font.DrawString(spriteBatch, name, namePos, nameColor * hudInfoAlpha, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f);

                if (GameMain.DebugDraw)
                {
                    GUI.Font.DrawString(spriteBatch, ID.ToString(), namePos - new Vector2(0.0f, 20.0f), Color.White);
                }
            }

            if (isDead)
            {
                return;
            }

            if (health < maxHealth * 0.98f && hudInfoVisible)
            {
                Vector2 healthBarPos = new Vector2(pos.X - 50, DrawPosition.Y + 100.0f);
                GUI.DrawProgressBar(spriteBatch, healthBarPos, new Vector2(100.0f, 15.0f),
                                    health / maxHealth,
                                    Color.Lerp(Color.Red, Color.Green, health / maxHealth) * 0.8f * hudInfoAlpha,
                                    new Color(0.5f, 0.57f, 0.6f, 1.0f) * hudInfoAlpha);
            }
        }
Exemple #13
0
        public virtual void DrawFront(SpriteBatch spriteBatch, Camera cam)
        {
            if (!Enabled)
            {
                return;
            }

            if (GameMain.DebugDraw)
            {
                AnimController.DebugDraw(spriteBatch);

                if (aiTarget != null)
                {
                    aiTarget.Draw(spriteBatch);
                }
            }

            if (GUI.DisableHUD)
            {
                return;
            }

            Vector2 pos = DrawPosition;

            pos.Y += hudInfoHeight;
            if (!showinghealth)
            {
                pos.Y -= 30f;
            }

            if (CurrentHull != null && DrawPosition.Y > CurrentHull.WorldRect.Y - 120.0f)
            {
                float lowerAmount = DrawPosition.Y - (CurrentHull.WorldRect.Y - 120.0f);
                hudInfoHeight = MathHelper.Lerp(hudInfoHeight, 100.0f - lowerAmount, 0.65f);
                hudInfoHeight = Math.Max(hudInfoHeight, 20.0f);
            }
            else
            {
                hudInfoHeight = MathHelper.Lerp(hudInfoHeight, 100.0f, 0.65f);
            }
            pos.Y = -pos.Y;

            if (speechBubbleTimer > 0.0f)
            {
                GUI.SpeechBubbleIcon.Draw(spriteBatch, pos - Vector2.UnitY * 100.0f,
                                          speechBubbleColor * Math.Min(speechBubbleTimer, 1.0f), 0.0f,
                                          Math.Min(speechBubbleTimer, 1.0f));
            }

            //if (this == controlled) return;

            float hoverRange   = 500.0f;
            float fadeOutRange = 300.0f;
            float cursorDist   = Vector2.Distance(WorldPosition, cam.ScreenToWorld(PlayerInput.MousePosition));
            float hudInfoAlpha = MathHelper.Clamp(1.0f - (cursorDist - (hoverRange - fadeOutRange)) / fadeOutRange, 0.25f, 1.0f);

            //Disable the brightness changes of players names for characterless server hosts
            if (GameMain.Server != null && Character.Controlled == null)
            {
                hudInfoAlpha = 1.0f;
            }

            if (hudInfoVisible && info != null)
            {
                string name = Info.DisplayName;

                if (name != Info.Name)
                {
                    if (GameMain.Client != null &&
                        (GameMain.Client.HasPermission(ClientPermissions.Kick) ||
                         GameMain.Client.HasPermission(ClientPermissions.Ban)))
                    {
                        name += " (" + Info.Name + ")";
                    }
                    else if (GameMain.Server != null)
                    {
                        name += " (" + Info.Name + ")";
                    }
                    else if (controlled == null)
                    {
                        name += " " + TextManager.Get("Disguised");
                    }
                }

                Vector2 namePos = new Vector2(pos.X, pos.Y + 10.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom;

                Vector2 screenSize   = new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
                Vector2 viewportSize = new Vector2(cam.WorldView.Width, cam.WorldView.Height);
                namePos.X -= cam.WorldView.X; namePos.Y += cam.WorldView.Y;
                namePos   *= screenSize / viewportSize;
                namePos.X  = (float)Math.Floor(namePos.X); namePos.Y = (float)Math.Floor(namePos.Y);
                namePos   *= viewportSize / screenSize;
                namePos.X += cam.WorldView.X; namePos.Y -= cam.WorldView.Y;

                Color nameColor = Color.White;

                if (GameMain.NilMod.UseRecolouredNameInfo)
                {
                    if (Character.Controlled == null)
                    {
                        if (TeamID == 0)
                        {
                            if (!isDead)
                            {
                                nameColor = Color.White;
                            }
                            else
                            {
                                nameColor = Color.DarkGray;
                            }
                        }
                        else if (TeamID == 1)
                        {
                            if (!isDead)
                            {
                                nameColor = Color.LightBlue;
                            }
                            else
                            {
                                nameColor = Color.DarkBlue;
                            }
                        }
                        else if (TeamID == 2)
                        {
                            if (!isDead)
                            {
                                nameColor = Color.Red;
                            }
                            else
                            {
                                nameColor = Color.DarkRed;
                            }
                        }

                        //Im not really sure where to put this relative to teams and such so it can simply override all of them.
                        if (HuskInfectionState >= 0.5f || this.SpeciesName.ToLowerInvariant() == "humanhusk")
                        {
                            nameColor = new Color(255, 100, 255, 255);
                        }
                    }
                    else
                    {
                        if (TeamID == Character.Controlled.TeamID)
                        {
                            nameColor = Color.LightBlue;
                            if (IsDead)
                            {
                                nameColor = Color.DarkBlue;
                            }
                        }
                        if (TeamID != Character.Controlled.TeamID)
                        {
                            nameColor = Color.Red;
                            if (IsDead)
                            {
                                nameColor = Color.DarkRed;
                            }
                        }
                    }


                    if (Character.Controlled != null && TeamID != Character.Controlled.TeamID)
                    {
                        nameColor = Color.Red;
                        if (IsDead)
                        {
                            nameColor = Color.DarkRed;
                        }
                    }
                }
                else
                {
                    if (Character.Controlled != null)
                    {
                        if (TeamID != Character.Controlled.TeamID)
                        {
                            nameColor = Color.Red;
                        }
                    }
                }

                GUI.Font.DrawString(spriteBatch, name, namePos + new Vector2(1.0f / cam.Zoom, 1.0f / cam.Zoom), Color.Black, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.001f);
                GUI.Font.DrawString(spriteBatch, name, namePos, nameColor * hudInfoAlpha, 0.0f, Vector2.Zero, 1.0f / cam.Zoom, SpriteEffects.None, 0.0f);

                if (GameMain.DebugDraw)
                {
                    GUI.Font.DrawString(spriteBatch, ID.ToString(), namePos - new Vector2(0.0f, 20.0f), Color.White);
                }
            }

            showinghealth = false;

            if (isDead)
            {
                return;
            }

            if (GameMain.NilMod.UseUpdatedCharHUD)
            {
                if (((health < maxHealth * 0.98f) || oxygen < 95f || bleeding >= 0.05f || (((AnimController.CurrentHull == null) ?
                                                                                            100.0f : Math.Min(AnimController.CurrentHull.LethalPressure, 100.0f)) > 10f && NeedsAir && !Shielded && PressureProtection == 0f) || HuskInfectionState > 0f || Stun > 0f) && hudInfoVisible)
                {
                    showinghealth = true;

                    //Basic Colour
                    Color baseoutlinecolour;
                    //Basic Flash Colour if fine
                    Color FlashColour;
                    //Final Calculated outline colour
                    Color outLineColour;

                    //Negative Colours
                    Color NegativeLow  = new Color(145, 145, 145, 160);
                    Color NegativeHigh = new Color(25, 25, 25, 220);

                    //Health Colours
                    Color HealthPositiveHigh = new Color(0, 255, 0, 15);
                    Color HealthPositiveLow  = new Color(255, 0, 0, 60);
                    //Oxygen Colours
                    Color OxygenPositiveHigh = new Color(0, 255, 255, 15);
                    Color OxygenPositiveLow  = new Color(0, 0, 200, 60);
                    //Stun Colours
                    Color StunPositiveHigh = new Color(235, 135, 45, 100);
                    Color StunPositiveLow  = new Color(204, 119, 34, 30);
                    //Bleeding Colours
                    Color BleedPositiveHigh = new Color(255, 50, 50, 100);
                    Color BleedPositiveLow  = new Color(150, 50, 50, 15);
                    //Pressure Colours
                    Color PressurePositiveHigh = new Color(255, 255, 0, 100);
                    Color PressurePositiveLow  = new Color(125, 125, 0, 15);

                    //Husk Colours
                    Color HuskPositiveHigh = new Color(255, 100, 255, 150);
                    Color HuskPositiveLow  = new Color(125, 30, 125, 15);

                    float pressureFactor = (AnimController.CurrentHull == null) ?
                                           100.0f : Math.Min(AnimController.CurrentHull.LethalPressure, 100.0f);
                    if ((PressureProtection > 0.0f && (WorldPosition.Y > GameMain.NilMod.PlayerCrushDepthOutsideHull || (WorldPosition.Y > GameMain.NilMod.PlayerCrushDepthInHull && CurrentHull != null))) || Shielded)
                    {
                        pressureFactor = 0.0f;
                    }

                    if (IsRemotePlayer || this == Character.Controlled || AIController is HumanAIController)
                    {
                        //A players basic flash if ok
                        baseoutlinecolour = new Color(255, 255, 255, 15);
                        FlashColour       = new Color(220, 220, 220, 15);

                        if (HuskInfectionState >= 0.98f)
                        {
                            FlashColour = new Color(200, 0, 200, 255);
                        }
                        else if (HuskInfectionState > 0.5f)
                        {
                            FlashColour = new Color(85, 0, 85, 150);
                        }
                        else if (HuskInfectionState > 0f)
                        {
                            FlashColour = new Color(50, 0, 120, 50);
                        }
                        else if (pressureFactor > 80f)
                        {
                            FlashColour = new Color(200, 200, 0, 100);
                        }
                        else if (bleeding > 0.45f)
                        {
                            FlashColour = new Color(80, 30, 20, 100);
                        }
                        else if (pressureFactor > 45f)
                        {
                            FlashColour = new Color(200, 200, 0, 100);
                        }
                        else if (health < 0f)
                        {
                            FlashColour = new Color(25, 25, 25, 40);
                        }
                        else if (oxygen < 0f)
                        {
                            FlashColour = new Color(40, 40, 255, 40);
                        }
                        else if (pressureFactor > 5f)
                        {
                            FlashColour = new Color(200, 200, 0, 100);
                        }
                        else if (oxygen < 35f)
                        {
                            FlashColour = new Color(40, 40, 255, 40);
                        }
                        else if (health < 25f)
                        {
                            FlashColour = new Color(25, 25, 25, 40);
                        }
                        else if (oxygen < 70f)
                        {
                            FlashColour = new Color(40, 40, 255, 40);
                        }
                        else if (health < 50f)
                        {
                            FlashColour = new Color(25, 25, 25, 40);
                        }
                        else if (Stun >= 1f)
                        {
                            FlashColour = new Color(5, 5, 5, 80);
                        }

                        if (IsUnconscious || Stun >= 5f)
                        {
                            baseoutlinecolour = new Color(40, 40, 40, 35);
                        }
                    }
                    //Is an AI or well, not controlled by anybody, make their border different
                    else
                    {
                        baseoutlinecolour = new Color(40, 40, 40, 15);
                        FlashColour       = new Color(5, 5, 5, 15);

                        //if (HuskInfectionState >= 2f) FlashColour = new Color(255, 0, 255, 255);
                        //else if (HuskInfectionState > 1f) FlashColour = new Color(200, 0, 200, 150);
                        //else if (HuskInfectionState > 0f) FlashColour = new Color(120, 0, 120, 100);
                        if (pressureFactor > 80f && NeedsAir)
                        {
                            FlashColour = new Color(200, 200, 0, 100);
                        }
                        else if (bleeding > 1f)
                        {
                            FlashColour = new Color(255, 10, 10, 100);
                        }
                        else if (pressureFactor > 45f && NeedsAir)
                        {
                            FlashColour = new Color(200, 200, 0, 100);
                        }
                        else if (Stun >= 1f)
                        {
                            FlashColour = new Color(10, 10, 10, 100);
                        }
                    }

                    if (GameMain.NilMod.CharFlashColourTime >= (NilMod.CharFlashColourRate / 2))
                    {
                        outLineColour = Color.Lerp(baseoutlinecolour, FlashColour, (GameMain.NilMod.CharFlashColourTime - (NilMod.CharFlashColourRate / 2)) / (NilMod.CharFlashColourRate / 2)) * hudInfoAlpha;
                    }
                    else
                    {
                        outLineColour = Color.Lerp(FlashColour, baseoutlinecolour, GameMain.NilMod.CharFlashColourTime / (NilMod.CharFlashColourRate / 2)) * hudInfoAlpha;
                    }



                    //Smooth out the Health bar movement a little c:
                    //if (LastHealthStatusVector == null || LastHealthStatusVector == Vector2.Zero) LastHealthStatusVector = new Vector2(pos.X - 20f, -pos.Y);
                    //if ((LastHealthStatusVector.X + 40f) - DrawPosition.X > 2.0f || (LastHealthStatusVector.X + 40f) - DrawPosition.X < -2.0f || (LastHealthStatusVector.Y - 70f) - pos.Y > 2.0f || (LastHealthStatusVector.Y - 70f) - pos.Y < -2.0f) LastHealthStatusVector = new Vector2(pos.X - 40f, -pos.Y);
                    //Vector2 healthBarPos = LastHealthStatusVector;

                    //Smooth out the Health bar movement a little c:

                    Vector2 namePos = Vector2.Zero;

                    if (info != null)
                    {
                        namePos = new Vector2(pos.X, pos.Y + 10.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom;
                    }


                    Vector2 screenSize   = new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
                    Vector2 viewportSize = new Vector2(cam.WorldView.Width, cam.WorldView.Height);
                    namePos.X -= cam.WorldView.X; namePos.Y += cam.WorldView.Y;
                    namePos   *= screenSize / viewportSize;
                    namePos.X  = (float)Math.Floor(namePos.X); namePos.Y = (float)Math.Floor(namePos.Y);
                    namePos   *= viewportSize / screenSize;
                    namePos.X += cam.WorldView.X; namePos.Y -= cam.WorldView.Y;

                    if (info == null)
                    {
                        if (LastHealthStatusVector == null || LastHealthStatusVector == Vector2.Zero)
                        {
                            LastHealthStatusVector = new Vector2(pos.X - 20f, -pos.Y);
                        }
                        if ((LastHealthStatusVector.X + 40f) - DrawPosition.X > 2.0f || (LastHealthStatusVector.X + 40f) - DrawPosition.X < -2.0f || (LastHealthStatusVector.Y - 70f) - pos.Y > 2.0f || (LastHealthStatusVector.Y - 70f) - pos.Y < -2.0f)
                        {
                            LastHealthStatusVector = new Vector2(pos.X - 40f, -pos.Y);
                        }
                    }
                    else
                    {
                        if (LastHealthStatusVector == null || LastHealthStatusVector == Vector2.Zero)
                        {
                            LastHealthStatusVector = new Vector2(namePos.X, -namePos.Y);
                        }
                        if ((LastHealthStatusVector.X + 20f) - namePos.X > 2.0f || (LastHealthStatusVector.X + 20f) - namePos.X < -2.0f || (LastHealthStatusVector.Y - 30f) - namePos.Y > 2.0f || (LastHealthStatusVector.Y - 30f) - namePos.Y < -2.0f)
                        {
                            LastHealthStatusVector = new Vector2(namePos.X + 20f, -namePos.Y - 30f);
                        }
                    }

                    Vector2 healthBarPos = LastHealthStatusVector;

                    //GUI.DrawProgressBar(spriteBatch, healthBarPos, new Vector2(100.0f, 10.0f), health / maxHealth, Color.Lerp(Color.Red, Color.Green, health / maxHealth) * 0.8f);

                    //Health Bar (Keep visible)
                    if (Health >= 0f)
                    {
                        if ((NeedsAir && oxygen > 85f) || !NeedsAir)
                        {
                            GUI.DrawProgressBar(spriteBatch, healthBarPos, new Vector2(80.0f, 20.0f), health / maxHealth, Color.Lerp(HealthPositiveLow, HealthPositiveHigh, health / maxHealth) * hudInfoAlpha, outLineColour, 2f, 0, "Left");
                        }
                        else
                        {
                            GUI.DrawProgressBar(spriteBatch, healthBarPos, new Vector2(80.0f, 10.0f), health / maxHealth, Color.Lerp(HealthPositiveLow, HealthPositiveHigh, health / maxHealth) * hudInfoAlpha, outLineColour, 2f, 0, "Left");
                        }
                    }
                    //Health has gone below 0
                    else
                    {
                        if ((NeedsAir && oxygen > 85f) || !NeedsAir)
                        {
                            GUI.DrawProgressBar(spriteBatch, healthBarPos, new Vector2(80.0f, 20.0f), -(health / maxHealth), Color.Lerp(NegativeLow, NegativeHigh, -(health / maxHealth)) * hudInfoAlpha, outLineColour, 2f, 0, "Right");
                        }
                        else
                        {
                            GUI.DrawProgressBar(spriteBatch, healthBarPos, new Vector2(80.0f, 10.0f), -(health / maxHealth), Color.Lerp(NegativeLow, NegativeHigh, -(health / maxHealth)) * hudInfoAlpha, outLineColour, 2f, 0, "Right");
                        }
                    }

                    //Oxygen Bar
                    if (NeedsAir && (oxygen <= 85f && oxygen >= 0f))
                    {
                        GUI.DrawProgressBar(spriteBatch, new Vector2(healthBarPos.X, healthBarPos.Y - 10f), new Vector2(80.0f, 10.0f), oxygen / 100f, Color.Lerp(OxygenPositiveLow, OxygenPositiveHigh, oxygen / 100f) * hudInfoAlpha, outLineColour, 2f, 0f, "Left");
                    }
                    //Oxygen has gone below 0
                    else if (NeedsAir && oxygen < 0f)
                    {
                        GUI.DrawProgressBar(spriteBatch, new Vector2(healthBarPos.X, healthBarPos.Y - 10f), new Vector2(80.0f, 10.0f), -(oxygen / 100f), Color.Lerp(NegativeLow, NegativeHigh, -(oxygen / 100f)) * hudInfoAlpha, outLineColour, 2f, 0f, "Right");
                    }

                    //Stun Bar
                    if (Stun > 1.0f && !IsUnconscious)
                    {
                        GUI.DrawProgressBar(spriteBatch, new Vector2(healthBarPos.X, healthBarPos.Y - 20f), new Vector2(80.0f, 10.0f), Stun / 60f, Color.Lerp(StunPositiveLow, StunPositiveHigh, Stun / 60f) * hudInfoAlpha, outLineColour, 2f, 0f, "Left");
                    }

                    //Bleed Bar
                    if (bleeding > 0.0f)
                    {
                        GUI.DrawProgressBar(spriteBatch, new Vector2(healthBarPos.X, healthBarPos.Y + 10f), new Vector2(40.0f, 10.0f), bleeding / 5f, Color.Lerp(BleedPositiveLow, BleedPositiveHigh, bleeding / 5f) * hudInfoAlpha, outLineColour, 2f, 0f, "Left");
                    }
                    //Pressure Bar
                    if (pressureFactor > 0.0f)
                    {
                        GUI.DrawProgressBar(spriteBatch, new Vector2(healthBarPos.X + 40f, healthBarPos.Y + 10f), new Vector2(40.0f, 10.0f), pressureFactor / 100f, Color.Lerp(PressurePositiveLow, PressurePositiveHigh, pressureFactor / 100f) * hudInfoAlpha, outLineColour, 2f, 0f, "Right");
                    }
                    //Husk Bar
                    if (HuskInfectionState > 0.0f)
                    {
                        GUI.DrawProgressBar(spriteBatch, new Vector2(healthBarPos.X + 80f, healthBarPos.Y + ((pressureFactor > 0.0f) ? 10.0f : 0.0f)), new Vector2(20.0f, (pressureFactor > 0.0f) ? 30.0f : 20.0f), HuskInfectionState, Color.Lerp(HuskPositiveLow, HuskPositiveHigh, HuskInfectionState) * hudInfoAlpha, outLineColour, 2f, 0f, "Bottom");
                    }
                }
            }
            else
            {
                Vector2 healthBarPos = new Vector2(pos.X - 50, DrawPosition.Y + 80.0f);

                GUI.DrawProgressBar(spriteBatch, healthBarPos, new Vector2(100.0f, 15.0f),
                                    health / maxHealth,
                                    Color.Lerp(Color.Red, Color.Green, health / maxHealth) * 0.8f * hudInfoAlpha,
                                    new Color(0.5f, 0.57f, 0.6f, 1.0f) * hudInfoAlpha, 2f, 0f, "Left");
            }
        }
Exemple #14
0
        private void ReadStatus(NetBuffer msg)
        {
            if (GameMain.Server != null)
            {
                DebugConsole.ThrowError("Server attempted to read character status from a networked message");
                return;
            }

            bool isDead = msg.ReadBoolean();

            if (isDead)
            {
                causeOfDeath = (CauseOfDeath)msg.ReadByte();
                byte severedLimbCount = msg.ReadByte();
                if (causeOfDeath == CauseOfDeath.Pressure)
                {
                    Implode(true);
                }
                else
                {
                    Kill(causeOfDeath, true);
                }
                for (int i = 0; i < severedLimbCount; i++)
                {
                    int severedJointIndex = msg.ReadByte();
                    AnimController.SeverLimbJoint(AnimController.LimbJoints[severedJointIndex]);
                }
            }
            else
            {
                health = msg.ReadRangedSingle(minHealth, maxHealth, 8);

                bool lowOxygen = msg.ReadBoolean();
                if (lowOxygen)
                {
                    Oxygen = msg.ReadRangedSingle(-100.0f, 100.0f, 8);
                }
                else
                {
                    Oxygen = 100.0f;
                }

                bool isBleeding = msg.ReadBoolean();
                if (isBleeding)
                {
                    bleeding = msg.ReadRangedSingle(0.0f, 5.0f, 8);
                }
                else
                {
                    bleeding = 0.0f;
                }

                bool stunned = msg.ReadBoolean();
                if (stunned)
                {
                    float newStunTimer = msg.ReadRangedSingle(0.0f, 60.0f, 8);
                    SetStun(newStunTimer, true, true);
                }
                else
                {
                    SetStun(0.0f, true, true);
                }

                bool huskInfected = msg.ReadBoolean();
                if (huskInfected)
                {
                    HuskInfectionState = Math.Max(HuskInfectionState, 0.01f);
                }
                else
                {
                    HuskInfectionState = 0.0f;
                }
            }
        }