using System.Collections.Generic; using Gameplay.Unit; using Gameplay.Vehicle.Impl; namespace Gameplay.Vehicle { public class VehicleManager { private Dictionary> _troopVehicles = new Dictionary>(); public VehicleManager() { } public void AddVehicle(NormalVehicle vehicle) { var troopId = vehicle.commonData.troopId; if (!_troopVehicles.ContainsKey(troopId)) { _troopVehicles.Add(troopId, new List()); } _troopVehicles[troopId].Add(vehicle); } public void RemoveVehicle(NormalVehicle vehicle) { var troopId = vehicle.commonData.troopId; if (_troopVehicles.ContainsKey(troopId)) { _troopVehicles[troopId].Remove(vehicle); } } public NormalVehicle GetVehicleByTroop(int troopId) { if (_troopVehicles.TryGetValue(troopId, out var vehicle)) { if (vehicle.Count > 0) { return vehicle[0]; } } return null; } /// /// 查找敌方载具,添加到提供的列表中 /// /// 己方部队ID /// 存储结果的列表 public void SearchEnemies(int troopId, List resultList) { if (resultList == null) return; foreach (var team in _troopVehicles) { if (Level.Level.IsEnemy(team.Key, troopId)) { var vehicles = team.Value; for (int i = 0; i < vehicles.Count; i++) { resultList.Add(vehicles[i]); } } } } /// /// 查找友方载具,添加到提供的列表中 /// /// 己方部队ID /// 存储结果的列表 public void SearchFriend(int troopId, List resultList) { if (resultList == null) return; foreach (var team in _troopVehicles) { if (!Level.Level.IsEnemy(team.Key, troopId)) { var vehicles = team.Value; for (int i = 0; i < vehicles.Count; i++) { resultList.Add(vehicles[i]); } } } } } }