Guest User

Untitled

a guest
Apr 9th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.89 KB | None | 0 0
  1. /*
  2. *
  3. *
  4. * Command to create eq 'sets'
  5. *
  6. * 2003-Nov-13: Morpher, initial
  7. * 2004-Jul-05: Morpher, brief option
  8. *
  9. */
  10.  
  11. #include <commands.h>
  12. #include <daemons.h>
  13. #include <std.h>
  14.  
  15. inherit DAEMON;
  16.  
  17. #define ARMOR_VARS
  18. #include <armor.h>
  19.  
  20. #define LIMIT_EQ (50)
  21. #define LIMIT_SETS ( 5)
  22.  
  23. int cmd_eqset(string str)
  24. {
  25. object plr;
  26. int i,j;
  27. string a1, a2, *ae, cmd, *ta, tmp;
  28. object *tao;
  29. mapping eqset;
  30.  
  31. ae = keys(armor_expand);
  32. plr = this_player();
  33.  
  34. if (plr -> query_ghost())
  35. {
  36. return notify_fail("Your ghostly hands just pass through the objects..\n");
  37. }
  38.  
  39. if (!mapp(plr->query("cmd_eqset")))
  40. {
  41. plr->set("cmd_eqset", ([ "brief" : "off",
  42. "created" : time(),
  43. "sets" : ([]),
  44. "version" : 2 ]) );
  45. }
  46. eqset = plr->query("cmd_eqset");
  47.  
  48. if (eqset["version"] == 1)
  49. {
  50. eqset["brief"] = "off";
  51. eqset["version"] = 2;
  52. plr->set("cmd_eqset", eqset);
  53. eqset = plr->query("cmd_eqset");
  54. }
  55.  
  56. if (!stringp(str)) str = "list";
  57.  
  58. if (sscanf(str,"%s %s %s",cmd,a1,a2) != 3) // lazy parsing(tm)
  59. { // should use get_args() parser but it would need tuning...
  60. a2 = "";
  61. if (sscanf(str,"%s %s",cmd,a1) != 2)
  62. {
  63. a1 = "";
  64. cmd = str;
  65. }
  66. }
  67. a1 = a1[0..31];
  68.  
  69. switch( cmd )
  70. {
  71. case "add" :
  72. if (sizeof(a2))
  73. {
  74. if (!mapp(eqset["sets"][a1]))
  75. {
  76. if (sizeof(eqset["sets"]) < LIMIT_SETS)
  77. {
  78. eqset["sets"][a1] = ([]);
  79. tell(plr, "Eqset "+a1+" added.\n", MSG_COMMAND);
  80. } else {
  81. tell(plr, "You can only have "+LIMIT_SETS+" eqsets.\n", MSG_COMMAND);
  82. return 1;
  83. }
  84. }
  85.  
  86. switch(a2)
  87. {
  88. case "all" :
  89. tao = items_all(plr);
  90. break;
  91. case "noeq":
  92. tao = items_inv(plr);
  93. break;
  94. case "eq" :
  95. tao = items_eq (plr);
  96. break;
  97. default:
  98. tao = ({ present(a2,plr) });
  99. tao -= ({ 0 });
  100. break;
  101. }
  102.  
  103. if ((i = sizeof(tao)))
  104. {
  105. j = 0;
  106. while (i--)
  107. {
  108. if (sizeof(eqset["sets"][a1]) < LIMIT_EQ)
  109. {
  110. if (!tao[i]->query("no_save") && (tmp = tao[i]->query_save_data_id()) != "0-0")
  111. {
  112. if (!mapp(eqset["sets"][a1][tmp]))
  113. {
  114. eqset["sets"][a1][tmp] = ([ "short" : tao[i]->query_short() ]);
  115. tell(
  116. plr,
  117. sprintf("Added %s to eqset %s.\n",
  118. tao[i]->query_short(),
  119. a1),
  120. MSG_COMMAND);
  121. j = 1;
  122. }
  123. }
  124. } else {
  125. tell(plr, "Eqset "+a1+" is full.\n", MSG_COMMAND);
  126. }
  127. }
  128. plr->set("cmd_eqset", eqset);
  129. if (!j)
  130. {
  131. tell(plr, "No item found to add to eqset "+a1+".\n", MSG_COMMAND);
  132. }
  133. return 1;
  134. } else {
  135. tell(plr, "No item found to add to eqset "+a1+".\n", MSG_COMMAND);
  136. return 1;
  137. }
  138. }
  139. break;
  140. case "brief" :
  141. eqset["brief"] = eqset["brief"] == "on" ? "off" : "on";
  142. plr->set("cmd_eqset", eqset);
  143. switch ( eqset["brief"] )
  144. {
  145. case "on" : tell(plr, "Eqset brief mode on.\n" , MSG_COMMAND); break;
  146. case "off": tell(plr, "Eqset brief mode off.\n", MSG_COMMAND); break;
  147. }
  148. return 1;
  149. case "del" :
  150. case "delete" :
  151. if (sizeof(a2))
  152. {
  153. if (mapp(eqset["sets"][a1]))
  154. {
  155. if (a2 == "all")
  156. {
  157. map_delete(eqset["sets"],a1);
  158. tell(plr, "Eqset "+a1+" deleted.\n", MSG_COMMAND);
  159. plr->set("cmd_eqset", eqset);
  160. return 1;
  161. } else {
  162. if (present(a2,plr))
  163. {
  164. tmp = present(a2,plr)->query_save_data_id();
  165. if (mapp(eqset["sets"][a1][tmp]))
  166. {
  167. tell(plr, "Item "+eqset["sets"][a1][tmp]["short"]+" deleted from eqset "+a1+".\n", MSG_COMMAND);
  168. map_delete(eqset["sets"][a1],tmp);
  169. plr->set("cmd_eqset", eqset);
  170. } else {
  171. tell(plr, "Item "+a2+" is not in eqset "+a1+".\n", MSG_COMMAND);
  172. }
  173. } else {
  174. tell(plr, "No item found to delete from eqset "+a1+".\n", MSG_COMMAND);
  175. }
  176. return 1;
  177. }
  178. } else {
  179. tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
  180. return 1;
  181. }
  182. }
  183. break;
  184. case "wear" :
  185. if (sizeof(a1))
  186. {
  187. if (a2 != "noremove")
  188. {
  189. if (stringp(plr->query_temp("cmd_eqset")))
  190. {
  191. cmd_eqset("remove "+plr->query_temp("cmd_eqset"));
  192. }
  193. }
  194.  
  195. if (mapp(eqset["sets"][a1]))
  196. {
  197. tao = map_array(
  198. keys(eqset["sets"][a1]),
  199. (: member_array($1,$2->query_save_data_id()) != -1 ? $2[member_array($1,$2->query_save_data_id())] : 0 :),
  200. items_all(plr));
  201. tao -= ({ 0 });
  202. tao = sort_array (tao, (: member_array($1->query("type"),$(ae))-member_array($2->query("type"),$(ae)) :));
  203. tao = filter_array(tao, (: CMD_WEAR->cmd_wear($1,1,$2) :), plr); // hrr...
  204.  
  205. if (sizeof(tao))
  206. {
  207. if (eqset["brief"] == "on")
  208. {
  209. tell(plr, "You wear eqset "+a1+".\n", MSG_COMMAND);
  210. } else {
  211. tell(plr, "You wear "+items_array_text(sort_array(tao->query_short(),1))+" (eqset "+a1+").\n", MSG_COMMAND);
  212. }
  213. } else {
  214. tell(plr, "No items worn from eqset "+a1+".\n", MSG_COMMAND);
  215. }
  216. plr->set_temp("cmd_eqset", a1);
  217. } else {
  218. tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
  219. }
  220. return 1;
  221. }
  222. break;
  223. case "rem" :
  224. case "remove" :
  225. if (sizeof(a1))
  226. {
  227. if (mapp(eqset["sets"][a1]))
  228. {
  229. tao = map_array(
  230. keys(eqset["sets"][a1]),
  231. (: member_array($1,$2->query_save_data_id()) != -1 ? $2[member_array($1,$2->query_save_data_id())] : 0 :),
  232. items_all(plr));
  233. tao -= ({ 0 });
  234. tao = filter_array(tao, (: CMD_REMOVE->cmd_remove($1,1,$2) :), plr); // hrr...
  235.  
  236. if (sizeof(tao))
  237. {
  238. if (eqset["brief"] == "on")
  239. {
  240. tell(plr, "You remove eqset "+a1+".\n", MSG_COMMAND);
  241. } else {
  242. tell(plr, "You remove "+items_array_text(sort_array(tao->query_short(),1))+". (eqset "+a1+").\n", MSG_COMMAND);
  243. }
  244. } else {
  245. tell(plr, "No items unworn from eqset "+a1+".\n", MSG_COMMAND);
  246. }
  247. plr->set_temp("cmd_eqset", 0);
  248. } else {
  249. tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
  250. }
  251. return 1;
  252. }
  253. break;
  254. case "view" :
  255. if (sizeof(a1))
  256. {
  257. if (mapp(eqset["sets"][a1]))
  258. {
  259. ta = map_array(
  260. keys(eqset["sets"][a1]),
  261. (: member_array($1,$2) == -1 ? $(eqset["sets"][a1])[$1]["short"] + " (?)" : $(eqset["sets"][a1])[$1]["short"] :),
  262. items_all(plr)->query_save_data_id());
  263.  
  264. if (sizeof(ta))
  265. {
  266. tell(plr, "Eqset "+a1+" has following items: "+items_array_text(sort_array(ta,1))+".\n", MSG_COMMAND);
  267. } else {
  268. tell(plr, "There is no items in eqset "+a1+".\n", MSG_COMMAND);
  269. }
  270. } else {
  271. tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
  272. }
  273. return 1;
  274. }
  275. break;
  276. case "validate":
  277. if (sizeof(a1))
  278. {
  279. if (mapp(eqset["sets"][a1]))
  280. {
  281. ta = map_array(
  282. keys(eqset["sets"][a1]),
  283. (: member_array($1,$2) == -1 ? $1 : "" :),
  284. items_all(plr)->query_save_data_id());
  285. ta = filter_array(ta, (: sizeof($1) :) );
  286.  
  287. if ( (i = sizeof(ta)) )
  288. {
  289. while (i--)
  290. {
  291. tell(plr, "Item "+eqset["sets"][a1][ta[i]]["short"]+" deleted from eqset "+a1+".\n", MSG_COMMAND);
  292. map_delete(eqset["sets"][a1],ta[i]);
  293. }
  294. plr->set("cmd_eqset", eqset);
  295. }
  296. tell (plr, "Eqset "+a1+" validated.\n", MSG_COMMAND);
  297. } else {
  298. tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
  299. }
  300. return 1;
  301. }
  302. break;
  303. case "keep" :
  304. if (sizeof(a1))
  305. {
  306. if (mapp(eqset["sets"][a1]))
  307. {
  308. tao = map_array(
  309. keys(eqset["sets"][a1]),
  310. (: member_array($1,$2->query_save_data_id()) != -1 ? $2[member_array($1,$2->query_save_data_id())] : 0 :),
  311. items_all(plr));
  312. tao -= ({ 0 });
  313.  
  314. if (sizeof(tao))
  315. {
  316. tao->set("keep",1);
  317. tell(plr, "You put "+items_array_text(sort_array(tao->query_short(),1))+" in keep (eqset "+a1+").\n", MSG_COMMAND);
  318. } else {
  319. tell(plr, "You have no items from eqset "+a1+".\n", MSG_COMMAND);
  320. }
  321. } else {
  322. tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
  323. }
  324. return 1;
  325. }
  326. break;
  327. case "nokeep" :
  328. if (sizeof(a1))
  329. {
  330. if (mapp(eqset["sets"][a1]))
  331. {
  332. tao = map_array(
  333. keys(eqset["sets"][a1]),
  334. (: member_array($1,$2->query_save_data_id()) != -1 ? $2[member_array($1,$2->query_save_data_id())] : 0 :),
  335. items_all(plr));
  336. tao -= ({ 0 });
  337.  
  338. if (sizeof(tao))
  339. {
  340. tao->set("keep",0);
  341. tell(plr, "You remove "+items_array_text(sort_array(tao->query_short(),1))+" from keep (eqset "+a1+").\n", MSG_COMMAND);
  342. } else {
  343. tell(plr, "You have no items from eqset "+a1+".\n", MSG_COMMAND);
  344. }
  345. } else {
  346. tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
  347. }
  348. return 1;
  349. }
  350. break;
  351. case "loc" :
  352. case "location":
  353. // lets think about this later as there must be buggy containers...
  354. break;
  355. case "list" :
  356. ta = sort_array(keys(eqset["sets"]),-1);
  357. i = sizeof(ta);
  358.  
  359. if (i)
  360. {
  361. tell(plr, "You have following eq sets defined:\n", MSG_COMMAND);
  362. while (i--)
  363. {
  364. tell(
  365. plr,
  366. sprintf(" %s with %d items.\n",
  367. ta[i],
  368. sizeof(eqset["sets"][ta[i]])));
  369. }
  370. } else {
  371. tell(plr, "No eqsets defined.\n", MSG_COMMAND);
  372. }
  373. return 1;
  374. break;
  375. }
  376.  
  377. if (sizeof(a2))
  378. {
  379. tell(plr, "Command "+a1+" has no argument.\n", MSG_COMMAND);
  380. } else {
  381. tell(plr, "Required argument malformed or missing.\n", MSG_COMMAND);
  382. }
  383. return 1;
  384. }
  385.  
  386. string help()
  387. {
  388. return @LT
  389. Command: eqset
  390. Usage:
  391. 1. eqset add <setname> <item>
  392. <setname> is any name you want to use to id the set (no spaces)
  393. <item> is either the name of an item to add to the set, or
  394. all - which adds all items you have
  395. eq - which adds all items you have equipped
  396. noeq - which adds all items in your inventory
  397. 2. eqset del <setname> <item>
  398. This deletes <item> from the given <setname>
  399. 3. eqset del <setname> all
  400. This deletes the entire eqset by the given name
  401. 4. eqset wear <setname>
  402. This will make you wear all the items in the eqset, it will remove
  403. the current eqset first.
  404. 5. eqset wear <setname> noremove
  405. This will make you wear the eqset given, but it will NOT remove the
  406. old set first.
  407. 6. eqset remove <setname>
  408. This will make you remove all items in the eqset
  409. 7. eqset list
  410. This will list the names of all eqsets you have created
  411. 8. eqset view <setname>
  412. This shows you what items are in the given eqset.
  413. 9. eqset validate <setname>
  414. Removes items you no longer have (carried) from set.
  415. 10. eqset keep <setname>
  416. Put items in eqset to keep.
  417. 11. eqset nokeep <setname>
  418. Remove items in eqset from keep.
  419. 12. eqset brief (toggle)
  420. Show minimal information when wearing/unwearing.
  421.  
  422. Each player can define a maximum of 5 sets and each set can contain only
  423. 50 items. Note that added items are uniquely identified and thus even if
  424. you have bunch of 'identical' looking items this command will be able to
  425. differentiate them.
  426. LT;
  427. }
Advertisement
Add Comment
Please, Sign In to add comment