Esempio n. 1
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;
        }
    }