From acde9c395754848fbbe04b7b64292d6da28164d6 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Mon, 12 Feb 2018 21:06:06 -0600 Subject: [PATCH] Add automatic reload on empty (for slow rate of fire) Automatic reload on empty with no reload sound for instagib or sniper rifle style of play. This also serves as a proof of concept for ways to limit the max rate of fire. Bugfixes: -Game ends properly in non-network games when the player runs out of lives -Game limits button reappears after a game ends properly --- .idea/misc.xml | 2 +- app/build.gradle | 4 ++-- .../com/simplecoil/simplecoil/FullscreenActivity.java | 9 ++++++++- app/src/main/java/com/simplecoil/simplecoil/Globals.java | 2 ++ .../simplecoil/simplecoil/PlayerSettingsAlertDialog.java | 7 +++++++ .../main/java/com/simplecoil/simplecoil/TcpClient.java | 3 +++ .../main/java/com/simplecoil/simplecoil/TcpServer.java | 3 +++ app/src/main/res/layout/player_settings_dialog.xml | 7 +++++++ app/src/main/res/values/strings.xml | 1 + 9 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index ba7052b..635999d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -24,7 +24,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 65247f3..cfd9364 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.simplecoil.simplecoil" minSdkVersion 21 targetSdkVersion 26 - versionCode 6 - versionName "1.5" + versionCode 7 + versionName "1.6" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/com/simplecoil/simplecoil/FullscreenActivity.java b/app/src/main/java/com/simplecoil/simplecoil/FullscreenActivity.java index baa6fb9..7d75b1c 100644 --- a/app/src/main/java/com/simplecoil/simplecoil/FullscreenActivity.java +++ b/app/src/main/java/com/simplecoil/simplecoil/FullscreenActivity.java @@ -1185,6 +1185,7 @@ private void endGame() { mGameTimer.stop(); mUseNetworkingButton.setVisibility(View.VISIBLE); mFiringModeButton.setVisibility(View.VISIBLE); + mGameLimitButton.setVisibility(View.VISIBLE); setNetworkMenu(NETWORK_TYPE_ENABLED); } @@ -1749,7 +1750,8 @@ public void onFinish() { mReloading = RELOADING_STATE_NONE; mReloadBar.setVisibility(View.INVISIBLE); mShotsRemainingTV.setVisibility(View.VISIBLE); - playSound(R.raw.reload, getApplicationContext()); + if (!Globals.getInstance().mReloadOnEmpty) + playSound(R.raw.reload, getApplicationContext()); Log.d(TAG, "Reload finished"); } } @@ -2044,6 +2046,9 @@ public void run() { mTcpClient.sendTCPMessage(TcpServer.TCPMESSAGE_PREFIX + TcpServer.TCPPREFIX_MESG + NetMsg.NETMSG_LEAVE); else mUDPListenerService.sendUDPMessageAll(NetMsg.NETMSG_LEAVE); + } + } else { + if (mHasLivesLimit && mEliminationCount <= 0) { Toast.makeText(getApplicationContext(), getString(R.string.dialog_out_of_lives), Toast.LENGTH_LONG).show(); endGame(); // Sorry, you're out of the game } @@ -2073,6 +2078,8 @@ public void run() { mLastShotFired = System.currentTimeMillis() + HIT_ANIMATION_DURATION_MILLISECONDS; mUDPListenerService.sendUDPMessageAll(NetMsg.NETMSG_SHOTFIRED); } + if (Globals.getInstance().mReloadOnEmpty && shotsRemaining == 0 && Globals.getInstance().mGameState != Globals.GAME_STATE_NONE) + startReload(); } } // Handy utility code if you want to see the raw data diff --git a/app/src/main/java/com/simplecoil/simplecoil/Globals.java b/app/src/main/java/com/simplecoil/simplecoil/Globals.java index 0ed6afb..b3991a3 100644 --- a/app/src/main/java/com/simplecoil/simplecoil/Globals.java +++ b/app/src/main/java/com/simplecoil/simplecoil/Globals.java @@ -44,6 +44,7 @@ public class Globals { public volatile boolean mOverrideLives = false; public volatile int mOverrideLivesVal = 0; public volatile boolean mAllowPlayerSettings = true; + public volatile boolean mReloadOnEmpty = false; // Primarily intended for instagib // 1 for FFA, 2 for 2 Teams, and 4 for 4 Teams public static final int GAME_MODE_FFA = 1; @@ -249,6 +250,7 @@ public static class PlayerSettings { int health = Globals.MAX_HEALTH; byte shots = Globals.RELOAD_COUNT; long reloadTime = Globals.RELOAD_TIME_MILLISECONDS; + boolean reloadOnEmpty = false; long spawnTime = Globals.RESPAWN_TIME_SECONDS; int damage = Globals.DAMAGE_PER_HIT; boolean overrideLives = false; diff --git a/app/src/main/java/com/simplecoil/simplecoil/PlayerSettingsAlertDialog.java b/app/src/main/java/com/simplecoil/simplecoil/PlayerSettingsAlertDialog.java index 4012215..78e51c5 100644 --- a/app/src/main/java/com/simplecoil/simplecoil/PlayerSettingsAlertDialog.java +++ b/app/src/main/java/com/simplecoil/simplecoil/PlayerSettingsAlertDialog.java @@ -34,6 +34,7 @@ public class PlayerSettingsAlertDialog extends AlertDialog { private EditText mHealthET = null; private EditText mReloadShotsET = null; private EditText mReloadTimeET = null; + private Switch mReloadOnEmptySwitch = null; private EditText mSpawnTimeET = null; private EditText mDamageET = null; private Switch mOverrideLivesSwitch = null; @@ -70,6 +71,7 @@ public void getServerSettings() { mHealthET.setText("" + playerSettings.health); mReloadShotsET.setText("" + playerSettings.shots); mReloadTimeET.setText("" + playerSettings.reloadTime); + mReloadOnEmptySwitch.setChecked(playerSettings.reloadOnEmpty); mSpawnTimeET.setText("" + playerSettings.spawnTime); mDamageET.setText("" + (playerSettings.damage * -1)); mOverrideLivesSwitch.setChecked(playerSettings.overrideLives); @@ -88,6 +90,7 @@ private void getLocalSettings() { mHealthET.setText("" + Globals.getInstance().mFullHealth); mReloadShotsET.setText("" + Globals.getInstance().mFullReload); mReloadTimeET.setText("" + Globals.getInstance().mReloadTime); + mReloadOnEmptySwitch.setChecked(Globals.getInstance().mReloadOnEmpty); mSpawnTimeET.setText("" + Globals.getInstance().mRespawnTime); mDamageET.setText("" + (Globals.getInstance().mDamage * -1)); mOverrideLivesSwitch.setChecked(Globals.getInstance().mOverrideLives); @@ -106,6 +109,7 @@ protected void onCreate(Bundle savedInstanceState) { mHealthET = view.findViewById(R.id.health_et); mReloadShotsET = view.findViewById(R.id.reload_shots_et); mReloadTimeET = view.findViewById(R.id.reload_time_et); + mReloadOnEmptySwitch = view.findViewById(R.id.reload_on_empty_switch); mSpawnTimeET = view.findViewById(R.id.spawn_time_et); mDamageET = view.findViewById(R.id.damage_et); mOverrideLivesSwitch = view.findViewById(R.id.override_lives_limit_switch); @@ -117,6 +121,7 @@ public void onClick(View view) { mHealthET.setText("" + Globals.MAX_HEALTH); mReloadShotsET.setText("" + Globals.RELOAD_COUNT); mReloadTimeET.setText("" + Globals.RELOAD_TIME_MILLISECONDS); + mReloadOnEmptySwitch.setChecked(false); mSpawnTimeET.setText("" + Globals.RESPAWN_TIME_SECONDS); mDamageET.setText("" + (Globals.DAMAGE_PER_HIT * -1)); mOverrideLivesSwitch.setChecked(false); @@ -140,6 +145,7 @@ public void onClick(DialogInterface dialog, int which) { if (value > 10000 || value < 0) value = (int) Globals.RELOAD_TIME_MILLISECONDS; Globals.getInstance().mReloadTime = value; + Globals.getInstance().mReloadOnEmpty = mReloadOnEmptySwitch.isChecked(); value = Integer.parseInt(mSpawnTimeET.getText().toString()); if (value > 1000 || value <= 0) value = (int) Globals.RESPAWN_TIME_SECONDS; @@ -174,6 +180,7 @@ public void onClick(DialogInterface dialog, int which) { if (value > 10000 || value < 0) value = (int) Globals.RELOAD_TIME_MILLISECONDS; playerSettings.reloadTime = value; + playerSettings.reloadOnEmpty = mReloadOnEmptySwitch.isChecked(); value = Integer.parseInt(mSpawnTimeET.getText().toString()); if (value > 1000 || value <= 0) value = (int) Globals.RESPAWN_TIME_SECONDS; diff --git a/app/src/main/java/com/simplecoil/simplecoil/TcpClient.java b/app/src/main/java/com/simplecoil/simplecoil/TcpClient.java index 9d1ed58..8eb47aa 100644 --- a/app/src/main/java/com/simplecoil/simplecoil/TcpClient.java +++ b/app/src/main/java/com/simplecoil/simplecoil/TcpClient.java @@ -282,6 +282,7 @@ public void sendPlayerSettings() { playerSettings.put(TcpServer.JSON_HEALTH, Globals.getInstance().mFullHealth); playerSettings.put(TcpServer.JSON_RELOAD_SHOTS, Globals.getInstance().mFullReload); playerSettings.put(TcpServer.JSON_RELOAD_TIME, Globals.getInstance().mReloadTime); + playerSettings.put(TcpServer.JSON_RELOAD_ON_EMPTY, Globals.getInstance().mReloadOnEmpty); playerSettings.put(TcpServer.JSON_SPAWN_TIME, Globals.getInstance().mRespawnTime); playerSettings.put(TcpServer.JSON_DAMAGE, Globals.getInstance().mDamage); if (Globals.getInstance().mOverrideLives) @@ -378,6 +379,7 @@ private void parseGameInfo(String message) { playerSettings.health = setting.getInt(TcpServer.JSON_HEALTH); playerSettings.shots = (byte)setting.getInt(TcpServer.JSON_RELOAD_SHOTS); playerSettings.reloadTime = setting.getLong(TcpServer.JSON_RELOAD_TIME); + playerSettings.reloadOnEmpty = setting.getBoolean(TcpServer.JSON_RELOAD_ON_EMPTY); playerSettings.spawnTime = setting.getLong(TcpServer.JSON_SPAWN_TIME); playerSettings.damage = setting.getInt(TcpServer.JSON_DAMAGE); if (setting.has(TcpServer.JSON_LIVESLIMIT)) { @@ -391,6 +393,7 @@ private void parseGameInfo(String message) { Globals.getInstance().mFullHealth = playerSettings.health; Globals.getInstance().mFullReload = playerSettings.shots; Globals.getInstance().mReloadTime = playerSettings.reloadTime; + Globals.getInstance().mReloadOnEmpty = playerSettings.reloadOnEmpty; Globals.getInstance().mRespawnTime = playerSettings.spawnTime; Globals.getInstance().mDamage = playerSettings.damage; Globals.getInstance().mOverrideLives = playerSettings.overrideLives; diff --git a/app/src/main/java/com/simplecoil/simplecoil/TcpServer.java b/app/src/main/java/com/simplecoil/simplecoil/TcpServer.java index b8a4ff9..5d3fe84 100644 --- a/app/src/main/java/com/simplecoil/simplecoil/TcpServer.java +++ b/app/src/main/java/com/simplecoil/simplecoil/TcpServer.java @@ -88,6 +88,7 @@ public class TcpServer extends Service { public static final String JSON_HEALTH = "health"; public static final String JSON_RELOAD_SHOTS = "reloadshots"; public static final String JSON_RELOAD_TIME = "reloadtime"; + public static final String JSON_RELOAD_ON_EMPTY = "reloadonempty"; public static final String JSON_SPAWN_TIME = "spawntime"; public static final String JSON_DAMAGE = "damage"; public static final String JSON_ALLOWPLAYERSETTINGS = "allowplayersettings"; @@ -439,6 +440,7 @@ public void sendPlayerSettings(byte playerID, boolean applyAll, boolean allowPla player.put(JSON_HEALTH, entry.getValue().health); player.put(JSON_RELOAD_SHOTS, entry.getValue().shots); player.put(JSON_RELOAD_TIME, entry.getValue().reloadTime); + player.put(JSON_RELOAD_ON_EMPTY, entry.getValue().reloadOnEmpty); player.put(JSON_SPAWN_TIME, entry.getValue().spawnTime); player.put(JSON_DAMAGE, entry.getValue().damage); if (entry.getValue().overrideLives) @@ -793,6 +795,7 @@ private void parsePlayerInfo(String message, ClientData client) { settings.health = player.getInt(JSON_HEALTH); settings.shots = (byte)player.getInt(JSON_RELOAD_SHOTS); settings.reloadTime = player.getLong(JSON_RELOAD_TIME); + settings.reloadOnEmpty = player.getBoolean(JSON_RELOAD_ON_EMPTY); settings.spawnTime = player.getLong(JSON_SPAWN_TIME); settings.damage = player.getInt(JSON_DAMAGE); if (player.has(JSON_LIVESLIMIT)) { diff --git a/app/src/main/res/layout/player_settings_dialog.xml b/app/src/main/res/layout/player_settings_dialog.xml index 2fcc382..4a24391 100644 --- a/app/src/main/res/layout/player_settings_dialog.xml +++ b/app/src/main/res/layout/player_settings_dialog.xml @@ -74,6 +74,13 @@ android:inputType="number" > + + Respawn Time (Seconds) Reload Time (Milliseconds) Shots Per Reload + Reload on empty? Damage Per Hit To Others (Network Game Only) Override lives limit? Lives