diff --git a/prefab/projectile/Catapult.tscn b/prefab/projectile/Catapult.tscn index 7903949..cccc863 100644 --- a/prefab/projectile/Catapult.tscn +++ b/prefab/projectile/Catapult.tscn @@ -15,14 +15,15 @@ slide_on_ceiling = false platform_floor_layers = 4294967042 platform_wall_layers = 32 script = ExtResource("1_ib3qh") -Life = 5000 +Life = 30000 Durability = 3.0 MaxDamage = 3 MinDamage = 10 DamageType = 2 KnockbackForce = Vector2(2, -3) Speed = 300.0 -EnableBounce = true +IgnoreWall = true +EnableTracking = true [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("CircleShape2D_dgro2") diff --git a/prefab/projectile/curseOfTheUndead.tscn b/prefab/projectile/curseOfTheUndead.tscn index e658bdc..0be0bb3 100644 --- a/prefab/projectile/curseOfTheUndead.tscn +++ b/prefab/projectile/curseOfTheUndead.tscn @@ -12,13 +12,14 @@ radius = 11.0 collision_layer = 0 collision_mask = 0 script = ExtResource("1_ib3qh") -Life = 5000 +Life = 30000 Durability = 1.0 MaxDamage = 3 MinDamage = 10 DamageType = 2 KnockbackForce = Vector2(2, -3) Speed = 500.0 +IgnoreWall = true [node name="CurseOfTheUndead" type="Sprite2D" parent="."] texture = ExtResource("1_k8el6") diff --git a/prefab/weapons/StaffNecromancy.tscn b/prefab/weapons/StaffNecromancy.tscn index 602315c..a186043 100644 --- a/prefab/weapons/StaffNecromancy.tscn +++ b/prefab/weapons/StaffNecromancy.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=9 format=3 uid="uid://dnnn2xyayiehk"] +[gd_scene load_steps=8 format=3 uid="uid://dnnn2xyayiehk"] [ext_resource type="Texture2D" uid="uid://wt50kx6bup51" path="res://sprites/weapon/StaffNecromancy.png" id="1_ms3us"] [ext_resource type="Script" path="res://scripts/weapon/ProjectileWeapon.cs" id="1_w8hhv"] -[ext_resource type="PackedScene" uid="uid://c01av43yk1q71" path="res://prefab/projectile/curseOfTheUndead.tscn" id="2_34250"] [ext_resource type="Texture2D" uid="uid://dg5vwprt66w4j" path="res://sprites/weapon/StaffNecromancy_Icon.png" id="3_31iau"] [ext_resource type="PackedScene" uid="uid://bdxgx5vcof8em" path="res://prefab/projectile/Catapult.tscn" id="3_hk5nr"] [ext_resource type="AudioStream" uid="uid://cak6chjjsu7wo" path="res://sounds/fire.wav" id="4_ffr2k"] @@ -18,9 +17,8 @@ collision_layer = 8 collision_mask = 34 angular_damp = -1.0 script = ExtResource("1_w8hhv") -OffsetAngle = 0.523 -NumberOfProjectiles = 15.0 -ProjectileScenes = [ExtResource("2_34250"), ExtResource("3_hk5nr")] +OffsetAngle = 0.087 +ProjectileScenes = [ExtResource("3_hk5nr")] Sequentially = true FiringIntervalAsMillisecond = 300 UniqueIcon = ExtResource("3_31iau") diff --git a/scripts/Config.cs b/scripts/Config.cs index 5e2c0dd..9d2ab59 100644 --- a/scripts/Config.cs +++ b/scripts/Config.cs @@ -418,6 +418,30 @@ public static class Config public const int VerticalVelocityOfDamageNumbers = 5; + public static class OffsetAngleMode + { + + /// + /// Random(Default) + /// 随机的(默认) + /// + public const int Random = 0; + + /// + /// AlwaysSame + /// 永远不变的偏移角度 + /// + public const int AlwaysSame = 1; + + /// + /// Cross + /// 交叉变换 + /// + public const int Cross = 2; + + + } + /// /// Physical collision layer number /// 物理碰撞层 序号 diff --git a/scripts/character/AiCharacter.cs b/scripts/character/AiCharacter.cs index dae3f58..32190e1 100644 --- a/scripts/character/AiCharacter.cs +++ b/scripts/character/AiCharacter.cs @@ -341,7 +341,7 @@ public sealed partial class AiCharacter : CharacterTemplate if (NavigationAgent2D != null && IsOnFloor()) { var nextPathPosition = NavigationAgent2D.GetNextPathPosition(); - var direction = (nextPathPosition - GlobalPosition).Normalized(); + var direction = GlobalPosition.DirectionTo(nextPathPosition); velocity = direction * Config.CellSize * Speed * ProtectedSpeedScale; } } diff --git a/scripts/loader/uiLoader/SplashScreenLoader.cs b/scripts/loader/uiLoader/SplashScreenLoader.cs index 06568ad..46ce1f7 100644 --- a/scripts/loader/uiLoader/SplashScreenLoader.cs +++ b/scripts/loader/uiLoader/SplashScreenLoader.cs @@ -111,7 +111,10 @@ public partial class SplashScreenLoader : UiLoaderTemplate FriendInjury = true }; CampManager.SetDefaultCamp(defaultCamp); - var mazoku = new Camp(Config.CampId.Mazoku); + var mazoku = new Camp(Config.CampId.Mazoku) + { + FriendInjury = true + }; CampManager.AddCamp(mazoku); var aborigines = new Camp(Config.CampId.Aborigines); CampManager.AddCamp(aborigines); diff --git a/scripts/projectile/Projectile.cs b/scripts/projectile/Projectile.cs index d43975f..01c6c82 100644 --- a/scripts/projectile/Projectile.cs +++ b/scripts/projectile/Projectile.cs @@ -61,6 +61,18 @@ public partial class Projectile : CharacterBody2D /// [Export] public bool IgnoreWall; + /// + /// Enable the tracking of the enemy + /// 启用追踪敌人的功能 + /// + [Export] public bool EnableTracking; + + /// + /// The target + /// 设置目标 + /// + public Node2D? Target { get; set; } + private List? _projectileDecorators; @@ -271,7 +283,23 @@ public partial class Projectile : CharacterBody2D public override void _PhysicsProcess(double delta) { var collisionInfo = MoveAndCollide(Velocity * (float)delta); - if (collisionInfo != null) + if (collisionInfo == null) + { + //No collision. + //没有撞到任何东西。 + if (EnableTracking && Target != null) + { + //Track the target + //追踪目标 + //Gets a vector of the projectile pointing at the enemy's position. + //得到抛射体指向敌人位置的向量。 + var desiredVelocity = GlobalPosition.DirectionTo(Target.GlobalPosition) * Speed; + //The weight is smaller, the circle is larger. + //weight越小,子弹绕的圈越大。 + Velocity = Velocity.Lerp(desiredVelocity, 0.1f); + } + } + else { //Bump into other objects. //撞到其他对象。 diff --git a/scripts/weapon/ProjectileWeapon.cs b/scripts/weapon/ProjectileWeapon.cs index 0e65302..69a760a 100644 --- a/scripts/weapon/ProjectileWeapon.cs +++ b/scripts/weapon/ProjectileWeapon.cs @@ -27,7 +27,19 @@ public partial class ProjectileWeapon : WeaponTemplate /// 散射弧度 /// [Export] protected float OffsetAngle; - + + /// + /// Offset angle mode + /// 偏移角度模式 + /// + [Export] protected int OffsetAngleMode = Config.OffsetAngleMode.Random; + + /// + /// Whether the last offset angle is positive + /// 上次的偏移角度是否为正向的 + /// + private bool _positiveOffsetAngle = true; + /// /// The number of projectiles fired at once /// 一次可以发射多少个子弹 @@ -69,6 +81,7 @@ public partial class ProjectileWeapon : WeaponTemplate } } + /// /// GetRandomAngle /// 获取随机的偏移弧度 @@ -83,6 +96,27 @@ public partial class ProjectileWeapon : WeaponTemplate return 0; } + if (OffsetAngleMode == Config.OffsetAngleMode.Cross) + { + float result; + if (_positiveOffsetAngle) + { + result = -OffsetAngle / 2; + } + else + { + result = OffsetAngle / 2; + } + + _positiveOffsetAngle = !_positiveOffsetAngle; + return result; + } + + if (OffsetAngleMode == Config.OffsetAngleMode.AlwaysSame) + { + return OffsetAngle; + } + var min = -OffsetAngle / 2; return min + RandomUtils.Instance.NextSingle() * OffsetAngle; } @@ -136,7 +170,8 @@ public partial class ProjectileWeapon : WeaponTemplate NodeUtils.CallDeferredAddChild(GameSceneNodeHolder.ProjectileContainer, projectile); projectile.Owner = owner; projectile.Velocity = - ((enemyGlobalPosition - _marker2D.GlobalPosition).Normalized() * projectile.Speed).Rotated(GetRandomAngle()); + (_marker2D.GlobalPosition.DirectionTo(enemyGlobalPosition) * projectile.Speed) + .Rotated(GetRandomAngle()); projectile.Position = _marker2D.GlobalPosition; } }