add_wood_recipes.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. // 直接使用artisan命令运行,不需要手动初始化
  3. echo "开始添加木材相关配方数据...\n";
  4. // 配方数据
  5. $recipes = [
  6. [
  7. 'name' => '木板制作',
  8. 'result_item_id' => 34, // 木板ID
  9. 'result_quantity' => 4,
  10. 'success_rate' => 1.0, // 100%成功率
  11. 'coin_cost' => json_encode(['gold' => 2]),
  12. 'cooldown_seconds' => 0,
  13. 'is_visible' => 1,
  14. 'unlock_conditions' => json_encode([]),
  15. 'materials' => [
  16. [
  17. 'item_id' => 33, // 木材ID
  18. 'quantity' => 1,
  19. 'is_consumed' => 1
  20. ]
  21. ]
  22. ],
  23. [
  24. 'name' => '木箱制作',
  25. 'result_item_id' => 35, // 木箱ID(假设存在)
  26. 'result_quantity' => 1,
  27. 'success_rate' => 1.0,
  28. 'coin_cost' => json_encode(['gold' => 5]),
  29. 'cooldown_seconds' => 0,
  30. 'is_visible' => 1,
  31. 'unlock_conditions' => json_encode([]),
  32. 'materials' => [
  33. [
  34. 'item_id' => 34, // 木板ID
  35. 'quantity' => 4,
  36. 'is_consumed' => 1
  37. ]
  38. ]
  39. ],
  40. [
  41. 'name' => '木制工具箱',
  42. 'result_item_id' => 36, // 木制工具箱ID(假设存在)
  43. 'result_quantity' => 1,
  44. 'success_rate' => 0.9, // 90%成功率
  45. 'coin_cost' => json_encode(['gold' => 10]),
  46. 'cooldown_seconds' => 30,
  47. 'is_visible' => 1,
  48. 'unlock_conditions' => json_encode(['level' => 5]),
  49. 'materials' => [
  50. [
  51. 'item_id' => 34, // 木板ID
  52. 'quantity' => 6,
  53. 'is_consumed' => 1
  54. ],
  55. [
  56. 'item_id' => 37, // 铁钉ID(假设存在)
  57. 'quantity' => 2,
  58. 'is_consumed' => 1
  59. ]
  60. ]
  61. ],
  62. [
  63. 'name' => '高级木材加工',
  64. 'result_item_id' => 38, // 高级木材ID(假设存在)
  65. 'result_quantity' => 1,
  66. 'success_rate' => 0.8, // 80%成功率
  67. 'coin_cost' => json_encode(['gold' => 15]),
  68. 'cooldown_seconds' => 60,
  69. 'is_visible' => 1,
  70. 'unlock_conditions' => json_encode(['level' => 10]),
  71. 'materials' => [
  72. [
  73. 'item_id' => 33, // 木材ID
  74. 'quantity' => 3,
  75. 'is_consumed' => 1
  76. ],
  77. [
  78. 'item_id' => 39, // 特殊工具ID(假设存在)
  79. 'quantity' => 1,
  80. 'is_consumed' => 0 // 不消耗,只需要拥有
  81. ]
  82. ]
  83. ]
  84. ];
  85. try {
  86. DB::beginTransaction();
  87. foreach ($recipes as $recipeData) {
  88. echo "添加配方: {$recipeData['name']}\n";
  89. // 提取材料数据
  90. $materials = $recipeData['materials'];
  91. unset($recipeData['materials']);
  92. // 添加时间戳
  93. $recipeData['created_at'] = now();
  94. $recipeData['updated_at'] = now();
  95. // 插入配方
  96. $recipeId = DB::table('item_recipes')->insertGetId($recipeData);
  97. // 插入材料
  98. foreach ($materials as $material) {
  99. $material['recipe_id'] = $recipeId;
  100. $material['created_at'] = now();
  101. $material['updated_at'] = now();
  102. DB::table('item_recipe_materials')->insert($material);
  103. echo " - 添加材料: 物品ID {$material['item_id']}, 数量 {$material['quantity']}\n";
  104. }
  105. echo "配方 '{$recipeData['name']}' 添加成功,ID: {$recipeId}\n\n";
  106. }
  107. DB::commit();
  108. echo "所有木材相关配方添加完成!\n";
  109. } catch (Exception $e) {
  110. DB::rollBack();
  111. echo "错误: " . $e->getMessage() . "\n";
  112. exit(1);
  113. }