525 lines
18 KiB
C#
525 lines
18 KiB
C#
using Newtonsoft.Json;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Unity.VisualScripting;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Windows;
|
|
using static BettingBtn;
|
|
using static UnityEditor.Progress;
|
|
|
|
|
|
public class AllHouseContro : MonoBehaviour
|
|
{
|
|
public PlayerInfo settlementCoinUpdate;//结算后更新左上角玩家金币数字===================================================================
|
|
public List<HouseBtn> HouseBtnList=new List<HouseBtn>();
|
|
public int roomNo = -1;
|
|
public int escapeId = -1;
|
|
public string gameNo;
|
|
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;
|
|
|
|
public List<otherWoniu> otherWoniusList=new List<otherWoniu>();//其他蜗牛列表
|
|
public PlayerMove player;//玩家
|
|
|
|
public bool HaveLoad;
|
|
|
|
public HistoryPanel historyPanel;
|
|
|
|
public bool IsLoadIn;//是否已经进入游戏
|
|
public bool IsHideLoadPanel;//是否关闭加载页面
|
|
// Start is called before the first frame update
|
|
async void Start()
|
|
{
|
|
battleRoyaleGameDetails();
|
|
GetInfo516();
|
|
InvokeRepeating("checkOutAllTheEscapeRoomsAsync", 2,2);
|
|
}
|
|
void OnDestroy()
|
|
{
|
|
CancelInvoke("checkOutAllTheEscapeRoomsAsync");
|
|
}
|
|
|
|
public async Task ReGet511()
|
|
{
|
|
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;
|
|
gameNo = Global.global.response.data.gameEscapeModel.gameNo;
|
|
int index = 0;
|
|
if (Global.global.response.data.gameEscapeRoomResponseVoList.Count>0)
|
|
{
|
|
foreach (GameEscapeRoomResponseVo item in Global.global.response.data.gameEscapeRoomResponseVoList)
|
|
{
|
|
|
|
if (HouseBtnList[index].roomNo == item.roomNo)
|
|
{
|
|
HouseBtnList[index].escapeId = item.escapeId;
|
|
HouseBtnList[index].roomBeansCoin = item.roomBeansCoin;
|
|
}
|
|
index++;
|
|
//HouseBtnList[index].roomNo = item.roomNo;
|
|
|
|
//HouseBtn a = HouseBtnList[index];
|
|
//HouseBtnList[index].gameObject.GetComponentInChildren<Button>().onClick.AddListener(() => {
|
|
// roomNo = item.roomNo;
|
|
// Debug.Log("所在房间Id" + roomNo);
|
|
// Debug.Log(a.gameObject.name);
|
|
// house = a;
|
|
// Debug.Log("=====-----" + item.roomNo.ToString());
|
|
//});
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
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.gameObject.GetComponentInChildren<Button>().onClick.AddListener(() => {
|
|
// // roomNo = item.roomNo;
|
|
|
|
// //});
|
|
// //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;
|
|
gameNo = Global.global.response.data.gameEscapeModel.gameNo;
|
|
int index = 0;
|
|
if (Global.global.response.data.gameEscapeRoomResponseVoList.Count > 0)
|
|
{
|
|
foreach (GameEscapeRoomResponseVo item in Global.global.response.data.gameEscapeRoomResponseVoList)
|
|
{
|
|
|
|
if (HouseBtnList[index].roomNo == item.roomNo)
|
|
{
|
|
HouseBtnList[index].escapeId = item.escapeId;
|
|
HouseBtnList[index].roomBeansCoin = item.roomBeansCoin;
|
|
}
|
|
index++;
|
|
//HouseBtnList[index].roomNo = item.roomNo;
|
|
|
|
//HouseBtn a = HouseBtnList[index];
|
|
//HouseBtnList[index].gameObject.GetComponentInChildren<Button>().onClick.AddListener(() => {
|
|
// roomNo = item.roomNo;
|
|
// Debug.Log("所在房间Id" + roomNo);
|
|
// Debug.Log(a.gameObject.name);
|
|
// house = a;
|
|
// Debug.Log("=====-----" + item.roomNo.ToString());
|
|
//});
|
|
|
|
|
|
}
|
|
}
|
|
is_jisha_jiesuan = false;
|
|
is_jisha = false;
|
|
|
|
IsLoadIn = true;
|
|
//StartCoroutine(LoadPanel.instance.ToHidePanel());
|
|
}
|
|
public bool is_jisha = false;
|
|
public bool is_jisha_jiesuan = false;
|
|
|
|
|
|
|
|
|
|
public async void ReHouseText()//刷新房间文本
|
|
{
|
|
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查询逃亡房间 请求:" + JsonUtility.ToJson(body) + " 详情响应: " + response);
|
|
ServerResponse serverResponse = JsonConvert.DeserializeObject<ServerResponse>(response);
|
|
//int index = 0;
|
|
foreach (var item in serverResponse.data.gameEscapeRoomResponseVoList)
|
|
{
|
|
foreach (HouseBtn houseBtn in HouseBtnList)
|
|
{
|
|
if (houseBtn.roomNo == item.roomNo)
|
|
{
|
|
houseBtn.roomBeansCoin = item.roomBeansCoin;
|
|
houseBtn.roomUserNo = item.roomUserNo;
|
|
houseBtn.text.GetComponentInChildren<TextBox>().SetText(item.roomBeansCoin);
|
|
|
|
}
|
|
}
|
|
//if (HouseBtnList.Count > index)
|
|
//{
|
|
|
|
// HouseBtnList[index].text.GetComponentInChildren<TextBox>().SetText(item.roomBeansCoin);
|
|
//}
|
|
|
|
//index++;
|
|
}
|
|
Debug.Log("更新房间蜗牛蛋");
|
|
}
|
|
|
|
public async void checkOutAllTheEscapeRoomsAsync()//5.1.2
|
|
{
|
|
|
|
|
|
//foreach (HouseBtn house in HouseBtnList)
|
|
//{
|
|
// house.GetComponentInChildren<Button>().onClick.AddListener(() => {
|
|
// roomNo = house.roomNo;
|
|
// Debug.Log("所在房间Id" + roomNo);
|
|
|
|
// });
|
|
//}
|
|
|
|
|
|
//GetInfo516();
|
|
//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查询逃亡房间 请求:"+ JsonUtility.ToJson(body) +" 详情响应: " + response);
|
|
ServerResponse serverResponse = JsonConvert.DeserializeObject<ServerResponse>(response);
|
|
//int index = 0;
|
|
foreach (var item in serverResponse.data.gameEscapeRoomResponseVoList){
|
|
foreach (HouseBtn houseBtn in HouseBtnList)
|
|
{
|
|
if (houseBtn.roomNo==item.roomNo)
|
|
{
|
|
houseBtn.roomBeansCoin = item.roomBeansCoin;
|
|
houseBtn.roomUserNo = item.roomUserNo;
|
|
houseBtn.text.GetComponentInChildren<TextBox>().SetText(item.roomBeansCoin);
|
|
|
|
}
|
|
}
|
|
//if (HouseBtnList.Count > index)
|
|
//{
|
|
|
|
// HouseBtnList[index].text.GetComponentInChildren<TextBox>().SetText(item.roomBeansCoin);
|
|
//}
|
|
|
|
//index++;
|
|
}
|
|
Debug.Log("更新房间蜗牛蛋");
|
|
if(serverResponse.data.carrySeconds == -1)
|
|
{
|
|
//OtherBack();
|
|
|
|
|
|
|
|
detailsText.GetComponentInChildren<Text>().text = "";//游戏结束
|
|
battleRoyaleGameDetails();
|
|
|
|
LoadPanel.instance.ShowPanel();
|
|
CanMoveWoniu();//允许蜗牛移动
|
|
ClearText();
|
|
//ReHouseText();
|
|
BoosReturn();
|
|
player.ReturnStartPos();
|
|
allother.Reflash();//假蜗牛随机
|
|
allother.ClearAllWoniu();
|
|
IsHideLoadPanel = false;
|
|
GetInfo516();
|
|
PlayerInfo.instance.AllBetCoins = 0;//投注归0
|
|
}
|
|
else if (serverResponse.data.carrySeconds < 45){
|
|
|
|
if (IsLoadIn && !IsHideLoadPanel&& serverResponse.data.carrySeconds <38)//关闭加载页面
|
|
{
|
|
LoadPanel.instance.HidePanel();
|
|
IsHideLoadPanel = true;
|
|
HaveallotherMove = false;
|
|
}
|
|
|
|
//ClearBoosHouseId();//清空boos房间号
|
|
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();
|
|
|
|
|
|
allother.startIEmove();//生成其他蜗牛
|
|
//if (!HaveallotherMove)
|
|
//{
|
|
// //StartCoroutine(allother.IECreateWoniu());
|
|
|
|
|
|
// HaveallotherMove = true;
|
|
// //其他蜗牛进笼子
|
|
//}
|
|
|
|
}
|
|
else if (serverResponse.data.carrySeconds > 45 && serverResponse.data.carrySeconds < 50)
|
|
{
|
|
StopWoniu();
|
|
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);
|
|
}
|
|
|
|
}
|
|
|
|
//击杀刷新房间蛋
|
|
//checkOutAllTheEscapeRoomsAsync();
|
|
|
|
}
|
|
}
|
|
else if (serverResponse.data.carrySeconds > 56) {
|
|
|
|
CloseBoosDoor(BoosHouse);
|
|
ClearBoosHouseId();////
|
|
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;
|
|
|
|
|
|
|
|
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("没有结果");
|
|
|
|
//BoosReturn();
|
|
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 async void GetInfo516()
|
|
{
|
|
|
|
string response = await web.SendRequest(web.URL + "/snail/gameEscape/queryLatestRecord", "POST", null, Global.global.CreateHeaders());
|
|
Debug.Log("5.1.6: " + response);
|
|
ServerResponse516 serverResponse_516 = JsonConvert.DeserializeObject<ServerResponse516>(response);
|
|
Debug.Log(serverResponse_516.data.gameEscapeRoomKillCountResponseVoList[0].roomNo+"sdsdddddddddddddddddddddddddddddddd");
|
|
foreach (gameEscapeRoomKillCountResponseVo item in serverResponse_516.data.gameEscapeRoomKillCountResponseVoList)
|
|
{
|
|
historyPanel.SetKilledText(item);
|
|
}
|
|
//historyPanel.SetKilledText(serverResponse_516.data.gameEscapeRoomKillCountResponseVoList);
|
|
foreach (gameEscapeModel item in serverResponse_516.data.gameEscapeModelList)
|
|
{
|
|
|
|
if (item.gameNo == gameNo)
|
|
{
|
|
historyPanel.SetKillHouse(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void OtherBack()
|
|
{
|
|
foreach (otherWoniu item in otherWoniusList)
|
|
{
|
|
|
|
item.BackWait();
|
|
Debug.Log("other回去");
|
|
}
|
|
}
|
|
|
|
public void StopWoniu()//禁止玩家移动
|
|
{
|
|
foreach (HouseBtn item in HouseBtnList)
|
|
{
|
|
item.gameObject.GetComponentInChildren<Button>().enabled=false;
|
|
}
|
|
}
|
|
public void CanMoveWoniu()//允许玩家移动
|
|
{
|
|
foreach (HouseBtn item in HouseBtnList)
|
|
{
|
|
item.gameObject.GetComponentInChildren<Button>().enabled=true;
|
|
|
|
}
|
|
}
|
|
|
|
public void ClearBoosHouseId()
|
|
{
|
|
foreach (GameObject item in bossobj)//Boos回去
|
|
{
|
|
|
|
item.transform.GetComponent<BossContro>().HouseId = -1;
|
|
|
|
}
|
|
}
|
|
|
|
public async void BoosReturn()
|
|
{
|
|
foreach (GameObject item in bossobj)//Boos回去
|
|
{
|
|
await Task.Delay(100);
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
public void ClearText()//本地手动清零
|
|
{
|
|
foreach (HouseBtn houseBtn in HouseBtnList)
|
|
{
|
|
|
|
houseBtn.text.GetComponentInChildren<TextBox>().SetText(0);
|
|
|
|
|
|
}
|
|
}
|
|
}
|