Guest User

Untitled

a guest
Nov 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 KB | None | 0 0
  1. spikeQuest1Init = function() {
  2. this = .Map();
  3.  
  4. context1 = .tmp.stateQuest.QuestContext("spikeQuest1FindMeBook");
  5. context1.initialStateId = "idle";
  6.  
  7. //methods and variables in quest context
  8. context1.say = function(mob, char, str, arg1, arg2) {
  9. char.act("%1$C1 говорит тебе '{G%2$s{x'", mob, mob.print(str, arg1, arg2));
  10. };
  11.  
  12. context1.checkAnswer = function(self, char, txt) { //used in state2
  13.  
  14. var data;
  15. data = .Map();
  16.  
  17. data.spike = self;
  18.  
  19. if (txt.match("да|yes|sure|ок")) {
  20. // state 2 -> state 3
  21. if (.tmp.stateQuest.doTransition(char, "spikeQuest1FindMeBook", "answer yes", data)) {
  22. return; }
  23. }
  24.  
  25. if(txt.match("нет|no")) {
  26. // state 2 -> state 1
  27. if (.tmp.stateQuest.doTransition(char, "spikeQuest1FindMeBook", "answer no", data)) {
  28. return; }
  29. }
  30. // state 2 -> state 2
  31. if (.tmp.stateQuest.doTransition(char, "spikeQuest1FindMeBook", "invalid answer", data)) {
  32. return; }
  33. };
  34.  
  35.  
  36. var questMob;
  37. questMob = .get_mob_index(8000);
  38. //context1.questMob = .get_mob_index(8000);
  39. context1.book = .get_obj_index(8020);
  40. context1.room = .get_room_index(8002);
  41. context1.containers = .List().add(8001, 8002, 8012);
  42. context1.anotherBooks = .List().add(8003, 8013, 8014, 8015);
  43.  
  44. //states and transitions
  45. state1_idle = context1.State("idle");
  46.  
  47. //state 1 -> state 2
  48. state1_idle.Transition("listen spike", "taking quest", function (data) {
  49.  
  50. data.questContext.say(data.spike, data.character, "Мне нужна %s", data.questContext.book.short_descr.ruscase(1), null);
  51.  
  52. data.questContext.say(data.spike, data.character, "Принесешь ее?", null, null);
  53. });
  54.  
  55. state2_taking_quest = context1.State("taking quest");
  56.  
  57. //state 2 -> state 1
  58. state2_taking_quest.Transition("answer no", "idle", function (data) {
  59.  
  60. data.questContext.say(data.spike, data.character, "Жаль.", null, null);
  61. });
  62.  
  63. //state 2 -> state 2
  64. state2_taking_quest.Transition("invalid answer", "taking quest", function (data) {
  65.  
  66. data.questContext.say(data.spike, data.character, "Да, или нет?", null, null);
  67. });
  68.  
  69. //state 2 -> state 3
  70. state2_taking_quest.Transition("answer yes", "searching book", function (data) {
  71.  
  72. data.questContext.say(data.spike, data.character, "Ура!", null, null);
  73.  
  74. data.questContext.book.create().obj_to_obj(data.questContext.room.get_obj_vnum(data.questContext.containers.random()));
  75. });
  76.  
  77. state3_searching_book = context1.State("searching book");
  78.  
  79. //state 3 -> state 3
  80. state3_searching_book.Transition("wrong book", "searching book", function(data) {
  81.  
  82. data.questContext.say(data.spike, data.character, "Мне нужна другая книга.", null, null);
  83.  
  84. data.spike.interpret("give " + "'" + data.thisBook.name + "' '" + data.character.name + "'");
  85. });
  86.  
  87. //state 3 -> state 4
  88. state3_searching_book.Transition("recieve book", "complete", function(data) {
  89.  
  90. //"Спасибо, %C1.", data.character дает английское имя из-за ch.print()
  91. data.questContext.say(data.spike, data.character, "Спасибо тебе, %s.", data.character.russianName.ruscase(1), null);
  92.  
  93. data.thisBook.extract();
  94.  
  95. data.character.act("Квест выполнен.");
  96. });
  97.  
  98. state4_complete = context1.State("complete");
  99.  
  100. //state 4 -> state 1 TEST
  101. state4_complete.Transition("return", "idle", function(data) {
  102.  
  103. data.questContext.say(data.spike, data.character, "Я готов повторить.", null, null);
  104. });
  105.  
  106. //triggers
  107. //var SpikeP;
  108. //SpikeP = .tmp.stateQuest.getQuestContext("spikeQuest1FindMeBook").questMob;
  109.  
  110. questMob.onListen = function(self, char, txt) { // state 1 idle
  111.  
  112. var data;
  113. data = .Map();
  114.  
  115. data.spike = self;
  116.  
  117. // state 1 -> state 2
  118. if(.tmp.stateQuest.doTransition(char, "spikeQuest1FindMeBook", "listen spike", data)) {
  119.  
  120. return true;
  121.  
  122. }
  123. else return false;
  124. };
  125.  
  126. questMob.postTell = function(self, char, txt) { //state 2 taking quest
  127.  
  128. if (char != self) {
  129. .tmp.stateQuest.getQuestContext("spikeQuest1FindMeBook").checkAnswer(self, char, txt);
  130. }
  131. };
  132.  
  133. questMob.postSpeech = function(self, char, txt) { //state 2 taking quest
  134.  
  135. if (char != self) {
  136. .tmp.stateQuest.getQuestContext("spikeQuest1FindMeBook").checkAnswer(self, char, txt);
  137. }
  138. };
  139.  
  140. questMob.postGive = function(self, char, obj) { //state 3 searching book
  141.  
  142. var data, book, anotherBooks;
  143. data = .Map();
  144.  
  145. data.spike = self;
  146. data.thisBook = obj;
  147.  
  148. book = .tmp.stateQuest.getQuestContext("spikeQuest1FindMeBook").book;
  149. anotherBooks = .tmp.stateQuest.getQuestContext("spikeQuest1FindMeBook").anotherBooks;
  150.  
  151. if (anotherBooks.has(obj.vnum)) {
  152. // state 3 -> state 3
  153. if (.tmp.stateQuest.doTransition(char, "spikeQuest1FindMeBook", "wrong book", data)) {
  154. return; }
  155. }
  156.  
  157. if (obj.vnum == book.vnum) {
  158. // state 3 -> state 4
  159. if (.tmp.stateQuest.doTransition(char, "spikeQuest1FindMeBook", "recieve book", data)) {
  160. return; }
  161. }
  162. };
  163.  
  164. questMob.onBribe = function(self, char, arg, amount) { //возврат в idle для теста
  165.  
  166. var data;
  167. data = .Map();
  168.  
  169. data.spike = self;
  170.  
  171. if (arg == 1 || amount > 9) {
  172.  
  173. .tmp.stateQuest.doTransition(char, "spikeQuest1FindMeBook", "return", data);
  174. }
  175. };
  176.  
  177.  
  178. .tmp.stateQuest.registerQuestContext(context1);
  179.  
  180. return .tmp.stateQuest.visualize(context1);
  181.  
  182. }
Add Comment
Please, Sign In to add comment