Example #1
0
        private static bool TestEquips(Dictionary <string, int> requriedSkills, List <Equip> equips, List <Decoration> decorations)
        {
            var skills    = new Dictionary <string, int>();
            var holeDatas = new List <HoleData>();

            foreach (var equip in equips)
            {
                if (equip != null)
                {
                    var equipData = EquipDatas.GetEquipDataByEquip(equip);
                    foreach (var skill in equipData.skills)
                    {
                        var skillTitle = skill.title;
                        var skillLevel = skill.level;
                        if (!skills.ContainsKey(skillTitle))
                        {
                            skills.Add(skillTitle, 0);
                        }
                        skills[skillTitle] += skillLevel;
                    }
                    holeDatas.AddRange(equipData.holes);
                }
            }

            var tempRequriedSkills = new Dictionary <string, int>(requriedSkills);

            foreach (var skill in skills)
            {
                var skillTitle = skill.Key;
                var skillLevel = skill.Value;
                if (tempRequriedSkills.ContainsKey(skillTitle))
                {
                    tempRequriedSkills[skillTitle] -= skillLevel;
                }
            }
            foreach (var skill in tempRequriedSkills)
            {
                if (skill.Value > 0)
                {
                    return(TryDecoration(tempRequriedSkills, holeDatas, decorations));
                }
            }
            return(true);
        }
Example #2
0
        public static List <Suit> FindSuits(Dictionary <string, int> requriedSkills, List <Decoration> existDecorations, Stone existStone)
        {
            Dictionary <EquipType, List <Equip> > filteredEquips = EquipDatas.GetFilteredEquips(requriedSkills);

            if (existStone != null)
            {
                filteredEquips[EquipType.Stone].Clear();
                filteredEquips[EquipType.Stone].Add(null);
                filteredEquips[EquipType.Stone].Add(existStone);
            }

            List <Suit> suits = new List <Suit>();

            foreach (var head in filteredEquips[EquipType.Head])
            {
                foreach (var body in filteredEquips[EquipType.Body])
                {
                    foreach (var arm in filteredEquips[EquipType.Arm])
                    {
                        foreach (var waist in filteredEquips[EquipType.Waist])
                        {
                            foreach (var leg in filteredEquips[EquipType.Leg])
                            {
                                foreach (var stone in filteredEquips[EquipType.Stone])
                                {
                                    var equips = new List <Equip> {
                                        head, body, arm, waist, leg, stone
                                    };
                                    if (TestEquips(requriedSkills, equips, existDecorations))
                                    {
                                        suits.Add(new Suit(equips));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(suits);
        }
Example #3
0
            public void RefreshContent()
            {
                const string equipText =
                    "头部:{0}\n" +
                    "胸部:{1}\n" +
                    "手部:{2}\n" +
                    "腰部:{3}\n" +
                    "腿部:{4}\n" +
                    "护石:{5}";

                if (selectedSuit == null)
                {
                    equips.text = string.Format(equipText, @"无", @"无", @"无", @"无", @"无", @"无");
                }
                else
                {
                    Equip headEquip  = selectedSuit.equips.ContainsKey(EquipType.Head) ? selectedSuit.equips[EquipType.Head] : null;
                    Equip bodyEquip  = selectedSuit.equips.ContainsKey(EquipType.Body) ? selectedSuit.equips[EquipType.Body] : null;
                    Equip armEquip   = selectedSuit.equips.ContainsKey(EquipType.Arm) ? selectedSuit.equips[EquipType.Arm] : null;
                    Equip waistEquip = selectedSuit.equips.ContainsKey(EquipType.Waist) ? selectedSuit.equips[EquipType.Waist] : null;
                    Equip legEquip   = selectedSuit.equips.ContainsKey(EquipType.Leg) ? selectedSuit.equips[EquipType.Leg] : null;
                    Equip stoneEquip = selectedSuit.equips.ContainsKey(EquipType.Stone) ? selectedSuit.equips[EquipType.Stone] : null;
                    equips.text = string.Format(equipText,
                                                headEquip != null ? headEquip.title : @"无",
                                                bodyEquip != null ? bodyEquip.title : @"无",
                                                armEquip != null ? armEquip.title : @"无",
                                                waistEquip != null ? waistEquip.title : @"无",
                                                legEquip != null ? legEquip.title : @"无",
                                                stoneEquip != null ? stoneEquip.title : @"无"
                                                );
                }

                for (int i = scrollItem.parent.childCount - 1; i >= 0; i--)
                {
                    var content = scrollItem.parent.GetChild(i);
                    if (content != scrollItem)
                    {
                        GameObject.Destroy(content.gameObject);
                    }
                }
                if (selectedSuit != null)
                {
                    HashSet <string> skillNames = new HashSet <string>();
                    foreach (var skillUI in skillUIs)
                    {
                        if (skillUI.skill != null)
                        {
                            skillNames.Add(skillUI.skill.title);
                        }
                    }
                    foreach (var type in Enum.GetValues(typeof(EquipType)))
                    {
                        if (selectedSuit.equips.ContainsKey((EquipType)type))
                        {
                            var equip = selectedSuit.equips[(EquipType)type];
                            if (equip != null)
                            {
                                foreach (var skill in EquipDatas.GetEquipDataByEquip(equip).skills)
                                {
                                    skillNames.Add(skill.title);
                                }
                            }
                        }
                    }

                    HashSet <int> holeLevels = new HashSet <int>()
                    {
                        1, 2, 3
                    };

                    scroller.content.sizeDelta = new Vector2(scroller.content.sizeDelta.x, (skillNames.Count + holeLevels.Count) * scrollItem.GetComponent <RectTransform>().sizeDelta.y);
                    int index = 0;
                    foreach (var skillName in skillNames)
                    {
                        var item = GameObject.Instantiate(scrollItem);
                        item.transform.SetParent(scrollItem.parent);
                        item.gameObject.SetActive(true);
                        item.transform.Find("Name").GetComponent <Text>().text = skillName;
                        int total = 0;
                        foreach (var type in Enum.GetValues(typeof(EquipType)))
                        {
                            var text = item.transform.Find(type.ToString());
                            if (text == null)
                            {
                                continue;
                            }
                            int level = 0;
                            if (selectedSuit.equips.ContainsKey((EquipType)type))
                            {
                                var equip = selectedSuit.equips[(EquipType)type];
                                if (equip != null)
                                {
                                    var skills = EquipDatas.GetEquipDataByEquip(equip).skills;
                                    foreach (var skill in skills)
                                    {
                                        if (skill.title == skillName)
                                        {
                                            level = skill.level;
                                        }
                                    }
                                }
                            }
                            text.GetComponent <Text>().text = level.ToString();
                            total += level;
                        }
                        item.transform.Find("Total").GetComponent <Text>().text = total.ToString();

                        item.GetComponent <RectTransform>().sizeDelta = scrollItem.GetComponent <RectTransform>().sizeDelta;
                        item.GetComponent <RectTransform>().offsetMin = scrollItem.GetComponent <RectTransform>().offsetMin;
                        item.GetComponent <RectTransform>().offsetMax = scrollItem.GetComponent <RectTransform>().offsetMax;
                        item.transform.position -= new Vector3(0, index++ *scrollItem.GetComponent <RectTransform>().sizeDelta.y, 0);
                    }
                    foreach (var holeLevel in holeLevels)
                    {
                        var item = GameObject.Instantiate(scrollItem);
                        item.transform.SetParent(scrollItem.parent);
                        item.gameObject.SetActive(true);
                        item.transform.Find("Name").GetComponent <Text>().text = holeLevel + "级孔";
                        int total = 0;
                        foreach (var type in Enum.GetValues(typeof(EquipType)))
                        {
                            var text = item.transform.Find(type.ToString());
                            if (text == null)
                            {
                                continue;
                            }
                            int count = 0;
                            if (selectedSuit.equips.ContainsKey((EquipType)type))
                            {
                                var equip = selectedSuit.equips[(EquipType)type];
                                if (equip != null)
                                {
                                    var holes = EquipDatas.GetEquipDataByEquip(equip).holes;
                                    foreach (var hole in holes)
                                    {
                                        if (hole.maxLevel == holeLevel)
                                        {
                                            count++;
                                        }
                                    }
                                }
                            }
                            text.GetComponent <Text>().text = count.ToString();
                            total += count;
                        }
                        item.transform.Find("Total").GetComponent <Text>().text = total.ToString();

                        item.GetComponent <RectTransform>().sizeDelta = scrollItem.GetComponent <RectTransform>().sizeDelta;
                        item.GetComponent <RectTransform>().offsetMin = scrollItem.GetComponent <RectTransform>().offsetMin;
                        item.GetComponent <RectTransform>().offsetMax = scrollItem.GetComponent <RectTransform>().offsetMax;
                        item.transform.position -= new Vector3(0, index++ *scrollItem.GetComponent <RectTransform>().sizeDelta.y, 0);
                    }
                }
            }
Example #4
0
        public void Start()
        {
            SkillDatas.Init();
            EquipDatas.Init();

            //Skill
            List <Dropdown.OptionData> skillOptions = new List <Dropdown.OptionData>();

            skillOptions.Add(new Dropdown.OptionData(@"空"));
            foreach (var skill in SkillDatas.GetSkillDatas())
            {
                skillOptions.Add(new Dropdown.OptionData(skill.Key));
            }
            foreach (var skillUI in skillUIs)
            {
                skillUI.dropdown.options = skillOptions;
                skillUI.dropdown.onValueChanged.AddListener(skillUI.OnSelectSkill);
                skillUI.add.onClick.AddListener(skillUI.OnAddLevel);
                skillUI.minus.onClick.AddListener(skillUI.OnMinusLevel);
                skillUI.skill = null;
                skillUI.RefreshUI();
            }

            //Stone
            List <Dropdown.OptionData> stoneOptions = new List <Dropdown.OptionData>();

            stoneOptions.Add(new Dropdown.OptionData(@"空"));
            foreach (var equip in EquipDatas.GetEquipDatas()[EquipType.Stone])
            {
                stoneOptions.Add(new Dropdown.OptionData(equip.Key));
            }
            stoneUI.dropdown.options = stoneOptions;
            stoneUI.dropdown.onValueChanged.AddListener(stoneUI.OnSelectStone);
            stoneUI.stone = null;

            //Decoration
            List <Dropdown.OptionData> decorationOptions = new List <Dropdown.OptionData>();

            decorationOptions.Add(new Dropdown.OptionData(@"空"));
            foreach (var equip in EquipDatas.GetEquipDatas()[EquipType.Decoration])
            {
                decorationOptions.Add(new Dropdown.OptionData(equip.Key));
            }
            decorationUI.dropdown.options = decorationOptions;
            decorationUI.dropdown.onValueChanged.AddListener(decorationUI.OnSelectDecoration);
            decorationUI.add.onClick.AddListener(decorationUI.OnAdd);
            decorationUI.decoration      = null;
            decorationUI.decorationItems = new List <DecorationUI.DecorationItem>();
            decorationUI.RefreshUI();

            //Search
            searchUI.onClick.AddListener(OnSearch);

            //Dialog
            resultDialog.GetComponentInChildren <Button>().onClick.AddListener(OnDialogConfirm);
            resultDialog.gameObject.SetActive(false);

            //Suit
            suitUI.skillUIs = skillUIs;
            suitUI.suitsSelection.onValueChanged.AddListener(suitUI.OnSelectSuit);
            suitUI.selectedSuit = null;
            suitUI.suits        = new List <Suit>();
            suitUI.RefreshSelection();
        }
Example #5
0
        private static bool TryDecoration(Dictionary <string, int> requriedSkills, List <HoleData> holes, List <Decoration> decorations)
        {
            bool success = true;

            foreach (var skillPair in requriedSkills)
            {
                if (skillPair.Value > 0)
                {
                    success = false;
                    break;
                }
            }
            if (!success)
            {
                if (holes.Count == 0 || decorations.Count == 0)
                {
                    success = false;
                }
                else
                {
                    var lastHole = holes[holes.Count - 1];
                    holes.Remove(lastHole);

                    if (TryDecoration(requriedSkills, holes, decorations))
                    {
                        success = true;
                    }
                    else
                    {
                        for (int i = 0; i < decorations.Count; i++)
                        {
                            var decoration     = decorations[i];
                            var decorationData = EquipDatas.GetEquipDataByEquip(decorations[i]);
                            if (lastHole.maxLevel >= decorationData.level)
                            {
                                foreach (var skill in decorationData.skills)
                                {
                                    if (requriedSkills.ContainsKey(skill.title))
                                    {
                                        requriedSkills[skill.title] -= skill.level;
                                    }
                                }
                                decorations.RemoveAt(i);

                                if (TryDecoration(requriedSkills, holes, decorations))
                                {
                                    success = true;
                                }

                                foreach (var skill in decorationData.skills)
                                {
                                    if (requriedSkills.ContainsKey(skill.title))
                                    {
                                        requriedSkills[skill.title] += skill.level;
                                    }
                                }
                                decorations.Insert(i, decoration);

                                if (success)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    holes.Add(lastHole);
                }
            }
            return(success);
        }