_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Battle_Royale/AllHouseContro.cs
2024-11-18 18:52:31 +08:00

280 lines
10 KiB
C#

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Windows;
using static UnityEditor.Progress;
using static UnityEngine.UIElements.UxmlAttributeDescription;
public class AllHouseContro : MonoBehaviour
{
public PlayerInfo settlementCoinUpdate;//结算后更新左上角玩家金币数字===================================================================
public List<HouseBtn> HouseBtnList=new List<HouseBtn>();
public int roomNo = -1;
public int escapeId = -1;
public GameObject text;
public GameObject detailsText;
public HouseBtn house;
public List<GameObject> bossobj;
public HouseBtn BoosHouse;//Boos房间
public GameObject BazhuPanel;
public WarnPanel warnPanel;
public List<GameObject> wonnius = new List<GameObject>();
public Allother allother;//控制其他蜗牛
public bool HaveallotherMove;
// 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();
item.gameObject.GetComponentInChildren<Button>().onClick.AddListener(item.OnClickBtn);
//item.wn.GetComponent<wuniusj>().show();
}
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<ServerResponse>(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());
});
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){
ControAllDoorOpen();
text.GetComponentInChildren<Text>().text = (45 - serverResponse.data.carrySeconds).ToString();
detailsText.GetComponentInChildren<Text>().text = "秒后霸主出现";
await Task.Delay(1000);
text.GetComponentInChildren<Text>().text = (45 - serverResponse.data.carrySeconds - 1).ToString();
if (!HaveallotherMove)
{
StartCoroutine(allother.WoniuToMove());
HaveallotherMove = true;
//其他蜗牛进笼子
}
}
else if (serverResponse.data.carrySeconds > 45 && serverResponse.data.carrySeconds < 50)
{
ControAllDoorClose();//关门
OpenBoosDoor(BoosHouse);//boos开门
text.GetComponentInChildren<Text>().text = "";
detailsText.GetComponentInChildren<Text>().text = "霸主出现了";
if (!is_jisha){
is_jisha = true;
warnPanel.ShowPanel();
await Task.Delay(3000);
warnPanel.HidePanel();
response = await web.SendRequest(web.URL + "/snail/gameEscape/queryKill", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
//Debug.Log("5.1.4: " + response);
ServerResponse514 serverResponse_514 = JsonConvert.DeserializeObject<ServerResponse514>(response);
string[] parts = serverResponse_514.data.roomNoKill.Split(","); // 根据 ',' 分割字符串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_++;
}
else
{
Debug.Log("sdsdsdssssssssssssssss" + parts.Length);
}
}
}
}
else if (serverResponse.data.carrySeconds > 50) {
CloseBoosDoor(BoosHouse);
text.GetComponentInChildren<Text>().text = "";
detailsText.GetComponentInChildren<Text>().text = "结算";
PlayerInfo.instance.AllBetCoins = 0;//投注归0
PlayerInfo.instance.SelfWoniuText.text= PlayerInfo.instance.AllBetCoins.ToString();
PlayerInfo.instance.HaveBet=false;
HaveallotherMove=false;
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);
ServerResponse515 serverResponse_515 = JsonConvert.DeserializeObject<ServerResponse515>(response);
if (serverResponse_515.data==null)
{
Debug.Log("5.1.5:结算数据为空");
}
else
{
switch (serverResponse_515.data.outcome)
{
case 0:
Debug.Log("没有结果");
break;
case 1:
SucceePanel.instance.ShowPanel();
Debug.Log("胜利");
BoosReturn();
break;
case 2:
FailPanel.instance.ShowPanel();
Debug.Log("失败");
BoosReturn();
break;
}
settlementCoinUpdate.QueryPlayerInfo();
Debug.Log("结算后更新左上角玩家蜗蛋数量:===============================================" + settlementCoinUpdate.Money);
}
}
}
}
public void BoosReturn()
{
foreach (GameObject item in bossobj)//Boos回去
{
item.GetComponent<BossContro>().ReturnParent();
}
}
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;
}
public void OpenBoosDoor(HouseBtn boosHouse)
{
if (!boosHouse.DoorIsOpen)
{
Tools.MoveUpOrDwon(boosHouse.door, 270);
boosHouse.DoorIsOpen = true;
}
}
public void CloseBoosDoor(HouseBtn boosHouse)
{
if (boosHouse.DoorIsOpen)
{
Tools.MoveUpOrDwon(boosHouse.door, -270);
boosHouse.DoorIsOpen = false;
}
}
}