diff --git a/android-mvn/pom.xml b/android-mvn/pom.xml index e3b3daf..795bf1c 100644 --- a/android-mvn/pom.xml +++ b/android-mvn/pom.xml @@ -68,7 +68,7 @@ com.github.msx80.omicron omicron-engine - 0.0.4 + 0.0.5 diff --git a/android-mvn/src/main/java/com/github/msx80/omicron/AndroidLauncher.java b/android-mvn/src/main/java/com/github/msx80/omicron/AndroidLauncher.java index 0b3a07b..980d9b8 100644 --- a/android-mvn/src/main/java/com/github/msx80/omicron/AndroidLauncher.java +++ b/android-mvn/src/main/java/com/github/msx80/omicron/AndroidLauncher.java @@ -14,6 +14,7 @@ import com.github.msx80.omicron.AndroidPlugin; import com.github.msx80.omicron.HardwareInterface; import com.github.msx80.omicron.api.Game; +import com.github.msx80.omicron.api.Sys; import com.github.msx80.omicron.api.adv.*; import com.github.msx80.omicron.fantasyconsole.cartridges.*; import java.util.Properties; @@ -27,7 +28,10 @@ public class AndroidLauncher extends AndroidApplication implements HardwareInter private byte[] bytesToSave = null; private Consumer fileResult = null; - //AndroidPlugin plugin = new NfcAndroidPlugin(); + + private Sys sys; + + PluginManager plugins = new PluginManager(this); @Override protected void onCreate (Bundle savedInstanceState) { @@ -59,30 +63,54 @@ protected void onCreate (Bundle savedInstanceState) { } AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); - initialize(new GdxOmicron(c, this), config); + GdxOmicron go = new GdxOmicron(c, this); + sys = go; + initialize(go, config); } - + /* @Override protected void onResume() { super.onResume(); - //plugin.onResume(this); + for(HardwarePlugin p : plugins.getPlugins()) + { + if(p instanceof AndroidPlugin) + { + ((AndroidPlugin)p).onResume(this); + } + } } @Override protected void onPause() { super.onPause(); - //plugin.onPause(this); + for(HardwarePlugin p : plugins.getPlugins()) + { + if(p instanceof AndroidPlugin) + { + ((AndroidPlugin)p).onPause(this); + } } + }*/ @Override public void onNewIntent(Intent intent) { - //plugin.onNewIntent(this, intent); + super.onNewIntent(intent); + setIntent(intent); + for(HardwarePlugin p : plugins.getPlugins()) + { + if(p instanceof AndroidPlugin) + { + + boolean ok = ((AndroidPlugin)p).resolveIntent(intent); + if(ok) return; + } + } } - +/* @Override public void openUrl(String url) throws Exception { Uri uri = Uri.parse( url ); @@ -92,16 +120,16 @@ public void openUrl(String url) throws Exception { @Override public void saveFile(String mimeType, String filename, byte[] content, Consumer result) { - /*this.bytesToSave = content; + this.bytesToSave = content; this.fileResult = result; Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(mimeType); //not needed, but maybe usefull intent.putExtra(Intent.EXTRA_TITLE, filename); //not needed, but maybe usefull startActivityForResult(intent, SAVE_FILE); - */ + } - + */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == SAVE_FILE ) { @@ -140,7 +168,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { public Object hardware(String module, String command, Object param) { - return null; + return plugins.getPlugin(module).exec(command, param); } @@ -148,4 +176,37 @@ public Object hardware(String module, String command, Object param) { return new String[0]; } + + + @Override + public Sys getSys() { + + return sys; + } + + @Override + public void setSys(Sys sys) { + // not needed + + } + + @Override + public void gamePaused() { + for(HardwarePlugin p : plugins.getPlugins()) + { + p.onPause(); + } + + } + + @Override + public void gameRestored() { + for(HardwarePlugin p : plugins.getPlugins()) + { + p.onResume(); + } + + } + + } diff --git a/android-mvn/src/main/java/com/github/msx80/omicron/AndroidLauncher.java.bak b/android-mvn/src/main/java/com/github/msx80/omicron/AndroidLauncher.java.bak deleted file mode 100644 index cb7b4f8..0000000 --- a/android-mvn/src/main/java/com/github/msx80/omicron/AndroidLauncher.java.bak +++ /dev/null @@ -1,150 +0,0 @@ -package com.github.msx80.omicron; - -import android.os.Bundle; -import android.net.Uri; -import android.content.Intent; -import android.widget.Toast; -import android.app.Activity; -import java.io.IOException; -import java.io.OutputStream; -import java.util.function.Consumer; -import com.badlogic.gdx.backends.android.AndroidApplication; -import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; -import com.github.msx80.omicron.GdxOmicron; -import com.github.msx80.omicron.AndroidPlugin; -import com.github.msx80.omicron.HardwareInterface; -import com.github.msx80.omicron.api.Game; -import com.github.msx80.omicron.api.adv.*; -import com.github.msx80.omicron.fantasyconsole.cartridges.*; -import java.util.Properties; - -import android.content.pm.*; - -public class AndroidLauncher extends AndroidApplication implements HardwareInterface { - - private static final int SAVE_FILE = 3345993; - - private byte[] bytesToSave = null; - private Consumer fileResult = null; - - //AndroidPlugin plugin = new NfcAndroidPlugin(); - - @Override - protected void onCreate (Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ExceptionHandler.addHandler(this); - Cartridge c = null; - try { - // ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); - //Bundle bundle = ai.metaData; - //String gameClass = bundle.getString("gameClass"); - - java.io.InputStream is = this.getClass().getClassLoader().getResourceAsStream("omicron_android.properties"); - java.util.Properties p = new Properties(); - p.load(is); - String gameClass = p.getProperty("omicron.pkg")+"."+p.getProperty("omicron.main"); - - int n = gameClass.lastIndexOf('.'); - String pkg = gameClass.substring(0, n); - String main = gameClass.substring(n+1); - - c = new ClasspathCartridge("Gamex", pkg, main); - - //plugin.onCreate(this, savedInstanceState); - //if(true) throw new RuntimeException("err"); - //g = (Game)Class.forName(gameClass).newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - - AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); - initialize(new GdxOmicron(c, this), config); - } - - - @Override - protected void onResume() { - super.onResume(); - //plugin.onResume(this); - } - - @Override - protected void onPause() { - super.onPause(); - //plugin.onPause(this); - } - - - @Override - public void onNewIntent(Intent intent) { - - //plugin.onNewIntent(this, intent); - } - - - @Override - public void openUrl(String url) throws Exception { - Uri uri = Uri.parse( url ); - Intent intent = new Intent( Intent.ACTION_VIEW, uri ); - this.startActivity( intent ); - } - - @Override - public void saveFile(String mimeType, String filename, byte[] content, Consumer result) { - /*this.bytesToSave = content; - this.fileResult = result; - Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType(mimeType); //not needed, but maybe usefull - intent.putExtra(Intent.EXTRA_TITLE, filename); //not needed, but maybe usefull - startActivityForResult(intent, SAVE_FILE); - */ - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - if(requestCode == SAVE_FILE ) { - // clean stuff - byte[] bytes = bytesToSave; - bytesToSave = null; - Consumer onResult = fileResult; - fileResult = null; - - if (resultCode == Activity.RESULT_OK) { - Uri uri = data.getData(); - Toast.makeText(this, "Info: "+uri, Toast.LENGTH_SHORT).show(); - //just as an example, I am writing a String to the Uri I received from the user: - String error = null; - try { - OutputStream output = getContext().getContentResolver().openOutputStream(uri); - - output.write(bytes); - output.flush(); - output.close(); - } - catch(Exception e) { - Toast.makeText(this, "Error: "+e.getMessage(), Toast.LENGTH_SHORT).show(); - error = e.getMessage(); - } - onResult.accept(error); - - } - else - { - Toast.makeText(this, "Not saved", Toast.LENGTH_SHORT).show(); - onResult.accept("dismissed"); - } - } -} - - public Object hardware(String module, String command, Object param) - { - return null; - } - - - @Override public String[] startupArgs() - { - return new String[0]; - } -} diff --git a/android-mvn/src/main/java/com/github/msx80/omicron/AndroidPlugin.java b/android-mvn/src/main/java/com/github/msx80/omicron/AndroidPlugin.java index 0a739d4..bb8c219 100644 --- a/android-mvn/src/main/java/com/github/msx80/omicron/AndroidPlugin.java +++ b/android-mvn/src/main/java/com/github/msx80/omicron/AndroidPlugin.java @@ -1,17 +1,11 @@ package com.github.msx80.omicron; -import android.os.Bundle; -import android.content.Context; +import android.app.Activity; import android.content.Intent; -public interface AndroidPlugin -{ - - void onCreate (android.app.Activity ctx, Bundle savedInstanceState); - - void onResume(android.app.Activity ctx); - - void onPause(android.app.Activity ctx); - - void onNewIntent(android.app.Activity ctx, Intent intent); + +public interface AndroidPlugin extends HardwarePlugin{ + + boolean resolveIntent(Intent intent); + } diff --git a/android-mvn/src/main/java/com/github/msx80/omicron/CrashActivity.java.bak b/android-mvn/src/main/java/com/github/msx80/omicron/CrashActivity.java.bak deleted file mode 100644 index 5e1b4fa..0000000 --- a/android-mvn/src/main/java/com/github/msx80/omicron/CrashActivity.java.bak +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.msx80.omicron; -import android.os.Bundle; -import android.app.Activity; -import android.view.Menu; -import android.widget.*; -import android.view.ViewGroup.LayoutParams; - -public class CrashActivity extends Activity { - - TextView error; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); - - TextView error = new TextView(this); - - error.setText(getIntent().getStringExtra("error")); - - ScrollView scroll = new ScrollView(this); - scroll.setBackgroundColor(android.R.color.transparent); - scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); - scroll.addView(error); - - setContentView(scroll); - } -} \ No newline at end of file diff --git a/android-mvn/src/main/java/com/github/msx80/omicron/NfcAndroidPlugin.java.pippo b/android-mvn/src/main/java/com/github/msx80/omicron/NfcAndroidPlugin.java.pippo deleted file mode 100644 index 031a1e5..0000000 --- a/android-mvn/src/main/java/com/github/msx80/omicron/NfcAndroidPlugin.java.pippo +++ /dev/null @@ -1,204 +0,0 @@ -package com.github.msx80.omicron; - -import android.os.Bundle; -import android.content.Context; - -import android.app.PendingIntent; -import android.content.Intent; -import android.nfc.NdefMessage; -import android.nfc.NdefRecord; -import android.nfc.NfcAdapter; -import android.nfc.Tag; -import android.nfc.tech.MifareClassic; -import android.nfc.tech.MifareUltralight; -import android.os.Bundle; -import android.util.Log; -import android.widget.TextView; -import android.widget.Toast; - -import org.w3c.dom.Text; - -import java.io.IOException; -import java.nio.charset.Charset; - - -public class NfcAndroidPlugin implements AndroidPlugin -{ - - NfcAdapter nfcAdapter; - PendingIntent pendingIntent; - //final static String TAG = "nfc_test"; - - - public void onCreate (android.app.Activity ctx, Bundle savedInstanceState) - { - nfcAdapter = NfcAdapter.getDefaultAdapter(ctx); - //If no NfcAdapter, display that the device has no NFC - if (nfcAdapter == null){ - throw new RuntimeException("No NFC capabilities found!"); - } - //Create a PendingIntent object so the Android system can - //populate it with the details of the tag when it is scanned. - //PendingIntent.getActivity(Context,requestcode(identifier for - // intent),intent,int) - pendingIntent = PendingIntent.getActivity(ctx,0,new Intent(ctx,ctx.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),0); - } - - public void onResume(android.app.Activity ctx) - { - nfcAdapter.enableForegroundDispatch(ctx,pendingIntent,null,null); - } - - public void onPause(android.app.Activity ctx) - { - if (nfcAdapter != null) - { - nfcAdapter.disableForegroundDispatch(ctx); - } - } - - - @Override - public void onNewIntent(android.app.Activity ctx, Intent intent) { - String action = intent.getAction(); - if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) - || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) - || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) - { - Tag tag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); - assert tag != null; - // byte[] payload = - String ss = detectTagData(tag); - Toast.makeText(ctx,ss,Toast.LENGTH_LONG).show(); - } - } - - - private String detectTagData(Tag tag) { - StringBuilder sb = new StringBuilder(); - byte[] id = tag.getId(); - sb.append("Ciaoo2").append('\n'); - sb.append("ID (hex): ").append(toHex(id)).append('\n'); - sb.append("ID (reversed hex): ").append(toReversedHex(id)).append('\n'); - sb.append("ID (dec): ").append(toDec(id)).append('\n'); - sb.append("ID (reversed dec): ").append(toReversedDec(id)).append('\n'); - - String prefix = "android.nfc.tech."; - sb.append("Technologies: "); - for (String tech : tag.getTechList()) { - sb.append(tech.substring(prefix.length())); - sb.append(", "); - } - - sb.delete(sb.length() - 2, sb.length()); - - for (String tech : tag.getTechList()) { - if (tech.equals(MifareClassic.class.getName())) { - sb.append('\n'); - String type = "Unknown"; - - try { - MifareClassic mifareTag = MifareClassic.get(tag); - - switch (mifareTag.getType()) { - case MifareClassic.TYPE_CLASSIC: - type = "Classic"; - break; - case MifareClassic.TYPE_PLUS: - type = "Plus"; - break; - case MifareClassic.TYPE_PRO: - type = "Pro"; - break; - } - sb.append("Mifare Classic type: "); - sb.append(type); - sb.append('\n'); - - sb.append("Mifare size: "); - sb.append(mifareTag.getSize() + " bytes"); - sb.append('\n'); - - sb.append("Mifare sectors: "); - sb.append(mifareTag.getSectorCount()); - sb.append('\n'); - - sb.append("Mifare blocks: "); - sb.append(mifareTag.getBlockCount()); - } catch (Exception e) { - sb.append("Mifare classic error: " + e.getMessage()); - } - } - - if (tech.equals(MifareUltralight.class.getName())) { - sb.append('\n'); - MifareUltralight mifareUlTag = MifareUltralight.get(tag); - String type = "Unknown"; - switch (mifareUlTag.getType()) { - case MifareUltralight.TYPE_ULTRALIGHT: - type = "Ultralight"; - break; - case MifareUltralight.TYPE_ULTRALIGHT_C: - type = "Ultralight C"; - break; - } - sb.append("Mifare Ultralight type: "); - sb.append(type); - } - } - Log.v("test",sb.toString()); - return sb.toString(); -} -private String toHex(byte[] bytes) { - StringBuilder sb = new StringBuilder(); - for (int i = bytes.length - 1; i >= 0; --i) { - int b = bytes[i] & 0xff; - if (b < 0x10) - sb.append('0'); - sb.append(Integer.toHexString(b)); - if (i > 0) { - sb.append(" "); - } - } - return sb.toString(); -} - -private String toReversedHex(byte[] bytes) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < bytes.length; ++i) { - if (i > 0) { - sb.append(" "); - } - int b = bytes[i] & 0xff; - if (b < 0x10) - sb.append('0'); - sb.append(Integer.toHexString(b)); - } - return sb.toString(); -} - -private long toDec(byte[] bytes) { - long result = 0; - long factor = 1; - for (int i = 0; i < bytes.length; ++i) { - long value = bytes[i] & 0xffl; - result += value * factor; - factor *= 256l; - } - return result; -} - -private long toReversedDec(byte[] bytes) { - long result = 0; - long factor = 1; - for (int i = bytes.length - 1; i >= 0; --i) { - long value = bytes[i] & 0xffl; - result += value * factor; - factor *= 256l; - } - return result; -} - - - -} diff --git a/doorsofdoom/pom.xml b/doorsofdoom/pom.xml index 9021129..7a5c3a8 100644 --- a/doorsofdoom/pom.xml +++ b/doorsofdoom/pom.xml @@ -29,9 +29,14 @@ omicron-basics 0.0.2 + + com.google.code.gson + gson + 2.11.0 + com.github.msx80.omicron - 0.0.4 + 0.0.5 omicron-desktop test diff --git a/doorsofdoom/src/main/java/com/github/msx80/doorsofdoom/DoorsOfDoom.java b/doorsofdoom/src/main/java/com/github/msx80/doorsofdoom/DoorsOfDoom.java index 9e9fee7..c210fc0 100644 --- a/doorsofdoom/src/main/java/com/github/msx80/doorsofdoom/DoorsOfDoom.java +++ b/doorsofdoom/src/main/java/com/github/msx80/doorsofdoom/DoorsOfDoom.java @@ -3,11 +3,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Map.Entry; +import java.util.concurrent.Callable; import java.util.Random; -import java.util.Set; import java.util.function.Consumer; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -22,7 +24,6 @@ import com.github.msx80.doorsofdoom.model.Monster; import com.github.msx80.doorsofdoom.model.MonsterDef; import com.github.msx80.doorsofdoom.model.Place; -import com.github.msx80.doorsofdoom.model.Range; import com.github.msx80.doorsofdoom.model.Run; import com.github.msx80.omicron.api.Game; import com.github.msx80.omicron.api.Pointer; @@ -56,11 +57,11 @@ public class DoorsOfDoom implements Game, GameInterface { private TextDrawer smallFont = null; private TextDrawer bigFont = null; - int x = 100; - int y = 10; - int dir = 0; + //int x = 100; + //int y = 10; + //int dir = 0; Pointer m; - boolean oldClick = false; + //boolean oldClick = false; int t = 0; //InventoryWidget invWidget = null; @@ -94,14 +95,28 @@ public class DoorsOfDoom implements Game, GameInterface { private String buildId; private void actionNewGame() { - doSound(15, 1f, 1f); - log.add(""); - log.add(5, "--=======================================================--"); - log.add(15, " You start a new game."); - log.add(5, "--=======================================================--"); - log.add(""); - run.init(); - enterStep(OUTDOOR); + Runnable newGame = () -> { + doSound(15, 1f, 1f); + log.add(""); + log.add(5, "--=======================================================--"); + log.add(15, " You start a new game."); + log.add(5, "--=======================================================--"); + log.add(""); + sys.mem("savestate", null); + run.init(); + enterStep(OUTDOOR); + }; + + if(hasSavedState()) + { + doSound(14, 1f, 1f); + confirm("Erase current game?", newGame, () -> { doSound(6, 1f, 1f); log.add(15, "New game canceled."); }); + } + else + { + newGame.run(); + } + } private void unimplemented() { @@ -301,6 +316,15 @@ public void init(final Sys sys) { this.r = new Random(sys.millis()); this.sys = sys; + + try { + sys.hardware("com.github.msx80.omicron.plugins.builtin.StatePlugin", "ON_RESUME", (Runnable )this::onResume); + sys.hardware("com.github.msx80.omicron.plugins.builtin.StatePlugin", "ON_PAUSE", (Runnable )this::onSuspend); + } catch (Exception e) { + e.printStackTrace(); + } + + buildId = "Build: "+new String(sys.binfile(1)); System.out.println(buildId); zoomsurf = sys.newSurface(128, 128); @@ -316,6 +340,18 @@ public void init(final Sys sys) { if (musicOn()) sys.music(1, 0.3f, true); + Callable> introOptions = () -> { + List list = new ArrayList<>(); + list.add(new Action("New Game!", this::actionNewGame)); + list.add(new Action("Settings", () -> {doSound(14, 1f, 1f); enterStep(SETTINGS);})); + if(hasSavedState()) + { + list.add(new Action("Continue!", this::restoreFromSavestate)); + } + return list; + + }; + INTRO = new Step(() -> { run.init(); log.add(15, "Welcome to", 6, " Doors of Doom", 15, "! by", 8, " MSX"); @@ -323,10 +359,7 @@ public void init(final Sys sys) { log.add(0, ""); log.add(15, "High score: ", 5, "" + getHighScore()); log.add(0, ""); - }, null, () -> Arrays.asList( - new Action("New Game!", this::actionNewGame), - new Action("Settings", () -> {doSound(14, 1f, 1f); enterStep(SETTINGS);}) - )); + }, null, introOptions); SETTINGS = new Step(() -> { // log.add(15, "Set your settings!"); @@ -427,6 +460,97 @@ public void init(final Sys sys) { enterStep(INTRO); } + private void onSuspend() + { + System.out.println("Paused received!"); + // unspool animations to get to a finite state + while(anims.isRunning()) + { + anims.update(); + System.out.println("Animations running"); + } + System.out.println("Done!"); + log.add(15, "suspended!"); + + if(step == OPENING || step == INDOOR || step == OUTDOOR || step == LOOT) + { + System.out.println("Saving config.."); + + String s = run.dump(); + sys.mem("savestate", stepToString(step)+s); + } + else + { + System.out.println("Cleaning suspend"); + sys.mem("savestate", null); + } + + + } + + private void onResume() + { + System.out.println("Resume received!"); + if(step == OPENING || step == INDOOR || step == OUTDOOR || step == LOOT) + { + // no need to resume, the game is already running + System.out.println("Game already running, no resume"); + // ensure we remove any save + sys.mem("savestate", null); + } + else + { + // if the application somehow restarted, we can resume + restoreFromSavestate(); + } + } + + private void restoreFromSavestate() { + String saveState = sys.mem("savestate"); + if(saveState != null && !saveState.isEmpty()) + { + doSound(15, 1f, 1f); + step = stringToStep(saveState.substring(0, 1)); + run = Run.load(saveState.substring(1)); + refreshCommands(); + + log.add(""); + log.add(5, "--=======================================================--"); + log.add(15, " You resume your previous game."); + log.add(5, "--=======================================================--"); + log.add(""); + + } + } + + private boolean hasSavedState() + { + String saveState = sys.mem("savestate"); + return saveState != null && !saveState.isEmpty(); + + } + + + private String stepToString(Step step) + { + if(step == OUTDOOR) return "T"; + if(step == INDOOR) return "I"; + if(step == OPENING) return "O"; + if(step == LOOT) return "L"; + throw new RuntimeException("wrong step! "); + } + + private Step stringToStep(String s) + { + if(s.equals("T")) return OUTDOOR; + if(s.equals("I")) return INDOOR; + if(s.equals("O")) return OPENING; + if(s.equals("L")) return LOOT; + + throw new RuntimeException("wrong step! "+s); + } + + private Step makeWinStep(final Sys sys) { Runnable onEnter = () -> { diff --git a/doorsofdoom/src/main/java/com/github/msx80/doorsofdoom/model/Run.java b/doorsofdoom/src/main/java/com/github/msx80/doorsofdoom/model/Run.java index 9d13b2e..bc4cbdc 100644 --- a/doorsofdoom/src/main/java/com/github/msx80/doorsofdoom/model/Run.java +++ b/doorsofdoom/src/main/java/com/github/msx80/doorsofdoom/model/Run.java @@ -1,6 +1,7 @@ package com.github.msx80.doorsofdoom.model; import com.github.msx80.doorsofdoom.DoorsOfDoom; +import com.google.gson.Gson; public class Run { public Pg pg; @@ -45,7 +46,16 @@ public void init() { pg.inventoryAdd(Item.SmallPotion, 3); pg.inventoryAdd(Item.Key, 50); + + /* + // pg.inventoryAdd(Item.Map, 1); + pg.inventoryAdd(Item.Rock, 1000); + pg.inventoryAdd(Item.Slingshot, 1); + + + pg.inventoryAdd(Item.MediumPotion, 3); + pg.inventoryAdd(Item.BigPotion, 3); pg.inventoryAdd(Item.Sword, 3); pg.inventoryAdd(Item.Shield, 1); pg.inventoryAdd(Item.Greaves, 1); @@ -61,12 +71,20 @@ public void init() { pg.inventoryAdd(Item.Slime, 22); pg.inventoryAdd(Item.Hamburger, 2); pg.inventoryAdd(Item.Phlogiston, 20); + pg.inventoryAdd(Item.Fur, 20); + pg.inventoryAdd(Item.Slime, 20); pg.inventoryAdd(Item.Ectoplasm, 20); pg.inventoryAdd(Item.BagOfGold, 2); pg.inventoryAdd(Item.FlamingSword, 1); pg.inventoryAdd(Item.CowardToken, 2); pg.inventoryAdd(Item.BagOfGold, 2); pg.inventoryAdd(Item.Knife, 2); + + pg.inventoryAdd(Item.DuraniumArmour, 2); + pg.inventoryAdd(Item.DuraniumShield, 2); + pg.inventoryAdd(Item.DuraniumChausses, 2); + pg.inventoryAdd(Item.DuraniumHelm, 2); + pg.inventoryAdd(Item.Blood, 4); pg.inventoryAdd(Item.Cheese, 15); pg.inventoryAdd(Item.Jacket, 15); @@ -107,11 +125,16 @@ public void init() { */ /* - pg.equip(Item.Bone); + pg.equip(Item.FlamingSword); + pg.equip(Item.Armour); + pg.equip(Item.Helm); + pg.equip(Item.Greaves); + pg.equip(Item.Shield); + */ // run.monster = new Monster(MonsterDef.SNAKE); - pg.addEffect(Effect.GHOSTLY); - pg.addEffect(Effect.REGENERATION); - */ + //pg.addEffect(Effect.GHOSTLY); + //pg.addEffect(Effect.BARRIER); + } public long score() { @@ -121,4 +144,19 @@ public long score() { + (pg.getInvCount(Item.CowardToken) * -15) + (exited ? DoorsOfDoom.EXIT_BONUS : 0); } + + public String dump() + { + Gson g = new Gson(); + String s = g.toJson(this); + System.out.println(s); + return s; + } + + public static Run load(String s) + { + Gson g = new Gson(); + Run r = g.fromJson(s, Run.class); + return r; + } }