Merge branch 'master' into coolthings

This commit is contained in:
Joonas Rikkonen
2017-12-17 21:11:42 +02:00
committed by GitHub
13 changed files with 102 additions and 34 deletions
@@ -61,7 +61,7 @@
<joint limb1="0" limb1anchor="64,-264" limb2="2" limb2anchor="0,-100" lowerlimit="180" upperlimit="210" canbesevered="true"/> <joint limb1="0" limb1anchor="64,-264" limb2="2" limb2anchor="0,-100" lowerlimit="180" upperlimit="210" canbesevered="true"/>
<joint limb1="0" limb1anchor="-100,100" limb2="3" limb2anchor="38,0" lowerlimit="-50" upperlimit="5" canbesevered="true"/> <joint limb1="0" limb1anchor="-100,100" limb2="3" limb2anchor="38,0" lowerlimit="-50" upperlimit="5" canbesevered="true"/>
<joint limb1="0" limb1anchor="140,268" limb2="4" limb2anchor="0,0" lowerlimit="87" upperlimit="93"/> <joint limb1="0" limb1anchor="140,268" limb2="4" limb2anchor="0,0" lowerlimit="87" upperlimit="93" canbesevered="false"/>
</ragdoll> </ragdoll>
@@ -236,7 +236,6 @@
name="Flashlight" name="Flashlight"
category="Equipment" category="Equipment"
Tags="smallitem" Tags="smallitem"
price="10"> price="10">
<Deconstruct time="15"> <Deconstruct time="15">
@@ -248,12 +247,11 @@
<Body width="27" height="10" density="15"/> <Body width="27" height="10" density="15"/>
<Holdable slots="Any,RightHand,LeftHand" holdpos="30,-15" aimpos="100,0" handle1="0,0"> <Holdable slots="Any,RightHand,LeftHand,Face" holdpos="30,-15" aimpos="100,0" handle1="-13" handle2="-13">
<StatusEffect type="OnActive" target="Contained" Condition="-0.2"/> <StatusEffect type="OnActive" target="Contained" Condition="-0.2"/>
</Holdable> </Holdable>
<LightComponent LightColor="1.0,1.0,1.0,1.0" Flicker="0.1" range="800" powerconsumption="10" IsOn="true"> <LightComponent LightColor="1.0,1.0,1.0,1.0" Flicker="0.1" range="800" powerconsumption="10" IsOn="true">
<LightTexture texture="Content/Lights/lightcone.png" origin="0.0, 0.5" size="2.0,1.0"/> <LightTexture texture="Content/Lights/lightcone.png" origin="0.0, 0.5" size="2.0,1.0"/>
</LightComponent> </LightComponent>
@@ -36,11 +36,12 @@
category="Machine" category="Machine"
type="Controller" type="Controller"
linkable="true" linkable="true"
disableitemusagewhenselected="true"
> >
<Sprite texture ="railgunetc.png" depth="0.8" sourcerect="182,0,61,97"/> <Sprite texture ="railgunetc.png" depth="0.8" sourcerect="182,0,61,97"/>
<Controller UserPos="-35.0, -50.0" direction ="Right" canbeselected = "true"> <Controller UserPos="-35.0, -50.0" direction ="Right" canbeselected="true">
<limbposition limb="Head" position="-5,-62"/> <limbposition limb="Head" position="-5,-62"/>
<limbposition limb="Torso" position="-5,-108"/> <limbposition limb="Torso" position="-5,-108"/>
<limbposition limb="LeftHand" position="43,-85"/> <limbposition limb="LeftHand" position="43,-85"/>
@@ -1011,8 +1011,6 @@ namespace Barotrauma
public override void HoldItem(float deltaTime, Item item, Vector2[] handlePos, Vector2 holdPos, Vector2 aimPos, bool aim, float holdAngle) public override void HoldItem(float deltaTime, Item item, Vector2[] handlePos, Vector2 holdPos, Vector2 aimPos, bool aim, float holdAngle)
{ {
Holdable holdable = item.GetComponent<Holdable>();
if (character.IsUnconscious || character.Stun > 0.0f) aim = false; if (character.IsUnconscious || character.Stun > 0.0f) aim = false;
//calculate the handle positions //calculate the handle positions
@@ -1030,7 +1028,6 @@ namespace Barotrauma
bool usingController = character.SelectedConstruction != null && character.SelectedConstruction.GetComponent<Controller>() != null; bool usingController = character.SelectedConstruction != null && character.SelectedConstruction.GetComponent<Controller>() != null;
float itemAngle; float itemAngle;
if (Anim != Animation.Climbing && !usingController && character.Stun <= 0.0f && aim && itemPos != Vector2.Zero) if (Anim != Animation.Climbing && !usingController && character.Stun <= 0.0f && aim && itemPos != Vector2.Zero)
{ {
@@ -1042,6 +1039,7 @@ namespace Barotrauma
itemAngle = (torso.body.Rotation + holdAngle * Dir); itemAngle = (torso.body.Rotation + holdAngle * Dir);
Holdable holdable = item.GetComponent<Holdable>();
if (holdable.ControlPose) if (holdable.ControlPose)
{ {
head.body.SmoothRotate(itemAngle); head.body.SmoothRotate(itemAngle);
@@ -947,13 +947,16 @@ namespace Barotrauma
} }
} }
for (int i = 0; i < selectedItems.Length; i++ ) if (SelectedConstruction == null || !SelectedConstruction.Prefab.DisableItemUsageWhenSelected)
{ {
if (selectedItems[i] == null) continue; for (int i = 0; i < selectedItems.Length; i++ )
if (i == 1 && selectedItems[0] == selectedItems[1]) continue; {
if (selectedItems[i] == null) continue;
if (i == 1 && selectedItems[0] == selectedItems[1]) continue;
if (IsKeyDown(InputType.Use)) selectedItems[i].Use(deltaTime, this); if (IsKeyDown(InputType.Use)) selectedItems[i].Use(deltaTime, this);
if (IsKeyDown(InputType.Aim) && selectedItems[i] != null) selectedItems[i].SecondaryUse(deltaTime, this); if (IsKeyDown(InputType.Aim) && selectedItems[i] != null) selectedItems[i].SecondaryUse(deltaTime, this);
}
} }
if (selectedConstruction != null) if (selectedConstruction != null)
@@ -372,7 +372,11 @@ namespace Barotrauma
commands.Add(new Command("giveperm", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) => commands.Add(new Command("giveperm", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) =>
{ {
if (GameMain.Server == null) return; if (GameMain.Server == null) return;
if (args.Length < 1) return; if (args.Length < 1)
{
NewMessage("giveperm [id]: Grants administrative permissions to the player with the specified client ID.", Color.Cyan);
return;
}
int id; int id;
int.TryParse(args[0], out id); int.TryParse(args[0], out id);
@@ -383,6 +387,12 @@ namespace Barotrauma
return; return;
} }
NewMessage("Valid permissions are:",Color.White);
NewMessage(" - all",Color.White);
foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions)))
{
NewMessage(" - " + permission.ToString(),Color.White);
}
ShowQuestionPrompt("Permission to grant to \"" + client.Name + "\"?", (perm) => ShowQuestionPrompt("Permission to grant to \"" + client.Name + "\"?", (perm) =>
{ {
ClientPermissions permission = ClientPermissions.None; ClientPermissions permission = ClientPermissions.None;
@@ -392,7 +402,11 @@ namespace Barotrauma
} }
else else
{ {
Enum.TryParse<ClientPermissions>(perm, out permission); if (!Enum.TryParse<ClientPermissions>(perm, out permission))
{
ThrowError("\"" + perm + "\" sn't a valid permission!");
return;
}
} }
client.SetPermissions(client.Permissions | permission); client.SetPermissions(client.Permissions | permission);
GameMain.Server.UpdateClientPermissions(client); GameMain.Server.UpdateClientPermissions(client);
@@ -403,7 +417,11 @@ namespace Barotrauma
commands.Add(new Command("revokeperm", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) => commands.Add(new Command("revokeperm", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) =>
{ {
if (GameMain.Server == null) return; if (GameMain.Server == null) return;
if (args.Length < 1) return; if (args.Length < 1)
{
NewMessage("revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", Color.Cyan);
return;
}
int id; int id;
int.TryParse(args[0], out id); int.TryParse(args[0], out id);
@@ -414,6 +432,12 @@ namespace Barotrauma
return; return;
} }
NewMessage("Valid permissions are:", Color.White);
NewMessage(" - all", Color.White);
foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions)))
{
NewMessage(" - " + permission.ToString(), Color.White);
}
ShowQuestionPrompt("Permission to revoke from \"" + client.Name + "\"?", (perm) => ShowQuestionPrompt("Permission to revoke from \"" + client.Name + "\"?", (perm) =>
{ {
ClientPermissions permission = ClientPermissions.None; ClientPermissions permission = ClientPermissions.None;
@@ -423,7 +447,11 @@ namespace Barotrauma
} }
else else
{ {
Enum.TryParse<ClientPermissions>(perm, out permission); if (!Enum.TryParse<ClientPermissions>(perm, out permission))
{
ThrowError("\"" + perm + "\" isn't a valid permission!");
return;
}
} }
client.SetPermissions(client.Permissions & ~permission); client.SetPermissions(client.Permissions & ~permission);
GameMain.Server.UpdateClientPermissions(client); GameMain.Server.UpdateClientPermissions(client);
@@ -34,7 +34,7 @@ namespace Barotrauma
base.Init(); base.Init();
Vector2 position = Level.Loaded.GetRandomItemPos( Vector2 position = Level.Loaded.GetRandomItemPos(
Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 30.0f); Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 10000.0f, 30.0f);
item = new Item(itemPrefab, position, null); item = new Item(itemPrefab, position, null);
item.MoveWithLevel = true; item.MoveWithLevel = true;
@@ -28,7 +28,7 @@ namespace Barotrauma
public override void Start(Level level) public override void Start(Level level)
{ {
Vector2 spawnPos; Vector2 spawnPos;
Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, true, out spawnPos); Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out spawnPos);
monster = Character.Create(monsterFile, spawnPos, null, GameMain.Client != null, true, false); monster = Character.Create(monsterFile, spawnPos, null, GameMain.Client != null, true, false);
monster.Enabled = false; monster.Enabled = false;
@@ -46,7 +46,7 @@ namespace Barotrauma
public override void Start(Level level) public override void Start(Level level)
{ {
Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, 30.0f); Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, Level.Loaded.Size.X * 0.3f, 30.0f);
item = new Item(itemPrefab, position, null); item = new Item(itemPrefab, position, null);
item.MoveWithLevel = true; item.MoveWithLevel = true;
@@ -85,7 +85,7 @@ namespace Barotrauma
if (disallowed) return null; if (disallowed) return null;
Vector2 spawnPos; Vector2 spawnPos;
if (!Level.Loaded.TryGetInterestingPosition(true, spawnPosType, true, out spawnPos)) if (!Level.Loaded.TryGetInterestingPosition(true, spawnPosType, 20000.0f, out spawnPos))
{ {
//no suitable position found, disable the event //no suitable position found, disable the event
repeat = false; repeat = false;
@@ -184,8 +184,8 @@ namespace Barotrauma.Items.Components
item.SetTransform(rightHand.SimPosition, 0.0f); item.SetTransform(rightHand.SimPosition, 0.0f);
} }
bool alreadySelected = character.HasSelectedItem(item); bool alreadySelected = character.HasEquippedItem(item);
if (picker.TrySelectItem(item)) if (picker.TrySelectItem(item) || picker.HasEquippedItem(item))
{ {
item.body.Enabled = true; item.body.Enabled = true;
IsActive = true; IsActive = true;
@@ -308,7 +308,7 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
if (item.body == null || !item.body.Enabled) return; if (item.body == null || !item.body.Enabled) return;
if (picker == null || !picker.HasSelectedItem(item)) if (picker == null || !picker.HasEquippedItem(item))
{ {
IsActive = false; IsActive = false;
return; return;
@@ -320,7 +320,37 @@ namespace Barotrauma.Items.Components
item.Submarine = picker.Submarine; item.Submarine = picker.Submarine;
picker.AnimController.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle); if (picker.HasSelectedItem(item))
{
picker.AnimController.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle);
}
else
{
Limb equipLimb = null;
if (picker.Inventory.IsInLimbSlot(item, InvSlotType.Face) || picker.Inventory.IsInLimbSlot(item, InvSlotType.Head))
{
equipLimb = picker.AnimController.GetLimb(LimbType.Head);
}
else if (picker.Inventory.IsInLimbSlot(item, InvSlotType.Torso))
{
equipLimb = picker.AnimController.GetLimb(LimbType.Torso);
}
else if (picker.Inventory.IsInLimbSlot(item, InvSlotType.Legs))
{
equipLimb = picker.AnimController.GetLimb(LimbType.Waist);
}
if (equipLimb != null)
{
float itemAngle = (equipLimb.Rotation + holdAngle * picker.AnimController.Dir);
Matrix itemTransfrom = Matrix.CreateRotationZ(equipLimb.Rotation);
Vector2 transformedHandlePos = Vector2.Transform(handlePos[0], itemTransfrom);
item.body.ResetDynamics();
item.SetTransform(equipLimb.SimPosition - transformedHandlePos, itemAngle);
}
}
} }
protected void Flip(Item item) protected void Flip(Item item)
@@ -134,6 +134,13 @@ namespace Barotrauma
private set; private set;
} }
[Serialize(false, false)]
public bool DisableItemUsageWhenSelected
{
get;
private set;
}
public bool CanSpriteFlipX public bool CanSpriteFlipX
{ {
get { return canSpriteFlipX; } get { return canSpriteFlipX; }
@@ -817,7 +817,7 @@ namespace Barotrauma
//50% chance of placing the ruins at a cave //50% chance of placing the ruins at a cave
if (Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < 0.5f) if (Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < 0.5f)
{ {
TryGetInterestingPosition(true, PositionType.Cave, false, out ruinPos); TryGetInterestingPosition(true, PositionType.Cave, 0.0f, out ruinPos);
} }
ruinPos.Y = Math.Min(ruinPos.Y, borders.Y + borders.Height - ruinSize.Y / 2); ruinPos.Y = Math.Min(ruinPos.Y, borders.Y + borders.Height - ruinSize.Y / 2);
@@ -894,7 +894,7 @@ namespace Barotrauma
} }
} }
public Vector2 GetRandomItemPos(PositionType spawnPosType, float randomSpread, float offsetFromWall = 10.0f) public Vector2 GetRandomItemPos(PositionType spawnPosType, float randomSpread, float minDistFromSubs, float offsetFromWall = 10.0f)
{ {
if (!positionsOfInterest.Any()) return Size*0.5f; if (!positionsOfInterest.Any()) return Size*0.5f;
@@ -906,7 +906,7 @@ namespace Barotrauma
do do
{ {
Vector2 startPos; Vector2 startPos;
Level.Loaded.TryGetInterestingPosition(true, spawnPosType, true, out startPos); Loaded.TryGetInterestingPosition(true, spawnPosType, minDistFromSubs, out startPos);
startPos += Rand.Vector(Rand.Range(0.0f, randomSpread, Rand.RandSync.Server), Rand.RandSync.Server); startPos += Rand.Vector(Rand.Range(0.0f, randomSpread, Rand.RandSync.Server), Rand.RandSync.Server);
@@ -935,7 +935,7 @@ namespace Barotrauma
public bool TryGetInterestingPosition(bool useSyncedRand, PositionType positionType, bool avoidSubs, out Vector2 position) public bool TryGetInterestingPosition(bool useSyncedRand, PositionType positionType, float minDistFromSubs, out Vector2 position)
{ {
if (!positionsOfInterest.Any()) if (!positionsOfInterest.Any())
{ {
@@ -945,17 +945,20 @@ namespace Barotrauma
var matchingPositions = positionsOfInterest.FindAll(p => positionType.HasFlag(p.PositionType)); var matchingPositions = positionsOfInterest.FindAll(p => positionType.HasFlag(p.PositionType));
if (avoidSubs) if (minDistFromSubs > 0.0f)
{ {
foreach (Submarine sub in Submarine.Loaded) foreach (Submarine sub in Submarine.Loaded)
{ {
float minDist = Math.Max(sub.Borders.Width, sub.Borders.Height); matchingPositions.RemoveAll(p => Vector2.DistanceSquared(p.Position, sub.WorldPosition) < minDistFromSubs * minDistFromSubs);
matchingPositions.RemoveAll(p => Vector2.Distance(p.Position, sub.WorldPosition) < minDist);
} }
} }
if (!matchingPositions.Any()) if (!matchingPositions.Any())
{ {
#if DEBUG
DebugConsole.ThrowError("Could not find a suitable position of interest. (PositionType: " + positionType + ", minDistFromSubs: " + minDistFromSubs + "\n" + Environment.StackTrace);
#endif
position = positionsOfInterest[Rand.Int(positionsOfInterest.Count, (useSyncedRand ? Rand.RandSync.Server : Rand.RandSync.Unsynced))].Position; position = positionsOfInterest[Rand.Int(positionsOfInterest.Count, (useSyncedRand ? Rand.RandSync.Server : Rand.RandSync.Unsynced))].Position;
return false; return false;
} }