Beispiel #1
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);
        }
Beispiel #2
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];
                }
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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;
            }
        }