222 lines
8.0 KiB
C#
222 lines
8.0 KiB
C#
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using TMPro;
|
||
using Unity.VisualScripting.Antlr3.Runtime;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
|
||
public class BettingBtn : Base
|
||
{
|
||
public PlayerInfo playerCoinUpdate;//用于每次下注后更新左上角金币数
|
||
public static BettingBtn instance;
|
||
public GameObject BetList;
|
||
public Button NumBtn;
|
||
public Text BetText;
|
||
public float BetValue;//投注的值
|
||
public float AllBetValue;//投注总值
|
||
|
||
public Button BetButton;//投注的按钮
|
||
|
||
public GameObject text1;
|
||
public GameObject text2;
|
||
public GameObject text3;
|
||
public GameObject text4;
|
||
public GameObject text5;
|
||
public GameObject text6;
|
||
|
||
|
||
|
||
public List<GameObject> list=new List<GameObject>();
|
||
public TextMeshProUGUI SelfWoniuText;
|
||
|
||
public bool SuccessBet;//是否成功下注
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
instance = this;
|
||
BetList.SetActive(false);
|
||
NumBtn.onClick.AddListener(OnClickNumBtn);
|
||
BetValue = 50;//默认50
|
||
SetBet();
|
||
}
|
||
|
||
void OnClickNumBtn()
|
||
{
|
||
BetList.SetActive(true);
|
||
|
||
}
|
||
[System.Serializable]
|
||
public class RequestData
|
||
{
|
||
public int userId;
|
||
public int escapeId;
|
||
public float bet;
|
||
public int roomNo;
|
||
}
|
||
public GameObject bg;
|
||
public async void OnClickBetBtnAsync()
|
||
{
|
||
// bg.GetComponentInChildren<AllHouseContro>().battleRoyaleGameDetails();
|
||
|
||
|
||
RequestData body = new RequestData();
|
||
body.escapeId = bg.GetComponentInChildren<AllHouseContro>().escapeId;
|
||
body.bet = BetValue;
|
||
body.roomNo = bg.GetComponentInChildren<AllHouseContro>().roomNo;
|
||
body.userId = Global.global.serverResponse.data.userId;
|
||
//Debug.Log(bg.GetComponentInChildren<AllHouseContro>().house);
|
||
//bg.GetComponentInChildren<AllHouseContro>().house.text.GetComponent<TextBox>().AddText(BetValue);
|
||
|
||
|
||
string response = await web.SendRequest(web.URL + "/snail/gameEscape/userBet", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
|
||
Debug.Log("用户下注响应: " + response+"|||||"+"请求参数:escapeId"+ body.escapeId+" bet:"+ body.bet+ " roomNo:"+ body.roomNo+" userId:"+ body.userId);
|
||
ServerResponse513 serverResponse_513 = JsonConvert.DeserializeObject<ServerResponse513>(response);
|
||
if (serverResponse_513.code==200)
|
||
{
|
||
bg.GetComponentInChildren<AllHouseContro>().ReHouseText();//5.1.2
|
||
StartCoroutine(Tools.AnimateTextMashPro(PlayerInfo.instance.AllBetCoins, PlayerInfo.instance.AllBetCoins + BetValue, 0.5f, SelfWoniuText));//修改蜗牛头上文本
|
||
PlayerInfo.instance.AllBetCoins += BetValue;
|
||
PlayerInfo.instance.HaveBet = true;
|
||
|
||
//调用玩家信息,更新左上角蜗蛋数量
|
||
playerCoinUpdate.QueryPlayerInfo();
|
||
addEventPopUp(serverResponse_513.message);
|
||
//Debug.Log("-------投注成功-------");
|
||
//Promptmgr.Instance.PromptBubble(serverResponse_513.message);
|
||
}
|
||
else {
|
||
// Debug.Log("-------投注失败-------");
|
||
addEventPopUp(serverResponse_513.message);
|
||
//Promptmgr.Instance.PromptBubble(serverResponse_513.message);
|
||
}
|
||
|
||
Debug.Log("点击了下注按钮================================================" + playerCoinUpdate.Money);
|
||
|
||
}
|
||
|
||
public async void BetAgain(Action onComplete=null)
|
||
{
|
||
//bg.GetComponentInChildren<AllHouseContro>().battleRoyaleGameDetails();
|
||
|
||
|
||
RequestData body = new RequestData();
|
||
body.escapeId = bg.GetComponentInChildren<AllHouseContro>().escapeId;
|
||
//body.bet = PlayerInfo.instance.AllBetCoins;
|
||
body.bet = 0;
|
||
body.roomNo = bg.GetComponentInChildren<AllHouseContro>().roomNo;
|
||
|
||
body.userId = Global.global.serverResponse.data.userId;
|
||
|
||
|
||
string response = await web.SendRequest(web.URL + "/snail/gameEscape/userBet", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
|
||
Debug.Log("用户切换下注响应: " + response + "|||||" + "请求参数:escapeId" + body.escapeId + " bet:" + body.bet + " roomNo:" + body.roomNo + " userId:" + body.userId);
|
||
ServerResponse513 serverResponse_513 = JsonConvert.DeserializeObject<ServerResponse513>(response);
|
||
if (serverResponse_513.code == 200)
|
||
{
|
||
|
||
// Debug.Log("-------切换投注成功-------");
|
||
addEventPopUp(serverResponse_513.message);
|
||
//Promptmgr.Instance.PromptBubble(serverResponse_513.message);
|
||
onComplete?.Invoke();
|
||
bg.GetComponentInChildren<AllHouseContro>().ReHouseText();//5.1.2
|
||
}
|
||
else
|
||
{
|
||
addEventPopUp(serverResponse_513.message);
|
||
// Promptmgr.Instance.PromptBubble(serverResponse_513.message);
|
||
//Debug.Log("-------切换投注失败-------");
|
||
}
|
||
|
||
}
|
||
|
||
void SetBet()
|
||
{
|
||
// 获取所有的Button组件
|
||
Button[] buttons = BetList.GetComponentsInChildren<Button>();
|
||
|
||
// 遍历每一个Button,添加点击事件
|
||
foreach (Button button in buttons)
|
||
{
|
||
button.onClick.AddListener(() => {
|
||
BetText.text = button.transform.GetComponentInChildren<Text>().text;
|
||
BetValue = float.Parse(BetText.text);
|
||
BetList.SetActive(false);
|
||
});
|
||
}
|
||
}
|
||
|
||
public void GiveMoney(string room_id)
|
||
{
|
||
//float AllMoney = text1.GetComponent<TextBox>().ReturnText() + text2.GetComponent<TextBox>().ReturnText() + text3.GetComponent<TextBox>().ReturnText()
|
||
// + text4.GetComponent<TextBox>().ReturnText() + text5.GetComponent<TextBox>().ReturnText() + text6.GetComponent<TextBox>().ReturnText();
|
||
|
||
|
||
foreach (GameObject item in list)
|
||
{
|
||
if (item.GetComponent<TextBox>().ParentHouse.GetComponent<HouseBtn>().roomNo == int.Parse(room_id))
|
||
{
|
||
|
||
//item.GetComponent<TextBox>().ParentHouse.GetComponent<HouseBtn>().wn.GetComponent<wuniusj>().yingchang();
|
||
item.GetComponent<TextBox>().PlayAni();
|
||
//ControMoney(item);//分钱
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
public void ControMoney(GameObject text)
|
||
{
|
||
float giveMoney= text.GetComponent<TextBox>().ReturnText();
|
||
text.GetComponent<TextBox>().SetText(-giveMoney);
|
||
|
||
float AllMoney = text1.GetComponent<TextBox>().ReturnText() + text2.GetComponent<TextBox>().ReturnText() + text3.GetComponent<TextBox>().ReturnText()
|
||
+ text4.GetComponent<TextBox>().ReturnText() + text5.GetComponent<TextBox>().ReturnText() + text6.GetComponent<TextBox>().ReturnText();
|
||
|
||
for (int i=0;i<list.Count;i++)
|
||
{
|
||
if (list[i]==text)
|
||
{
|
||
continue;
|
||
}
|
||
list[i].GetComponent<TextBox>().SetText(giveMoney*(list[i].GetComponent<TextBox>().ReturnText()/AllMoney));
|
||
}
|
||
}
|
||
|
||
//public void GiveMoneyToPlayer()
|
||
//{
|
||
// switch (PlayerMovePos.instance.HouseId)
|
||
// {
|
||
// case 1:
|
||
// PlayerInfo.instance.SetMoney(text1.GetComponent<TextBox>().ReturnText()/2);
|
||
|
||
// break;
|
||
// case 2:
|
||
// PlayerInfo.instance.SetMoney(text2.GetComponent<TextBox>().ReturnText()/2);
|
||
// break;
|
||
// case 3:
|
||
// PlayerInfo.instance.SetMoney(text3.GetComponent<TextBox>().ReturnText() / 2);
|
||
// break;
|
||
// case 4:
|
||
// PlayerInfo.instance.SetMoney(text4.GetComponent<TextBox>().ReturnText()/2);
|
||
// break;
|
||
// case 5:
|
||
// PlayerInfo.instance.SetMoney(text5.GetComponent<TextBox>().ReturnText() / 2);
|
||
// break;
|
||
// case 6:
|
||
// PlayerInfo.instance.SetMoney(text6.GetComponent<TextBox>().ReturnText() / 2);
|
||
// break;
|
||
// default:
|
||
// Debug.Log("未选择房间");
|
||
// break;
|
||
// }
|
||
//}
|
||
}
|