Exemplo n.º 1
0
    public Hero OnRandomOneHero()
    {
        HeroJob     heroJob     = (HeroJob)Random.Range((int)HeroJob.Archer, (int)HeroJob.NULL);
        HeroSex     sex         = Random.Range(0, 100) > 50 ? HeroSex.Female : HeroSex.Male;
        HeroQuality heroQuality = (HeroQuality)Random.Range((int)HeroQuality.B, (int)HeroQuality.NULL);
        Hero        hero        = new Hero
        {
            id          = GetRandomId(),
            heroLevel   = 1,
            heroJob     = heroJob,
            heroQuality = heroQuality,
            heroSex     = sex
        };
        ///////获取身体/////////////////////////////////////////////
        List <DIYTableData> dIYTableDatas = DataManager.GetInstance().GetDIYTableDatasByHeroJobAndSex(heroJob, sex);

        if (dIYTableDatas.Count > 0)
        {
            int          bodyIndex = Random.Range(0, dIYTableDatas.Count);
            DIYTableData body      = dIYTableDatas[bodyIndex];
            hero.heroPartDic[HeroPart.Body] = body.id;
        }
        List <DIYTableData> dIYTableDataHairs = DataManager.GetInstance().GetDIYTableDatasByHeroPartAndSex(HeroPart.Hair, sex);

        if (dIYTableDataHairs.Count > 0)
        {
            int          hairIndex = Random.Range(0, dIYTableDataHairs.Count);
            DIYTableData hairdata  = dIYTableDataHairs[hairIndex];
            hero.heroPartDic[HeroPart.Hair] = hairdata.id;
        }
        int min_age        = DataManager.instance.GetConfigValueToInt("min_age");
        int max_age        = DataManager.instance.GetConfigValueToInt("max_age");
        int have_beard_age = DataManager.instance.GetConfigValueToInt("have_beard_age");
        int age            = Random.Range(min_age, max_age); //随机年龄

        if (age < have_beard_age && sex == HeroSex.Male)     //xx岁以下不添加胡子
        {
            List <DIYTableData> dIYTableDataBeards = DataManager.GetInstance().GetDIYTableDatasByHeroPartAndSex(HeroPart.Beard, sex);
            if (dIYTableDataBeards.Count > 0)
            {
                int          beardIndex = Random.Range(0, dIYTableDataBeards.Count);
                DIYTableData bearddata  = dIYTableDataBeards[beardIndex];
                hero.heroPartDic[HeroPart.Beard] = bearddata.id;
            }
        }
        return(hero);
    }
    public void ParseJSON(JSONNode json)
    {
        Identity      = json["identity"].AsDecodedURL();
        MinCount      = json["min-count"].AsInt;
        MaxCount      = json["max-count"].AsInt;
        RequireAwoken = json["awoken"].AsBool;
        Quality       = json["quality"].AsEnum <HeroQuality>();

        ItemsGuaranteed = new RetireRewardDictionary();
        ItemsRandom     = new RetireRewardDictionary();
        Types           = new List <HeroType>();

        //Parse the Key-Value pairs in the Guaranteed & Random items:
        var guaranteedItems = JSONManager.SplitKVFloats(json["guaranteed-items"]);
        var randomItems     = JSONManager.SplitKVFloats(json["random-items"]);

        foreach (var kv in guaranteedItems)
        {
            ItemsGuaranteed.Add(kv.Key, kv.Value);
        }
        foreach (var kv in randomItems)
        {
            ItemsRandom.Add(kv.Key, kv.Value);
        }

        //Validate this entry...
        if (MinCount > MaxCount)
        {
            JSONError("MinCount > MaxCount, should probably swap these in RetireRewards table.");
        }
        if (ItemsGuaranteed.Count == 0 && ItemsRandom.Count == 0)
        {
            JSONError("RetireReward doesn't have any Guaranteed -or- Random items!");
        }

        //Tracer.trace(Debug());
    }
Exemplo n.º 3
0
    public Hero(HeroData data, int Seed, int QualityLevel = 0, Dictionary <string, int> skillLevelDictionary = null)
    {
        this.data = data;

        if (data == null)
        {
            Tracer.traceWarn("Testing dummy Hero object.");
            return;
        }

        // Hero Variance
        _heroVarianceSeed = Seed;

        Random.InitState(_heroVarianceSeed);

        // Hero Quality
        _quality = HeroQuality.Common + this.QualityLevel;
        float Qchance = Random.Range(0f, 1f);

        if (Qchance <= dataMan.globalData.GetGlobalAsFloat(GlobalProps.SUMMON_QUALITY_3STAR))
        {
            _quality = HeroQuality.Legendary;
        }
        else if (Qchance <= (dataMan.globalData.GetGlobalAsFloat(GlobalProps.SUMMON_QUALITY_3STAR) + dataMan.globalData.GetGlobalAsFloat(GlobalProps.SUMMON_QUALITY_2STAR)))
        {
            _quality = HeroQuality.Rare + this.QualityLevel;
        }

        // Hero Personality
        HeroPersonality[] personalities = (HeroPersonality[])System.Enum.GetValues(typeof(HeroPersonality));
        int personatlityIndex           = Random.Range(0, personalities.Length);

        personality = personalities[personatlityIndex];


        if (data.Skills != null && data.Skills.Count > 0)
        {
            if (data.Skills.Count > 4)
            {
                Debug.LogError("Too many skills on hero: " + data.Identity);
                for (int i = 0; i < (data.Skills.Count - 4); i++)
                {
                    data.Skills.RemoveAt(data.Skills.Count - 1);
                    Debug.Log("Remove skill on " + data.Identity + " at index [" + (data.Skills.Count - 1) + "]");
                }
            }
            foreach (Skill skill in data.Skills)
            {
                Skills.Add((Skill)UnityEngine.Object.Instantiate(skill));

                /*if (skillLevelDictionary != null && skillLevelDictionary.Count > 0) // skills exist on the server
                 *  SkillLevels.Add(skill.Identity, skillLevelDictionary[skill.Identity]);
                 * else
                 *  SkillLevels.Add(skill.Identity, 1);*/
            }
            ResetSkillsCooldown();

            tapSkill = GameManager.Instance.GetRandomTapSkill();
            if (tapSkill == null)
            {
                Tracer.traceCounter("TapSkill is null, probably because there was no TapSkills in the GameManager (yet?)");
            }
        }
        else
        {
            Tracer.traceError("This hero has no skills: " + this.DebugID);
        }

        //Let's the GameManager know to check all heroes to run CheckHasWeapon() method.
        GameManager.Instance.checkHeroWeapons = true;
    }