2 using Microsoft.Xna.Framework;
10 private float rangeX, rangeY;
12 private Vector2 detectOffset;
14 private float updateTimer;
26 [
Serialize(
false,
IsPropertySaveable.No, description:
"Has the item currently detected movement. Intended to be used by StatusEffect conditionals (setting this value in XML has no effect).")]
47 get {
return rangeX; }
50 rangeX = MathHelper.Clamp(value, 0.0f, 1000.0f);
59 get {
return rangeY; }
62 rangeY = MathHelper.Clamp(value, 0.0f, 1000.0f);
66 [
InGameEditable,
Serialize(
"0,0",
IsPropertySaveable.Yes, description:
"The position to detect the movement at relative to the item. For example, 0,100 would detect movement 100 units above the item.")]
69 get {
return detectOffset; }
73 detectOffset.X = MathHelper.Clamp(value.X, -rangeX, rangeX);
74 detectOffset.Y = MathHelper.Clamp(value.Y, -rangeY, rangeY);
82 Vector2 transformedDetectOffset = detectOffset;
83 if (
item.
FlippedX) { transformedDetectOffset.X = -transformedDetectOffset.X; }
84 if (
item.
FlippedY) { transformedDetectOffset.Y = -transformedDetectOffset.Y; }
85 return transformedDetectOffset;
89 [
Editable(MinValueFloat = 0.1f, MaxValueFloat = 100.0f, DecimalCount = 2),
Serialize(0.1f,
IsPropertySaveable.Yes, description:
"How often the sensor checks if there's something moving near it. Higher values are better for performance.", alwaysUseInstanceValues:
true)]
96 private int maxOutputLength;
97 [
Editable,
Serialize(200,
IsPropertySaveable.No, description:
"The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
100 get {
return maxOutputLength; }
103 maxOutputLength = Math.Max(value, 0);
107 private string output;
111 get {
return output; }
114 if (value ==
null) {
return; }
123 private string falseOutput;
127 get {
return falseOutput; }
130 if (value ==
null) {
return; }
154 : base(
item, element)
170 base.Load(componentElement, usePrefabValues, idRemap, isItemSwap);
182 if (!
string.IsNullOrEmpty(signalOut)) {
item.
SendSignal(
new Signal(signalOut, 1),
"state_out"); }
189 updateTimer -= deltaTime;
190 if (updateTimer > 0.0f) {
return; }
205 Rectangle detectRect =
new Rectangle((
int)(detectPos.X - rangeX), (
int)(detectPos.Y - rangeY), (
int)(rangeX * 2), (
int)(rangeY * 2));
206 float broadRangeX = Math.Max(rangeX * 2, 500);
207 float broadRangeY = Math.Max(rangeY * 2, 500);
214 foreach (var cell
in cells)
221 foreach (var edge
in cell.Edges)
223 Vector2 e1 = edge.Point1 + cell.Translation;
224 Vector2 e2 = edge.Point2 + cell.Translation;
225 if (MathUtils.LineSegmentsIntersect(e1, e2,
new Vector2(detectRect.X, detectRect.Y),
new Vector2(detectRect.Right, detectRect.Y)) ||
226 MathUtils.LineSegmentsIntersect(e1, e2,
new Vector2(detectRect.X, detectRect.Bottom),
new Vector2(detectRect.Right, detectRect.Bottom)) ||
227 MathUtils.LineSegmentsIntersect(e1, e2,
new Vector2(detectRect.X, detectRect.Y),
new Vector2(detectRect.X, detectRect.Bottom)) ||
228 MathUtils.LineSegmentsIntersect(e1, e2,
new Vector2(detectRect.Right, detectRect.Y),
new Vector2(detectRect.Right, detectRect.Bottom)))
249 if (worldBorders.Intersects(detectRect))
260 bool hasTriggers = triggerFromHumans || triggerFromPets || triggerFromMonsters;
261 if (!hasTriggers) {
return; }
268 if (c.
SpawnTime > Timing.TotalTime - 1.0) {
continue; }
271 if (!triggerFromHumans) {
continue; }
275 if (!triggerFromPets) {
continue; }
280 if (!triggerFromMonsters) {
continue; }
308 public override XElement
Save(XElement parentElement)
310 Vector2 prevDetectOffset = detectOffset;
311 XElement element = base.Save(parentElement);
312 detectOffset = prevDetectOffset;
static readonly List< Character > CharacterList
readonly AnimController AnimController
Contains character data that should be editable in the character editor.
static bool CompareGroup(Identifier group1, Identifier group2)
static readonly Identifier HumanGroup
float GetAttributeFloat(string key, float def)
bool GetAttributeBool(string key, bool def)
XAttribute? GetAttribute(string name)
virtual Vector2 WorldPosition
void ResetCachedVisibleSize()
void SendSignal(string signal, string connectionName)
The base class for components holding the different functionalities of the item
void ApplyStatusEffects(ActionType type, float deltaTime, Character character=null, Limb targetLimb=null, Entity useTarget=null, Character user=null, Vector2? worldPosition=null, float afflictionMultiplier=1.0f)
Vector2 TransformedDetectOffset
MotionSensor(Item item, ContentXElement element)
override void Load(ContentXElement componentElement, bool usePrefabValues, IdRemap idRemap, bool isItemSwap)
override void Update(float deltaTime, Camera cam)
override XElement Save(XElement parentElement)
List< VoronoiCell > GetCells(Vector2 worldPos, int searchDepth=2)
override Vector2? WorldPosition
static List< Submarine > Loaded
Rectangle? Borders
Extents of the solid items/structures (ones with a physics body) and hulls
ActionType
ActionTypes define when a StatusEffect is executed.