geometry-tower-defense/Assets/GameMain/Scripts/CustomComponent/PlayerInventory/PlayerInventoryTowerRosterS...

47 lines
1.6 KiB
C#

using System.Collections.Generic;
using GeometryTD.Core;
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using UnityEngine;
namespace GeometryTD.CustomComponent
{
public sealed class PlayerInventoryTowerRosterService
{
private readonly PlayerInventoryQueryModel _queryModel;
private readonly int _maxParticipantTowerCount;
public PlayerInventoryTowerRosterService(PlayerInventoryQueryModel queryModel, int maxParticipantTowerCount)
{
_queryModel = queryModel;
_maxParticipantTowerCount = Mathf.Max(1, maxParticipantTowerCount);
}
public ParticipantTowerAssignResult TryAddParticipantTower(long towerInstanceId, int maxCount)
{
int resolvedMaxCount = Mathf.Max(1, maxCount);
resolvedMaxCount = Mathf.Min(resolvedMaxCount, _maxParticipantTowerCount);
return InventoryParticipantUtility.TryAddParticipantTower(
_queryModel.Inventory,
towerInstanceId,
resolvedMaxCount);
}
public bool TryRemoveParticipantTower(long towerInstanceId)
{
return InventoryParticipantUtility.TryRemoveParticipantTower(
_queryModel.Inventory,
towerInstanceId,
_maxParticipantTowerCount);
}
public int ReduceTowerEndurance(IReadOnlyList<long> towerInstanceIds, float enduranceLoss)
{
return InventoryTowerEnduranceUtility.ReduceTowerEndurance(
_queryModel.Inventory,
towerInstanceIds,
enduranceLoss);
}
}
}