code
stringlengths
3
1.18M
language
stringclasses
1 value
package org.clockworkmages.games.anno1186.generator.sets; import org.clockworkmages.games.anno1186.TimeConstants; import org.clockworkmages.games.anno1186.dao.GameObjectsList; import org.clockworkmages.games.anno1186.generator.GameObjectGenerator; import org.clockworkmages.games.anno1186.model.Effecting; import org.clockworkmages.games.anno1186.model.FetishConstants; import org.clockworkmages.games.anno1186.model.character.SkillConstants; import org.clockworkmages.games.anno1186.model.character.StatConstants; import org.clockworkmages.games.anno1186.model.effect.Effect; import org.clockworkmages.games.anno1186.model.option.GenericOption; import org.clockworkmages.games.anno1186.model.situation.GenericSituation; import org.clockworkmages.games.anno1186.scripting.tools.ScriptBuilder; import org.clockworkmages.games.anno1186.scripting.tools.TextBuilder; public class PalosCardPlayer extends GameObjectGenerator // implements StatConstants, SkillConstants, TechnicalSituationConstants, TimeConstants { public static final String STATE = "STATE"; public static final String STATE_NEW = "NEW"; public String getFileName() { return "palos_cardplayer"; } @Override public GameObjectsList generate() { GameObjectsList gameObjects = new GameObjectsList(); GenericOption option = new GenericOption(); GenericSituation situation = new GenericSituation(); String STATE_NEGOTIATING = "NEGOTIATING"; String STATE_WON = "WON"; String STATE_LOST = "LOST"; String STATE_LOST_SUBMISSION = "LOST_SUBMISSION"; String PLOT_PALOS_TAVERN_CARDPLAYER_ISGONE = "PALOS_TAVERN_CARDPLAYER_ISGONE"; // located options option = new GenericOption(); option.setSituationId("PALOS_TAVERN"); option.setAddToStack(true); option.setSee("two locals playing cards"); option.setLabel("Card players"); option.setIcon("talk"); option.setGoToSituation("PALOS_TAVERN_CARDPLAYER"); option.setCondition("!" + ScriptBuilder.NEW().util().isDay().and().not().plot() .is(PLOT_PALOS_TAVERN_CARDPLAYER_ISGONE).toString()); gameObjects.getOptions().add(option); // situations: situation = new GenericSituation(); situation.setId("PALOS_TAVERN_CARDPLAYER"); switchState(situation, STATE_NEW); situation.setTitle("Diego, the gambler sailor"); situation.setText(// "As you approach the table where the two men were playing cards, one of them gets up, throws his cards onto the table angrily and walks out the tavern's door, cursing under his nose.\n" + "The other player happily gathers the cards and the coins lying on the table and then looks up at you, flashing you a beaming smile smile.\n" + // "He is a young man, maybe twenty, and not unhandsome. With his relaxed pose, tanned skin and cheap, comfortable clothes he could probably be a sailor on a shore leave.\n" + TextBuilder .NEW() .iff() .plot() .get("BIRTH") .equalsString("SCUM") .then(// "{f:i}[Origin]{f} You actually know that guy - it's Diego, a sailor and a gambler that you've seen in Palos several times before. He something cheats in cards, but generally he's good company.\n") .asText() + " - Well hello there, friend! - he says as you come closer - ${if " + ScriptBuilder.NEW().plot().get("BIRTH") + "=='SCUM'}Name's Diego. ${fi}Care for a game of cards? I just won a few coins from that poor sod and it's only fair that I lose them to you.\n"); gameObjects.getSituations().add(situation); // STATE=NEW // win the game option = new GenericOption(); option.setCondition(checkState(STATE_NEW).and().me().getGold().ge(50) .and().util().random(100).le(40).toString()); switchState(option, STATE_WON); option.getEffects().add( new Effect(ScriptBuilder.NEW().me().addGold(50).toString())); option.getEffects().add( new Effect(ScriptBuilder.NEW().plot() .set(PLOT_PALOS_TAVERN_CARDPLAYER_ISGONE).toString())); option.setLabel("Sure, let's play!"); option.setTextAfter(" - Sure, let's play!\n" + "Diego deals the cards and you actually get a strong hand with three aces. You get two more cards and get one more ace! You easily beat Dieago's two pairs of eights and dames. You win!\n" + "- Damn, it, you're one lucky " + TextBuilder.NEW().iff().me().isMale().then("bastard") .elsee("wench").asText() + " - says Diego - Here's your gold. I'm broke, again, so I'm done gambling for tonight."); situation.getOptions().add(option); // lose the game option = new GenericOption(); option.setOr(true); // condition option.setCondition(checkState(STATE_NEW).and().me().getGold().ge(50) .toString()); // switchState(option, STATE_NEW); // target option.getEffects().add( new Effect(ScriptBuilder.NEW().me().addGold(-50).toString())); // effect option.setLabel("Sure, let's play!"); option.setTextAfter("- Well... ok. Let's play!\n" + "Diego deals the cards and you get an average hand - you only have a pair of tens. You exchange three cards but only get a five. Diego easily beats you with his three dames. You lose!!\n" + "- Well, lucky me - says Diego with a smile as he collects the coins from the table. - How about we play another round, for 50 coins again?\n"); situation.getOptions().add(option); option = new GenericOption(); option.setOr(true); option.setCondition(checkState(STATE_NEW) .and() .util() .fetishesEnabled(FetishConstants.MEN, FetishConstants.SUBMISSION).toString()); switchState(option, STATE_NEGOTIATING); option.setLabel("I don't have that sort of money"); option.setTextAfter("- I don't have that much money.\n" + "Diego looks at you for a moment, rubbing his chin thoughtfully.\n" + " - I see - he says eventually - Fortunately for you, I have a weak spot for comely ${if " + ScriptBuilder.NEW().me().isMale() + "}lads${else}lasses${fi} like you. How about we play anyway. You win, you take my 50 coins. I win, you spend the next hour in my room with your lips . One way or another, it's your lucky night."); situation.getOptions().add(option); // NEGOTIATING option = new GenericOption(); option.setCondition(checkState(STATE_NEGOTIATING).and().util() .random(100).le(40).toString()); switchState(option, STATE_WON); option.getEffects().add( new Effect(ScriptBuilder.NEW().me().addGold(50).toString())); option.setLabel("Well... ok. Let's play!"); option.setTextAfter("- Well... ok. Let's play!\n" + "Diego deals the cards and you actually get a strong hand with three aces. You get two more cards and get one more ace! You easily beat Dieago's two pairs of eights and dames. You win!\n" + "- Damn, it, you're one lucky " + "${if " + ScriptBuilder.NEW().me().isMale() + "}bastard${else}wench${fi}" + " - says Diego - Here's your gold. I'm broke, again, so I'm done gambling for tonight."); situation.getOptions().add(option); option = new GenericOption(); option.setOr(true); option.setCondition(checkState(STATE_NEGOTIATING).toString()); switchState(option, STATE_LOST_SUBMISSION); option.setLabel("Well... ok. Let's play!"); option.setTextAfter("- Well... ok. Let's play!\n" + "Diego deals the cards and you get an average hand - you only have a pair of tens. You exchange three cards but only get a five. Diego easily beats you with his three dames. You lose!!\n" + "- Well, lucky me - says Diego with a smile - I guess it's time to pay up, so let's go upstairs to my room so you can start working.\n"); situation.getOptions().add(option); // LOST_SUBMISSION option = new GenericOption(); option.setCondition(checkState(STATE_LOST_SUBMISSION).toString()); option.setGoToSituation("PALOS_TAVERN_CARDPLAYER_SUBMIT"); option.setTimePassed(1 * HOUR); option.setLabel("Damn it... ok, let's get it over with. (Submit)"); situation.getOptions().add(option); option = new GenericOption(); option.setCondition(checkState(STATE_LOST_SUBMISSION) .and() .util() .roll(// ScriptBuilder.NEW().me().getEffectiveStat(PERCEPTION) .toString() + "+20" // , "PALOS_SPOT_MARKED_CARDS").toString()); option.setGoToSituation(ST_EMPTY_RETURN); option.getEffects().add( new Effect(ScriptBuilder.NEW().plot() .set(PLOT_PALOS_TAVERN_CARDPLAYER_ISGONE).toString())); option.setLabel("Hey, those cards are marked! (Perception)"); option.setTextAfter("Looking at the cards you notice that some of them were marked with tiny scratches on their backs. The scratches are not easy to notice, but they're definitely there. \n" + " - Hey, those cards are marked!- you exclaim as you realize you were conned, drawing the attention of some of the other patrons of the taverns. \n" + " - Shhh... - whispers Diego, looking around nervously - Ok, ok, maybe they are. No need to make such a fuss about it, noone here wants trouble. Just... forget the whole thing, you owe me nothing. Now if you'll excuse me, I need to be going.\n" + "That said, Diego leaves the tavern in a hurry, followed by some hostile looks of people who overheard you talking.."); situation.getOptions().add(option); // option = new GenericOption(); checkStates(STATE_WON, STATE_LOST, STATE_NEGOTIATING); option.setGoToSituation(ST_EMPTY_RETURN); option.setIcon("back"); option.setLabel("Need to be going, c'ya!"); option.setTextAfter(" - Need to be going, c'ya!\n - Sure, take care!"); situation.getOptions().add(option); // PALOS_TAVERN_CARDPLAYER_SUBMIT situation = new GenericSituation(); situation.setId("PALOS_TAVERN_CARDPLAYER_SUBMIT"); situation.setText(// "You follow Diego upstairs to his room [TODO]\n"); gameObjects.getSituations().add(situation); situation.getEffects().add( new Effect(ScriptBuilder.NEW().me() .increaseStat(REPUTATION, -2).toString())); situation.getEffects().add( new Effect(ScriptBuilder.NEW().plot() .set(PLOT_PALOS_TAVERN_CARDPLAYER_ISGONE).toString())); gameObjects.getSituations().add(situation); option = new GenericOption(); option.setGoBack(true); option.setIcon("back"); option.setLabel("Go back downstairs"); situation.getOptions().add(option); return gameObjects; } protected void switchState(Effecting effecting, String stateValue) { Effect effect = new Effect(ScriptBuilder.NEW().situation() .setState(STATE, stateValue).toString()); effecting.getEffects().add(effect); } protected ScriptBuilder checkStates(String... states) { ScriptBuilder scriptBuilder = ScriptBuilder.NEW(); for (String state : states) { scriptBuilder = scriptBuilder.situation().getState(STATE) .equalsString(state); } return scriptBuilder; } protected ScriptBuilder checkState(String stateValue) { return ScriptBuilder.NEW().situation().getState(STATE) .equalsString(stateValue); } }
Java
package org.clockworkmages.games.anno1186.generator.sets; import org.clockworkmages.games.anno1186.dao.GameObjectsList; import org.clockworkmages.games.anno1186.generator.GameObjectGenerator; import org.clockworkmages.games.anno1186.model.map.tactical.GameAreaDO; import org.clockworkmages.games.anno1186.model.map.tactical.SimpleTileObject; public class Tiles extends GameObjectGenerator { public String getFileName() { return "tiles"; } @Override public GameObjectsList generate() { GameObjectsList gameObjects = new GameObjectsList(); SimpleTileObject tileObject; tileObject = new SimpleTileObject("g", "tile-chalk", true); gameObjects.getTileObjects().add(tileObject); tileObject = new SimpleTileObject("npc_juan1", "hummie", "PALOS_TAVERN_JUAN"); gameObjects.getTileObjects().add(tileObject); GameAreaDO gameAreaDO = new GameAreaDO(); gameAreaDO.setId("palos_tavern"); gameAreaDO.setX(7); gameAreaDO.setY(6); for (int y = 0; y < gameAreaDO.getY(); y++) { for (int x = 0; x < gameAreaDO.getX(); x++) { gameAreaDO.getTiles().add("g"); } } gameAreaDO.getTiles().remove(7 * 1 - 1 + 2); gameAreaDO.getTiles().add(7 * 1 - 1 + 2, "npc_juan1"); gameObjects.getGameAreas().add(gameAreaDO); return gameObjects; } }
Java
package org.clockworkmages.games.anno1186.generator.sets; public interface TechnicalSituationConstants { public static String ST_EMPTY_RETURN = "EMPTY_RETURN"; }
Java
package org.clockworkmages.games.anno1186.generator.sets; import org.clockworkmages.games.anno1186.DamageConstants; import org.clockworkmages.games.anno1186.TimeConstants; import org.clockworkmages.games.anno1186.dao.GameObjectsList; import org.clockworkmages.games.anno1186.generator.GameObjectGenerator; import org.clockworkmages.games.anno1186.model.character.SkillConstants; import org.clockworkmages.games.anno1186.model.character.StatConstants; import org.clockworkmages.games.anno1186.model.effect.Effect; import org.clockworkmages.games.anno1186.model.item.Item; import org.clockworkmages.games.anno1186.model.item.ItemConstants; import org.clockworkmages.games.anno1186.model.option.GenericOption; import org.clockworkmages.games.anno1186.scripting.tools.EffectBuilder; import org.clockworkmages.games.anno1186.scripting.tools.ScriptBuilder; public class BasicItems extends GameObjectGenerator // implements StatConstants, SkillConstants, TechnicalSituationConstants, TimeConstants, ItemConstants, DamageConstants { public String getFileName() { return "basicItems"; } @Override public GameObjectsList generate() { GameObjectsList gameObjects = new GameObjectsList(); GenericOption useOption; Item item; Effect effect; item = new Item("DAGGER", "Dagger", "A simple dagger, small but sharp"); item.setEquipmentSlotId(EQUIPMENT_SLOT_R_HAND); item.setItemType(ITEM_TYPE_DAGGER); item.setValue(10); effect = new Effect(ScriptBuilder.NEW().me() .modifyDamage(PHYSICAL, 2, 2).toString()); item.getEquippedEffects().add(effect); effect = new Effect(ScriptBuilder.NEW().me() .modifyDerivate(D_ATTACK_STAMINA_COST, 1).toString()); item.getEquippedEffects().add(effect); gameObjects.getItems().add(item); item = new Item("SHORT_SWORD", "Short sword", "A short sword, simple and somewhat rusted in places, but still sharp."); item.setEquipmentSlotId(EQUIPMENT_SLOT_R_HAND); item.setItemType(ITEM_TYPE_SWORD); item.setValue(10); effect = new Effect(ScriptBuilder.NEW().me() .modifyDamage(PHYSICAL, 2, 4).toString()); item.getEquippedEffects().add(effect); effect = new Effect(ScriptBuilder.NEW().me() .modifyDerivate(D_ATTACK_STAMINA_COST, 1).toString()); item.getEquippedEffects().add(effect); gameObjects.getItems().add(item); item = new Item( "HEALING_POTION", "Healing potion", "Magical elixir in a glass bottle. It has the color of honey and a pleasantly refreshing herbal taste."); item.setValue(10); gameObjects.getItems().add(item); useOption = new GenericOption(); useOption.setLabel("Drink"); useOption.getEffects().add( EffectBuilder.NEW().me().removeCurrentItem().compileEffect()); useOption.getEffects().add( EffectBuilder.NEW().me().increaseStat(HEALTH, 50) .compileEffect()); useOption .setTextAfter("You drink the healing potion in a single gulp. Yummie!"); useOption.setConsumesCombatAction(true); useOption.setGoToSituation(ST_EMPTY_RETURN); item.getUseOptions().add(useOption); return gameObjects; } }
Java
package org.clockworkmages.games.anno1186.generator.sets; import org.clockworkmages.games.anno1186.GameTimeService; import org.clockworkmages.games.anno1186.dao.GameObjectsList; import org.clockworkmages.games.anno1186.generator.GameObjectGenerator; import org.clockworkmages.games.anno1186.model.character.SkillConstants; import org.clockworkmages.games.anno1186.model.character.StatConstants; import org.clockworkmages.games.anno1186.model.option.GenericOption; import org.clockworkmages.games.anno1186.model.situation.GenericSituation; import org.clockworkmages.games.anno1186.scripting.tools.ScriptBuilder; import org.clockworkmages.games.anno1186.scripting.tools.TextBuilder; public class Palos extends GameObjectGenerator // implements StatConstants, SkillConstants, TechnicalSituationConstants { public String getFileName() { return "palos"; } @Override public GameObjectsList generate() { GameObjectsList gameObjects = new GameObjectsList(); GenericOption option = new GenericOption(); GenericSituation situation = new GenericSituation(); situation = new GenericSituation(); situation.setClearScreen(true); situation.setId("PALOS_TAVERN"); situation.setText("You are in the Mermaid's Luck tavern in Palos ."); gameObjects.getSituations().add(situation); option = new GenericOption(); option.setLabel("Innkeeper"); option.setIcon("talk"); option.setGoToSituation("PALOS_INNKEEPER"); situation.getOptions().add(option); option = new GenericOption(); option.setLabel("Go to your room (Sleep until morning)"); option.setIcon("sleep"); option.setTimePassed(8 * GameTimeService.HOUR); option.setCondition("!" + ScriptBuilder.UTIL().isDay().and().plot() .is("PALOS_JOINED_THE_CREW")); option.setTextAfter("You go to your room and fall asleep almost immediately. When you awake, it's early morning."); situation.getOptions().add(option); option = new GenericOption(); option.setLabel("Go out"); option.setIcon("out"); option.setTimePassed(20 * GameTimeService.SECOND); option.setGoToSituation("PALOS_MARKET"); // option.setCondition("!" + ScriptBuilder.UTIL().isDay()); situation.getOptions().add(option); // option = new GenericOption(); // option.setOr(true); // option.setLabel("Go out"); // option.setIcon("out"); // option.setTimePassed(20 * GameTimeService.SECOND); // option.setGoToSituation("PALOS_MARKET_DAY"); // situation.getOptions().add(option); situation = new GenericSituation(); situation.setClearScreen(true); situation.setId("PALOS_MARKET"); situation .setText("You are in the dockside market in western part of Palos.\n" + TextBuilder .NEW() .iff() .util() .isDay() .then("It's a warm autumn day and there's a lot of people around you, buying and selling fish as well as exotic goods imported from faraway lands") .elsee("It is night already and there's not a sould to be seen here at this late hour.") .asText()); gameObjects.getSituations().add(situation); option = new GenericOption(); option.setLabel("Palos docks"); option.setIcon("west"); option.setTimePassed(20 * GameTimeService.SECOND); option.setGoToSituation("PALOS_DOCKS"); situation.getOptions().add(option); option = new GenericOption(); option.setLabel("Dark alley"); option.setIcon("south"); option.setTimePassed(20 * GameTimeService.SECOND); option.setGoToSituation("PALOS_ALLEY"); situation.getOptions().add(option); option = new GenericOption(); option.setLabel("Mermaid's Luck tavern"); option.setIcon("in"); option.setTimePassed(20 * GameTimeService.SECOND); option.setGoToSituation("PALOS_TAVERN"); situation.getOptions().add(option); situation = new GenericSituation(); situation.setClearScreen(true); situation.setId("PALOS_ALLEY"); situation .setText("You are in the dockside market in western part of Palos.\n" + TextBuilder .NEW() .iff() .util() .isDay() .then("It's a warm autumn day and there's a lot of people around you, buying and selling fish as well as exotic goods imported from faraway lands") .elsee("It is night already and there's not a sould to be seen here at this late hour.") .asText()); gameObjects.getSituations().add(situation); option = new GenericOption(); option.setLabel("Palos market"); option.setIcon("north"); option.setTimePassed(20 * GameTimeService.SECOND); option.setGoToSituation("PALOS_MARKET"); situation.getOptions().add(option); situation = new GenericSituation(); situation.setClearScreen(true); situation.setId("PALOS_DOCKS"); situation .setText("You are in the dockside market in western part of Palos.\n" + TextBuilder .NEW() .iff() .util() .isDay() .then("It's a warm autumn day and there's a lot of people around you, buying and selling fish as well as exotic goods imported from faraway lands") .elsee("It is night already and there's not a sould to be seen here at this late hour.") .asText()); gameObjects.getSituations().add(situation); option = new GenericOption(); option.setLabel("Palos market"); option.setIcon("east"); option.setTimePassed(20 * GameTimeService.SECOND); option.setGoToSituation("PALOS_MARKET"); situation.getOptions().add(option); // // TODO // talking with Juan de la cosa: // -the expedition // --crew // --Cristobal Colon // --duration of the journey // -pay // --(Speech) pay in advance // -(pickpocket) // -Agree! // // -Tavern's common room // --innkeeper // --go to your room (Sleep until morning) // --cheap whore // -Dockside market of Palos // -Dark alley // --Shady character // ---Fight! (reputation>5) // ---Trade (reputation<5): brass knuckles, sharp dagger, wolfsbane // extract return gameObjects; } }
Java
package org.clockworkmages.games.anno1186.generator.sets; import org.clockworkmages.games.anno1186.dao.GameObjectsList; import org.clockworkmages.games.anno1186.generator.GameObjectGenerator; import org.clockworkmages.games.anno1186.model.character.GenderConstants; import org.clockworkmages.games.anno1186.model.character.StatConstants; import org.clockworkmages.games.anno1186.model.effect.Effect; import org.clockworkmages.games.anno1186.model.option.GenericOption; import org.clockworkmages.games.anno1186.model.situation.GenericSituation; import org.clockworkmages.games.anno1186.scripting.tools.EffectBuilder; import org.clockworkmages.games.anno1186.scripting.tools.ScriptBuilder; public class CharacterCreation extends GameObjectGenerator // implements StatConstants, GenderConstants { public String getFileName() { return "characterCreation"; } @Override public GameObjectsList generate() { GameObjectsList gameObjects = new GameObjectsList(); GenericOption option = new GenericOption(); GenericSituation situation = new GenericSituation(); String PLOT_BIRTH = "BIRTH"; gameObjects.setGameStartSituation("SCC_INTRO1"); // situation = new GenericSituation(); situation.setId("SCC_INTRO1"); situation.setText("{f:large}I{f}t is the year 1492."); gameObjects.getSituations().add(situation); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_BIRTH"); option.setLabel("Next"); situation.getOptions().add(option); situation = new GenericSituation(); situation.setId("SCC_CHOOSE_BIRTH"); situation .setText(" But all those events have taken place far away and we don't need to worry about them for the time being - they are of little concern for where this story begins.\n" + // " This story, it begins in the city of Palos located on the western coast of the Kingdom of Spain.\n" + // "\n" + // " You were born [...]"); situation.getEffects().add( EffectBuilder.NEW().me().increaseStat(STRENGTH, 20) .compileEffect()); situation.getEffects().add( EffectBuilder.NEW().me().increaseStat(ENDURANCE, 20) .compileEffect()); situation.getEffects().add( EffectBuilder.NEW().me().increaseStat(AGILITY, 20) .compileEffect()); situation.getEffects().add( EffectBuilder.NEW().me().increaseStat(PERCEPTION, 20) .compileEffect()); situation.getEffects().add( EffectBuilder.NEW().me().increaseStat(INTELLIGENCE, 20) .compileEffect()); situation.getEffects().add( EffectBuilder.NEW().me().increaseStat(WILLPOWER, 20) .compileEffect()); situation.getEffects().add( EffectBuilder.NEW().me().increaseStat(CHARM, 20) .compileEffect()); situation.getEffects().add( EffectBuilder.NEW().me().increaseStat(FATE, 4).compileEffect()); situation.getEffects().add( EffectBuilder.NEW().me().increaseStat(MAX_FATE, 4) .compileEffect()); situation.getEffects().add( EffectBuilder.NEW().me().gainExperience(180).compileEffect()); gameObjects.getSituations().add(situation); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_TALENT"); option.setLabel("...a daughter of poor peasants..."); option.setTextAfter("in a poor village in western Spain, as a third daughter in a family of poor peasants living of the land."); option.getEffects().add( EffectBuilder.me().setGender(FEMALE).compileEffect()); option.getEffects().add(new Effect("plot.set('BIRTH','PEASANT')")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_TALENT"); option.setLabel("...a son of poor peasants..."); option.setTextAfter("in a poor village in western Spain, as a third son in a family of poor peasants living of the land."); option.getEffects().add( EffectBuilder.me().setGender(MALE).compileEffect()); option.getEffects().add(new Effect("plot.set('BIRTH','PEASANT')")); option.setIcon("up"); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_TALENT"); option.setLabel("...fourth son of a noble lord."); option.setTextAfter("as the fourth son of a wealthy noble. Your life was comfortable but your future - a younger son with no chance to inherit the family fortune - has always ben somewhat vague."); option.getEffects().add( EffectBuilder.me().setGender(MALE).compileEffect()); option.getEffects().add( EffectBuilder.me().equipItemNoInv("DAGGER").compileEffect()); option.getEffects().add( EffectBuilder.me().equipItemNoInv("SHORT_SWORD") .compileEffect()); option.getEffects().add( EffectBuilder.me().addItem("HEALING_POTION").compileEffect()); option.getEffects().add(new Effect("plot.set('BIRTH','NOBLE')")); situation.getOptions().add(option); // option = new GenericOption(); // option.setGoToSituation("SCC_CHOOSE_TALENT"); // option.setLabel("...younger daughter in a noble family."); // option.setTextAfter("as the second daughter in a noble and respected family. Your youngest years were comfortable, if a tad boring - the education of young noble girls in these days revolves mostly aroud embroidery, playing a flute and - if you're lucky - reading romances."); // option.getEffects().add(new Effect("me.setStat('GENDER',2)")); // option.getEffects().add(new Effect("plot.set('BIRTH','NOBLE')")); // option.getEffects().add(new // Effect("me.increaseStat('REPUTATION',5)")); // situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_TALENT"); option.setLabel("...daughter of a whore."); option.setTextAfter("as a daughter of a... uh... courtisan. Not a typical start for a heroine, true, but one does not choose one's parents, and at least your childhood - spent in the dirty streets of Palos' poorest quarter - was an educative one."); option.getEffects().add( EffectBuilder.me().setGender(FEMALE).compileEffect()); option.getEffects().add(new Effect("plot.set('BIRTH','SCUM')")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_TALENT"); option.setLabel("...son of a whore."); option.setTextAfter("as a son of a... uh... courtisan. Not a typical start for a hero, true, but one does not choose one's parents, and at least your childhood - spent in the dirty streets of Palos' poorest quarter - was an educative one."); option.getEffects().add( EffectBuilder.me().setGender(MALE).compileEffect()); option.getEffects().add(new Effect("plot.set('BIRTH','SCUM')")); situation.getOptions().add(option); // 2. Gift situation = new GenericSituation(); situation.setClearScreen(false); situation.setId("SCC_CHOOSE_TALENT"); situation.setText("In your childhood you friends would call you [...]"); gameObjects.getSituations().add(situation); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setLabel("\"Bull\"."); option.setTextAfter("\"Bull\", because you were strong as one."); option.getEffects().add(new Effect("me.increaseStat('STRENGTH',15)")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setLabel("\"Bruiser\"."); option.setTextAfter("\"Bruiser\", because you were always eager to get into a fight, and ligning-quick with your fists."); option.getEffects().add(new Effect("me.increaseSkill('UNARMED',2)")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setLabel("\"Rock\"."); option.setTextAfter("\"Rock\", because of how tough you've always been."); option.getEffects().add(new Effect("me.increaseStat('ENDURANCE',15)")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setLabel("\"Smartass\"."); option.setTextAfter("\"Smartass\", because you were smart and never ashamed to show it, and they were all just jealous. Think of it, you didn't have all that many friends."); option.getEffects().add( new Effect("me.increaseStat('INTELLIGENCE',10)")); option.getEffects().add(new Effect("me.increaseSkill('HISTORY',1)")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setLabel("\"Hawkeye\"."); option.setTextAfter("\"Hawkeye\", because of your sharp senses."); option.getEffects().add(new Effect("me.increaseStat('PERCEPTION',15)")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setLabel("\"Ferret\"."); option.setTextAfter("\"Ferret\", because of your agility and speed that let you get out of almost any trouble."); option.getEffects().add(new Effect("me.increaseStat('AGILITY',15)")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setCondition("plot.get('BIRTH')=='NOBLE' && me.isMale()"); option.setLabel("\"Golden Boy\"."); option.setTextAfter("\"Golden Boy\", because of your pretty face and natural charm."); option.getEffects().add(new Effect("me.increaseStat('CHARM',10)")); option.getEffects().add(new Effect("me.increaseSkill('SPEECH',1)")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setCondition("plot.get('BIRTH')=='NOBLE' && me.getStat('GENDER')==2"); option.setLabel("\"Princess\"."); option.setTextAfter("\"Princess\", because of your pretty face and natural charm."); option.getEffects().add(new Effect("me.increaseStat('CHARM',10)")); option.getEffects().add(new Effect("me.increaseSkill('SPEECH',1)")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setCondition("plot.get('BIRTH')!='NOBLE' && me.isMale()"); option.setLabel("\"Hercules\"."); option.setTextAfter("\"Hercules\", because of your great looks and muscular body."); option.getEffects().add(new Effect("me.increaseStat('STRENGTH',5)")); option.getEffects().add(new Effect("me.increaseStat('CHARM',5)")); option.getEffects().add( new Effect("me.increaseSkill('BODYBUILDING',1)")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setCondition("plot.get('BIRTH')=='SCUM'"); option.setLabel("\"Shadow\"."); option.setTextAfter("\"Shadow\", because of your skill at hiding and moving silently."); option.getEffects().add(new Effect("me.increaseStat('AGILITY',5)")); option.getEffects().add(new Effect("me.increaseSkill('STEALTH',1)")); situation.getOptions().add(option); option = new GenericOption(); option.setGoToSituation("SCC_CHOOSE_YOUTH"); option.setCondition("plot.get('BIRTH')=='SCUM'"); option.setLabel("\"Imp\"."); option.setTextAfter("\"Imp\", because of that strange deformity of your flesh you had since you were born that almost looks demonic in nature. Who knows, perhaps it even is - everyone knows that devils and monsters exist, and you never knew who your father was."); option.getEffects().add(new Effect("me.increaseStat('CORRUPTION',5)")); option.getEffects().add(new Effect("me.addRandomMutation()")); situation.getOptions().add(option); // 3. Youth: situation = new GenericSituation(); situation.setClearScreen(false); situation.setId("SCC_CHOOSE_YOUTH"); situation.setText("You spent your youth [...]"); gameObjects.getSituations().add(situation); // - peasant, smith option = new GenericOption(); option.setGoToSituation("SCC_END"); option.setCondition("plot.get('BIRTH')=='PEASANT' && me.isMale()==1"); option.setLabel("...as an apprentice to the village's blacksmith."); option.setTextAfter("as an apprentice to the village's blacksmith, which gave you both a respected profession and a bulging biceps. In time you moved to the city of Palos, where your skill got you an apprenticeship at the workshop of a local goldsmith.\n And it was in Palos that your adventure started, on the evening of August 2nd a.D. 1492, as you were having a supper in the common room of a dockside tavern where you were renting a room."); option.getEffects().add(new Effect("me.increaseStat('STRENGTH',5)")); option.getEffects().add(new Effect("me.increaseStat('ENDURANCE',5)")); option.getEffects().add(new Effect("me.increaseSkill('SMITHING',1)")); option.getEffects().add(new Effect("me.increaseSkill('BLUDGEON',2)")); option.getEffects().add(new Effect("plot.set('YOUTH','SMITH')")); situation.getOptions().add(option); // - peasant, M/F, brigand option = new GenericOption(); option.setGoToSituation("SCC_END"); option.setCondition("plot.get('BIRTH')=='PEASANT'"); option.setLabel("...robbing${if me.isMale()} and raping${fi}."); option.setTextAfter("as a brigand. Sadly, the poverty left you little choice - it was either that or starve to death, so at the age of 13, when you were old enough to hold a bow, you joined up with a bunch of local men and started robbing the merchants traveling the nearby roads. Unsurprisingly, after a few years your band was tracked down by the royal guardsmen and almost all your friends were imprisoned or killed. You were the only one who managed to escape, but you were forced to run away from your home. That's how you ended up in Palos - a desperate ${if me.getStat('GENDER')==2}wo${fi}man and a wanted criminal looking for a ship on which to escape the people chasing you.\n And it was in Palos that your adventure started, on the evening of August 2nd a.D. 1492, as you were having a supper in the common room of a cheap dockside tavern where you rented a room for a night."); option.getEffects().add(new Effect("me.increaseStat('STRENGTH',5)")); option.getEffects().add(new Effect("me.increaseStat('ENDURANCE',5)")); option.getEffects().add(new Effect("me.increaseSkill('AXE',2)")); option.getEffects().add(new Effect("me.increaseSkill('BLUDGEON',2)")); option.getEffects().add(new Effect("plot.set('YOUTH','BRIGAND')")); option.getEffects().add( new Effect("me.increaseStat('STATUS_CRIMINALS',5)")); situation.getOptions().add(option); // - peasant, M/F, hunter option = new GenericOption(); option.setGoToSituation("SCC_END"); option.setCondition("plot.get('BIRTH')=='PEASANT' && me.isMale()"); option.setLabel("...hunting in the woods to help feed your family."); option.setTextAfter("hunting in the woodstrying to help feed you family. Well ok, it was actually poaching, but at the end of the day what matters is that you learned how to survive in the wild, and even managed to bring a rabbit or two home for supper. Unfortunately, your activities drew the attention of a local noble and you had to flee your home village out of fear for being tried for poaching. That's how you ended up in Palos, a stranger in an unfamiliar place with hardly any money on you. looking for a ship on which to escape the people chasing you.\n And it was in Palos that your adventure started, on the evening of August 2nd a.D. 1492, as you were having a supper in the common room of a cheap dockside tavern where you rented a room for a night."); option.getEffects().add(new Effect("me.increaseStat('PERCEPTION',5)")); option.getEffects().add(new Effect("me.increaseStat('AGILITY',5)")); option.getEffects().add(new Effect("me.increaseSkill('SURVIVAL',1)")); option.getEffects().add(new Effect("plot.set('YOUTH','HUNTER')")); situation.getOptions().add(option); // - noble, priest option = new GenericOption(); option.setGoToSituation("SCC_END"); option.setCondition("plot.get('BIRTH')=='NOBLE' && me.isMale()"); option.setLabel("...as a novice in a monastery."); option.setTextAfter("in a local monastery, studying to become a priest, which was a perfectly common career path for a third son of a noble family. This may not sound like fun, but your family figured out that securing you a position in the omnipotent Church would benefit everyone best.\n As your novicehood was nearing an end, your mentor - prelate Gonzalo - approached you with an intriguing offer. He spoke to you of a sea expedition funded by the Spanish crown, an expedition whose purpose it was to discover uncharted lands in the far west, beyond the great ocean. An expedition that must - in prelate's oppinion - have a representative of the Holy Faith amongst its numbert, so that whatever lands it would discover could be claimed for the Church; and whatever wild tribes it would encounter could be converted to the Faith.\n And you - a young and devoted priest - would make a perfect candidate.\n The prelate did not pressure you much, but he asked you to consider the notion and meet with the expedition's leader, one Juan de la Cosa. That is how you ended up in Palos on the evening of August 2nd a.D. 1492, having a modest supper in a dockside tavern where master Cosa was supposed to meet with you."); option.getEffects() .add(new Effect("me.increaseStat('INTELLIGENCE',5)")); option.getEffects().add(new Effect("me.increaseStat('WILLPOWER',5)")); option.getEffects().add(new Effect("me.increaseSkill('MEDITATION',1)")); option.getEffects().add(new Effect("me.increaseSkill('THEOLOGY',1)")); option.getEffects().add(new Effect("plot.set('YOUTH','NOVICE')")); situation.getOptions().add(option); // - noble, officer option = new GenericOption(); option.setGoToSituation("SCC_END"); option.setCondition("plot.get('BIRTH')=='NOBLE' && me.isMale()"); option.setLabel("...as a navy officer."); option.setTextAfter("in a navy academy and then aboard a ship, serving first as a servant and then as a younger officer aboard a navy ship commanded by a friend of your father. You learned a lot about running a ship and commanding a crew, you also got some combat training.\n At the end of your education your superiors sent you a curious request - to meet with one Juan de la Cosa, a merchant and ship owner, and accompany him on the mission that the man was undertaking in service to the Spanish Crown.\nThat is how you ended up in Palos on the evening of August 2nd a.D. 1492, having a modest supper in a dockside tavern where master Cosa was supposed to meet with you."); option.getEffects() .add(new Effect("me.increaseStat('INTELLIGENCE',5)")); option.getEffects().add(new Effect("me.increaseStat('STRENGTH',5)")); option.getEffects().add(new Effect("me.increaseSkill('SPEECH',1)")); option.getEffects().add(new Effect("me.increaseSkill('SWORD',2)")); option.getEffects().add(new Effect("plot.set('YOUTH','OFFICER')")); option.getEffects().add(new Effect("me.increaseStat('REPUTATION',5)")); situation.getOptions().add(option); // - noble, academic option = new GenericOption(); option.setGoToSituation("SCC_END"); option.setCondition("plot.get('BIRTH')=='NOBLE' && me.isMale()"); option.setLabel("...studying at a university."); option.setTextAfter("studying at the renowned university of Toledo where your parents sent you after you proved to be an extraoridinarily intelligent kid. Or maybe you were just being annoying and they wanted to send you somewhere far away... Well never mind, at any rate you got as good an education as anyone could hope for.\n At the end of your education your father sent you a curious request - to meet with one Juan de la Cosa, a merchant, ship owner and a friend of your family, and accompany him on the mission that the man was undertaking in service to the Spanish Crown as his personal secretary and scribe.\n That is how you ended up in Palos on the evening of August 2nd a.D. 1492, having a modest supper in a dockside tavern where master Cosa was supposed to meet with you."); option.getEffects().add( new Effect("me.increaseStat('INTELLIGENCE',10)")); option.getEffects().add(new Effect("me.increaseSkill('SPEECH',1)")); option.getEffects().add(new Effect("me.increaseSkill('THEOLOGY',1)")); option.getEffects().add(new Effect("me.increaseSkill('HISTORY',2)")); option.getEffects().add(new Effect("plot.set('YOUTH','ACADEMIC')")); situation.getOptions().add(option); // - scum, thief option = new GenericOption(); option.setGoToSituation("SCC_END"); option.setCondition("plot.get('BIRTH')=='SCUM'"); option.setLabel("...robbing and pickpocketing."); option.setTextAfter("robbing the rich and supporting the poor, especially yourself. You actually got yourself quite a renown in Palos' underworld and were counted amoung the most agile pickpockets, and best burglars. Still, it was a dangerous life and recently the local guards have taken one of your fences prisoner and it's clearly just a matter of time before they torture your name out of him, and come for you next. Which means you need to get out of Palos, maybe on some ship, one that would get away from here, quick and far.\n And so it was that your adventure started, on the evening of August 2nd a.D. 1492, as you were having a supper in the common room of a cheap dockside tavern where you were renting a room for a night."); option.getEffects().add(new Effect("me.increaseStat('AGILITY',5)")); option.getEffects().add(new Effect("me.increaseStat('PERCEPTION',5)")); option.getEffects().add(new Effect("me.increaseSkill('STEALTH',1)")); option.getEffects().add(new Effect("me.increaseSkill('DAGGER',1)")); option.getEffects().add(new Effect("plot.set('YOUTH','THIEF')")); option.getEffects().add( new Effect("me.increaseStat('STATUS_CRIMINALS',5)")); situation.getOptions().add(option); // - scum, gangster option = new GenericOption(); option.setGoToSituation("SCC_END"); option.setCondition("plot.get('BIRTH')=='SCUM'"); option.setLabel("...in a gang."); option.setTextAfter("as a member of a local gang. It was a brutal life, especially at a astart, but in time it made you strong, and people learned to fear and respect you. Unfortunately, the city guard has been putting much effort into tracking your gang down recently, and some of your friends were already caught and hanged. Which means you need to get out of Palos, and you need to get away from here quick and far.\n" + " And so it was that your adventure started, on the evening of August 2nd a.D. 1492, as you were having a supper in the common room of a cheap dockside tavern where you were renting a room for a night."); option.getEffects().add(new Effect("me.increaseStat('STRENGTH',5)")); option.getEffects().add(new Effect("me.increaseStat('ENDURANCE',5)")); option.getEffects().add(new Effect("me.increaseSkill('DAGGER',1)")); option.getEffects().add(new Effect("me.increaseSkill('BLUDGEON',2)")); option.getEffects().add( new Effect("me.increaseSkill('INTERROGATION',2)")); option.getEffects().add(new Effect("plot.set('YOUTH','GANGSTER')")); option.getEffects().add( new Effect("me.increaseStat('STATUS_CRIMINALS',5)")); situation.getOptions().add(option); // - scum, whore option = new GenericOption(); option.setGoToSituation("SCC_END"); option.setCondition("plot.get('BIRTH')=='SCUM'"); option.setLabel("...as a whore."); option.setTextAfter("as a ${if me.isMale()}male ${fi}whore. Nothing much more to say about it really. I mean, if anyone offered you to become the ${if me.isMale()}king${else}queen${fi} of England instead the you'd accept. But noone did. And everyone needs to eat, so you needed the money. It was no easy life though, and at the age of 18 you decided you can't go on like that anymore, so you talked to some people at the docks and managed to get yourself a job as a cabin ${if me.isMale()}boy${else}wench${fi} on a merchant vessel named Santa Maria sailing out for India.\n" + " And so it was that your adventure started, on the evening of August 2nd a.D. 1492, as you were having a supper in the common room of a cheap dockside tavern where you were supposed to meet with your new employee, one Juan de la Cosa."); option.getEffects().add(new Effect("me.increaseStat('CHARM',10)")); option.getEffects().add(new Effect("me.increaseSkill('BARTER',1)")); option.getEffects().add(new Effect("me.increaseSkill('SPEECH',1)")); option.getEffects().add(new Effect("plot.set('YOUTH','WHORE')")); option.getEffects().add(new Effect("me.increaseStat('REPUTATION',-5)")); situation.getOptions().add(option); // - peasant,F, herbalist option = new GenericOption(); option.setGoToSituation("SCC_END"); option.setCondition(ScriptBuilder.NEW().plot().get(PLOT_BIRTH) .equalsString("PEASANT").and().not().me().isMale().toString()); option.setLabel("...as an apprentice to a local midwife."); option.setTextAfter("as an apprentice to a local midwife, learning how to gather and mix herbs, assist during a birth or mend broken bones. It gave you purpose, but somehow you always felt you were destined for something more... adventurous and meaningful. So one day you decided you'd travel to Palos and see if a skilled medic - which you consider yourself to be, regardless of what the rest of the world might think - can find some job there.\n " + " And so it was that your adventure started, on the evening of August 2nd a.D. 1492, as you were having a supper in the common room of a cheap dockside tavern where you rented a room for a night."); option.getEffects() .add(new Effect("me.increaseStat('INTELLIGENCE',5)")); option.getEffects().add(new Effect("me.increaseStat('ENDURANCE',5)")); option.getEffects().add(new Effect("me.increaseSkill('ALCHEMY',1)")); option.getEffects().add(new Effect("me.increaseSkill('SPEECH',1)")); option.getEffects().add(new Effect("plot.set('YOUTH','HERBALIST')")); situation.getOptions().add(option); situation = new GenericSituation(); situation.setClearScreen(false); situation.setId("SCC_END"); situation.getEffects().add( new Effect("me.increaseStat('" + ENDURANCE + "',15)")); gameObjects.getSituations().add(situation); option = new GenericOption(); option.setLabel("Next"); option.setGoToSituation("PALOS_TAVERN_JUAN"); option.getEffects().add(new Effect("me.restoreAll()")); option.getEffects().add( EffectBuilder.NEW().util().goToLocation("palos_tavern", 2, 2) .compileEffect()); situation.getOptions().add(option); return gameObjects; } }
Java
package org.clockworkmages.games.anno1186.generator; import java.util.List; import org.clockworkmages.games.anno1186.dao.GameObjectsList; import org.clockworkmages.games.anno1186.model.character.NonPlayerCharacter; import org.clockworkmages.games.anno1186.model.option.GenericOption; import org.clockworkmages.games.anno1186.scripting.tools.EffectBuilder; public abstract class GameObjectGenerator { public abstract GameObjectsList generate(); protected void addDefaultEffectsToCombatOptions(GameObjectsList gameObjects) { for (NonPlayerCharacter enemy : gameObjects.getNpcs()) { for (List<GenericOption> options : new List[] { enemy.getVictoriousOptions(), enemy.getSubduingOptions(), enemy.getDefeatedOptions(), enemy.getSubduedOptions() }) { for (GenericOption option0 : options) { option0.getEffects().add( EffectBuilder.NEW().me().healthAtLeast1() .compileEffect()); } } } } public abstract String getFileName(); }
Java
package org.fantasmerica.model.character; import java.util.Map; import org.clockworkmages.games.anno1186.model.character.Stat; import org.clockworkmages.games.anno1186.model.item.EquipmentSlot; import org.fantasmerica.model.trigger.GameTrigger; import org.fantasmerica.model.trigger.TriggerType; public class Combatant { Map<Stat, Double> baseStats; Map<Stat, Double> modifiedStats; Map<DerivateStat, Double> derivateStats; Map<TriggerType, GameTrigger> conditions; Gender gender; Map<EquipmentSlot, EquippableItem> equippedItems; }
Java
package org.fantasmerica.model.character; import org.fantasmerica.model.trigger.GameTrigger; public class MonsterTemplateDto { String image; List<GameTrigger> triggers; List<String> lootListIds; GenericSituationDto surrenderSituation; GenericSituationDto victorySituation; GenericSituationDto defeatSituation; }
Java
package org.fantasmerica.model; public class Event { }
Java
package org.fantasmerica.model; public enum DamageType { }
Java
package org.fantasmerica.model.trigger; import java.util.Map; import org.fantasmerica.model.DamageType; import org.fantasmerica.model.character.Combatant; public abstract class OnSuccesfulHitTrigger extends GameTrigger { public abstract void execute(Combatant me, Combatant enemy, Map<DamageType, Double> damageCaused, boolean isCriticalHit); }
Java
package org.fantasmerica.model.trigger; import org.fantasmerica.model.character.Combatant; public abstract class BeginningOfTurnTrigger extends GameTrigger { public abstract void execute(Combatant me, Combatant enemy); }
Java
package org.fantasmerica.model.trigger; public abstract class GameTrigger { private boolean removeAfterCombat = false; protected void setRemoveAfterCombat(boolean removeAfterCombat) { this.removeAfterCombat = removeAfterCombat; } public boolean isRemoveAfterCombat() { return removeAfterCombat; } }
Java
package org.fantasmerica.model.trigger; import org.fantasmerica.model.DamageType; import org.fantasmerica.model.character.Combatant; public class PoisonedTrigger extends BeginningOfTurnTrigger { double damagePerTurn; int triggerDuration; public PoisonedTrigger(double damagePerTurn, int triggerDuration) { setRemoveAfterCombat(true); this.damagePerTurn = damagePerTurn; this.triggerDuration = triggerDuration; } @Override public void execute(Combatant me, Combatant enemy) { // TODO Auto-generated method stub me.causeDamage(damagePerTurn, DamageType.POISON); if (--triggerDuration == 1) { me.removeTrigger(this); } } }
Java
package org.fantasmerica.model.trigger; public enum TriggerType { STAT_RECOUNT,SUCCESFUL_HIT, GOT_HIT }
Java
package org.fantasmerica.model.trigger; import java.util.Map; import org.fantasmerica.model.DamageType; import org.fantasmerica.model.character.Combatant; public class PoisoningStrikeTrigger extends OnSuccesfulHitTrigger { double damagePerTurn; int triggerDuration; int poisonDuration; private PoisoningStrikeTrigger(double damagePerTurn, int triggerDuration, int poisonDuration) { if (triggerDuration != MagicNumbers.PERMANENT) { setRemoveAfterCombat(true); } this.damagePerTurn = damagePerTurn; this.triggerDuration = triggerDuration; this.poisonDuration = poisonDuration; } @Override public void execute(Combatant me, Combatant enemy, Map<DamageType, Double> damageCaused, boolean isCriticalHit) { enemy.registerTrigger(new PoisonedTrigger(damagePerTurn, poisonDuration)); if (--triggerDuration == 0) { me.removeTrigger(this); } } }
Java
package org.fantasmerica.model.situation; import org.clockworkmages.games.anno1186.model.effect.Effect; public class Situation { String image; String text; List<Effect> effects; List<Option> options; }
Java
package org.fantasmerica.model.situation; public class EventDo extends SituationDo { List<LocationType> locationTypes; List<String> conditions; }
Java
package org.fantasmerica.gui; import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLayeredPane; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class GameApplication { /** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. */ public static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("Fantasmerica"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Container pane = frame.getContentPane(); // final GamePanel gamePanel = new GamePanel(); // frame.add(gamePanel); JLayeredPane layeredPane = new JLayeredPane(); layeredPane.setPreferredSize(new Dimension(300, 310)); layeredPane.setBorder(BorderFactory .createTitledBorder("Move the Mouse to Move Duke")); // layeredPane.addMouseMotionListener(new MouseMotionAdapter() { // } frame.add(layeredPane); // Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { try { // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (InstantiationException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } /* Turn off metal's use bold fonts */ UIManager.put("swing.boldMetal", Boolean.FALSE); // Schedule a job for the event dispatch thread: // creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
Java
package org.clockworkmages.games.anno1186; import java.util.ArrayList; import java.util.List; import org.clockworkmages.games.anno1186.model.option.Option; import org.clockworkmages.games.anno1186.scripting.ScriptingService; public class OptionUtil { public static List<Option> getAvailableOptions(List<Option> options) { ScriptingService scriptingService = GameBeansContext .getBean(ScriptingService.class); List<Option> availableOptions = new ArrayList<Option>(); boolean orGroupAlreadyEvaluated = false; for (Option option : options) { String condition = option.getCondition(); boolean isOrOption = option.isOr(); if (isOrOption && orGroupAlreadyEvaluated) { continue; } if (condition == null || scriptingService.conditionIsMet(condition)) { availableOptions.add(option); orGroupAlreadyEvaluated = true; } else { orGroupAlreadyEvaluated = false; } } return availableOptions; } }
Java
package org.clockworkmages.games.anno1186.model.character; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import org.clockworkmages.games.anno1186.model.GameObject; import org.clockworkmages.games.anno1186.model.effect.Effect; public class Skill extends GameObject { private String name; private List<Effect> effects = new ArrayList<Effect>(); /** * Stats that are taken into consideration when calculating the chance of * the use of thiss skill to succeed. */ private List<String> rulingStats = new ArrayList<String>(); /** * Number by which the value of ruling stats is multiplied when adding it to * the calculation of skill tests's success chance. By default equals one * for common skills (Speech, Survival), but can be less for skills that * require expertise specific (lockpicking, theology). */ private double statModifier = 1; public Skill() { } public Skill(String id, String name, double statModifier, String... rulingStatIds) { this(id, name, rulingStatIds); this.statModifier = statModifier; } public Skill(String id, String name, String... rulingStatIds) { super(id); this.name = name; for (String statId : rulingStatIds) { this.rulingStats.add(statId); } } public String getName() { return name; } public void setName(String name) { this.name = name; } @XmlElement(name = "effect") public List<Effect> getEffects() { return effects; } public void setEffects(List<Effect> effects) { this.effects = effects; } @XmlElement(name = "stats") public List<String> getRulingStats() { return rulingStats; } public void setRulingStats(List<String> rulingStats) { this.rulingStats = rulingStats; } @XmlAttribute(name = "statModifier") public double getStatModifier() { return statModifier; } public void setStatModifier(double statModifie) { this.statModifier = statModifie; } }
Java
package org.clockworkmages.games.anno1186.model.character; public interface StatConstants { String STRENGTH = "STRENGTH", ENDURANCE = "ENDURANCE", AGILITY = "AGILITY", PERCEPTION = "PERCEPTION", INTELLIGENCE = "INTELLIGENCE", WILLPOWER = "WILLPOWER", CHARM = "CHARM", // HEALTH = "HEALTH", STAMINA = "STAMINA", FATE = "FATE", // MAX_FATE = "MAX_FATE", // D_ACCURACY = "ACCURACY", D_EVASION = "EVASION", // D_EXPERIENCE_MODIFIER = "EXPERIENCE_MODIFIER", D_ATTACK_STAMINA_COST = "ATTACK_STAMINA_COST", // // D_MAX_HEALTH = "MAX_HEALTH", D_MAX_STAMINA = "MAX_STAMINA", // REPUTATION = "REPUTATION", VIRTUE = "VIRTUE", // SPELL_COST_REDUCTION = "SPELL_COST_REDUCTION"; }
Java
package org.clockworkmages.games.anno1186.model.character; public interface GenderConstants { public static final int MALE = 1, FEMALE = 2, NEUTRUM = 0; }
Java
package org.clockworkmages.games.anno1186.model.character; import org.clockworkmages.games.anno1186.model.GameObject; public class Stat extends GameObject { private String name; private boolean socialStatus; public Stat() { } public Stat(String id, String name) { super(id); this.name = name; } public Stat(String id, String name, boolean socialStatus) { this(id, name); this.socialStatus = socialStatus; } public String getName() { return name; } public void setName(String name) { this.name = name; } public boolean isSocialStatus() { return socialStatus; } public void setSocialStatus(boolean socialStatus) { this.socialStatus = socialStatus; } }
Java
package org.clockworkmages.games.anno1186.model.character; //TODO can be moved to XML. public enum IncapacitatedState { /** * Must pass an Endurance test. */ STUNNED(StatConstants.ENDURANCE, "You are stunned and cannot take any actions.", "Recover", "You manage to recover.", "You fail to recover."), /** * Must pass a * Willpower test. */ CHARMED(StatConstants.WILLPOWER, "You are charmed and cannot control your actions.", "Resist the spell", "You manage to break the spell and regain control of your mind.", "You fail to resist the spell."), /** * Must pass a Agility test. */ BOUND(StatConstants.AGILITY, "Your movements ae constricted and you cannot take any actions.", "Break free", "You manage to break free.", "You fail to break free."), /** * Must pass a Strength test. */ HELD(StatConstants.STRENGTH, "Your movements ae constricted and you cannot take any actions.", "Break free", "You manage to break free.", "You fail to break free."); private String resistingStatId; private String description; private String resistingOptionLabel; private String resistingSuccessText; private String resistingFailureText; private IncapacitatedState(String resistingStatId, String description, String resistingOptionLabel, String resistingSuccessText, String resistinFailureText) { this.resistingStatId = resistingStatId; this.description = description; this.resistingOptionLabel = resistingOptionLabel; this.resistingSuccessText = resistingSuccessText; this.resistingFailureText = resistinFailureText; } public String getResistingStatId() { return resistingStatId; } public String getDescription() { return description; } public String getResistingOptionLabel() { return resistingOptionLabel; } public String getResistingSuccessText() { return resistingSuccessText; } public String getResistingFailureText() { return resistingFailureText; } }
Java
package org.clockworkmages.games.anno1186.model.character; public enum Spell { }
Java
package org.clockworkmages.games.anno1186.model.character; import java.beans.Transient; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlTransient; import org.clockworkmages.games.anno1186.model.effect.ConditionStatus; import org.clockworkmages.games.anno1186.model.item.Item; public abstract class GameCharacter { private String name; private List<Item> inventory = new ArrayList<Item>(); private Map<String, Item> equippedItems = new HashMap<String, Item>(); private Map<String, Integer> skills = new HashMap<String, Integer>(); private Set<String> spells = new HashSet<String>(); private Map<String, ConditionStatus> conditions = new HashMap<String, ConditionStatus>(); private Set<String> perks = new HashSet<String>(); private Map<String, Double> baseStats = new HashMap<String, Double>(); private Map<String, Double> effectiveStats = new HashMap<String, Double>(); private Map<String, Double> derivates = new HashMap<String, Double>(); private Map<String, Double> damageMinimals = new HashMap<String, Double>(); private Map<String, Double> damageRanges = new HashMap<String, Double>(); private Map<String, Double> damageResistances = new HashMap<String, Double>(); private int gold; private int gender; private int level = 1; private int experience = 0; /** * Informs if the character's name is a personal name or not, and whether it * should be preceded by "the" in a fraze (e.g. * "You hit *the* wolf for 5 damage" but * "You hit Johny Uglynose for 5 damage"). */ private boolean addThe = false; /** * Transient flag that informs the game that some of the stats, skills, * perks or conditions have changed and that the derived stats need to be * recalculated. */ private boolean statsAreStale; public List<Item> getInventory() { return inventory; } public void setInventory(List<Item> inventory) { this.inventory = inventory; } public Map<String, Item> getEquippedItems() { return equippedItems; } public int getBaseStatAsInt(String statId) { return getStatAsInt(baseStats, statId); } public int getEffectiveStatAsInt(String statId) { return getStatAsInt(effectiveStats, statId); } public int getDerivateAsInt(String statId) { return getStatAsInt(derivates, statId); } private int getStatAsInt(Map<String, Double> stats, String statId) { Double value = stats.get(statId); if (value == null) { return 0; } else { return value.intValue(); } } public String getName() { return name; } public void setName(String name) { this.name = name; } @Transient public boolean isStatsAreStale() { return statsAreStale; } public void setStatsAreStale(boolean statsAreStale) { this.statsAreStale = statsAreStale; } public Map<String, Integer> getSkills() { return skills; } public void setSkills(Map<String, Integer> skills) { this.skills = skills; } public Set<String> getSpells() { return spells; } public void setSpells(Set<String> spells) { this.spells = spells; } public Map<String, ConditionStatus> getConditions() { return conditions; } public void setConditions(Map<String, ConditionStatus> conditions) { this.conditions = conditions; } public Set<String> getPerks() { return perks; } public void setPerks(Set<String> perks) { this.perks = perks; } @XmlElement(name = "baseStats") public Map<String, Double> getBaseStats() { return baseStats; } public void setBaseStats(Map<String, Double> baseStats) { this.baseStats = baseStats; } @XmlTransient public Map<String, Double> getEffectiveStats() { return effectiveStats; } public void setEffectiveStats(Map<String, Double> effectiveStats) { this.effectiveStats = effectiveStats; } @XmlTransient public Map<String, Double> getDerivates() { return derivates; } public void setDerivates(Map<String, Double> derivates) { this.derivates = derivates; } public void setEquippedItems(Map<String, Item> equippedItems) { this.equippedItems = equippedItems; } public int getGold() { return gold; } public void setGold(int gold) { this.gold = gold; } public int getGender() { return gender; } public void setGender(int gender) { this.gender = gender; } @XmlElement(name = "damageMinimal") public Map<String, Double> getDamageMinimals() { return damageMinimals; } public void setDamageMinimals(Map<String, Double> damageMinimals) { this.damageMinimals = damageMinimals; } @XmlElement(name = "damageRange") public Map<String, Double> getDamageRanges() { return damageRanges; } public void setDamageRanges(Map<String, Double> damageRanges) { this.damageRanges = damageRanges; } @XmlElement(name = "damageResistance") public Map<String, Double> getDamageResistances() { return damageResistances; } public void setDamageResistances(Map<String, Double> damageResistances) { this.damageResistances = damageResistances; } public void increaseBaseStat(String statId, double value) { Double initialValue = baseStats.get(statId); if (initialValue == null) { initialValue = 0d; } baseStats.put(statId, initialValue + value); } public boolean isAddThe() { return addThe; } public void setAddThe(boolean addThe) { this.addThe = addThe; } public abstract boolean isEnemy(); // helper methods public double getHealth() { Double health = baseStats.get(StatConstants.HEALTH); return health == null ? 0 : health; } public void setHealth(double health) { baseStats.put(StatConstants.HEALTH, health); } public double getMaxHealth() { Double maxHealth = derivates.get(StatConstants.D_MAX_HEALTH); return maxHealth == null ? 0 : maxHealth; } public double getStamina() { Double health = baseStats.get(StatConstants.STAMINA); return health == null ? 0 : health; } public void setStamina(double health) { baseStats.put(StatConstants.STAMINA, health); } public double getMaxStamina() { Double maxHealth = derivates.get(StatConstants.D_MAX_STAMINA); return maxHealth == null ? 0 : maxHealth; } public int getLevel() { return level; } public void setLevel(int level) { this.level = level; } public int getExperience() { return experience; } public void setExperience(int experience) { this.experience = experience; } }
Java
package org.clockworkmages.games.anno1186.model.character; import org.clockworkmages.games.anno1186.model.GameObject; public class Mutation extends GameObject { private String name; private String equipmentSlot; private String description; private boolean canEquipItems = true; public Mutation() { } public Mutation(String id, String name, String equipmentSlot, String description, boolean canEquipItems) { super(id); this.name = name; this.equipmentSlot = equipmentSlot; this.description = description; this.canEquipItems = canEquipItems; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEquipmentSlot() { return equipmentSlot; } public void setEquipmentSlot(String equipmentSlot) { this.equipmentSlot = equipmentSlot; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public boolean isCanEquipItems() { return canEquipItems; } public void setCanEquipItems(boolean canEquipItems) { this.canEquipItems = canEquipItems; } }
Java
package org.clockworkmages.games.anno1186.model.character; public class PlayerCharacter extends GameCharacter { @Override public boolean isEnemy() { return false; } }
Java
package org.clockworkmages.games.anno1186.model.character; public interface SkillConstants { String STEALTH = "STEALTH", BODYBUILDING = "BODYBUILDING", BARTER = "BODYBUILDING", MEDITATION = "MEDITATION", ALCHEMY = "ALCHEMY", SMITHING = "SMITHING", SURVIVAL = "SURVIVAL", SPEECH = "SPEECH", // BLUDGEON = "BLUDGEON", SWORD = "SWORD", DAGGER = "DAGGER", AXE = "AXE", POLEARM = "POLEARM", UNARMED = "UNARMED", // HISTORY = "HISTORY", THEOLOGY = "THEOLOGY", DEMONOLOGY = "DEMONOLOGY", INTERROGATION = "INTERROGATION"; }
Java
package org.clockworkmages.games.anno1186.model.character; public class SpecialAttack { private String effect; private String condition; private String text; public SpecialAttack() { super(); } public SpecialAttack(String text, String effect, String condition) { super(); this.effect = effect; this.condition = condition; this.text = text; } public String getEffect() { return effect; } public void setEffect(String effect) { this.effect = effect; } public String getCondition() { return condition; } public void setCondition(String condition) { this.condition = condition; } public String getText() { return text; } public void setText(String text) { this.text = text; } }
Java
package org.clockworkmages.games.anno1186.model.character; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import org.clockworkmages.games.anno1186.model.option.Option; public class NonPlayerCharacter extends GameCharacter { private String id; private String description; private List<SpecialAttack> specialAttacks = new ArrayList<SpecialAttack>(); private String subduingText; private String subduedText; private List<Option> victoriousOptions = new ArrayList<Option>(); private List<Option> defeatedOptions = new ArrayList<Option>(); private List<Option> subduingOptions = new ArrayList<Option>(); private List<Option> subduedOptions = new ArrayList<Option>(); private String fleeTo; public String getId() { return id; } public void setId(String id) { this.id = id; } public List<SpecialAttack> getSpecialAttacks() { return specialAttacks; } public void setSpecialAttacks(List<SpecialAttack> specialAttacks) { this.specialAttacks = specialAttacks; } public String getSubduingText() { return subduingText; } public void setSubduingText(String subduingText) { this.subduingText = subduingText; } public String getSubduedText() { return subduedText; } public void setSubduedText(String subduedText) { this.subduedText = subduedText; } @XmlElement(name = "victoriousOption") public List<Option> getVictoriousOptions() { return victoriousOptions; } public void setVictoriousOptions(List<Option> victoriousOptions) { this.victoriousOptions = victoriousOptions; } @XmlElement(name = "defeatedOption") public List<Option> getDefeatedOptions() { return defeatedOptions; } public void setDefeatedOptions(List<Option> defeatedOptions) { this.defeatedOptions = defeatedOptions; } @XmlElement(name = "subduingOption") public List<Option> getSubduingOptions() { return subduingOptions; } public void setSubduingOptions(List<Option> subduingOptions) { this.subduingOptions = subduingOptions; } @XmlElement(name = "subduedOption") public List<Option> getSubduedOptions() { return subduedOptions; } public void setSubduedOptions(List<Option> subduedOptions) { this.subduedOptions = subduedOptions; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @Override public boolean isEnemy() { return true; } @XmlAttribute public String getFleeTo() { return fleeTo; } public void setFleeTo(String fleeTo) { this.fleeTo = fleeTo; } }
Java
package org.clockworkmages.games.anno1186.model.map.tactical; public class GameArea { private Tile[][] tiles; public Tile[][] getTiles() { return tiles; } public void setTiles(Tile[][] tiles) { this.tiles = tiles; } }
Java
package org.clockworkmages.games.anno1186.model.map.tactical; public class TileTerrain extends TileObject { private String image; public void setImage(String image) { this.image = image; } @Override public String getImage() { return image; } @Override public boolean isPassable() { return true; } @Override public String getSituationId() { return null; } }
Java
package org.clockworkmages.games.anno1186.model.map.tactical; public class SimpleTileObject extends TileObject { private String image; private boolean passable; private String situationId; public SimpleTileObject() { } public SimpleTileObject(String id, String image, boolean passable) { super(id); this.image = image; this.passable = passable; } public SimpleTileObject(String id, String image, String situationId) { super(id); this.image = image; this.passable = false; this.situationId = situationId; } public String getImage() { return image; } public void setImage(String image) { this.image = image; } public boolean isPassable() { return passable; } public void setPassable(boolean passable) { this.passable = passable; } public String getSituationId() { return situationId; } public void setSituationId(String situationId) { this.situationId = situationId; } }
Java
package org.clockworkmages.games.anno1186.model.map.tactical; import java.util.ArrayList; import java.util.List; public class Tile { private List<TileObject> tileObjects = new ArrayList<TileObject>(); public List<TileObject> getTileObjects() { return tileObjects; } public void setTileObjects(List<TileObject> tileObjects) { this.tileObjects = tileObjects; } }
Java
package org.clockworkmages.games.anno1186.model.map.tactical; import org.clockworkmages.games.anno1186.model.GameObject; public abstract class TileObject extends GameObject { public TileObject() { } public TileObject(String id) { super(id); } public abstract String getImage(); public abstract boolean isPassable(); public abstract String getSituationId(); }
Java
package org.clockworkmages.games.anno1186.model.map.tactical; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import org.clockworkmages.games.anno1186.model.GameObject; public class GameAreaDO extends GameObject { private int x; private int y; /** * Array of space-separated Strings. Each entry represents the list of * TileObjects of a single Tile. */ private List<String> tiles = new ArrayList<String>(); @XmlElement(name = "tile") public List<String> getTiles() { return tiles; } public void setTiles(List<String> tiles) { this.tiles = tiles; } @XmlAttribute public int getX() { return x; } public void setX(int x) { this.x = x; } @XmlAttribute public int getY() { return y; } public void setY(int y) { this.y = y; }; }
Java
package org.clockworkmages.games.anno1186.model.map.board; public class BoardType { List<TileAvailability> availableTiles; }
Java
package org.clockworkmages.games.anno1186.model.map.board; import org.junit.runner.manipulation.Sortable; public class TileAvailability implements Comparable<TileAvailability> { TileType tileType; boolean unique; boolean required; Integer fixedLocation; List<BoardSection> availableBoardSections; @Override public int compareTo(TileAvailability o) { required with fixed location first... } }
Java
package org.clockworkmages.games.anno1186.model; public enum Direction { NORTH(0, 1), EAST(1, 0), SOUTH(0, -1), WEST(-1, 0); private int x; private int y; private Direction(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } }
Java
package org.clockworkmages.games.anno1186.model.effect; import javax.xml.bind.annotation.XmlAttribute; import org.clockworkmages.games.anno1186.model.GameObject; public class Effect extends GameObject { private String effect; private String condition; public Effect() { } public Effect(String effect) { this.effect = effect; } public Effect(String effect, String condition) { this.effect = effect; this.condition = condition; } @XmlAttribute(name = "effect") public String getEffect() { return effect; } public void setEffect(String effect) { this.effect = effect; } public String getCondition() { return condition; } @XmlAttribute(name = "if") public void setCondition(String condition) { this.condition = condition; } }
Java
package org.clockworkmages.games.anno1186.model.effect; public class ConditionStatus { /** * Level of the condition. Some onditions have effects that may be stronger * or weaker, depending on the level. */ private int level; /** * Time (as Date.getTime()) aftr which this condition should be * deactivated/automatically removed. */ private long validUntil; /** * For continuous Conditions (Conditions that have interval>0) only, this * informs when the Condition's effect has last been triggered and when it * sohuld be triggered next. */ private long lastExecuted; public ConditionStatus(int level, long validUntil, long lastExecuted) { super(); this.level = level; this.validUntil = validUntil; this.lastExecuted = lastExecuted; } public int getLevel() { return level; } public void setLevel(int level) { this.level = level; } public long getValidUntil() { return validUntil; } public void setValidUntil(long validUntil) { this.validUntil = validUntil; } public long getLastExecuted() { return lastExecuted; } public void setLastExecuted(long lastExecuted) { this.lastExecuted = lastExecuted; } }
Java
package org.clockworkmages.games.anno1186.model.effect; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlElement; import org.clockworkmages.games.anno1186.GameBeansContext; import org.clockworkmages.games.anno1186.GameStateService; import org.clockworkmages.games.anno1186.model.GameObject; public class Condition extends GameObject { private List<Effect> effects = new ArrayList<Effect>(); private String name; private String description; /** * Combat-only conditions are automatically removed at the end of the * combat. */ private boolean combatOnly = false; /** * Interval says how often the Condition's affects should occur. This is * typically important for confition that affect base statistics (e.g. * damage or regenerate health). */ private Long interval; public ConditionStatus makeStatus(int level, long validUntil) { long gameTime = GameBeansContext.getBean(GameStateService.class) .getGameState().getTime(); ConditionStatus conditionStatus = new ConditionStatus(level, validUntil, gameTime); return conditionStatus; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @XmlElement(name = "effect") public List<Effect> getEffects() { return effects; } public void setEffects(List<Effect> effects) { this.effects = effects; } public boolean isCombatOnly() { return combatOnly; } public void setCombatOnly(boolean combatOnly) { this.combatOnly = combatOnly; } public Long getInterval() { return interval; } public void setInterval(Long interval) { this.interval = interval; } }
Java
package org.clockworkmages.games.anno1186.model.effect; public interface ConditionConstanst { String SATISFIED = "SATISFIED"; String TIRED = "TIRED"; }
Java
package org.clockworkmages.games.anno1186.model.effect; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlElement; import org.clockworkmages.games.anno1186.model.GameObject; public class Perk extends GameObject { private List<Effect> effects = new ArrayList<Effect>(); private String name; private String description; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @XmlElement(name = "effect") public List<Effect> getEffects() { return effects; } public void setEffects(List<Effect> effects) { this.effects = effects; } }
Java
package org.clockworkmages.games.anno1186.model; /** * Current game mode, which basically corresponds to the type of the screen * screen (Card activated in the main CardLayout) that is currently being * presented. */ public enum GameMode { LOCAL_MAP, SITUATION, COMBAT, // TODO: all the LOCKPICK and DISARM screens, ALCHEMY etc. }
Java
package org.clockworkmages.games.anno1186.model; public class Fetish extends GameObject implements Comparable<Fetish> { private String name; private String description; public Fetish() { } public Fetish(String id, String name, String description) { super(id); this.name = name; this.description = description; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @Override public int compareTo(Fetish o) { return this.name.compareTo(o.getName()); } }
Java
package org.clockworkmages.games.anno1186.model; import javax.xml.bind.annotation.XmlAttribute; public class GameObject { private String id; public GameObject() { } public GameObject(String id) { super(); this.id = id; } @XmlAttribute public String getId() { return id; } public void setId(String id) { this.id = id; } }
Java
package org.clockworkmages.games.anno1186.model; import java.util.List; import org.clockworkmages.games.anno1186.model.effect.Effect; public interface Effecting { List<Effect> getEffects(); }
Java
package org.clockworkmages.games.anno1186.model.situation; public class SituationPoolForwarder implements ExplorableGameEvent { private String situationPool; private String condition; private int probability; private String targetSituationPool; public String getAreaType() { return situationPool; } public void setSituationPool(String situationPool) { this.situationPool = situationPool; } public String getCondition() { return condition; } public void setCondition(String condition) { this.condition = condition; } public int getProbability() { return probability; } public void setProbability(int probability) { this.probability = probability; } public String getTargetSituationPool() { return targetSituationPool; } public void setTargetSituationPool(String targetSituationPool) { this.targetSituationPool = targetSituationPool; } }
Java
package org.clockworkmages.games.anno1186.model.situation; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import org.clockworkmages.games.anno1186.model.option.GenericOption; import org.clockworkmages.games.anno1186.model.option.Option; //@XmlRootElement(name = "situation") public class GenericSituation extends Situation implements ExplorableGameEvent { // exploration event situation only: /** * Situation pool (typically: a location, such as Forest or Desert) where * this situation can potentially occur. */ private String situationPool; /** * Condition that needs to be met for this situation to be available for * picking when exploring the given situationPool/location. */ private String condition; /** * Probability of this situation. This is not a percentual value, it just * makes this situation more or less probable compared to other explorable * situations. */ private int probability; @XmlElement(name = "option") public List<GenericOption> getGenericOptions() { List<GenericOption> genericOptions = new ArrayList<GenericOption>(); for (Option option : getOptions()) { if (option instanceof GenericOption) { genericOptions.add((GenericOption) option); } } return genericOptions; } public void setGenericOptions(List<GenericOption> options) { this.getOptions().clear(); this.getOptions().addAll(options); } @XmlAttribute public String getAreaType() { return situationPool; } public void setSituationPool(String situationPool) { this.situationPool = situationPool; } @XmlAttribute public String getCondition() { return condition; } public void setCondition(String condition) { this.condition = condition; } @XmlAttribute public int getProbability() { return probability; } public void setProbability(int probability) { this.probability = probability; } }
Java
package org.clockworkmages.games.anno1186.model.situation; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import org.clockworkmages.games.anno1186.model.Effecting; import org.clockworkmages.games.anno1186.model.GameObject; import org.clockworkmages.games.anno1186.model.effect.Effect; import org.clockworkmages.games.anno1186.model.option.Option; public abstract class Situation extends GameObject implements Effecting { public Situation() { }; public Situation(String id) { super(id); }; private boolean clearScreen = true; private List<Option> options = new ArrayList<Option>(); private String text; private String title; private List<Effect> effects = new ArrayList<Effect>(); protected List<Option> asList(Option... options) { return Arrays.asList(options); } /** * This method gets overwritten in technical Situations. */ public void update() { } @XmlAttribute public boolean isClearScreen() { return clearScreen; } public void setClearScreen(boolean clearScreen) { this.clearScreen = clearScreen; } public List<Option> getOptions() { return options; } public String getText() { return text; } public void setText(String text) { this.text = text; } @XmlAttribute public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } @XmlElement(name = "effect") public List<Effect> getEffects() { return effects; } public void setEffects(List<Effect> effects) { this.effects = effects; } }
Java
package org.clockworkmages.games.anno1186.model.situation; public interface ExplorableGameEvent { /** * Situation pool (typically: a location, such as Forest or Desert) where * this situation can potentially occur. */ String getAreaType(); /** * Condition that needs to be met for this situation to be available for * picking when exploring the given situationPool/location. */ String getCondition(); /** * Probability of this situation. This is not a percentual value, it just * makes this situation more or less probable compared to other explorable * situations. */ int getProbability(); }
Java
package org.clockworkmages.games.anno1186.model; public interface FetishConstants { String MEN = "1_MEN", WOMEN = "2_WOMEN", DOMINATION = "3_DOMINATION", SUBMISSION = "4_SUBMISSION", MYTHICAL = "5_MYTHICAL", ALIEN = "6_ALIEN", ANAL = "7_ANAL", URINATION = "8_URINATION", FEET = "9_FEET"; }
Java
package org.clockworkmages.games.anno1186.model.option; import org.clockworkmages.games.anno1186.GameStateService; import org.clockworkmages.games.anno1186.Injected; public class GoBackOption extends Option { public static GoBackOption INSTANCE = new GoBackOption(); @Injected private GameStateService gameStateService; private GoBackOption() { super("BACK"); setIcon("back"); setLabel("Back"); } @Override public void select() { gameStateService.removeCurrentSituation(); super.select(); } }
Java
package org.clockworkmages.games.anno1186.model.option; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import org.clockworkmages.games.anno1186.GameBeansContext; import org.clockworkmages.games.anno1186.GameDataService; import org.clockworkmages.games.anno1186.GameGuiService; import org.clockworkmages.games.anno1186.GameState; import org.clockworkmages.games.anno1186.GameStateService; import org.clockworkmages.games.anno1186.GameTimeService; import org.clockworkmages.games.anno1186.SituationPoolService; import org.clockworkmages.games.anno1186.SituationService; import org.clockworkmages.games.anno1186.dao.ImageIconDescriptor; import org.clockworkmages.games.anno1186.model.GameObject; import org.clockworkmages.games.anno1186.model.character.NonPlayerCharacter; import org.clockworkmages.games.anno1186.model.situation.Situation; import org.clockworkmages.games.anno1186.situations.combat.CombatSituation; import org.clockworkmages.games.anno1186.text.TextUtil; /** * @author Tomek * */ public abstract class Option extends GameObject { private String label; private String tooltip; /** * Text to be presented after the option has been selected. Can be null, * especially if the option targets a Situation or Location that have their * own description. */ private String textAfter; private boolean consumesCombatAction; private boolean textfield = false; private String condition; /** * Special condition that indicates that this option shall only be available * for evaluation if the previous option was evaluated as false. */ private boolean or; private long timePassed; /** * Id of the icon defined in game data as ${link {@link ImageIconDescriptor} * . If defined, the appropriate icon will be displayed before the option's * label. */ private String icon; /** * ID of the situation that this option will take the player to. */ private String goToSituation; /** * ID of the situation pool that this option will take the player to. * * Situation pool will then return a single situation - either selected * randomly or based on logical conditions. */ private String goToSituationPool; /** * Id of the enemy. */ private String goToCombat; /** * If sets to <b>true</b> the new situation will be added to the situation * stack and it will be possible to return from it to the current situation. * * Typical applications are opening an inventory or a spellbook when in a * camp or in combat; examining an enemy or item; or going to a shop while * in on the city screen. */ private boolean addToStack = false; /** * If sets to <b>true</b> selecting this option will remove current * situation from stack, returning the player to the previous situation on * stack. */ private boolean goBack = false; public Option() { } public Option(String id) { super(id); } public void select() { GameTimeService gameTimeService = GameBeansContext .getBean(GameTimeService.class); SituationService situationManager = GameBeansContext .getBean(SituationService.class); GameGuiService gameGuiService = GameBeansContext .getBean(GameGuiService.class); GameDataService gameDataService = GameBeansContext .getBean(GameDataService.class); GameStateService gameStateService = GameBeansContext .getBean(GameStateService.class); GameState gameState = gameStateService.getGameState(); gameState.setPreviousSituation(gameState.getCurrentSituation()); if (this.consumesCombatAction && gameStateService.isInCombat()) { // the player has used some item or has cast a spell in the middle // of combat, consuming his combat turn. // Return to combat situation screen immediately: List<Situation> situationStack = gameState.getSituationStack(); int size = situationStack.size(); for (int i = size - 1; i >= 0; i--) { if (situationStack.get(i) instanceof CombatSituation) { ((CombatSituation) situationStack.get(i)) .setPlayerConsumedCombatAction(true); break; } else { situationStack.remove(i); } } } else if (goBack) { gameStateService.removeCurrentSituation(); } else if (this.goToSituation != null) { if (!this.addToStack) { gameStateService.removeCurrentSituation(); } for (String s : this.goToSituation.split(",")) { // in some cases the "gotToSituation" can contain a // coma-separated list of situations that should all be added to // the situation stack in the specified order String situationId = s.trim(); gameStateService.addSituation(situationId, true); } } else if (this.goToSituationPool != null) { SituationPoolService situationPoolService = GameBeansContext .getBean(SituationPoolService.class); Situation situationFromPool = situationPoolService .getRandomSituationFromPool(this.goToSituationPool); gameStateService.addSituation(situationFromPool, this.addToStack); } else if (this.goToCombat != null) { NonPlayerCharacter enemy = gameDataService.getGameData().getNpcs() .get(this.goToCombat); CombatSituation combatSituation = new CombatSituation(enemy); gameStateService.addSituation(combatSituation, this.addToStack); } if (timePassed > 0) { gameTimeService.advanceTime(timePassed); } if (textAfter != null) { gameGuiService.getTextPane().removeTrailing("[...]"); String parsedText = TextUtil.parse(this.textAfter); gameGuiService.getTextPane().appendText(parsedText + "\n"); } situationManager.playCurrentSituation(); } @XmlAttribute public String getLabel() { return label; } public String getTooltip() { return tooltip; } @XmlAttribute public boolean isConsumesCombatAction() { return consumesCombatAction; } public String getTextAfter() { return textAfter; } public void setTextAfter(String text) { this.textAfter = text; } public void setLabel(String label) { this.label = label; } public void setTooltip(String description) { this.tooltip = description; } public void setConsumesCombatAction(boolean consumesCombatAction) { this.consumesCombatAction = consumesCombatAction; } @XmlAttribute public boolean isTextfield() { return textfield; } public void setTextfield(boolean textfield) { this.textfield = textfield; } public String getCondition() { return condition; } public void setCondition(String condition) { this.condition = condition; } @XmlAttribute public boolean isOr() { return or; } public void setOr(boolean or) { this.or = or; } @XmlAttribute public long getTimePassed() { return timePassed; } public void setTimePassed(long timePassed) { this.timePassed = timePassed; } @XmlAttribute public String getIcon() { return icon; } public void setIcon(String icon) { this.icon = icon; } @XmlAttribute public String getGoToSituation() { return goToSituation; } public void setGoToSituation(String goToSituation) { this.goToSituation = goToSituation; } @XmlAttribute public String getGoToSituationPool() { return goToSituationPool; } public void setGoToSituationPool(String goToSituationPool) { this.goToSituationPool = goToSituationPool; } @XmlAttribute public boolean isAddToStack() { return addToStack; } public void setAddToStack(boolean addToStack) { this.addToStack = addToStack; } @XmlAttribute public boolean isGoBack() { return goBack; } public void setGoBack(boolean goBack) { this.goBack = goBack; } @XmlAttribute public String getGoToCombat() { return goToCombat; } public void setGoToCombat(String goToCombat) { this.goToCombat = goToCombat; } }
Java
package org.clockworkmages.games.anno1186.model.option; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import org.clockworkmages.games.anno1186.GameBeansContext; import org.clockworkmages.games.anno1186.dao.GameObjectsList; import org.clockworkmages.games.anno1186.model.Effecting; import org.clockworkmages.games.anno1186.model.effect.Effect; import org.clockworkmages.games.anno1186.scripting.ScriptingService; public class GenericOption extends Option implements Effecting { /** * Reference to the ID of a named Option. If this value is set, the Option * is treated as a virtual markup to be removed and replaced by a reference * to the named option during game data loading process. */ private String ref; /** * The text to be added to the "You see..." portion of the Situation's * description text. */ private String see; /** * Id of the Situation that this option should be appended to. This field * should only be set for a "located" options - GenericOption defined at the * top-level of a ${link {@link GameObjectsList} that is supposed to extend * a Situation defined in a different file (which makes modding easier). */ private String situationId; private List<Effect> effects = new ArrayList<Effect>(); @Override public void select() { ScriptingService scriptingService = GameBeansContext .getBean(ScriptingService.class); for (Effect effect : effects) { if (effect.getCondition() == null || scriptingService.conditionIsMet(effect.getCondition())) { scriptingService.execute(effect.getEffect()); } } super.select(); } @XmlAttribute public String getRef() { return ref; } public void setRef(String ref) { this.ref = ref; } @XmlAttribute public String getSee() { return see; } public void setSee(String see) { this.see = see; } public String getSituationId() { return situationId; } public void setSituationId(String situationId) { this.situationId = situationId; } @XmlElement(name = "effect") public List<Effect> getEffects() { return effects; } public void setEffects(List<Effect> effects) { this.effects = effects; } }
Java
package org.clockworkmages.games.anno1186.model.item; import org.clockworkmages.games.anno1186.model.GameObject; public class EquipmentSlot extends GameObject { /** * Textual template to be used when generating character's description. Can * and should contain placeholders, e.g * "On you back you carry ${item.shortDescription}." */ private String description; public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } }
Java
package org.clockworkmages.games.anno1186.model.item; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import org.clockworkmages.games.anno1186.model.GameObject; import org.clockworkmages.games.anno1186.model.effect.Effect; import org.clockworkmages.games.anno1186.model.option.GenericOption; public class Item extends GameObject { private String name; private String description; private int value; private String sellableCondition; private List<Effect> equippedEffects = new ArrayList<Effect>(); private String equipmentSlotId; /** * Options that should be available for that item. */ private List<GenericOption> useOptions = new ArrayList<GenericOption>(); private String itemType; public Item() { } public Item(String id, String name, String description) { super(id); this.name = name; this.description = description; } @XmlElement(name = "effect") public List<Effect> getEffects() { return equippedEffects; } public void setEffects(List<Effect> effects) { this.equippedEffects = effects; } @XmlAttribute(name = "slot") public String getEquipmentSlotId() { return equipmentSlotId; } public void setEquipmentSlotId(String equipmentSlotId) { this.equipmentSlotId = equipmentSlotId; } @XmlAttribute(name = "type") public String getItemType() { return itemType; } public void setItemType(String itemType) { this.itemType = itemType; } @XmlAttribute(name = "name") public String getName() { return name; } public void setName(String name) { this.name = name; } @XmlAttribute(name = "description") public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @XmlAttribute(name = "value") public int getValue() { return value; } public void setValue(int value) { this.value = value; } @XmlAttribute(name = "sellableIf") public String getSellableCondition() { return sellableCondition; } public void setSellableCondition(String sellableCondition) { this.sellableCondition = sellableCondition; } @XmlElement(name = "equippedEffect") public List<Effect> getEquippedEffects() { return equippedEffects; } public void setEquippedEffects(List<Effect> equipEffects) { this.equippedEffects = equipEffects; } @XmlElement(name = "useOption") public List<GenericOption> getUseOptions() { return useOptions; } public void setUseOptions(List<GenericOption> useOptions) { this.useOptions = useOptions; } }
Java
package org.clockworkmages.games.anno1186.model.item; public interface ItemConstants { final String EQUIPMENT_SLOT_HEAD = "Head"; final String EQUIPMENT_SLOT_TORSO = "Torso"; final String EQUIPMENT_SLOT_LEGS = "Legs"; final String EQUIPMENT_SLOT_SHOES = "Shoes"; final String EQUIPMENT_SLOT_BELT = "Belt"; final String EQUIPMENT_SLOT_R_HAND = "RHand"; final String EQUIPMENT_SLOT_L_HAND = "LHand"; final String EQUIPMENT_SLOT_RING = "Ring"; final String EQUIPMENT_SLOT_BACK = "Back"; final String ITEM_TYPE_SWORD = "Sword"; final String ITEM_TYPE_AXE = "Axe"; final String ITEM_TYPE_Bludgeon = "Bludgeon"; final String ITEM_TYPE_DAGGER = "Dagger"; final String ITEM_TYPE_POLEARM = "Polearm"; final String ITEM_TYPE_ = "Unarmed"; final String ITEM_TYPE_ARMOR_LIGHT = "Light"; final String ITEM_TYPE_ARMOR_MEDIUM = "Heavy"; final String ITEM_TYPE_AMOR_HEAVY = "Medium"; }
Java
package org.clockworkmages.games.anno1186.model.common; public class Pair<T1, T2> { private T1 first; private T2 second; public Pair() { } public Pair(T1 first, T2 second) { this.first = first; this.second = second; } public T1 getFirst() { return first; } public void setFirst(T1 first) { this.first = first; } public T2 getSecond() { return second; } public void setSecond(T2 second) { this.second = second; } }
Java
package org.clockworkmages.games.anno1186; import org.clockworkmages.games.anno1186.model.map.tactical.GameArea; import org.clockworkmages.games.anno1186.model.map.tactical.GameAreaDO; import org.clockworkmages.games.anno1186.model.map.tactical.Tile; import org.clockworkmages.games.anno1186.model.map.tactical.TileObject; public class GameAreaService { @Injected private GameDataService gameDataService; public GameArea fromDO(GameAreaDO gameAreaDO) { GameArea gameArea = new GameArea(); Tile[][] tiles = new Tile[gameAreaDO.getX()][gameAreaDO.getY()]; gameArea.setTiles(tiles); int i = 0; for (int y = gameAreaDO.getY() - 1; y >= 0; y--) { for (int x = 0; x < gameAreaDO.getX(); x++) { String tileObjectsString = gameAreaDO.getTiles().get(i++); Tile tile = new Tile(); for (String tileObjectId : tileObjectsString.split(" ")) { TileObject tileObject = gameDataService.getGameData() .getTileObjects().get(tileObjectId); tile.getTileObjects().add(tileObject); } tiles[x][y] = tile; } } return gameArea; } }
Java
package org.clockworkmages.games.anno1186.tools; import java.util.Date; import java.util.Iterator; import java.util.Map; import org.clockworkmages.games.anno1186.gui.GameUiUtil; public class ThreadDumpLogger { public static void createThreadDumpAfter5sec() { final Thread someThread = new Thread(new Runnable() { @Override public void run() { long targetTime = new Date().getTime() + 5000; while (new Date().getTime() < targetTime) { // do nothing } // try { // wait(5000); // } catch (Exception e) { // e.printStackTrace(); // } Map<Thread, StackTraceElement[]> traces = Thread .getAllStackTraces(); Iterator<Thread> i = traces.keySet().iterator(); while (i.hasNext()) { Thread thd = i.next(); System.out.println("*** Thread id" + thd.getId() + ":" + thd.getName() + " ***"); StackTraceElement[] trace = traces.get(thd); for (int j = 0; j < trace.length; ++j) { GameUiUtil.logError(trace[j].toString()); // System.out.println(trace[j]); } } } }); someThread.setDaemon(true); someThread.start(); } }
Java
package org.clockworkmages.games.anno1186; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; public class GameBeansContext { private static Map<Class<?>, Object> singletonBeans = new HashMap<Class<?>, Object>(); public static void register(Object bean) { singletonBeans.put(bean.getClass(), bean); } public static <T> T getBean(Class<T> clazz) { return (T) singletonBeans.get(clazz); } public static void processInjectAnnotations(Object bean) { for (Field field : bean.getClass().getDeclaredFields()) { if (field.isAnnotationPresent(Injected.class)) { Class<?> fieldClass = field.getType(); Object beanToInject = singletonBeans.get(fieldClass); if (beanToInject == null) { throw new RuntimeException( "Could not find any registered bean of type " + fieldClass.getCanonicalName()); } field.setAccessible(true); try { field.set(bean, beanToInject); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } } } public static void processInjectAnnotations() { for (Object bean : singletonBeans.values()) { processInjectAnnotations(bean); } } }
Java
package org.clockworkmages.games.anno1186; import java.util.List; import org.clockworkmages.games.anno1186.gui.FontStyleConstants; import org.clockworkmages.games.anno1186.model.GameMode; import org.clockworkmages.games.anno1186.model.character.PlayerCharacter; import org.clockworkmages.games.anno1186.model.effect.Effect; import org.clockworkmages.games.anno1186.model.option.GenericOption; import org.clockworkmages.games.anno1186.model.option.Option; import org.clockworkmages.games.anno1186.model.situation.Situation; import org.clockworkmages.games.anno1186.scripting.ScriptingService; import org.clockworkmages.games.anno1186.text.TextUtil; public class SituationService { @Injected private GameStateService gameStateService; @Injected private GameGuiService gameGuiService; @Injected private ScriptingService scriptingService; @Injected private GameCharacterService gameCharacterService; /** * The situation that was played previously. This information is stored in * order to avoid clearing the text if we're only switching between the * dialog options of a single situation. */ private Situation previouslyPlayedSituation = null; /** * */ /** * */ public void playCurrentSituation() { GameState gameState = gameStateService.getGameState(); Situation currentSituation = gameState.getCurrentSituation(); if (currentSituation == null) { // ok, the Situation has finished, we will now go back to the // GameMode.LOCAL_MAP gameState.setGameMode(GameMode.LOCAL_MAP); gameGuiService.getTextPane().clearText(); return; } currentSituation.update(); if (currentSituation != previouslyPlayedSituation) { if (currentSituation.isClearScreen()) { gameGuiService.getTextPane().clearText(); } boolean currentSituationWasRecentlyAdded = gameStateService .getGameState().currentSituationWasRecentlyAdded(); if (currentSituationWasRecentlyAdded && currentSituation.getEffects() != null) { for (Effect effect : currentSituation.getEffects()) { if (effect.getCondition() == null || scriptingService.conditionIsMet(effect .getCondition())) { scriptingService.execute(effect.getEffect()); } } } } List<Option> options = currentSituation.getOptions(); // CardLayout optionCardLayout = (CardLayout) gameGuiService // .getOptionCardPanel().getLayout(); // Text for the "You see [...]." portion of the generic Situation's // description. StringBuffer seeTextBuffer = new StringBuffer(); if (currentSituation != previouslyPlayedSituation) { String title = currentSituation.getTitle(); if (title != null) { gameGuiService.getTextPane().appendText( "{f:b}" + title + "{f}\n\n"); } gameGuiService.getTextPane().appendText( TextUtil.parse(currentSituation.getText()) + "\n"); if (seeTextBuffer.length() > 0) { String seeText = seeTextBuffer.toString(); seeText = "\nYou see {f:b}" + seeText.substring(0, seeText.length() - 2) + "{f}.+\n\n"; gameGuiService.getTextPane().appendText(seeText); } previouslyPlayedSituation = currentSituation; } gameGuiService.getTextPane().flushInfoBuffer(); if (gameState.getCharacter().isStatsAreStale()) { gameCharacterService.refreshStats(gameState.getCharacter()); } if (options.size() == 1 && options.get(0).isTextfield()) { // this situation requires a text input (e.g. naming your character) gameGuiService.getOptionTextInputKeyListener().setOption( options.get(0)); // optionCardLayout.show(gameGuiService.getOptionCardPanel(), // GameUiConstants.OPTION_PANEL_TEXT_CARD); gameGuiService.getTextPane().appendText(" ", FontStyleConstants.TEXTINPUT); } else { // this situation requires the user to select an available option // for a list gameGuiService.getOptionList().removeAll(); List<Option> availableOptions = OptionUtil .getAvailableOptions(options); for (Option option : availableOptions) { if (option instanceof GenericOption) { String seeText = ((GenericOption) option).getSee(); if (seeText != null) { seeTextBuffer.append(seeText).append(", "); } } } gameGuiService.getOptionList().setListData( (Option[]) availableOptions.toArray(new Option[] {})); gameGuiService.getTextPane().appendText(" ", FontStyleConstants.OPTIONLIST); // optionCardLayout.show(gameGuiService.getOptionCardPanel(), // GameUiConstants.OPTION_PANEL_LIST_CARD); } gameGuiService.getBottomLeft().repaint(); PlayerCharacter me = gameState.getCharacter(); double maxHealth = me.getMaxHealth(); double healthState = maxHealth == 0 ? 0 : me.getHealth() / me.getMaxHealth(); gameGuiService .getExplorationPanel() .getLeftTotemPanel() .getTotemImage() .setTargetState(healthState > 0 ? healthState : 0, 2 * TimeConstants.SECOND); } }
Java
package org.clockworkmages.games.anno1186; /** * Container for all the static references that need to be accessible from any * place in the code. * * TODO not the prettiest solution, but I don't see any alternatives. * ThreadLocal wouldn't be much prettier. * * @author Tom */ public class Game { // Game data: // public static GameData gameData; // // public static GameState gameState; // graphical resources used in generic objects (Situations and Options) // public static Map<String, ImageIcon> imageIcons = new HashMap<String, // ImageIcon>(); // UI objects: // public static AnimatedTextPane textPane; // // public static InfoTextPane statsPane; // // public static JList<Option> optionList; // // public static JTextField optionTextInput; // // public static OptionTextInputKeyListener optionTextInputKeyListener; // // public static JPanel optionCardPanel; }
Java
package org.clockworkmages.games.anno1186; import java.io.File; import java.io.FileReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.HashMap; import java.util.Map; import javax.swing.ImageIcon; import org.clockworkmages.games.anno1186.dao.GameFilesList; import org.clockworkmages.games.anno1186.dao.GameObjectsList; import org.clockworkmages.games.anno1186.dao.SerializationUtil; import org.clockworkmages.games.anno1186.gui.GameUiUtil; public class GameDataService { private GameData gameData = new GameData(); private Map<String, ImageIcon> imageIcons = new HashMap<String, ImageIcon>(); public Map<String, ImageIcon> getImageIcons() { return imageIcons; } public void mergeGameDataFromResourceList(String gameFilesFilePath) { try { InputStream is = this.getClass().getClassLoader() .getResourceAsStream(gameFilesFilePath); InputStreamReader reader = new InputStreamReader(is); GameFilesList gameObjectsList = SerializationUtil.deserialize( reader, GameFilesList.class); for (String gameObjectsResource : gameObjectsList.getFiles()) { mergeGameDataFromResource(gameObjectsResource); } } catch (Exception e) { GameUiUtil.logError(e); throw new RuntimeException(e); } } public void mergeGameDataFromResource(String gameDataResourcePath) { try { InputStream is = this.getClass().getClassLoader() .getResourceAsStream(gameDataResourcePath); InputStreamReader reader = new InputStreamReader(is); GameObjectsList gameObjectsListFromFile = SerializationUtil .deserializeGameData(reader); gameData.merge(gameObjectsListFromFile); } catch (Exception e) { GameUiUtil.logError(e); throw new RuntimeException(e); } } public void mergeGameDataFromLocalDirectory(String gameDataDirectoryPath) { try { File gameDataDirectory = new File(gameDataDirectoryPath); if (!gameDataDirectory.exists() || !gameDataDirectory.isDirectory()) { return; } File[] gameObjectsListXmlFiles = gameDataDirectory.listFiles(); for (File gameObjectListXmlFile : gameObjectsListXmlFiles) { GameUiUtil.logError("Loading game data file: " + gameObjectListXmlFile.getAbsolutePath()); Reader reader = new FileReader(gameObjectListXmlFile); GameObjectsList gameObjectsListFromFile = SerializationUtil .deserializeGameData(reader); gameData.merge(gameObjectsListFromFile); } } catch (Exception e) { GameUiUtil.logError(e); throw new RuntimeException(e); } } public GameData getGameData() { return gameData; } public void cleanGameData() { gameData = new GameData(); } }
Java
package org.clockworkmages.games.anno1186; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; @Target({ FIELD }) @Retention(RUNTIME) @Documented public @interface Injected { }
Java
package org.clockworkmages.games.anno1186; import java.awt.Image; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Calendar; import java.util.Map.Entry; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import org.clockworkmages.games.anno1186.controllers.LocalMapMovementController; import org.clockworkmages.games.anno1186.dao.FileUtil; import org.clockworkmages.games.anno1186.gui.GamePanel; import org.clockworkmages.games.anno1186.model.option.GoBackOption; import org.clockworkmages.games.anno1186.model.option.Option; import org.clockworkmages.games.anno1186.model.situation.Situation; import org.clockworkmages.games.anno1186.scripting.EnemyScriptingWrapper; import org.clockworkmages.games.anno1186.scripting.PlayerCharacterScriptingWrapper; import org.clockworkmages.games.anno1186.scripting.PlotScriptingWrapper; import org.clockworkmages.games.anno1186.scripting.ScriptingService; import org.clockworkmages.games.anno1186.scripting.SituationScriptingWrapper; import org.clockworkmages.games.anno1186.scripting.UtilScriptingWrapper; import org.clockworkmages.games.anno1186.situations.gameoptions.GameMenuSituation; import org.clockworkmages.games.anno1186.situations.gameoptions.options.GameMenuOption; import org.clockworkmages.games.anno1186.situations.inventory.options.InventoryOption; public class GameApplication { /** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. */ public static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("Anno 1186"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Container pane = frame.getContentPane(); final GamePanel gamePanel = new GamePanel(); frame.add(gamePanel); // Container pane = frame.getContentPane(); // Display the window. frame.pack(); frame.setVisible(true); // "Debug" for identifying problems observed when running the // application as a standalone JAR: Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); gamePanel .getExplorationPanel() .getTextPane() .appendText( e.getClass().getName() + " " + e.getMessage() + "\n\n" + errors.toString()); } }); } public static void initContextBeans() { GameBeansContext.register(new GameCharacterService()); GameBeansContext.register(new GameDataService()); GameBeansContext.register(new GameStateService()); GameBeansContext.register(new GameTimeService()); GameBeansContext.register(new SituationService()); GameBeansContext.register(new SituationPoolService()); GameBeansContext.register(new GameAreaService()); GameBeansContext.register(new EnemyScriptingWrapper()); GameBeansContext.register(new PlayerCharacterScriptingWrapper()); GameBeansContext.register(new PlotScriptingWrapper()); GameBeansContext.register(new ScriptingService()); GameBeansContext.register(new SituationScriptingWrapper()); GameBeansContext.register(new UtilScriptingWrapper()); // GameBeansContext.register(InventoryOption.INSTANCE); GameBeansContext.register(GoBackOption.INSTANCE); GameBeansContext.register(GameMenuOption.INSTANCE); // GameBeansContext.register(GameMenuSituation.INSTANCE); GameGuiService gameGuiService = new GameGuiService(); GameBeansContext.register(gameGuiService); LocalMapMovementController localMapMovementController = new LocalMapMovementController(); GameBeansContext.register(localMapMovementController); GameBeansContext.processInjectAnnotations(); } public static void initGameData() { // GameData gameData = new GameData(); GameDataService gameDataService = GameBeansContext .getBean(GameDataService.class); String resourceListFile = "data/gameFiles.xml"; gameDataService.mergeGameDataFromResourceList(resourceListFile); // GameDataManager // .mergeGameDataFromResource(gameData, "gameData/base.xml"); // GameDataManager.mergeGameDataFromResource(gameData, // "gameData/characterCreation.xml"); String gameDataLocalDirectory = "./data"; gameDataService.mergeGameDataFromLocalDirectory(gameDataLocalDirectory); // Situation<?> gameStartSituation = gameData.getSituations().get( // gameData.getGameStartSituation()); } public static void initTechnicalOptionsAndSituations() { GameDataService gameDataService = GameBeansContext .getBean(GameDataService.class); // InventoryOption inventoryOption = GameBeansContext // .getBean(InventoryOption.class); // GoBackOption goBackOption = GameBeansContext // .getBean(GoBackOption.class); for (Option option : new Option[] { InventoryOption.INSTANCE, GoBackOption.INSTANCE, GameMenuOption.INSTANCE }) { gameDataService.getGameData().getOptions() .put(option.getId(), option); } for (Situation situation : new Situation[] { GameMenuSituation.INSTANCE }) { gameDataService.getGameData().getSituations() .put(situation.getId(), situation); } gameDataService.getGameData().postMerge(); } public static void initGuiResources() { GameDataService gameDataService = GameBeansContext .getBean(GameDataService.class); for (Entry<String, String> entry : gameDataService.getGameData() .getOptionImageIconDescriptors().entrySet()) { Image image = FileUtil.getResourceAsImage(entry.getValue()); ImageIcon imageIcon = new ImageIcon(image, entry.getKey()); gameDataService.getImageIcons().put(entry.getKey(), imageIcon); } } public static void startNewGame() { // Game.gameState = new GameState(); GameStateService gameStateService = GameBeansContext .getBean(GameStateService.class); GameDataService gameDataService = GameBeansContext .getBean(GameDataService.class); GameTimeService gameTimeService = GameBeansContext .getBean(GameTimeService.class); SituationService situationService = GameBeansContext .getBean(SituationService.class); Calendar calendar = Calendar.getInstance(); calendar.set(1492, Calendar.AUGUST, 2, 22, 16); gameStateService.getGameState().setTime(calendar.getTimeInMillis()); gameTimeService.advanceTime(1L); Situation startSituation = gameDataService.getGameData() .getSituations().get(GameMenuSituation.ID); gameStateService.addSituation(startSituation, true); situationService.playCurrentSituation(); } public static void main(String[] args) { try { // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (InstantiationException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } /* Turn off metal's use bold fonts */ UIManager.put("swing.boldMetal", Boolean.FALSE); // Schedule a job for the event dispatch thread: // creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { initContextBeans(); createAndShowGUI(); initGameData(); initTechnicalOptionsAndSituations(); initGuiResources(); startNewGame(); } }); } }
Java
package org.clockworkmages.games.anno1186; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.clockworkmages.games.anno1186.dao.GameObjectsList; import org.clockworkmages.games.anno1186.dao.ImageIconDescriptor; import org.clockworkmages.games.anno1186.gui.GameUiUtil; import org.clockworkmages.games.anno1186.model.Fetish; import org.clockworkmages.games.anno1186.model.character.Mutation; import org.clockworkmages.games.anno1186.model.character.NonPlayerCharacter; import org.clockworkmages.games.anno1186.model.character.Skill; import org.clockworkmages.games.anno1186.model.character.Stat; import org.clockworkmages.games.anno1186.model.effect.Condition; import org.clockworkmages.games.anno1186.model.effect.Effect; import org.clockworkmages.games.anno1186.model.effect.Perk; import org.clockworkmages.games.anno1186.model.item.EquipmentSlot; import org.clockworkmages.games.anno1186.model.item.Item; import org.clockworkmages.games.anno1186.model.map.tactical.GameAreaDO; import org.clockworkmages.games.anno1186.model.map.tactical.SimpleTileObject; import org.clockworkmages.games.anno1186.model.map.tactical.TileObject; import org.clockworkmages.games.anno1186.model.option.GenericOption; import org.clockworkmages.games.anno1186.model.option.Option; import org.clockworkmages.games.anno1186.model.situation.ExplorableGameEvent; import org.clockworkmages.games.anno1186.model.situation.GenericSituation; import org.clockworkmages.games.anno1186.model.situation.Situation; public class GameData { private Map<String, List<ExplorableGameEvent>> eventPools = new HashMap<String, List<ExplorableGameEvent>>(); private Map<String, Situation> situations = new HashMap<String, Situation>(); private Map<String, Option> namedOptions = new HashMap<String, Option>(); private List<GenericOption> locatedOptions = new ArrayList<GenericOption>(); private Map<String, Stat> stats = new HashMap<String, Stat>(); private Map<String, Skill> skills = new HashMap<String, Skill>(); private Map<String, Perk> perks = new HashMap<String, Perk>(); private Map<String, Condition> conditions = new HashMap<String, Condition>(); private Map<String, EquipmentSlot> equipmentSlots = new LinkedHashMap<String, EquipmentSlot>(); private Map<String, Mutation> mutations = new HashMap<String, Mutation>(); private Map<String, String> optionImageIconDescriptors = new HashMap<String, String>(); private Map<String, Item> items = new HashMap<String, Item>(); private Map<String, NonPlayerCharacter> npcs = new HashMap<String, NonPlayerCharacter>(); private Map<String, Fetish> fetishes = new HashMap<String, Fetish>(); private List<Effect> baseEffects = new ArrayList<Effect>(); private String gameStartSituation; private Map<String, TileObject> tileObjects = new HashMap<String, TileObject>(); private Map<String, GameAreaDO> gameAreas = new HashMap<String, GameAreaDO>(); public void merge(GameObjectsList gameObjects) { for (ImageIconDescriptor imageIconDescriptor : gameObjects.getIcons()) { optionImageIconDescriptors.put(imageIconDescriptor.getId(), imageIconDescriptor.getPath()); } for (SimpleTileObject tileObject : gameObjects.getTileObjects()) { this.tileObjects.put(tileObject.getId(), tileObject); } for (GameAreaDO gameAreaDO : gameObjects.getGameAreas()) { this.gameAreas.put(gameAreaDO.getId(), gameAreaDO); } for (Stat stat : gameObjects.getStats()) { stats.put(stat.getId(), stat); } for (Skill skill : gameObjects.getSkills()) { skills.put(skill.getId(), skill); } for (Perk perk : gameObjects.getPerks()) { perks.put(perk.getId(), perk); } for (Condition condition : gameObjects.getConditions()) { conditions.put(condition.getId(), condition); } for (EquipmentSlot equipmentSlot : gameObjects.getEquipmentSlots()) { equipmentSlots.put(equipmentSlot.getId(), equipmentSlot); } for (Item item : gameObjects.getItems()) { items.put(item.getId(), item); } for (NonPlayerCharacter npc : gameObjects.getNpcs()) { npcs.put(npc.getId(), npc); } for (Fetish fetish : gameObjects.getFetishes()) { fetishes.put(fetish.getId(), fetish); } for (Mutation mutation : gameObjects.getMutations()) { mutations.put(mutation.getId(), mutation); } this.baseEffects.addAll(gameObjects.getBaseEffects()); for (GenericOption option : gameObjects.getOptions()) { if (option.getId() != null) { namedOptions.put(option.getId(), option); } if (option.getSituationId() != null) { locatedOptions.add(option); } } for (GenericSituation situation : gameObjects.getSituations()) { if (situation.getId() != null) { situations.put(situation.getId(), situation); } if (situation.getAreaType() != null) { String situationPoolId = situation.getAreaType(); List<ExplorableGameEvent> pool = eventPools .get(situationPoolId); if (pool == null) { pool = new ArrayList<ExplorableGameEvent>(); eventPools.put(situationPoolId, pool); } pool.add(situation); } } if (gameObjects.getGameStartSituation() != null) { this.gameStartSituation = gameObjects.getGameStartSituation(); } } /** * Post process the named options (options whose id can be referenced by a * placeholder-option of some Situations) and located Options (options that * are defined outside of the Situation's original file but that should be * added to that Situation in order to extend it). */ public void postMerge() { // process named Options: Map<Integer, String> replacements = new HashMap<Integer, String>(); for (Situation situation : situations.values()) { replacements.clear(); List<Option> options = situation.getOptions(); for (int i = 0; i < situation.getOptions().size(); i++) { Option option = situation.getOptions().get(i); if (option instanceof GenericOption) { String reference = ((GenericOption) option).getRef(); if (reference != null) { replacements.put(i, reference); } } } for (Entry<Integer, String> entry : replacements.entrySet()) { int index = entry.getKey(); String reference = entry.getValue(); Option namedOption = this.namedOptions.get(reference); options.remove(index); options.add(index, namedOption); } } // process located Options: for (GenericOption option : this.locatedOptions) { String situationId = option.getSituationId(); Situation situation = situations.get(situationId); if (situation == null) { GameUiUtil .logError("Invalid Situation reference in a locatedOption: " + situationId); } else { situation.getOptions().add(option); } } } public Map<String, List<ExplorableGameEvent>> getEventPools() { return eventPools; } public Map<String, Situation> getSituations() { return situations; } public Map<String, Option> getOptions() { return namedOptions; } public Map<String, EquipmentSlot> getEquipmentSlots() { return equipmentSlots; } public Map<String, Perk> getPerks() { return perks; } public String getGameStartSituation() { return gameStartSituation; } public Map<String, Stat> getStats() { return stats; } public Map<String, Skill> getSkills() { return skills; } public Map<String, Mutation> getMutations() { return mutations; } public Map<String, String> getOptionImageIconDescriptors() { return optionImageIconDescriptors; } public Map<String, Condition> getConditions() { return conditions; } public Map<String, Item> getItems() { return items; } public List<Effect> getBaseEffects() { return baseEffects; } public Map<String, NonPlayerCharacter> getNpcs() { return npcs; } public Map<String, Fetish> getFetishes() { return fetishes; } public Map<String, TileObject> getTileObjects() { return tileObjects; } public Map<String, GameAreaDO> getGameAreas() { return gameAreas; } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Image; public class MainTextPanel extends AnimatedTextPane { private AnimatedImage sunImage; private AnimatedImage moonImage; public MainTextPanel(Image iSunImage, Image iMoonImage) { sunImage = new AnimatedCircularImage(iSunImage, 0.50, 1, 0.4, true); sunImage.setTargetState(1, 6000); getImages().put("sun", sunImage); moonImage = new AnimatedCircularImage(iMoonImage, 0.50, 1, 0.4, true); moonImage.setTargetState(1, 6000); getImages().put("moon", moonImage); } public AnimatedImage getSunImage() { return sunImage; } public AnimatedImage getMoonImage() { return moonImage; } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Image; public class TotemPanel extends AnimatedPanel { private AnimatedImage totemImage; public TotemPanel(Image iTotemImage) { totemImage = new AnimatedSlidingInImage(iTotemImage); getImages().put("totem", totemImage); setOpaque(false); } public AnimatedImage getTotemImage() { return totemImage; } }
Java
package org.clockworkmages.games.anno1186.gui; import java.io.PrintWriter; import java.io.StringWriter; import org.clockworkmages.games.anno1186.GameBeansContext; import org.clockworkmages.games.anno1186.GameGuiService; public class GameUiUtil { public static void logError(String message) { System.out.println(message); GameBeansContext .getBean(GameGuiService.class) .getTextPane() .addInfoToBuffer("\n[ERROR]" + message + "\n", FontStyleConstants.RED_BOLD); System.out.println(message); } public static void logError(Exception e) { StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); logError(errors.toString()); } public static void logError(String message, Exception e) { StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); logError(message + "\n" + errors.toString()); } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Graphics; import java.awt.Image; import javax.swing.JPanel; import org.clockworkmages.games.anno1186.GameBeansContext; import org.clockworkmages.games.anno1186.GameState; import org.clockworkmages.games.anno1186.GameStateService; import org.clockworkmages.games.anno1186.dao.FileUtil; import org.clockworkmages.games.anno1186.model.map.tactical.GameArea; import org.clockworkmages.games.anno1186.model.map.tactical.Tile; import org.clockworkmages.games.anno1186.model.map.tactical.TileObject; public class LocalMapPanel extends JPanel { @Override public void paintComponent(final Graphics g) { GameStateService gameStateService = GameBeansContext .getBean(GameStateService.class); if (gameStateService == null) { return; } GameState gameState = gameStateService.getGameState(); GameArea gameArea = gameState.getGameArea(); if (gameArea == null) { return; } super.paintComponent(g); int myX = gameState.getLocalMapX(); int myY = gameState.getLocalMapY(); for (int row = 0; row < 7; row++) { int startAt = 0; // = Math.abs(row - 3) - 1; // if (startAt == -1) { // startAt = 0; // } for (int column = 6; column >= 0; column--) { if (column >= startAt && column <= 6 - startAt) { int tileY = myY - row + 3; int tileX = myX + column - 3; if (tileX >= 0 && tileX < gameArea.getTiles().length && tileY >= 0 && tileY < gameArea.getTiles()[tileX].length) { Tile tile = gameArea.getTiles()[tileX][tileY]; for (TileObject tileObject : tile.getTileObjects()) { String image = tileObject.getImage(); if (image != null) { // TODO all Images should be cached Image tileImage = FileUtil .getResourceAsImage("images/map/" + image + ".png"); // final BufferedImage tileImage = ImageIO // .read(new URL( // "classpath://images/map/" // + image + ".png")); g.drawImage(tileImage, (column) * 40 + (row - 2) * 18 // - tileImage.getWidth(null) + 40, (row) * 20 // - tileImage.getHeight(null) + 28, null); } } } if (row == 3 && column == 3) { Image tileImage = FileUtil .getResourceAsImage("images/map/" + "hummie" + ".png"); g.drawImage(tileImage, (column) * 40 + (row - 2) * 18 // - tileImage.getWidth(null) + 40, (row) * 20 // - tileImage.getHeight(null) + 28, null); } } } } }; }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Graphics; import java.text.SimpleDateFormat; import java.util.Date; import org.clockworkmages.games.anno1186.GameStateService; import org.clockworkmages.games.anno1186.Injected; import org.clockworkmages.games.anno1186.model.character.PlayerCharacter; import org.clockworkmages.games.anno1186.model.character.StatConstants; import org.clockworkmages.games.anno1186.util.MathUtil; public class StatsInfoTextPane extends InfoTextPane { @Injected private GameStateService gameStateService; private SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm"); @Override public void paint(Graphics g) { if (gameStateService != null) { PlayerCharacter pc = gameStateService.getGameState().getCharacter(); int level = pc.getLevel(); String statsInfo = "\n\n" + formatter.format(new Date(gameStateService.getGameState() .getTime())) + "\n\n" + // "Health: " + pc.getBaseStatAsInt(StatConstants.HEALTH) + "/" + pc.getDerivateAsInt(StatConstants.D_MAX_HEALTH) + "\n" + // "Stamina: " + pc.getBaseStatAsInt(StatConstants.STAMINA) + "/" + pc.getDerivateAsInt(StatConstants.D_MAX_STAMINA) + "\n" + // "Fate: " + pc.getBaseStatAsInt(StatConstants.FATE) + "/" + pc.getEffectiveStatAsInt(StatConstants.MAX_FATE) + "\n" + // "Level: " + level + " (" + (pc.getExperience() - MathUtil.experienceNeededToLevelUp(level)) + "/" + (MathUtil.experienceNeededToLevelUp(level + 1) - MathUtil .experienceNeededToLevelUp(level)) + ")" + "\n" + // "Gold: " + pc.getGold(); clearText(); appendText(statsInfo); } super.paint(g); } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.util.LinkedHashMap; import java.util.Map; import javax.swing.JPanel; import javax.swing.Timer; public class AnimatedPanel extends JPanel implements ActionListener { private Map<String, AnimatedImage> images = new LinkedHashMap<String, AnimatedImage>(); private Timer timer; private long lastPerformed = System.currentTimeMillis(); public AnimatedPanel() { super(); timer = new Timer(50, this); timer.setInitialDelay(100); timer.start(); this.addComponentListener(new ComponentAdapter() { @Override public void componentResized(final ComponentEvent e) { for (AnimatedImage animatedImage : images.values()) { // TODO } AnimatedPanel.this.repaint(); } }); } public Map<String, AnimatedImage> getImages() { return images; } @Override public void paintComponent(final Graphics g) { long interval = System.currentTimeMillis() - lastPerformed; lastPerformed = System.currentTimeMillis(); for (AnimatedImage animatedImage : images.values()) { animatedImage.update(interval); animatedImage.draw(g, this); } super.paintComponent(g); } @Override public void actionPerformed(ActionEvent e) { this.repaint(); } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Graphics; import java.awt.Image; import javax.swing.JComponent; public class AnimatedCircularImage extends AnimatedImage { /** * Location of the center as a 0-100% of the panel's width. */ private double centerX; /** * Location of the center as a 0-100% of the panel's height. */ private double centerY; /** * Location of the center as a 0-100% of the panel's width or height * (depending on whether radiusIsX=true). */ private double radius; private boolean radiusIsX; public AnimatedCircularImage(Image image, double centerX, double centerY, double radius, boolean radiusIsX) { super(image); this.centerX = centerX; this.centerY = centerY; this.radius = radius; this.radiusIsX = radiusIsX; } @Override public void draw(Graphics g, JComponent panel) { double radiusInPixels; if (radiusIsX) { radiusInPixels = panel.getWidth() * this.radius; } else { radiusInPixels = panel.getHeight() * this.radius; } double x = centerX * panel.getWidth() + Math.sin(2 * Math.PI * (1 - getState())) * radiusInPixels // center the image at the selected point - getImage().getWidth(null) / 2; double y = centerY * panel.getHeight() + Math.cos(2 * Math.PI * (1 - getState())) * radiusInPixels // center the image at the selected point - getImage().getHeight(null) / 2; ; g.drawImage(getImage(), (int) x, (int) y, null); } }
Java
package org.clockworkmages.games.anno1186.gui; public interface FontStyleConstants { public static final String REGULAR = "regular"; public static final String ITALIC = "i"; public static final String BOLD = "b"; public static final String LARGE = "large"; public static final String RED_BOLD = "rb"; public static final String OPTIONLIST = "options"; public static final String TEXTINPUT = "textinput"; }
Java
package org.clockworkmages.games.anno1186.gui; public interface GameUiConstants { String EXPLORATION_CARD = "CARD_EXPLORE"; String OPTION_PANEL_TEXT_CARD = "textOption"; String OPTION_PANEL_LIST_CARD = "listOption"; String IMAGE_TEXT_SUN = "sun"; String IMAGE_TEXT_MOON = "moon"; String IMAGE_TOTEM = "totem"; }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.CardLayout; import javax.swing.JPanel; import org.clockworkmages.games.anno1186.GameBeansContext; import org.clockworkmages.games.anno1186.GameGuiService; public class GamePanel extends JPanel { private LocalExplorationPanel explorationPanel; public GamePanel() { CardLayout layout = new CardLayout(); this.setLayout(layout); this.setOpaque(false); explorationPanel = new LocalExplorationPanel(); this.add(explorationPanel, GameUiConstants.EXPLORATION_CARD); layout.show(this, GameUiConstants.EXPLORATION_CARD); GameGuiService gameGuiService = GameBeansContext .getBean(GameGuiService.class); gameGuiService.setGamePanel(this); } public LocalExplorationPanel getExplorationPanel() { return explorationPanel; } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Graphics; import java.awt.Image; import javax.swing.JComponent; public class AnimatedSlidingInImage extends AnimatedImage { public AnimatedSlidingInImage(Image image) { super(image); } @Override public void draw(Graphics g, JComponent panel) { double x = 0.5d * panel.getWidth() // center the image at the center of the panel - getImage().getWidth(null) / 2; double y = panel.getHeight() - getImage().getHeight(null) * getState(); g.drawImage(getImage(), (int) x, (int) y, null); } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Graphics; import java.awt.Image; import javax.swing.JComponent; public abstract class AnimatedImage { /** * A 0-1 state of the image. It may be defining the location, size or * opacity of the image; or a combination of any of those. */ private double state = 0d; private double targetState = 0d; private double timeToGetToTargetState = 0; private Image image; public AnimatedImage(Image image) { this.image = image; } public abstract void draw(Graphics g, JComponent panel); public void setTargetState(double targetState, double timeToGetToTargetState) { this.targetState = targetState; this.timeToGetToTargetState = timeToGetToTargetState; } public void update(long interval) { if (timeToGetToTargetState <= 0) { return; } if (interval >= timeToGetToTargetState) { state = targetState; } else { double change = (state - targetState) * (interval / timeToGetToTargetState); state = state - change; } // GameUiUtil.logError(interval + " " + state); timeToGetToTargetState = timeToGetToTargetState - interval; if (timeToGetToTargetState <= 0) { timeToGetToTargetState = 0; while (this.state > 1) { this.state = this.state - 1; } while (this.state < 0) { this.state = this.state + 1; } } } public double getState() { return state; } protected Image getImage() { return image; } public void setState(double state) { this.state = state; } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Component; import java.util.Map; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.ListCellRenderer; import javax.swing.SwingConstants; import org.clockworkmages.games.anno1186.GameBeansContext; import org.clockworkmages.games.anno1186.GameDataService; import org.clockworkmages.games.anno1186.model.option.Option; import org.clockworkmages.games.anno1186.text.TextUtil; public class OptionListCellRenderer implements ListCellRenderer<Option> { // private final ListCellRenderer<Option> defaultRenderer; // // public OptionListCellRenderer(ListCellRenderer<Option> cellRenderer) { // this.defaultRenderer = cellRenderer; // } @Override public Component getListCellRendererComponent(JList<? extends Option> list, Option option, int index, boolean isSelected, boolean cellHasFocus) { // JLabel result = // (JLabel)defaultRenderer.getListCellRendererComponent(list, // value, index, isSelected, cellHasFocus); GameDataService gameDataService = GameBeansContext .getBean(GameDataService.class); Map<String, ImageIcon> imageIcons = gameDataService.getImageIcons(); String text = (index + 1) + ". " + TextUtil.parse(option.getLabel()); ImageIcon imageIcon = null; if (option.getIcon() != null) { imageIcon = imageIcons.get(option.getIcon()); if (imageIcon == null) { GameUiUtil.logError("Invalid icon reference - " + option.getIcon()); } } if (imageIcon == null) { imageIcon = imageIcons.get("none"); } JLabel result = new JLabel(text, imageIcon, SwingConstants.LEFT); return result; } }
Java
package org.clockworkmages.games.anno1186.gui; public abstract class InfoTextPane extends AnimatedTextPane { public InfoTextPane() { super(false); } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import org.clockworkmages.games.anno1186.model.option.Option; public class OptionTextInputKeyListener implements KeyListener { private Option option; @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_ENTER) { option.select(); } } public Option getOption() { return option; } public void setOption(Option option) { this.option = option; } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.swing.JTextPane; import javax.swing.Timer; import javax.swing.text.StyledDocument; import org.clockworkmages.games.anno1186.model.common.Pair; public class AnimatedTextPane extends JTextPane implements ActionListener { private Map<String, AnimatedImage> images = new LinkedHashMap<String, AnimatedImage>(); private Timer timer; private long lastPerformed = System.currentTimeMillis(); private List<Pair<String, String>> infoTextAndFontIdBuffer = new ArrayList<Pair<String, String>>(); public AnimatedTextPane() { this(true); } public AnimatedTextPane(boolean animated) { super(); setOpaque(false); if (animated) { timer = new Timer(50, this); timer.setInitialDelay(100); timer.start(); this.addComponentListener(new ComponentAdapter() { @Override public void componentResized(final ComponentEvent e) { for (AnimatedImage animatedImage : images.values()) { // TODO } AnimatedTextPane.this.repaint(); } }); } } public Map<String, AnimatedImage> getImages() { return images; } @Override public void paintComponent(final Graphics g) { long interval = System.currentTimeMillis() - lastPerformed; lastPerformed = System.currentTimeMillis(); for (AnimatedImage animatedImage : images.values()) { animatedImage.update(interval); animatedImage.draw(g, this); } super.paintComponent(g); } @Override public void actionPerformed(ActionEvent e) { this.repaint(); } public void clearText() { StyledDocument doc = getStyledDocument(); try { doc.remove(0, doc.getLength()); } catch (Exception e) { GameUiUtil.logError(e); } } public void removeTrailing(String trailingCharacters) { StyledDocument doc = getStyledDocument(); try { String text = doc.getText(0, doc.getLength()); // check for last index, in case there's e.g. an empty space after // the trailing character int lastIndex = text.lastIndexOf(trailingCharacters); if (lastIndex > -1) { doc.remove(lastIndex, doc.getLength() - lastIndex); } } catch (Exception e) { GameUiUtil.logError(e); } } public void appendText(String message) { String[] as = message.split("\\{f"); for (String s : as) { String fontStyleId; String text; int endOfFontDefinition = s.indexOf("}"); if (endOfFontDefinition == -1) { // assume that's the last font-per-text definition in the text: text = s; fontStyleId = FontStyleConstants.REGULAR; } else if (endOfFontDefinition == 0) { // the {f} tag which means we should switch from whatever // special font was being used before to the regular font. text = s.substring(endOfFontDefinition + 1); fontStyleId = FontStyleConstants.REGULAR; } else { // something like {f:b}, which means we should switch to the // special font: text = s.substring(endOfFontDefinition + 1); if (!s.startsWith(":")) { // not good, that's some incorrect definition GameUiUtil .logError("Unrecognizable font definition in the text: {f" + s); fontStyleId = FontStyleConstants.REGULAR; } else { fontStyleId = s.substring(1, endOfFontDefinition); } } appendText(text, fontStyleId); } } public synchronized void appendText(String message, String fontStyleId) { StyledDocument doc = getStyledDocument(); try { doc.insertString(doc.getLength(), message, doc.getStyle(fontStyleId)); } catch (Exception e) { GameUiUtil.logError(e); } } public void addInfoToBuffer(String infoText) { this.infoTextAndFontIdBuffer.add(new Pair<String, String>(infoText, FontStyleConstants.RED_BOLD)); } public void addInfoToBuffer(String infoText, String fontStyleId) { this.infoTextAndFontIdBuffer.add(new Pair<String, String>(infoText, fontStyleId)); } public void flushInfoBuffer() { for (Pair<String, String> infoTextAndFontStyleId : this.infoTextAndFontIdBuffer) { appendText(infoTextAndFontStyleId.getFirst(), infoTextAndFontStyleId.getSecond()); } this.infoTextAndFontIdBuffer.clear(); } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.Button; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JPanel; import org.clockworkmages.games.anno1186.situations.gameoptions.options.GameMenuOption; import org.clockworkmages.games.anno1186.situations.inventory.options.InventoryOption; import org.clockworkmages.games.anno1186.situations.sexsettings.options.SexSettingsOption; import org.clockworkmages.games.anno1186.situations.status.options.CharacterStatusOption; public class GeneralOptionsPanel extends JPanel implements ActionListener { private static final String AC_INVENTORY = "Inventory"; private static final String AC_STATUS = "Status"; private static final String AC_SEXSETTINGS = "Sex Settings"; private static final String AC_GAME_MENU = "Game Menu"; public GeneralOptionsPanel() { this.setOpaque(false); Button button; button = new Button("Inventory"); button.setActionCommand(AC_INVENTORY); button.addActionListener(this); button.setFocusable(false); this.add(button); button = new Button("Status"); button.setActionCommand(AC_STATUS); button.addActionListener(this); button.setFocusable(false); this.add(button); button = new Button("Settings"); button.setActionCommand(AC_SEXSETTINGS); button.addActionListener(this); button.setFocusable(false); this.add(button); button = new Button("Game Menu"); button.setActionCommand(AC_GAME_MENU); button.addActionListener(this); button.setFocusable(false); this.add(button); } @Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { case AC_INVENTORY: InventoryOption.INSTANCE.select(); break; case AC_STATUS: CharacterStatusOption.INSTANCE.select(); break; case AC_SEXSETTINGS: SexSettingsOption.INSTANCE.select(); break; case AC_GAME_MENU: GameMenuOption.INSTANCE.select(); break; } } }
Java
package org.clockworkmages.games.anno1186.gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Image; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JLayeredPane; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.KeyStroke; import javax.swing.ToolTipManager; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; import javax.swing.text.StyledDocument; import org.clockworkmages.games.anno1186.GameBeansContext; import org.clockworkmages.games.anno1186.controllers.LocalMapMovementController; import org.clockworkmages.games.anno1186.dao.FileUtil; import org.clockworkmages.games.anno1186.model.option.Option; /** * Collection of GUI elements for the default game screen. */ public class LocalExplorationPanel extends JPanel { private MainTextPanel textPane; private InfoTextPane statsPanel; private JList<Option> optionList; private JTextField optionTextInput; private OptionTextInputKeyListener optionTextInputKeyListener; // private JPanel optionCardPanel; private TotemPanel leftTotemPanel; private TotemPanel rightTotemPanel; private LocalMapPanel localMapPanel; public LocalExplorationPanel() { this.setFocusable(true); this.requestFocusInWindow(); this.setLayout(new BorderLayout()); this.setPreferredSize(new Dimension(650, 605)); // JButton optionsbutton = new JButton("Options"); // add(optionsbutton, BorderLayout.PAGE_START); final Image sunImage = FileUtil.getResourceAsImage("images/sun.png"); final Image moonImage = FileUtil.getResourceAsImage("images/moon.png"); textPane = new MainTextPanel(sunImage, moonImage); StyledDocument doc = textPane.getStyledDocument(); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(450, 450)); scrollPane.setOpaque(true); scrollPane.setBorder(null); JPanel statsTotemsOptionsPanel = new JPanel(); statsTotemsOptionsPanel.setLayout(new BorderLayout()); statsTotemsOptionsPanel.setPreferredSize(new Dimension(180, 700)); add(statsTotemsOptionsPanel, BorderLayout.EAST); // final Image guiBottomImage = FileUtil // .getResourceAsImage("images/gui_bottom.png"); // JPanel bottomPanel = new JPanel() { // @Override // public void paintComponent(final Graphics g) { // super.paintComponent(g); // g.drawImage(guiBottomImage, 0, 0, null); // } // }; // bottomPanel.setLayout(new BorderLayout()); // add(bottomPanel, BorderLayout.PAGE_END); localMapPanel = new LocalMapPanel(); // localMapPanel.setPreferredSize(new Dimension(270, 220)); // mapStatsOptionsPanel.add(localMapPanel, BorderLayout.CENTER); final Image totemImage = FileUtil .getResourceAsImage("images/totem.png"); leftTotemPanel = new TotemPanel(totemImage); leftTotemPanel.setPreferredSize(new Dimension(50, 450)); statsTotemsOptionsPanel.add(leftTotemPanel, BorderLayout.WEST); leftTotemPanel.getTotemImage().setTargetState(0, 1000); rightTotemPanel = new TotemPanel(totemImage); rightTotemPanel.setPreferredSize(new Dimension(50, 450)); statsTotemsOptionsPanel.add(rightTotemPanel, BorderLayout.EAST); rightTotemPanel.getTotemImage().setTargetState(0, 1000); statsPanel = new StatsInfoTextPane(); statsPanel.setPreferredSize(new Dimension(180, 155)); statsTotemsOptionsPanel.add(statsPanel, BorderLayout.CENTER); GameBeansContext.register(statsPanel); GeneralOptionsPanel generalOptionsPanel = new GeneralOptionsPanel(); generalOptionsPanel.setPreferredSize(new Dimension(180, 155)); statsTotemsOptionsPanel.add(generalOptionsPanel, BorderLayout.PAGE_END); // Options panel: ToolTipManager toolTipManager = ToolTipManager.sharedInstance(); // optionCardPanel = new JPanel(new CardLayout()); // optionCardPanel.setOpaque(false); // optionCardPanel.setPreferredSize(new Dimension(450, 155)); // bottomPanel.add(optionCardPanel, BorderLayout.CENTER); // JPanel textOptionPanel = new JPanel(); // textOptionPanel.setOpaque(false); // textOptionPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // optionCardPanel.add(textOptionPanel, // GameUiConstants.OPTION_PANEL_TEXT_CARD); OptionTextInputKeyListener optionTextInputKeyListener = new OptionTextInputKeyListener(); optionTextInput = new JTextField(10); optionTextInput.setMaximumSize(new Dimension(100, 25)); optionTextInput.addKeyListener(optionTextInputKeyListener); // textOptionPanel.add(optionTextInput); optionList = new JList<Option>() { @Override public String getToolTipText(MouseEvent event) { Point p = event.getPoint(); int location = locationToIndex(p); if (location > -1) { String tip = ((Option) getModel().getElementAt(location)) .getTooltip(); return tip; } return ""; } }; optionList.setOpaque(false); ((JLabel) optionList.getCellRenderer()).setOpaque(false); optionList.setCellRenderer(new OptionListCellRenderer()); optionList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent arg0) { if (!arg0.getValueIsAdjusting()) { Option selectedOption = optionList.getSelectedValue(); if (selectedOption != null) { selectedOption.select(); } } } }); toolTipManager.registerComponent(optionList); // JPanel listOptionPanel = new JPanel(); // listOptionPanel.setOpaque(false); // listOptionPanel.setLayout(new GridLayout(1, 1)); // listOptionPanel.add(optionList); // optionCardPanel.add(listOptionPanel, // GameUiConstants.OPTION_PANEL_LIST_CARD); // ((CardLayout) optionCardPanel.getLayout()).show(optionCardPanel, // "listOption"); final LocalMapMovementController mapMovementController = GameBeansContext .getBean(LocalMapMovementController.class); Action processMove = new AbstractAction() { public void actionPerformed(ActionEvent e) { mapMovementController.move(e.getActionCommand()); } }; getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( KeyStroke.getKeyStroke('w'), "processMove"); getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( KeyStroke.getKeyStroke('d'), "processMove"); getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( KeyStroke.getKeyStroke('s'), "processMove"); getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( KeyStroke.getKeyStroke('a'), "processMove"); getActionMap().put("processMove", processMove); addStylesToDocument(doc); JLayeredPane textAndMapPanel = new JLayeredPane(); textAndMapPanel.setBounds(0, 0, 600, 400); textAndMapPanel.setPreferredSize(new Dimension(300, 310)); localMapPanel.setBounds(0, 0, 300, 300); textAndMapPanel.add(localMapPanel, Integer.valueOf(2), 0); scrollPane.setBounds(100, 100, 300, 300); textAndMapPanel.add(scrollPane, Integer.valueOf(3), 0); // JPanel textAndMapPanel = new JPanel(); // textAndMapPanel.setLayout(new BorderLayout()); // textAndMapPanel.add(scrollPane, BorderLayout.PAGE_START); // textAndMapPanel.add(localMapPanel, BorderLayout.PAGE_END); add(textAndMapPanel, BorderLayout.WEST); } protected void addStylesToDocument(StyledDocument doc) { // Initialize some styles. Style def = StyleContext.getDefaultStyleContext().getStyle( StyleContext.DEFAULT_STYLE); Style regular = doc.addStyle(FontStyleConstants.REGULAR, def); StyleConstants.setFontFamily(def, "SansSerif"); Style s = doc.addStyle(FontStyleConstants.ITALIC, regular); StyleConstants.setItalic(s, true); s = doc.addStyle(FontStyleConstants.BOLD, regular); StyleConstants.setBold(s, true); s = doc.addStyle(FontStyleConstants.RED_BOLD, regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.RED); s = doc.addStyle(FontStyleConstants.LARGE, regular); StyleConstants.setFontSize(s, 16); // option list: s = doc.addStyle(FontStyleConstants.OPTIONLIST, regular); StyleConstants.setFontSize(s, 16); Box optionListBox = Box.createVerticalBox(); optionListBox.add(optionList); optionListBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0)); StyleConstants.setComponent(s, optionListBox); // text input: s = doc.addStyle(FontStyleConstants.TEXTINPUT, regular); StyleConstants.setFontSize(s, 16); Box textInputBox = Box.createVerticalBox(); textInputBox.add(optionTextInput); textInputBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0)); StyleConstants.setComponent(s, textInputBox); } public MainTextPanel getTextPane() { return textPane; } public InfoTextPane getBottomLeftPanel() { return statsPanel; } public JList<Option> getOptionList() { return optionList; } public JTextField getOptionTextInput() { return optionTextInput; } public OptionTextInputKeyListener getOptionTextInputKeyListener() { return optionTextInputKeyListener; } // public JPanel getOptionCardPanel() { // return optionCardPanel; // } public TotemPanel getLeftTotemPanel() { return leftTotemPanel; } public TotemPanel getRightTotemPanel() { return rightTotemPanel; } public LocalMapPanel getLocalMapPanel() { return localMapPanel; } }
Java
package org.clockworkmages.games.anno1186.scripting.tools; public interface BuilderWrapper { ScriptBuilder iff(); void then(String s); void elsee(String s); ScriptBuilder elseIf(); }
Java
package org.clockworkmages.games.anno1186.scripting.tools; import org.clockworkmages.games.anno1186.model.effect.Effect; public class ScriptBuilder { public static final String LEVEL = "level"; protected StringBuffer sb; protected BuilderWrapper parent; public ScriptBuilder() { this.sb = new StringBuffer(""); } public ScriptBuilder(StringBuffer sb) { this.sb = sb; } public ScriptBuilder(BuilderWrapper parent) { this(); this.parent = parent; } public ScriptBuilder(StringBuffer sb, BuilderWrapper parent) { this(sb); this.parent = parent; } public static MeScriptBuilder ME() { return new MeScriptBuilder(); } public static UtilScriptBuilder UTIL() { return new UtilScriptBuilder(); } public static PlotScriptBuilder PLOT() { return new PlotScriptBuilder(); } public static ScriptBuilder NOT() { StringBuffer sb = new StringBuffer("!"); return new ScriptBuilder(sb); } public ScriptBuilder not() { sb.append("!"); return this; } public static ScriptBuilder NEW() { StringBuffer sb = new StringBuffer(""); return new ScriptBuilder(sb); } public MeScriptBuilder me() { return new MeScriptBuilder(sb, parent); } public EnemyScriptBuilder enemy() { return new EnemyScriptBuilder(sb, parent); } public UtilScriptBuilder util() { return new UtilScriptBuilder(sb, parent); } public PlotScriptBuilder plot() { return new PlotScriptBuilder(sb, parent); } public SituationScriptBuilder situation() { return new SituationScriptBuilder(sb, parent); } public ScriptBuilder gt() { sb.append(">"); return this; } public ScriptBuilder gt(int value) { sb.append(">" + value); return this; } public ScriptBuilder ge() { sb.append(">="); return this; } public ScriptBuilder ge(int value) { sb.append(">=" + value); return this; } public ScriptBuilder lt() { sb.append("<"); return this; } public ScriptBuilder lt(int value) { sb.append("<" + value); return this; } public ScriptBuilder le() { sb.append("<="); return this; } public ScriptBuilder le(int value) { sb.append("<" + value); return this; } public ScriptBuilder equals(String value) { sb.append("==" + value); return this; } public ScriptBuilder equalsString(String value) { sb.append("=='" + value + "'"); return this; } public ScriptBuilder append(String value) { sb.append(value); return this; } public ScriptBuilder and() { sb.append(" && "); return this; } @Override public String toString() { return sb.toString(); } public ScriptBuilder iff() { return parent.iff(); } public ScriptBuilder then(String s) { parent.then(s); return this; } public ScriptBuilder elsee(String s) { parent.elsee(s); return this; } public ScriptBuilder elseIf() { return parent.elseIf(); } public BuilderWrapper getParent() { return parent; } public String asText() { return parent.toString(); } public Effect compileEffect() { return ((EffectBuilder) parent).compile(); } public String asPlaceholder() { return "${" + sb.toString() + "}"; } }
Java
package org.clockworkmages.games.anno1186.scripting.tools; import org.clockworkmages.games.anno1186.model.effect.Effect; public class EffectBuilder implements BuilderWrapper { private ScriptBuilder effectScriptBuilder; private ScriptBuilder conditionScriptBuilder; private EffectBuilder() { this.effectScriptBuilder = new ScriptBuilder(this); this.conditionScriptBuilder = new ScriptBuilder(this); } public static ScriptBuilder NEW() { return new EffectBuilder().getEffectScriptBuilder(); } public static MeScriptBuilder me() { return new EffectBuilder().getEffectScriptBuilder().me(); } public ScriptBuilder getEffectScriptBuilder() { return effectScriptBuilder; } public ScriptBuilder iff() { return conditionScriptBuilder; } public void then(String s) { throw new UnsupportedOperationException(); } public void elsee(String s) { throw new UnsupportedOperationException(); } public ScriptBuilder elseIf() { throw new UnsupportedOperationException(); } public Effect compile() { String sEffect = effectScriptBuilder.toString(); String sCondition = conditionScriptBuilder.toString(); Effect effect; if (sCondition.length() > 0) { effect = new Effect(sEffect, sCondition); } else { effect = new Effect(sEffect); } return effect; } }
Java
package org.clockworkmages.games.anno1186.scripting.tools; public class PlotScriptBuilder extends ScriptBuilder { public PlotScriptBuilder() { super(new StringBuffer("plot")); } public PlotScriptBuilder(StringBuffer sb, BuilderWrapper parent) { super(sb, parent); sb.append("plot"); } public ScriptBuilder is(String plotId) { sb.append(".is('" + plotId + "')"); return this; } public ScriptBuilder get(String plotId) { sb.append(".get('" + plotId + "')"); return this; } public ScriptBuilder set(String plotId) { sb.append(".set('" + plotId + "')"); return this; } public ScriptBuilder set(String plotId, String value) { sb.append(".set('" + plotId + "','" + value + "')"); return this; } }
Java
package org.clockworkmages.games.anno1186.scripting.tools; public class EnemyScriptBuilder extends GameCharacterScriptBuilder { public EnemyScriptBuilder() { super("enemy"); } public EnemyScriptBuilder(StringBuffer sb, BuilderWrapper parent) { super(sb, parent); sb.append("enemy"); } }
Java
package org.clockworkmages.games.anno1186.scripting.tools; import java.util.ArrayList; import java.util.List; public class TextBuilder implements BuilderWrapper { private List<ScriptBuilder> conditionScriptBuilders = new ArrayList<ScriptBuilder>(); private List<String> conditionalTexts = new ArrayList<String>(); private String defaultText; public static TextBuilder NEW() { return new TextBuilder(); } @Override public ScriptBuilder iff() { ScriptBuilder scriptBuilder = new ScriptBuilder(this); this.conditionScriptBuilders.add(scriptBuilder); return scriptBuilder; } @Override public void then(String s) { conditionalTexts.add(s); } @Override public void elsee(String s) { defaultText = s; } @Override public ScriptBuilder elseIf() { ScriptBuilder scriptBuilder = new ScriptBuilder(this); this.conditionScriptBuilders.add(scriptBuilder); return scriptBuilder; } public String toString() { StringBuffer sb = new StringBuffer(); for (int i = 0; i < conditionScriptBuilders.size(); i++) { ScriptBuilder conditionScriptBuilder = conditionScriptBuilders .get(i); String conditionalText = conditionalTexts.get(i); sb.append(i == 0 ? "${if" : "${elseif").append(" ") .append(conditionScriptBuilder.toString()).append("}") .append(conditionalText); } if (defaultText != null) { sb.append("${else}").append(defaultText); } sb.append("${fi}"); return sb.toString(); } }
Java
package org.clockworkmages.games.anno1186.scripting.tools; public class SituationScriptBuilder extends ScriptBuilder { public SituationScriptBuilder() { super(new StringBuffer("situation")); } public SituationScriptBuilder(StringBuffer sb, BuilderWrapper parent) { super(sb, parent); sb.append("situation"); } public ScriptBuilder addState(String stateId) { sb.append(".addState('" + stateId + "')"); return this; } public ScriptBuilder hasState(String stateId) { sb.append(".hasState('" + stateId + "')"); return this; } public ScriptBuilder getState(String stateId) { sb.append(".getState('" + stateId + "')"); return this; } public ScriptBuilder setState(String stateId, String value) { sb.append(".setState('" + stateId + "','" + value + "')"); return this; } }
Java
package org.clockworkmages.games.anno1186.scripting.tools; public class MeScriptBuilder extends GameCharacterScriptBuilder { public MeScriptBuilder() { super("me"); } public MeScriptBuilder(StringBuffer sb, BuilderWrapper parent) { super(sb, parent); sb.append("me"); } }
Java
package org.clockworkmages.games.anno1186.scripting.tools; public abstract class GameCharacterScriptBuilder extends ScriptBuilder { public GameCharacterScriptBuilder(String prefix) { super(new StringBuffer(prefix)); } public GameCharacterScriptBuilder(StringBuffer sb, BuilderWrapper parent) { super(sb, parent); } public ScriptBuilder getEffectiveStat(String statId) { sb.append(".getEffectiveStat('" + statId + "')"); return this; } public ScriptBuilder addGold(int amount) { sb.append(".addGold(" + amount + ")"); return this; } public ScriptBuilder setGender(int gender) { sb.append(".setGender(" + gender + ")"); return this; } public ScriptBuilder getGender() { sb.append(".getGender()"); return this; } public ScriptBuilder isMale() { sb.append(".isMale()"); return this; } public ScriptBuilder getSkillLevel(String skillId) { sb.append(".getSkillLevel('" + skillId + "')"); return this; } public ScriptBuilder isUnarmed() { sb.append(".isUnarmed()"); return this; } public ScriptBuilder modifyDerivate(String id, int modifyBy) { sb.append(".modifyDerivate('" + id + "'," + modifyBy + ")"); return this; } public ScriptBuilder modifyDerivate(String id, double modifyBy) { sb.append(".modifyDerivate('" + id + "'," + modifyBy + ")"); return this; } public ScriptBuilder modifyDerivate(String id, String modifyBy) { sb.append(".modifyDerivate('" + id + "'," + modifyBy + ")"); return this; } public ScriptBuilder modifyDerivatePerc(String id, int modifyByPerc) { sb.append(".modifyDerivatePerc('" + id + "'," + modifyByPerc + ")"); return this; } public ScriptBuilder modifyDerivatePerc(String id, String modifyByPerc) { sb.append(".modifyDerivatePerc('" + id + "'," + modifyByPerc + ")"); return this; } public ScriptBuilder modifyDamage(String damageTypeId, double minDamage, double range) { sb.append(".modifyDamage('" + damageTypeId + "'," + minDamage + "," + range + ")"); return this; } public ScriptBuilder modifyDamage(String damageTypeId, String minDamage, String range) { sb.append(".modifyDamage('" + damageTypeId + "'," + minDamage + "," + range + ")"); return this; } public ScriptBuilder getGold() { sb.append(".getGold()"); return this; } public ScriptBuilder increaseStat(String statId, int value) { sb.append(".increaseStat('" + statId + "'," + value + ")"); return this; } public ScriptBuilder getDerivate(String statId) { sb.append(".getDerivate('" + statId + "')"); return this; } public ScriptBuilder skillRoll(String skillId, int difficulty) { sb.append(".skillRoll('" + skillId + "'," + difficulty + ")"); return this; } public ScriptBuilder skillRoll(String skillId, String difficulty) { sb.append(".skillRoll('" + skillId + "'," + difficulty + ")"); return this; } public ScriptBuilder skillRoll(String skillId, int difficulty, String cacheKey) { sb.append(".skillRoll('" + skillId + "'," + difficulty + ",'" + cacheKey + "')"); return this; } public ScriptBuilder skillRoll(String skillId, String difficulty, String cacheKey) { sb.append(".skillRoll('" + skillId + "'," + difficulty + ",'" + cacheKey + "')"); return this; } public ScriptBuilder skillChance(String skillId, int difficulty) { sb.append(".skillChance('" + skillId + "'," + difficulty + ")"); return this; } public ScriptBuilder equipItemNoInv(String itemId) { sb.append(".equipItemNoInv('" + itemId + "')"); return this; } public ScriptBuilder equipItem(String itemId) { sb.append(".equipItem('" + itemId + "')"); return this; } public ScriptBuilder unequipItem(String itemId) { sb.append(".unequipItem('" + itemId + "')"); return this; } public ScriptBuilder addItem(String itemId) { sb.append(".addItem('" + itemId + "')"); return this; } public ScriptBuilder removeItem(String itemId) { sb.append(".removeItem('" + itemId + "')"); return this; } public ScriptBuilder removeCurrentItem() { sb.append(".removeCurrentItem()"); return this; } public ScriptBuilder addCondition(String conditionId, int level, long duration) { sb.append(".addCondition('" + conditionId + "'," + level + "," + duration + ")"); return this; } public ScriptBuilder incapacitate(String incapacitatedStateId, int difficulty) { sb.append(".incapacitate('" + incapacitatedStateId + "'," + difficulty + ")"); return this; } public ScriptBuilder survived() { sb.append(".survived()"); return this; } public ScriptBuilder healthAtLeast1() { sb.append(".healthAtLeast1()"); return this; } public ScriptBuilder gainExperience(int experience) { sb.append(".gainExperience(" + experience + ")"); return this; } }
Java
package org.clockworkmages.games.anno1186.scripting.tools; public class UtilScriptBuilder extends ScriptBuilder { public UtilScriptBuilder() { super(new StringBuffer("util")); } public UtilScriptBuilder(StringBuffer sb, BuilderWrapper parent) { super(sb, parent); sb.append("util"); } public ScriptBuilder random(int range) { sb.append(".random(" + range + ")"); return this; } public ScriptBuilder situationRandom(int range, String situationId) { sb.append(".situationRandom(" + range + ",'" + situationId + "')"); return this; } public ScriptBuilder dailyRandom(int range, String dailyCacheKey) { sb.append(".dailyRandom(" + range + ",'" + dailyCacheKey + "')"); return this; } public ScriptBuilder getHour() { sb.append(".getHour()"); return this; } public ScriptBuilder isDay() { sb.append(".isDay()"); return this; } public ScriptBuilder isNight() { sb.append(".isNight()"); return this; } public ScriptBuilder chance(String pow) { sb.append(".chance(" + pow + ")"); return this; } public ScriptBuilder roll(String pow) { sb.append(".roll(" + pow + ")"); return this; } public ScriptBuilder roll(String pow, String cacheKey) { sb.append(".roll(" + pow + ",'" + cacheKey + "')"); return this; } public ScriptBuilder fetishesEnabled(String... fetishIds) { String sFetishIds = ""; for (String fetishId : fetishIds) { sFetishIds += ",'" + fetishId + "'"; } sb.append(".fetishesEnabled(" + sFetishIds.substring(1) + ")"); return this; } public ScriptBuilder goToLocation(String gameAreaId, int x, int y) { sb.append(".goToLocation('" + gameAreaId + "'," + x + "," + y + ")"); return this; } }
Java