surv_1.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. event.load("entity_click");
  2. event.load("block_break");
  3. event.load("inv_click");
  4. overworld = world.get("overworld");
  5. loc = loc.new(overworld, 66, 69, 444);
  6. plot_list = plot.get(loc);
  7. village_plot_id = plot.getId(list.getIndex(plot_list, 0));
  8. farmer_quest = list.new();
  9. farmer_inv = inv.new("222222222");
  10. farmer_inv_id = inv.getId(farmer_inv);
  11. air_item = read.item("minecraft:air");
  12. crops_tag = block.getTag("minecraft:crops");
  13. age7_property = block.getProperty("age_0_7");
  14. farm_loc1 = loc.new(overworld, 69, 69, 444);
  15. farm_loc2 = loc.new(overworld, 73, 69, 440);
  16. @wait
  17. wait();
  18. iGoto(event);
  19. goto("wait");
  20. @entity_click
  21. entity_name = entity.getName(entity);
  22. if(entity_name == "Bauer") {
  23. if(getGrowPercentage(farm_loc1, farm_loc2, "minecraft:wheat") >= 80) {
  24. inv.setItem(farmer_inv, 0, read.item("minecraft:wheat", 1, "Weizenfeld ernten"));
  25. } else {
  26. inv.setItem(farmer_inv, 0, air_item);
  27. }
  28. inv.open(farmer_inv, player, "Verfügbare Quests");
  29. }
  30. goto("wait");
  31. @inv_click
  32. if(item.getType(item) != "minecraft:air") {
  33. if(inv_id == farmer_inv_id) {
  34. if(inv_slot == 0) {
  35. player_uuid = player.getUuid(player);
  36. if(list.contains(farmer_quest, player_uuid)) {
  37. player.speak(player, "Bauer", "Du bist bereits mit dieser Aufgabe betraut. Geh dahin und ernte das gesamte Weizenfeld.");
  38. } else {
  39. player.speak(player, "Bauer", "Die Weizenernte kann beginnen. Geh dahin und ernte das gesamte Feld.");
  40. list.add(farmer_quest, player.getUuid(player));
  41. }
  42. }
  43. }
  44. }
  45. goto("wait");
  46. @block_break
  47. player_uuid = player.getUuid(player);
  48. //Hat der Spieler die Quest "Weizenfeld ernten"?
  49. if(list.contains(farmer_quest, player_uuid)) {
  50. //Baut der Spieler einen Block des Weizenfelds ab?
  51. if(loc.isBetween(block_loc, farm_loc1, farm_loc2) && block_type == "minecraft:wheat") {
  52. cancel = false;
  53. //Ist das Weizenfeld fertig abgeerntet?
  54. if(getGrowPercentage(farm_loc1, farm_loc2, "minecraft:wheat") == 0) {
  55. //An alle Spieler, die diese Quest haben, eine Erledigung schicken
  56. msgQuesters(farmer_quest, "Bauer", "Vielen Dank für das ernten des Weizenfelds! Hier hast du eine Belohnung.");
  57. rewardQuesters(farmer_quest, 5, 0, 0);
  58. }
  59. }
  60. }
  61. goto("wait");
  62. function getGrowPercentage(location1, location2, block_type) {
  63. crops_counter = 0;
  64. ready_counter = 0;
  65. loc.sort(location1, location2);
  66. x_diff = loc.getX(location2) - loc.getX(location1);
  67. y_diff = loc.getY(location2) - loc.getY(location1);
  68. z_diff = loc.getZ(location2) - loc.getZ(location1);
  69. for(x = 0; x <= x_diff; x++) {
  70. for(y = 0; y <= y_diff; y++) {
  71. for(z = 0; z <= z_diff; z++) {
  72. mod_loc = loc.mod(location1, x, y, z);
  73. if(block.getType(mod_loc) == block_type) {
  74. crops_counter++;
  75. if(block.property.getValue(mod_loc, $age7_property) == 7) {
  76. ready_counter++;
  77. }
  78. }
  79. }
  80. }
  81. }
  82. readyPercent = ready_counter / crops_counter * 100;
  83. return readyPercent;
  84. }
  85. function msgQuesters(farmer_quest, from, message) {
  86. for(i = 0; i < list.getSize(farmer_quest); i++) {
  87. player_uuid = list.getIndex(farmer_quest, i);
  88. player_name = player.getName(player_uuid);
  89. if(isOnline(player_name)) {
  90. player = read.player(player_name);
  91. player.speak(player, from, message);
  92. }
  93. }
  94. return;
  95. }
  96. function rewardQuesters(farmer_quest, copper, silver, gold) {
  97. for(i = 0; i < list.getSize(farmer_quest); i++) {
  98. player_uuid = list.getIndex(farmer_quest, i);
  99. player_name = player.getName(player_uuid);
  100. if(isOnline(player_name)) {
  101. player = read.player(player_name);
  102. if(copper > 0) {
  103. safeGiveItemPlayer(player, read.item("km:coin_copper", copper));
  104. }
  105. if(silver > 0) {
  106. safeGiveItemPlayer(player, read.item("km:coin_silver", silver));
  107. }
  108. if(gold> 0) {
  109. safeGiveItemPlayer(player, read.item("km:coin_gold", gold));
  110. }
  111. }
  112. }
  113. return;
  114. }
  115. function safeGiveItemPlayer(player, item) {
  116. rest_item = player.giveItem(player, item);
  117. item.drop(entity.getLocation(player), rest_item);
  118. return;
  119. }
  120. function isOnline(player_name) {
  121. if(read.player(player_name) == null) {
  122. return false;
  123. }
  124. return true;
  125. }