GUNS GUNS GUNS
GUESS WHAT
This commit is contained in:
parent
1e273d691e
commit
8aaccac2b5
83 changed files with 15291 additions and 1291 deletions
74
Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs
Normal file
74
Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ConstantWeaponData : WeaponData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new ConstantWeapon(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConstantWeapon : IBehavior, IAlwaysUpdatedBehavior
|
||||
{
|
||||
private ConstantWeaponData _data;
|
||||
|
||||
public int _burstCount;
|
||||
public float _burstTimer;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public event Action OnStartFiring;
|
||||
public event Action OnStopFiring;
|
||||
|
||||
private bool _firing;
|
||||
private bool _stoppedFiring;
|
||||
|
||||
public ConstantWeapon(ItemManager context, ConstantWeaponData c, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = c;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
if (!_firing)
|
||||
{
|
||||
_firing = true;
|
||||
OnStartFiring?.Invoke();
|
||||
}
|
||||
|
||||
_stoppedFiring = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AlwaysUpdate(float delta)
|
||||
{
|
||||
// Update executes after AlwaysUpdate,
|
||||
// so if the stop flag didn't get disabled previous frame,
|
||||
// we know the weapon has stopped firing
|
||||
if (_firing)
|
||||
{
|
||||
if (_stoppedFiring)
|
||||
{
|
||||
_firing = false;
|
||||
_stoppedFiring = false;
|
||||
OnStopFiring?.Invoke();
|
||||
}
|
||||
else
|
||||
_stoppedFiring = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue