Beispiel #1
0
    /// <summary>
    /// 读完所有表后处理
    /// </summary>
    public static void afterReadConfigAll()
    {
        if (_dic == null)
        {
            return;
        }

        RandomItemConfig[] values;
        RandomItemConfig   v;

        for (int i = (values = _dic.getValues()).Length - 1; i >= 0; --i)
        {
            if ((v = values[i]) != null)
            {
                switch (v.type)
                {
                case RandomItemType.Single:
                {
                    int itemID = v.args[0][0];
                    if (itemID > 0 && ItemConfig.get(itemID) == null)
                    {
                        Ctrl.throwError("找不到物品ID", itemID);
                        return;
                    }
                }
                break;

                case RandomItemType.AverageItem:
                {
                    foreach (int[] v2 in v.args)
                    {
                        if (v2[0] > 0 && ItemConfig.get(v2[0]) == null)
                        {
                            Ctrl.throwError("找不到物品ID", v2[0]);
                            return;
                        }
                    }
                }
                break;

                case RandomItemType.WeightItem:
                {
                    foreach (int[] v2 in v.args)
                    {
                        if (v2[1] > 0 && ItemConfig.get(v2[1]) == null)
                        {
                            Ctrl.throwError("找不到物品ID", v2[1]);
                            return;
                        }
                    }
                }
                break;

                case RandomItemType.WeightCreateItem:
                {
                    foreach (int[] v2 in v.args)
                    {
                        if (v2[1] > 0 && CreateItemConfig.get(v2[1]) == null)
                        {
                            Ctrl.throwError("找不到创建物品ID", v2[1]);
                            return;
                        }
                    }
                }
                break;

                case RandomItemType.WeightRandomItem:
                {
                    foreach (int[] v2 in v.args)
                    {
                        if (v2[1] > 0 && RandomItemConfig.get(v2[1]) == null)
                        {
                            Ctrl.throwError("找不到随机物品ID", v2[1]);
                            return;
                        }
                    }
                }
                break;
                }
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// 随机一组物品
    /// </summary>
    public void randomList(SList <ItemData> list, ILogicEntity entity)
    {
        //list 不需要在这里clear ,最外层调用者负责维护
        if (seedType == ClientRandomSeedType.Server)
        {
            Ctrl.throwError("此随机组不支持客户端随机");
            return;
        }

        if (seedType == ClientRandomSeedType.Seed && !CommonSetting.needClientRandomSeeds)
        {
            Ctrl.throwError("此随机组模式需要开启客户端随机种子模式");
            return;
        }

        switch (type)
        {
        case RandomItemListType.SingleItem:
        {
            int[] arr = args[0];

            if (arr[0] > 0)
            {
                list.add(BaseC.logic.createItem(arr[0], arr.Length > 1 ? arr[1] : 1));
            }
        }
        break;

        case RandomItemListType.SingleRandomItem:
        {
            int[] arr = args[0];

            if (arr[0] > 0)
            {
                ItemData data = RandomItemConfig.get(arr[0]).randomOne(entity, seedType);

                if (data != null)
                {
                    data.num *= (arr.Length > 1 ? arr[1] : 1);

                    list.add(data);
                }
            }
        }
        break;

        case RandomItemListType.SumProbRandomItem:
        {
            foreach (int[] arr in args)
            {
                bool randomProb = false;

                //万分位
                if (seedType == ClientRandomSeedType.Client)
                {
                    randomProb = MathUtils.randomProb(arr[0], 10000);
                }
                else
                {
                    randomProb = entity.randomProb(arr[0], 10000);
                }

                if (randomProb)
                {
                    ItemData data = RandomItemConfig.get(arr[1]).randomOne(entity, seedType);

                    if (data != null)
                    {
                        int min = arr.Length > 2 ? arr[2] : 1;
                        int max = arr.Length > 3 ? arr[3] : min;

                        if (min == max)
                        {
                            data.num *= min;
                        }
                        else
                        {
                            if (seedType == ClientRandomSeedType.Client)
                            {
                                data.num *= MathUtils.randomRange2(min, max);
                            }
                            else
                            {
                                data.num *= entity.randomRange2(min, max);
                            }
                        }

                        list.add(data);
                    }
                }
            }
        }
        break;

        case RandomItemListType.WeightRandomList:
        {
            int[] arr = _weightTool.randomForIntArr(entity, seedType);

            if (arr[1] > 0)
            {
                get(arr[1]).randomList(list, entity);
            }
        }
        break;
        }
    }
Beispiel #3
0
 /** 随机一个物品(可能为空) */
 public ItemData randomItem(int randomItemConfigID, ILogicEntity entity, int seedType)
 {
     return(RandomItemConfig.get(randomItemConfigID).randomOne(entity, seedType));
 }
Beispiel #4
0
    /// <summary>
    /// 读完所有表后处理
    /// </summary>
    public static void afterReadConfigAll()
    {
        if (_dic == null)
        {
            return;
        }

        RandomItemListConfig[] values;
        RandomItemListConfig   v;

        for (int i = (values = _dic.getValues()).Length - 1; i >= 0; --i)
        {
            if ((v = values[i]) != null)
            {
                switch (v.type)
                {
                case RandomItemListType.SingleItem:
                {
                    int itemID = v.args[0][0];
                    if (itemID > 0 && ItemConfig.get(itemID) == null)
                    {
                        Ctrl.throwError("找不到物品ID", itemID);
                        return;
                    }
                }
                break;

                case RandomItemListType.SingleRandomItem:
                {
                    int randomItemID = v.args[0][0];

                    if (randomItemID > 0 && RandomItemConfig.get(randomItemID) == null)
                    {
                        Ctrl.throwError("找不到随机物品ID", randomItemID);
                        return;
                    }
                }
                break;

                case RandomItemListType.SumProbRandomItem:
                {
                    foreach (int[] v2 in v.args)
                    {
                        if (v2[1] > 0 && RandomItemConfig.get(v2[1]) == null)
                        {
                            Ctrl.throwError("找不到随机物品ID", v2[1]);
                            return;
                        }
                    }
                }
                break;

                case RandomItemListType.WeightRandomList:
                {
                    foreach (int[] v2 in v.args)
                    {
                        if (v2[1] > 0 && RandomItemListConfig.get(v2[1]) == null)
                        {
                            Ctrl.throwError("找不到随机物品组ID", v2[1]);
                            return;
                        }
                    }
                }
                break;
                }

                //直接算出统计
                v.getNeedGridNum();
            }
        }
    }