Exemplo n.º 1
0
        public static float GetGarbleAmount(Entity listener, Entity sender, float range, float obstructionmult = 2.0f)
        {
            if (listener == null || sender == null)
            {
                return(0.0f);
            }
            if (listener.WorldPosition == sender.WorldPosition)
            {
                return(0.0f);
            }

            float dist = Vector2.Distance(listener.WorldPosition, sender.WorldPosition);

            if (dist > range)
            {
                return(1.0f);
            }

            Hull listenerHull = listener == null ? null : Hull.FindHull(listener.WorldPosition);
            Hull sourceHull   = sender == null ? null : Hull.FindHull(sender.WorldPosition);

            if (sourceHull != listenerHull)
            {
                if (Submarine.CheckVisibility(listener.SimPosition, sender.SimPosition) != null)
                {
                    dist = (dist + 100f) * obstructionmult;
                }
            }
            if (dist > range)
            {
                return(1.0f);
            }

            return(dist / range);
        }
Exemplo n.º 2
0
        public override void Update(float deltaTime, Camera cam)
        {
            base.Update(deltaTime, cam);

            Entity refEntity = equipper;

            if (isEquippable)
            {
                if (equipper == null || equipper.Removed)
                {
                    IsActive = false;
                    return;
                }
            }
            else
            {
                refEntity = item;
            }

            thermalEffectState += deltaTime;
            thermalEffectState %= 10000.0f;

            if (updateTimer > 0.0f)
            {
                updateTimer -= deltaTime;
                return;
            }

            visibleCharacters.Clear();
            foreach (Character c in Character.CharacterList)
            {
                if (c == equipper || !c.Enabled || c.Removed)
                {
                    continue;
                }
                if (!ShowDeadCharacters && c.IsDead)
                {
                    continue;
                }

                float dist = Vector2.DistanceSquared(refEntity.WorldPosition, c.WorldPosition);
                if (dist < Range * Range)
                {
                    Vector2 diff = c.WorldPosition - refEntity.WorldPosition;
                    if (Submarine.CheckVisibility(refEntity.SimPosition, refEntity.SimPosition + ConvertUnits.ToSimUnits(diff)) == null)
                    {
                        visibleCharacters.Add(c);
                    }
                }
            }

            updateTimer = UpdateInterval;
        }
Exemplo n.º 3
0
        public static string ApplyDistanceEffect(Entity listener, Entity Sender, string text, float range, float obstructionmult = 2.0f)
        {
            if (listener.WorldPosition == Sender.WorldPosition)
            {
                return(text);
            }

            float dist = Vector2.Distance(listener.WorldPosition, Sender.WorldPosition);

            if (dist > range)
            {
                return("");
            }

            if (Submarine.CheckVisibility(listener.SimPosition, Sender.SimPosition) != null)
            {
                dist = (dist + 100f) * obstructionmult;
            }
            if (dist > range)
            {
                return("");
            }

            float garbleAmount = dist / range;

            if (garbleAmount < 0.3f)
            {
                return(text);
            }

            int startIndex = Math.Max(text.IndexOf(':') + 1, 1);

            StringBuilder sb = new StringBuilder(text.Length);

            for (int i = 0; i < text.Length; i++)
            {
                sb.Append((i > startIndex && Rand.Range(0.0f, 1.0f) < garbleAmount) ? '-' : text[i]);
            }

            return(sb.ToString());
        }
Exemplo n.º 4
0
        public override void Update(float deltaTime, Camera cam)
        {
            base.Update(deltaTime, cam);

            if (equipper == null || equipper.Removed)
            {
                IsActive = false;
                return;
            }

            if (updateTimer > 0.0f)
            {
                updateTimer -= deltaTime;
                return;
            }

            visibleCharacters.Clear();
            foreach (Character c in Character.CharacterList)
            {
                if (c == equipper || !c.Enabled || c.Removed)
                {
                    continue;
                }

                float dist = Vector2.DistanceSquared(equipper.WorldPosition, c.WorldPosition);
                if (dist < Range * Range)
                {
                    Vector2 diff = c.WorldPosition - equipper.WorldPosition;
                    if (Submarine.CheckVisibility(equipper.SimPosition, equipper.SimPosition + ConvertUnits.ToSimUnits(diff)) == null)
                    {
                        visibleCharacters.Add(c);
                    }
                }
            }

            updateTimer = UpdateInterval;
        }
Exemplo n.º 5
0
        public static float GetGarbleAmount(Entity listener, Entity sender, float range, float obstructionmult = 2.0f)
        {
            if (listener == null || sender == null)
            {
                return(0.0f);
            }
            if (listener.WorldPosition == sender.WorldPosition)
            {
                return(0.0f);
            }

            float dist = Vector2.Distance(listener.WorldPosition, sender.WorldPosition);

            if (dist > range)
            {
                return(1.0f);
            }

            Hull listenerHull = listener == null ? null : Hull.FindHull(listener.WorldPosition);
            Hull sourceHull   = sender == null ? null : Hull.FindHull(sender.WorldPosition);

            if (sourceHull != listenerHull)
            {
                if ((sourceHull == null || !sourceHull.GetConnectedHulls(includingThis: false, searchDepth: 2, ignoreClosedGaps: true).Contains(listenerHull)) &&
                    Submarine.CheckVisibility(listener.SimPosition, sender.SimPosition) != null)
                {
                    dist = (dist + 100f) * obstructionmult;
                }
            }
            if (dist > range)
            {
                return(1.0f);
            }

            return(dist / range);
        }
        private Item?ScanForTargets(VineTile branch)
        {
            Hull    parent   = Behavior.Parent;
            Vector2 worldPos = Behavior.GetWorldPosition() + branch.Position;
            Vector2 pos      = parent.Position + Behavior.Offset + branch.Position;

            Vector2 diameter    = ConvertUnits.ToSimUnits(new Vector2(branch.Rect.Width / 2f, branch.Rect.Height / 2f));
            Vector2 topLeft     = ConvertUnits.ToSimUnits(pos) - diameter;
            Vector2 bottomRight = ConvertUnits.ToSimUnits(pos) + diameter;

            int  highestPriority = 0;
            Item?currentItem     = null;

            foreach (Item item in Item.ItemList.Where(it => !Behavior.ClaimedTargets.Contains(it)))
            {
                if (Behavior.IgnoredTargets.ContainsKey(item))
                {
                    continue;
                }

                int priority = 0;
                foreach (BallastFloraBehavior.AITarget target in Behavior.Targets)
                {
                    if (!target.Matches(item) || target.Priority <= highestPriority)
                    {
                        continue;
                    }
                    priority = target.Priority;
                    break;
                }

                if (priority == 0)
                {
                    continue;
                }

                if (item.Submarine != parent.Submarine || Vector2.Distance(worldPos, item.WorldPosition) > Behavior.Sight)
                {
                    continue;
                }

                Vector2 itemSimPos = ConvertUnits.ToSimUnits(item.Position);

#if DEBUG || UNSTABLE
                Tuple <Vector2, Vector2> debugLine1 = Tuple.Create(parent.Position - ConvertUnits.ToDisplayUnits(topLeft), parent.Position - ConvertUnits.ToDisplayUnits(itemSimPos - diameter));
                Tuple <Vector2, Vector2> debugLine2 = Tuple.Create(parent.Position - ConvertUnits.ToDisplayUnits(bottomRight), parent.Position - ConvertUnits.ToDisplayUnits(itemSimPos + diameter));
                Behavior.debugSearchLines.Add(debugLine2);
                Behavior.debugSearchLines.Add(debugLine1);
#endif

                Body?body1 = Submarine.CheckVisibility(itemSimPos - diameter, topLeft);
                if (Blocks(body1, item))
                {
                    continue;
                }

                Body?body2 = Submarine.CheckVisibility(itemSimPos + diameter, bottomRight);
                if (Blocks(body2, item))
                {
                    continue;
                }

                highestPriority = priority;
                currentItem     = item;
            }

            if (currentItem != null)
            {
                foreach (BallastFloraBranch existingBranch in Behavior.Branches)
                {
                    if (Behavior.BranchContainsTarget(existingBranch, currentItem))
                    {
                        Behavior.ClaimTarget(currentItem, existingBranch);
                        return(null);
                    }
                }

                return(currentItem);
            }

            return(null);