public static CharaData Generate(long id, NativeStringList NSL)
        {
            var tmp = new CharaData();

            float vv       = id;
            var   name_tmp = "Chara" + (vv * vv).GetHashCode().ToString();

            NSL.Add(name_tmp);

            vv *= 0.1f;
            vv  = vv * vv;

            tmp.ID      = id;
            tmp.Name    = NSL.Last;
            tmp.HP      = (int)id * 100;
            tmp.MP      = (int)id * 50;
            tmp.Attack  = vv * 4;
            tmp.Defence = vv * 3;
            //tmp.Attack = (int)id * 4;
            //tmp.Defence = (int)id * 3;

            return(tmp);
        }
Example #2
0
        private static bool ParseLineImpl(ref CharaDataParser.DataPack pack, ReadOnlyStringEntity line)
        {
            pack.Lines++;
            if (line.Length < 1)
            {
                return(true);
            }

            line.Split('\t', pack.str_list);

            //--- check data block
            if (pack.str_list.Length >= 2 && pack.str_list[0] == pack.mark_tag)
            {
                if (pack.str_list[1] == pack.mark_header)
                {
                    pack.read_mode = CharaDataParser.ReadMode.Header;
                }
                else if (pack.str_list[1] == pack.mark_ext)
                {
                    pack.read_mode = CharaDataParser.ReadMode.ExtData;
                }
                else if (pack.str_list[1] == pack.mark_ext_end)
                {
                    pack.read_mode = CharaDataParser.ReadMode.None;
                }
                else if (pack.str_list[1] == pack.mark_body)
                {
                    //--- check header info was read correctly or not
                    if (pack.N <= 0 || pack.D <= 0 || pack.R < 0.0 || pack.R >= 1.0)
                    {
                        pack.read_mode = CharaDataParser.ReadMode.HeaderError;
                        return(false);
                    }
                    pack.read_mode = CharaDataParser.ReadMode.Body;
                }
                return(true);
            }
            if (pack.read_mode == CharaDataParser.ReadMode.None)
            {
                return(true);
            }

            //--- ignore comment line
            if (pack.str_list[0].Length >= 1 && pack.str_list[0].Slice(0, 1) == pack.mark_comment)
            {
                return(true);
            }

            //--- store data
            if (pack.read_mode == CharaDataParser.ReadMode.Header)
            {
                bool success = true;
                // using normal TryParse() for large scope optimization of BurstCompile
                if (pack.str_list[0] == pack.mark_n_total)
                {
                    success = pack.str_list[1].TryParse(out pack.N);
                }
                else if (pack.str_list[0] == pack.mark_d)
                {
                    success = pack.str_list[1].TryParse(out pack.D);
                }
                else if (pack.str_list[0] == pack.mark_r)
                {
                    success = pack.str_list[1].TryParse(out pack.R);
                }

                if (!success)
                {
                    pack.read_mode = CharaDataParser.ReadMode.HeaderError;
                    return(false);
                }
            }
            else if (pack.read_mode == CharaDataParser.ReadMode.ExtData)
            {
                if (pack.str_list.Length > 1)
                {
                    // must be 1 element in line
                    pack.read_mode = CharaDataParser.ReadMode.Base64DataError;
                    return(false);
                }
                else if (pack.str_list.Length == 1)
                {
                    bool success = pack.b64_decoder.GetBytes(pack.b64_decoded_bytes, pack.str_list[0]);
                    if (!success)
                    {
                        pack.read_mode = CharaDataParser.ReadMode.Base64DataError;
                        return(false);
                    }
                }
            }
            else if (pack.read_mode == CharaDataParser.ReadMode.Body)
            {
                if (pack.str_list.Length < 6)
                {
                    return(true);
                }

                var  tmp     = new CharaData();
                bool success = true;
                // using normal TryParse() for large scope optimization of BurstCompile
                success = success && pack.str_list[0].TryParse(out tmp.ID);
                success = success && pack.str_list[2].TryParse(out tmp.HP);
                success = success && pack.str_list[3].TryParse(out tmp.MP);
                success = success && pack.str_list[4].TryParse(out tmp.Attack);
                success = success && pack.str_list[5].TryParse(out tmp.Defence);

                if (!success)
                {
                    pack.read_mode = CharaDataParser.ReadMode.FormatError;
                    return(false);
                }

                pack.tmp_name.Add(pack.str_list[1]);
                tmp.Name = pack.tmp_name.Last;

                pack.Data.Add(tmp);

                if (pack.Data.Length > pack.N)
                {
                    pack.read_mode = CharaDataParser.ReadMode.FormatError;
                    return(false);
                }
            }

            return(true);
        }
Example #3
0
        private bool ParseLineImpl(ReadOnlyStringEntity line)
        {
            pack.Lines++;
            if (line.Length < 1)
            {
                return(true);
            }

            if (EnableBurstFunc)
            {
                BurstFunc.Split(line, '\t', _str_list);
            }
            else
            {
                line.Split('\t', _str_list);
            }

            //--- check data block
            if (_str_list.Length >= 2 && _str_list[0] == pack.mark_tag)
            {
                if (_str_list[1] == pack.mark_header)
                {
                    pack.read_mode = ReadMode.Header;
                }
                else if (_str_list[1] == pack.mark_ext)
                {
                    pack.read_mode = ReadMode.ExtData;
                }
                else if (_str_list[1] == pack.mark_ext_end)
                {
                    pack.read_mode = ReadMode.None;
                }
                else if (_str_list[1] == pack.mark_body)
                {
                    //--- check header info was read correctly or not
                    if (pack.N <= 0 || pack.D <= 0 || pack.R < 0.0 || pack.R >= 1.0)
                    {
                        pack.read_mode = ReadMode.HeaderError;
                        return(false);
                    }
                    pack.read_mode = ReadMode.Body;
                }
                return(true);
            }
            if (pack.read_mode == ReadMode.None)
            {
                return(true);
            }

            //--- ignore comment line
            if (_str_list[0].Length >= 1 && _str_list[0].Slice(0, 1) == pack.mark_comment)
            {
                return(true);
            }

            //--- store data
            if (pack.read_mode == ReadMode.Header)
            {
                bool success = true;
                if (EnableBurstFunc)
                {
                    // using BurstCompiler applied TryParse
                    if (_str_list[0] == pack.mark_n_total)
                    {
                        success = BurstFunc.TryParse(_str_list[1], out pack.N);
                    }
                    else if (_str_list[0] == pack.mark_d)
                    {
                        success = BurstFunc.TryParse(_str_list[1], out pack.D);
                    }
                    else if (_str_list[0] == pack.mark_r)
                    {
                        success = BurstFunc.TryParse(_str_list[1], out pack.R);
                    }
                }
                else
                {
                    // using normal TryParse()
                    if (_str_list[0] == pack.mark_n_total)
                    {
                        success = _str_list[1].TryParse(out pack.N);
                    }
                    else if (_str_list[0] == pack.mark_d)
                    {
                        success = _str_list[1].TryParse(out pack.D);
                    }
                    else if (_str_list[0] == pack.mark_r)
                    {
                        success = _str_list[1].TryParse(out pack.R);
                    }
                }

                if (!success)
                {
                    pack.read_mode = ReadMode.HeaderError;
                    return(false);
                }
            }
            else if (pack.read_mode == ReadMode.ExtData)
            {
                if (_str_list.Length > 1)
                {
                    // must be 1 element in line
                    pack.read_mode = ReadMode.Base64DataError;
                    return(false);
                }
                else if (_str_list.Length == 1)
                {
                    bool success = true;
                    if (EnableBurst)
                    {
                        // using BurstCompiler applied GetChars()
                        success = BurstFunc.GetBytes(_b64_decoder, _b64_decoded_bytes, _str_list[0]);
                    }
                    else
                    {
                        // using normal GetChars()
                        success = _b64_decoder.GetBytes(_b64_decoded_bytes, _str_list[0]);
                    }

                    if (!success)
                    {
                        pack.read_mode = ReadMode.Base64DataError;
                        return(false);
                    }
                }
            }
            else if (pack.read_mode == ReadMode.Body)
            {
                if (_str_list.Length < 6)
                {
                    return(true);
                }

                var  tmp     = new CharaData();
                bool success = true;
                if (EnableBurstFunc)
                {
                    // using BurstCompiler applied TryParse
                    success = success && BurstFunc.TryParse(_str_list[0], out tmp.ID);
                    success = success && BurstFunc.TryParse(_str_list[2], out tmp.HP);
                    success = success && BurstFunc.TryParse(_str_list[3], out tmp.MP);
                    success = success && BurstFunc.TryParse(_str_list[4], out tmp.Attack);
                    success = success && BurstFunc.TryParse(_str_list[5], out tmp.Defence);
                }
                else
                {
                    // using normal TryParse()
                    success = success && _str_list[0].TryParse(out tmp.ID);
                    success = success && _str_list[2].TryParse(out tmp.HP);
                    success = success && _str_list[3].TryParse(out tmp.MP);
                    success = success && _str_list[4].TryParse(out tmp.Attack);
                    success = success && _str_list[5].TryParse(out tmp.Defence);
                }

                if (!success)
                {
                    pack.read_mode = ReadMode.FormatError;
                    return(false);
                }

                _tmp_name.Add(_str_list[1]);
                tmp.Name = _tmp_name.Last;

                Data.Add(tmp);

                if (Data.Length > pack.N)
                {
                    pack.read_mode = ReadMode.FormatError;
                    return(false);
                }
            }

            return(true);
        }