_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Battle_Royale/AllHouseContro.cs

184 lines
7.0 KiB
C#
Raw Normal View History

2024-11-15 23:31:54 +08:00
using Newtonsoft.Json;
2024-11-14 18:11:08 +08:00
using System.Collections;
using System.Collections.Generic;
2024-11-15 23:31:54 +08:00
using System.Threading.Tasks;
2024-11-14 18:11:08 +08:00
using UnityEditor;
using UnityEngine;
2024-11-15 23:31:54 +08:00
using UnityEngine.UI;
2024-11-16 02:05:07 +08:00
using UnityEngine.Windows;
2024-11-15 23:31:54 +08:00
using static UnityEditor.Progress;
using static UnityEngine.UIElements.UxmlAttributeDescription;
2024-11-14 18:11:08 +08:00
public class AllHouseContro : MonoBehaviour
{
public List<HouseBtn> HouseBtnList=new List<HouseBtn>();
2024-11-15 23:31:54 +08:00
public int roomNo = -1;
public int escapeId = -1;
public GameObject text;
public GameObject detailsText;
public HouseBtn house;
2024-11-16 02:05:07 +08:00
public List<GameObject> bossobj;
2024-11-14 18:11:08 +08:00
// Start is called before the first frame update
2024-11-15 23:31:54 +08:00
async void Start()
2024-11-14 18:11:08 +08:00
{
2024-11-15 23:31:54 +08:00
battleRoyaleGameDetails();
InvokeRepeating("checkOutAllTheEscapeRoomsAsync", 2,2);
2024-11-14 18:11:08 +08:00
}
2024-11-15 23:31:54 +08:00
void OnDestroy()
{
CancelInvoke("checkOutAllTheEscapeRoomsAsync");
}
public async Task battleRoyaleGameDetails()//5.1.1
{
foreach (HouseBtn item in HouseBtnList)
{
item.gameObject.GetComponentInChildren<Button>().onClick.RemoveAllListeners();
}
Dictionary<string, string> head511 = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
string response511 = await web.SendRequest(web.URL + "/snail/gameEscape/queryLatest", "POST", "{}", head511);
Debug.Log("5.1.1<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ" + response511);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
2024-11-16 02:05:07 +08:00
Global.global.response = JsonConvert.DeserializeObject<ServerResponse>(response511);
2024-11-15 23:31:54 +08:00
escapeId = Global.global.response.data.gameEscapeModel.id;
int index = 0;
foreach (GameEscapeRoomResponseVo item in Global.global.response.data.gameEscapeRoomResponseVoList)
{
HouseBtnList[index].escapeId = item.escapeId;
HouseBtnList[index].roomNo = item.roomNo;
HouseBtnList[index].roomBeansCoin = item.roomBeansCoin;
HouseBtn a = HouseBtnList[index];
HouseBtnList[index].gameObject.GetComponentInChildren<Button>().onClick.AddListener(() => {
roomNo = item.roomNo;
Debug.Log(a.gameObject.name);
house = a;
Debug.Log("=====-----" + item.roomNo.ToString());
});
HouseBtnList[index].gameObject.GetComponentInChildren<Button>().onClick.AddListener(HouseBtnList[index].OnClickBtn);
index++;
}
is_jisha_jiesuan = false;
is_jisha = false;
}
public bool is_jisha = false;
public bool is_jisha_jiesuan = false;
public async void checkOutAllTheEscapeRoomsAsync()//5.1.2
{
//Debug.Log("===");
userIDgameId body = new userIDgameId();
body.userId = Global.global.serverResponse.data.userId;
body.escapeId = escapeId;
string response = await web.SendRequest(web.URL+"/snail/gameEscape/queryEscapeRoomList", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
2024-11-16 02:05:07 +08:00
Debug.Log("5.1.2<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ: " + response);
2024-11-15 23:31:54 +08:00
ServerResponse serverResponse = JsonConvert.DeserializeObject<ServerResponse>(response);
int index = 0;
foreach (var item in serverResponse.data.gameEscapeRoomResponseVoList){
HouseBtnList[index].text.GetComponentInChildren<TextBox>().SetText(item.roomBeansCoin);
index++;
}
if(serverResponse.data.carrySeconds == -1)
{
detailsText.GetComponentInChildren<Text>().text = "<22><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
battleRoyaleGameDetails();
}
else if (serverResponse.data.carrySeconds < 45){
text.GetComponentInChildren<Text>().text = (60 - serverResponse.data.carrySeconds).ToString();
detailsText.GetComponentInChildren<Text>().text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
await Task.Delay(1000);
text.GetComponentInChildren<Text>().text = (60 - serverResponse.data.carrySeconds - 1).ToString();
}
else if (serverResponse.data.carrySeconds > 45 && serverResponse.data.carrySeconds < 50)
{
text.GetComponentInChildren<Text>().text = "";
detailsText.GetComponentInChildren<Text>().text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
if (!is_jisha){
is_jisha = true;
response = await web.SendRequest(web.URL + "/snail/gameEscape/queryKill", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
Debug.Log("5.1.4: " + response);
2024-11-16 02:05:07 +08:00
ServerResponse514 serverResponse_514 = JsonConvert.DeserializeObject<ServerResponse514>(response);
2024-11-15 23:41:28 +08:00
2024-11-16 02:05:07 +08:00
string[] parts = serverResponse_514.data.roomNoKill.Split(","); // <20><><EFBFBD><EFBFBD> ',' <20>ָ<EFBFBD><D6B8>ַ<EFBFBD><D6B7><EFBFBD>d
int index_ = 0;
foreach (string part in parts) {
if (parts.Length > index_)
{
int a = 0;
foreach (HouseBtn item in HouseBtnList)
{
if (a == int.Parse(parts[index_])) {
bossobj[index_].GetComponent<BossContro>().BossMove(int.Parse(parts[index_]));
bossobj[index_].GetComponent<PlayerMove>().room_id = parts[index_];
}
a++;
}
index_++;
}
}
2024-11-15 23:31:54 +08:00
}
}
else if (serverResponse.data.carrySeconds > 50) {
text.GetComponentInChildren<Text>().text = "";
detailsText.GetComponentInChildren<Text>().text = "<22><><EFBFBD><EFBFBD>";
if (!is_jisha_jiesuan)
{
is_jisha_jiesuan = true;
response = await web.SendRequest(web.URL + "/snail/gameEscape/queryUserBetResult", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
Debug.Log("5.1.5: " + response);
2024-11-16 02:05:07 +08:00
2024-11-15 23:31:54 +08:00
}
}
}
2024-11-14 18:11:08 +08:00
public void ControAllDoorOpen()
{
for (int i=0;i<HouseBtnList.Count;i++)
{
if (!HouseBtnList[i].DoorIsOpen)
{
Tools.MoveUpOrDwon(HouseBtnList[i].door,270);
HouseBtnList[i].DoorIsOpen = true;
}
}
}
public void ControAllDoorClose()
{
for (int i = 0; i < HouseBtnList.Count; i++)
{
if (HouseBtnList[i].DoorIsOpen)
{
Tools.MoveUpOrDwon(HouseBtnList[i].door, -270);
HouseBtnList[i].DoorIsOpen = false;
}
}
}
public void ControOneDoorOpen(int id,System.Action onComplete = null)
{
Tools.MoveUpOrDwon(HouseBtnList[id-1].door, 270,onComplete);
HouseBtnList[id-1].DoorIsOpen = true;
}
public void ControOneDoorClose(int id, System.Action onComplete = null)
{
Tools.MoveUpOrDwon(HouseBtnList[id - 1].door, -270, onComplete);
HouseBtnList[id - 1].DoorIsOpen = false;
}
}