Пример #1
0
        private List <DeckSlot> CreateDeckSlots()
        {
            List <DeckSlot> list = new List <DeckSlot>();
            God             god  = PlayerData.instance.god;
            int             id   = m_currentWeapon.get_id();

            if (RuntimeData.squadDefinitions.TryGetValue(m_currentWeapon.defaultDeck.value, out SquadDefinition value))
            {
                DeckInfo deckInfo = value.ToDeckInfo();
                deckInfo.Id = -value.get_id();
                list.Add(new DeckSlot(deckInfo.FillEmptySlotsCopy(), preconstructed: true));
            }
            foreach (DeckInfo deck in PlayerData.instance.GetDecks())
            {
                if (deck.God == (int)god && deck.Weapon == id)
                {
                    list.Add(new DeckSlot(deck.Clone().FillEmptySlotsCopy()));
                    if (list.Count >= 4)
                    {
                        break;
                    }
                }
            }
            int i = list.Count;

            for (int num = 4; i < num; i++)
            {
                DeckInfo deckInfo2 = new DeckInfo().FillEmptySlotsCopy();
                deckInfo2.Name   = RuntimeData.FormattedText(92537);
                deckInfo2.God    = (int)god;
                deckInfo2.Weapon = id;
                list.Add(new DeckSlot(deckInfo2));
            }
            return(list);
        }
Пример #2
0
    public void TrySave()
    {
        if (pClass == "")
        {
            errorMessage.text = "Save Failed: Invalid Class";
            errorMessage.gameObject.SetActive(true);
            return;
        }

        if (!ValidateCardNums())
        {
            errorMessage.text = "Save Failed: Amount of certain cards is invalid. It can be 0, 1, or 2; and only for listed cards.";
            errorMessage.gameObject.SetActive(true);
            return;
        }

        string deckSizeStr = GameInfo.deckSize.ToString();

        if (cardSum.text != (deckSizeStr + "/" + deckSizeStr))
        {
            errorMessage.text = "Save Failed: Total amount of cards is invalid. It must be " + deckSizeStr;
            errorMessage.gameObject.SetActive(true);
            return;
        }

        errorMessage.text = "Success! Saved " + pClass + " deck.";
        errorMessage.gameObject.SetActive(true);

        DeckInfo deckInfo = new DeckInfo(pClass, GetDeckFromUI());
        string   json     = JsonUtility.ToJson(deckInfo);

        Directory.CreateDirectory(Application.dataPath + "/SaveData");
        File.WriteAllText(ClassFileLocation(), json);
    }
Пример #3
0
        public static DeckInfo EnsureDataConsistency(this DeckInfo deck)
        {
            RepeatedField <int> spells = deck.Spells;

            for (int num = spells.get_Count() - 1; num >= 0; num--)
            {
                int key = spells.get_Item(num);
                if (!RuntimeData.spellDefinitions.TryGetValue(key, out SpellDefinition _))
                {
                    spells.RemoveAt(num);
                }
            }
            RepeatedField <int> companions = deck.Companions;

            for (int num2 = companions.get_Count() - 1; num2 >= 0; num2--)
            {
                int key2 = companions.get_Item(num2);
                if (!RuntimeData.companionDefinitions.TryGetValue(key2, out CompanionDefinition _))
                {
                    companions.RemoveAt(num2);
                }
            }
            if (!RuntimeData.weaponDefinitions.TryGetValue(deck.Weapon, out WeaponDefinition _))
            {
                deck.Weapon = 0;
            }
            return(deck);
        }
Пример #4
0
        public static DeckInfo ToDeckInfo(this SquadDefinition definition)
        {
            if (!RuntimeData.weaponDefinitions.TryGetValue(definition.weapon.value, out WeaponDefinition value))
            {
                return(null);
            }
            DeckInfo deckInfo = new DeckInfo
            {
                Name   = RuntimeData.FormattedText(63105),
                God    = (int)value.god,
                Weapon = value.get_id()
            };
            IReadOnlyList <Id <CompanionDefinition> > companions = definition.companions;
            int i = 0;

            for (int count = companions.Count; i < count; i++)
            {
                if (RuntimeData.companionDefinitions.TryGetValue(companions[i].value, out CompanionDefinition _))
                {
                    deckInfo.Companions.Add(companions[i].value);
                }
            }
            IReadOnlyList <Id <SpellDefinition> > spells = definition.spells;
            int j = 0;

            for (int count2 = spells.Count; j < count2; j++)
            {
                if (RuntimeData.spellDefinitions.TryGetValue(spells[j].value, out SpellDefinition _))
                {
                    deckInfo.Spells.Add(spells[j].value);
                }
            }
            return(deckInfo);
        }
Пример #5
0
        public static int GetLevel(this DeckInfo info, ILevelProvider weaponLevelProvider)
        {
            int level = 0;

            weaponLevelProvider.TryGetLevel(info.Weapon, out level);
            return(Math.Max(1, level));
        }
Пример #6
0
        public string InsertPreconstructedDeckCardsInDb(string url, PreconstructedDeckImporter preconstructedDeckImporter)
        {
            string html = _webAccess.GetHtml(url);

            DeckInfo deckInfo = preconstructedDeckImporter.ParseDeckPage(html);

            if (deckInfo == null)
            {
                return(null);
            }

            MagicDatabase.InsertNewPreconstructedDeck(deckInfo.IdEdition, deckInfo.Name, url);
            IPreconstructedDeck preconstructedDeck = MagicDatabase.GetPreconstructedDeck(deckInfo.IdEdition, deckInfo.Name);

            foreach (DeckCardInfo deckCardInfo in deckInfo.Cards)
            {
                if (deckCardInfo.NeedToCreate)
                {
                    int idGatherer = MagicDatabase.InsertNewCardEditionWithFakeGathererId(deckCardInfo.IdEdition, deckCardInfo.IdCard, deckCardInfo.IdRarity, deckCardInfo.PictureUrl);
                    MagicDatabase.InsertOrUpdatePreconstructedDeckCardEdition(preconstructedDeck.Id, idGatherer, deckCardInfo.Number);
                }
                else
                {
                    MagicDatabase.InsertOrUpdatePreconstructedDeckCardEdition(preconstructedDeck.Id, deckCardInfo.IdGatherer, deckCardInfo.Number);
                }
            }
            return(null);
        }
Пример #7
0
 public void SetCurrentDeck(DeckInfo deckInfo)
 {
     if (m_decksDropDown != null)
     {
         m_decksDropDown.value = m_deckList.IndexOf(deckInfo);
     }
 }
Пример #8
0
        private void InitDecks()
        {
            m_deckList = new List <DeckInfo>();
            m_decksDropDown.ClearOptions();
            God god           = PlayerData.instance.god;
            int currentWeapon = PlayerData.instance.GetCurrentWeapon();

            if (RuntimeData.weaponDefinitions.TryGetValue(currentWeapon, out WeaponDefinition value))
            {
                if (RuntimeData.squadDefinitions.TryGetValue(value.defaultDeck.value, out SquadDefinition value2))
                {
                    DeckInfo deckInfo = value2.ToDeckInfo();
                    deckInfo.Id = -value2.get_id();
                    m_deckList.Add(deckInfo);
                }
                foreach (DeckInfo deck in PlayerData.instance.GetDecks())
                {
                    if (deck.Weapon == currentWeapon)
                    {
                        m_deckList.Add(deck);
                    }
                }
                int selectedDeckId = PlayerData.instance.GetSelectedDeckByWeapon(value.get_id());
                int num            = -1;
                num = m_deckList.FindIndex((DeckInfo deck) => deck.Id == selectedDeckId);
                if (m_decksDropDown != null)
                {
                    m_decksDropDown.AddOptions((from sd in m_deckList
                                                select sd.Name).ToList());
                    m_decksDropDown.value = num;
                }
            }
        }
Пример #9
0
        public void Populate(List <DeckSlot> deckSlots, WeaponDefinition weapon)
        {
            m_definition = weapon;
            int index = 0;
            int selectedDeckForWeapon = m_modifications.GetSelectedDeckForWeapon(weapon.get_id());

            for (int i = 0; i < deckSlots.Count; i++)
            {
                m_presets[i].ForceSelect(selected: false);
                DeckSlot deckSlot = deckSlots[i];
                if (deckSlot.DeckInfo != null && deckSlot.DeckInfo.Id.HasValue && deckSlot.DeckInfo.Id.Value == selectedDeckForWeapon)
                {
                    index = i;
                }
                DeckInfo deckInfo = deckSlot.DeckInfo;
                int      num;
                bool     isAvailableEmptyDeckSlot;
                if (deckInfo == null || !deckInfo.Id.HasValue)
                {
                    num = 1;
                }
                else
                {
                    isAvailableEmptyDeckSlot = deckSlot.isAvailableEmptyDeckSlot;
                }
                m_presets[i].Populate(deckSlot, selectedDeckForWeapon);
            }
            m_presets[index].ForceSelect();
        }
Пример #10
0
        public static DeckInfo TrimCopy(this DeckInfo info, int defaultValue = -1)
        {
            DeckInfo deckInfo = new DeckInfo
            {
                Id     = info.Id,
                Name   = info.Name,
                God    = info.God,
                Weapon = info.Weapon
            };
            RepeatedField <int> companions = info.Companions;
            int i = 0;

            for (int count = companions.get_Count(); i < count; i++)
            {
                if (companions.get_Item(i) != defaultValue)
                {
                    deckInfo.Companions.Add(companions.get_Item(i));
                }
            }
            RepeatedField <int> spells = info.Spells;
            int j = 0;

            for (int count2 = spells.get_Count(); j < count2; j++)
            {
                if (spells.get_Item(j) != defaultValue)
                {
                    deckInfo.Spells.Add(spells.get_Item(j));
                }
            }
            return(deckInfo);
        }
Пример #11
0
    public void DoneButtonHandler()
    {
        DeckInfo deckToSave = new DeckInfo(_deckList, DeckName.text, _buildingForCharacter);

        DecksStorage.Instance.AllDecks.Add(deckToSave);
        DecksStorage.Instance.SaveDecksIntoPlayerPrefs();
        DeckBuildingScreen.Instance.ShowScreenForCollectionBrowsing();
    }
Пример #12
0
    public void ApplyLookToIcon(DeckInfo info)
    {
        DeckInformation = info;
        DeckNotCompleteObject.SetActive(!info.IsComplete());

        portrait.charAsset = info.Character;
        portrait.ApplyLookFromAsset();
        DeckNameText.text = info.DeckName;
    }
Пример #13
0
    public void ApplyLockToIcon(DeckInfo info)
    {
        DeckInfomation = info;

        //check if deck is complete
        DeckNoCompleteObject.SetActive(!info.IsComplete());

        DeckNameText.text = info.DeckName;
    }
Пример #14
0
    public void DoneButtonHandler()
    {
        // save current deck list, character and deck name into DecksStorage
        DeckInfo deckToSave = new DeckInfo(deckList, DeckName.text, buildingForCharacter);

        DecksStorage.Instance.AllDecks.Add(deckToSave);
        DecksStorage.Instance.SaveDecksIntoPlayerPrefs();
        // the screen with collection and pre-made decks is loaded by calling other methods on this button
        DeckBuildingScreen.Instance.ShowScreenForCollectionBrowsing();
    }
Пример #15
0
        private void OnSaveConfirm()
        {
            m_safeExit    = true;
            ExitAfterSave = true;
            DeckInfo deckInfo = m_selectedSlot.DeckInfo.TrimCopy();
            string   name     = string.IsNullOrWhiteSpace(deckInfo.Name) ? RuntimeData.FormattedText(92537) : deckInfo.Name;

            m_frame.SendSaveSquadRequest(deckInfo.Id, name, (Family)deckInfo.God, deckInfo.Weapon, (IReadOnlyList <int>)deckInfo.Companions, (IReadOnlyList <int>)deckInfo.Spells);
            m_ui.interactable = false;
        }
Пример #16
0
 // Use this for initialization
 void Awake()
 {
     spriteRef = publicSpriteRef;
     playerRef = publicPlayerRef;
     collectionControllerRef         = publicCollectionControllerRef;
     offensiveDeckPartControllerRef  = publicOffensiveDeckPartControllerRef;
     deffensiveDeckPartControllerRef = publicDeffensiveDeckPartControllerRef;
     supportiveDeckPartControllerRef = publicSupportiveDeckPartControllerRef;
     deckInfoRef = publicDeckInfoRef;
     cameraRef   = publicCameraRef;
 }
Пример #17
0
    public void GetDeck()
    {
        string   json     = File.ReadAllText(Application.dataPath + "/SaveData/CurrentDeck.txt");
        DeckInfo deckInfo = JsonUtility.FromJson <DeckInfo>(json);

        foreach (var card in deckInfo.deck)
        {
            playerDeckCards.Add(new Pair <Card, CardInfo>(card, new CardInfo()));
        }

        Shuffle(playerDeckCards);
    }
Пример #18
0
 public void SetCurrentDeck(DeckInfo deckInfo)
 {
     m_pvpButton.set_interactable(deckInfo != null);
     if (deckInfo == null)
     {
         m_currentDeckName.SetText(64793);
     }
     else
     {
         m_currentDeckName.SetText(66030, new IndexedValueProvider(deckInfo.Name));
     }
 }
Пример #19
0
        public void RemoveCurrent(int weapon)
        {
            DeckInfo deckInfo = new DeckInfo().FillEmptySlotsCopy();

            deckInfo.Name   = RuntimeData.FormattedText(92537);
            deckInfo.God    = (int)PlayerData.instance.god;
            deckInfo.Weapon = weapon;
            DeckSlot value = m_selectedSlot = new DeckSlot(deckInfo);

            m_deck.SetValue(value);
            m_eventController.OnDeckSlotSelectionChange(m_selectedSlot);
        }
Пример #20
0
 public void SetAllDecks(IEnumerable <DeckInfo> decksInfos)
 {
     m_decks.Clear();
     foreach (DeckInfo decksInfo in decksInfos)
     {
         if (decksInfo.Id.HasValue)
         {
             int      value  = decksInfo.Id.Value;
             DeckInfo value2 = decksInfo.EnsureDataConsistency();
             m_decks.Add(value, value2);
         }
     }
     this.OnDeckListUpdated?.Invoke();
 }
Пример #21
0
        public DeckInfo GetAIDeck(DeckInfo userDeckInfo, bool isTutorial)
        {
            if (isTutorial)
            {
                return(new DeckInfo(userDeckInfo.GuardianId, new int[] { 31001, 31003, 31002, 32002, 32009 }));
            }

            // var diceInfos = TableManager.Get().DiceInfo.Values;
            // var arr = diceInfos.Where(info => info.enableDice).ToArray();
            // var shuffled = arr.OrderBy(x => Guid.NewGuid()).ToList();
            // return shuffled.Take(5).Select(info => info.id).ToArray();

            return(userDeckInfo);
        }
Пример #22
0
        private void SelectDeckForWeaponDeckForWeapon(DeckSlot slot)
        {
            DeckInfo deckInfo = slot.DeckInfo;

            if (deckInfo != null)
            {
                deckInfo = deckInfo.TrimCopy();
                int?id = deckInfo.Id;
                if (id.HasValue && deckInfo.IsValid())
                {
                    m_modifications.SetSelectedDeckForWeapon(deckInfo.Weapon, id.Value);
                }
            }
        }
Пример #23
0
    public void DoneButtonHandler()
    {
        //save current deck list into DeckStorage
        DeckInfo deckToSave = new DeckInfo(deckList, DeckName.text);

        DeckStorage.Instance.AllDecks.Add(deckToSave);
        DeckStorage.Instance.SaveDecksIntoPlayerPrefs();
        //the screen with the collection and pre-made decks is loaded by calling
        //other functions on this button
        CCScreen.Instance.ShowScreenForCollectionBrowsing();

        //reset card counter
        CardCount.Instance.count = 0;
        CardCount.Instance.SetCountText();
    }
Пример #24
0
    private bool DeckIsValid()
    {
        string json;

        json = File.ReadAllText(Application.dataPath + "/SaveData/" + pClass + "DeckSave.txt");
        DeckInfo    deckInfo = JsonUtility.FromJson <DeckInfo>(json);
        List <Card> deck     = deckInfo.deck;

        if (deck.Count != GameInfo.deckSize)
        {
            return(false);
        }
        //probably enough for now..
        return(true);
    }
Пример #25
0
        async UniTask StartFakeGame()
        {
            if (TableManager.Get().Loaded == false)
            {
                TableManager.Get().Init(Application.persistentDataPath + "/Resources/");
            }

            var server = FindObjectOfType <RWNetworkServer>(true);

            server.gameObject.SetActive(true);
            var userInfo = UserInfoManager.Get().GetUserInfo();

            var userDeck  = userInfo.GetActiveDeck;
            var diceDeck  = userDeck.Take(5).ToArray();
            var guadianId = userDeck[5];

            if (TutorialManager.isTutorial)
            {
                server.serverGameLogic.modeType = PLAY_TYPE.Tutorial;
            }
            else
            {
                server.serverGameLogic.modeType = playType;
            }

            server.serverGameLogic.hostMode = true;

            var userDeckInfo = new DeckInfo(guadianId, diceDeck);

            server.MatchData.AddPlayerInfo(
                userInfo.userID,
                userInfo.userNickName, 0, 0,
                userDeckInfo);
            server.MatchData.AddPlayerInfo(
                "AI",
                "AI", 0, 0,
                GetAIDeck(userDeckInfo, TutorialManager.isTutorial), false);

            server.authenticator = null;
            var client = FindObjectOfType <RWNetworkClient>();

            client.authenticator = null;
            client.LocalUserId   = userInfo.userID;
            client.LocalNickName = userInfo.userNickName;

            server.Listening = false;
            await server.StartHost(client);
        }
Пример #26
0
        public static DeckInfo FillEmptySlotsCopy(this DeckInfo clone, int defaultValue = -1)
        {
            int i = clone.Companions.get_Count();

            for (int num = 4; i < num; i++)
            {
                clone.Companions.Add(defaultValue);
            }
            int j = clone.Spells.get_Count();

            for (int num2 = 8; j < num2; j++)
            {
                clone.Spells.Add(defaultValue);
            }
            return(clone);
        }
Пример #27
0
        public DeckInfo ToDeckInfo()
        {
            DeckInfo info = new DeckInfo() {
                Id = ID,
                CardBack = CardBackID,
                CardBackOverride = false,
                DeckType = DeckType,
                Hero = HeroID,
                HeroOverride = false,
                HeroPremium = HeroPremium,
                Name = Name,
                LastModified = LastModified.UnixTimeStamp(),
                Validity = 31
            };

            return info;
        }
Пример #28
0
    private void LoadDeck()
    {
        if (!File.Exists(ClassFileLocation()))
        {
            ResetCardsNum();
            return;
        }

        string      json     = File.ReadAllText(ClassFileLocation());
        DeckInfo    deckInfo = JsonUtility.FromJson <DeckInfo>(json);
        List <Card> deck     = deckInfo.deck;

        if (DeckIsValid(deck))
        {
            SetUIFromDeck(deck);
        }
        return;
    }
Пример #29
0
        private bool ExtractDeckData()
        {
            try
            {
                _players.Add(ReadString(40));
                _players.Add(ReadString(40));
                if (Tag)
                {
                    _players.Add(ReadString(40));
                    _players.Add(ReadString(40));
                }

                DataReader.ReadInt32(); //lifepoints
                DataReader.ReadInt32(); //handcount
                DataReader.ReadInt32(); //drawcount
                DataReader.ReadInt32(); //other duel settings


                for (int i = 0; i < _players.Count; i++)
                {
                    DeckInfo deck = new DeckInfo();
                    //main deck
                    int count = DataReader.ReadInt32();
                    for (int main = 0; main < count; main++)
                    {
                        deck.MainDeck.Add(DataReader.ReadInt32().ToString());
                    }
                    //extra deck
                    count = DataReader.ReadInt32();
                    for (int extra = 0; extra < count; extra++)
                    {
                        deck.ExtraDeck.Add(DataReader.ReadInt32().ToString());
                    }
                    _deckData.Add(deck);
                }
            }
            catch (Exception)
            {
                //failed invalid data?
                return(false);
            }

            return(true);
        }
Пример #30
0
        public void SendSaveSquadRequest(int?id, string name, Family god, int weapon, IReadOnlyList <int> companions, IReadOnlyList <int> spells)
        {
            DeckInfo deckInfo = new DeckInfo
            {
                Id     = id,
                Name   = name,
                Weapon = weapon,
                God    = (int)god
            };

            deckInfo.Companions.AddRange((IEnumerable <int>)companions);
            deckInfo.Spells.AddRange((IEnumerable <int>)spells);
            SaveDeckCmd message = new SaveDeckCmd
            {
                Info = deckInfo
            };

            m_connection.Write(message);
        }
Пример #31
0
        public static bool IsValid(this DeckInfo info)
        {
            if (info == null)
            {
                return(false);
            }
            RepeatedField <int> spells = info.Spells;
            int count = spells.get_Count();

            if (count < 8)
            {
                return(false);
            }
            for (int i = 0; i < count; i++)
            {
                if (spells.get_Item(i) <= 0)
                {
                    return(false);
                }
            }
            RepeatedField <int> companions = info.Companions;
            int count2 = info.Companions.get_Count();

            if (count2 < 4)
            {
                return(false);
            }
            for (int j = 0; j < count2; j++)
            {
                if (companions.get_Item(j) <= 0)
                {
                    return(false);
                }
            }
            int?num = info.Weapon;

            if (!num.HasValue || !PlayerData.instance.weaponInventory.TryGetLevel(num.Value, out int _))
            {
                return(false);
            }
            return(true);
        }
Пример #32
0
        private bool ExtractDeckData()
        {
            try
            {
                _players.Add(ReadString(40));
                _players.Add(ReadString(40));
                if (Tag)
                {
                    _players.Add(ReadString(40));
                    _players.Add(ReadString(40));
                }

                DataReader.ReadInt32();//lifepoints
                DataReader.ReadInt32();//handcount
                DataReader.ReadInt32();//drawcount
                DataReader.ReadInt32();//other duel settings

                for (int i = 0; i < _players.Count; i++)
                {
                    DeckInfo deck = new DeckInfo();
                    //main deck
                    int count = DataReader.ReadInt32();
                    for (int main = 0; main < count; main++)
                        deck.MainDeck.Add(DataReader.ReadInt32().ToString());
                    //extra deck
                    count = DataReader.ReadInt32();
                    for (int extra = 0; extra < count; extra++)
                        deck.ExtraDeck.Add(DataReader.ReadInt32().ToString());
                    _deckData.Add(deck);
                }
            }
            catch(Exception)
            {
                //failed invalid data?
                return false;
            }

            return true;
        }