3 using Microsoft.Xna.Framework;
5 using System.Collections.Generic;
22 private int spriteIndex;
49 Triggers.ForEach(t => t.NeedsNetworkSyncing =
false);
70 return spriteIndex < 0 || prefab.
Sprites.Count == 0 ? null : prefab.Sprites[spriteIndex % prefab.Sprites.Count];
82 public string Name =>
Prefab?.Name ??
"LevelObject (null)";
84 public Dictionary<Identifier, SerializableProperty>
SerializableProperties {
get; } =
new Dictionary<Identifier, SerializableProperty>();
114 Physics.CollisionWall | Physics.CollisionCharacter | Physics.CollisionProjectile :
115 Physics.CollisionWall | Physics.CollisionCharacter;
118 foreach (var triggerElement
in prefab.LevelTriggerElements)
120 Triggers ??=
new List<LevelTrigger>();
121 Vector2 triggerPosition = triggerElement.GetAttributeVector2(
"position", Vector2.Zero) * scale;
123 if (rotation != 0.0f)
125 var ca = (float)Math.Cos(rotation);
126 var sa = (float)Math.Sin(rotation);
128 triggerPosition =
new Vector2(
129 ca * triggerPosition.X + sa * triggerPosition.Y,
130 -sa * triggerPosition.X + ca * triggerPosition.Y);
133 var newTrigger =
new LevelTrigger(triggerElement,
new Vector2(position.X, position.Y) + triggerPosition, -rotation, scale, prefab.Name);
134 if (newTrigger.PhysicsBody !=
null)
136 newTrigger.PhysicsBody.UserData =
this;
138 int parentTriggerIndex = prefab.LevelTriggerElements.IndexOf(triggerElement.Parent);
139 if (parentTriggerIndex > -1) { newTrigger.ParentTrigger =
Triggers[parentTriggerIndex]; }
143 if (spriteIndex == -1)
145 foreach (var overrideProperties
in prefab.OverrideProperties)
147 if (overrideProperties ==
null) {
continue; }
148 if (overrideProperties.Sprites.Count > 0)
150 spriteIndex = Rand.Int(overrideProperties.Sprites.Count, Rand.RandSync.ServerAndClient);
161 partial
void InitProjSpecific();
168 if (
Prefab.TakeLevelWallDamage)
172 damage = Math.Max(
Health, damage);
177 public void AddDamage(
float damage,
float deltaTime,
Entity attacker,
bool isNetworkEvent =
false)
179 if (
Health <= 0.0f) {
return; }
184 tookDamage |= !MathUtils.NearlyEqual(damage, 0.0f);
210 public Vector2
LocalToWorld(Vector2 localPosition,
float swingState = 0.0f)
212 Vector2 emitterPos = localPosition *
Scale;
218 var ca = (float)Math.Cos(rot);
219 var sa = (float)Math.Sin(rot);
221 emitterPos =
new Vector2(
222 ca * emitterPos.X + sa * emitterPos.Y,
223 -sa * emitterPos.X + ca * emitterPos.Y);
230 RemoveProjSpecific();
233 partial
void RemoveProjSpecific();
243 if (
Prefab.TakeLevelWallDamage)
247 for (
int j = 0; j <
Triggers.Count; j++)
249 if (!
Triggers[j].UseNetworkSyncing) {
continue; }
Attacks are used to deal damage to characters, structures and items. They can be defined in the weapo...
float GetLevelWallDamage(float deltaTime)
static NetworkMember NetworkMember
static GameSession GameSession
LevelObjectManager LevelObjectManager
void AddDamage(float damage, float deltaTime, Entity attacker, bool isNetworkEvent=false)
readonly LevelObjectPrefab Prefab
LevelObject(LevelObjectPrefab prefab, Vector3 position, float scale, float rotation=0.0f)
override string ToString()
void ServerWrite(IWriteMessage msg, Client c)
Dictionary< Identifier, SerializableProperty > SerializableProperties
LevelObjectPrefab ActivePrefab
List< LevelTrigger > Triggers
AttackResult AddDamage(Character attacker, Vector2 worldPosition, Attack attack, Vector2 impulseDirection, float deltaTime, bool playSound=true)
Vector2 LocalToWorld(Vector2 localPosition, float swingState=0.0f)
XElement PhysicsBodyElement
Dictionary< Sprite, XElement > SpriteSpecificPhysicsBodyElements
IEnumerable< StatusEffect > StatusEffects
Category CollisionCategories
bool SetTransformIgnoreContacts(Vector2 simPosition, float rotation, bool setPrevTransform=true)
StatusEffects can be used to execute various kinds of effects: modifying the state of some entity in ...
virtual void Apply(ActionType type, float deltaTime, Entity entity, ISerializableEntity target, Vector2? worldPosition=null)
void WriteRangedSingle(Single val, Single min, Single max, int bitCount)
ActionType
ActionTypes define when a StatusEffect is executed.