Esempio n. 1
0
        private void InitDishAll(PlayerData _playerData)
        {
            for (int i = 0; i < _playerData.dish.Count; i++)
            {
                DishData data = _playerData.dish[i];

                if (!data.sds.GetResult().GetIsUniversal() && !dishAll.Contains(data.sds.GetResult()))
                {
                    dishAll.Add(data.sds.GetResult());
                }
            }
        }
Esempio n. 2
0
        private void RefreshDishTo(bool _isMine, ushort _tick)
        {
            Worker[]        workers;
            List <DishData> dish;

            if (_isMine)
            {
                workers = mData.workers;
                dish    = mData.dish;
            }
            else
            {
                workers = oData.workers;
                dish    = oData.dish;
            }

            for (int i = 0; i < dish.Count; i++)
            {
                int tickWithWorker = 0;

                int tickWithoutWorker = _tick - tick;

                DishData data = dish[i];

                for (int m = 0; m < workers.Length; m++)
                {
                    Worker worker = workers[m];

                    if (worker.pos == i)
                    {
                        if (worker.punishTick < tickWithoutWorker)
                        {
                            tickWithWorker = tickWithoutWorker - worker.punishTick;

                            tickWithoutWorker -= tickWithWorker;
                        }

                        break;
                    }
                }

                if (tickWithoutWorker > 0)
                {
                    RefreshOneDishWithoutWorkerTo(data, tickWithoutWorker);
                }

                if (tickWithWorker > 0)
                {
                    RefreshOneDishWithWorkerTo(data, tickWithWorker);
                }
            }
        }
Esempio n. 3
0
        internal void SetDishData(IList <int> _dish)
        {
            for (int i = 0; i < _dish.Count; i++)
            {
                DishData data = new DishData();

                IDishSDS sds = CookMain.getDishData(_dish[i]);

                data.sds = sds;

                dish.Add(data);
            }
        }
Esempio n. 4
0
        internal void FromBytes(BinaryReader _br)
        {
            money = _br.ReadInt32();

            int num = _br.ReadInt32();

            for (int i = 0; i < num; i++)
            {
                DishData data = new DishData();

                data.FromBytes(_br);

                dish.Add(data);
            }

            for (int i = 0; i < CookConst.WORKER_NUM; i++)
            {
                workers[i].FromBytes(_br);
            }

            for (int i = 0; i < CookConst.RESULT_STATE.Length; i++)
            {
                bool b = _br.ReadBoolean();

                if (b)
                {
                    DishResult dishResult = result[i];

                    if (dishResult == null)
                    {
                        dishResult = new DishResult();

                        result[i] = dishResult;
                    }

                    dishResult.FromBytes(_br);
                }
                else
                {
                    result[i] = null;
                }
            }
        }
Esempio 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;
                }
            }
        }
Esempio n. 6
0
        private void GetCommandCompleteDishReal(CommandCompleteDish _command, PlayerData _playerData)
        {
            if (_command.pos > -1 && _command.pos < _playerData.dish.Count)
            {
                DishData dish = _playerData.dish[_command.pos];

                if (dish.result != null)
                {
                    if (_command.targetPos > -1 && _command.targetPos < _playerData.result.Length && _playerData.result[_command.targetPos] == null)
                    {
                        _playerData.result[_command.targetPos] = dish.result;
                    }

                    dish.result = null;

                    dish.state = DishState.NULL;

                    dish.time = 0;

                    eventCallBack?.Invoke(_command);
                }
            }
        }
Esempio n. 7
0
        private void RefreshOneDishWithoutWorkerTo(DishData _data, int _tick)
        {
            while (_tick > 0)
            {
                switch (_data.state)
                {
                case DishState.PREPAREING:

                    _data.time -= _data.sds.GetPrepareDecreaseValue() * _tick;

                    if (_data.time < 0)
                    {
                        _data.time = 0;

                        _data.state = DishState.NULL;
                    }

                    _tick = 0;

                    break;

                case DishState.COOKING:

                    _data.time += _tick;

                    if (_data.time > _data.sds.GetCookTime() * CookConst.TICK_NUM_PER_SECOND)
                    {
                        _tick = (int)(_data.time - GetTimeFix(_data.sds.GetCookTime() * CookConst.TICK_NUM_PER_SECOND));

                        _data.time = 0;

                        _data.state = DishState.OPTIMIZING;

                        _data.result = new DishResult();

                        _data.result.sds = _data.sds.GetResult();
                    }
                    else
                    {
                        _tick = 0;
                    }

                    break;

                case DishState.OPTIMIZING:

                    if (_data.result != null)
                    {
                        _data.result.time += CookConst.EXCEED_VALUE_3 * _tick;

                        if (_data.result.time > _data.result.sds.GetExceedTime() * CookConst.TICK_NUM_PER_SECOND)
                        {
                            _data.time = 0;

                            _data.result = null;

                            _data.state = DishState.NULL;
                        }
                    }

                    _data.time -= _data.sds.GetOptimizeDecreaseValue() * _tick;

                    if (_data.time < 0)
                    {
                        _data.time = 0;
                    }

                    _tick = 0;

                    break;

                default:

                    if (_data.result != null)
                    {
                        _data.result.time += CookConst.EXCEED_VALUE_3 * _tick;

                        if (_data.result.time > _data.result.sds.GetExceedTime() * CookConst.TICK_NUM_PER_SECOND)
                        {
                            _data.time = 0;

                            _data.result = null;

                            _data.state = DishState.NULL;
                        }
                    }

                    _tick = 0;

                    break;
                }
            }
        }
Esempio n. 8
0
        private void RefreshDish(bool _isMine)
        {
            Worker[]        workers;
            List <DishData> dish;

            if (_isMine)
            {
                workers = mData.workers;
                dish    = mData.dish;
            }
            else
            {
                workers = oData.workers;
                dish    = oData.dish;
            }

            for (int i = 0; i < dish.Count; i++)
            {
                DishData data = dish[i];

                bool hasWorker = false;

                for (int m = 0; m < workers.Length; m++)
                {
                    Worker worker = workers[m];

                    if (worker.pos == i)
                    {
                        if (worker.punishTick == 0)
                        {
                            hasWorker = true;
                        }

                        break;
                    }
                }

                if (hasWorker)
                {
                    switch (data.state)
                    {
                    case DishState.PREPAREING:

                        data.time++;

                        if (data.time > data.sds.GetPrepareTime() * CookConst.TICK_NUM_PER_SECOND)
                        {
                            data.time = 0;

                            if (data.sds.GetCookTime() > 0)
                            {
                                data.state = DishState.COOKING;
                            }
                            else
                            {
                                data.state = DishState.OPTIMIZING;

                                data.result = new DishResult();

                                data.result.sds = data.sds.GetResult();
                            }
                        }

                        break;

                    case DishState.COOKING:

                        data.time++;

                        if (data.time > data.sds.GetCookTime() * CookConst.TICK_NUM_PER_SECOND)
                        {
                            data.time = 0;

                            data.state = DishState.OPTIMIZING;

                            data.result = new DishResult();

                            data.result.sds = data.sds.GetResult();
                        }

                        break;

                    case DishState.OPTIMIZING:

                        data.time++;

                        if (data.time > data.sds.GetOptimizeTime() * CookConst.TICK_NUM_PER_SECOND)
                        {
                            data.time = 0;

                            data.state = DishState.NULL;

                            data.result.isOptimized = true;
                        }

                        break;

                    default:

                        if (data.result == null)
                        {
                            data.time++;

                            data.state = DishState.PREPAREING;
                        }
                        else
                        {
                            data.result.time += CookConst.EXCEED_VALUE_3;

                            if (data.result.time > data.result.sds.GetExceedTime() * CookConst.TICK_NUM_PER_SECOND)
                            {
                                data.time = 0;

                                data.result = null;

                                data.state = DishState.NULL;
                            }
                        }

                        break;
                    }
                }
                else
                {
                    switch (data.state)
                    {
                    case DishState.PREPAREING:

                        data.time -= data.sds.GetPrepareDecreaseValue();

                        if (data.time < 0)
                        {
                            data.time = 0;

                            data.state = DishState.NULL;
                        }

                        break;

                    case DishState.COOKING:

                        data.time++;

                        if (data.time > data.sds.GetCookTime() * CookConst.TICK_NUM_PER_SECOND)
                        {
                            data.time = 0;

                            data.state = DishState.OPTIMIZING;

                            data.result = new DishResult();

                            data.result.sds = data.sds.GetResult();
                        }

                        break;

                    case DishState.OPTIMIZING:

                        data.time -= data.sds.GetOptimizeDecreaseValue();

                        if (data.time < 0)
                        {
                            data.time = 0;
                        }

                        data.result.time += CookConst.EXCEED_VALUE_3;

                        if (data.result.time > data.result.sds.GetExceedTime() * CookConst.TICK_NUM_PER_SECOND)
                        {
                            data.time = 0;

                            data.result = null;

                            data.state = DishState.NULL;
                        }

                        break;

                    default:

                        if (data.result != null)
                        {
                            data.result.time += CookConst.EXCEED_VALUE_3;

                            if (data.result.time > data.result.sds.GetExceedTime() * CookConst.TICK_NUM_PER_SECOND)
                            {
                                data.time = 0;

                                data.result = null;

                                data.state = DishState.NULL;
                            }
                        }

                        break;
                    }
                }
            }
        }