92 lines
2.7 KiB
C#
92 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Vehicle.Impl;
|
|
namespace Gameplay.Vehicle
|
|
{
|
|
public class VehicleManager
|
|
{
|
|
|
|
private Dictionary<int, List<NormalVehicle>> _troopVehicles = new Dictionary<int, List<NormalVehicle>>();
|
|
|
|
public VehicleManager()
|
|
{
|
|
|
|
}
|
|
|
|
public void AddVehicle(NormalVehicle vehicle)
|
|
{
|
|
var troopId = vehicle.commonData.troopId;
|
|
if (!_troopVehicles.ContainsKey(troopId))
|
|
{
|
|
_troopVehicles.Add(troopId, new List<NormalVehicle>());
|
|
}
|
|
_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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查找敌方载具,添加到提供的列表中
|
|
/// </summary>
|
|
/// <param name="troopId">己方部队ID</param>
|
|
/// <param name="resultList">存储结果的列表</param>
|
|
public void SearchEnemies(int troopId, List<GameUnit> 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]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查找友方载具,添加到提供的列表中
|
|
/// </summary>
|
|
/// <param name="troopId">己方部队ID</param>
|
|
/// <param name="resultList">存储结果的列表</param>
|
|
public void SearchFriend(int troopId, List<GameUnit> 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]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|