diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs index 8d24a04..e80b072 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -615,7 +615,18 @@ _continuousCount = _continuousCount > 0 ? _continuousCount - 1 : 0; //减子弹数量 - CurrAmmo -= UseAmmoCount(); + if (_originWeaponAttribute != _weaponAttribute) //Ai使用该武器, 有一定概率不消耗弹药 + { + if (Utils.RandomRangeFloat(0, 1) < _weaponAttribute.AiAmmoConsumptionProbability) //触发消耗弹药 + { + CurrAmmo -= UseAmmoCount(); + } + } + else + { + CurrAmmo -= UseAmmoCount(); + } + //开火间隙 _fireInterval = 60 / Attribute.StartFiringSpeed; //攻击冷却 diff --git a/DungeonShooting_Godot/src/game/item/weapon/WeaponAttribute.cs b/DungeonShooting_Godot/src/game/item/weapon/WeaponAttribute.cs index 8a5ecc1..60e72b7 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/WeaponAttribute.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/WeaponAttribute.cs @@ -236,6 +236,16 @@ public float AiTargetLockingTime = 0; /// + /// 用于Ai, Ai使用该武器发射的子弹速度缩放比 + /// + public float AiBulletSpeedScale = 0.5f; + + /// + /// 用于Ai, Ai使用该武器消耗弹药的概率, (0 - 1) + /// + public float AiAmmoConsumptionProbability = 1f; + + /// /// Ai 使用该武器时的武器数据, 设置该字段, 可让同一把武器在敌人和玩家手上有不同属性 /// public WeaponAttribute AiUseAttribute; diff --git a/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs b/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs index bd44f44..1d66d3f 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs @@ -11,6 +11,11 @@ /// public Area2D CollisionArea { get; private set; } + /// + /// 发射该子弹的武器 + /// + public Weapon Weapon { get; private set; } + // 最大飞行距离 private float MaxDistance; @@ -20,13 +25,22 @@ //当前子弹已经飞行的距离 private float CurrFlyDistance = 0; - public void Init(float speed, float maxDistance, Vector2 position, float rotation, uint targetLayer) + public void Init(Weapon weapon, float speed, float maxDistance, Vector2 position, float rotation, uint targetLayer) { + Weapon = weapon; CollisionArea = GetNode("CollisionArea"); CollisionArea.CollisionMask = targetLayer; CollisionArea.AreaEntered += OnArea2dEntered; - - FlySpeed = speed; + + //只有玩家使用该武器才能获得正常速度的子弹 + if (weapon.Master is Player) + { + FlySpeed = speed; + } + else + { + FlySpeed = speed * weapon.Attribute.AiBulletSpeedScale; + } MaxDistance = maxDistance; Position = position; Rotation = rotation; diff --git a/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs b/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs index 5a2c9f0..b0a9644 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs @@ -131,6 +131,7 @@ const string bulletId = ActivityIdPrefix.Bullet + "0001"; var bullet = ActivityObject.Create(bulletId); bullet.Init( + this, 350, Utils.RandomRangeFloat(Attribute.MinDistance, Attribute.MaxDistance), FirePoint.GlobalPosition, diff --git a/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs b/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs index 7ee7c40..139496f 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs @@ -95,6 +95,7 @@ const string bulletId = ActivityIdPrefix.Bullet + "0001"; var bullet = ActivityObject.Create(bulletId); bullet.Init( + this, Utils.RandomRangeInt(280, 380), Utils.RandomRangeFloat(Attribute.MinDistance, Attribute.MaxDistance), FirePoint.GlobalPosition,