using System; using System.Collections.Generic; using Cute; using UnityEngine; using Wizard; public class CardMake : MonoBehaviour { private IDictionary DestructDict; private IDictionary _craftDict; public Action OnCardSell; public Action OnCardSellId; public Action OnCardBuy; public Action OnClose; private Action _onFinishCardDestruct; public void StartCardDestruct(int cardId) { if (DestructDict == null) { DestructDict = new Dictionary(); } else { DestructDict.Clear(); } int possessionCardNum = 0; // Pre-Phase-5b: headless has no user inventory DestructDict = new Dictionary(); DestructDict.Add(cardId.ToString(), "1," + possessionCardNum); DestructCard(); } private void DestructCard() { // Pre-Phase-5b: fired CardDestructTask via NetworkManager. Headless has no wire // task service; short-circuit straight to the success callback so the UI event // chain (OnRequestFinishDestruct → TriggerUpdateUserDeck → OnClose) still fires. OnRequestFinishDestruct(default(NetworkTask.ResultCode)); } private void OnRequestFinishDestruct(NetworkTask.ResultCode error) { TriggerUpdateUserDeck(); if (_onFinishCardDestruct != null) { _onFinishCardDestruct(); } } private void TriggerUpdateUserDeck() { List list = new List(DestructDict.Keys); for (int i = 0; i < list.Count; i++) { int obj = int.Parse(list[i]); if (OnCardSellId != null) { OnCardSellId(obj); } } if (OnCardSell != null) { OnCardSell(); } if (OnClose != null) { OnClose(); } list = null; } public void StartCardCraft(int cardId) { if (_craftDict == null) { _craftDict = new Dictionary(); } else { _craftDict.Clear(); } int possessionCardNum = 0; // Pre-Phase-5b: headless has no user inventory _craftDict.Add(cardId.ToString(), $"{1},{possessionCardNum}"); CraftCard(); } private void CraftCard() { // Pre-Phase-5b: fired CardCreateTask via NetworkManager. See DestructCard. OnRequestFinishCraft(default(NetworkTask.ResultCode)); } private void OnRequestFinishCraft(NetworkTask.ResultCode error) { if (OnCardBuy != null) { OnCardBuy(); } if (OnClose != null) { OnClose(); } } public void StartCraftAll(IDictionary craftDict) { if (_craftDict == null) { _craftDict = new Dictionary(); } else { _craftDict.Clear(); } foreach (KeyValuePair item in craftDict) { if (item.Value > 0) { string value = CreateRequestParam(item.Key, item.Value); _craftDict.Add(item.Key.ToString(), value); } } if (_craftDict.Count > 0) { CraftCard(); } } private string CreateRequestParam(int cardId, int num) { int possessionCardNum = 0; // Pre-Phase-5b: headless has no user inventory return $"{num},{possessionCardNum}"; } }