38f1ddb...178a853: v0.8.9.1, removed content folder
This commit is contained in:
@@ -4,6 +4,7 @@ using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
@@ -12,23 +13,29 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class Turret : Powered, IDrawableComponent, IServerSerializable
|
||||
{
|
||||
Sprite barrelSprite;
|
||||
private Sprite barrelSprite, railSprite;
|
||||
|
||||
Vector2 barrelPos;
|
||||
private Vector2 barrelPos;
|
||||
private Vector2 transformedBarrelPos;
|
||||
|
||||
bool? hasLight;
|
||||
LightComponent lightComponent;
|
||||
private LightComponent lightComponent;
|
||||
|
||||
private float rotation, targetRotation;
|
||||
|
||||
float rotation, targetRotation;
|
||||
private float reload, reloadTime;
|
||||
|
||||
float reload, reloadTime;
|
||||
private float minRotation, maxRotation;
|
||||
|
||||
float minRotation, maxRotation;
|
||||
private float launchImpulse;
|
||||
|
||||
float launchImpulse;
|
||||
private Camera cam;
|
||||
|
||||
Camera cam;
|
||||
private float angularVelocity;
|
||||
|
||||
private int failedLaunchAttempts;
|
||||
|
||||
private Character user;
|
||||
|
||||
[Serialize("0,0", false)]
|
||||
public Vector2 BarrelPos
|
||||
{
|
||||
@@ -36,9 +43,18 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
return barrelPos;
|
||||
}
|
||||
set
|
||||
set
|
||||
{
|
||||
barrelPos = value;
|
||||
UpdateTransformedBarrelPos();
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 TransformedBarrelPos
|
||||
{
|
||||
get
|
||||
{
|
||||
return transformedBarrelPos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +65,7 @@ namespace Barotrauma.Items.Components
|
||||
set { launchImpulse = value; }
|
||||
}
|
||||
|
||||
[Serialize(5.0f, false)]
|
||||
[Serialize(5.0f, false), Editable(0.0f, 1000.0f)]
|
||||
public float Reload
|
||||
{
|
||||
get { return reloadTime; }
|
||||
@@ -69,6 +85,64 @@ namespace Barotrauma.Items.Components
|
||||
maxRotation = MathHelper.ToRadians(Math.Max(value.X, value.Y));
|
||||
|
||||
rotation = (minRotation + maxRotation) / 2;
|
||||
#if CLIENT
|
||||
if (lightComponent != null)
|
||||
{
|
||||
lightComponent.Rotation = rotation;
|
||||
lightComponent.Light.Rotation = -rotation;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[Serialize(5.0f, false), Editable(0.0f, 1000.0f, DecimalCount = 2)]
|
||||
public float SpringStiffnessLowSkill
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
[Serialize(2.0f, false), Editable(0.0f, 1000.0f, DecimalCount = 2)]
|
||||
public float SpringStiffnessHighSkill
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Serialize(50.0f, false), Editable(0.0f, 1000.0f, DecimalCount = 2)]
|
||||
public float SpringDampingLowSkill
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
[Serialize(10.0f, false), Editable(0.0f, 1000.0f, DecimalCount = 2)]
|
||||
public float SpringDampingHighSkill
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Serialize(1.0f, false), Editable(0.0f, 100.0f, DecimalCount = 2)]
|
||||
public float RotationSpeedLowSkill
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
[Serialize(5.0f, false), Editable(0.0f, 100.0f, DecimalCount = 2)]
|
||||
public float RotationSpeedHighSkill
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private float baseRotationRad;
|
||||
[Serialize(0.0f, true), Editable(0.0f, 360.0f)]
|
||||
public float BaseRotation
|
||||
{
|
||||
get { return MathHelper.ToDegrees(baseRotationRad); }
|
||||
set
|
||||
{
|
||||
baseRotationRad = MathHelper.ToRadians(value);
|
||||
UpdateTransformedBarrelPos();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,51 +150,62 @@ namespace Barotrauma.Items.Components
|
||||
: base(item, element)
|
||||
{
|
||||
IsActive = true;
|
||||
|
||||
string barrelSpritePath = element.GetAttributeString("barrelsprite", "");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(barrelSpritePath))
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (!barrelSpritePath.Contains("/"))
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
barrelSpritePath = Path.Combine(Path.GetDirectoryName(item.Prefab.ConfigFile), barrelSpritePath);
|
||||
case "barrelsprite":
|
||||
barrelSprite = new Sprite(subElement);
|
||||
break;
|
||||
case "railsprite":
|
||||
railSprite = new Sprite(subElement);
|
||||
break;
|
||||
}
|
||||
|
||||
barrelSprite = new Sprite(
|
||||
barrelSpritePath,
|
||||
element.GetAttributeVector2("origin", Vector2.Zero));
|
||||
}
|
||||
|
||||
hasLight = null;
|
||||
|
||||
|
||||
InitProjSpecific(element);
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(XElement element);
|
||||
|
||||
private void UpdateTransformedBarrelPos()
|
||||
{
|
||||
float flippedRotation = BaseRotation;
|
||||
if (item.FlippedX) flippedRotation = -flippedRotation;
|
||||
//if (item.FlippedY) flippedRotation = 180.0f - flippedRotation;
|
||||
transformedBarrelPos = MathUtils.RotatePointAroundTarget(barrelPos * item.Scale, new Vector2(item.Rect.Width / 2, item.Rect.Height / 2), flippedRotation);
|
||||
#if CLIENT
|
||||
item.SpriteRotation = MathHelper.ToRadians(flippedRotation);
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void OnItemLoaded()
|
||||
{
|
||||
var lightComponents = item.GetComponents<LightComponent>();
|
||||
if (lightComponents != null && lightComponents.Count() > 0)
|
||||
{
|
||||
lightComponent = lightComponents.FirstOrDefault(lc => lc.Parent == this);
|
||||
#if CLIENT
|
||||
if (lightComponent != null)
|
||||
{
|
||||
lightComponent.Rotation = rotation;
|
||||
lightComponent.Light.Rotation = -rotation;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
if (hasLight == null)
|
||||
{
|
||||
List<LightComponent> lightComponents = item.GetComponents<LightComponent>();
|
||||
|
||||
if (lightComponents != null && lightComponents.Count>0)
|
||||
{
|
||||
lightComponent = lightComponents.Find(lc => lc.Parent == this);
|
||||
hasLight = (lightComponent != null);
|
||||
}
|
||||
else
|
||||
{
|
||||
hasLight = false;
|
||||
}
|
||||
}
|
||||
|
||||
this.cam = cam;
|
||||
|
||||
if (reload > 0.0f) reload -= deltaTime;
|
||||
|
||||
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
|
||||
|
||||
UpdateProjSpecific(deltaTime);
|
||||
|
||||
if (minRotation == maxRotation) return;
|
||||
|
||||
float targetMidDiff = MathHelper.WrapAngle(targetRotation - (minRotation + maxRotation) / 2.0f);
|
||||
@@ -132,47 +217,94 @@ namespace Barotrauma.Items.Components
|
||||
targetRotation = (targetMidDiff < 0.0f) ? minRotation : maxRotation;
|
||||
}
|
||||
|
||||
float deltaRotation = MathHelper.WrapAngle(targetRotation-rotation);
|
||||
deltaRotation = MathHelper.Clamp(deltaRotation, -0.5f, 0.5f) * 5.0f;
|
||||
float degreeOfSuccess = user == null ? 0.5f : DegreeOfSuccess(user);
|
||||
if (degreeOfSuccess < 0.5f) degreeOfSuccess *= degreeOfSuccess; //the ease of aiming drops quickly with insufficient skill levels
|
||||
float springStiffness = MathHelper.Lerp(SpringStiffnessLowSkill, SpringStiffnessHighSkill, degreeOfSuccess);
|
||||
float springDamping = MathHelper.Lerp(SpringDampingLowSkill, SpringDampingHighSkill, degreeOfSuccess);
|
||||
float rotationSpeed = MathHelper.Lerp(RotationSpeedLowSkill, RotationSpeedHighSkill, degreeOfSuccess);
|
||||
|
||||
rotation += deltaRotation * deltaTime;
|
||||
angularVelocity +=
|
||||
(MathHelper.WrapAngle(targetRotation - rotation) * springStiffness - angularVelocity * springDamping) * deltaTime;
|
||||
angularVelocity = MathHelper.Clamp(angularVelocity, -rotationSpeed, rotationSpeed);
|
||||
|
||||
rotation += angularVelocity * deltaTime;
|
||||
|
||||
float rotMidDiff = MathHelper.WrapAngle(rotation - (minRotation + maxRotation) / 2.0f);
|
||||
|
||||
if (rotMidDiff < -maxDist)
|
||||
{
|
||||
rotation = minRotation;
|
||||
angularVelocity *= -0.5f;
|
||||
}
|
||||
else if (rotMidDiff > maxDist)
|
||||
{
|
||||
rotation = maxRotation;
|
||||
angularVelocity *= -0.5f;
|
||||
}
|
||||
|
||||
if ((bool)hasLight)
|
||||
if (lightComponent != null)
|
||||
{
|
||||
lightComponent.Rotation = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
partial void UpdateProjSpecific(float deltaTime);
|
||||
|
||||
public override bool Use(float deltaTime, Character character = null)
|
||||
{
|
||||
if (!characterUsable && character != null) return false;
|
||||
return TryLaunch(character);
|
||||
return TryLaunch(deltaTime, character);
|
||||
}
|
||||
|
||||
private bool TryLaunch(Character character = null)
|
||||
private bool TryLaunch(float deltaTime, Character character = null)
|
||||
{
|
||||
if (GameMain.Client != null) return false;
|
||||
|
||||
if (reload > 0.0f) return false;
|
||||
|
||||
var projectiles = GetLoadedProjectiles(true);
|
||||
if (projectiles.Count == 0) return false;
|
||||
if (GetAvailablePower() < powerConsumption)
|
||||
{
|
||||
#if CLIENT
|
||||
if (!flashLowPower && character != null && character == Character.Controlled)
|
||||
{
|
||||
flashLowPower = true;
|
||||
GUI.PlayUISound(GUISoundType.PickItemFail);
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (MapEntity e in item.linkedTo)
|
||||
{
|
||||
//use linked projectile containers in case they have to react to the turret being launched somehow
|
||||
//(play a sound, spawn more projectiles)
|
||||
Item linkedItem = e as Item;
|
||||
if (linkedItem == null) continue;
|
||||
ItemContainer projectileContainer = linkedItem.GetComponent<ItemContainer>();
|
||||
if (projectileContainer != null) linkedItem.Use(deltaTime, null);
|
||||
}
|
||||
|
||||
if (GetAvailablePower() < powerConsumption) return false;
|
||||
var projectiles = GetLoadedProjectiles(true);
|
||||
if (projectiles.Count == 0)
|
||||
{
|
||||
//coilguns spawns ammo in the ammo boxes with the OnUse statuseffect when the turret is launched,
|
||||
//causing a one frame delay before the gun can be launched (or more in multiplayer where there may be a longer delay)
|
||||
// -> attempt to launch the gun multiple times before showing the "no ammo" flash
|
||||
failedLaunchAttempts++;
|
||||
#if CLIENT
|
||||
if (!flashNoAmmo && character != null && character == Character.Controlled && failedLaunchAttempts > 20)
|
||||
{
|
||||
flashNoAmmo = true;
|
||||
failedLaunchAttempts = 0;
|
||||
GUI.PlayUISound(GUISoundType.PickItemFail);
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
failedLaunchAttempts = 0;
|
||||
|
||||
var batteries = item.GetConnectedComponents<PowerContainer>();
|
||||
|
||||
float availablePower = 0.0f;
|
||||
foreach (PowerContainer battery in batteries)
|
||||
{
|
||||
@@ -215,14 +347,10 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
projectile.body.ResetDynamics();
|
||||
projectile.body.Enabled = true;
|
||||
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y)), -rotation);
|
||||
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.WorldRect.X + transformedBarrelPos.X, item.WorldRect.Y - transformedBarrelPos.Y)), -rotation);
|
||||
projectile.FindHull();
|
||||
projectile.Submarine = projectile.body.Submarine;
|
||||
|
||||
LaunchProjSpecific();
|
||||
|
||||
ApplyStatusEffects(ActionType.OnUse, 1.0f, user);
|
||||
|
||||
Projectile projectileComponent = projectile.GetComponent<Projectile>();
|
||||
if (projectileComponent != null)
|
||||
{
|
||||
@@ -236,34 +364,23 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ComponentState, item.components.IndexOf(this), projectile });
|
||||
}
|
||||
|
||||
ApplyStatusEffects(ActionType.OnUse, 1.0f, user: user);
|
||||
LaunchProjSpecific();
|
||||
}
|
||||
|
||||
partial void LaunchProjSpecific();
|
||||
|
||||
public override bool AIOperate(float deltaTime, Character character, AIObjectiveOperateItem objective)
|
||||
{
|
||||
var projectiles = GetLoadedProjectiles();
|
||||
|
||||
if (projectiles.Count == 0 || (projectiles.Count == 1 && objective.Option.ToLowerInvariant() != "fire at will"))
|
||||
if (character.AIController.SelectedAiTarget?.Entity is Character previousTarget &&
|
||||
previousTarget.IsDead)
|
||||
{
|
||||
ItemContainer container = null;
|
||||
foreach (MapEntity e in item.linkedTo)
|
||||
{
|
||||
var containerItem = e as Item;
|
||||
if (containerItem == null) continue;
|
||||
|
||||
container = containerItem.GetComponent<ItemContainer>();
|
||||
if (container != null) break;
|
||||
}
|
||||
|
||||
if (container == null || container.ContainableItems.Count==0) return true;
|
||||
|
||||
var containShellObjective = new AIObjectiveContainItem(character, container.ContainableItems[0].Names[0], container);
|
||||
containShellObjective.IgnoreAlreadyContainedItems = true;
|
||||
objective.AddSubObjective(containShellObjective);
|
||||
return false;
|
||||
character?.Speak(TextManager.Get("DialogTurretTargetDead"), null, 0.0f, "killedtarget" + previousTarget.ID, 30.0f);
|
||||
character.AIController.SelectTarget(null);
|
||||
}
|
||||
else if (GetAvailablePower() < powerConsumption)
|
||||
|
||||
if (GetAvailablePower() < powerConsumption)
|
||||
{
|
||||
var batteries = item.GetConnectedComponents<PowerContainer>();
|
||||
|
||||
@@ -275,27 +392,65 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
batteryToLoad = battery;
|
||||
lowestCharge = battery.Charge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (batteryToLoad == null) return true;
|
||||
|
||||
if (batteryToLoad.RechargeSpeed < batteryToLoad.MaxRechargeSpeed * 0.4f)
|
||||
{
|
||||
objective.AddSubObjective(new AIObjectiveOperateItem(batteryToLoad, character, "", false));
|
||||
objective.AddSubObjective(new AIObjectiveOperateItem(batteryToLoad, character, "", false));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int projectileCount = 0;
|
||||
int maxProjectileCount = 0;
|
||||
foreach (MapEntity e in item.linkedTo)
|
||||
{
|
||||
var projectileContainer = e as Item;
|
||||
if (projectileContainer == null) continue;
|
||||
|
||||
var containedItems = projectileContainer.ContainedItems;
|
||||
if (containedItems != null)
|
||||
{
|
||||
var container = projectileContainer.GetComponent<ItemContainer>();
|
||||
if (containedItems != null) maxProjectileCount += container.Capacity;
|
||||
projectileCount += containedItems.Length;
|
||||
}
|
||||
}
|
||||
|
||||
if (projectileCount == 0 || (projectileCount < maxProjectileCount && objective.Option.ToLowerInvariant() != "fireatwill"))
|
||||
{
|
||||
ItemContainer container = null;
|
||||
foreach (MapEntity e in item.linkedTo)
|
||||
{
|
||||
var containerItem = e as Item;
|
||||
if (containerItem == null) continue;
|
||||
|
||||
container = containerItem.GetComponent<ItemContainer>();
|
||||
if (container != null) break;
|
||||
}
|
||||
|
||||
if (container == null || container.ContainableItems.Count == 0) return true;
|
||||
|
||||
var containShellObjective = new AIObjectiveContainItem(character, container.ContainableItems[0].Identifiers[0], container);
|
||||
character?.Speak(TextManager.Get("DialogLoadTurret").Replace("[itemname]", item.Name), null, 0.0f, "loadturret", 30.0f);
|
||||
containShellObjective.MinContainedAmount = projectileCount + 1;
|
||||
containShellObjective.IgnoreAlreadyContainedItems = true;
|
||||
objective.AddSubObjective(containShellObjective);
|
||||
return false;
|
||||
}
|
||||
|
||||
//enough shells and power
|
||||
Character closestEnemy = null;
|
||||
float closestDist = 3000.0f;
|
||||
float closestDist = 10000.0f * 10000.0f;
|
||||
foreach (Character enemy in Character.CharacterList)
|
||||
{
|
||||
//ignore humans and characters that are inside the sub
|
||||
if (enemy.IsDead || enemy.SpeciesName == "human" || enemy.AnimController.CurrentHull != null) continue;
|
||||
|
||||
float dist = Vector2.Distance(enemy.WorldPosition, item.WorldPosition);
|
||||
float dist = Vector2.DistanceSquared(enemy.WorldPosition, item.WorldPosition);
|
||||
if (dist < closestDist)
|
||||
{
|
||||
closestEnemy = enemy;
|
||||
@@ -304,20 +459,26 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
if (closestEnemy == null) return false;
|
||||
|
||||
character.AIController.SelectTarget(closestEnemy.AiTarget);
|
||||
|
||||
character.CursorPosition = closestEnemy.WorldPosition;
|
||||
if (item.Submarine!=null) character.CursorPosition -= item.Submarine.Position;
|
||||
if (item.Submarine != null) character.CursorPosition -= item.Submarine.Position;
|
||||
character.SetInput(InputType.Aim, false, true);
|
||||
|
||||
float enemyAngle = MathUtils.VectorToAngle(closestEnemy.WorldPosition-item.WorldPosition);
|
||||
float enemyAngle = MathUtils.VectorToAngle(closestEnemy.WorldPosition - item.WorldPosition);
|
||||
float turretAngle = -rotation;
|
||||
|
||||
if (Math.Abs(MathUtils.GetShortestAngle(enemyAngle, turretAngle)) > 0.01f) return false;
|
||||
if (Math.Abs(MathUtils.GetShortestAngle(enemyAngle, turretAngle)) > 0.1f) return false;
|
||||
|
||||
var pickedBody = Submarine.PickBody(ConvertUnits.ToSimUnits(item.WorldPosition), closestEnemy.SimPosition, null);
|
||||
if (pickedBody != null && !(pickedBody.UserData is Limb)) return false;
|
||||
|
||||
if (objective.Option.ToLowerInvariant() == "fire at will") Use(deltaTime, character);
|
||||
if (objective.Option.ToLowerInvariant() == "fireatwill")
|
||||
{
|
||||
character?.Speak(TextManager.Get("DialogFireTurret").Replace("[itemname]", item.Name), null, 0.0f, "fireturret", 5.0f);
|
||||
character.SetInput(InputType.Use, true, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -355,81 +516,132 @@ namespace Barotrauma.Items.Components
|
||||
base.RemoveComponentSpecific();
|
||||
|
||||
if (barrelSprite != null) barrelSprite.Remove();
|
||||
if (railSprite != null) railSprite.Remove();
|
||||
|
||||
#if CLIENT
|
||||
moveSoundChannel?.Dispose(); moveSoundChannel = null;
|
||||
#endif
|
||||
}
|
||||
|
||||
private List<Projectile> GetLoadedProjectiles(bool returnFirst = false, bool returnNull = false)
|
||||
private List<Projectile> GetLoadedProjectiles(bool returnFirst = false)
|
||||
{
|
||||
List<Projectile> projectiles = new List<Projectile>();
|
||||
|
||||
//check the item itself first
|
||||
CheckProjectileContainer(item, projectiles, returnFirst);
|
||||
foreach (MapEntity e in item.linkedTo)
|
||||
{
|
||||
var projectileContainer = e as Item;
|
||||
if (projectileContainer == null) continue;
|
||||
|
||||
if (returnNull)
|
||||
{
|
||||
var itemContainer = projectileContainer.GetComponent<ItemContainer>();
|
||||
if (itemContainer == null) continue;
|
||||
if (itemContainer.Inventory == null) continue;
|
||||
if (itemContainer.Inventory.Items == null) continue;
|
||||
for (int i = 0; i < itemContainer.Inventory.Items.Length; i++)
|
||||
{
|
||||
projectiles.Add(itemContainer.Inventory.Items[i]?.GetComponent<Projectile>());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var containedItems = projectileContainer.ContainedItems;
|
||||
if (containedItems == null) continue;
|
||||
|
||||
for (int i = 0; i < containedItems.Length; i++)
|
||||
{
|
||||
var projectileComponent = containedItems[i].GetComponent<Projectile>();
|
||||
if (projectileComponent != null)
|
||||
{
|
||||
projectiles.Add(projectileComponent);
|
||||
if (returnFirst) return projectiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e is Item projectileContainer) { CheckProjectileContainer(projectileContainer, projectiles, returnFirst); }
|
||||
if (returnFirst && projectiles.Any()) return projectiles;
|
||||
}
|
||||
|
||||
return projectiles;
|
||||
}
|
||||
|
||||
public override void FlipX()
|
||||
private void CheckProjectileContainer(Item projectileContainer, List<Projectile> projectiles, bool returnFirst)
|
||||
{
|
||||
minRotation = (float)Math.PI - minRotation;
|
||||
maxRotation = (float)Math.PI - maxRotation;
|
||||
var containedItems = projectileContainer.ContainedItems;
|
||||
if (containedItems == null) return;
|
||||
|
||||
for (int i = 0; i < containedItems.Length; i++)
|
||||
{
|
||||
var projectileComponent = containedItems[i].GetComponent<Projectile>();
|
||||
if (projectileComponent != null)
|
||||
{
|
||||
projectiles.Add(projectileComponent);
|
||||
if (returnFirst) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
//check if the contained item is another itemcontainer with projectiles inside it
|
||||
if (containedItems[i].ContainedItems == null) continue;
|
||||
for (int j = 0; j < containedItems[i].ContainedItems.Length; j++)
|
||||
{
|
||||
projectileComponent = containedItems[i].ContainedItems[j].GetComponent<Projectile>();
|
||||
if (projectileComponent != null)
|
||||
{
|
||||
projectiles.Add(projectileComponent);
|
||||
if (returnFirst) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void FlipX(bool relativeToSub)
|
||||
{
|
||||
minRotation = MathHelper.Pi - minRotation;
|
||||
maxRotation = MathHelper.Pi - maxRotation;
|
||||
|
||||
var temp = minRotation;
|
||||
minRotation = maxRotation;
|
||||
maxRotation = temp;
|
||||
|
||||
barrelPos.X = item.Rect.Width / item.Scale - barrelPos.X;
|
||||
|
||||
while (minRotation < 0)
|
||||
{
|
||||
minRotation += MathHelper.TwoPi;
|
||||
maxRotation += MathHelper.TwoPi;
|
||||
}
|
||||
rotation = (minRotation + maxRotation) / 2;
|
||||
|
||||
UpdateTransformedBarrelPos();
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power)
|
||||
|
||||
public override void FlipY(bool relativeToSub)
|
||||
{
|
||||
baseRotationRad = MathUtils.WrapAngleTwoPi(baseRotationRad - MathHelper.Pi);
|
||||
UpdateTransformedBarrelPos();
|
||||
|
||||
/*minRotation = -minRotation;
|
||||
maxRotation = -maxRotation;
|
||||
|
||||
var temp = minRotation;
|
||||
minRotation = maxRotation;
|
||||
maxRotation = temp;
|
||||
|
||||
barrelPos.Y = item.Rect.Height / item.Scale - barrelPos.Y;
|
||||
|
||||
while (minRotation < 0)
|
||||
{
|
||||
minRotation += MathHelper.TwoPi;
|
||||
maxRotation += MathHelper.TwoPi;
|
||||
}
|
||||
rotation = (minRotation + maxRotation) / 2;
|
||||
|
||||
UpdateTransformedBarrelPos();*/
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power, float signalStrength = 1.0f)
|
||||
{
|
||||
switch (connection.Name)
|
||||
{
|
||||
case "position_in":
|
||||
float.TryParse(signal, out targetRotation);
|
||||
|
||||
IsActive = true;
|
||||
|
||||
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out float newRotation))
|
||||
{
|
||||
targetRotation = MathHelper.ToRadians(newRotation);
|
||||
IsActive = true;
|
||||
}
|
||||
user = sender;
|
||||
break;
|
||||
case "trigger_in":
|
||||
item.Use((float)Timing.Step, sender);
|
||||
user = sender;
|
||||
//triggering the Use method through item.Use will fail if the item is not characterusable and the signal was sent by a character
|
||||
//so lets do it manually
|
||||
if (!characterUsable && sender != null)
|
||||
{
|
||||
TryLaunch(sender);
|
||||
TryLaunch((float)Timing.Step, sender);
|
||||
}
|
||||
break;
|
||||
case "toggle":
|
||||
case "toggle_light":
|
||||
foreach (ItemComponent component in item.components)
|
||||
{
|
||||
if (component.Parent == this && component is LightComponent lightComponent)
|
||||
{
|
||||
lightComponent.IsOn = !lightComponent.IsOn;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user