| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using Photon.Pun;
- using System;
- using Hashtable = ExitGames.Client.Photon.Hashtable;
- using UnityEngine.EventSystems;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Globalization;
- public class ContinuousController : MonoBehaviour
- {
- [Header("game language")]
- // public Language language;
- [Header("Game version")]
- public float GameVer;
- [Header("ignore updates")]
- public bool IgnoreUpdate;
- [Header("card list")]
- public CEntity_Base[] CardList = new CEntity_Base[] { };
- [Header("Card list sorted by card ID")]
- public CEntity_Base[] SortedCardList = new CEntity_Base[] { };
- [Header("Card back image")]
- public Sprite ReverseCard;
- public Sprite ReverseCard_Digitama;
- [Header("SE prefab")]
- public SoundObject soundObject;
- [Header("deck code encryption")]
- public ShuffleDeckCode ShuffleDeckCode;
- DeckData _battleDeckData = null;
- public DeckData BattleDeckData
- {
- get
- {
- return _battleDeckData;
- }
- set
- {
- _battleDeckData = value;
- if (value != null)
- {
- LastBattleDeckData = value;
- }
- }
- }
- public DeckData LastBattleDeckData { get; private set; } = null;
- public bool NeedUpdate { get; set; }
- public bool isRandomMatch { get; set; }
- [HideInInspector] public List<SkillInfo> nullSkillInfos = null;
- public String GameVerString => Application.version;//GameVer.ToString(CultureInfo.InvariantCulture);
- #region Key for property to save deck data for battle
- public static string DeckDataPropertyKey => "BattleDeckData";
- #endregion
- #region Key for the property that stores the player name data
- public static string PlayerNameKey => "PlayerNameKey";
- #endregion
- #region Key for the property that stores the win count data
- public static string WinCountKey => "WinCountKey";
- #endregion
- [Header("Player name character limit")]
- public int PlayerNameMaxLength;
- #region Call up a scene for data storage
- public static IEnumerator LoadCoroutine()
- {
- if (instance == null)
- {
- SceneManager.LoadSceneAsync("ContinuousControllerScene", LoadSceneMode.Additive);
- while (instance == null)
- {
- yield return null;
- }
- instance.Init();
- }
- }
- #endregion
- #region List of Deck Recipes
- public List<DeckData> DeckDatas { get; set; } = new List<DeckData>();
- #endregion
- #region Deck Recipe Key
- public string DeckDatasPlayerPrefsKey { get { return "DeckDatas3"; } }
- #endregion
- public CEntity_Base DiaboromonToken { get; private set; }
- public CEntity_Base AmonToken { get; private set; }
- public CEntity_Base UmonToken { get; private set; }
- public CEntity_Base FujitsumonToken { get; private set; }
- public CEntity_Base GyuukimonToken { get; private set; }
- public CardRestriction BanList { get; private set; } = new CardRestriction(new List<CardLimitCount>(), new List<BannedPair>());
- void LoadBanList()
- {
- BanList = DataBase.ENGBanList;
- /*
- string banlistText = StreamingAssetsUtility.GetText("BanList");
- if (!string.IsNullOrEmpty(banlistText))
- {
- List<CEntity_Base> banlistDatasFromText = DeckCodeUtility.GetAllDeckCardsFromDeckBuilderDeckCode(banlistText, plusCount: 1);
- List<CEntity_Base> distinctBanlistDatas = banlistDatasFromText.Distinct().ToList();
- List<CardLimitCount> banlistDatas = new List<CardLimitCount>();
- foreach (CEntity_Base cEntity_Base in distinctBanlistDatas)
- {
- int maxCount = banlistDatasFromText.Count(cEntity_Base1 => cEntity_Base1.CardID == cEntity_Base.CardID);
- maxCount--;
- if (maxCount >= 0)
- {
- banlistDatas.Add(new CardLimitCount(cEntity_Base.CardID, maxCount));
- }
- }
- BanList = banlistDatas;
- }
- */
- }
- async Task CreateTokenData()
- {
- DiaboromonToken = new CEntity_Base()
- {
- cardColors = new List<CardColor>() { CardColor.White },
- PlayCost = 14,
- Level = 6,
- CardName_JPN = "ディアボロモン",
- CardName_ENG = "Diaboromon",
- Form_JPN = new List<string>() { "究極体" },
- Form_ENG = new List<string>() { "Mega" },
- Attribute_JPN = new List<string>() { "不明" },
- Attribute_ENG = new List<string>() { "Unknown" },
- Type_JPN = new List<string>() { "種族不明" },
- Type_ENG = new List<string>() { "Unidentified" },
- CardSpriteName = "BT2-082-token",
- cardKind = CardKind.Digimon,
- DP = 3000,
- };
- await DiaboromonToken.GetCardSprite();
- AmonToken = new CEntity_Base()
- {
- cardColors = new List<CardColor>() { CardColor.Red },
- PlayCost = -1,
- Level = 0,
- CardName_JPN = "紅炎のアモン",
- CardName_ENG = "Amon of Crimson Flame",
- Form_JPN = new List<string>(),
- Form_ENG = new List<string>(),
- Attribute_JPN = new List<string>(),
- Attribute_ENG = new List<string>(),
- Type_JPN = new List<string>(),
- Type_ENG = new List<string>(),
- CardSpriteName = "BT14-018-token-red",
- cardKind = CardKind.Digimon,
- DP = 6000,
- CardEffectClassName = "Bushiagumon_BT4_038"
- };
- await AmonToken.GetCardSprite();
- UmonToken = new CEntity_Base()
- {
- cardColors = new List<CardColor>() { CardColor.Yellow },
- PlayCost = -1,
- Level = 0,
- CardName_JPN = "蒼雷のウモン",
- CardName_ENG = "Umon of Blue Thunder",
- Form_JPN = new List<string>(),
- Form_ENG = new List<string>(),
- Attribute_JPN = new List<string>(),
- Attribute_ENG = new List<string>(),
- Type_JPN = new List<string>(),
- Type_ENG = new List<string>(),
- CardSpriteName = "BT14-018-token-yellow",
- cardKind = CardKind.Digimon,
- DP = 6000,
- CardEffectClassName = "Koemon_BT1_031"
- };
- await UmonToken.GetCardSprite();
- FujitsumonToken = new CEntity_Base()
- {
- cardColors = new List<CardColor>() { CardColor.Purple },
- PlayCost = -1,
- Level = 0,
- CardName_JPN = "フジツモン",
- CardName_ENG = "Fujitsumon",
- Form_JPN = new List<string>(),
- Form_ENG = new List<string>(),
- Attribute_JPN = new List<string>(),
- Attribute_ENG = new List<string>(),
- Type_JPN = new List<string>(),
- Type_ENG = new List<string>(),
- CardSpriteName = "EX5-058-token",
- cardKind = CardKind.Digimon,
- DP = 3000,
- CardEffectClassName = "Fujitsumon_EX5_058_token"
- };
- await FujitsumonToken.GetCardSprite();
- GyuukimonToken = new CEntity_Base()
- {
- cardColors = new List<CardColor>() { CardColor.Purple },
- PlayCost = 7,
- Level = 5,
- CardName_JPN = "ギュウキモン",
- CardName_ENG = "Gyuukimon",
- Form_JPN = new List<string>() { "究極の" },
- Form_ENG = new List<string>() { "Ultimate" },
- Attribute_JPN = new List<string>() { "ウイルス" },
- Attribute_ENG = new List<string>() { "Virus" },
- Type_JPN = new List<string>() { "ダークアニマル" },
- Type_ENG = new List<string>() { "Dark Animal" },
- CardSpriteName = "LM-018-token",
- cardKind = CardKind.Digimon,
- DP = 3000,
- };
- await GyuukimonToken.GetCardSprite();
- }
- public static ContinuousController instance = null;
- private void Awake()
- {
- instance = this;
- }
- public async void Init()
- {
- int random = RandomUtility.getRamdom();
- UnityEngine.Random.InitState(random);
- Debug.Log($"Game Initialize - random number sequence initialization,InitState:{random}");
- Sprite reverseCardSprite = await StreamingAssetsUtility.GetSprite("card_back_main");
- if (reverseCardSprite != null)
- {
- ReverseCard = reverseCardSprite;
- }
- Sprite reverseDigieggCardSprite = await StreamingAssetsUtility.GetSprite("card_back_sub");
- if (reverseDigieggCardSprite != null)
- {
- ReverseCard_Digitama = reverseDigieggCardSprite;
- }
- // deck data
- DeckDatas = PlayerPrefsUtil.LoadList<DeckData>(DeckDatasPlayerPrefsKey);
- ModifyAllDeckDatas();
- GetComponent<StarterDeck>().SetStarterDecks();
- SaveDeckDatas();
- // player data
- LoadPlayerName();
- LoadWinCount();
- // game play
- LoadAutoEffectOrder();
- LoadAutoDeckBottomOrder();
- LoadAutoDeckTopOrder();
- LoadAutoMinDigivolutionCost();
- LoadAutoMaxCardCount();
- LoadAutoHatch();
- LoadShowCutInAnimation();
- LoadReverseOpponentsCards();
- LoadTurnSuspendedCards();
- LoadCheckBeforeEndingSelection();
- LoadSuspendedCardsDirectionIsLeft();
- //Graphics
- LoadShowBackgroundParticle();
- // Sound
- LoadVolume();
- // ServerRegion
- LoadServerRegion();
- // Language
- LoadLanguage();
- await CreateTokenData();
- LoadBanList();
- DontDestroyOnLoad(gameObject);
- }
- public void ModifyAllDeckDatas()
- {
- List<DeckData> tempDeckDatas = new List<DeckData>();
- foreach (DeckData deckData in DeckDatas)
- {
- tempDeckDatas.Add(deckData);
- }
- foreach (DeckData deckData in tempDeckDatas)
- {
- if (deckData.AllDeckCards().Count == 0)
- {
- DeckDatas.Remove(deckData);
- }
- }
- for (int i = 0; i < DeckDatas.Count; i++)
- {
- //DeckData deckData = new DeckData(DeckData.GetDeckCode(DeckDatas[i].DeckName, DeckData.SortedDeckCardsList(DeckDatas[i].DeckCards()), DeckData.SortedDeckCardsList(DeckDatas[i].DigitamaDeckCards()), DeckDatas[i].KeyCard));
- DeckData deckData = DeckDatas[i];
- DeckDatas[i] = deckData.ModifiedDeckData();
- }
- SaveDeckDatas();
- }
- public void SaveDeckDatas()
- {
- PlayerPrefsUtil.SaveList(DeckDatasPlayerPrefsKey, DeckDatas);
- PlayerPrefs.Save();
- }
- #region Player Name
- string _playerName;
- string _playerNameKey = "PlayerName";
- public string PlayerName
- {
- get
- {
- if (string.IsNullOrEmpty(_playerName))
- {
- return "Player";
- }
- return _playerName;
- }
- set
- {
- _playerName = value;
- }
- }
- public void SavePlayerName(string playerName)
- {
- PlayerName = playerName;
- PlayerPrefs.SetString(_playerNameKey, playerName);
- PlayerPrefs.Save();
- }
- public void LoadPlayerName()
- {
- if (PlayerPrefs.HasKey(_playerNameKey))
- {
- PlayerName = PlayerPrefs.GetString(_playerNameKey);
- }
- if (string.IsNullOrEmpty(PlayerName))
- {
- PlayerName = "Player";
- }
- }
- #endregion
- #region number of victories
- public int WinCount { get; set; }
- string _winCountKey = "WinCount";
- public void SaveWinCount()
- {
- PlayerPrefs.SetInt(_winCountKey, WinCount);
- PlayerPrefs.Save();
- }
- public void LoadWinCount()
- {
- if (PlayerPrefs.HasKey(_winCountKey))
- {
- WinCount = PlayerPrefs.GetInt(_winCountKey);
- }
- }
- #endregion
- #region Auto effect order
- [HideInInspector] public bool autoEffectOrder = false;
- string _autoEffectOrderKey = "AutoEffectOrder";
- public void SaveAutoEffectOrder()
- {
- PlayerPrefsUtil.SetBool(_autoEffectOrderKey, autoEffectOrder);
- PlayerPrefs.Save();
- }
- public void LoadAutoEffectOrder()
- {
- autoEffectOrder = PlayerPrefsUtil.GetBool(_autoEffectOrderKey, false);
- }
- #endregion
- #region Auto deck bottom order
- [HideInInspector] public bool autoDeckBottomOrder = false;
- string _autoDeckBottomOrderKey = "AutoDeckBottomOrder";
- public void SaveAutoDeckBottomOrder()
- {
- PlayerPrefsUtil.SetBool(_autoDeckBottomOrderKey, autoDeckBottomOrder);
- PlayerPrefs.Save();
- }
- public void LoadAutoDeckBottomOrder()
- {
- autoDeckBottomOrder = PlayerPrefsUtil.GetBool(_autoDeckBottomOrderKey, false);
- }
- #endregion
- #region Auto deck top order
- [HideInInspector] public bool autoDeckTopOrder = false;
- string _autoDeckTopOrderKey = "AutoDeckTopOrder";
- public void SaveAutoDeckTopOrder()
- {
- PlayerPrefsUtil.SetBool(_autoDeckTopOrderKey, autoDeckTopOrder);
- PlayerPrefs.Save();
- }
- public void LoadAutoDeckTopOrder()
- {
- autoDeckTopOrder = PlayerPrefsUtil.GetBool(_autoDeckTopOrderKey, false);
- }
- #endregion
- #region Auto min digivolution cost
- [HideInInspector] public bool autoMinDigivolutionCost = false;
- string _autoMinDigivolutionCostKey = "AutoMinDigivolutionCost";
- public void SaveAutoMinDigivolutionCost()
- {
- PlayerPrefsUtil.SetBool(_autoMinDigivolutionCostKey, autoMinDigivolutionCost);
- PlayerPrefs.Save();
- }
- public void LoadAutoMinDigivolutionCost()
- {
- autoMinDigivolutionCost = PlayerPrefsUtil.GetBool(_autoMinDigivolutionCostKey, false);
- }
- #endregion
- #region Auto max card count
- [HideInInspector] public bool autoMaxCardCount = false;
- string _autoMaxCardCountKey = "AutoMaxCardCount";
- public void SaveAutoMaxCardCount()
- {
- PlayerPrefsUtil.SetBool(_autoMaxCardCountKey, autoMaxCardCount);
- PlayerPrefs.Save();
- }
- public void LoadAutoMaxCardCount()
- {
- autoMaxCardCount = PlayerPrefsUtil.GetBool(_autoMaxCardCountKey, false);
- }
- #endregion
- #region Auto hatch
- [HideInInspector] public bool autoHatch = false;
- string _autoHatchKey = "AutoHatch";
- public void SaveAutoHatch()
- {
- PlayerPrefsUtil.SetBool(_autoHatchKey, autoHatch);
- PlayerPrefs.Save();
- }
- public void LoadAutoHatch()
- {
- autoHatch = PlayerPrefsUtil.GetBool(_autoHatchKey, false);
- }
- #endregion
- #region Show CutIn Animation
- [HideInInspector] public bool showCutInAnimation = false;
- string _showCutInAnimationKey = "ShowCutInAnimation";
- public void SaveShowCutInAnimation()
- {
- PlayerPrefsUtil.SetBool(_showCutInAnimationKey, showCutInAnimation);
- PlayerPrefs.Save();
- }
- public void LoadShowCutInAnimation()
- {
- showCutInAnimation = PlayerPrefsUtil.GetBool(_showCutInAnimationKey, true);
- }
- #endregion
- #region Reverse opponents' cards
- [HideInInspector] public bool reverseOpponentsCards = false;
- string _reverseOpponentsCardsKey = "ReverseOpponentsCards";
- public void SaveReverseOpponentsCards()
- {
- PlayerPrefsUtil.SetBool(_reverseOpponentsCardsKey, reverseOpponentsCards);
- PlayerPrefs.Save();
- }
- public void LoadReverseOpponentsCards()
- {
- reverseOpponentsCards = PlayerPrefsUtil.GetBool(_reverseOpponentsCardsKey, false);
- }
- #endregion
- #region Turn suspended cards
- [HideInInspector] public bool turnSuspendedCards = false;
- string _turnSuspendedCardsKey = "TurnSuspendedCards";
- public void SaveTurnSuspendedCards()
- {
- PlayerPrefsUtil.SetBool(_turnSuspendedCardsKey, turnSuspendedCards);
- PlayerPrefs.Save();
- }
- public void LoadTurnSuspendedCards()
- {
- turnSuspendedCards = PlayerPrefsUtil.GetBool(_turnSuspendedCardsKey, true);
- }
- #endregion
- #region Check before ending selection
- [HideInInspector] public bool checkBeforeEndingSelection = false;
- string _checkBeforeEndingSelectionKey = "CheckBeforeEndingSelection";
- public void SaveCheckBeforeEndingSelection()
- {
- PlayerPrefsUtil.SetBool(_checkBeforeEndingSelectionKey, checkBeforeEndingSelection);
- PlayerPrefs.Save();
- }
- public void LoadCheckBeforeEndingSelection()
- {
- checkBeforeEndingSelection = PlayerPrefsUtil.GetBool(_checkBeforeEndingSelectionKey, true);
- }
- #endregion
- #region Suspended cards' direction is left
- [HideInInspector] public bool suspendedCardsDirectionIsLeft = false;
- string _suspendedCardsDirectionIsLeftKey = "SuspendedCardsDirectionIsLeft";
- public void SaveSuspendedCardsDirectionIsLeft()
- {
- PlayerPrefsUtil.SetBool(_suspendedCardsDirectionIsLeftKey, suspendedCardsDirectionIsLeft);
- PlayerPrefs.Save();
- }
- public void LoadSuspendedCardsDirectionIsLeft()
- {
- suspendedCardsDirectionIsLeft = PlayerPrefsUtil.GetBool(_suspendedCardsDirectionIsLeftKey, true);
- }
- #endregion
- #region Show background particle
- [HideInInspector] public bool showBackgroundParticle = false;
- string _showBackgroundParticleKey = "ShowBackgroundParticle";
- public void SaveShowBackgroundParticle()
- {
- PlayerPrefsUtil.SetBool(_showBackgroundParticleKey, showBackgroundParticle);
- PlayerPrefs.Save();
- }
- public void LoadShowBackgroundParticle()
- {
- showBackgroundParticle = PlayerPrefsUtil.GetBool(_showBackgroundParticleKey, true);
- }
- #endregion
- #region Sound volume
- public float BGMVolume { get; set; }
- public float SEVolume { get; set; }
- public void SetBGMVolume(float BGMVolume)
- {
- this.BGMVolume = BGMVolume;
- PlayerPrefs.SetFloat("BGMVolume", BGMVolume);
- PlayerPrefs.Save();
- }
- public void SetSEVolume(float SEVolume)
- {
- this.SEVolume = SEVolume;
- PlayerPrefs.SetFloat("SEVolume", SEVolume);
- PlayerPrefs.Save();
- }
- public void ChangeBGMVolume(AudioSource audioSource)
- {
- audioSource.volume = BGMVolume * 0.25f * 0.8f;
- }
- public void ChangeSEVolume(AudioSource audioSource)
- {
- audioSource.volume = SEVolume * 0.5f * 0.8f;
- }
- void LoadVolume()
- {
- BGMVolume = 0.5f;
- SEVolume = 0.5f;
- if (PlayerPrefs.HasKey("BGMVolume"))
- {
- BGMVolume = PlayerPrefs.GetFloat("BGMVolume");
- }
- if (PlayerPrefs.HasKey("SEVolume"))
- {
- SEVolume = PlayerPrefs.GetFloat("SEVolume");
- }
- }
- #endregion
- #region Server region
- [HideInInspector] public string serverRegion = "us";
- string _serverRegionKey = "ServerRegion";
- public void SaveServerRegion()
- {
- PlayerPrefs.SetString(_serverRegionKey, serverRegion);
- PlayerPrefs.Save();
- }
- public void LoadServerRegion()
- {
- serverRegion = PlayerPrefs.GetString(_serverRegionKey, "us");
- }
- public string LastConnectServerRegion = "";
- #endregion
- #region Language
- [HideInInspector] public Language language = Language.ENG;
- string _languageKey = "Language";
- public void SaveLanguage()
- {
- PlayerPrefs.SetString(_languageKey, language.ToString());
- PlayerPrefs.Save();
- }
- public void LoadLanguage()
- {
- language = (Language)Enum.Parse(typeof(Language), PlayerPrefs.GetString(_languageKey, "ENG"));
- }
- #endregion
- #region PlaySE(AudioClip clip)
- public SoundObject PlaySE(AudioClip clip)
- {
- SoundObject _soundObject = Instantiate(soundObject);
- _soundObject.PlaySE(clip);
- return _soundObject;
- }
- #endregion
- #region カードIndexからカードを取得
- public CEntity_Base getCardEntityByCardID(int cardIndex)
- {
- int searchIndex = cardIndex - 1;
- int count = 0;
- do
- {
- if (count != 0)
- {
- searchIndex += (int)Math.Pow(-1, count % 2) * count / 2;
- }
- if (0 <= searchIndex)
- {
- if (searchIndex <= SortedCardList.Length - 1)
- {
- CEntity_Base cEntity_Base = SortedCardList[searchIndex];
- if (cEntity_Base != null)
- {
- if (cEntity_Base.CardIndex == cardIndex)
- {
- return cEntity_Base;
- }
- }
- }
- else
- {
- for (int i = 0; i < 300; i++)
- {
- CEntity_Base cEntity_Base = SortedCardList[SortedCardList.Length - 1 - i];
- if (cEntity_Base != null)
- {
- if (cEntity_Base.CardIndex == cardIndex)
- {
- return cEntity_Base;
- }
- }
- }
- return null;
- }
- }
- if (count != 0)
- {
- searchIndex -= (int)Math.Pow(-1, count % 2) * count / 2;
- }
- count++;
- }
- while (count <= 20);
- return null;
- }
- #endregion
- public Coroutine LoadingTextCoroutine;
- bool _endBattle = false;
- public void EndBattle()
- {
- if (!_endBattle)
- {
- _endBattle = true;
- StartCoroutine(EndBattleCoroutine());
- }
- }
- public IEnumerator EndBattleCoroutine()
- {
- if (Opening.instance == null)
- {
- yield break;
- }
- Opening.instance.openingObject.SetActive(true);
- //yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
- //Camera camera1 = Camera.main;
- //Destroy(camera1.gameObject);
- //yield return null;
- isAI = false;
- int random = RandomUtility.getRamdom();
- UnityEngine.Random.InitState(random);
- Debug.Log($"random number sequence initialization, InitState:{random}");
- var unload = SceneManager.UnloadSceneAsync("BattleScene");
- yield return unload;
- yield return Resources.UnloadUnusedAssets();
- yield return StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
- //Opening.instance.MainCamera.gameObject.SetActive(true);
- foreach (Camera camera in Opening.instance.openingCameras)
- {
- camera.gameObject.SetActive(true);
- }
- Opening.instance.LoadingObject_light.gameObject.SetActive(false);
- yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SetPlayerName());
- if (isRandomMatch)
- {
- Debug.Log("Unload from Random Match");
- yield return StartCoroutine(Opening.instance.battle.lobbyManager_RandomMatch.CloseLobbyCoroutine());
- yield return StartCoroutine(Opening.instance.battle.selectBattleMode.SetUpSelectBattleModeCoroutine());
- }
- else
- {
- Debug.Log("Unload from Room Match");
- yield return StartCoroutine(Opening.instance.battle.roomManager.Init(true));
- yield return new WaitForSeconds(0.1f);
- }
- yield return new WaitWhile(() => GManager.instance != null);
- Opening.instance.LoadingObject.gameObject.SetActive(false);
- yield return StartCoroutine(Opening.instance.LoadingObject_Unload.EndLoading());
- _endBattle = false;
- if (!isRandomMatch)
- {
- Hashtable PlayerProp = PhotonNetwork.LocalPlayer.CustomProperties;
- if (PlayerProp.TryGetValue("isBattle", out object value))
- {
- PlayerProp["isBattle"] = false;
- }
- else
- {
- PlayerProp.Add("isBattle", false);
- }
- PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProp);
- }
- Scene newScene = SceneManager.GetSceneByName("Opening");
- SceneManager.SetActiveScene(newScene);
- for (int i = 0; i < 3; i++)
- {
- yield return new WaitForSeconds(0.1f);
- EventSystem.current.SetSelectedGameObject(Opening.instance.battle.selectBattleMode.transform.GetChild(0).gameObject);
- //Debug.Log("フォーカスを設定");
- }
- //GUI.UnfocusWindow();
- yield return null;
- //StartCoroutine(DestroyEffectCoroutine());
- if (Opening.instance.OpeningBGM != null)
- {
- if (!Opening.instance.OpeningBGM.isPlaying)
- {
- Opening.instance.OpeningBGM.StartPlayBGM(Opening.instance.bgm);
- }
- }
- }
- private void Update()
- {
- #if UNITY_WINDOWS
- if (Input.GetKey(KeyCode.Escape))
- {
- Application.Quit();
- }
- #endif
- }
- int _frameCount = 0;
- int _updateFrame = 40;
- void LateUpdate()
- {
- #region Update only once every few frames
- _frameCount++;
- if (_frameCount < _updateFrame)
- {
- return;
- }
- else
- {
- _frameCount = 0;
- }
- #endregion
- if (PhotonNetwork.InRoom)
- {
- if (!isAI)
- {
- bool notEnterOther = false;
- if (PhotonNetwork.PlayerList.Length == 1)
- {
- if (GManager.instance != null)
- {
- notEnterOther = true;
- }
- }
- if (notEnterOther)
- {
- if (PhotonNetwork.CurrentRoom.MaxPlayers != 1)
- {
- PhotonNetwork.CurrentRoom.MaxPlayers = 1;
- }
- }
- else
- {
- if (PhotonNetwork.CurrentRoom.MaxPlayers != 2)
- {
- PhotonNetwork.CurrentRoom.MaxPlayers = 2;
- }
- }
- }
- }
- }
- public bool isAI { get; set; } = false;
- //Flag that the sharing of the random number sequence is over.
- public bool DoneSetRandom { get; set; } = false;
- public bool CanSetRandom { get; set; } = false;
- [PunRPC]
- public void SetRandom(int random)
- {
- StartCoroutine(SetRandomCoroutine(random));
- }
- IEnumerator SetRandomCoroutine(int random)
- {
- yield return new WaitWhile(() => !CanSetRandom);
- UnityEngine.Random.InitState(random);
- DoneSetRandom = true;
- Debug.Log($"random number sequence initialization,InitState:{random}");
- }
- }
- #region Manage random numbers
- public static class RandomUtility
- {
- private static System.Random random;
- public static int getRamdom()
- {
- int _max = 1500000000;
- if (random == null)
- {
- random = new System.Random((int)DateTime.Now.Ticks);
- }
- return random.Next(0, _max);
- }
- #region IsSucceedProbability(float Probability)
- public static bool IsSucceedProbability(float Probability)
- {
- if (Probability >= 1)
- {
- return true;
- }
- if (Probability <= 0)
- {
- return false;
- }
- float random = UnityEngine.Random.Range(0f, 1f);
- if (random <= Probability)
- {
- return true;
- }
- return false;
- }
- #endregion
- #region Shuffle the deck
- public static List<CEntity_Base> ShuffledDeckCards(List<CEntity_Base> DeckCards)
- {
- List<CEntity_Base> CardDatas = new List<CEntity_Base>();
- foreach (CEntity_Base cEntity_Base in DeckCards)
- {
- CardDatas.Add(cEntity_Base);
- }
- // The initial value of integer n is the number of cards in the deck
- int n = CardDatas.Count;
- for (int i = 0; i < 20; i++)
- {
- // Repeat until n is less than 1
- while (n > 1)
- {
- n--;
- // k is a random value between 0 and n+1
- int k = UnityEngine.Random.Range(0, n + 1);
- // Assign the kth card to temp
- CEntity_Base temp = CardDatas[k];
- CardDatas[k] = CardDatas[n];
- CardDatas[n] = temp;
- }
- }
- return CardDatas;
- }
- public static List<CardSource> ShuffledDeckCards(List<CardSource> DeckCards)
- {
- List<CardSource> CardDatas = new List<CardSource>();
- foreach (CardSource cardSource in DeckCards)
- {
- CardDatas.Add(cardSource);
- }
- // 整数 n の初期値はデッキの枚数
- int n = CardDatas.Count;
- for (int i = 0; i < 20; i++)
- {
- // nが1より小さくなるまで繰り返す
- while (n > 1)
- {
- n--;
- // kは 0 ~ n+1 の間のランダムな値
- int k = UnityEngine.Random.Range(0, n + 1);
- // k番目のカードをtempに代入
- CardSource temp = CardDatas[k];
- CardDatas[k] = CardDatas[n];
- CardDatas[n] = temp;
- }
- }
- return CardDatas;
- }
- #endregion
- }
- #endregion
- #region Manage connections to Photon
- public class PhotonUtility
- {
- #region Disconnected from Photon
- public static IEnumerator DisconnectCoroutine()
- {
- #region Exit Room
- if (PhotonNetwork.InRoom)
- {
- PhotonNetwork.LeaveRoom();
- }
- yield return new WaitWhile(() => PhotonNetwork.InRoom);
- #endregion
- #region Exit from the lobby
- if (PhotonNetwork.InLobby)
- {
- PhotonNetwork.LeaveLobby();
- }
- yield return new WaitWhile(() => PhotonNetwork.InLobby);
- #endregion
- #region Disconnected from Photon
- if (PhotonNetwork.IsConnected)
- {
- PhotonNetwork.Disconnect();
- }
- yield return new WaitWhile(() => PhotonNetwork.IsConnected);
- #endregion
- }
- #endregion
- #region Connect to Photon server
- public static IEnumerator ConnectToMasterServerCoroutine()
- {
- if (!PhotonNetwork.IsConnected || ContinuousController.instance.LastConnectServerRegion != ContinuousController.instance.serverRegion)
- {
- if (PhotonNetwork.IsConnected)
- {
- yield return ContinuousController.instance.StartCoroutine(DisconnectCoroutine());
- yield return new WaitWhile(() => PhotonNetwork.IsConnected);
- }
- PhotonNetwork.NetworkingClient.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
- PhotonNetwork.ConnectToRegion(ContinuousController.instance.serverRegion);
- PhotonNetwork.NickName = ContinuousController.instance.PlayerName;
- PhotonNetwork.GameVersion = ContinuousController.instance.GameVerString;
- ContinuousController.instance.LastConnectServerRegion = ContinuousController.instance.serverRegion;
- }
- yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
- }
- #endregion
- #region Connect to Photon Server and Lobby
- public static IEnumerator ConnectToLobbyCoroutine()
- {
- #region Connect to Photon server
- yield return ContinuousController.instance.StartCoroutine(ConnectToMasterServerCoroutine());
- #endregion
- #region Save player name to custom properties
- yield return ContinuousController.instance.StartCoroutine(SetPlayerName());
- #endregion
- #region Save the number of wins to a custom property
- Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
- object value;
- hash = PhotonNetwork.LocalPlayer.CustomProperties;
- if (hash.TryGetValue(ContinuousController.WinCountKey, out value))
- {
- hash[ContinuousController.WinCountKey] = ContinuousController.instance.WinCount;
- }
- else
- {
- hash.Add(ContinuousController.WinCountKey, ContinuousController.instance.WinCount);
- }
- PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
- while (true)
- {
- Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
- if (_hash.TryGetValue(ContinuousController.WinCountKey, out value))
- {
- if ((int)value == ContinuousController.instance.WinCount)
- {
- break;
- }
- }
- yield return null;
- }
- #endregion
- #region Connect to Lobby
- if (!PhotonNetwork.InLobby)
- {
- PhotonNetwork.JoinLobby();
- }
- yield return new WaitWhile(() => !PhotonNetwork.InLobby);
- yield return new WaitUntil(() => PhotonNetwork.InLobby && PhotonNetwork.IsConnectedAndReady);
- #endregion
- }
- #endregion
- #region Save player name to properties
- public static IEnumerator SetPlayerName()
- {
- Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
- object value;
- hash = PhotonNetwork.LocalPlayer.CustomProperties;
- if (hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
- {
- hash[ContinuousController.PlayerNameKey] = ContinuousController.instance.PlayerName;
- }
- else
- {
- hash.Add(ContinuousController.PlayerNameKey, ContinuousController.instance.PlayerName);
- }
- PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
- while (true)
- {
- Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
- if (_hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
- {
- if ((string)value == ContinuousController.instance.PlayerName)
- {
- break;
- }
- }
- yield return null;
- }
- }
- #endregion
- #region Save deck data to custom properties
- public static IEnumerator SignUpBattleDeckData()
- {
- Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
- if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
- {
- hash[ContinuousController.DeckDataPropertyKey] = ContinuousController.instance.BattleDeckData.GetThisDeckCode();
- }
- else
- {
- hash.Add(ContinuousController.DeckDataPropertyKey, ContinuousController.instance.BattleDeckData.GetThisDeckCode());
- }
- //Debug.Log($"バトルデッキデータ登録,KeyCard:{ContinuousController.instance.BattleDeckData.KeyCard.CardName_JPN}");
- PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
- while (true)
- {
- Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
- if (_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
- {
- if ((string)value == ContinuousController.instance.BattleDeckData.GetThisDeckCode())
- {
- break;
- }
- }
- yield return null;
- }
- }
- #endregion
- #region Remove custom properties from deck data
- public static IEnumerator DeleteBattleDeckData()
- {
- Hashtable hash = PhotonNetwork.LocalPlayer.CustomProperties;
- if (hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out object value))
- {
- hash.Remove(ContinuousController.DeckDataPropertyKey);
- }
- PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
- while (true)
- {
- Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
- if (!_hash.TryGetValue(ContinuousController.DeckDataPropertyKey, out value))
- {
- break;
- }
- yield return null;
- }
- }
- #endregion
- }
- #endregion
- public enum Language
- {
- ENG,
- JPN,
- }
|