< Summary

Information
Class: CounterDrone.Core.Simulation.DroneEntity
Assembly: CounterDrone.Core
File(s): C:\Users\Tellme\apps\CounterDroneBackend\src\CounterDrone.Core\Simulation\DroneEntity.cs
Line coverage
90%
Covered lines: 81
Uncovered lines: 9
Coverable lines: 90
Total lines: 125
Line coverage: 90%
Branch coverage
87%
Covered branches: 21
Total branches: 24
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_GroupId()100%210%
get_TargetType()100%11100%
get_PowerType()100%11100%
get_Wingspan()100%210%
get_TypicalSpeed()100%11100%
get_Route()100%11100%
get_CurrentWaypointIndex()100%11100%
get_PosX()100%11100%
get_PosY()100%11100%
get_PosZ()100%11100%
get_Hp()100%11100%
get_Status()100%11100%
get_ExposureTime()100%11100%
get_FormationOffsetX()100%11100%
get_FormationOffsetY()100%11100%
.ctor(...)100%22100%
ApplyFormationOffset(...)66.66%8663.63%
Update(...)91.66%121290.62%
ApplyDamage(...)100%44100%
MarkZoneIntruded()100%11100%

File(s)

C:\Users\Tellme\apps\CounterDroneBackend\src\CounterDrone.Core\Simulation\DroneEntity.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using CounterDrone.Core.Algorithms;
 4using CounterDrone.Core.Models;
 5
 6namespace CounterDrone.Core.Simulation
 7{
 8    public class DroneEntity
 9    {
 555510        public string Id { get; }
 011        public string GroupId { get; }
 2512        public TargetType TargetType { get; }
 2513        public PowerType PowerType { get; }
 014        public float Wingspan { get; }
 554515        public float TypicalSpeed { get; } // km/h
 1664016        public List<Waypoint> Route { get; }
 1110517        public int CurrentWaypointIndex { get; private set; }
 3375918        public float PosX { get; private set; }
 3375319        public float PosY { get; private set; }
 3371020        public float PosZ { get; private set; }
 1119321        public float Hp { get; private set; } = 1.0f;
 3335922        public DroneStatus Status { get; private set; } = DroneStatus.Flying;
 7523        public float ExposureTime { get; set; } // 在云团中的累计暴露时间
 2024        public float FormationOffsetX { get; set; }
 2125        public float FormationOffsetY { get; set; }
 26
 2027        public DroneEntity(string id, string groupId, TargetConfig config, List<Waypoint> route, int formationIndex, flo
 2028        {
 2029            Id = id;
 2030            GroupId = groupId;
 2031            TargetType = (TargetType)config.TargetType;
 2032            PowerType = (PowerType)config.PowerType;
 2033            Wingspan = (float)config.Wingspan;
 2034            TypicalSpeed = (float)config.TypicalSpeed;
 2035            Route = route;
 36
 2037            if (route.Count > 0)
 2038            {
 2039                PosX = (float)route[0].PosX;
 2040                PosY = (float)route[0].PosY;
 2041                PosZ = (float)route[0].PosZ;
 2042            }
 43
 44            // 编队偏移
 2045            ApplyFormationOffset(formationIndex, spacing, mode);
 2046            PosX += FormationOffsetX;
 2047            PosY += FormationOffsetY;
 2048        }
 49
 50        private void ApplyFormationOffset(int index, float spacing, FormationMode mode)
 2051        {
 3952            if (index == 0) return;
 153            var offset = spacing * index;
 154            switch (mode)
 55            {
 56                case FormationMode.Formation:
 157                    FormationOffsetY = offset; // 沿 Y 轴横队排列
 158                    break;
 59                case FormationMode.Swarm:
 060                    var rng = new Random(index * 137);
 061                    FormationOffsetX = (float)(rng.NextDouble() - 0.5) * spacing * 3;
 062                    FormationOffsetY = (float)(rng.NextDouble() - 0.5) * spacing * 3;
 063                    break;
 64            }
 2065        }
 66
 67        public void Update(float deltaTime, float windSpeed, WindDirection windDir)
 554568        {
 554569            if (Status != DroneStatus.Flying) return;
 554570            if (Route.Count == 0) return;
 554571            if (CurrentWaypointIndex >= Route.Count - 1)
 072            {
 073                Status = DroneStatus.ReachedTarget;
 074                return;
 75            }
 76
 554577            var target = Route[CurrentWaypointIndex + 1];
 554578            var speedMs = TypicalSpeed / 3.6f;
 554579            var dx = (float)(target.PosX - PosX);
 554580            var dy = (float)(target.PosY - PosY);
 554581            var dz = (float)(target.PosZ - PosZ);
 554582            var dist = (float)Math.Sqrt(dx * dx + dy * dy + dz * dz);
 554583            var step = speedMs * deltaTime;
 84
 554585            if (dist < 1.0f || step >= dist)
 586            {
 587                PosX = (float)target.PosX;
 588                PosY = (float)target.PosY;
 589                PosZ = (float)target.PosZ;
 590                CurrentWaypointIndex++;
 591                if (CurrentWaypointIndex >= Route.Count - 1)
 592                    Status = DroneStatus.ReachedTarget;
 593                return;
 94            }
 95
 96            // 移动方向
 554097            var ratio = step / dist;
 554098            PosX += dx * ratio;
 554099            PosY += dy * ratio;
 5540100            PosZ += dz * ratio;
 101
 102            // 风偏
 5540103            (float wx, float wy, float wz) = Kinematics.WindToVector(windDir, windSpeed);
 5540104            PosX += wx * deltaTime;
 5540105            PosY += wy * deltaTime;
 5540106            PosZ += wz * deltaTime;
 5545107        }
 108
 109        public void ApplyDamage(float damage)
 27110        {
 28111            if (Status != DroneStatus.Flying) return;
 26112            Hp -= damage;
 26113            if (Hp <= 0)
 3114            {
 3115                Hp = 0;
 3116                Status = DroneStatus.Destroyed;
 3117            }
 27118        }
 119
 120        public void MarkZoneIntruded()
 1121        {
 1122            Status = DroneStatus.ZoneIntruded;
 1123        }
 124    }
 125}