This commit is contained in:
YiHan0621
2025-10-11 14:30:38 +08:00
parent 6c98d9a449
commit 2e4a318ca3
158 changed files with 7344 additions and 2213 deletions

View File

@@ -31,7 +31,7 @@ namespace TcgEngine
public int matches;
public int victories;
public int defeats;
public int crystal;
public int crystals;
public UserCardData[] cards;
public UserCardData[] packs;

View File

@@ -4,8 +4,14 @@ using UnityEngine;
namespace TcgEngine
{
public enum TradeCurrency
{
Coin , // 金币
Crystal, // 水晶(通用充值货币)
}
/// <summary>
/// Defines all packs data
/// 定义所有包的数据
/// </summary>
[CreateAssetMenu(fileName = "PackData", menuName = "TcgEngine/PackData", order = 5)]
@@ -36,6 +42,7 @@ namespace TcgEngine
[Header("Availability")]
public bool available = true;
public int cost = 100; //Cost to buy
public TradeCurrency tradeCurrency;
public static List<PackData> pack_list = new List<PackData>();
@@ -100,7 +107,7 @@ namespace TcgEngine
}
else
{
Debug.LogWarning($"Pack {id} 卡图片加载失败: {cardback_img_path}");
Debug.LogWarning($"Pack {id} 卡图片加载失败: {cardback_img_path}");
}
}
else

View File

@@ -8,8 +8,8 @@ using TcgEngine.UI;
namespace TcgEngine.Client
{
/// <summary>
/// Main client script for the matchmaker
/// Will send requests to server and receive a response when a matchmaking succeed or fail
/// 匹配器的主客户端脚本
/// 将向服务器发送请求并在匹配成功或失败时接收响应
/// </summary>
public class GameClientMatchmaker : MonoBehaviour

View File

@@ -8,7 +8,7 @@ using TcgEngine.UI;
namespace TcgEngine.Client
{
/// <summary>
/// Area of the hand of packs, will spawn/despawns visual packs based on what player has in the data
/// 手部区域的包,将根据玩家在数据中拥有的内容生成/销毁视觉包
/// </summary>
public class HandPackArea : MonoBehaviour

View File

@@ -8,8 +8,8 @@ using TcgEngine.FX;
namespace TcgEngine.Client
{
/// <summary>
/// Visual representation of a card found in a pack (once opened)
/// The card can be flipped by clicking on it
///打开后找到的卡片的可视化表示
///通过点击卡片可以翻转它
/// </summary>
public class PackCard : MonoBehaviour
@@ -43,6 +43,7 @@ namespace TcgEngine.Client
void Awake()
{
card_list.Add(this);
Debug.Log($"当前数量{card_list.Count}");
}
private void OnDestroy()
@@ -62,6 +63,11 @@ namespace TcgEngine.Client
if (removed && timer > 4f)
Destroy(gameObject);
if (card_list.Count==5)
{
}
}
public void SetCard(PackData pack, CardData card, VariantData variant)
@@ -73,6 +79,7 @@ namespace TcgEngine.Client
cardback.sprite = pack.GetCardbackImage();
card_ui.SetCard(card, variant);
card_ui.card_image.SetNativeSize();
new_card?.SetActive(false);
UserData udata = Authenticator.Get().GetUserData();

View File

@@ -465,7 +465,7 @@ namespace TcgEngine.Gameplay
case TaskRewardType.Crystal:
if (userData != null)
{
userData.crystal += amount;
userData.crystals += amount;
Debug.Log($"获取{amount}个钻石");
}
break;

View File

@@ -72,7 +72,7 @@ namespace TcgEngine.UI
if (udata != null)
{
credits_txt.text = GameUI.FormatNumber(udata.coins);
crystalText.text = GameUI.FormatNumber(udata.crystal);
crystalText.text = GameUI.FormatNumber(udata.crystals);
}
bool matchmaking = GameClientMatchmaker.Get().IsMatchmaking();

View File

@@ -135,6 +135,7 @@ namespace TcgEngine.Client
string url = ApiClient.ServerURL + "/users/packs/open";
string json = ApiTool.ToJson(req);
Debug.Log($"[上传卡牌]{json}");
WebResponse res = await ApiClient.Get().SendPostRequest(url, json);
if (res.success)

View File

@@ -6,9 +6,8 @@ using UnityEngine.UI;
namespace TcgEngine.UI
{
/// <summary>
/// Pack panel is similar to the collection, but shows all the packs you own and all available packs
/// 卡包面板与收藏相似,但会显示您拥有的所有卡包以及所有可用卡包
/// </summary>
public class PackPanel : UIPanel
{
[Header("Packs")]
@@ -17,6 +16,13 @@ namespace TcgEngine.UI
public CardGrid grid_content;
public GameObject pack_prefab;
[Header("货币")]
public Text coin;
public Text crystal;
[Header("当前选择准备卡组")]
public PackData preparePack;
private List<GameObject> pack_list = new List<GameObject>();
private static PackPanel instance;
@@ -29,13 +35,11 @@ namespace TcgEngine.UI
//Delete grid content
for (int i = 0; i < grid_content.transform.childCount; i++)
Destroy(grid_content.transform.GetChild(i).gameObject);
}
protected override void Start()
{
base.Start();
}
protected override void Update()
@@ -50,10 +54,14 @@ namespace TcgEngine.UI
RefreshPacks();
}
/// <summary>
/// 刷新全部
/// </summary>
private void RefreshAll()
{
RefreshPacks();
RefreshStarterDeck();
RefreshCurrency();
}
public void RefreshPacks()
@@ -72,6 +80,10 @@ namespace TcgEngine.UI
pack_ui.onClick += OnClickPack;
pack_ui.onClickRight += OnClickPack;
pack_list.Add(nPack);
if (pack.title == "白银卡包")
{
SetPackData(pack);
}
}
}
@@ -87,6 +99,39 @@ namespace TcgEngine.UI
}
}
}
private void OnClickPack()
{
if (preparePack != null)
{
PackZoomPanel.Get().OnClickBuy(preparePack);
}
}
/// <summary>
/// 刷新货币
/// </summary>
public void RefreshCurrency()
{
coin.text = MainMenu.Get().credits_txt.text;
crystal.text = MainMenu.Get().crystalText.text;
}
/// <summary>
/// 设置即将打开卡包的数据
/// </summary>
private string SetPackData(PackData pack)
{
PlayerPrefs.SetString("SetPack",pack.id);
if (PlayerPrefs.GetString("SetPack") != null)
{
string setPack = PlayerPrefs.GetString("SetPack");
Debug.Log($"已设置{setPack},准备就绪");
}
return PlayerPrefs.GetString("SetPack");
}
public void OnClickPack(PackUI pack)
{

View File

@@ -98,6 +98,8 @@ namespace TcgEngine.UI
if (res.success)
{
PackPanel.Get().ReloadUserPack();
Debug.Log($"够买成功!{req.pack}");
PackPanel.Get().RefreshCurrency();
Hide();
}
else
@@ -118,6 +120,19 @@ namespace TcgEngine.UI
}
}
public void OnClickBuy(PackData setPack)
{
pack = setPack;
if (Authenticator.Get().IsTest())
{
BuyPackTest();
}
if (Authenticator.Get().IsApi())
{
BuyPackApi();
}
}
private void OnClickTab(TabButton btn)
{
if (btn.group == "menu")

View File

@@ -7,7 +7,7 @@ using UnityEngine;
namespace TcgEngine
{
/// <summary>
/// Base class for sending and receiving network messages
/// 发送和接收网络消息的基础类
/// </summary>
public class NetworkMessaging

View File

@@ -215,6 +215,8 @@ namespace TcgEngine
for (int i = 0; i < req.variants.Length; i++)
req.variants[i] = AddPackVariant(pack.variants[i]);
// req.trade_currency = pack.tradeCurrency;
string url = ApiClient.ServerURL + "/packs/add";
string json = ApiTool.ToJson(req);
await ApiClient.Get().SendPostRequest(url, json);
@@ -248,6 +250,7 @@ namespace TcgEngine
req.hp = card.hp;
req.cost = card.cost;
req.packs = new string[card.packs.Length];
req.isOnline = card.isOnline;
for (int i = 0; i < req.packs.Length; i++)
{
@@ -277,6 +280,7 @@ namespace TcgEngine
rcard.hp = card.hp;
rcard.cost = card.cost;
rcard.packs = new string[card.packs.Length];
rcard.isOnline = card.isOnline;
for (int p = 0; p < card.packs.Length; p++)
{
rcard.packs[p] = card.packs[p].id;
@@ -452,6 +456,7 @@ namespace TcgEngine
public int hp;
public int cost;
public string[] packs;
public bool isOnline;
}
[System.Serializable]
@@ -464,6 +469,7 @@ namespace TcgEngine
public PackAddProbability[] rarities_1st;
public PackAddProbability[] rarities;
public PackAddProbability[] variants;
public string trade_currency;
}
[System.Serializable]

View File

@@ -9,7 +9,7 @@ using UnityEngine.EventSystems;
namespace TcgEngine.UI
{
/// <summary>
/// Display a pack and all its information
/// 显示一个包及其所有信息
/// </summary>
public class PackUI : MonoBehaviour, IPointerClickHandler