Renames "OnSecondaryUse" to "OnAim" for more sense

adds new "OnHudUse" to separate normal and self use
This commit is contained in:
Alex Noir
2017-12-10 13:39:00 +03:00
parent db7d5539e0
commit 00653c5aa4
12 changed files with 62 additions and 17 deletions
@@ -36,6 +36,7 @@ namespace Barotrauma
{
if (Items[slotIndex] == null) return false;
//Isn't this useless? Client isn't handling status effects. Plus, this doesn't send the ActionType so it can be wrong even.
#if CLIENT
if (GameMain.Client != null)
{
@@ -46,10 +47,10 @@ namespace Barotrauma
if (GameMain.Server != null)
{
GameMain.Server.CreateEntityEvent(Items[slotIndex], new object[] { NetEntityEvent.Type.ApplyStatusEffect, ActionType.OnUse, character.ID });
GameMain.Server.CreateEntityEvent(Items[slotIndex], new object[] { NetEntityEvent.Type.ApplyStatusEffect, ActionType.OnHudUse, character.ID });
}
Items[slotIndex].ApplyStatusEffects(ActionType.OnUse, 1.0f, character);
Items[slotIndex].ApplyStatusEffects(ActionType.OnHudUse, 1.0f, character);
return true;
}
@@ -255,7 +255,7 @@ namespace Barotrauma.Items.Components
dockingTarget.dockingDir = -dockingDir;
#if CLIENT
PlaySound(ActionType.OnSecondaryUse, item.WorldPosition);
PlaySound(ActionType.OnAim, item.WorldPosition);
#endif
ConnectWireBetweenPorts();
@@ -36,7 +36,7 @@ namespace Barotrauma.Items.Components
return true;
}
public override void SecondaryUse(float deltaTime, Character character = null)
public override void Aim(float deltaTime, Character character = null)
{
if (throwing) return;
}
@@ -290,8 +290,15 @@ namespace Barotrauma.Items.Components
return false;
}
//called when the item is used via the HUD button
//returns true if the item was used succesfully (not out of ammo, reloading, etc)
public virtual bool HudUse(float deltaTime, Character character = null)
{
return false;
}
//called when the item is equipped and right mouse button is pressed
public virtual void SecondaryUse(float deltaTime, Character character = null) { }
public virtual void Aim(float deltaTime, Character character = null) { }
//called when the item is placed in a "limbslot"
public virtual void Equip(Character character) { }
@@ -160,7 +160,7 @@ namespace Barotrauma.Items.Components
return true;
}
public override void SecondaryUse(float deltaTime, Character character = null)
public override void Aim(float deltaTime, Character character = null)
{
if (this.character == null || this.character != character || this.character.SelectedConstruction != item || !character.CanInteractWith(item))
{
@@ -118,7 +118,7 @@ namespace Barotrauma.Items.Components
}
public override void SecondaryUse(float deltaTime, Character character = null)
public override void Aim(float deltaTime, Character character = null)
{
if (reload > 0.0f) return;
@@ -242,7 +242,7 @@ namespace Barotrauma.Items.Components
return true;
}
public override void SecondaryUse(float deltaTime, Character character = null)
public override void Aim(float deltaTime, Character character = null)
{
if (nodes.Count > 1)
{
@@ -16,7 +16,7 @@ namespace Barotrauma
{
public enum ActionType
{
Always, OnPicked, OnUse, OnSecondaryUse,
Always, OnPicked, OnUse, OnHudUse, OnAim,
OnWearing, OnContaining, OnContained,
OnActive, OnFailure, OnBroken,
OnFire, InWater,
@@ -800,6 +800,7 @@ namespace Barotrauma
if (!ic.WasUsed)
{
ic.StopSounds(ActionType.OnUse);
ic.StopSounds(ActionType.OnHudUse);
}
#endif
ic.WasUsed = false;
@@ -1165,12 +1166,38 @@ namespace Barotrauma
if (remove) Remove();
}
public void SecondaryUse(float deltaTime, Character character = null)
public void HudUse(float deltaTime, Character character = null)
{
if (condition == 0.0f) return;
bool remove = false;
foreach (ItemComponent ic in components)
{
if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue;
if (ic.HudUse(deltaTime, character))
{
ic.WasUsed = true;
#if CLIENT
ic.PlaySound(ActionType.OnHudUse, WorldPosition);
#endif
ic.ApplyStatusEffects(ActionType.OnHudUse, deltaTime, character);
if (ic.DeleteOnUse) remove = true;
}
}
if (remove) Remove();
}
public void Aim(float deltaTime, Character character = null)
{
foreach (ItemComponent ic in components)
{
if (!ic.HasRequiredContainedItems(character == Character.Controlled)) continue;
ic.SecondaryUse(deltaTime, character);
ic.Aim(deltaTime, character);
}
}