public bool LoadFromDBFile(string dbPath)
        {
            if (string.IsNullOrEmpty(dbPath))
            {
                return(false);
            }
            m_dbPath = dbPath;

            var sqlCnn = new SQLiteConnection();

            sqlCnn.ConnectionString = string.Format("Data Source={0};Version = 3", dbPath);
            sqlCnn.Open();

            var cmd = sqlCnn.CreateCommand();

            cmd.CommandText = "Select * FROM material";

            var reader = cmd.ExecuteReader();

            if (reader == null)
            {
                MyDebug.WriteLine("Error loading Material data from DBFile!");
                return(false);
            }
            m_ingredientList.Clear();
            m_indexMap.Clear();
            while (reader.Read())
            {
                int column  = 0;
                var matData = new IngredientData();
                matData.id      = reader.GetInt32Safe(column++);
                matData.key     = reader.GetStringSafe(column++);
                matData.food_id = reader.GetInt32Safe(column++);
                matData.price   = reader.GetInt32Safe(column++);
                matData.texture = reader.GetStringSafe(column++);

                string colName = reader.GetName(column);
                if (colName.Contains("name_"))
                {
                    string location = colName.Substring(5);
                    matData.display_name.Add(location, reader.GetStringSafe(column));
                }
                else if (colName.Contains("position"))
                {
                    //int mapId = int.Parse(colName.Substring(8));
                    matData.display_position.Add(colName.Substring(8), reader.GetStringSafe(column));
                }
                column++;

                m_ingredientList.Add(matData);
                m_indexMap.AddValue(matData.key, matData.id, m_ingredientList.Count - 1);
            }

            reader.Close();
            cmd.Dispose();
            sqlCnn.Close();
            sqlCnn.Dispose();

            return(true);
        }
        public void AddIngredient(IngredientData ing)
        {
            int i;

            if (!m_indexMap.GetValue(ing.key, out i))
            {
                m_ingredientList.Add(ing);
                i = m_ingredientList.Count - 1;
                m_indexMap.AddValue(ing.key, ing.id, i);
            }
        }
        public void RemoveIngredient(int id)
        {
            int i;

            if (m_indexMap.GetValue(id, out i))
            {
                IngredientData ing = m_ingredientList[i];
                m_indexMap.RemoveValue(ing.key, id);
                m_ingredientList.RemoveAt(i);
            }
        }
Пример #4
0
        private int calcFoodPrice(string key)
        {
            int price = 0;

            if (!m_foodPriceDict.TryGetValue(key, out price))
            {
                FoodData fd = GetFood(key);
                if (fd != null)
                {
                    float priceDecay = 1.0f;
                    var   ingList    = fd.ingredients;
                    if (ingList.Count == 0)
                    {
                        price += fd.price;
                    }
                    else
                    {
                        for (int i = 0; i < ingList.Count; ++i)
                        {
                            string         ingKey  = ingList[i];
                            IngredientData ingData = _ingMgr.GetIngredient(ingKey);
                            if (ingData == null)
                            {
                                FoodData foodData = GetFood(ingKey);
                                if (foodData != null)
                                {
                                    price += calcFoodPrice(foodData.key);
                                }
                            }
                            else
                            {
                                price      += (int)(ingData.price * priceDecay);
                                priceDecay *= 0.6f;
                            }
                        }
                    }

                    CookwareData cw = _cwMgr.GetCookware(fd.cookware_type + 1);
                    if (cw != null)
                    {
                        // 需要厨具制作则根据制作时长再作调整
                        priceDecay = 1.2f;
                        float cookTime = fd.cook_time;
                        float baseTime = cw.base_work_time;
                        if (cookTime > baseTime * 1.8f)
                        {
                            priceDecay += 0.3f;
                        }
                        else if (cookTime > baseTime)
                        {
                            priceDecay += (cookTime - baseTime) * 0.375f / baseTime;
                        }
                        price = (int)(price * priceDecay);
                    }
                }

                m_foodPriceDict.Add(key, price);
            }

            return(price);
        }