3 using Microsoft.Xna.Framework;
5 using System.Collections.Generic;
10 partial class Projectile : ItemComponent
12 private readonly List<ParticleEmitter> particleEmitters =
new List<ParticleEmitter>();
27 Shoot(
User, simPosition, simPosition, rotation, ignoredBodies:
User.
AnimController.
Limbs.Where(l => !l.IsSevered).Select(l => l.body.FarseerBody).ToList(), createNetworkEvent:
false);
32 Launch(
User, simPosition, rotation);
41 Vector2 simPosition =
new Vector2(
44 Vector2 axis =
new Vector2(
47 StickTargetType targetType = (StickTargetType)msg.
ReadByte();
57 case StickTargetType.Structure:
62 if (bodyIndex == 255) { bodyIndex = 0; }
63 if (bodyIndex >= structure.Bodies.Count)
65 DebugConsole.ThrowError($
"Failed to read a projectile update from the server. Structure body index out of bounds ({bodyIndex}, structure: {structure})");
68 var body = structure.Bodies[bodyIndex];
69 StickToTarget(body, axis);
73 DebugConsole.AddWarning($
"\"{item.Prefab.Identifier}\" failed to stick to a structure. Could not find a structure with the ID {structureId}");
76 case StickTargetType.Limb:
81 if (limbIndex >= character.AnimController.Limbs.Length)
83 DebugConsole.ThrowError($
"Failed to read a projectile update from the server. Limb index out of bounds ({limbIndex}, character: {character})");
86 if (character.Removed) {
return; }
87 var limb = character.AnimController.Limbs[limbIndex];
88 StickToTarget(limb.body.FarseerBody, axis);
92 DebugConsole.AddWarning($
"\"{this.item.Prefab.Identifier}\" failed to stick to a limb. Could not find a character with the ID {characterId}");
95 case StickTargetType.Item:
99 if (targetItem.Removed) {
return; }
100 var door = targetItem.GetComponent<
Door>();
103 StickToTarget(door.Body.FarseerBody, axis);
105 else if (targetItem.body !=
null)
107 StickToTarget(targetItem.body.FarseerBody, axis);
112 DebugConsole.AddWarning($
"\"{this.item.Prefab.Identifier}\" failed to stick to an item. Could not find n item with the ID {itemID}");
115 case StickTargetType.Submarine:
119 StickToTarget(targetSub.PhysicsBody.FarseerBody, axis);
123 DebugConsole.AddWarning($
"\"{item.Prefab.Identifier}\" failed to stick to a submarine. Could not find a structure with the ID {targetSubmarineId}");
126 case StickTargetType.LevelWall:
129 if (levelWallIndex >= 0 && levelWallIndex < allCells.Count)
131 StickToTarget(allCells[levelWallIndex].Body, axis);
135 DebugConsole.ThrowError($
"Failed to read a projectile update from the server. Level wall index out of bounds ({levelWallIndex}, wall count: {allCells.Count})");
146 partial
void LaunchProjSpecific(Vector2 startLocation, Vector2 endLocation)
150 if (
item.
body.
Dir < 0.0f) { rotation += MathHelper.Pi; }
153 particlePos = ConvertToWorldCoordinates(particlePos);
155 startLocation = ConvertToWorldCoordinates(startLocation);
157 endLocation = ConvertToWorldCoordinates(endLocation);
159 Tuple<Vector2, Vector2> tracerPoints =
new Tuple<Vector2, Vector2>(startLocation, endLocation);
162 emitter.
Emit(1.0f, particlePos, hullGuess:
null, angle: rotation, particleRotation: rotation, colorMultiplier: emitter.
Prefab.
Properties.
ColorMultiplier, tracerPoints: tracerPoints);
165 static Vector2 ConvertToWorldCoordinates(Vector2 position)
168 if (containing !=
null)
176 partial
void InitProjSpecific(ContentXElement element)
178 foreach (var subElement
in element.Elements())
180 switch (subElement.Name.ToString().ToLowerInvariant())
182 case "particleemitter":
readonly AnimController AnimController
static Entity FindEntityByID(ushort ID)
Find an entity based on the ID
void Shoot(Character user, Vector2 weaponPos, Vector2 spawnPos, float rotation, List< Body > ignoredBodies, bool createNetworkEvent, float damageMultiplier=1f, float launchImpulseModifier=0f)
void ClientEventRead(IReadMessage msg, float sendingTime)
List< VoronoiCell > GetAllCells()
readonly ParticleEmitterPrefab Prefab
void Emit(float deltaTime, Vector2 position, Hull? hullGuess=null, float angle=0.0f, float particleRotation=0.0f, float velocityMultiplier=1.0f, float sizeMultiplier=1.0f, float amountMultiplier=1.0f, Color? colorMultiplier=null, ParticlePrefab? overrideParticle=null, bool mirrorAngle=false, Tuple< Vector2, Vector2 >? tracerPoints=null)
readonly ParticleEmitterProperties Properties
bool SetTransform(Vector2 simPosition, float rotation, bool setPrevTransform=true)
static Submarine FindContainingInLocalCoordinates(Vector2 position, float inflate=500.0f)
Finds the sub whose borders contain the position. Note that this method uses the "actual" position of...
override Vector2? Position