Advertisement
dsiver144

DSI

Jan 30th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.23 KB | None | 0 0
  1. //=============================================================================
  2. // DSI_MOG_PickUp_Add-on.js
  3. //=============================================================================
  4.  
  5. /*:
  6. * @plugindesc Commission for RadiantCadenza.
  7. * Give more options to MOG Pick Up Plugin.
  8. * <DSI-MOG-PickUp>
  9. * @help Event Notetag:
  10. * .::About v1.0::.
  11. * + <can throw in> : Tag this to event that you want to throw object onto.
  12. * + <can't throw over> : Tag this to event then you can't throw object over it.
  13. * + pick_up_self_switch : #self_switch_key (Ex: pick_up_self_switch : D)
  14. * when you pick object up, turn its self switch #self_switch_key ON. This self
  15. * switch will be Off if you throw the object.
  16. * + landed_self_switch : #self_switch_key (Ex: landed_self_switch : C)
  17. * when object landed, turn its self switch #self_switch_key ON.
  18. * + landed_common_event : #common_event_id (Ex: landed_common_event : 1)
  19. * when object landed, run common event #common_event_id.
  20. * .::About v1.1::.
  21. * + Improve Smart Throw.
  22. * + landed_target_self_switch : #self_switch_key (Ex: landed_target_self_switch : B)
  23. * when object landed, turn on self switch #self_switch_key of the object below it.
  24. * + landed_switch : #switch_id (Ex: landed_switch : 12)
  25. * when object landed, turn the switch #switch_id ON.
  26. * @author dsiver144
  27. *
  28. * @param holdEventSwitch
  29. * @desc This Switch will be turned ON if player hold an Object.
  30. * @text Hold Event Switch
  31. * @type switch
  32. * @default 10
  33. *
  34. * @param impassibleRegions
  35. * @desc Player can't throw object over these tiles has these region id tagged.
  36. * @text Impassible Regions
  37. * @default 5,6,7
  38. *
  39. * @param impassibleTerrains
  40. * @desc Player can't throw object over these terrains.
  41. * @text Impassible Terrains
  42. * @default 4,5,6
  43. *
  44. * @param canThrowRegions
  45. * @desc Player can throw object into these tiles even that tile is impassible.
  46. * @text Can Throw Regions
  47. * @default 8,9,10
  48. *
  49. */
  50. (function(){
  51. var params = $plugins.filter(function (f) {return f.description.contains("<DSI-MOG-PickUp>");})[0].parameters;
  52. var DSIVER144 = DSIVER144 || {}
  53. DSIVER144.holdEventSwitch = Number(params['holdEventSwitch']);
  54. DSIVER144.impassibleRegions = params['impassibleRegions'].split(',').map(function(str) {return Number(str);});
  55. DSIVER144.impassibleTerrains = params['impassibleTerrains'].split(',').map(function(str) {return Number(str);});
  56. DSIVER144.canThrowRegions = params['canThrowRegions'].split(',').map(function(str) {return Number(str);});
  57. console.log(DSIVER144);
  58. //==============================
  59. // * can Pass Throw
  60. //==============================
  61. Game_CharacterBase.prototype.canPassThrow = function(x, y, d) {
  62. var x2 = $gameMap.roundXWithDirection(x, d);
  63. var y2 = $gameMap.roundYWithDirection(y, d);
  64. if (d === 2) {x3 = x; y3 = y + 1;
  65. } else if (d === 4) {x3 = x - 1;y3 = y;
  66. } else if (d === 6) {x3 = x + 1;y3 = y;
  67. } else {x3 = x;y3 = y - 1;
  68. };
  69. if (!$gameMap.isValid(x2, y2)) {
  70. return false;
  71. };
  72. if (DSIVER144.canThrowRegions.contains($gameMap.regionId(x2,y2))) {
  73. return true;
  74. }
  75. if (DSIVER144.impassibleRegions.contains($gameMap.regionId(x2,y2))) {
  76. return false;
  77. }
  78. if (DSIVER144.impassibleTerrains.contains($gameMap.terrainTag(x2,y2))) {
  79. return false;
  80. }
  81. if ($gameMap.eventsXy(x2,y2)[0] && $gameMap.eventsXy(x2,y2)[0].checkCantThrowObjectOver()) {
  82. return false;
  83. }
  84. if (this.isThrough() || this.isDebugThrough()) {
  85. return true;
  86. };
  87. if (DSIVER144.impassibleRegions.contains($gameMap.regionId(x3,y3))) {
  88. return false;
  89. }
  90. if (DSIVER144.impassibleTerrains.contains($gameMap.terrainTag(x3,y3))) {
  91. return false;
  92. }
  93. if ($gameMap.eventsXy(x2,y2)[0] && $gameMap.eventsXy(x2,y2)[0].checkCanThrowIn()) {
  94. return true;
  95. }
  96. if (!$gameMap.isPassable(x3, y3)) {
  97. return false;
  98. };
  99. if (this.isCollidedWithCharacters(x2, y2)) {
  100. return false;
  101. };
  102. return true;
  103. };
  104. //==============================
  105. // * can Throw
  106. //==============================
  107. Game_CharacterBase.prototype.canThrow = function(x, y, d) {
  108. var x2 = $gameMap.roundXWithDirection(x, d);
  109. var y2 = $gameMap.roundYWithDirection(y, d);
  110. if (DSIVER144.impassibleRegions.contains($gameMap.regionId(x2,y2))) {
  111. return false;
  112. }
  113. if (DSIVER144.impassibleTerrains.contains($gameMap.terrainTag(x2,y2))) {
  114. return false;
  115. }
  116. if ($gameMap.eventsXy(x2,y2)[0] && $gameMap.eventsXy(x2,y2)[0].checkCantThrowObjectOver()) {
  117. return false;
  118. }
  119. return true;
  120. };
  121. //==============================
  122. // * throw Event
  123. //==============================
  124. Game_Player.prototype.throwEvent = function(event) {
  125. var r = event._throw.range; var xr = 0; var yr = 0; var checkFlag = false;
  126. if (this._direction === 2) {
  127. x = this._x; y = this._y;
  128. if (!this.canThrow(x,y,this._direction)) return;
  129. // Check if there is a block throw region or object
  130. for (var i = 1; i < r; i++) {
  131. if (!this.canThrow(x,y + i,this._direction)) {
  132. checkFlag = true;
  133. break;
  134. }
  135. }
  136. if (checkFlag) {
  137. xr = 0; yr = 0;
  138. for (var i = 0; i < r; i++) {
  139. if (this.canPassThrow(x,y+i,this._direction)) {
  140. yr++;
  141. } else break;
  142. }
  143. } else {
  144. x = this._x; y = this._y + r - 1; x2 = 0; y2 = +r;
  145. for (var i = 0; i < r; i++) {
  146. if (this.canPassThrow(x,y,this._direction)) {xr = x2; yr = y2;break};
  147. y--;y2--;
  148. };
  149. }
  150. } else if (this._direction === 4) {
  151. x = this._x; y = this._y;
  152. if (!this.canThrow(x,y,this._direction)) return;
  153. // Check if there is a block throw region or object
  154. for (var i = 1; i < r; i++) {
  155. if (!this.canThrow(x-i,y,this._direction)) {
  156. checkFlag = true;
  157. break;
  158. }
  159. }
  160. if (checkFlag) {
  161. xr = 0; yr = 0;
  162. for (var i = 0; i < r; i++) {
  163. if (this.canPassThrow(x-i,y,this._direction)) {
  164. xr--;
  165. } else break;
  166. }
  167. } else {
  168. x = this._x - r + 1; y = this._y; x2 = -r; y2 = 0;
  169. for (var i = 0; i < r; i++) {
  170. if (this.canPassThrow(x,y,this._direction)) {xr = x2; yr = y2;break};
  171. x++;x2++;
  172. };
  173. }
  174. } else if (this._direction === 6) {
  175. x = this._x; y = this._y;
  176. if (!this.canThrow(x,y,this._direction)) return;
  177. // Check if there is a block throw region or object
  178. for (var i = 1; i < r; i++) {
  179. if (!this.canThrow(x+i,y,this._direction)) {
  180. checkFlag = true;
  181. break;
  182. }
  183. }
  184. if (checkFlag) {
  185. xr = 0; yr = 0;
  186. for (var i = 0; i < r; i++) {
  187. if (this.canPassThrow(x+i,y,this._direction)) {
  188. xr++;
  189. } else break;
  190. }
  191. } else {
  192. x = this._x + r - 1; y = this._y; x2 = +r; y2 = 0;
  193. for (var i = 0; i < r; i++) {
  194. if (this.canPassThrow(x,y,this._direction)) {xr = x2; yr = y2;break};
  195. x--;x2--;
  196. };
  197. }
  198. } else if (this._direction === 8) {
  199. x = this._x; y = this._y;
  200. if (!this.canThrow(x,y,this._direction)) return;
  201. // Check if there is a block throw region or object
  202. for (var i = 1; i < r; i++) {
  203. if (!this.canThrow(x,y - i,this._direction)) {
  204. checkFlag = true;
  205. break;
  206. }
  207. }
  208. if (checkFlag) {
  209. xr = 0; yr = 0;
  210. for (var i = 0; i < r; i++) {
  211. if (this.canPassThrow(x,y - i,this._direction)) {
  212. yr--;
  213. } else break;
  214. }
  215. } else {
  216. x = this._x; y = this._y - r + 1; x2 = 0; y2 = -r;
  217. for (var i = 0; i < r; i++) {
  218. if (this.canPassThrow(x,y,this._direction)) {xr = x2; yr = y2;break};
  219. y++;y2++;
  220. };
  221. }
  222. };
  223. console.log("Final Coor: " + xr + " " + yr);
  224. if (xr === 0 && yr ===0) {return};
  225. event.jump(xr,yr)
  226. event._throw.enabled = false
  227. event._throw.wait = 30;
  228. event._through = this._throw.through;
  229. event._directionFix = this._throw._directionFix;
  230. this._pickup.check = true;
  231. };
  232. //==============================
  233. // * Pick UP
  234. //==============================
  235. var alias_Game_Event_pickUp = Game_Event.prototype.pickUp;
  236. Game_Event.prototype.pickUp = function() {
  237. alias_Game_Event_pickUp.call(this);
  238. $gameSwitches.setValue(DSIVER144.holdEventSwitch, true);
  239. if (this.checkPickUpSelfSwitchComment()) {
  240. var key = [this._mapId, this._eventId, this._throw.pick_up_self_switch];
  241. console.log("Here");
  242. $gameSelfSwitches.setValue(key, true);
  243. }
  244. };
  245. //==============================
  246. // * check Can Throw Object Into
  247. //==============================
  248. Game_Event.prototype.checkCanThrowIn = function() {
  249. if (this._canThrowInto) return true;
  250. var enable = false
  251. if (!this._erased && this.page()) {this.list().forEach(function(l) {
  252. if (l.code === 108) {var comment = l.parameters[0].split(' : ')
  253. if (comment[0].toLowerCase() == "<can throw in>"){
  254. this._canThrowInto = true;
  255. enable = true;
  256. };};
  257. }, this);};
  258. return enable;
  259. };
  260. //==============================
  261. // * check Can't Throw Object Over
  262. //==============================
  263. Game_Event.prototype.checkCantThrowObjectOver = function() {
  264. if (this._cantThrowOver) return true;
  265. var enable = false
  266. if (!this._erased && this.page()) {this.list().forEach(function(l) {
  267. if (l.code === 108) {var comment = l.parameters[0].split(' : ')
  268. if (comment[0].toLowerCase() == "<can't throw over>"){
  269. this._cantThrowOver = true;
  270. enable = true;
  271. };};
  272. }, this);};
  273. return enable;
  274. };
  275. //==============================
  276. // * check Pick Self Switch Comment
  277. //==============================
  278. Game_Event.prototype.checkPickUpSelfSwitchComment = function() {
  279. var enable = false
  280. if (!this._erased && this.page()) {this.list().forEach(function(l) {
  281. if (l.code === 108) {var comment = l.parameters[0].split(' : ')
  282. if (comment[0].toLowerCase() == "pick_up_self_switch"){
  283. this._throw.pick_up_self_switch = comment[1];
  284. enable = true;
  285. };};
  286. }, this);};
  287. return enable;
  288. };
  289. //==============================
  290. // * check Land Self Switch & Common Event Comment
  291. //==============================
  292. Game_Event.prototype.checkEventLandedComment = function() {
  293. var enable = false
  294. if (!this._erased && this.page()) {this.list().forEach(function(l) {
  295. if (l.code === 108) {var comment = l.parameters[0].split(' : ')
  296. if (comment[0].toLowerCase() == "landed_self_switch") {
  297. this._throw.landed_self_switch = comment[1];
  298. enable = true;
  299. }
  300. if (comment[0].toLowerCase() == "landed_target_self_switch") {
  301. this._throw.landed_target_self_switch = comment[1];
  302. enable = true;
  303. }
  304. if (comment[0].toLowerCase() == "landed_switch") {
  305. this._throw.landed_switch = Number(comment[1]);
  306. enable = true;
  307. }
  308. if (comment[0].toLowerCase() == "landed_common_event") {
  309. this._throw.landed_common_event = comment[1];
  310. enable = true;
  311. };};
  312. }, this);};
  313. return enable;
  314. };
  315. //==============================
  316. // * Update
  317. //==============================
  318. var _mog_pick_gchabase_update = Game_CharacterBase.prototype.update;
  319. Game_CharacterBase.prototype.update = function() {
  320. if (this._throw.wait > 0) {this._throw.wait--;
  321. if (this.isJumping()) {this.updateJump()};
  322. if (!this.isJumping()) {
  323. $gameSwitches.setValue(DSIVER144.holdEventSwitch, false);
  324. if (this._throw.pick_up_self_switch) {
  325. var key = [this._mapId, this._eventId, this._throw.pick_up_self_switch];
  326. $gameSelfSwitches.setValue(key, false);
  327. this.refresh();
  328. }
  329. if (this.checkEventLandedComment()) {
  330. if (this._throw.landed_self_switch) {
  331. var key = [this._mapId, this._eventId, this._throw.landed_self_switch];
  332. $gameSelfSwitches.setValue(key, true);
  333. this.refresh();
  334. }
  335. if (this._throw.landed_switch) {
  336. $gameSwitches.setValue(this._throw.landed_switch, true);
  337. }
  338. if (this._throw.landed_target_self_switch) {
  339. var throw_event = this;
  340. var event = $gameMap.eventsXy(this._x, this._y).filter(function(e) {return e._eventId !== throw_event._eventId;})[0];
  341. if (event) {
  342. console.log(event);
  343. var key = [this._mapId, event._eventId, this._throw.landed_target_self_switch];
  344. $gameSelfSwitches.setValue(key, true);
  345. event.refresh();
  346. }
  347. }
  348. if (this._throw.landed_common_event) {
  349. $gameTemp.reserveCommonEvent(Number(this._throw.landed_common_event));
  350. }
  351. }
  352. this._throw.wait = 0;
  353. };
  354. return;
  355. };
  356. if (this._pickup.wait > 0) {this._pickup.wait--;return};
  357. if (this._throw.enabled) {this.updatePickUp();return};
  358. _mog_pick_gchabase_update.call(this);
  359. };
  360. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement