Commit a302d069 authored by J114514's avatar J114514

Merge branch 'master' of git.moenext.com:sherry_chaos/MDPro3

parents 4fe50b4a 58388b96
......@@ -15,7 +15,7 @@ MonoBehaviour:
m_DefaultGroup: ca8b8e6916019834fb0ec5578fa0be37
m_currentHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
Hash: c432a641708e2489f36cf4d00293c756
m_OptimizeCatalogSize: 0
m_BuildRemoteCatalog: 0
m_CatalogRequestsTimeout: 0
......@@ -56,7 +56,7 @@ MonoBehaviour:
m_ContentStateBuildPathProfileVariableName: <default settings path>
m_CustomContentStateBuildPath:
m_ContentStateBuildPath:
m_BuildAddressablesWithPlayerBuild: 2
m_BuildAddressablesWithPlayerBuild: 1
m_overridePlayerVersion: '[UnityEditor.PlayerSettings.bundleVersion]'
m_GroupAssets:
- {fileID: 11400000, guid: 00d23bf82261d794b8ad80777f3da3ae, type: 2}
......
......@@ -36,7 +36,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: -0, z: -0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 22, y: -20}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 44, y: 44}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &579422588954085143
......
......@@ -822,25 +822,25 @@ namespace Percy
Move(2);
break;
case GameMessage.Move:
var raw = currentReader.ReadBytes(16);
int pc = raw[4];
int pl = raw[5];
int cc = raw[8];
int cl = raw[9];
int cs = raw[10];
int cp = raw[11];
if (!Convert.ToBoolean(cl & ((int)CardLocation.Grave + (int)CardLocation.Overlay)) &&
Convert.ToBoolean(cl & ((int)CardLocation.Deck + (int)CardLocation.Hand))
|| Convert.ToBoolean(cp & (int)CardPosition.FaceDown))
{
raw[0] = 0;
raw[1] = 0;
raw[2] = 0;
raw[3] = 0;
}
currentWriter.Write(raw);
//var raw = currentReader.ReadBytes(16);
//int pc = raw[4];
//int pl = raw[5];
//int cc = raw[8];
//int cl = raw[9];
//int cs = raw[10];
//int cp = raw[11];
//if (!Convert.ToBoolean(cl & ((int)CardLocation.Grave + (int)CardLocation.Overlay)) &&
// Convert.ToBoolean(cl & ((int)CardLocation.Deck + (int)CardLocation.Hand))
// || Convert.ToBoolean(cp & (int)CardPosition.FaceDown))
//{
// raw[0] = 0;
// raw[1] = 0;
// raw[2] = 0;
// raw[3] = 0;
//}
//currentWriter.Write(raw);
break;
case GameMessage.PosChange:
Move(9);
......
......@@ -194,15 +194,21 @@ namespace MDPro3
public static string GetConfigDeckName(bool containType = true)
{
var config = Get("DeckInUse", EMPTY_STRING);
if(!containType && config.Contains("/"))
if(config.StartsWith("/") && config.Length > 1)
config = config[1..];
if (!containType && config.Contains("/"))
config = Path.GetFileName(config);
return config;
}
public static void SetConfigDeck(string deckName, bool needCheck = false)
{
if(needCheck)
Set("DeckInUse", $"{Program.instance.deckSelector.DeckType}/{deckName}");
if (needCheck)
{
var type = Program.instance.deckSelector.DeckType;
var config = type == string.Empty ? deckName : $"{type}/{deckName}";
Set("DeckInUse", config);
}
else
Set("DeckInUse", deckName);
}
......
......@@ -248,8 +248,9 @@ namespace MDPro3.Net
public static async Task<MyCardMatchInfo> GetMatchInfo(string arena)
{
using var request = UnityWebRequest.PostWwwForm(matchUrl + "?arena=" + arena, jsonHeader);
var u16Secret = await GetUserU16SecretAsync();
request.SetRequestHeader(contentTypeHeader, jsonHeader);
request.SetRequestHeader(authHeader, "Basic " + CustomBase64Encode(account.user.username + ":" + account.user.id));
request.SetRequestHeader(authHeader, "Basic " + CustomBase64Encode(account.user.username + ":" + u16Secret));
var send = request.SendWebRequest();
await TaskUtility.WaitUntil(() => send.isDone);
......@@ -389,19 +390,19 @@ namespace MDPro3.Net
JoinPrivate = 5,
}
public static string GetJoinRoomPassword(MyCardRoomOptions options, string roomId, int userId, bool _private = false)
public static async UniTask<string> GetJoinRoomPassword(MyCardRoomOptions options, string roomId, int userId, bool _private = false)
{
byte[] optionsBuffer = new byte[6];
optionsBuffer[1] = (byte)((_private ? (int)RoomAction.JoinPrivate : (int)RoomAction.JoinPublic) << 4);
EncryptBuffer(optionsBuffer, userId);
await EncryptBuffer(optionsBuffer);
string base64String = Convert.ToBase64String(optionsBuffer);
return base64String + roomId;
}
public static string GetCreateRoomPasswd(MyCardRoomOptions options, string roomID, int userId, bool _private = false)
public static async Task<string> GetCreateRoomPasswd(MyCardRoomOptions options, string roomID, int userId, bool _private = false)
{
byte[] optionsBuffer = new byte[6];
optionsBuffer[1] = (byte)(((byte)(_private ? RoomAction.CreatePrivate : RoomAction.CreatePublic) << 4) | (byte)(options.duel_rule << 1) | (options.auto_death ? 0x1 : 0));
......@@ -410,13 +411,13 @@ namespace MDPro3.Net
WriteUInt16LE(optionsBuffer, 3, (ushort)options.start_lp);
optionsBuffer[5] = (byte)(((byte)options.start_hand << 4) | options.draw_count);
EncryptBuffer(optionsBuffer, userId);
await EncryptBuffer(optionsBuffer);
string base64String = Convert.ToBase64String(optionsBuffer);
return base64String + roomID;
}
private static void EncryptBuffer(byte[] buffer, int external_id)
private static async UniTask EncryptBuffer(byte[] buffer)
{
int checksum = 0;
......@@ -427,7 +428,8 @@ namespace MDPro3.Net
buffer[0] = (byte)(checksum & 0xff);
int secret = (external_id % 65535) + 1;
var u16Secret = await GetUserU16SecretAsync();
int secret = u16Secret % 65535 + 1;
for (int i = 0; i < buffer.Length; i += 2)
{
......@@ -453,6 +455,55 @@ namespace MDPro3.Net
buffer[offset + 1] = (byte)((value >> 8) & 0xff);
}
[Serializable]
private class AuthResponse
{
public int u16Secret;
}
private static async UniTask<int> GetUserU16SecretAsync()
{
static void Bad(string message)
{
MessageManager.Cast(InterString.Get("MyCard: 获取用户密钥失败。请重新登录。([?])", message));
throw new Exception($"Get U16 secret failed: {message}");
}
if(account == null)
Bad("No account info");
if (string.IsNullOrEmpty(account.token))
Bad("no token");
var token = account.token;
using var request = UnityWebRequest.Get(authUrl);
request.SetRequestHeader("Authorization", $"Bearer {token}");
request.SetRequestHeader("Content-Type", "application/json");
await request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
Bad(request.error);
return 0;
}
try
{
var jsonResponse = request.downloadHandler.text;
var authInfo = JsonUtility.FromJson<AuthResponse>(jsonResponse);
if (authInfo == null || authInfo.u16Secret == 0)
{
Bad("no secret or invalid response");
return 0;
}
return authInfo.u16Secret;
}
catch (Exception e)
{
Bad(e.ToString());
return 0;
}
}
#endregion
}
......
......@@ -234,6 +234,8 @@ namespace MDPro3.Net
deckYdk = decks[i].GetYDK(),
//timeStamp = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeMilliseconds()
};
if (body.decks[i].deckType == "/")
body.decks[i].deckType = string.Empty;
decks[i].deckId = ids[i];
decks[i].userId = MyCard.account.user.id.ToString();
......@@ -444,7 +446,7 @@ namespace MDPro3.Net
{
if (decks == null)
return false;
return decks.Any(deck => !deck.isDelete && deck.deckName == deckName && deck.deckType == deckType);
return decks.Any(deck => !deck.isDelete && deck.deckName == deckName && deck.GetType() == deckType);
}
#endregion
......@@ -490,6 +492,13 @@ namespace MDPro3.Net
var dataTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(lastDate);
return dataTimeOffset.LocalDateTime;
}
public new string GetType()
{
if (string.IsNullOrEmpty(deckType) || deckType == "/")
return string.Empty;
return deckType;
}
}
[Serializable]
......@@ -597,6 +606,8 @@ namespace MDPro3.Net
this.deckId = deckId;
this.deckName = deckName;
deckType = deck.type;
if(deckType == "/")
deckType = string.Empty;
if (deck.Pickup.Count > 0)
deckCoverCard1 = deck.Pickup[0];
if (deck.Pickup.Count > 1)
......
......@@ -334,9 +334,13 @@ namespace MDPro3.Servant
else
decksNeedUpdateFromServer.Add(deckName, decks[i]);
}
if((Path.GetFileName(deckName) != od.deckName || GetDeckTypeFromName(deckName) != od.deckType)
&& !decksNeedUpdateFromServer.Keys.Contains(deckName))
if((Path.GetFileName(deckName) != od.deckName || GetDeckTypeFromName(deckName) != od.GetType())
&& !decksNeedUpdateFromServer.Keys.Contains(deckName)
&& !decksNeedUpdateToServer.Keys.Contains(deckName))
{
//Debug.Log($"[{Path.GetFileName(deckName)}] [{od.deckName}] [{GetDeckTypeFromName(deckName)}] [{od.GetType()}]");
decksNeedUpdateFromServer.Add(deckName, decks[i]);
}
}
break;
}
......@@ -362,9 +366,9 @@ namespace MDPro3.Servant
var od = OnlineDeck.GetByID(deck.Value.deckId);
var oldPath = Program.PATH_DECK + deck.Key + Program.EXPANSION_YDK;
if (Path.GetFileName(deck.Key) != od.deckName || deck.Value.type != od.deckType)
if (Path.GetFileName(deck.Key) != od.deckName || deck.Value.type != od.GetType())
File.Delete(oldPath);
var newPath = Program.PATH_DECK + (od.deckType == string.Empty ? string.Empty : $"{od.deckType}/") + od.deckName + Program.EXPANSION_YDK;
var newPath = Program.PATH_DECK + (od.GetType() == string.Empty ? string.Empty : $"{od.GetType()}/") + od.deckName + Program.EXPANSION_YDK;
if(!Directory.Exists(Path.GetDirectoryName(newPath)))
Directory.CreateDirectory(Path.GetDirectoryName(newPath));
File.WriteAllText(newPath, od.deckYdk);
......@@ -377,18 +381,18 @@ namespace MDPro3.Servant
.Where(od => !od.isDelete && !localFoundIds.Contains(od.deckId));
foreach (var deck in odtd)
{
var path = Program.PATH_DECK + (deck.deckType == string.Empty ? string.Empty : $"{deck.deckType}/") + deck.deckName + Program.EXPANSION_YDK;
var path = Program.PATH_DECK + (deck.GetType() == string.Empty ? string.Empty : $"{deck.GetType()}/") + deck.deckName + Program.EXPANSION_YDK;
if (File.Exists(path))
{
Debug.Log($"删除服务器同名卡组 [{deck.deckType}/{deck.deckName}] [{deck.deckId}]。");
Debug.Log($"删除服务器同名卡组 [{deck.GetType()}/{deck.deckName}] [{deck.deckId}]。");
_ = OnlineDeck.DeleteDecks(new List<string> { deck.deckId });
continue;
}
Debug.Log($"卡组[{deck.deckType} / {deck.deckName}] [{deck.deckId}]需要下载。");
Debug.Log($"卡组[{deck.GetType()} / {deck.deckName}] [{deck.deckId}]需要下载。");
var d = new Deck(deck.deckYdk, deck.deckId, MyCard.account.user.username)
{
type = deck.deckType
type = deck.GetType()
};
d.Save(Path.GetFileName(deck.deckName), deck.GetUpdateUtcTime(), false);
}
......
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using YgomSystem.UI;
using UnityEngine.UI;
using DGTween = DG.Tweening.Tween;
namespace MDPro3.UI
{
......@@ -9,32 +10,105 @@ namespace MDPro3.UI
{
public float range;
public float time;
float startY;
readonly Ease ease = Ease.InOutSine;
[Header("Smoothing")]
public Ease ease = Ease.InOutSine;
[Tooltip("Normal = Update, Late = LateUpdate. Late is often smoother for UI.")]
public UpdateType updateType = UpdateType.Late;
[Tooltip("If true, animation ignores Time.timeScale (keeps moving in pause/slowmo).")]
public bool ignoreTimeScale = true;
private RectTransform _rt;
private Image _img;
private float _centerY;
private DGTween _startupTween;
private DGTween _loopTween;
private void Awake()
{
_rt = GetComponent<RectTransform>();
_img = GetComponent<Image>();
}
private void Start()
{
startY = GetComponent<RectTransform>().anchoredPosition.y;
_centerY = _rt.anchoredPosition.y;
foreach (var alpha in GetComponents<TweenAlpha>())
if (alpha.label == "Show")
GetComponent<Image>().color = new Color(1, 1, 1, alpha.to);
{
if (alpha.label == "Show" && _img != null)
_img.color = new Color(1f, 1f, 1f, alpha.to);
}
foreach (var position in GetComponents<TweenPosition>())
{
if (position.label == "Loop")
{
range = position.from.y - position.to.y;
time = position.duration;
break;
}
if (time > 0)
MoveUp();
}
if (time > 0f && !Mathf.Approximately(range, 0f))
StartSmoothLoop();
}
void MoveUp()
private void StartSmoothLoop()
{
GetComponent<RectTransform>().DOAnchorPosY(startY + range, time).SetEase(ease).OnComplete(() => { MoveDown(); });
KillTweens();
float yMin = _centerY - range;
float yMax = _centerY + range;
float curY = _rt.anchoredPosition.y;
float firstTarget = (Mathf.Abs(curY - yMax) <= Mathf.Abs(curY - yMin)) ? yMax : yMin;
float otherTarget = (firstTarget == yMax) ? yMin : yMax;
float fullDist = Mathf.Abs(yMax - yMin);
float firstDist = Mathf.Abs(curY - firstTarget);
float firstTime = (fullDist > 0.0001f) ? time * (firstDist / fullDist) : 0f;
_startupTween = _rt.DOAnchorPosY(firstTarget, firstTime)
.SetEase(ease)
.SetUpdate(updateType, ignoreTimeScale);
_startupTween.OnComplete(() =>
{
_loopTween = _rt.DOAnchorPosY(otherTarget, time)
.SetEase(ease)
.SetLoops(-1, LoopType.Yoyo)
.SetUpdate(updateType, ignoreTimeScale);
});
}
private void OnDisable()
{
if (_startupTween != null && _startupTween.IsActive()) _startupTween.Pause();
if (_loopTween != null && _loopTween.IsActive()) _loopTween.Pause();
}
void MoveDown()
private void OnEnable()
{
if (_startupTween != null && _startupTween.IsActive()) _startupTween.Play();
if (_loopTween != null && _loopTween.IsActive()) _loopTween.Play();
}
private void OnDestroy()
{
KillTweens();
}
private void KillTweens()
{
GetComponent<RectTransform>().DOAnchorPosY(startY - range, time).SetEase(ease).OnComplete(() => { MoveUp(); });
if (_startupTween != null && _startupTween.IsActive()) _startupTween.Kill();
if (_loopTween != null && _loopTween.IsActive()) _loopTween.Kill();
_startupTween = null;
_loopTween = null;
}
}
}
......@@ -52,7 +52,12 @@ namespace MDPro3.UI
{
AudioManager.PlaySE("SE_MENU_DECIDE");
base.CallSubmitEvent();
var password = MyCard.GetJoinRoomPassword(options, roomId, MyCard.account.user.id);
_ = WaitPasswordToJoin();
}
private async UniTask WaitPasswordToJoin()
{
var password = await MyCard.GetJoinRoomPassword(options, roomId, MyCard.account.user.id);
TcpHelper.LinkStart(MyCard.duelUrl, MyCard.account.user.username, MyCard.athleticPort.ToString(), password, false, null);
}
......
......@@ -381,6 +381,8 @@ namespace MDPro3.UI
//NameAreaGroup.SetActive(condition == Condition.Editable);
InputDeckName.gameObject.SetActive(condition == Condition.Editable);
TextDeckName.gameObject.SetActive(condition != Condition.Editable);
if (condition == Condition.Pickup)
ButtonDeck.gameObject.SetActive(false);
}
public RectTransform GetDeckLocationParent(DeckLocation location)
......
......@@ -140,7 +140,7 @@ PlayerSettings:
loadStoreDebugModeEnabled: 0
visionOSBundleVersion: 1.0
tvOSBundleVersion: 1.0
bundleVersion: 1.3.8
bundleVersion: 1.3.8.1
preloadedAssets:
- {fileID: 11400000, guid: 5fb02d2098f52054b89ce4a9f63ba9ee, type: 2}
- {fileID: -944628639613478452, guid: a916821eb5eea2842a69be6041bcdb82, type: 3}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment