diff --git a/DungeonShooting_Godot/excel/excelFile/BulletBase.xlsx b/DungeonShooting_Godot/excel/excelFile/BulletBase.xlsx
index 24855bd..04648f8 100644
--- a/DungeonShooting_Godot/excel/excelFile/BulletBase.xlsx
+++ b/DungeonShooting_Godot/excel/excelFile/BulletBase.xlsx
Binary files differ
diff --git a/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs b/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs
index 32a873d..3e7b34e 100644
--- a/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs
+++ b/DungeonShooting_Godot/src/game/activity/bullet/laser/Laser.cs
@@ -17,20 +17,9 @@
get => CollisionMask;
set => CollisionMask = value;
}
- public Weapon Weapon { get; set; }
- public ExcelConfig.BulletBase BulletBase { get; set; }
- public Role TriggerRole { get; set; }
-
- ///
- /// 最小伤害
- ///
- public int MinHarm { get; set; } = 4;
-
- ///
- /// 最大伤害
- ///
- public int MaxHarm { get; set; } = 4;
-
+
+ public BulletData BulletData { get; private set; }
+
public bool IsDestroyed { get; private set; }
public float Width { get; set; }
@@ -50,23 +39,31 @@
AreaEntered += OnArea2dEntered;
}
-
- public void Init(Weapon weapon, uint attackLayer, Vector2 position, float rotation, float width, float distance)
+
+ public void InitData(BulletData data, uint attackLayer)
{
- TriggerRole = weapon.TriggerRole;
- Weapon = weapon;
+ InitData(data, attackLayer, 5);
+ }
+
+ public void InitData(BulletData data, uint attackLayer, float width)
+ {
AttackLayer = attackLayer;
- Position = position;
- Rotation = rotation;
+ Position = data.Position;
+ Rotation = data.Rotation;
//计算射线最大距离, 也就是撞到墙壁的距离
- var targetPosition = position + Vector2.FromAngle(rotation) * distance;
- var parameters = PhysicsRayQueryParameters2D.Create(position, targetPosition, PhysicsLayer.Wall);
+ var targetPosition = data.Position + Vector2.FromAngle(data.Rotation) * data.MaxDistance;
+ var parameters = PhysicsRayQueryParameters2D.Create(data.Position, targetPosition, PhysicsLayer.Wall);
var result = GetWorld2D().DirectSpaceState.IntersectRay(parameters);
+ float distance;
if (result != null && result.TryGetValue("position", out var point))
{
- distance = position.DistanceTo((Vector2)point);
+ distance = Position.DistanceTo((Vector2)point);
+ }
+ else
+ {
+ distance = data.MaxDistance;
}
Collision.SetDeferred(CollisionShape2D.PropertyName.Disabled, false);
@@ -127,10 +124,10 @@
if (role != null)
{
//计算子弹造成的伤害
- var damage = Utils.Random.RandomRangeInt(MinHarm, MaxHarm);
- if (TriggerRole != null)
+ var damage = Utils.Random.RandomRangeInt(BulletData.MinHarm, BulletData.MaxHarm);
+ if (BulletData.TriggerRole != null)
{
- damage = TriggerRole.RoleState.CallCalcDamageEvent(damage);
+ damage = BulletData.TriggerRole.RoleState.CallCalcDamageEvent(damage);
}
//造成伤害
role.CallDeferred(nameof(Role.Hurt), damage, Rotation);
diff --git a/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs b/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs
index 50570ea..234e7fe 100644
--- a/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs
+++ b/DungeonShooting_Godot/src/game/activity/bullet/normal/Bullet.cs
@@ -23,35 +23,8 @@
set => CollisionArea.CollisionMask = value;
}
- ///
- /// 发射该子弹的武器
- ///
- public Weapon Weapon { get; set; }
-
- public ExcelConfig.BulletBase BulletBase { get; set; }
+ public BulletData BulletData { get; private set; }
- ///
- /// 最小伤害
- ///
- public int MinHarm { get; set; } = 4;
-
- ///
- /// 最大伤害
- ///
- public int MaxHarm { get; set; } = 4;
-
- ///
- /// 发射该子弹的角色
- ///
- public Role TriggerRole { get; set; }
-
- ///
- /// 最大飞行距离
- ///
- public float MaxDistance { get; set; }
-
- // 子弹飞行速度
- private float FlySpeed;
//当前子弹已经飞行的距离
private float CurrFlyDistance = 0;
@@ -61,37 +34,17 @@
CollisionArea.AreaEntered += OnArea2dEntered;
}
- ///
- /// 显示红色描边
- ///
- /// 射出该子弹的武器
- /// 速度
- /// 最大飞行距离
- /// 位置
- /// 角度
- /// 攻击目标层级
- public void Init(Weapon weapon, float speed, float maxDistance, Vector2 position, float rotation, uint targetLayer)
+ public void InitData(BulletData data, uint attackLayer)
{
- Weapon = weapon;
- TriggerRole = weapon.TriggerRole;
- AttackLayer = targetLayer;
-
- if (TriggerRole == null || !TriggerRole.IsAi) //只有玩家使用该武器才能获得正常速度的子弹
- {
- FlySpeed = speed;
- }
- else
- {
- FlySpeed = speed * weapon.AiUseAttribute.AiAttackAttr.BulletSpeedScale;
- }
- MaxDistance = maxDistance;
- Position = position;
- Rotation = rotation;
+ BulletData = data;
+ AttackLayer = attackLayer;
+ Position = data.Position;
+ Rotation = data.Rotation;
ShadowOffset = new Vector2(0, 5);
- BasisVelocity = new Vector2(FlySpeed, 0).Rotated(Rotation);
+ BasisVelocity = new Vector2(data.FlySpeed, 0).Rotated(Rotation);
//如果子弹会对玩家造成伤害, 则显示红色描边
- if (Player.Current.CollisionWithMask(targetLayer))
+ if (Player.Current.CollisionWithMask(attackLayer))
{
ShowBorderFlashes();
}
@@ -147,8 +100,8 @@
return;
}
//距离太大, 自动销毁
- CurrFlyDistance += FlySpeed * delta;
- if (CurrFlyDistance >= MaxDistance)
+ CurrFlyDistance += BulletData.FlySpeed * delta;
+ if (CurrFlyDistance >= BulletData.MaxDistance)
{
PlayDisappearEffect();
Destroy();
@@ -166,16 +119,16 @@
node.AddToActivityRoot(RoomLayerEnum.YSortLayer);
//计算子弹造成的伤害
- var damage = Utils.Random.RandomRangeInt(MinHarm, MaxHarm);
- if (TriggerRole != null)
+ var damage = Utils.Random.RandomRangeInt(BulletData.MinHarm, BulletData.MaxHarm);
+ if (BulletData.TriggerRole != null)
{
- damage = TriggerRole.RoleState.CallCalcDamageEvent(damage);
+ damage = BulletData.TriggerRole.RoleState.CallCalcDamageEvent(damage);
}
//击退
if (role is not Player) //目标不是玩家才会触发击退
{
- var attr = Weapon.GetUseAttribute(TriggerRole);
+ var attr = BulletData.Weapon.GetUseAttribute(BulletData.TriggerRole);
var repel = Utils.Random.RandomConfigRange(attr.Bullet.RepelRnage);
if (repel != 0)
{
@@ -197,13 +150,13 @@
private void TestBoom()
{
//击中爆炸,测试用
- if (TriggerRole == null || !TriggerRole.IsAi)
+ if (BulletData.TriggerRole == null || !BulletData.TriggerRole.IsAi)
{
var explode = ObjectManager.GetExplode(ResourcePath.prefab_bullet_explode_Explode0001_tscn);
explode.Position = Position;
explode.RotationDegrees = Utils.Random.RandomRangeInt(0, 360);
explode.AddToActivityRootDeferred(RoomLayerEnum.YSortLayer);
- explode.Init(TriggerRole.AffiliationArea, AttackLayer, 25, MinHarm, MaxHarm, 50, 150);
+ explode.Init(BulletData.TriggerRole.AffiliationArea, AttackLayer, 25, BulletData.MinHarm, BulletData.MaxHarm, 50, 150);
explode.RunPlay();
}
}
diff --git a/DungeonShooting_Godot/src/game/activity/bullet/normal/IBullet.cs b/DungeonShooting_Godot/src/game/activity/bullet/normal/IBullet.cs
index 62165d9..6e74709 100644
--- a/DungeonShooting_Godot/src/game/activity/bullet/normal/IBullet.cs
+++ b/DungeonShooting_Godot/src/game/activity/bullet/normal/IBullet.cs
@@ -7,29 +7,12 @@
/// 攻击的层级
///
uint AttackLayer { get; set; }
-
///
- /// 发射该子弹的武器
+ /// 子弹数据
///
- Weapon Weapon { get; set; }
-
+ BulletData BulletData { get; }
///
- /// 使用的配置数据
+ /// 初始化子弹数据
///
- ExcelConfig.BulletBase BulletBase { get; set; }
-
- ///
- /// 发射该子弹的角色
- ///
- Role TriggerRole { get; set; }
-
- ///
- /// 最小伤害
- ///
- int MinHarm { get; set; }
-
- ///
- /// 最大伤害
- ///
- int MaxHarm { get; set; }
+ void InitData(BulletData data, uint attackLayer);
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs
index efce912..c7a7f06 100644
--- a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs
+++ b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs
@@ -1944,28 +1944,35 @@
///
private Bullet ShootSolidBullet(float fireRotation, ExcelConfig.BulletBase bullet)
{
- var speed = Utils.Random.RandomConfigRange(bullet.SpeedRange);
- var distance = Utils.Random.RandomConfigRange(bullet.DistanceRange);
+ var data = new BulletData()
+ {
+ Weapon = this,
+ BulletBase = bullet,
+ TriggerRole = TriggerRole,
+ MinHarm = Utils.GetConfigRangeStart(Attribute.Bullet.HarmRange),
+ MaxHarm = Utils.GetConfigRangeEnd(Attribute.Bullet.HarmRange),
+ MaxDistance = Utils.Random.RandomConfigRange(bullet.DistanceRange),
+ FlySpeed = Utils.Random.RandomConfigRange(bullet.SpeedRange),
+ Position = FirePoint.GlobalPosition,
+ };
+
var deviationAngle = Utils.Random.RandomConfigRange(bullet.DeviationAngleRange);
if (TriggerRole != null)
{
- speed = TriggerRole.RoleState.CallCalcBulletSpeedEvent(this, speed);
- distance = TriggerRole.RoleState.CallCalcBulletDistanceEvent(this, distance);
+ data.FlySpeed = TriggerRole.RoleState.CallCalcBulletSpeedEvent(this, data.FlySpeed);
+ data.MaxDistance = TriggerRole.RoleState.CallCalcBulletDistanceEvent(this, data.MaxDistance);
deviationAngle = TriggerRole.RoleState.CallCalcBulletDeviationAngleEvent(this, deviationAngle);
}
-
+
+ if (TriggerRole != null && TriggerRole.IsAi) //只有玩家使用该武器才能获得正常速度的子弹
+ {
+ data.FlySpeed *= AiUseAttribute.AiAttackAttr.BulletSpeedScale;
+ }
+
+ data.Rotation = fireRotation + Mathf.DegToRad(deviationAngle);
//创建子弹
var bulletInstance = Create(bullet.Prefab);
- bulletInstance.Init(
- this,
- speed,
- distance,
- FirePoint.GlobalPosition,
- fireRotation + Mathf.DegToRad(deviationAngle),
- GetAttackLayer()
- );
- bulletInstance.MinHarm = Utils.GetConfigRangeStart(Attribute.Bullet.HarmRange);
- bulletInstance.MaxHarm = Utils.GetConfigRangeEnd(Attribute.Bullet.HarmRange);
+ bulletInstance.InitData(data, GetAttackLayer());
return bulletInstance;
}
@@ -1974,25 +1981,27 @@
///
private Laser ShootLaser(float fireRotation, ExcelConfig.BulletBase bullet)
{
- var laser = ResourceManager.LoadAndInstantiate(bullet.Prefab);
- laser.AddToActivityRoot(RoomLayerEnum.YSortLayer);
+ var data = new BulletData()
+ {
+ Weapon = this,
+ BulletBase = bullet,
+ TriggerRole = TriggerRole,
+ MinHarm = Utils.GetConfigRangeStart(Attribute.Bullet.HarmRange),
+ MaxHarm = Utils.GetConfigRangeEnd(Attribute.Bullet.HarmRange),
+ MaxDistance = Utils.Random.RandomConfigRange(bullet.DistanceRange),
+ Position = FirePoint.GlobalPosition,
+ };
var deviationAngle = Utils.Random.RandomConfigRange(Attribute.Bullet.DeviationAngleRange);
- if (Master != null)
+ if (TriggerRole != null)
{
- deviationAngle = Master.RoleState.CallCalcBulletDeviationAngleEvent(this, deviationAngle);
+ deviationAngle = TriggerRole.RoleState.CallCalcBulletDeviationAngleEvent(this, deviationAngle);
}
- laser.Init(
- this,
- GetAttackLayer(),
- FirePoint.GlobalPosition,
- fireRotation + Mathf.DegToRad(deviationAngle),
- 3,
- 600
- );
- laser.MinHarm = Utils.GetConfigRangeStart(Attribute.Bullet.HarmRange);
- laser.MaxHarm = Utils.GetConfigRangeEnd(Attribute.Bullet.HarmRange);
+ data.Rotation = fireRotation + Mathf.DegToRad(deviationAngle);
+ //创建激光
+ var laser = ResourceManager.LoadAndInstantiate(bullet.Prefab);
+ laser.AddToActivityRoot(RoomLayerEnum.YSortLayer);
return laser;
}
diff --git a/DungeonShooting_Godot/src/game/data/BulletData.cs b/DungeonShooting_Godot/src/game/data/BulletData.cs
new file mode 100644
index 0000000..d7146cd
--- /dev/null
+++ b/DungeonShooting_Godot/src/game/data/BulletData.cs
@@ -0,0 +1,54 @@
+
+using Config;
+using Godot;
+
+///
+/// 子弹数据
+///
+public class BulletData
+{
+ ///
+ /// 发射该子弹的武器
+ ///
+ public Weapon Weapon;
+
+ ///
+ /// 使用的配置数据
+ ///
+ public ExcelConfig.BulletBase BulletBase;
+
+ ///
+ /// 发射该子弹的角色
+ ///
+ public Role TriggerRole;
+
+ ///
+ /// 最小伤害
+ ///
+ public int MinHarm;
+
+ ///
+ /// 最大伤害
+ ///
+ public int MaxHarm;
+
+ ///
+ /// 最大飞行距离
+ ///
+ public float MaxDistance;
+
+ ///
+ /// 子弹飞行速度
+ ///
+ public float FlySpeed;
+
+ ///
+ /// 坐标
+ ///
+ public Vector2 Position;
+
+ ///
+ /// 旋转角度
+ ///
+ public float Rotation;
+}
\ No newline at end of file