Ejemplo n.º 1
0
        private void RefreshRequireTo(ushort _tick, List <ushort> _seedList)
        {
            int oldNum = tick / CookConst.REQUIRE_PRODUCE_TIME + (tick % CookConst.REQUIRE_PRODUCE_TIME == 0 ? 0 : 1);

            for (int i = oldNum; i < _seedList.Count; i++)
            {
                SetSeed(_seedList[i]);

                DishRequirement requirement = GetRequire();

                requirement.time = tick - i * CookConst.REQUIRE_PRODUCE_TIME;

                require.Add(requirement);
            }

            for (int i = require.Count - 1; i > -1; i--)
            {
                DishRequirement requirement = require[i];

                requirement.time += _tick - tick;

                if (requirement.time > CookConst.REQUIRE_EXCEED_TIME * CookConst.TICK_NUM_PER_SECOND)
                {
                    require.RemoveAt(i);
                }
            }
        }
Ejemplo n.º 2
0
        internal void FromBytes(BinaryReader _br)
        {
            Reset();

            tick = _br.ReadUInt16();

            requirementUid = _br.ReadInt32();

            mData.FromBytes(_br);

            oData.FromBytes(_br);

            int num = _br.ReadInt32();

            for (int i = 0; i < num; i++)
            {
                DishRequirement requirement = new DishRequirement();

                requirement.FromBytes(_br);

                require.Add(requirement);
            }

            InitDishAll();
        }
Ejemplo n.º 3
0
        private DishRequirement GetRequire()
        {
            DishRequirement requirement = new DishRequirement();

            requirement.uid = GetRequirementUid();

            List <IResultSDS> list = new List <IResultSDS>(dishAll);

            int num = random.Get(CookConst.REQUIRE_NUM_MIN, maxRequirementNum + 1);

            DishResultBase[] resultArr = new DishResultBase[num];

            requirement.dishArr = resultArr;

            int optimizeNum = random.Get((int)(CookConst.OPTIMIZE_PROBABILITY_MAX * num) + 1);

            for (int i = 0; i < num; i++)
            {
                int index = random.Get(list.Count);

                IResultSDS sds = list[index];

                if (sds.GetMaxNum() > 1)
                {
                    int oldNum = 1;

                    for (int m = 0; m < i; m++)
                    {
                        DishResultBase tmpResult = resultArr[m];

                        if (tmpResult.sds == sds)
                        {
                            oldNum++;
                        }
                    }

                    if (oldNum == sds.GetMaxNum())
                    {
                        list.RemoveAt(index);
                    }
                }
                else
                {
                    list.RemoveAt(index);
                }

                bool isOptimize = i < optimizeNum;

                DishResultBase result = new DishResultBase();

                result.sds = sds;

                result.isOptimized = isOptimize;

                resultArr[i] = result;
            }

            return(requirement);
        }
Ejemplo n.º 4
0
        private void AddReward(List <int> _resultList, PlayerData _playerData, DishRequirement _requirement)
        {
            int num = 0;

            bool allOptimized = true;

            for (int i = 0; i < _requirement.dishArr.Length; i++)
            {
                DishResultBase resultBase = _requirement.dishArr[i];

                num += resultBase.isOptimized ? resultBase.sds.GetMoneyOptimized() : resultBase.sds.GetMoney();

                int index = _resultList[i];

                DishResult result;

                if (index > -1 && index < _playerData.result.Length)
                {
                    result = _playerData.result[index];
                }
                else
                {
                    result = _playerData.dish[-index - 1].result;
                }

                if (!result.isOptimized)
                {
                    allOptimized = false;
                }
            }

            float fix = 1 + (_requirement.dishArr.Length - CookConst.REQUIRE_NUM_MIN) * (CookConst.REQUIRE_REWARD_FIX - 1) / (CookConst.REQUIRE_NUM_MAX - CookConst.REQUIRE_NUM_MIN);

            if (allOptimized)
            {
                num = (int)(num * fix * CookConst.REQUIRE_REWARD_ALL_OPTIMIZED_FIX);
            }
            else
            {
                num = (int)(num * fix);
            }

            _playerData.money += num;
        }
Ejemplo n.º 5
0
        internal void GetCommandCompleteRequirement(CommandCompleteRequirement _command)
        {
            for (int i = 0; i < require.Count; i++)
            {
                DishRequirement requirement = require[i];

                if (requirement.uid == _command.requirementUid)
                {
                    PlayerData playerData = _command.isMine ? mData : oData;

                    if (CheckCanCompleteRequirement(_command.resultList, playerData, requirement, true))
                    {
                        AddReward(_command.resultList, playerData, requirement);

                        require.RemoveAt(i);

                        for (int m = 0; m < _command.resultList.Count; m++)
                        {
                            int index = _command.resultList[m];

                            if (index > -1)
                            {
                                playerData.result[index] = null;
                            }
                            else
                            {
                                DishData dish = playerData.dish[-index - 1];

                                dish.result = null;

                                dish.state = DishState.NULL;

                                dish.time = 0;
                            }
                        }

                        eventCallBack?.Invoke(_command);
                    }

                    break;
                }
            }
        }
Ejemplo n.º 6
0
        private void RefreshRequire()
        {
            if (tick % CookConst.REQUIRE_PRODUCE_TIME == 0)
            {
                DishRequirement requirement = GetRequire();

                require.Add(requirement);
            }

            for (int i = require.Count - 1; i > -1; i--)
            {
                DishRequirement requirement = require[i];

                requirement.time++;

                if (requirement.time > CookConst.REQUIRE_EXCEED_TIME * CookConst.TICK_NUM_PER_SECOND)
                {
                    require.RemoveAt(i);
                }
            }
        }
Ejemplo n.º 7
0
        public bool CheckCanCompleteRequirement(List <int> _resultList, DishRequirement _requirement)
        {
            PlayerData playerData = clientIsMine ? main.mData : main.oData;

            return(main.CheckCanCompleteRequirement(_resultList, playerData, _requirement, false));
        }
Ejemplo n.º 8
0
        internal bool CheckCanCompleteRequirement(List <int> _resultList, PlayerData _playerData, DishRequirement _requirement, bool _throwException)
        {
            if (_resultList.Count != _requirement.dishArr.Length)
            {
                if (_throwException)
                {
                    throw new Exception("CheckCanCompleteRequirement  false0");
                }

                return(false);
            }

            List <DishResult> resultList = new List <DishResult>();

            for (int i = 0; i < _resultList.Count; i++)
            {
                int index = _resultList[i];

                if (index > -1 && index < _playerData.result.Length)
                {
                    DishResult result = _playerData.result[index];

                    if (result != null && !resultList.Contains(result))
                    {
                        resultList.Add(result);
                    }
                    else
                    {
                        if (_throwException)
                        {
                            throw new Exception("CheckCanCompleteRequirement  false1");
                        }

                        return(false);
                    }
                }
                else if (index < 0 && index > -_playerData.dish.Count - 1)
                {
                    DishResult result = _playerData.dish[-index - 1].result;

                    if (result != null && !resultList.Contains(result))
                    {
                        resultList.Add(result);
                    }
                    else
                    {
                        if (_throwException)
                        {
                            throw new Exception("CheckCanCompleteRequirement  false2");
                        }

                        return(false);
                    }
                }
                else
                {
                    if (_throwException)
                    {
                        throw new Exception("CheckCanCompleteRequirement  false3");
                    }

                    return(false);
                }
            }

            List <DishResultBase> requirementList = new List <DishResultBase>(_requirement.dishArr);

            for (int i = resultList.Count - 1; i > -1; i--)
            {
                DishResult result = resultList[i];

                for (int m = requirementList.Count - 1; m > -1; m--)
                {
                    DishResultBase requirement = requirementList[m];

                    if (result.sds == requirement.sds && result.isOptimized == requirement.isOptimized)
                    {
                        resultList.RemoveAt(i);

                        requirementList.RemoveAt(m);

                        break;
                    }
                }
            }

            if (requirementList.Count == 0)
            {
                return(true);
            }

            for (int i = resultList.Count - 1; i > -1; i--)
            {
                DishResult result = resultList[i];

                for (int m = requirementList.Count - 1; m > -1; m--)
                {
                    DishResultBase requirement = requirementList[m];

                    if (result.sds == requirement.sds && result.isOptimized)
                    {
                        resultList.RemoveAt(i);

                        requirementList.RemoveAt(m);

                        break;
                    }
                }
            }

            if (requirementList.Count == 0)
            {
                return(true);
            }

            for (int i = resultList.Count - 1; i > -1; i--)
            {
                DishResult result = resultList[i];

                for (int m = requirementList.Count - 1; m > -1; m--)
                {
                    DishResultBase requirement = requirementList[m];

                    if (result.sds.GetIsUniversal() && (result.isOptimized == requirement.isOptimized || result.isOptimized))
                    {
                        resultList.RemoveAt(i);

                        requirementList.RemoveAt(m);

                        break;
                    }
                }
            }

            if (requirementList.Count == 0)
            {
                return(true);
            }
            else
            {
                if (_throwException)
                {
                    throw new Exception("CheckCanCompleteRequirement  false4");
                }

                return(false);
            }
        }