improves hitscan weapons (#248)

- fixes inhand sprite visibility
- adds visible charge level
- refactor sound recourse load, now you can specify fire sound from YAML
- adds laser cannon - more powerful laser
- adds new assets for cannon
This commit is contained in:
Injazz
2019-06-02 04:16:55 +05:00
committed by Pieter-Jan Briers
parent da35a0f3c9
commit 400778eb73
32 changed files with 349 additions and 11 deletions

View File

@@ -1,14 +1,27 @@
using System;
using Content.Shared.GameObjects.Components.Power;
using Content.Server.GameObjects.Components.Power;
using Robust.Shared.Serialization;
using Robust.Server.GameObjects;
namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
{
public class HitscanWeaponCapacitorComponent : PowerCellComponent
{
private AppearanceComponent _appearance;
public override string Name => "HitscanWeaponCapacitor";
public override float Charge
{
get => base.Charge;
set
{
base.Charge = value;
_updateAppearance();
}
}
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
@@ -19,6 +32,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
base.Initialize();
Charge = Capacity;
Owner.TryGetComponent(out _appearance);
}
public float GetChargeFrom(float toDeduct)
@@ -27,6 +42,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
ChargeChanged();
var chargeChangedBy = Math.Min(this.Charge, toDeduct);
this.DeductCharge(chargeChangedBy);
_updateAppearance();
return chargeChangedBy;
}
@@ -43,6 +59,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
this.AddCharge(battery.Charge);
battery.DeductCharge(battery.Charge);
}
_updateAppearance();
}
private void _updateAppearance()
{
_appearance?.SetData(PowerCellVisuals.ChargeLevel, Charge / Capacity);
}
}

View File

@@ -29,6 +29,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
private int _damage;
private int _baseFireCost;
private float _lowerChargeLimit;
private string _fireSound;
//As this is a component that sits on the weapon rather than a static value
//we just declare the field and then use GetComponent later to actually get it.
@@ -46,10 +47,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
{
base.ExposeData(serializer);
serializer.DataField(ref _spritename, "sprite", "Objects/laser.png");
serializer.DataField(ref _spritename, "fireSprite", "Objects/laser.png");
serializer.DataField(ref _damage, "damage", 10);
serializer.DataField(ref _baseFireCost, "baseFireCost", 300);
serializer.DataField(ref _lowerChargeLimit, "lowerChargeLimit", 10);
serializer.DataField(ref _fireSound, "fireSound", "/Audio/laser.ogg");
}
public override void Initialize()
@@ -58,6 +60,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
var rangedWeapon = Owner.GetComponent<RangedWeaponComponent>();
capacitorComponent = Owner.GetComponent<HitscanWeaponCapacitorComponent>();
rangedWeapon.FireHandler = Fire;
}
public bool AttackBy(AttackByEventArgs eventArgs)
@@ -124,7 +127,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan
};
var mgr = IoCManager.Resolve<IEntitySystemManager>();
mgr.GetEntitySystem<EffectSystem>().CreateParticle(message);
Owner.GetComponent<SoundComponent>().Play("/Audio/laser.ogg", AudioParams.Default.WithVolume(-5));
Owner.GetComponent<SoundComponent>().Play(_fireSound, AudioParams.Default.WithVolume(-5));
}
}
}