Skip to content

Commit

Permalink
Add automatic reload on empty (for slow rate of fire)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Dees-Troy committed Feb 13, 2018
1 parent 00b124c commit acde9c3
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/simplecoil/simplecoil/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/simplecoil/simplecoil/TcpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/simplecoil/simplecoil/TcpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)) {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/player_settings_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
android:inputType="number" >
</EditText>

<Switch
android:id="@+id/reload_on_empty_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/player_settings_reload_on_empty" />

<TextView
android:id="@+id/spawn_time_title"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<string name="player_settings_spawn_time">Respawn Time (Seconds)</string>
<string name="player_settings_reload_time">Reload Time (Milliseconds)</string>
<string name="player_settings_reload_shots">Shots Per Reload</string>
<string name="player_settings_reload_on_empty">Reload on empty?</string>
<string name="player_settings_damage">Damage Per Hit To Others (Network Game Only)</string>
<string name="player_settings_override_lives">Override lives limit?</string>
<string name="player_settings_lives">Lives</string>
Expand Down

0 comments on commit acde9c3

Please sign in to comment.