diff --git a/prefab/role/Role.tscn b/prefab/role/Role.tscn
index c2d47e0..b2bfbf2 100644
--- a/prefab/role/Role.tscn
+++ b/prefab/role/Role.tscn
@@ -85,7 +85,7 @@
position = Vector2( 0, -12 )
frames = SubResource( 6 )
animation = "idle"
-frame = 3
+frame = 2
playing = true
[node name="HitArea" type="Area2D" parent="."]
diff --git a/prefab/ui/Cursor.tscn b/prefab/ui/Cursor.tscn
index 1202607..2f93075 100644
--- a/prefab/ui/Cursor.tscn
+++ b/prefab/ui/Cursor.tscn
@@ -7,6 +7,7 @@
script = ExtResource( 2 )
[node name="Center" type="Sprite" parent="."]
+visible = false
texture = ExtResource( 1 )
region_enabled = true
region_rect = Rect2( 3, 3, 2, 2 )
diff --git a/src/props/IProp.cs b/src/props/IProp.cs
new file mode 100644
index 0000000..e7b1932
--- /dev/null
+++ b/src/props/IProp.cs
@@ -0,0 +1,12 @@
+
+///
+/// 道具接口
+///
+public interface IProp
+{
+ ///
+ /// 与角色互动时调用
+ ///
+ /// 触发者
+ void Tnteractive(Role master);
+}
\ No newline at end of file
diff --git a/src/role/Role.cs b/src/role/Role.cs
index 165986a..4b41ba9 100644
--- a/src/role/Role.cs
+++ b/src/role/Role.cs
@@ -144,12 +144,7 @@
{
if (HasTnteractive())
{
- var tempItem = InteractiveItem;
- //临时处理
- var parent = tempItem.GetParent();
- parent.RemoveChild(tempItem);
- Holster.PickupGun(tempItem);
- parent.QueueFree();
+ InteractiveItem.Tnteractive(this);
}
}
diff --git a/src/weapon/gun/Gun.cs b/src/weapon/gun/Gun.cs
index 3819255..c18a344 100644
--- a/src/weapon/gun/Gun.cs
+++ b/src/weapon/gun/Gun.cs
@@ -4,7 +4,7 @@
///
/// 枪的基类
///
-public abstract class Gun : Area2D
+public abstract class Gun : Area2D, IProp
{
///
/// 开火回调事件
@@ -50,6 +50,15 @@
public Role Master { get; private set; }
///
+ /// 当前弹夹弹药剩余量
+ ///
+ public int CurrAmmo { get; private set; }
+ ///
+ /// 剩余弹药量
+ ///
+ public int ResidueAmmo { get; private set; }
+
+ ///
/// 枪管的开火点
///
public Position2D FirePoint { get; private set; }
@@ -91,16 +100,58 @@
private float upTimer = 0;
//连发次数
private float continuousCount = 0;
+ //连发状态记录
private bool continuousShootFlag = false;
- //状态 0 在地上, 1 被拾起
- private int _state = 0;
+
+ ///
+ /// 初始化时调用
+ ///
+ protected abstract void Init();
+
+ ///
+ /// 单次开火时调用的函数
+ ///
+ protected abstract void Fire();
+
+ ///
+ /// 发射子弹时调用的函数, 每发射一枚子弹调用一次,
+ /// 如果做霰弹枪效果, 一次开火发射5枚子弹, 则该函数调用5次
+ ///
+ protected abstract void ShootBullet();
+
+ ///
+ /// 当武器被拾起时调用
+ ///
+ /// 拾起该武器的角色
+ protected abstract void OnPickUp(Role master);
+
+ ///
+ /// 当武器被扔掉时调用
+ ///
+ protected abstract void OnThrowOut();
+
+ ///
+ /// 当武器被激活时调用, 也就是使用当武器是调用
+ ///
+ protected abstract void OnActive();
+
+ ///
+ /// 当武器被收起时调用
+ ///
+ protected abstract void OnConceal();
public override void _Process(float delta)
{
if (Master == null) //这把武器被扔在地上
{
-
+ triggerTimer = triggerTimer > 0 ? triggerTimer - delta : 0;
+ triggerFlag = false;
+ attackFlag = false;
+ attackTimer = attackTimer > 0 ? attackTimer - delta : 0;
+ CurrScatteringRange = Mathf.Max(CurrScatteringRange - Attribute.ScatteringRangeBackSpeed * delta, Attribute.StartScatteringRange);
+ continuousCount = 0;
+ delayedTime = 0;
}
else if (Master.Holster.ActiveGun != this) //当前武器没有被使用
{
@@ -108,6 +159,7 @@
triggerFlag = false;
attackFlag = false;
attackTimer = attackTimer > 0 ? attackTimer - delta : 0;
+ CurrScatteringRange = Mathf.Max(CurrScatteringRange - Attribute.ScatteringRangeBackSpeed * delta, Attribute.StartScatteringRange);
continuousCount = 0;
delayedTime = 0;
}
@@ -200,6 +252,9 @@
FirePoint.Position = new Vector2(attribute.FirePosition.x, -attribute.FirePosition.y);
OriginPoint.Position = new Vector2(0, -attribute.FirePosition.y);
+ //弹药量
+ CurrAmmo = attribute.CartridgeCapacity;
+
Init();
}
@@ -324,42 +379,13 @@
}
}
- ///
- /// 初始化时调用
- ///
- protected abstract void Init();
-
- ///
- /// 单次开火时调用的函数
- ///
- protected abstract void Fire();
-
- ///
- /// 发射子弹时调用的函数, 每发射一枚子弹调用一次,
- /// 如果做霰弹枪效果, 一次开火发射5枚子弹, 则该函数调用5次
- ///
- protected abstract void ShootBullet();
-
- ///
- /// 当武器被拾起时调用
- ///
- /// 拾起该武器的角色
- protected abstract void OnPickUp(Role master);
-
- ///
- /// 当武器被扔掉时调用
- ///
- protected abstract void OnThrowOut();
-
- ///
- /// 当武器被激活时调用, 也就是使用当武器是调用
- ///
- protected abstract void OnActive();
-
- ///
- /// 当武器被收起时调用
- ///
- protected abstract void OnConceal();
+ public void Tnteractive(Role master)
+ {
+ var parent = GetParent();
+ parent.RemoveChild(this);
+ master.Holster.PickupGun(this);
+ parent.QueueFree();
+ }
///
/// 触发落到地面
@@ -376,7 +402,6 @@
public void _PickUpGun(Role master)
{
Master = master;
- _state = 1;
//握把位置
GunSprite.Position = Attribute.HoldPosition;
AnimationPlayer.Play("RESET");
@@ -392,7 +417,6 @@
public void _ThrowOutGun()
{
Master = null;
- _state = 0;
GunSprite.Position = Attribute.CenterPosition;
AnimationPlayer.Play("Floodlight");
OnThrowOut();
@@ -423,7 +447,10 @@
return (T)CreateBullet(bulletPack, globalPostion, globalRotation, parent);
}
-
+ ///
+ /// 实例化并返回子弹对象
+ ///
+ /// 子弹的预制体
protected IBullet CreateBullet(PackedScene bulletPack, Vector2 globalPostion, float globalRotation, Node parent = null)
{
// 实例化子弹
diff --git a/src/weapon/gun/GunAttribute.cs b/src/weapon/gun/GunAttribute.cs
index c5195f6..b03b528 100644
--- a/src/weapon/gun/GunAttribute.cs
+++ b/src/weapon/gun/GunAttribute.cs
@@ -34,15 +34,35 @@
///
public bool ContinuousShoot = true;
///
+ /// 弹夹容量
+ ///
+ public int CartridgeCapacity = 30;
+ ///
+ /// 弹夹容量上限
+ ///
+ public int MaxCartridgeCapacity = 90;
+ ///
+ /// 装弹时间
+ ///
+ public float ReloadTime = 1.5f;
+ ///
+ /// 每粒子弹是否是单独装填, 如果是, 那么每上一发子弹的时间就是 ReloadTime, 可以做霰弹枪装填效果
+ ///
+ public bool AloneReload = false;
+ ///
+ /// 单独装填的子弹时可以立即射击, 必须要将 'AloneReload' 属性设置为 true
+ ///
+ public bool AloneReloadCanShoot = false;
+ ///
/// 是否为松发开火, 也就是松开扳机才开火, 若要启用该属性, 必须将 'ContinuousShoot' 设置为 false
///
public bool LooseShoot = false;
///
- /// 连续发射最小次数, 仅当ContinuousShoot为false时生效
+ /// 连续发射最小次数, 仅当 ContinuousShoot 为 false 时生效
///
public int MinContinuousCount = 3;
///
- /// 连续发射最大次数, 仅当ContinuousShoot为false时生效
+ /// 连续发射最大次数, 仅当 ContinuousShoot 为 false 时生效
///
public int MaxContinuousCount = 3;
///