Advertisement
romaji

modified Marathon

Nov 14th, 2018
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 31.98 KB | None | 0 0
  1. /*
  2.     Copyright (c) 2010, NullNoname
  3.     All rights reserved.
  4.  
  5.     Redistribution and use in source and binary forms, with or without
  6.     modification, are permitted provided that the following conditions are met:
  7.  
  8.         * Redistributions of source code must retain the above copyright
  9.           notice, this list of conditions and the following disclaimer.
  10.         * Redistributions in binary form must reproduce the above copyright
  11.           notice, this list of conditions and the following disclaimer in the
  12.           documentation and/or other materials provided with the distribution.
  13.         * Neither the name of NullNoname nor the names of its
  14.           contributors may be used to endorse or promote products derived from
  15.           this software without specific prior written permission.
  16.  
  17.     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18.     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21.     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22.     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23.     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24.     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25.     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26.     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27.     POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. package mu.nu.nullpo.game.subsystem.mode;
  30.  
  31. import mu.nu.nullpo.game.component.BGMStatus;
  32. import mu.nu.nullpo.game.component.Controller;
  33. import mu.nu.nullpo.game.component.Piece;
  34. import mu.nu.nullpo.game.event.EventReceiver;
  35. import mu.nu.nullpo.game.net.NetUtil;
  36. import mu.nu.nullpo.game.play.GameEngine;
  37. import mu.nu.nullpo.util.CustomProperties;
  38. import mu.nu.nullpo.util.GeneralUtil;
  39.  
  40. /**
  41.  * MARATHON Mode
  42.  */
  43. public class MarathonMode extends NetDummyMode {
  44.     /** Current version */
  45.     protected static final int CURRENT_VERSION = 2;
  46.  
  47.     /** Fall velocity table (numerators) */
  48.     protected static final int tableGravity[]     = { 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, 465, 731, 1280, 1707,  -1,  -1,  -1};
  49.  
  50.     /** Fall velocity table (denominators) */
  51.     protected static final int tableDenominator[] = {63, 50, 39, 30, 22, 16, 12,  8,  6,  4,  3,  2,  1, 256, 256,  256,  256, 256, 256, 256};
  52.  
  53.     /** Line counts when BGM changes occur */
  54.     protected static final int tableBGMChange[] = {50, 100, 150, 200, -1};
  55.  
  56.     /** Line counts when game ending occurs */
  57.     protected static final int tableGameClearLines[] = {150, 200, -1};
  58.  
  59.     /** Number of entries in rankings */
  60.     protected static final int RANKING_MAX = 10;
  61.  
  62.     /** Number of ranking types */
  63.     protected static final int RANKING_TYPE = 3;
  64.  
  65.     /** Number of game types */
  66.     protected static final int GAMETYPE_MAX = 3;
  67.  
  68.     /** Most recent scoring event type constants */
  69.     protected static final int EVENT_NONE = 0,
  70.                              EVENT_SINGLE = 1,
  71.                              EVENT_DOUBLE = 2,
  72.                              EVENT_TRIPLE = 3,
  73.                              EVENT_FOUR = 4,
  74.                              EVENT_TSPIN_ZERO_MINI = 5,
  75.                              EVENT_TSPIN_ZERO = 6,
  76.                              EVENT_TSPIN_SINGLE_MINI = 7,
  77.                              EVENT_TSPIN_SINGLE = 8,
  78.                              EVENT_TSPIN_DOUBLE_MINI = 9,
  79.                              EVENT_TSPIN_DOUBLE = 10,
  80.                              EVENT_TSPIN_TRIPLE = 11,
  81.                              EVENT_TSPIN_EZ = 12;
  82.  
  83.     /** Most recent increase in score */
  84.     protected int lastscore;
  85.  
  86.     /** Time to display the most recent increase in score */
  87.     protected int scgettime;
  88.  
  89.     /** Most recent scoring event type */
  90.     protected int lastevent;
  91.  
  92.     /** True if most recent scoring event is a B2B */
  93.     protected boolean lastb2b;
  94.  
  95.     /** Combo count for most recent scoring event */
  96.     protected int lastcombo;
  97.  
  98.     /** Piece ID for most recent scoring event */
  99.     protected int lastpiece;
  100.  
  101.     /** Current BGM */
  102.     protected int bgmlv;
  103.  
  104.     /** Level at start time */
  105.     protected int startlevel;
  106.  
  107.     /** Flag for types of T-Spins allowed (0=none, 1=normal, 2=all spin) */
  108.     protected int tspinEnableType;
  109.  
  110.     /** Old flag for allowing T-Spins */
  111.     protected boolean enableTSpin;
  112.  
  113.     /** Flag for enabling wallkick T-Spins */
  114.     protected boolean enableTSpinKick;
  115.  
  116.     /** Spin check type (4Point or Immobile) */
  117.     protected int spinCheckType;
  118.  
  119.     /** Immobile EZ spin */
  120.     protected boolean tspinEnableEZ;
  121.  
  122.     /** Flag for enabling B2B */
  123.     protected boolean enableB2B;
  124.  
  125.     /** Flag for enabling combos */
  126.     protected boolean enableCombo;
  127.  
  128.     /** Game type */
  129.     protected int goaltype;
  130.  
  131.     /** Big */
  132.     protected boolean big;
  133.  
  134.     /** Version */
  135.     protected int version;
  136.  
  137.     /** Current round's ranking rank */
  138.     protected int rankingRank;
  139.  
  140.     /** Rankings' scores */
  141.     protected int[][] rankingScore;
  142.  
  143.     /** Rankings' line counts */
  144.     protected int[][] rankingLines;
  145.  
  146.     /** Rankings' times */
  147.     protected int[][] rankingTime;
  148.  
  149.     /*
  150.      * Mode name
  151.      */
  152.     @Override
  153.     public String getName() {
  154.         return "MARATHON";
  155.     }
  156.  
  157.     /*
  158.      * Initialization
  159.      */
  160.     @Override
  161.     public void playerInit(GameEngine engine, int playerID) {
  162.         owner = engine.owner;
  163.         receiver = engine.owner.receiver;
  164.         lastscore = 0;
  165.         scgettime = 0;
  166.         lastevent = EVENT_NONE;
  167.         lastb2b = false;
  168.         lastcombo = 0;
  169.         lastpiece = 0;
  170.         bgmlv = 0;
  171.  
  172.         rankingRank = -1;
  173.         rankingScore = new int[RANKING_TYPE][RANKING_MAX];
  174.         rankingLines = new int[RANKING_TYPE][RANKING_MAX];
  175.         rankingTime = new int[RANKING_TYPE][RANKING_MAX];
  176.  
  177.         netPlayerInit(engine, playerID);
  178.  
  179.         if(owner.replayMode == false) {
  180.             loadSetting(owner.modeConfig);
  181.             loadRanking(owner.modeConfig, engine.ruleopt.strRuleName);
  182.             version = CURRENT_VERSION;
  183.         } else {
  184.             loadSetting(owner.replayProp);
  185.             if((version == 0) && (owner.replayProp.getProperty("marathon.endless", false) == true)) goaltype = 2;
  186.  
  187.             // NET: Load name
  188.             netPlayerName = engine.owner.replayProp.getProperty(playerID + ".net.netPlayerName", "");
  189.         }
  190.  
  191.         engine.owner.backgroundStatus.bg = startlevel;
  192.         engine.framecolor = GameEngine.FRAME_COLOR_GREEN;
  193.     }
  194.  
  195.     /**
  196.      * Set the gravity rate
  197.      * @param engine GameEngine
  198.      */
  199.     public void setSpeed(GameEngine engine) {
  200.         int lv = engine.statistics.level;
  201.  
  202.         if(lv < 0) lv = 0;
  203.         if(lv >= tableGravity.length) lv = tableGravity.length - 1;
  204.  
  205.         engine.speed.gravity = tableGravity[lv];
  206.         engine.speed.denominator = tableDenominator[lv];
  207.     }
  208.  
  209.     /*
  210.      * Called at settings screen
  211.      */
  212.     @Override
  213.     public boolean onSetting(GameEngine engine, int playerID) {
  214.         // NET: Net Ranking
  215.         if(netIsNetRankingDisplayMode) {
  216.             netOnUpdateNetPlayRanking(engine, goaltype);
  217.         }
  218.         // Menu
  219.         else if(engine.owner.replayMode == false) {
  220.             // Configuration changes
  221.             int change = updateCursor(engine, 8, playerID);
  222.  
  223.             if(change != 0) {
  224.                 engine.playSE("change");
  225.  
  226.                 switch(menuCursor) {
  227.                 case 0:
  228.                     startlevel += change;
  229.                     if(tableGameClearLines[goaltype] >= 0) {
  230.                         if(startlevel < 0) startlevel = (tableGameClearLines[goaltype] - 1) / 10;
  231.                         if(startlevel > (tableGameClearLines[goaltype] - 1) / 10) startlevel = 0;
  232.                     } else {
  233.                         if(startlevel < 0) startlevel = 19;
  234.                         if(startlevel > 19) startlevel = 0;
  235.                     }
  236.                     engine.owner.backgroundStatus.bg = startlevel;
  237.                     break;
  238.                 case 1:
  239.                     //enableTSpin = !enableTSpin;
  240.                     tspinEnableType += change;
  241.                     if(tspinEnableType < 0) tspinEnableType = 2;
  242.                     if(tspinEnableType > 2) tspinEnableType = 0;
  243.                     break;
  244.                 case 2:
  245.                     enableTSpinKick = !enableTSpinKick;
  246.                     break;
  247.                 case 3:
  248.                     spinCheckType += change;
  249.                     if(spinCheckType < 0) spinCheckType = 1;
  250.                     if(spinCheckType > 1) spinCheckType = 0;
  251.                     break;
  252.                 case 4:
  253.                     tspinEnableEZ = !tspinEnableEZ;
  254.                     break;
  255.                 case 5:
  256.                     enableB2B = !enableB2B;
  257.                     break;
  258.                 case 6:
  259.                     enableCombo = !enableCombo;
  260.                     break;
  261.                 case 7:
  262.                     goaltype += change;
  263.                     if(goaltype < 0) goaltype = GAMETYPE_MAX - 1;
  264.                     if(goaltype > GAMETYPE_MAX - 1) goaltype = 0;
  265.  
  266.                     if((startlevel > (tableGameClearLines[goaltype] - 1) / 10) && (tableGameClearLines[goaltype] >= 0)) {
  267.                         startlevel = (tableGameClearLines[goaltype] - 1) / 10;
  268.                         engine.owner.backgroundStatus.bg = startlevel;
  269.                     }
  270.                     break;
  271.                 case 8:
  272.                     big = !big;
  273.                     break;
  274.                 }
  275.  
  276.                 // NET: Signal options change
  277.                 if(netIsNetPlay && (netNumSpectators > 0)) {
  278.                     netSendOptions(engine);
  279.                 }
  280.             }
  281.  
  282.             // Confirm
  283.             if(engine.ctrl.isPush(Controller.BUTTON_A) && (menuTime >= 5)) {
  284.                 engine.playSE("decide");
  285.                 saveSetting(owner.modeConfig);
  286.                 receiver.saveModeConfig(owner.modeConfig);
  287.  
  288.                 // NET: Signal start of the game
  289.                 if(netIsNetPlay) netLobby.netPlayerClient.send("start1p\n");
  290.  
  291.                 return false;
  292.             }
  293.  
  294.             // Cancel
  295.             if(engine.ctrl.isPush(Controller.BUTTON_B) && !netIsNetPlay) {
  296.                 engine.quitflag = true;
  297.             }
  298.  
  299.             // NET: Netplay Ranking
  300.             if(engine.ctrl.isPush(Controller.BUTTON_D) && netIsNetPlay && startlevel == 0 && !big &&
  301.                     engine.ai == null) {
  302.                 netEnterNetPlayRankingScreen(engine, playerID, goaltype);
  303.             }
  304.  
  305.             menuTime++;
  306.         }
  307.         // Replay
  308.         else {
  309.             menuTime++;
  310.             menuCursor = -1;
  311.  
  312.             if(menuTime >= 60) {
  313.                 return false;
  314.             }
  315.         }
  316.  
  317.         return true;
  318.     }
  319.  
  320.     /*
  321.      * Render the settings screen
  322.      */
  323.     @Override
  324.     public void renderSetting(GameEngine engine, int playerID) {
  325.         if(netIsNetRankingDisplayMode) {
  326.             // NET: Netplay Ranking
  327.             netOnRenderNetPlayRanking(engine, playerID, receiver);
  328.         } else {
  329.             String strTSpinEnable = "";
  330.             if(version >= 2) {
  331.                 if(tspinEnableType == 0) strTSpinEnable = "OFF";
  332.                 if(tspinEnableType == 1) strTSpinEnable = "T-ONLY";
  333.                 if(tspinEnableType == 2) strTSpinEnable = "ALL";
  334.             } else {
  335.                 strTSpinEnable = GeneralUtil.getONorOFF(enableTSpin);
  336.             }
  337.             drawMenu(engine, playerID, receiver, 0, EventReceiver.COLOR_BLUE, 0,
  338.                     "LEVEL", String.valueOf(startlevel + 1),
  339.                     "SPIN BONUS", strTSpinEnable,
  340.                     "EZ SPIN", GeneralUtil.getONorOFF(enableTSpinKick),
  341.                     "SPIN TYPE", (spinCheckType == 0) ? "4POINT" : "IMMOBILE",
  342.                     "EZIMMOBILE", GeneralUtil.getONorOFF(tspinEnableEZ),
  343.                     "B2B", GeneralUtil.getONorOFF(enableB2B),
  344.                     "COMBO",  GeneralUtil.getONorOFF(enableCombo),
  345.                     "GOAL",  (goaltype == 2) ? "ENDLESS" : tableGameClearLines[goaltype] + " LINES",
  346.                     "BIG", GeneralUtil.getONorOFF(big));
  347.         }
  348.     }
  349.  
  350.     /*
  351.      * Called for initialization during "Ready" screen
  352.      */
  353.     @Override
  354.     public void startGame(GameEngine engine, int playerID) {
  355.         engine.statistics.level = startlevel;
  356.         engine.statistics.levelDispAdd = 1;
  357.         engine.b2bEnable = enableB2B;
  358.         if(enableCombo == true) {
  359.             engine.comboType = GameEngine.COMBO_TYPE_NORMAL;
  360.         } else {
  361.             engine.comboType = GameEngine.COMBO_TYPE_DISABLE;
  362.         }
  363.         engine.big = big;
  364.  
  365.         if(version >= 2) {
  366.             engine.tspinAllowKick = enableTSpinKick;
  367.             if(tspinEnableType == 0) {
  368.                 engine.tspinEnable = false;
  369.             } else if(tspinEnableType == 1) {
  370.                 engine.tspinEnable = true;
  371.             } else {
  372.                 engine.tspinEnable = true;
  373.                 engine.useAllSpinBonus = true;
  374.             }
  375.         } else {
  376.             engine.tspinEnable = enableTSpin;
  377.         }
  378.  
  379.         engine.spinCheckType = spinCheckType;
  380.         engine.tspinEnableEZ = tspinEnableEZ;
  381.  
  382.         setSpeed(engine);
  383.  
  384.         if(netIsWatch) {
  385.             owner.bgmStatus.bgm = BGMStatus.BGM_NOTHING;
  386.         }
  387.     }
  388.  
  389.     /*
  390.      * Render score
  391.      */
  392.     @Override
  393.     public void renderLast(GameEngine engine, int playerID) {
  394.         if(owner.menuOnly) return;
  395.  
  396.         receiver.drawScoreFont(engine, playerID, 0, 0, this.getName(), EventReceiver.COLOR_GREEN);
  397.  
  398.         if(tableGameClearLines[goaltype] == -1) {
  399.             receiver.drawScoreFont(engine, playerID, 0, 1, "(ENDLESS GAME)", EventReceiver.COLOR_GREEN);
  400.         } else {
  401.             receiver.drawScoreFont(engine, playerID, 0, 1, "(" + tableGameClearLines[goaltype] + " LINES GAME)", EventReceiver.COLOR_GREEN);
  402.         }
  403.  
  404.         if( (engine.stat == GameEngine.Status.SETTING) || ((engine.stat == GameEngine.Status.RESULT) && (owner.replayMode == false)) ) {
  405.             if((owner.replayMode == false) && (big == false) && (engine.ai == null)) {
  406.                 float scale = (receiver.getNextDisplayType() == 2) ? 0.5f : 1.0f;
  407.                 int topY = (receiver.getNextDisplayType() == 2) ? 6 : 4;
  408.                 receiver.drawScoreFont(engine, playerID, 3, topY-1, "SCORE  LINE TIME", EventReceiver.COLOR_BLUE, scale);
  409.  
  410.                 for(int i = 0; i < RANKING_MAX; i++) {
  411.                     receiver.drawScoreFont(engine, playerID,  0, topY+i, String.format("%2d", i + 1), EventReceiver.COLOR_YELLOW, scale);
  412.                     receiver.drawScoreFont(engine, playerID,  3, topY+i, String.valueOf(rankingScore[goaltype][i]), (i == rankingRank), scale);
  413.                     receiver.drawScoreFont(engine, playerID, 10, topY+i, String.valueOf(rankingLines[goaltype][i]), (i == rankingRank), scale);
  414.                     receiver.drawScoreFont(engine, playerID, 15, topY+i, GeneralUtil.getTime(rankingTime[goaltype][i]), (i == rankingRank), scale);
  415.                 }
  416.             }
  417.         } else {
  418.             receiver.drawScoreFont(engine, playerID, 0, 3, "SCORE", EventReceiver.COLOR_BLUE);
  419.             String strScore;
  420.             if((lastscore == 0) || (scgettime >= 120)) {
  421.                 strScore = String.valueOf(engine.statistics.score);
  422.             } else {
  423.                 strScore = String.valueOf(engine.statistics.score) + "(+" + String.valueOf(lastscore) + ")";
  424.             }
  425.             receiver.drawScoreFont(engine, playerID, 0, 4, strScore);
  426.  
  427.             receiver.drawScoreFont(engine, playerID, 0, 6, "LINE", EventReceiver.COLOR_BLUE);
  428.             if((engine.statistics.level >= 19) && (tableGameClearLines[goaltype] < 0))
  429.                 receiver.drawScoreFont(engine, playerID, 0, 7, engine.statistics.lines + "");
  430.             else
  431.                 receiver.drawScoreFont(engine, playerID, 0, 7, engine.statistics.lines + "/" + ((engine.statistics.level + 1) * 10));
  432.  
  433.             receiver.drawScoreFont(engine, playerID, 0, 9, "LEVEL", EventReceiver.COLOR_BLUE);
  434.             receiver.drawScoreFont(engine, playerID, 0, 10, String.valueOf(engine.statistics.level + 1));
  435.  
  436.             receiver.drawScoreFont(engine, playerID, 0, 12, "TIME", EventReceiver.COLOR_BLUE);
  437.             receiver.drawScoreFont(engine, playerID, 0, 13, GeneralUtil.getTime(engine.statistics.time));
  438.  
  439.             if((lastevent != EVENT_NONE) && (scgettime < 120)) {
  440.                 String strPieceName = Piece.getPieceName(lastpiece);
  441.  
  442.                 switch(lastevent) {
  443.                 case EVENT_SINGLE:
  444.                     receiver.drawMenuFont(engine, playerID, 2, 21, "SINGLE", EventReceiver.COLOR_DARKBLUE);
  445.                     break;
  446.                 case EVENT_DOUBLE:
  447.                     receiver.drawMenuFont(engine, playerID, 2, 21, "DOUBLE", EventReceiver.COLOR_BLUE);
  448.                     break;
  449.                 case EVENT_TRIPLE:
  450.                     receiver.drawMenuFont(engine, playerID, 2, 21, "TRIPLE", EventReceiver.COLOR_GREEN);
  451.                     break;
  452.                 case EVENT_FOUR:
  453.                     if(lastb2b) receiver.drawMenuFont(engine, playerID, 3, 21, "FOUR", EventReceiver.COLOR_RED);
  454.                     else receiver.drawMenuFont(engine, playerID, 3, 21, "FOUR", EventReceiver.COLOR_ORANGE);
  455.                     break;
  456.                 case EVENT_TSPIN_ZERO_MINI:
  457.                     receiver.drawMenuFont(engine, playerID, 2, 21, strPieceName + "-SPIN", EventReceiver.COLOR_PURPLE);
  458.                     break;
  459.                 case EVENT_TSPIN_ZERO:
  460.                     receiver.drawMenuFont(engine, playerID, 2, 21, strPieceName + "-SPIN", EventReceiver.COLOR_PINK);
  461.                     break;
  462.                 case EVENT_TSPIN_SINGLE_MINI:
  463.                     if(lastb2b) receiver.drawMenuFont(engine, playerID, 1, 21, strPieceName + "-MINI-S", EventReceiver.COLOR_RED);
  464.                     else receiver.drawMenuFont(engine, playerID, 1, 21, strPieceName + "-MINI-S", EventReceiver.COLOR_ORANGE);
  465.                     break;
  466.                 case EVENT_TSPIN_SINGLE:
  467.                     if(lastb2b) receiver.drawMenuFont(engine, playerID, 1, 21, strPieceName + "-SINGLE", EventReceiver.COLOR_RED);
  468.                     else receiver.drawMenuFont(engine, playerID, 1, 21, strPieceName + "-SINGLE", EventReceiver.COLOR_ORANGE);
  469.                     break;
  470.                 case EVENT_TSPIN_DOUBLE_MINI:
  471.                     if(lastb2b) receiver.drawMenuFont(engine, playerID, 1, 21, strPieceName + "-MINI-D", EventReceiver.COLOR_RED);
  472.                     else receiver.drawMenuFont(engine, playerID, 1, 21, strPieceName + "-MINI-D", EventReceiver.COLOR_ORANGE);
  473.                     break;
  474.                 case EVENT_TSPIN_DOUBLE:
  475.                     if(lastb2b) receiver.drawMenuFont(engine, playerID, 1, 21, strPieceName + "-DOUBLE", EventReceiver.COLOR_RED);
  476.                     else receiver.drawMenuFont(engine, playerID, 1, 21, strPieceName + "-DOUBLE", EventReceiver.COLOR_ORANGE);
  477.                     break;
  478.                 case EVENT_TSPIN_TRIPLE:
  479.                     if(lastb2b) receiver.drawMenuFont(engine, playerID, 1, 21, strPieceName + "-TRIPLE", EventReceiver.COLOR_RED);
  480.                     else receiver.drawMenuFont(engine, playerID, 1, 21, strPieceName + "-TRIPLE", EventReceiver.COLOR_ORANGE);
  481.                     break;
  482.                 case EVENT_TSPIN_EZ:
  483.                     if(lastb2b) receiver.drawMenuFont(engine, playerID, 3, 21, "EZ-" + strPieceName, EventReceiver.COLOR_RED);
  484.                     else receiver.drawMenuFont(engine, playerID, 3, 21, "EZ-" + strPieceName, EventReceiver.COLOR_ORANGE);
  485.                     break;
  486.                 }
  487.  
  488.                 if((lastcombo >= 2) && (lastevent != EVENT_TSPIN_ZERO_MINI) && (lastevent != EVENT_TSPIN_ZERO))
  489.                     receiver.drawMenuFont(engine, playerID, 2, 22, (lastcombo - 1) + "COMBO", EventReceiver.COLOR_CYAN);
  490.             }
  491.         }
  492.  
  493.         // NET: Number of spectators
  494.         netDrawSpectatorsCount(engine, 0, 18);
  495.         // NET: All number of players
  496.         if(playerID == getPlayers() - 1) {
  497.             netDrawAllPlayersCount(engine);
  498.             netDrawGameRate(engine);
  499.         }
  500.         // NET: Player name (It may also appear in offline replay)
  501.         netDrawPlayerName(engine);
  502.     }
  503.  
  504.     /*
  505.      * Called after every frame
  506.      */
  507.     @Override
  508.     public void onLast(GameEngine engine, int playerID) {
  509.         scgettime++;
  510.     }
  511.  
  512.     /*
  513.      * Calculate score
  514.      */
  515.     @Override
  516.     public void calcScore(GameEngine engine, int playerID, int lines) {
  517.         // Line clear bonus
  518.         int pts = 0;
  519.  
  520.         if(engine.tspin) {
  521.             // T-Spin 0 lines
  522.             if((lines == 0) && (!engine.tspinez)) {
  523.                 if(engine.tspinmini) {
  524.                     pts += 100 * (engine.statistics.level + 1);
  525.                     lastevent = EVENT_TSPIN_ZERO_MINI;
  526.                 } else {
  527.                     pts += 400 * (engine.statistics.level + 1);
  528.                     lastevent = EVENT_TSPIN_ZERO;
  529.                 }
  530.             }
  531.             // Immobile EZ Spin
  532.             else if(engine.tspinez && (lines > 0)) {
  533.                 if(engine.b2b) {
  534.                     pts += 180 * (engine.statistics.level + 1);
  535.                 } else {
  536.                     pts += 120 * (engine.statistics.level + 1);
  537.                 }
  538.                 lastevent = EVENT_TSPIN_EZ;
  539.             }
  540.             // T-Spin 1 line
  541.             else if(lines == 1) {
  542.                 if(engine.tspinmini) {
  543.                     if(engine.b2b) {
  544.                         pts += 300 * (engine.statistics.level + 1);
  545.                     } else {
  546.                         pts += 200 * (engine.statistics.level + 1);
  547.                     }
  548.                     lastevent = EVENT_TSPIN_SINGLE_MINI;
  549.                 } else {
  550.                     if(engine.b2b) {
  551.                         pts += 1200 * (engine.statistics.level + 1);
  552.                     } else {
  553.                         pts += 800 * (engine.statistics.level + 1);
  554.                     }
  555.                     lastevent = EVENT_TSPIN_SINGLE;
  556.                 }
  557.             }
  558.             // T-Spin 2 lines
  559.             else if(lines == 2) {
  560.                 if(engine.tspinmini && engine.useAllSpinBonus) {
  561.                     if(engine.b2b) {
  562.                         pts += 600 * (engine.statistics.level + 1);
  563.                     } else {
  564.                         pts += 400 * (engine.statistics.level + 1);
  565.                     }
  566.                     lastevent = EVENT_TSPIN_DOUBLE_MINI;
  567.                 } else {
  568.                     if(engine.b2b) {
  569.                         pts += 1800 * (engine.statistics.level + 1);
  570.                     } else {
  571.                         pts += 1200 * (engine.statistics.level + 1);
  572.                     }
  573.                     lastevent = EVENT_TSPIN_DOUBLE;
  574.                 }
  575.             }
  576.             // T-Spin 3 lines
  577.             else if(lines >= 3) {
  578.                 if(engine.b2b) {
  579.                     pts += 2400 * (engine.statistics.level + 1);
  580.                 } else {
  581.                     pts += 1600 * (engine.statistics.level + 1);
  582.                 }
  583.                 lastevent = EVENT_TSPIN_TRIPLE;
  584.             }
  585.         } else {
  586.             if(lines == 1) {
  587.                 pts += 100 * (engine.statistics.level + 1); // 1Column
  588.                 lastevent = EVENT_SINGLE;
  589.             } else if(lines == 2) {
  590.                 pts += 300 * (engine.statistics.level + 1); // 2Column
  591.                 lastevent = EVENT_DOUBLE;
  592.             } else if(lines == 3) {
  593.                 pts += 500 * (engine.statistics.level + 1); // 3Column
  594.                 lastevent = EVENT_TRIPLE;
  595.             } else if(lines >= 4) {
  596.                 // 4 lines
  597.                 if(engine.b2b) {
  598.                     pts += 1200 * (engine.statistics.level + 1);
  599.                 } else {
  600.                     pts += 800 * (engine.statistics.level + 1);
  601.                 }
  602.                 lastevent = EVENT_FOUR;
  603.             }
  604.         }
  605.  
  606.         lastb2b = engine.b2b;
  607.  
  608.         // Combo
  609.         if((enableCombo) && (engine.combo >= 1) && (lines >= 1)) {
  610.             pts += ((engine.combo - 1) * 50) * (engine.statistics.level + 1);
  611.             lastcombo = engine.combo;
  612.         }
  613.  
  614.         // All clear
  615.         if((lines >= 1) && (engine.field.isEmpty())) {
  616.             engine.playSE("bravo");
  617.             pts += 1800 * (engine.statistics.level + 1);
  618.         }
  619.  
  620.         // Add to score
  621.         if(pts > 0) {
  622.             lastscore = pts;
  623.             lastpiece = engine.nowPieceObject.id;
  624.             scgettime = 0;
  625.             if(lines >= 1) engine.statistics.scoreFromLineClear += pts;
  626.             else engine.statistics.scoreFromOtherBonus += pts;
  627.             engine.statistics.score += pts;
  628.         }
  629.  
  630.         // BGM fade-out effects and BGM changes
  631.         if(tableBGMChange[bgmlv] != -1) {
  632.             if(engine.statistics.lines >= tableBGMChange[bgmlv] - 5) owner.bgmStatus.fadesw = true;
  633.  
  634.             if( (engine.statistics.lines >= tableBGMChange[bgmlv]) &&
  635.                 ((engine.statistics.lines < tableGameClearLines[goaltype]) || (tableGameClearLines[goaltype] < 0)) )
  636.             {
  637.                 bgmlv++;
  638.                 owner.bgmStatus.bgm = bgmlv;
  639.                 owner.bgmStatus.fadesw = false;
  640.             }
  641.         }
  642.  
  643.         // Meter
  644.         engine.meterValue = ((engine.statistics.lines % 10) * receiver.getMeterMax(engine)) / 9;
  645.         engine.meterColor = GameEngine.METER_COLOR_GREEN;
  646.         if(engine.statistics.lines % 10 >= 4) engine.meterColor = GameEngine.METER_COLOR_YELLOW;
  647.         if(engine.statistics.lines % 10 >= 6) engine.meterColor = GameEngine.METER_COLOR_ORANGE;
  648.         if(engine.statistics.lines % 10 >= 8) engine.meterColor = GameEngine.METER_COLOR_RED;
  649.  
  650.         if((engine.statistics.lines >= tableGameClearLines[goaltype]) && (tableGameClearLines[goaltype] >= 0)) {
  651.             // Ending
  652.             engine.ending = 1;
  653.             engine.gameEnded();
  654.         } else if((engine.statistics.lines >= (engine.statistics.level + 1) * 10) && (engine.statistics.level < 19)) {
  655.             // Level up
  656.             engine.statistics.level++;
  657.  
  658.             owner.backgroundStatus.fadesw = true;
  659.             owner.backgroundStatus.fadecount = 0;
  660.             owner.backgroundStatus.fadebg = engine.statistics.level;
  661.  
  662.             setSpeed(engine);
  663.             engine.playSE("levelup");
  664.         }
  665.     }
  666.  
  667.     /*
  668.      * Soft drop
  669.      */
  670.     @Override
  671.     public void afterSoftDropFall(GameEngine engine, int playerID, int fall) {
  672.         engine.statistics.scoreFromSoftDrop += fall;
  673.         engine.statistics.score += fall;
  674.     }
  675.  
  676.     /*
  677.      * Hard drop
  678.      */
  679.     @Override
  680.     public void afterHardDropFall(GameEngine engine, int playerID, int fall) {
  681.         engine.statistics.scoreFromHardDrop += fall * 2;
  682.         engine.statistics.score += fall * 2;
  683.     }
  684.  
  685.     /*
  686.      * Render results screen
  687.      */
  688.     @Override
  689.     public void renderResult(GameEngine engine, int playerID) {
  690.         drawResultStats(engine, playerID, receiver, 0, EventReceiver.COLOR_BLUE,
  691.                 Statistic.SCORE, Statistic.LINES, Statistic.LEVEL, Statistic.TIME, Statistic.SPL, Statistic.LPM);
  692.         drawResultRank(engine, playerID, receiver, 12, EventReceiver.COLOR_BLUE, rankingRank);
  693.         drawResultNetRank(engine, playerID, receiver, 14, EventReceiver.COLOR_BLUE, netRankingRank[0]);
  694.         drawResultNetRankDaily(engine, playerID, receiver, 16, EventReceiver.COLOR_BLUE, netRankingRank[1]);
  695.  
  696.         if(netIsPB) {
  697.             receiver.drawMenuFont(engine, playerID, 2, 21, "NEW PB", EventReceiver.COLOR_ORANGE);
  698.         }
  699.  
  700.         if(netIsNetPlay && (netReplaySendStatus == 1)) {
  701.             receiver.drawMenuFont(engine, playerID, 0, 22, "SENDING...", EventReceiver.COLOR_PINK);
  702.         } else if(netIsNetPlay && !netIsWatch && (netReplaySendStatus == 2)) {
  703.             receiver.drawMenuFont(engine, playerID, 1, 22, "A: RETRY", EventReceiver.COLOR_RED);
  704.         }
  705.     }
  706.  
  707.     /*
  708.      * Called when saving replay
  709.      */
  710.     @Override
  711.     public void saveReplay(GameEngine engine, int playerID, CustomProperties prop) {
  712.         saveSetting(prop);
  713.  
  714.         // NET: Save name
  715.         if((netPlayerName != null) && (netPlayerName.length() > 0)) {
  716.             prop.setProperty(playerID + ".net.netPlayerName", netPlayerName);
  717.         }
  718.  
  719.         // Update rankings
  720.         if((owner.replayMode == false) && (big == false) && (engine.ai == null)) {
  721.             updateRanking(engine.statistics.score, engine.statistics.lines, engine.statistics.time, goaltype);
  722.  
  723.             if(rankingRank != -1) {
  724.                 saveRanking(owner.modeConfig, engine.ruleopt.strRuleName);
  725.                 receiver.saveModeConfig(owner.modeConfig);
  726.             }
  727.         }
  728.     }
  729.  
  730.     /**
  731.      * Load settings from property file
  732.      * @param prop Property file
  733.      */
  734.     protected void loadSetting(CustomProperties prop) {
  735.         startlevel = prop.getProperty("marathon.startlevel", 0);
  736.         tspinEnableType = prop.getProperty("marathon.tspinEnableType", 1);
  737.         enableTSpin = prop.getProperty("marathon.enableTSpin", true);
  738.         enableTSpinKick = prop.getProperty("marathon.enableTSpinKick", true);
  739.         spinCheckType = prop.getProperty("marathon.spinCheckType", 0);
  740.         tspinEnableEZ = prop.getProperty("marathon.tspinEnableEZ", false);
  741.         enableB2B = prop.getProperty("marathon.enableB2B", true);
  742.         enableCombo = prop.getProperty("marathon.enableCombo", true);
  743.         goaltype = prop.getProperty("marathon.gametype", 0);
  744.         big = prop.getProperty("marathon.big", false);
  745.         version = prop.getProperty("marathon.version", 0);
  746.     }
  747.  
  748.     /**
  749.      * Save settings to property file
  750.      * @param prop Property file
  751.      */
  752.     protected void saveSetting(CustomProperties prop) {
  753.         prop.setProperty("marathon.startlevel", startlevel);
  754.         prop.setProperty("marathon.tspinEnableType", tspinEnableType);
  755.         prop.setProperty("marathon.enableTSpin", enableTSpin);
  756.         prop.setProperty("marathon.enableTSpinKick", enableTSpinKick);
  757.         prop.setProperty("marathon.spinCheckType", spinCheckType);
  758.         prop.setProperty("marathon.tspinEnableEZ", tspinEnableEZ);
  759.         prop.setProperty("marathon.enableB2B", enableB2B);
  760.         prop.setProperty("marathon.enableCombo", enableCombo);
  761.         prop.setProperty("marathon.gametype", goaltype);
  762.         prop.setProperty("marathon.big", big);
  763.         prop.setProperty("marathon.version", version);
  764.     }
  765.  
  766.     /**
  767.      * Read rankings from property file
  768.      * @param prop Property file
  769.      * @param ruleName Rule name
  770.      */
  771.     @Override
  772.     protected void loadRanking(CustomProperties prop, String ruleName) {
  773.         for(int i = 0; i < RANKING_MAX; i++) {
  774.             for(int j = 0; j < GAMETYPE_MAX; j++) {
  775.                 rankingScore[j][i] = prop.getProperty("marathon.ranking." + ruleName + "." + j + ".score." + i, 0);
  776.                 rankingLines[j][i] = prop.getProperty("marathon.ranking." + ruleName + "." + j + ".lines." + i, 0);
  777.                 rankingTime[j][i] = prop.getProperty("marathon.ranking." + ruleName + "." + j + ".time." + i, 0);
  778.             }
  779.         }
  780.     }
  781.  
  782.     /**
  783.      * Save rankings to property file
  784.      * @param prop Property file
  785.      * @param ruleName Rule name
  786.      */
  787.     protected void saveRanking(CustomProperties prop, String ruleName) {
  788.         for(int i = 0; i < RANKING_MAX; i++) {
  789.             for(int j = 0; j < GAMETYPE_MAX; j++) {
  790.                 prop.setProperty("marathon.ranking." + ruleName + "." + j + ".score." + i, rankingScore[j][i]);
  791.                 prop.setProperty("marathon.ranking." + ruleName + "." + j + ".lines." + i, rankingLines[j][i]);
  792.                 prop.setProperty("marathon.ranking." + ruleName + "." + j + ".time." + i, rankingTime[j][i]);
  793.             }
  794.         }
  795.     }
  796.  
  797.     /**
  798.      * Update rankings
  799.      * @param sc Score
  800.      * @param li Lines
  801.      * @param time Time
  802.      */
  803.     protected void updateRanking(int sc, int li, int time, int type) {
  804.         rankingRank = checkRanking(sc, li, time, type);
  805.  
  806.         if(rankingRank != -1) {
  807.             // Shift down ranking entries
  808.             for(int i = RANKING_MAX - 1; i > rankingRank; i--) {
  809.                 rankingScore[type][i] = rankingScore[type][i - 1];
  810.                 rankingLines[type][i] = rankingLines[type][i - 1];
  811.                 rankingTime[type][i] = rankingTime[type][i - 1];
  812.             }
  813.  
  814.             // Add new data
  815.             rankingScore[type][rankingRank] = sc;
  816.             rankingLines[type][rankingRank] = li;
  817.             rankingTime[type][rankingRank] = time;
  818.         }
  819.     }
  820.  
  821.     /**
  822.      * Calculate ranking position
  823.      * @param sc Score
  824.      * @param li Lines
  825.      * @param time Time
  826.      * @return Position (-1 if unranked)
  827.      */
  828.     protected int checkRanking(int sc, int li, int time, int type) {
  829.         for(int i = 0; i < RANKING_MAX; i++) {
  830.             if(sc > rankingScore[type][i]) {
  831.                 return i;
  832.             } else if((sc == rankingScore[type][i]) && (li > rankingLines[type][i])) {
  833.                 return i;
  834.             } else if((sc == rankingScore[type][i]) && (li == rankingLines[type][i]) && (time < rankingTime[type][i])) {
  835.                 return i;
  836.             }
  837.         }
  838.  
  839.         return -1;
  840.     }
  841.  
  842.     /**
  843.      * NET: Send various in-game stats (as well as goaltype)
  844.      * @param engine GameEngine
  845.      */
  846.     @Override
  847.     protected void netSendStats(GameEngine engine) {
  848.         int bg = engine.owner.backgroundStatus.fadesw ? engine.owner.backgroundStatus.fadebg : engine.owner.backgroundStatus.bg;
  849.         String msg = "game\tstats\t";
  850.         msg += engine.statistics.score + "\t" + engine.statistics.lines + "\t" + engine.statistics.totalPieceLocked + "\t";
  851.         msg += engine.statistics.time + "\t" + engine.statistics.level + "\t";
  852.         msg += engine.statistics.lpm + "\t" + engine.statistics.spl + "\t" + goaltype + "\t";
  853.         msg += engine.gameActive + "\t" + engine.timerActive + "\t";
  854.         msg += lastscore + "\t" + scgettime + "\t" + lastevent + "\t" + lastb2b + "\t" + lastcombo + "\t" + lastpiece + "\t";
  855.         msg += bg + "\n";
  856.         netLobby.netPlayerClient.send(msg);
  857.     }
  858.  
  859.     /**
  860.      * NET: Receive various in-game stats (as well as goaltype)
  861.      */
  862.     @Override
  863.     protected void netRecvStats(GameEngine engine, String[] message) {
  864.         engine.statistics.score = Integer.parseInt(message[4]);
  865.         engine.statistics.lines = Integer.parseInt(message[5]);
  866.         engine.statistics.totalPieceLocked = Integer.parseInt(message[6]);
  867.         engine.statistics.time = Integer.parseInt(message[7]);
  868.         engine.statistics.level = Integer.parseInt(message[8]);
  869.         engine.statistics.lpm = Float.parseFloat(message[9]);
  870.         engine.statistics.spl = Double.parseDouble(message[10]);
  871.         goaltype = Integer.parseInt(message[11]);
  872.         engine.gameActive = Boolean.parseBoolean(message[12]);
  873.         engine.timerActive = Boolean.parseBoolean(message[13]);
  874.         lastscore = Integer.parseInt(message[14]);
  875.         scgettime = Integer.parseInt(message[15]);
  876.         lastevent = Integer.parseInt(message[16]);
  877.         lastb2b = Boolean.parseBoolean(message[17]);
  878.         lastcombo = Integer.parseInt(message[18]);
  879.         lastpiece = Integer.parseInt(message[19]);
  880.         engine.owner.backgroundStatus.bg = Integer.parseInt(message[20]);
  881.  
  882.         // Meter
  883.         engine.meterValue = ((engine.statistics.lines % 10) * receiver.getMeterMax(engine)) / 9;
  884.         engine.meterColor = GameEngine.METER_COLOR_GREEN;
  885.         if(engine.statistics.lines % 10 >= 4) engine.meterColor = GameEngine.METER_COLOR_YELLOW;
  886.         if(engine.statistics.lines % 10 >= 6) engine.meterColor = GameEngine.METER_COLOR_ORANGE;
  887.         if(engine.statistics.lines % 10 >= 8) engine.meterColor = GameEngine.METER_COLOR_RED;
  888.     }
  889.  
  890.     /**
  891.      * NET: Send end-of-game stats
  892.      * @param engine GameEngine
  893.      */
  894.     @Override
  895.     protected void netSendEndGameStats(GameEngine engine) {
  896.         String subMsg = "";
  897.         subMsg += "SCORE;" + engine.statistics.score + "\t";
  898.         subMsg += "LINE;" + engine.statistics.lines + "\t";
  899.         subMsg += "LEVEL;" + (engine.statistics.level + engine.statistics.levelDispAdd) + "\t";
  900.         subMsg += "TIME;" + GeneralUtil.getTime(engine.statistics.time) + "\t";
  901.         subMsg += "SCORE/LINE;" + engine.statistics.spl + "\t";
  902.         subMsg += "LINE/MIN;" + engine.statistics.lpm + "\t";
  903.  
  904.         String msg = "gstat1p\t" + NetUtil.urlEncode(subMsg) + "\n";
  905.         netLobby.netPlayerClient.send(msg);
  906.     }
  907.  
  908.     /**
  909.      * NET: Send game options to all spectators
  910.      * @param engine GameEngine
  911.      */
  912.     @Override
  913.     protected void netSendOptions(GameEngine engine) {
  914.         String msg = "game\toption\t";
  915.         msg += startlevel + "\t" + tspinEnableType + "\t" + enableTSpinKick + "\t" + spinCheckType + "\t" + tspinEnableEZ + "\t";
  916.         msg += enableB2B + "\t" + enableCombo + "\t" + goaltype + "\t" + big + "\n";
  917.         netLobby.netPlayerClient.send(msg);
  918.     }
  919.  
  920.     /**
  921.      * NET: Receive game options
  922.      */
  923.     @Override
  924.     protected void netRecvOptions(GameEngine engine, String[] message) {
  925.         startlevel = Integer.parseInt(message[4]);
  926.         tspinEnableType = Integer.parseInt(message[5]);
  927.         enableTSpinKick = Boolean.parseBoolean(message[6]);
  928.         spinCheckType = Integer.parseInt(message[7]);
  929.         tspinEnableEZ = Boolean.parseBoolean(message[8]);
  930.         enableB2B = Boolean.parseBoolean(message[9]);
  931.         enableCombo = Boolean.parseBoolean(message[10]);
  932.         goaltype = Integer.parseInt(message[11]);
  933.         big = Boolean.parseBoolean(message[12]);
  934.     }
  935.  
  936.     /**
  937.      * NET: Get goal type
  938.      */
  939.     @Override
  940.     protected int netGetGoalType() {
  941.         return goaltype;
  942.     }
  943.  
  944.     /**
  945.      * NET: It returns true when the current settings doesn't prevent leaderboard screen from showing.
  946.      */
  947.     @Override
  948.     protected boolean netIsNetRankingViewOK(GameEngine engine) {
  949.         return ((startlevel == 0) && (!big) && (engine.ai == null));
  950.     }
  951. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement