CreateSampleRecipes.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Module\Game\Models\GameConsumeGroup;
  6. use App\Module\Game\Models\GameConsumeItem;
  7. use App\Module\Game\Models\GameRewardGroup;
  8. use App\Module\Game\Models\GameRewardItem;
  9. use App\Module\Game\Models\GameConditionGroup;
  10. use App\Module\Game\Models\GameConditionItem;
  11. use App\Module\GameItems\Models\ItemRecipe;
  12. class CreateSampleRecipes extends Command
  13. {
  14. /**
  15. * The name and signature of the console command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'recipes:create-samples';
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = '创建示例合成配方(使用组系统)';
  26. /**
  27. * Execute the console command.
  28. */
  29. public function handle()
  30. {
  31. $this->info('开始创建示例合成配方...');
  32. try {
  33. DB::beginTransaction();
  34. // 创建木板制作配方
  35. $this->createWoodPlankRecipe();
  36. // 创建高级木材加工配方
  37. $this->createAdvancedWoodRecipe();
  38. DB::commit();
  39. $this->info('示例配方创建完成!');
  40. } catch (\Exception $e) {
  41. DB::rollBack();
  42. $this->error('创建失败: ' . $e->getMessage());
  43. return 1;
  44. }
  45. return 0;
  46. }
  47. /**
  48. * 创建木板制作配方
  49. */
  50. private function createWoodPlankRecipe()
  51. {
  52. $this->info('创建木板制作配方...');
  53. // 1. 创建消耗组
  54. $consumeGroup = GameConsumeGroup::create([
  55. 'name' => '木板制作消耗',
  56. 'code' => 'wood_plank_consume',
  57. 'description' => '制作木板需要消耗的材料',
  58. ]);
  59. // 添加消耗项:1个木材
  60. GameConsumeItem::create([
  61. 'group_id' => $consumeGroup->id,
  62. 'consume_type' => 1, // 物品类型
  63. 'target_id' => 33, // 木材ID
  64. 'quantity' => 1,
  65. ]);
  66. // 2. 创建奖励组
  67. $rewardGroup = GameRewardGroup::create([
  68. 'name' => '木板制作奖励',
  69. 'code' => 'wood_plank_reward',
  70. 'description' => '制作木板获得的奖励',
  71. 'is_random' => false, // 全部发放
  72. ]);
  73. // 添加奖励项:4个木板(假设木板ID为34)
  74. GameRewardItem::create([
  75. 'group_id' => $rewardGroup->id,
  76. 'reward_type' => 1, // 物品类型
  77. 'target_id' => 34, // 木板ID(需要先创建木板物品)
  78. 'quantity' => 4,
  79. 'weight' => 1.0,
  80. 'is_guaranteed' => true,
  81. ]);
  82. // 3. 创建配方
  83. ItemRecipe::create([
  84. 'name' => '木板制作',
  85. 'code' => 'wood_plank_craft',
  86. 'description' => '将木材加工成木板,是基础的木工技能',
  87. 'consume_group_id' => $consumeGroup->id,
  88. 'reward_group_id' => $rewardGroup->id,
  89. 'condition_group_id' => null, // 无条件,默认解锁
  90. 'success_rate' => 1.0, // 100%成功率
  91. 'cooldown_seconds' => 0,
  92. 'sort_order' => 100,
  93. 'is_active' => true,
  94. ]);
  95. $this->line(' - 木板制作配方创建完成');
  96. }
  97. /**
  98. * 创建高级木材加工配方
  99. */
  100. private function createAdvancedWoodRecipe()
  101. {
  102. $this->info('创建高级木材加工配方...');
  103. // 1. 创建消耗组
  104. $consumeGroup = GameConsumeGroup::create([
  105. 'name' => '高级木材加工消耗',
  106. 'code' => 'advanced_wood_consume',
  107. 'description' => '高级木材加工需要消耗的材料',
  108. ]);
  109. // 添加消耗项:3个木材 + 10金币
  110. GameConsumeItem::create([
  111. 'group_id' => $consumeGroup->id,
  112. 'consume_type' => 1, // 物品类型
  113. 'target_id' => 33, // 木材ID
  114. 'quantity' => 3,
  115. ]);
  116. GameConsumeItem::create([
  117. 'group_id' => $consumeGroup->id,
  118. 'consume_type' => 2, // 货币类型
  119. 'target_id' => 1, // 金币ID
  120. 'quantity' => 10,
  121. ]);
  122. // 2. 创建奖励组
  123. $rewardGroup = GameRewardGroup::create([
  124. 'name' => '高级木材加工奖励',
  125. 'code' => 'advanced_wood_reward',
  126. 'description' => '高级木材加工获得的奖励',
  127. 'is_random' => true, // 随机发放
  128. 'random_count' => 1, // 随机选择1个奖励
  129. ]);
  130. // 添加奖励项:随机获得高级木材或特殊木材
  131. GameRewardItem::create([
  132. 'group_id' => $rewardGroup->id,
  133. 'reward_type' => 1, // 物品类型
  134. 'target_id' => 35, // 高级木材ID(需要先创建)
  135. 'quantity' => 2,
  136. 'weight' => 70.0, // 70%概率
  137. 'is_guaranteed' => false,
  138. ]);
  139. GameRewardItem::create([
  140. 'group_id' => $rewardGroup->id,
  141. 'reward_type' => 1, // 物品类型
  142. 'target_id' => 36, // 特殊木材ID(需要先创建)
  143. 'quantity' => 1,
  144. 'weight' => 30.0, // 30%概率
  145. 'is_guaranteed' => false,
  146. ]);
  147. // 3. 创建条件组
  148. $conditionGroup = GameConditionGroup::create([
  149. 'name' => '高级木材加工条件',
  150. 'code' => 'advanced_wood_condition',
  151. 'description' => '解锁高级木材加工的条件',
  152. 'logic_type' => 1, // 全部满足
  153. ]);
  154. // 添加条件项:玩家等级≥5
  155. GameConditionItem::create([
  156. 'group_id' => $conditionGroup->id,
  157. 'condition_type' => 1, // 假设1为玩家等级条件
  158. 'target_id' => 0, // 玩家等级不需要target_id
  159. 'operator' => 4, // 大于等于
  160. 'value' => 5,
  161. ]);
  162. // 4. 创建配方
  163. ItemRecipe::create([
  164. 'name' => '高级木材加工',
  165. 'code' => 'advanced_wood_craft',
  166. 'description' => '使用特殊工艺加工木材,有机会获得稀有材料',
  167. 'consume_group_id' => $consumeGroup->id,
  168. 'reward_group_id' => $rewardGroup->id,
  169. 'condition_group_id' => $conditionGroup->id,
  170. 'success_rate' => 0.8, // 80%成功率
  171. 'cooldown_seconds' => 300, // 5分钟冷却
  172. 'sort_order' => 50,
  173. 'is_active' => true,
  174. ]);
  175. $this->line(' - 高级木材加工配方创建完成');
  176. }
  177. }