_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Login/selectLatest511.cs

286 lines
8.3 KiB
C#
Raw Normal View History

2024-11-14 18:25:21 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using System.Threading.Tasks;
/*public class selectLatest511 : MonoBehaviour
{
public static selectLatest511 instance;
public int gameEscapeId;
public int carrySeconds;
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD> gameEscapeId <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
public static event Action<int> OnGameEscapeIdUpdated;
void Start()
{
instance=this;
// <20><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD>¼ע<C2BC><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>¼<EFBFBD>󷵻ص<F3B7B5BB>token
// <20><><EFBFBD>˵<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ڴ˷<DAB4><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1>
// <20><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ص<EFBFBD><D8B5>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>token<65><6E><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD> gameEscapeId <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> HandleGameEscapeIdUpdated
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
}
private string token; // <20><><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD> token
void HandleTokenReceived(string token)
{
// ʹ<><CAB9> token
this.token = token;
Debug.Log("HandleTokenReceived<65><64><EFBFBD><EFBFBD>:" + token);
StartCoroutine(GameEscapeRoutine(token)); // <20><><EFBFBD><EFBFBD>Э<EFBFBD>̣<EFBFBD>ÿ2<C3BF><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>gameEscape
}
void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
Debug.Log("GameEscapeId <20>Ѹ<EFBFBD><D1B8><EFBFBD>Ϊ: " + newGameEscapeId);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫִ<D2AA>е<EFBFBD><D0B5>߼<EFBFBD>
}
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>IEnumerator<6F><72>Э<EFBFBD><D0AD>
IEnumerator GameEscapeRoutine(string token)
{
while (true) // <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>ÿ2<C3BF><EFBFBD><EBB7A2>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
yield return new WaitForSeconds(2f); // ÿ2<C3BF><32><EFBFBD><EFBFBD>ͣһ<CDA3><D2BB>
yield return LatestGame511(token); // <20><><EFBFBD><EFBFBD>gameEscape<70><65><EFBFBD><EFBFBD>
}
yield return null;
}
public async Task LatestGame511(string token)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ֵ
string Authorization = token;
//Debug.Log("Loding(Authorization)<29><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ֵ" + Authorization);
// 5.1<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ
Dictionary<string, string> head51 = new Dictionary<string, string>
{
{ "Authorization", Authorization }, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩͷ
};
string response51 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", head51);
Debug.Log("5.1<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ(<28><><EFBFBD><EFBFBD>)" + response51); // <20><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD>
// <20><><EFBFBD><EFBFBD>JSON<4F><4E><EFBFBD><EFBFBD>
string json = response51;
Response response = JsonConvert.DeserializeObject<Response>(json);
if (response != null && response.code == 200 && response.data != null)
{
gameEscapeId = response.data.gameEscapeModel.id;
//Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>idΪ: " + gameEscapeId);
carrySeconds= response.data.carrySeconds;
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
OnGameEscapeIdUpdated?.Invoke(gameEscapeId);
}
else
{
Debug.LogError("<22><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>");
}
}
void OnDestroy()
{
// ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
}
// Update is called once per frame
void Update()
{
}
[Serializable]
public class GameEscapeModel
{
public int id; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϷID
public string gameNo; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
}
[Serializable]
public class GameEscapeRoomResponseVo
{
public int escapeId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7>ID
public int roomNo; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
[Serializable]
public class Data
{
public int carrySeconds; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public GameEscapeModel gameEscapeModel; // Ƕ<>׵<EFBFBD>GameEscapeModel<65><6C><EFBFBD><EFBFBD>
public List<GameEscapeRoomResponseVo> gameEscapeRoomResponseVoList; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>б<EFBFBD>
public object gameEscapeUserModel; // <20>û<EFBFBD>ģ<EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>Ϊ<EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>
}
[Serializable]
public class Response
{
public int code; // ״̬<D7B4><CCAC>
public string message; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
public Data data; // <20><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
}
}*/
public class selectLatest511 : MonoBehaviour
{
public int gameEscapeId;
public int carrySeconds;
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD> gameEscapeId <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
public static event Action<int> OnGameEscapeIdUpdated;
private string token; // <20><><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD> token
void Start()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ȡ token
LoginAndGetToken.OnTokenReceived += HandleTokenReceived;
selectLatest511.OnGameEscapeIdUpdated += HandleGameEscapeIdUpdated;
}
void HandleTokenReceived(string token)
{
this.token = token;
Debug.Log("HandleTokenReceived<65><64><EFBFBD><EFBFBD>:" + token);
// һ<><D2BB>ʼ<EFBFBD><CABC>ȡ token ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> LatestGame511
LatestGame511(token).Wait();
// Ȼ<><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD>̣<EFBFBD>ÿ30<33><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> LatestGame511
StartCoroutine(GameEscapeRoutine(token));
}
void HandleGameEscapeIdUpdated(int newGameEscapeId)
{
Debug.Log("GameEscapeId <20>Ѹ<EFBFBD><D1B8><EFBFBD>Ϊ: " + newGameEscapeId);
}
IEnumerator GameEscapeRoutine(string token)
{
while (true)
{
yield return new WaitForSeconds(30f); // ÿ30<33><30><EFBFBD><EFBFBD>ͣһ<CDA3><D2BB>
yield return LatestGame511(token); // <20><><EFBFBD><EFBFBD> LatestGame511 <20><><EFBFBD><EFBFBD>
}
}
public async Task LatestGame511(string token)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ֵ
string Authorization = token;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
Dictionary<string, string> head511 = new Dictionary<string, string>
{
{ "Authorization", Authorization }
};
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󲢽<EFBFBD><F3B2A2BD><EFBFBD><EFBFBD><EFBFBD>Ӧ
string response511 = await web.SendRequest("http://121.40.42.41:8080/snail/LatestGame511/queryLatest", "POST", "{}", head511);
Debug.Log("5.1.1<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ" + response511);
// <20><><EFBFBD><EFBFBD>JSON<4F><4E><EFBFBD><EFBFBD>Ϊ Response <20><><EFBFBD><EFBFBD>
Response response = JsonConvert.DeserializeObject<Response>(response511);
if (response != null && response.code == 200 && response.data != null)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
gameEscapeId = response.data.gameEscapeModel.id;
carrySeconds = response.data.carrySeconds;
// ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
string gameNo = response.data.gameEscapeModel.gameNo;
float beansCoinAll = response.data.gameEscapeModel.beansCoinAll;
Debug.Log($"Game Escape ID: {gameEscapeId}");
Debug.Log($"Carry Seconds: {carrySeconds}");
Debug.Log($"Game No: {gameNo}");
Debug.Log($"Beans Coin All: {beansCoinAll}");
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
foreach (var room in response.data.gameEscapeRoomResponseVoList)
{
int roomNo = room.roomNo;
float roomBeansCoin = room.roomBeansCoin;
Debug.Log($"Room No: {roomNo}, Room Beans Coin: {roomBeansCoin}");
}
// <20><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
OnGameEscapeIdUpdated?.Invoke(gameEscapeId);
}
else
{
Debug.LogError("<22><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>");
}
}
void OnDestroy()
{
// ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
LoginAndGetToken.OnTokenReceived -= HandleTokenReceived;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[Serializable]
public class GameEscapeModel
{
public int id; // <20><>Ϸ ID
public string gameNo; // <20><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
public int demonMode;
public string startTime;
public string betTime;
public string countTime;
public string settleTime;
public int status;
public string roomNoKill;
public string roomNoRemain;
public float beansCoinAll;
public float beansCoinKill;
public float beansCoinRemain;
public float beansCoinFee;
public float beansCoinRank;
public float beansCoinDivide;
}
[Serializable]
public class GameEscapeRoomResponseVo
{
public int escapeId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7>ID
public int roomNo; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public float roomBeansCoin; // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
[Serializable]
public class Data
{
public int carrySeconds; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public GameEscapeModel gameEscapeModel; // Ƕ<>׵<EFBFBD>GameEscapeModel<65><6C><EFBFBD><EFBFBD>
public List<GameEscapeRoomResponseVo> gameEscapeRoomResponseVoList; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>б<EFBFBD>
public object gameEscapeUserModel; // <20>û<EFBFBD>ģ<EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>Ϊ<EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>
}
[Serializable]
public class Response
{
public int code; // ״̬<D7B4><CCAC>
public string message; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
public Data data; // <20><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
}
}