Guest User

Untitled

a guest
Jul 19th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.32 KB | None | 0 0
  1. package server.model.minigames.trawler;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import server.Config;
  7. import server.Server;
  8. import server.event.CycleEvent;
  9. import server.event.CycleEventContainer;
  10. import server.event.CycleEventHandler;
  11. import server.model.content.skills.Fishing;
  12. import server.model.items.GameItem;
  13. import server.model.players.Client;
  14. import server.model.players.Player;
  15.  
  16. public class Trawler extends GroupMinigame {
  17.  
  18. /*
  19. *
  20. */
  21.  
  22. /*
  23. * The waiting room for the minigame
  24. */
  25.  
  26. public WaitingRoom waiting_room = new TrawlerWaitingRoom(this);
  27.  
  28. /*
  29. * The arraylist containing all of the players
  30. */
  31.  
  32. public ArrayList<Player> players = new ArrayList<Player>();
  33.  
  34. /*
  35. * The arraylist containing all of the players that need to removed Created
  36. * so that an instance wouldn't have to be created every time the updating
  37. * is called simply just call the clear method
  38. */
  39.  
  40. public ArrayList<Player> players_to_remove = new ArrayList<Player>();
  41.  
  42. /*
  43. * A unique id, which the cycle event handler may use to stop the trawlers
  44. * event
  45. */
  46.  
  47. public static final int CYCLE_ID = 222;
  48.  
  49. /*
  50. * Random object
  51. */
  52.  
  53. private final Random random_gen = new Random();
  54.  
  55. /*
  56. * All of the animations needed for the minigame
  57. */
  58.  
  59. final int climb_up = 828;
  60. final int climb_down = 827;
  61. final int swimming_walk = 772;
  62. final int swimming_stand = 773;
  63. final int net_interaction = 832;
  64. final int SWIM_MOVEMENT_ANIMATION = 772;
  65. final int SWIM_STILL_ANIMATION = 773;
  66.  
  67. /*
  68. * All of the items needed for the minigame
  69. */
  70.  
  71. final int bailing_bucket_full = 585;
  72. final int bailing_bucket_empty = 583;
  73. final int rope = 954;
  74. final int swamp_paste = 1941;
  75.  
  76. /*
  77. * All of the objects needed for the minigame
  78. */
  79.  
  80. final int perfect_wall = 2177;
  81. final int patched_wall = 2168;
  82. final int leaking_wall = 2167;
  83.  
  84. /*
  85. * Variables that will be changing as the minigame progresses
  86. */
  87.  
  88. private int water_level = 0;
  89. private boolean net_ripped = false;
  90. public int fish_caught = 0;
  91. private boolean[] wall_status = new boolean[16];
  92. private boolean isSunk = false;
  93. private int game_time = 10;
  94. private boolean started = false;
  95. boolean in_progress = false;
  96.  
  97. /*
  98. * Contains the coordinates for each wall, since all of the objects of the
  99. * same id's and the methods needed to get them
  100. */
  101.  
  102. public enum Wall {
  103.  
  104. North_One_Normal(0, 1885, 4826), North_Two_Normal(1, 1886, 4826), North_Three_Normal(
  105. 2, 1887, 4826), North_Four_Normal(3, 1888, 4826), North_Five_Normal(
  106. 4, 1889, 4826), North_Six_Normal(5, 1890, 4826), North_Seven_Normal(
  107. 6, 1891, 4826), North_Eight_Normal(7, 1892, 4826), South_One_Normal(
  108. 8, 1885, 4823), South_Two_Normal(9, 1886, 4823), South_Three_Normal(
  109. 10, 1887, 4823), South_Four_Normal(11, 1888, 4823), South_Five_Normal(
  110. 12, 1889, 4823), South_Six_Normal(13, 1890, 4823), South_Seven_Normal(
  111. 14, 1891, 4823), South_Eight_Normal(15, 1892, 4823), North_One_Sinking(
  112. 0, 2013, 4826), North_Two_Sinking(1, 2014, 4826), North_Three_Sinking(
  113. 2, 2015, 4826), North_Four_Sinking(3, 2016, 4826), North_Five_Sinking(
  114. 4, 2017, 4826), North_Six_Sinking(5, 2018, 4826), North_Seven_Sinking(
  115. 6, 2019, 4826), North_Eight_Sinking(7, 2020, 4826), South_One_Sinking(
  116. 8, 2013, 4823), South_Two_Sinking(9, 2014, 4823), South_Three_Sinking(
  117. 10, 2015, 4823), South_Four_Sinking(11, 2016, 4823), South_Five_Sinking(
  118. 12, 2017, 4823), South_Six_Sinking(13, 2018, 4823), South_Seven_Sinking(
  119. 14, 2019, 4823), South_Eight_Sinking(15, 2020, 4823);
  120.  
  121. int index, x, y;
  122.  
  123. Wall(int index, int x, int y) {
  124. this.index = index;
  125. this.y = y;
  126. this.x = x;
  127. }
  128.  
  129. public static int getIndex(int x, int y) {
  130. for (Wall s : Wall.values()) {
  131. if (s != null) {
  132. if (s.x == x && s.y == y) {
  133. return s.index;
  134. }
  135. }
  136. }
  137. return -1;
  138. }
  139.  
  140. public static Wall getWallByIndex(int index, boolean sinking) {
  141. for (Wall w : Wall.values()) {
  142. if (w.index == index) {
  143. if (sinking && w.x < 2000) {
  144. continue;
  145. } else {
  146. return w;
  147. }
  148. }
  149. }
  150. return null;
  151. }
  152.  
  153. }
  154.  
  155. /*
  156. * Gets the amount of walls that are not broken
  157. */
  158.  
  159. public int getAvaliableWallSize() {
  160. int toReturn = 0;
  161. for (int j = 0; j < wall_status.length; j++) {
  162. if (wall_status[j] == false) {
  163. toReturn++;
  164. }
  165. }
  166. return toReturn;
  167. }
  168.  
  169. /*
  170. * Generates the indexes of the walls that are not broken
  171. */
  172.  
  173. public int[] getAvaliableWalls() {
  174. int[] toReturn = new int[getAvaliableWallSize()];
  175. int index = 0;
  176. for (int j = 0; j < wall_status.length; j++) {
  177. if (wall_status[j] == false) {
  178. toReturn[index] = j;
  179. index++;
  180. }
  181. }
  182. return toReturn;
  183. }
  184.  
  185. /*
  186. * Sets a random wall as broken & updates it
  187. */
  188.  
  189. public void breakRandomWall() {
  190. try {
  191. final int[] walls = getAvaliableWalls();
  192. int random = walls[random_gen.nextInt(walls.length)];
  193. wall_status[random] = true;
  194. updateWall(random);
  195. } catch (Exception e) {// Exception should never occur
  196.  
  197. }
  198. }
  199.  
  200. /*
  201. * Removes every wall and resets them back to default
  202. */
  203.  
  204. public void resetWalls() {
  205. for(Wall w : Wall.values()) {
  206. if(w != null) {
  207. Server.objectHandler.removeObject(Server.objectHandler.getObjectByPosition(w.x, w.y));
  208. Server.objectHandler.createAnObject(perfect_wall, w.x,w.y, w.y == 4826 ? 1 : 3);
  209. }
  210. }
  211. }
  212.  
  213. /*
  214. * Updates a wall based on index
  215. */
  216.  
  217. public void updateWall(int index) {
  218. Wall w = Wall.getWallByIndex(index, isSunk);
  219. if (w == null) {
  220. System.out.println("null");
  221. return;
  222. }
  223. Server.objectHandler.removeObject(Server.objectHandler.getObjectByPosition(w.x, w.y));
  224. Server.objectHandler.removeObject(Server.objectHandler.getObjectByPosition(w.x + (isSunk ? -128 : 128), w.y));
  225. if (wall_status[index] == true) {
  226. Server.objectHandler.createAnObject(leaking_wall, w.x, w.y,
  227. w.y == 4826 ? 1 : 3);
  228. if (isSunk)
  229. Server.objectHandler.createAnObject(leaking_wall, w.x - 128,
  230. w.y, w.y == 4826 ? 1 : 3);
  231. else
  232. Server.objectHandler.createAnObject(leaking_wall, w.x + 128,
  233. w.y, w.y == 4826 ? 1 : 3);
  234. } else {
  235. Server.objectHandler.createAnObject(patched_wall, w.x, w.y,
  236. w.y == 4826 ? 1 : 3);
  237. if (isSunk)
  238. Server.objectHandler.createAnObject(patched_wall, w.x - 128,
  239. w.y, w.y == 4826 ? 1 : 3);
  240. else
  241. Server.objectHandler.createAnObject(patched_wall, w.x + 128,
  242. w.y, w.y == 4826 ? 1 : 3);
  243. }
  244. }
  245.  
  246. /*
  247. * Updates every play in the game's interface, if the player is null they
  248. * are removed from the game
  249. */
  250.  
  251. public void playerUpdates() {
  252. for (Player p : players) {
  253. if (p != null) {
  254. p.asClient()
  255. .getPA()
  256. .sendFrame126(net_ripped ? "@red@Ripped" : "@gre@Okay",
  257. 11935);
  258. p.asClient().getPA().sendFrame126("" + fish_caught, 11937);
  259. p.asClient().getPA().sendFrame126(game_time + " mins", 11938);
  260. p.asClient().getPA().sendFrame20(391, water_level);
  261. } else {
  262. players_to_remove.add(p);
  263. }
  264. }
  265. if (players_to_remove.size() > 0) {
  266. for (Player p : players_to_remove) {
  267. players.remove(p);
  268. }
  269. players_to_remove.clear();
  270. }
  271. }
  272.  
  273. /*
  274. * Does everything needed when the game starts
  275. */
  276.  
  277. public void onStart() {
  278. resetWalls();
  279. waiting_room.setActive(false);
  280. water_level = 0;
  281. fish_caught = 0;
  282. net_ripped = false;
  283. isSunk = false;
  284. started = false;
  285. game_time = 10;
  286. in_progress = true;
  287. for (int j = 0; j < wall_status.length; j++) {
  288. wall_status[j] = false;
  289. }
  290. playerUpdates();
  291. for (Player p : players) {
  292. if (p != null) {
  293. p.asClient().getPA().removeAllSidebars();
  294. p.asClient().getPA().sendMapState(2);
  295. p.asClient().getPA().showInterface(3281);
  296. p.asClient().getPA().sendFrame36(75, 11);
  297. p.asClient().getPA().movePlayer(1885, 4825, 1);
  298. p.asClient().getPA().sendFrame126("", 11936);
  299. }
  300. }
  301. CycleEventHandler.getSingleton().addEvent(this, new CycleEvent() {
  302. @Override
  303. public void execute(CycleEventContainer container) {
  304. container.stop();
  305. }
  306.  
  307. @Override
  308. public void stop() {
  309. for (Player p : players) {
  310. if (p != null) {
  311. p.asClient().getPA().setSidebarInterfaces(p.asClient(), true);
  312. p.asClient().getPA().showInterface(5596);
  313. p.asClient().getPA().sendMapState(0);
  314. }
  315. }
  316. started = true;
  317. startGameTimer();
  318. }
  319. }, 25);
  320. }
  321.  
  322. /*
  323. * Does everything needed when the game ends
  324. */
  325.  
  326. public void onEndLose() {
  327. for (Player p : players) {
  328. if (p != null) {
  329. p.asClient().getPA().movePlayer(1885, 4825, 1);
  330. }
  331. }
  332. }
  333.  
  334. /*
  335. * Essentially starts the game
  336. */
  337.  
  338. public void start() {
  339.  
  340. CycleEventHandler.getSingleton().stopEvents(CYCLE_ID);// Stops any other
  341. // events using
  342. // the trawler's
  343. // id
  344. onStart();
  345. CycleEventHandler.getSingleton().addEvent(this, new CycleEvent() {
  346. @Override
  347. public void execute(CycleEventContainer container) {
  348. if (started) {
  349. tick();
  350. if (end() > 0) {
  351. if (end() == 1) {
  352. setSwimmingAnimations();// Loss
  353. movePlayersLoss();
  354. players.clear();
  355. } else if (end() == 2) {
  356. for (Player p : players) {
  357. if (p != null) {
  358. p.asClient().fishingTrawlerReward = playerReward(p);
  359. }
  360. }
  361. movePlayerWin(players);
  362. }
  363. container.stop();
  364. }
  365. }
  366. }
  367.  
  368. @Override
  369. public void stop() {
  370. waiting_room.reset();
  371. waiting_room.setActive(true);
  372. }
  373. }, 10);
  374. }
  375.  
  376. /*
  377. * Everything that should be done on one tick of the minigame
  378. */
  379.  
  380. public void tick() {
  381. int random;
  382. random = random_gen.nextInt(2) + 1;
  383. for (int j = 0; j < random; j++) {
  384. breakRandomWall();
  385. }
  386. ripNet();
  387. increaseWaterLevel();
  388. switchBoats();
  389. if (!net_ripped)
  390. increaseFish();
  391. playerUpdates();
  392. }
  393.  
  394. /*
  395. * Randomly breaks the net
  396. */
  397.  
  398. public void ripNet() {
  399. if (!net_ripped) {
  400. if (random_gen.nextInt(10) > 7) {
  401. net_ripped = true;
  402. }
  403. }
  404. }
  405.  
  406. /*
  407. * Adds water depending on the amount of leaks in the ship
  408. */
  409.  
  410. public void increaseWaterLevel() {
  411. int leaks = 16 - getAvaliableWalls().length;
  412. water_level += (leaks / 2) + random_gen.nextInt(leaks * random_gen.nextInt(2) + 1);
  413. }
  414.  
  415. /*
  416. * Fixes the holes in the ship
  417. */
  418.  
  419. public void fixHole(Player p, int x, int y) {
  420. if (doAction(p)) {
  421. if (p.asClient().getItems().playerHasItem(swamp_paste)) {
  422. int index = Wall.getIndex(x, y);
  423. if (index >= 0) {
  424. p.asClient().getItems().deleteItem2(swamp_paste, 1);
  425. p.startAnimation(832);
  426. wall_status[index] = false;
  427. updateWall(index);
  428. p.turnPlayerTo(x, y + (y == 4826 ? 1 : -1));
  429. }
  430. } else {
  431. p.asClient().sendMessage("You don't have any swamp paste.");
  432. }
  433. }
  434. }
  435.  
  436. /*
  437. * Moves the player to the top of the boat
  438. */
  439.  
  440. public void upLadder(Player p, int obX, int obY) {
  441. if (doAction(p)) {
  442. if (!isSunk) {
  443. p.startAnimation(climb_up);
  444. p.asClient().getPA()
  445. .movePlayer(obX == 1884 ? 1885 : 1892, obY, 1);
  446. } else {
  447. p.startAnimation(climb_up);
  448. p.asClient().getPA().movePlayer(obX == 2021 ? 2020 : 2013, obY, 1);
  449. }
  450. }
  451. }
  452.  
  453. /*
  454. * Moves the player to the top of the boat
  455. */
  456.  
  457. public void downLadder(Player p, int obX, int obY) {
  458. if (doAction(p)) {
  459. if (!isSunk) {
  460. p.startAnimation(climb_down);
  461. p.asClient().getPA()
  462. .movePlayer(obX == 1884 ? 1885 : 1892, obY, 0);
  463. } else {
  464. p.startAnimation(climb_down);
  465. p.asClient().getPA().movePlayer(obX == 2021 ? 2020 : 2013, obY, 0);
  466. }
  467. }
  468. }
  469.  
  470. /*
  471. * Fixes the net on the ship
  472. */
  473.  
  474. public void fixNet(Player p) {
  475. if (doAction(p)) {
  476. if (!net_ripped) {
  477. p.asClient().sendMessage("The net is not ripped.");
  478. return;
  479. }
  480. if (!p.asClient().getItems().playerHasItem(rope)) {
  481. p.asClient().sendMessage(
  482. "You need a rope before attempting to fix the net!");
  483. return;
  484. }
  485. p.startAnimation(net_interaction);
  486. if (skillCheck(p.playerLevel[Player.playerCrafting], 1, 0)) {
  487. p.asClient().getItems().deleteItem(rope, 1);
  488. net_ripped = false;
  489. playerUpdates();
  490. p.asClient().sendMessage("You successfully fix the net!");
  491. } else {
  492. p.asClient().getItems().deleteItem(rope, 1);
  493. p.asClient().sendMessage("You failed to repair the net!");
  494. }
  495. }
  496. }
  497.  
  498. /*
  499. * Returns true if the player can complete the interaction
  500. */
  501.  
  502. public boolean doAction(Player p) {
  503. if (!players.contains(p)) {
  504. return false;
  505. }
  506. if (System.currentTimeMillis() - p.lastFishingTrawlerInteraction >= 1600) {
  507. p.lastFishingTrawlerInteraction = System.currentTimeMillis();
  508. return true;
  509. } else {
  510. return false;
  511. }
  512. }
  513.  
  514. /*
  515. * Bails water out of the boat
  516. */
  517.  
  518. public void bail(Player p) {
  519. if (doAction(p)) {
  520. if (p.asClient().getItems().playerHasItem(bailing_bucket_empty)) {
  521. p.startAnimation(827);
  522. p.asClient().getItems()
  523. .replaceItem(bailing_bucket_empty, bailing_bucket_full);
  524. water_level -= random_gen.nextInt(3) + 1;
  525. }
  526. }
  527. }
  528.  
  529. /*
  530. * Bails water out of the boat
  531. */
  532.  
  533. public void emptyBucket(Player p) {
  534. if (doAction(p)) {
  535. if (p.asClient().getItems().playerHasItem(bailing_bucket_full)) {
  536. p.startAnimation(832);
  537. p.asClient().getItems()
  538. .replaceItem(bailing_bucket_full, bailing_bucket_empty);
  539. }
  540. }
  541. }
  542.  
  543. /*
  544. * Adds a random amount of fish to the total fish reaward, based off of the
  545. * amount of players in the game
  546. */
  547.  
  548. public void increaseFish() {
  549. fish_caught += random_gen.nextInt(players.size() + 2);
  550. }
  551.  
  552. /*
  553. * If it returns true, the minigame will end
  554. */
  555.  
  556. public int end() {
  557. if (players.size() == 0) {
  558. return 1;
  559. }
  560. if (water_level >= 100) {
  561. return 1;
  562. }
  563. if (game_time == 0) {
  564. return 2;
  565. }
  566. return 0;
  567. }
  568.  
  569. /*
  570. * Sets the swimming animations
  571. */
  572.  
  573. public void setSwimmingAnimations() {
  574. for(Player p : players) {
  575. if (p != null) {
  576. p.prevplayerWalkIndex = p.playerWalkIndex;
  577. p.prevPlayerStandIndex = p.playerStandIndex;
  578. p.prevPrevPlayerRunIndex = p.playerRunIndex;
  579. p.prevPlayerTurnIndex = p.playerTurnIndex;
  580. p.prevPlayerTurn180Index = p.playerTurn180Index;
  581. p.prevPlayerTurn90CCWIndex = p.playerTurn90CCWIndex;
  582. p.prevPlayerTurn90CWIndex = p.playerTurn90CWIndex;
  583. p.prevRunning2 = p.isRunning2;
  584. p.isRunning2 = false;
  585. p.playerRunIndex = SWIM_MOVEMENT_ANIMATION;
  586. p.playerStandIndex = SWIM_STILL_ANIMATION;
  587. p.playerWalkIndex = SWIM_MOVEMENT_ANIMATION;
  588. p.playerTurnIndex = SWIM_STILL_ANIMATION;
  589. p.playerTurn90CWIndex = SWIM_STILL_ANIMATION;
  590. p.playerTurn90CCWIndex = SWIM_STILL_ANIMATION;
  591. p.playerTurn180Index = SWIM_STILL_ANIMATION;
  592. p.asClient().getPA().requestUpdates();
  593. p.asClient().getPA().closeAllWindows();
  594. }
  595. }
  596. }
  597.  
  598. /*
  599. * Switches boats based on the water level
  600. */
  601.  
  602. public void switchBoats() {
  603. if (water_level > 25 && !isSunk) {
  604. isSunk = true;
  605. for (int j = 0; j < players.size(); j++) {
  606. if (players.get(j) != null) {
  607. players.get(j).stopMovement();
  608. players.get(j)
  609. .asClient()
  610. .getPA()
  611. .movePlayer(players.get(j).absX + 128,
  612. players.get(j).absY,
  613. players.get(j).heightLevel);
  614. }
  615. }
  616. }
  617. if (water_level <= 25 && isSunk) {
  618. isSunk = false;
  619. for (int j = 0; j < players.size(); j++) {
  620. if (players.get(j) != null) {
  621. players.get(j).stopMovement();
  622. players.get(j)
  623. .asClient()
  624. .getPA()
  625. .movePlayer(players.get(j).absX - 128,
  626. players.get(j).absY,
  627. players.get(j).heightLevel);
  628. }
  629. }
  630. }
  631. }
  632.  
  633. /*
  634. * Starts the timer for the game
  635. */
  636.  
  637. public void startGameTimer() {
  638. CycleEventHandler.getSingleton().addEvent(this, new CycleEvent() {
  639. @Override
  640. public void execute(CycleEventContainer container) {
  641. game_time--;
  642. if (game_time == 0) {
  643. container.stop();
  644. } else {
  645. waiting_room.messageWaiting("The trawler will return in "+game_time+ (game_time == 1 ? " minute" : " minutes")+"!");
  646. }
  647. }
  648.  
  649. @Override
  650. public void stop() {
  651.  
  652. }
  653. }, 100);
  654. }
  655.  
  656. /*
  657. * Slightly increases chance of higher level fish with levels
  658. */
  659.  
  660. public int chanceByLevel(Player p, int fish) {
  661. switch (fish) {
  662. case 381:
  663. if (p.asClient().playerLevel[p.asClient().playerFishing] >= 81
  664. && p.asClient().playerLevel[p.asClient().playerFishing] < 90) {
  665. return 5;
  666. } else if (p.asClient().playerLevel[p.asClient().playerFishing] >= 90
  667. && p.asClient().playerLevel[p.asClient().playerFishing] < 99) {
  668. return 9;
  669. } else if (p.asClient().playerLevel[p.asClient().playerFishing] == 99) {
  670. return 13;
  671. }
  672. return 0;
  673. case 395:
  674. if (p.asClient().playerLevel[p.asClient().playerFishing] >= 79
  675. && p.asClient().playerLevel[p.asClient().playerFishing] < 85) {
  676. return 8;
  677. } else if (p.asClient().playerLevel[p.asClient().playerFishing] >= 85
  678. && p.asClient().playerLevel[p.asClient().playerFishing] < 95) {
  679. return 13;
  680. } else if (p.asClient().playerLevel[p.asClient().playerFishing] >= 95) {
  681. return 17;
  682. }
  683. return 0;
  684. }
  685. return 0;
  686. }
  687.  
  688. /*
  689. * Loss teleporting
  690. */
  691. public void movePlayersLoss() {
  692. for (Player p : players) {
  693. if (p != null) {
  694. p.asClient().getPA().movePlayer(1952, 4826, 0);
  695. }
  696. }
  697. in_progress = false;
  698. players.clear();
  699. }
  700.  
  701. /*
  702. * Win teleporting
  703. */
  704.  
  705. public void movePlayerWin(final ArrayList<Player> pl) {
  706. for (Player p : pl) {
  707. if (p != null) {
  708. p.asClient().getPA().removeAllSidebars();
  709. p.asClient().getPA().sendMapState(2);
  710. p.asClient().getPA().showInterface(3281);
  711. p.asClient().getPA().sendFrame36(75, 12);
  712. p.asClient().getPA().movePlayer(2804, 3421, 0);
  713. }
  714. }
  715. CycleEventHandler.getSingleton().addEvent(this, new CycleEvent() {
  716. @Override
  717. public void execute(CycleEventContainer container) {
  718. container.stop();
  719. }
  720.  
  721. @Override
  722. public void stop() {
  723. for (Player p : pl) {
  724. if (p != null) {
  725. p.asClient().getPA().setSidebarInterfaces(p.asClient(), true);
  726. p.asClient().getPA().sendMapState(0);
  727. p.asClient().getPA().closeAllWindows();
  728. }
  729. }
  730. in_progress = false;
  731. players.clear();
  732. }
  733. }, 25);
  734. }
  735.  
  736. /*
  737. * Adds the rewards to each player
  738. */
  739.  
  740. public ArrayList<GameItem> playerReward(Player p) {
  741. ArrayList<GameItem> toReturn = new ArrayList<GameItem>();
  742. boolean turtles = true;
  743. boolean mantas = true;
  744. boolean lobsters = true;
  745. boolean swordfish = true;
  746. int turt = 0;
  747. int manta = 0;
  748. int lobs = 0;
  749. int swordFish = 0;
  750. int junk = 0;
  751. int done = 0;
  752. while (done != fish_caught) {
  753. done++;
  754. int random = random_gen.nextInt(100);
  755. if (random >= 85 - chanceByLevel(p, 381)) {
  756. if (mantas) {
  757. manta++;
  758. }
  759. } else if (random >= 70 - chanceByLevel(p, 381)) {
  760. if (turtles) {
  761. turt++;
  762. }
  763. } else if (random >= 40) {
  764. if (swordfish) {
  765. swordFish++;
  766. }
  767. } else if (random >= 5) {
  768. if (lobsters) {
  769. lobs++;
  770. }
  771. } else {
  772. junk++;
  773. }
  774. }
  775. int xpToAdd = 0;
  776. if (manta > 0) {
  777. toReturn.add(new GameItem(389, manta));
  778. if (p.playerLevel[p.playerFishing] >= 81) {
  779. xpToAdd += (manta * Fishing.getXP("Manta ray") * Config.FISHING_EXPERIENCE);
  780. }
  781. }
  782. if (turt > 0) {
  783. toReturn.add(new GameItem(395, turt));
  784. if (p.playerLevel[p.playerFishing] >= 79) {
  785. xpToAdd += (manta * Fishing.getXP("Sea turtle") * Config.FISHING_EXPERIENCE);
  786. }
  787. }
  788. if (lobs > 0) {
  789. toReturn.add(new GameItem(377, lobs));
  790. if (p.playerLevel[p.playerFishing] >= 40) {
  791. xpToAdd += (manta * Fishing.getXP("Lobster") * Config.FISHING_EXPERIENCE);
  792. }
  793. }
  794. if (swordFish > 0) {
  795. toReturn.add(new GameItem(371, swordFish));
  796. if (p.playerLevel[p.playerFishing] >= 50) {
  797. xpToAdd += (manta * Fishing.getXP("Swordfish") * Config.FISHING_EXPERIENCE);
  798. }
  799. }
  800. if (junk > 0)
  801. toReturn.add(new GameItem(685, junk));
  802. p.asClient().getPA().addSkillXP(xpToAdd, p.playerFishing);
  803. return toReturn;
  804. }
  805.  
  806. /*
  807. * Randomly returns true, players craft level increases chance of returning
  808. * true
  809. */
  810.  
  811. public boolean skillCheck(int level, int levelRequired, int itemBonus) {
  812. double chance = 0.0;
  813. double baseChance = Math.pow(10d - levelRequired / 10d, 2d) / 2d;
  814. chance = baseChance + ((level - levelRequired) / 2d)
  815. + (itemBonus / 10d);
  816. return chance >= (new Random().nextDouble() * 100.0);
  817. }
  818.  
  819. public void printChance() {
  820. int loop = 1000;
  821. int i1 = 0;
  822. int i2 = 0;
  823. int i3 = 0;
  824. int i4 = 0;
  825. int i5 = 0;
  826. int i6 = 0;
  827. int level = 10;
  828. for (int j = 0; j < loop; j++) {
  829. if (skillCheck(1, level, 0)) {
  830. i1++;
  831. }
  832. }
  833. for (int j = 0; j < loop; j++) {
  834. if (skillCheck(10, level, 0)) {
  835. i2++;
  836. }
  837. }
  838. for (int j = 0; j < loop; j++) {
  839. if (skillCheck(25, level, 0)) {
  840. i3++;
  841. }
  842. }
  843. for (int j = 0; j < loop; j++) {
  844. if (skillCheck(50, level, 0)) {
  845. i4++;
  846. }
  847. }
  848. for (int j = 0; j < loop; j++) {
  849. if (skillCheck(75, level, 0)) {
  850. i5++;
  851. }
  852. }
  853. for (int j = 0; j < loop; j++) {
  854. if (skillCheck(99, level, 0)) {
  855. i6++;
  856. }
  857. }
  858.  
  859. }
  860.  
  861.  
  862. @Override
  863. public WaitingRoom getWaitingRoom() {
  864. return waiting_room;
  865. }
  866.  
  867. @Override
  868. public String getWaitingRoomMessage() {
  869. return null;
  870. }
  871.  
  872. public boolean inProgress() {
  873. return in_progress;
  874. }
  875.  
  876. public int getGameTime() {
  877. return game_time;
  878. }
  879.  
  880. public void resetRewardsInterface(Client c) {
  881. for(int j = 0; j < 45; j++) {
  882. c.getPA().sendFrame34(-1, j, 4640, -1);
  883. }
  884. }
  885. public void showReward(Client c) {
  886. resetRewardsInterface(c);
  887. c.inFishingTrawlerRewardsInterface = true;
  888. c.getPA().showInterface(4564);
  889. for(int j = 0; j < c.fishingTrawlerReward.size(); j++) {
  890. c.getPA().sendFrame34(c.fishingTrawlerReward.get(j).id, j, 4640, c.fishingTrawlerReward.get(j).amount);
  891. }
  892. }
  893.  
  894. public void updateRewardSlot(Client c, int slot) {
  895. c.inFishingTrawlerRewardsInterface = true;
  896. c.getPA().sendFrame34(c.fishingTrawlerReward.get(slot).id, slot, 4640, c.fishingTrawlerReward.get(slot).amount);
  897. if(slot != 4 && c.fishingTrawlerReward.size() == 5) {
  898. c.getPA().sendFrame34(c.fishingTrawlerReward.get(4).id, 4, 4640, c.fishingTrawlerReward.get(4).amount);
  899. }
  900. }
  901.  
  902. public int getRewardSlot(int j) {
  903. if(j < 4) {
  904. return j;
  905. } else {
  906. return j+1;
  907. }
  908. }
  909.  
  910.  
  911. }
Advertisement
Add Comment
Please, Sign In to add comment