diff --git a/DungeonShooting_Godot/excel/excelFile/ActivityObject.xlsx b/DungeonShooting_Godot/excel/excelFile/ActivityObject.xlsx index 57a1830..dbdd157 100644 --- a/DungeonShooting_Godot/excel/excelFile/ActivityObject.xlsx +++ b/DungeonShooting_Godot/excel/excelFile/ActivityObject.xlsx Binary files differ diff --git a/DungeonShooting_Godot/excel/excelFile/Sound.xlsx b/DungeonShooting_Godot/excel/excelFile/Sound.xlsx index 4da2ebc..b2185d4 100644 --- a/DungeonShooting_Godot/excel/excelFile/Sound.xlsx +++ b/DungeonShooting_Godot/excel/excelFile/Sound.xlsx Binary files differ diff --git a/DungeonShooting_Godot/excel/excelFile/Weapon.xlsx b/DungeonShooting_Godot/excel/excelFile/Weapon.xlsx index 623f344..bba5663 100644 --- a/DungeonShooting_Godot/excel/excelFile/Weapon.xlsx +++ b/DungeonShooting_Godot/excel/excelFile/Weapon.xlsx Binary files differ diff --git a/DungeonShooting_Godot/resource/config/Weapon.json b/DungeonShooting_Godot/resource/config/Weapon.json index 990757d..57bbf71 100644 --- a/DungeonShooting_Godot/resource/config/Weapon.json +++ b/DungeonShooting_Godot/resource/config/Weapon.json @@ -74,6 +74,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0005", "__BeginReloadSound": "reloadBegin0004", "BeginReloadSoundDelayTime": 0.2, @@ -164,6 +167,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0005", "__BeginReloadSound": "reloadBegin0004", "BeginReloadSoundDelayTime": 0.2, @@ -255,6 +261,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0003", "__BeginReloadSound": "reloadBegin0002", "BeginReloadSoundDelayTime": 0, @@ -346,6 +355,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0003", "__BeginReloadSound": "reloadBegin0002", "BeginReloadSoundDelayTime": 0, @@ -436,6 +448,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0004", "__BeginReloadSound": "reloading0001", "BeginReloadSoundDelayTime": 0, @@ -526,6 +541,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0004", "__BeginReloadSound": "reloading0001", "BeginReloadSoundDelayTime": 0, @@ -613,6 +631,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "", "__BeginReloadSound": "", "BeginReloadSoundDelayTime": 0, @@ -700,6 +721,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "", "__BeginReloadSound": "", "BeginReloadSoundDelayTime": 0, @@ -790,6 +814,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0008", "__BeginReloadSound": "reloadBegin0009", "BeginReloadSoundDelayTime": 0, @@ -880,6 +907,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0008", "__BeginReloadSound": "reloadBegin0009", "BeginReloadSoundDelayTime": 0, @@ -970,6 +1000,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0002", "__BeginReloadSound": "reloadBegin0005", "BeginReloadSoundDelayTime": 0.2, @@ -1060,6 +1093,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0002", "__BeginReloadSound": "reloadBegin0005", "BeginReloadSoundDelayTime": 0.2, @@ -1150,6 +1186,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0007", "__BeginReloadSound": "reloadBegin0006", "BeginReloadSoundDelayTime": 0.2, @@ -1240,6 +1279,9 @@ "MeleeAttackHarmRange": [ 10 ], + "MeleeAttackRepelRnage": [ + 100 + ], "__ShootSound": "shooting0007", "__BeginReloadSound": "reloadBegin0006", "BeginReloadSoundDelayTime": 0.2, diff --git a/DungeonShooting_Godot/src/config/ExcelConfig_Weapon.cs b/DungeonShooting_Godot/src/config/ExcelConfig_Weapon.cs index 3ab51ab..2496449 100644 --- a/DungeonShooting_Godot/src/config/ExcelConfig_Weapon.cs +++ b/DungeonShooting_Godot/src/config/ExcelConfig_Weapon.cs @@ -261,7 +261,8 @@ public int[] HarmRange; /// - /// 造成伤害后击退值区间,按每发子弹算击退
+ /// 造成伤害后击退值区间
+ /// 如果发射子弹,则按每发子弹算击退
/// 格式为[value]或者[min,max] ///
[JsonInclude] @@ -322,6 +323,13 @@ public int[] MeleeAttackHarmRange; /// + /// 近战攻击造成伤害后击退值区间
+ /// 格式为[value]或者[min,max] + ///
+ [JsonInclude] + public float[] MeleeAttackRepelRnage; + + /// /// 射击音效 /// public Sound ShootSound; @@ -460,6 +468,7 @@ inst.ThrowCollisionSize = ThrowCollisionSize; inst.CanMeleeAttack = CanMeleeAttack; inst.MeleeAttackHarmRange = MeleeAttackHarmRange; + inst.MeleeAttackRepelRnage = MeleeAttackRepelRnage; inst.ShootSound = ShootSound; inst.BeginReloadSound = BeginReloadSound; inst.BeginReloadSoundDelayTime = BeginReloadSoundDelayTime; diff --git a/DungeonShooting_Godot/src/framework/activity/ExternalForce.cs b/DungeonShooting_Godot/src/framework/activity/ExternalForce.cs index 25a62a3..5f45e1b 100644 --- a/DungeonShooting_Godot/src/framework/activity/ExternalForce.cs +++ b/DungeonShooting_Godot/src/framework/activity/ExternalForce.cs @@ -17,26 +17,36 @@ public bool Enable { get; set; } = true; /// - /// 阻力大小, 也就是速度每秒衰减的量 - /// - public float Resistance { get; set; } = 0; - - /// /// 是否在空中也会受到阻力 /// public bool EnableResistanceInTheAir { get; set; } = true; /// - /// 当速度到达 0 后是否自动销毁, 默认 true + /// 当速度(Velocity和RotationSpeed)到达 0 后是否自动销毁, 默认 true /// public bool AutoDestroy { get; set; } = true; /// + /// 速率的阻力大小, 也就是速度每秒衰减的量 + /// + public float VelocityResistance { get; set; } + + /// /// 当前力的速率 /// public Vector2 Velocity { get; set; } = Vector2.Zero; /// + /// 当前力对物体造成的旋转速度, 弧度制 + /// + public float RotationSpeed { get; set; } + + /// + /// 旋转速率阻力大小, 也就是速度每秒衰减的量 + /// + public float RotationResistance { get; set; } + + /// /// 物理帧更新 /// public virtual void PhysicsProcess(float delta) diff --git a/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs b/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs index 67dff7f..cff7286 100644 --- a/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs +++ b/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs @@ -104,8 +104,9 @@ public ExternalForce AddForce(Vector2 velocity, float resistance) { var force = AddForce("_anonymity_" + _index++); + force.AutoDestroy = true; force.Velocity = velocity; - force.Resistance = resistance; + force.VelocityResistance = resistance; return force; } @@ -224,7 +225,7 @@ { force.PhysicsProcess(delta); //自动销毁 - if (force.AutoDestroy && force.Velocity == Vector2.Zero) + if (CheckAutoDestroy(force)) { _forceList.Remove(force); externalForces[i] = null; @@ -234,15 +235,35 @@ //外力总和 var finallyEf = new Vector2(); + //旋转速率总和 + var rotationSpeed = 0f; foreach (var force in externalForces) { if (force != null && force.Enable) + { finallyEf += force.Velocity; + rotationSpeed += force.RotationSpeed; + } + } + + //处理旋转 + if (rotationSpeed != 0) + { + ActivityInstance.Rotation += rotationSpeed * delta; + } + //衰减旋转速率 + for (var i = 0; i < _forceList.Count; i++) + { + var force = _forceList[i]; + if (force.RotationResistance != 0 && (force.EnableResistanceInTheAir || !ActivityInstance.IsThrowing)) + { + force.RotationSpeed = Mathf.MoveToward(force.RotationSpeed, 0, force.RotationResistance * delta); + } } //最终速率 var finallyVelocity = _basisVelocity + finallyEf; - + //处理移动 if (finallyVelocity != Vector2.Zero) { //计算移动 @@ -289,15 +310,9 @@ ); //力速度衰减 - if (force.Resistance != 0 && (force.EnableResistanceInTheAir || !ActivityInstance.IsThrowing)) + if (force.VelocityResistance != 0 && (force.EnableResistanceInTheAir || !ActivityInstance.IsThrowing)) { - force.Velocity = force.Velocity.MoveToward(Vector2.Zero, force.Resistance * delta); - } - - //自动销毁 - if (force.AutoDestroy && force.Velocity == Vector2.Zero) - { - _forceList.RemoveAt(i--); + force.Velocity = force.Velocity.MoveToward(Vector2.Zero, force.VelocityResistance * delta); } } } @@ -309,6 +324,12 @@ } } + //检测是否达到自动销毁的条件 + private bool CheckAutoDestroy(ExternalForce force) + { + return force.AutoDestroy && force.Velocity == Vector2.Zero && force.RotationSpeed == 0; + } + public override void DebugDraw() { //绘制力大小和方向 diff --git a/DungeonShooting_Godot/src/game/activity/role/Role.cs b/DungeonShooting_Godot/src/game/activity/role/Role.cs index 0f52874..6010427 100644 --- a/DungeonShooting_Godot/src/game/activity/role/Role.cs +++ b/DungeonShooting_Godot/src/game/activity/role/Role.cs @@ -1138,6 +1138,17 @@ { var damage = Utils.Random.RandomConfigRange(activeWeapon.Attribute.MeleeAttackHarmRange); damage = RoleState.CallCalcDamageEvent(damage); + + //击退 + if (role is not Player) //目标不是玩家才会触发击退 + { + var attr = IsAi ? activeWeapon.AiUseAttribute : activeWeapon.PlayerUseAttribute; + var repel = Utils.Random.RandomConfigRange(attr.MeleeAttackRepelRnage); + var position = role.GlobalPosition - MountPoint.GlobalPosition; + var v2 = position.Normalized() * repel; + role.MoveController.AddForce(v2, repel * 2); + } + role.CallDeferred(nameof(Hurt), damage, (role.GetCenterPosition() - GlobalPosition).Angle()); } else if (activityObject is Bullet bullet) //攻击子弹 diff --git a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs index a5ec76c..34ca189 100644 --- a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs @@ -975,7 +975,7 @@ tempAngle -= Attribute.UpliftAngle; _fireAngle = tempAngle; - if (Master != null) //是否被拾起 + if (Master != null) //被拾起 { //武器身位置 var max = Mathf.Abs(Mathf.Max(Utils.GetConfigRangeStart(Attribute.BacklashRange), Utils.GetConfigRangeEnd(Attribute.BacklashRange))); @@ -986,9 +986,12 @@ Position = new Vector2(_currBacklashLength, 0).Rotated(Rotation); RotationDegrees = tempAngle; } - else + else //在地上 { - + var v = Utils.Random.RandomConfigRange(Attribute.BacklashRange) * 5; + var externalForce = MoveController.AddForce(new Vector2(-v, 0).Rotated(Rotation), v * 2); + externalForce.RotationSpeed = -Mathf.DegToRad(40); + externalForce.RotationResistance = Mathf.DegToRad(80); } }