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

159 lines
5.9 KiB
C#

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using static UnityEditor.Progress;
using static UnityEngine.UIElements.UxmlAttributeDescription;
public class AllHouseContro : MonoBehaviour
{
public List<HouseBtn> HouseBtnList=new List<HouseBtn>();
public int roomNo = -1;
public int escapeId = -1;
public GameObject text;
public GameObject detailsText;
public HouseBtn house;
// Start is called before the first frame update
async void Start()
{
battleRoyaleGameDetails();
InvokeRepeating("checkOutAllTheEscapeRoomsAsync", 2,2);
}
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查询最近一场大屠杀" + response511);
// 解析服务器返回的数据
Global.global.response = JsonConvert.DeserializeObject<Response>(response511);
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());
//Debug.Log("5.1.2查询逃亡房间详情响应: " + response);
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 = "游戏结束了";
battleRoyaleGameDetails();
}
else if (serverResponse.data.carrySeconds < 45){
text.GetComponentInChildren<Text>().text = (60 - serverResponse.data.carrySeconds).ToString();
detailsText.GetComponentInChildren<Text>().text = "秒后霸主出现";
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 = "霸主出现了";
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);
}
}
else if (serverResponse.data.carrySeconds > 50) {
text.GetComponentInChildren<Text>().text = "";
detailsText.GetComponentInChildren<Text>().text = "结算";
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);
}
}
}
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;
}
}