1
0
Fork 0

PlayerEditor: rearranged and added defenses

This commit is contained in:
Carlos Galindo 2015-07-21 17:22:22 +02:00
parent 3a1ae709e3
commit a71b7aa7dc
4 changed files with 251 additions and 67 deletions

View file

@ -81,7 +81,7 @@ class Player implements Serializable {
}; //TODO: move the names to a string-array in the res/values folder
public static final int[] ABILITY_BOOST = new int[] {
-1, DEX, CON, INT, STR, CHA, WIS, CHA, INT, CHA, DEX, WIS, WIS, WIS, CHA, INT, WIS, DEX
NULL, DEX, CON, INT, STR, CHA, WIS, CHA, INT, CHA, DEX, WIS, WIS, WIS, CHA, INT, WIS, DEX
};
/**
@ -108,7 +108,6 @@ class Player implements Serializable {
setLevel();
this.raceInt = p.getInt(RACE, 0);
this.classInt = p.getInt(CLASS, 0);
this.def = new int[5];
setAtk(new int[] {
0,
p.getInt("fue", 10),
@ -118,6 +117,28 @@ class Player implements Serializable {
p.getInt("sab", 10),
p.getInt("car", 10)}
);
this.def = new int[]{
0,
p.getInt(
"ac",
10 + level / 2 + Math.max(0, Player.getModifier(Math.max(atk[DEX], atk[INT])))
),
p.getInt(
"fort",
10 + level / 2 + Player.getModifier(Math.max(atk[CON], atk[STR])) +
CLASS_STATS[DEF_FORT][classInt]
),
p.getInt(
"ref",
10 + level / 2 + Player.getModifier(Math.max(atk[DEX], atk[INT])) +
CLASS_STATS[DEF_REF][classInt]
),
p.getInt(
"will",
10 + level / 2 + Player.getModifier(Math.max(atk[CHA], atk[WIS])) +
CLASS_STATS[DEF_WILL][classInt]
)
};
setState();
this.hp = p.getInt( "pg" , maxHp);
this.surges = p.getInt( "curativeEfforts" , maxSurges);
@ -216,14 +237,13 @@ class Player implements Serializable {
+ ( level - 1 ) * CLASS_STATS[HP_ON_LEVEL_UP][classInt];
maxSurges =
Player.getModifier(atk[CON]) + CLASS_STATS[DAILY_SURGES][classInt];
//TODO: implement armor!
def[AC] = 10 + level / 2 + Math.max(0, Player.getModifier(Math.max(atk[DEX], atk[INT])));
def[FORT] = 10 + level / 2 + Player.getModifier(Math.max(atk[CON], atk[STR])) +
CLASS_STATS[DEF_FORT][classInt];
def[REF] = 10 + level / 2 + Player.getModifier(Math.max(atk[DEX], atk[INT])) +
CLASS_STATS[DEF_REF][classInt];
def[WILL] = 10 + level / 2 + Player.getModifier(Math.max(atk[CHA], atk[WIS])) +
CLASS_STATS[DEF_WILL][classInt];
// def[AC] = 10 + level / 2 + Math.max(0, Player.getModifier(Math.max(atk[DEX], atk[INT])));
// def[FORT] = 10 + level / 2 + Player.getModifier(Math.max(atk[CON], atk[STR])) +
// CLASS_STATS[DEF_FORT][classInt];
// def[REF] = 10 + level / 2 + Player.getModifier(Math.max(atk[DEX], atk[INT])) +
// CLASS_STATS[DEF_REF][classInt];
// def[WILL] = 10 + level / 2 + Player.getModifier(Math.max(atk[CHA], atk[WIS])) +
// CLASS_STATS[DEF_WILL][classInt];
}
static int getModifier(int i) {
@ -262,7 +282,12 @@ class Player implements Serializable {
e.putInt("int", atk[INT]);
e.putInt("sab", atk[WIS]);
e.putInt("car", atk[CHA]);
//TODO: defenses (add armor and other bonuses)
e.putInt("ac", def[AC]);
e.putInt("fort", def[FORT]);
e.putInt("ref", def[REF]);
e.putInt("will", def[WILL]);
e.putInt("pg", hp);
e.putInt("curativeEfforts", surges);
e.commit();

View file

@ -1,11 +1,13 @@
package com.kauron.dungeonmanager;
import android.app.Dialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
@ -18,7 +20,10 @@ import com.nispok.snackbar.SnackbarManager;
public class PlayerEditor extends ActionBarActivity {
private EditText name, xp;
private EditText[] atk = new EditText[7];
private EditText[] editAtk = new EditText[7];
private int[] def;
private int position;
private Player player;
private Spinner classSpinner, raceSpinner;
@Override
@ -32,12 +37,12 @@ public class PlayerEditor extends ActionBarActivity {
name = (EditText) findViewById(R.id.namePlayerEdit);
name.requestFocus();
xp = (EditText) findViewById(R.id.xpEdit);
atk[Player.STR] = (EditText) findViewById(R.id.STR);
atk[Player.CON] = (EditText) findViewById(R.id.CON);
atk[Player.DEX] = (EditText) findViewById(R.id.DEX);
atk[Player.WIS] = (EditText) findViewById(R.id.WIS);
atk[Player.INT] = (EditText) findViewById(R.id.INT);
atk[Player.CHA] = (EditText) findViewById(R.id.CHA);
editAtk[Player.STR] = (EditText) findViewById(R.id.STR);
editAtk[Player.CON] = (EditText) findViewById(R.id.CON);
editAtk[Player.DEX] = (EditText) findViewById(R.id.DEX);
editAtk[Player.WIS] = (EditText) findViewById(R.id.WIS);
editAtk[Player.INT] = (EditText) findViewById(R.id.INT);
editAtk[Player.CHA] = (EditText) findViewById(R.id.CHA);
classSpinner = (Spinner) findViewById(R.id.classSpinner);
classSpinner.setAdapter(
@ -56,16 +61,21 @@ public class PlayerEditor extends ActionBarActivity {
Player.RACE_STRINGS
)
);
int position = getIntent().getExtras().getInt("player", -1);
position = getIntent().getIntExtra("player", -1);
if ( position != -1 ) {
Player p = new Player(getSharedPreferences("player" + position, MODE_PRIVATE));
name.setText(p.getName());
xp.setText(String.valueOf(p.getXp()));
int[] attack = p.getAtk();
player = new Player(
getSharedPreferences(
getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE)
.getString("player" + position, ""),
MODE_PRIVATE)
);
name.setText(player.getName());
xp.setText(String.valueOf(player.getXp()));
int[] attack = player.getAtk();
for (int i = Player.STR; i < Player.CHA + 1; i++)
atk[i].setText(String.valueOf(attack[i]));
classSpinner.setSelection(p.getClassInt());
raceSpinner.setSelection(p.getRaceInt());
editAtk[i].setText(String.valueOf(attack[i]));
classSpinner.setSelection(player.getClassInt());
raceSpinner.setSelection(player.getRaceInt());
}
}
@ -121,8 +131,8 @@ public class PlayerEditor extends ActionBarActivity {
int[] atkInts = new int[7];
for (int i = Player.STR; i <= Player.CHA; i++)
if (!atk[i].getText().toString().isEmpty())
atkInts[i] = Integer.parseInt(atk[i].getText().toString());
if (!editAtk[i].getText().toString().isEmpty())
atkInts[i] = Integer.parseInt(editAtk[i].getText().toString());
boolean validAtk = true;
for (int i = Player.STR; i <= Player.CHA; i++)
if (atkInts[i] == 0) {
@ -139,13 +149,32 @@ public class PlayerEditor extends ActionBarActivity {
) {
SharedPreferences p = getSharedPreferences(Welcome.PREFERENCES, MODE_PRIVATE);
int i = p.getInt("players", 0);
String saveName = nameString;
for (int j = 0; j < i; j++) {
if (p.getString("player" + j, "").equals(saveName))
saveName += "2";
boolean isNew = true;
if (player == null) {
for (int j = 0; j < i; j++) {
if (nameString.equals(p.getString("player" + j, ""))) {
if (player == null) {
Toast.makeText(
this,
"There is another player with that name, edit that player or change the name",
Toast.LENGTH_LONG
).show();
return false;
}
isNew = false;
break;
}
}
} else {
isNew = false;
if (nameString != player.getName()) {
getSharedPreferences(player.getName(), MODE_PRIVATE).edit().clear().apply();
p.edit().putString("player" + position, nameString).apply();
}
}
p.edit().putString("player" + i, saveName).putInt("players", i + 1).apply();
SharedPreferences.Editor ed = getSharedPreferences(saveName, MODE_PRIVATE).edit();
if (isNew) p.edit().putString("player" + i, nameString).putInt("players", i + 1).apply();
SharedPreferences.Editor ed = getSharedPreferences(nameString, MODE_PRIVATE).edit();
//first save it all
ed.putString("playerName", nameString);
@ -153,16 +182,59 @@ public class PlayerEditor extends ActionBarActivity {
ed.putInt("raceInt", raceInt);
ed.putInt("px", pxInt);
ed.putInt("str", atkInts[Player.STR]);
ed.putInt("cha", atkInts[Player.CHA]);
ed.putInt("fue", atkInts[Player.STR]);
ed.putInt("car", atkInts[Player.CHA]);
ed.putInt("int", atkInts[Player.INT]);
ed.putInt("wis", atkInts[Player.WIS]);
ed.putInt("sab", atkInts[Player.WIS]);
ed.putInt("con", atkInts[Player.CON]);
ed.putInt("dex", atkInts[Player.DEX]);
ed.putInt("des", atkInts[Player.DEX]);
if (def != null) {
ed.putInt("ac", def[Player.AC]);
ed.putInt("fort", def[Player.FORT]);
ed.putInt("ref", def[Player.REF]);
ed.putInt("will", def[Player.WILL]);
}
ed.apply();
return true;
} else {
return false;
}
}
public void onDefenseClick(View view) {
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.defense_editor);
if (player != null) {
((EditText) dialog.findViewById(R.id.ac)).setText(
String.valueOf(player.getDef()[Player.AC]));
((EditText) dialog.findViewById(R.id.fort)).setText(
String.valueOf(player.getDef()[Player.FORT]));
((EditText) dialog.findViewById(R.id.ref)).setText(
String.valueOf(player.getDef()[Player.REF]));
((EditText) dialog.findViewById(R.id.will)).setText(
String.valueOf(player.getDef()[Player.WILL]));
}
dialog.findViewById(R.id.saveButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
def = new int[7];
EditText ac = (EditText) dialog.findViewById(R.id.ac);
if (!ac.getText().toString().isEmpty())
def[Player.AC] = Integer.parseInt(ac.getText().toString());
EditText fort = (EditText) dialog.findViewById(R.id.fort);
if (!ac.getText().toString().isEmpty())
def[Player.FORT] = Integer.parseInt(fort.getText().toString());
EditText ref = (EditText) dialog.findViewById(R.id.ref);
if (!ac.getText().toString().isEmpty())
def[Player.REF] = Integer.parseInt(ref.getText().toString());
EditText will = (EditText) dialog.findViewById(R.id.will);
if (!ac.getText().toString().isEmpty())
def[Player.WILL] = Integer.parseInt(will.getText().toString());
dialog.dismiss();
}
});
dialog.show();
}
}

View file

@ -79,7 +79,7 @@
</LinearLayout>
<GridLayout
android:layout_width="fill_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/secondLayout"
android:id="@+id/thirdLayout"
@ -116,8 +116,8 @@
android:inputType="number"
android:ems="3"
android:layout_row="0"
android:layout_column="1"
android:layout_row="2"
android:layout_column="0"
android:id="@+id/DEX"
android:hint="@string/DEX"
@ -129,7 +129,7 @@
android:inputType="number"
android:ems="3"
android:layout_row="1"
android:layout_row="0"
android:layout_column="1"
android:id="@+id/INT"
@ -142,8 +142,8 @@
android:inputType="number"
android:ems="3"
android:layout_row="0"
android:layout_column="2"
android:layout_row="1"
android:layout_column="1"
android:id="@+id/WIS"
android:hint="@string/WIS"
@ -156,35 +156,34 @@
android:ems="3"
android:imeOptions="actionDone"
android:layout_row="1"
android:layout_column="2"
android:layout_row="2"
android:layout_column="1"
android:id="@+id/CHA"
android:hint="@string/CHA"/>
</GridLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/thirdLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:visibility="gone"
android:id="@+id/fourthLayout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Defense"
android:id="@+id/defenseButton"
android:layout_below="@+id/secondLayout"
android:layout_toRightOf="@+id/thirdLayout"
android:layout_alignRight="@+id/secondLayout"
android:layout_alignEnd="@+id/secondLayout"
android:onClick="onDefenseClick" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/new_attack"
android:id="@+id/new_attack_button" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/powerList"
android:choiceMode="none" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Abilities"
android:id="@+id/abilityButton"
android:layout_below="@+id/defenseButton"
android:layout_toRightOf="@+id/thirdLayout"
android:layout_alignRight="@+id/defenseButton"
android:layout_alignEnd="@+id/defenseButton"
android:onClick="onAbilityClick" />
</RelativeLayout>

View file

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:columnCount="2"
android:rowCount="5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Fort"
android:id="@+id/fortText"
android:layout_row="1"
android:layout_column="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/fort"
android:layout_row="1"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Ref"
android:id="@+id/refText"
android:layout_row="2"
android:layout_column="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/ref"
android:layout_row="2"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="CA"
android:id="@+id/acText"
android:layout_row="0"
android:layout_column="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/ac"
android:layout_row="0"
android:layout_column="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Will"
android:id="@+id/willText"
android:layout_row="3"
android:layout_column="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:ems="10"
android:id="@+id/will"
android:layout_row="3"
android:layout_column="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:id="@+id/saveButton"
android:layout_row="4"
android:layout_column="1"
android:layout_gravity="right" />
</GridLayout>