Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.53 KB | None | 0 0
  1. // the formulation of spell components will usually go something along these lines:
  2. // find bow->find valid arrow for the spell->check for both->pass to spell process.
  3. // a lot of their spells should have default component usage to make the playing
  4. // and spellcasting manageable. For ease of development the order objects get put in
  5. // the components array should be: bow->arrow->additional components.
  6.  
  7. status spell_check_object_launch_skills(object item, int skill) {
  8. unless(item->is_weapon())
  9. return False;
  10. mapping skills = item->weapon()->type()->query_weapon_type_launch_skills();
  11. unless(skills)
  12. return False;
  13. foreach(int key, mixed val : skills) {
  14. if(key == skill)
  15. return True;
  16. }
  17. return False;
  18. }
  19.  
  20. object array spell_find_bow(object who) {
  21. object array equipment = who->query_equipment();
  22. object array weapons = 0;
  23. object bow = 0;
  24. foreach(object equip : equipment) {
  25. if(equip->is_weapon())
  26. array_push_object(weapons, equip);
  27. }
  28. unless(weapons)
  29. return ({});
  30. foreach(object wep : weapons) {
  31. if(spell_check_object_launch_skills(wep, Skill_Archery)) {
  32. bow = wep;
  33. break;
  34. }
  35. }
  36. return ({ bow });
  37. }
  38.  
  39. //check that they have a valid bow weapon equipped
  40.  
  41. status spell_check_bow(object array components, object who, status initial) {
  42. unless(sizeof(components))
  43. return Error(({
  44. who, "must have a type of bow equipped to use this spell",
  45. }));
  46. object component = components[0];
  47. unless(component->is_weapon())
  48. return Error(({
  49. who, "must have a type of bow equipped to use this spell",
  50. }));
  51. status archer = False;
  52. if(spell_check_object_launch_skills(component, Skill_Archery))
  53. archer = True;
  54. unless(archer)
  55. return Error(({
  56. who, "must have a type of bow equipped to use this spell",
  57. }));
  58. return True;
  59. }
  60.  
  61. //find their bow and any arrow, takes a status to check if their next arrow is mundane or not.
  62.  
  63. object array spell_find_bow_and_next_arrow(object who, status mundane) {
  64. object array bows = spell_find_bow(who);
  65. unless(sizeof(bows))
  66. return ({});
  67. object bow = bows[0];
  68. object arrow = who->find_ammunition(bow);
  69. unless(arrow)
  70. return ({});
  71. if(mundane) {
  72. if(arrow->query_property(Prop_Magical))
  73. return ({});
  74. else
  75. array_push_object(bows, arrow);
  76. return bows;
  77. }
  78. array_push_object(bows, arrow);
  79. return bows;
  80. }
  81.  
  82. //something we would use in spell_check_components_rule() for a valid equipped bow weapon and
  83. //a mundane arrow.
  84.  
  85. status spell_check_mundane_arrow_with_bow(object array components, object who, status initial) {
  86. //arrow should always be 2nd object
  87. unless(sizeof(components) == 2)
  88. return Error(({
  89. who, "can not cast this spell without a bow equipped and an available mundane arrow.",
  90. }));
  91. object arrow = components[1];
  92. unless(arrow)
  93. return Error(({
  94. who, "must have a mundane arrow to cast this spell",
  95. }));
  96. if(sizeof(arrow->query_properties(Prop_Magical)))
  97. return Error(({
  98. arrow, "must be mundane to cast this spell",
  99. }));
  100. return True;
  101. }
  102.  
  103. //checking if their bow has a arrow currently nocked in it or not
  104.  
  105. status spell_check_bow_has_nocked_arrow(object who) {
  106. object array bows = spell_find_bow(who);
  107. unless(sizeof(bows))
  108. return False;
  109. object bow = bows[0];
  110. object array arrow_in_bow = bow->query_child_objects();
  111. if(sizeof(arrow_in_bow))
  112. return True;
  113. return False;
  114. }
  115.  
  116. //find their next arrow or return 0
  117.  
  118. object spell_find_any_arrow(object who) {
  119. object array bows = spell_find_bow(who);
  120. unless(sizeof(bows))
  121. return 0;
  122. object bow = bows[0];
  123. object arrow = who->find_ammunition(bow);
  124. return arrow;
  125. }
  126.  
  127. //check the arrow for being mundane, for spells with only an arrow component
  128.  
  129. varargs status spell_check_mundane_arrow(object array components, object who, status initial) {
  130. object arrow = components[0];
  131. if(sizeof(arrow->query_properties(Prop_Magical)))
  132. return False;
  133. return True;
  134. }
  135.  
  136. //check if object is an arrow
  137.  
  138. status spell_check_is_arrow(object arrow) {
  139. if(arrow->is_weapon()) {
  140. if(arrow->weapon()->type()->query_weapon_type_ammunition_type(Ammunition_Type_Bow)) {
  141. return True;
  142. }
  143. }
  144. return False;
  145. }
  146.  
  147. //find a mundane arrow in either a quiver or the casters inventory or return empty array
  148.  
  149. object array spell_find_mundane_arrow(object who) {
  150. object quiver = 0;
  151. object arrow = 0;
  152. //find a quiver
  153. foreach(object item : who->query_equipment()) {
  154. if(item->is_armour()) {
  155. if(item->armour()->query_armour_type() == Armour_Type_Quiver) {
  156. quiver = item;
  157. break;
  158. }
  159. }
  160. }
  161. Debug_To("starhound", ({ "quiver", quiver }));
  162. //if quiver found, check it for mundane arrows first
  163. if(quiver) {
  164. //hopefully we can assume only arrows go in quivers
  165. object array quiver_inv = quiver->query_child_objects();
  166. foreach(object arrows : quiver_inv) {
  167. if(spell_check_is_arrow(arrows) && spell_check_mundane_arrow(({ arrows }), who, False)) {
  168. arrow = arrows;
  169. break;
  170. }
  171. }
  172. }
  173. //if we found a mundane arrow, return it now
  174. Debug_To("starhound", ({ "arrow", arrow }));
  175. if(arrow)
  176. return ({ arrow });
  177. //if no arrow yet, check their inventory
  178. foreach(object item : who->query_child_objects()) {
  179. if(spell_check_is_arrow(item)) {
  180. unless(spell_check_mundane_arrow(({ item }), who, False)) {
  181. continue;
  182. } else {
  183. arrow = item;
  184. break;
  185. }
  186. }
  187. }
  188. Debug_To("starhound", arrow);
  189. //should return an object array with a mundane arrow, or empty array
  190. return array_strip_zeroes(({ arrow }));
  191. }
  192.  
  193. //a function to find the object the caster is currently aiming at or default to the current attacker
  194.  
  195. object array spell_find_aiming(object who) {
  196. object array bows = spell_find_bow(who);
  197. unless(sizeof(bows))
  198. return ({});
  199. object array attackers = ::spell_find_attacker(who);
  200. if(sizeof(attackers))
  201. return attackers;
  202. object bow = bows[0];
  203. object target = who->query_aiming(bow);
  204. return ({ target });
  205. }
  206.  
  207. //loads an arrow into a bow, returns false if the bow already has an arrow nocked
  208.  
  209. status spell_load_arrow_into_bow(object who, object arrow, object bow) {
  210. if(spell_check_bow_has_nocked_arrow(who))
  211. return False;
  212. arrow->move(bow);
  213. return True;
  214. }
  215.  
  216. //a function to be called upon Spell_Step_Type_Gaze to make the caster aim their bow
  217.  
  218. //outdated with the addition of Spell_Step_Type_Aim but can still be used possibly?
  219. void spell_start_aiming(descriptor process) {
  220. descriptor s_p = Process_Query_Info(process, "Spellcasting_Process");
  221. object array targets = Spellcasting_Process_Query(s_p, Spellcasting_Process_Targets);
  222. object target = targets[0];
  223. object who = Spellcasting_Process_Query(s_p, Spellcasting_Process_Actor);
  224. object array components = Spellcasting_Process_Query(s_p, Spellcasting_Process_Components);
  225. object bow = components[0];
  226. who->init_command("aim bow" + " at " + which(target, who), Command_Flag_Suppress_Activity_Checks | Command_Flag_Override);
  227. }
  228.  
  229. //this function will assume there is already an arrow placed inside a bow
  230. //as well as aiming the bow at the target if not already aiming
  231.  
  232. void spell_execute_bow_fire_at_target(descriptor process) {
  233. descriptor s_p = Process_Query_Info(process, "Spellcasting_Process");
  234. object array targets = Spellcasting_Process_Query(s_p, Spellcasting_Process_Targets);
  235. object target = targets[0];
  236. object who = Spellcasting_Process_Query(s_p, Spellcasting_Process_Actor);
  237. object array components = Spellcasting_Process_Query(s_p, Spellcasting_Process_Components);
  238. object bow = components[0];
  239. object array aim = spell_find_aiming(who);
  240. if(sizeof(aim)) {
  241. who->init_command("fire bow", Command_Flag_Override | Command_Flag_Suppress_Activity_Checks);
  242. } else {
  243. spell_start_aiming(process);
  244. who->init_command("fire bow", Command_Flag_Override | Command_Flag_Suppress_Activity_Checks);
  245. }
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement