계산대 로직 중간저장

This commit is contained in:
2026-04-23 15:44:45 +09:00
parent e1124c927b
commit c8c39ddbc8
10 changed files with 163 additions and 9 deletions

View File

@@ -1,4 +1,9 @@
using System.Collections.Generic;
using UnityEngine;
using VRShopping.Interact;
using VRShopping.Items;
using VRShopping.Player;
using VRShopping.Shopping;
using VRShopping.UI;
public class PlayerController : MonoBehaviour,ITransScenePossible
@@ -9,6 +14,7 @@ public class PlayerController : MonoBehaviour,ITransScenePossible
private bool _controlPositive = true;
[SerializeField] private ShoppingOrderView _shoppingOrderView;
[SerializeField] private PlayerWallet playerWallet;
private void Awake()
{
@@ -35,4 +41,58 @@ public async void ToggleShoppingOrderList()
await _shoppingOrderView.ToggleShoppingOrderList();
_controlPositive = true;
}
public void Checkout(CheckoutMachine checkoutMachine)
{
List<CheckoutProductionRow> checkoutList = checkoutMachine.GetCheckoutList();
if(playerWallet.PayMoney(checkoutMachine.CheckoutSum))
{
Debug.Log("결제완료");
if (ShoppingOrderMissionClearCheck(checkoutList, out var missing))
{
Debug.Log("게임 클리어");
}
else
{
var parts = new List<string>(missing.Count);
foreach (var (group, shortage) in missing) parts.Add($"{group} x{shortage}");
Debug.Log($"장보기 목록 미충족 — 부족: {string.Join(", ", parts)}");
}
}
else
{
Debug.Log("예산 부족으로 결제 불가");
}
}
//계산한 품목이 장보기 목록을 모두 충족하는지 검사 (더 많은 건 허용)
//missing: 부족한 ProductGroup과 부족 수량 목록
private bool ShoppingOrderMissionClearCheck(List<CheckoutProductionRow> checkoutList, out List<(ProductGroup group, int shortage)> missing)
{
missing = new List<(ProductGroup, int)>();
ShoppingOrderList orderList = _shoppingOrderView != null ? _shoppingOrderView.OrderList : null;
if (orderList == null) return true;
//구매한 품목을 ProductGroup 기준으로 집계
var boughtByGroup = new Dictionary<ProductGroup, int>();
foreach (var row in checkoutList)
{
if (row.Item == null) continue;
boughtByGroup.TryGetValue(row.Item.ProductGroup, out int count);
boughtByGroup[row.Item.ProductGroup] = count + row.Quantity;
}
//목록의 각 항목을 전부 확인해서 부족분 수집
foreach (var entry in orderList.Entries)
{
boughtByGroup.TryGetValue(entry.ProductGroup, out int count);
int shortage = entry.RequiredQuantity - count;
if (shortage > 0) missing.Add((entry.ProductGroup, shortage));
}
return missing.Count == 0;
}
}