Exemplo n.º 1
0
        internal void ToBytes(BinaryWriter _bw)
        {
            _bw.Write(money);

            _bw.Write(dish.Count);

            for (int i = 0; i < dish.Count; i++)
            {
                dish[i].ToBytes(_bw);
            }

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

            for (int i = 0; i < CookConst.RESULT_STATE.Length; i++)
            {
                DishResult dishResult = result[i];

                if (dishResult != null)
                {
                    _bw.Write(true);

                    dishResult.ToBytes(_bw);
                }
                else
                {
                    _bw.Write(false);
                }
            }
        }
Exemplo n.º 2
0
        internal void FromBytes(BinaryReader _br)
        {
            int id = _br.ReadInt32();

            sds = CookMain.getDishData(id);

            state = (DishState)_br.ReadByte();

            time = _br.ReadSingle();

            bool b = _br.ReadBoolean();

            if (b)
            {
                if (result == null)
                {
                    result = new DishResult();
                }

                result.FromBytes(_br);
            }
            else
            {
                result = null;
            }
        }
Exemplo n.º 3
0
        private void GetCommandChangeResultPosReal(CommandChangeResultPos _command, PlayerData _playerData)
        {
            if (_command.pos > -1 && _command.pos < _playerData.result.Length)
            {
                DishResult result = _playerData.result[_command.pos];

                if (result != null)
                {
                    if (_command.targetPos == -1)
                    {
                        _playerData.result[_command.pos] = null;

                        eventCallBack?.Invoke(_command);
                    }
                    else
                    {
                        if (_command.targetPos > -1 && _command.targetPos < _playerData.result.Length && _command.pos != _command.targetPos)
                        {
                            _playerData.result[_command.pos] = _playerData.result[_command.targetPos];

                            _playerData.result[_command.targetPos] = result;

                            eventCallBack?.Invoke(_command);
                        }
                    }
                }
            }
        }
Exemplo 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;
                }
            }
        }
Exemplo n.º 5
0
        private void RefreshResultTo(bool _isMine, ushort _tick)
        {
            DishResult[] results = _isMine ? mData.result : oData.result;

            for (int i = 0; i < results.Length; i++)
            {
                DishResult result = results[i];

                if (result != null && CookConst.RESULT_STATE[i])
                {
                    result.time += (CookConst.RESULT_STATE[i] ? CookConst.EXCEED_VALUE_2 : CookConst.EXCEED_VALUE_1) * (_tick - tick);

                    if (result.time > result.sds.GetExceedTime() * CookConst.TICK_NUM_PER_SECOND)
                    {
                        results[i] = null;
                    }
                }
            }
        }
Exemplo n.º 6
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);
            }
        }