Пример #1
0
        //随机属性条数随机
        private int RandomAddCount(ElfRecord tbElf, int EquipRelateId)
        {
            if (EquipRelateId == -1)
            {
                return(0);
            }
            var tbRelate = Table.GetEquipRelate(EquipRelateId);

            if (tbRelate == null)
            {
                Logger.Error("EquipRelate Id={0} not find", EquipRelateId);
                return(0);
            }
            var AddCount     = 0;
            var nRandom      = MyRandom.Random(10000);
            var nTotleRandom = 0;

            for (var i = 0; i != tbRelate.AttrCount.Length; ++i)
            {
                nTotleRandom += tbRelate.AttrCount[i];
                if (nRandom < nTotleRandom)
                {
                    return(i);
                    //if (i == 0) return 0;
                    //AddCount = i;
                    //break;
                }
            }
            Logger.Error("Elf RandomAddCount not find Pro! EquipRelateId={0}", EquipRelateId);
            return(AddCount);
        }
Пример #2
0
        /// <summary>
        ///     随机一个迭代器
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="dict"></param>
        /// <returns></returns>
        public static KeyValuePair <TKey, TValue> Random <TKey, TValue>(this Dictionary <TKey, TValue> dict)
        {
            if (dict == null)
            {
                throw new ArgumentNullException();
            }

            var index = MyRandom.Random(dict.Count);

            {
                // foreach(var value in dict)
                var __enumerator4 = (dict).GetEnumerator();
                while (__enumerator4.MoveNext())
                {
                    var value = __enumerator4.Current;
                    {
                        if (index == 0)
                        {
                            return(value);
                        }

                        index--;
                    }
                }
            }

            throw new Exception("Dictionay is empty.");
        }
Пример #3
0
        /// <summary>
        ///     从[0,maxcount-1]中取随机几个[x0,x1...]
        /// </summary>
        /// <param name="maxcount"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        private static List <int> Random(int maxcount, int count)
        {
            var templist = new List <int>();

            if (count == 1)
            {
                templist.Add(MyRandom.Random(templist.Count));
                return(templist);
            }
            for (var i = 0; i != maxcount; i++)
            {
                templist.Add(i);
            }
            if (maxcount <= count)
            {
                return(templist);
            }
            var result = new List <int>();

            for (var i = 0; i != count; i++)
            {
                var r = MyRandom.Random(templist.Count);
                result.Add(templist[r]);
                templist.RemoveAt(r);
            }
            return(result);
        }
Пример #4
0
        //初始化数据
        private void Init(int nId, ItemBaseData Dbdata)
        {
            mDbData = Dbdata;
            SetId(nId);
            SetCount(1);
            CleanExdata();

            var tbItem = Table.GetItemBase(nId);
            var tbSU   = Table.GetSkillUpgrading(tbItem.Exdata[0]);
            var values = tbSU.Values;

            if (values.Count % 3 != 0)
            {
                Logger.Error("tbSU.Values.Count can't be divided by 3!!");
                return;
            }
            var count   = values.Count / 3;
            var idx     = MyRandom.Random(count) * 3;
            var sceneId = values[idx++];
            var x       = values[idx++];
            var y       = values[idx++];

            //初始exdata
            AddExdata(sceneId);
            AddExdata(x);
            AddExdata(y);
        }
Пример #5
0
        //随机宠物特长
        public static void RefreshSpeciality(ItemBase item, PetRecord tbPet)
        {
            var skills = new Dictionary <int, int>();

            for (var index = 0; index != 3; ++index)
            {
                var tbPetSkill = Table.GetPetSkillBase(tbPet.SpecialityLibrary[index]);
                if (tbPetSkill == null)
                {
                    return;
                }
                var needCount = 1;
                //if (tbPet.Speciality[index] > 1)
                //{
                //    continue;
                //}
                //for (int i = 0; i != 3; i++)
                //{
                //    if (tbPet.Speciality[i] <= 1)
                //    {
                //        needCount++;
                //    }
                //}
                skills.Clear();
                var nTotleAttrPro = 0;
                for (var i = 0; i < tbPetSkill.SpecialityPro.Length; i++)
                {
                    if (tbPetSkill.SpecialityPro[i] < 0 || tbPetSkill.Speciality[i] < 0)
                    {
                        break;
                    }
                    skills.Add(tbPetSkill.Speciality[i], tbPetSkill.SpecialityPro[i]);
                    nTotleAttrPro += tbPetSkill.SpecialityPro[i];
                }
                //整理概率
                int nRandom, nTotleRandom;
                for (var i = 0; i != needCount; ++i)
                {
                    nRandom      = MyRandom.Random(nTotleAttrPro);
                    nTotleRandom = 0;
                    foreach (var i1 in skills)
                    {
                        nTotleRandom += i1.Value;
                        if (nRandom < nTotleRandom)
                        {
                            item.SetExdata(5 + index, i1.Key);
                            nTotleAttrPro -= i1.Value;
                            skills.Remove(i1.Key);
                            break;
                        }
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        ///     随机一个元素出来
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="l"></param>
        /// <returns></returns>
        public static T Range <T>(this List <T> l)
        {
            if (l == null)
            {
                throw new ArgumentNullException();
            }
            if (l.Count == 0)
            {
                throw new Exception("List is empty.");
            }

            return(l[MyRandom.Random(l.Count)]);
        }
Пример #7
0
        public int RandBuffId(int buffGroupId = -1)
        {
            if (buffGroupId == -1)
            {
                var tbItem = Table.GetItemBase(GetId());
                if (tbItem == null)
                {
                    return(-1);
                }
                var equipId = tbItem.Exdata[0];
                var tbEquip = Table.GetEquip(equipId);
                if (tbEquip != null && tbEquip.BuffGroupId != -1)
                {
                    buffGroupId = tbEquip.BuffGroupId;
                }
                else
                {
                    return(-1);
                }
            }

            var tbBuffGroup = Table.GetBuffGroup(buffGroupId);

            if (tbBuffGroup != null)
            {
                if (tbBuffGroup.BuffID.Count != tbBuffGroup.QuanZhong.Count)
                {
                    Logger.Error("RandBuffId equipId {0} addbuffgroup {1} size not eaqual!", GetId(), buffGroupId);
                    return(-1);
                }

                var curBuffId = GetBuffId(0);
                var buffList  = new List <int>();
                var propList  = new List <int>();
                var index     = 0;
                var max       = 0;
                foreach (var buffId in tbBuffGroup.BuffID)
                {
                    //if (curBuffId != buffId)
                    {
                        max += tbBuffGroup.QuanZhong[index];
                        buffList.Add(buffId);
                        propList.Add(tbBuffGroup.QuanZhong[index]);
                    }
                    ++index;
                }

                index = 0;
                var rnd = MyRandom.Random(0, max - 1);
                foreach (var prop in propList)
                {
                    if (rnd < prop)
                    {
                        return(buffList[index]);
                    }
                    rnd -= prop;
                    ++index;
                }
            }

            return(-1);
        }
Пример #8
0
        //初始化附加属性
        public void InitAddAttr(ElfRecord tbElf, int addCount)
        {
            if (addCount <= 0 || addCount > 6)
            {
                return;
            }
            int nRandom, nTotleRandom;
            var TbAttrPro = Table.GetEquipEnchantChance(tbElf.RandomPropPro);

            if (TbAttrPro == null)
            {
                Logger.Error("Equip InitAddAttr Id={0} not find EquipEnchantChance Id={1}", tbElf.Id,
                             tbElf.RandomPropPro);
                return;
            }
            var tempAttrPro   = new Dictionary <int, int>();
            var nTotleAttrPro = 0;

            for (var i = 0; i != 23; ++i)
            {
                var nAttrpro = TbAttrPro.Attr[i];
                if (nAttrpro > 0)
                {
                    nTotleAttrPro += nAttrpro;
                    tempAttrPro[i] = nAttrpro;
                }
            }
            //属性值都在这里
            var tbEnchant = Table.GetEquipEnchant(tbElf.RandomPropValue);

            if (tbEnchant == null)
            {
                Logger.Error("Equip InitAddAttr Id={0} not find tbEquipEnchant Id={1}", tbElf.Id, tbElf.RandomPropValue);
                return;
            }
            //整理概率
            var AttrValue = new Dictionary <int, int>();

            for (var i = 0; i != addCount; ++i)
            {
                nRandom      = MyRandom.Random(nTotleAttrPro);
                nTotleRandom = 0;
                foreach (var i1 in tempAttrPro)
                {
                    nTotleRandom += i1.Value;
                    if (nRandom < nTotleRandom)
                    {
                        //AddCount = i1.Key;
                        AttrValue[i1.Key] = tbEnchant.Attr[i1.Key];
                        nTotleAttrPro    -= i1.Value;
                        tempAttrPro.Remove(i1.Key);
                        break;
                    }
                }
            }
            var NowAttrCount = AttrValue.Count;

            if (NowAttrCount < addCount)
            {
                Logger.Error("Equip InitAddAttr AddAttr Not Enough AddCount={0},NowAttrCount={1}", addCount,
                             NowAttrCount);
            }

            //EquipRelateRecord tbAttrRelate = Table.GetEquipRelate(tbElf.RandomAttrInterval);
            //if (tbAttrRelate == null)
            //{
            //    Logger.Error("Equip tbAttrRelate Id={0} not find EquipRelate Id={1}", tbElf.Id, tbElf.RandomAttrInterval);
            //    return;
            //}

            for (var i = 0; i != NowAttrCount; ++i)
            {
                var nKey    = AttrValue.Keys.Min();
                var nAttrId = ItemEquip2.GetAttrId(nKey);
                if (nAttrId == -1)
                {
                    continue;
                }
                var fValue = tbEnchant.Attr[nKey];
                //int AttrValueMin = fValue * tbElf.RandomValueMin / 100;
                //int AttrValueMax = fValue * tbElf.RandomValueMax / 100;
                //int AttrValueDiff = AttrValueMax - AttrValueMin;
                //nRandom = MyRandom.Random(10000);
                //nTotleRandom = 0;
                //int rMin = 0;
                //int rMax = 10000;
                //for (int j = 0; j != tbAttrRelate.Value.Length; ++j)
                //{
                //    nTotleRandom += tbAttrRelate.Value[j];
                //    if (nRandom < nTotleRandom)
                //    {
                //        switch (j)
                //        {
                //            case 0:
                //                {
                //                    rMin = 0;
                //                    rMax = 5000;
                //                }
                //                break;
                //            case 1:
                //                {
                //                    rMin = 5000;
                //                    rMax = 7500;
                //                }
                //                break;
                //            case 2:
                //                {
                //                    rMin = 7500;
                //                    rMax = 9000;
                //                }
                //                break;
                //            case 3:
                //                {
                //                    rMin = 9000;
                //                    rMax = 10000;
                //                }
                //                break;
                //        }
                //        break;
                //    }
                //}
                //int AttrValueMin2 = AttrValueMin + AttrValueDiff * rMin / 10000;
                //int AttrValueMax2 = AttrValueMin + AttrValueDiff * rMax / 10000;
                //int AttrRealValue = MyRandom.Random(AttrValueMin2, AttrValueMax2);
                AddAttr(i, nAttrId, fValue);
                AttrValue.Remove(nKey);
            }
        }
Пример #9
0
        //掉落母表
        public static void DropMother(int nId, Dictionary <int, int> Droplist)
        {
            var tbdropmo = Table.GetDropMother(nId);

            if (tbdropmo == null)
            {
                return;
            }
            //惊喜掉落
            if (tbdropmo.SurprisePro > 0 && tbdropmo.SurpriseDrop >= 0)
            {
                if (MyRandom.Random(10000) < tbdropmo.SurprisePro)
                {
                    //走惊喜掉落
                    Logger.Info("DropMother Surprise={0}", nId);
                    DropSon(nId, Droplist);
                    return;
                }
            }
            //正常掉落
            var Grouplist = new Dictionary <int, int>();

            for (var i = 0; i != tbdropmo.DropSon.Length; ++i)
            {
                var GroupId = tbdropmo.Group[i];
                if (GroupId == -1)
                {
//单独组
                    if (tbdropmo.Pro[i] > 0 && tbdropmo.DropSon[i] >= 0)
                    {
                        if (tbdropmo.DropMin[i] < 1 || tbdropmo.DropMax[i] < tbdropmo.DropMin[i])
                        {
                            Logger.Error("DropMother DropSon={0},Index={1},Min={2},Max={3}", nId, i, tbdropmo.DropMin[i],
                                         tbdropmo.DropMax[i]);
                            continue;
                        }
                        var nCount = MyRandom.Random(tbdropmo.DropMin[i], tbdropmo.DropMax[i]);
                        Logger.Info("DropMother DropSon={0},DropSon={1},Count={2}", nId, tbdropmo.DropSon[i], nCount);
                        for (var j = 0; j != nCount; ++j)
                        {
                            DropSon(tbdropmo.DropSon[i], Droplist);
                        }
                    }
                }
                else
                {
                    int pro;
                    if (!Grouplist.TryGetValue(GroupId, out pro))
                    {
                        pro = MyRandom.Random(10000);
                        Grouplist[GroupId] = pro;
                    }
                    if (pro <= 0)
                    {
                        continue;
                    }
                    if (pro <= tbdropmo.Pro[i])
                    {
//随机中了
                        var nCount = tbdropmo.DropMin[i];
                        if (nCount < 0 || nCount > tbdropmo.DropMax[i])
                        {
                            Logger.Error("DropMother CountError DropId={0},Group={1},Index={2},DropSon={3}", nId,
                                         GroupId, i, tbdropmo.DropSon[i]);
                            return;
                        }
                        if (tbdropmo.DropMin[i] < tbdropmo.DropMax[i])
                        {
                            nCount = MyRandom.Random(tbdropmo.DropMin[i], tbdropmo.DropMax[i]);
                        }
                        Logger.Info("DropMother DropId={0},Group={1},Index={2},DropSon={3},Count={4}", nId, GroupId, i,
                                    tbdropmo.DropSon[i], nCount);
                        for (var j = 0; j != nCount; ++j)
                        {
                            DropSon(tbdropmo.DropSon[i], Droplist);
                        }
                    }
                    Grouplist[GroupId] = pro - tbdropmo.Pro[i];
                }
            }
        }
Пример #10
0
        //掉落子表
        public static void DropSon(int nId, Dictionary <int, int> Droplist)
        {
            var tbdropson = Table.GetDropSon(nId);

            if (tbdropson == null)
            {
                return;
            }
            var nType = tbdropson.DropType;

            switch (nType)
            {
            case 0:     //固定掉落
            {
                for (var i = 0; i != tbdropson.Item.Length; ++i)
                {
                    var itemid    = tbdropson.Item[i];
                    var itemCount = tbdropson.Count[i];
                    if (itemCount < tbdropson.MaxCount[i])
                    {
                        itemCount = MyRandom.Random(itemCount, tbdropson.MaxCount[i]);
                    }
                    var itempro = tbdropson.Pro[i];
                    if (itemid >= 0 && itemCount > 0 && itempro > 0)
                    {
                        if (MyRandom.Random(10000) < itempro)
                        {
                            DropItem(Droplist, itemid, itemCount);
                        }
                    }
                }
            }
            break;

            case 1:     //随机掉落
            {
                if (MyRandom.Random(10000) > tbdropson.TotlePro)
                {
                    return;
                }
                var totlePro = MyRandom.Random(10000);
                for (var i = 0; i != tbdropson.Item.Length; ++i)
                {
                    var itemid    = tbdropson.Item[i];
                    var itemCount = tbdropson.Count[i];
                    if (itemCount < tbdropson.MaxCount[i])
                    {
                        itemCount = MyRandom.Random(itemCount, tbdropson.MaxCount[i]);
                    }
                    var itempro = tbdropson.Pro[i];
                    if (itemid >= 0 && itemCount > 0 && itempro > 0)
                    {
                        if (totlePro < itempro)
                        {
                            DropItem(Droplist, itemid, itemCount);
                            return;
                        }
                        totlePro -= itempro;
                    }
                }
            }
            break;
            }
        }