]> www.infradead.org Git - users/mchehab/andors-trail.git/commitdiff
Added immunity to critical hits for ghosts, undead and demons.
authoroskar.wiksten <oskar.wiksten@08aca716-68be-ccc6-4d58-36f5abd142ac>
Mon, 12 Mar 2012 21:16:57 +0000 (21:16 +0000)
committeroskar.wiksten <oskar.wiksten@08aca716-68be-ccc6-4d58-36f5abd142ac>
Mon, 12 Mar 2012 21:16:57 +0000 (21:16 +0000)
Added a way to re-sort the player's inventory by moving items to top/bottom.
Auto-close the level-up dialog if the player cannot level up (issue 284)

git-svn-id: https://andors-trail.googlecode.com/svn/trunk@222 08aca716-68be-ccc6-4d58-36f5abd142ac

13 files changed:
AndorsTrail/res/layout/levelup.xml
AndorsTrail/res/layout/monsterinfo.xml
AndorsTrail/res/menu/inventoryitem.xml
AndorsTrail/res/values/strings.xml
AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/HeroinfoActivity_Inventory.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LevelUpActivity.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/MonsterInfoActivity.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/CombatController.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/actor/Actor.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/actor/Monster.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/actor/MonsterType.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/actor/Player.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/item/ItemContainer.java

index fcf8ae24584993d4617244b93f8a44f702fd5a16..22d8326932463f90e2f7552b3dcd7969a66c5424 100644 (file)
@@ -90,7 +90,7 @@
                </LinearLayout>
 
                <!-- Workaround http://code.google.com/p/andors-trail/issues/detail?id=242 -->
-               <ListView android:layout_width="match_parent" android:layout_height="wrap_content" />  
+               <ListView android:layout_width="match_parent" android:layout_height="1dp" />  
        
        </LinearLayout>
 
index c3a3fcbc16d5aceaa18a777d38fa2318bb19fbb1..5d02a4eb000c336c07d530942a292a6fff454be0 100644 (file)
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                />
+                       <TextView
+                               android:layout_width="match_parent"
+                               android:layout_height="wrap_content"
+                               android:text="@string/actorinfo_immune_criticals"
+                               android:id="@+id/monsterinfo_immune_criticals"
+                               />
                        <com.gpl.rpg.AndorsTrail.view.ItemEffectsView
                                android:id="@+id/monsterinfo_onhiteffects"
                                android:layout_width="match_parent"
index f8195a944ba4f85cbadd17b0332af86d127dbc9b..bd8c419399b8a18f08ab406ae9a63207a9f29005 100644 (file)
@@ -13,4 +13,6 @@
                        <item android:id="@+id/inv_assign_slot3" android:title="@string/inventory_assign_slot3"></item>
                </menu>
        </item>
+       <item android:title="@string/inventory_movetop" android:id="@+id/inv_menu_movetop" />
+       <item android:title="@string/inventory_movebottom" android:id="@+id/inv_menu_movebottom" />
 </menu>
index 12dcd0b51fc1bb7b7d045724435d15234782cfec..95ab0d070de87886b55fc821397429e8ea5c04b6 100644 (file)
     <string name="skill_shortdescription_shadow_bless">Resistance against all types of conditions</string>
     <string name="skill_longdescription_shadow_bless">Lowers the chance of being afflicted with all types of conditions by %1$d %% for every skill level. This includes all types conditions caused by monster attacks such as Poison, Dazed or Fatigue.</string>
     
+    <string name="inventory_movetop">Move to top</string>
+    <string name="inventory_movebottom">Move to bottom</string>
+    <string name="actorinfo_immune_criticals">Immune to critical hits</string>
+        
 </resources>
index 43b1f5f1dfea1f5895655efd93dd9e1e5f05e34e..3c0d2c1d7d9d42e2d631ff12d0138e55e7a8ed5e 100644 (file)
@@ -229,6 +229,12 @@ public final class HeroinfoActivity_Inventory extends Activity {
                case R.id.inv_assign_slot3:
                        view.itemController.setQuickItem(lastSelectedItem, 2);
                        break;
+               case R.id.inv_menu_movetop:
+                       player.inventory.sortToTop(getSelectedItemType(info).id);
+                       break;
+               case R.id.inv_menu_movebottom:
+                       player.inventory.sortToBottom(getSelectedItemType(info).id);
+                       break;
                default:
                        return super.onContextItemSelected(item);
                }
index 0b50b6bf60fa688f4fc925520837c9d1129d1a34..5f2093f561dc90f568b6f6af57e2de55cb4a5433 100644 (file)
@@ -21,6 +21,9 @@ import com.gpl.rpg.AndorsTrail.model.actor.Player;
 public final class LevelUpActivity extends Activity {
        private WorldContext world;
        private Player player;
+       private ImageView levelup_image;
+       private TextView levelup_description;
+       private View levelup_adds_new_skillpoint;
        
     /** Called when the activity is first created. */
     @Override
@@ -34,13 +37,10 @@ public final class LevelUpActivity extends Activity {
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         
         setContentView(R.layout.levelup);
-       final Resources res = getResources();
        
-        ImageView img = (ImageView) findViewById(R.id.levelup_image);
-        world.tileManager.setImageViewTile(img, player);
-        
-        TextView tv = (TextView) findViewById(R.id.levelup_description);
-        tv.setText(res.getString(R.string.levelup_description, player.level+1));
+       levelup_image = (ImageView) findViewById(R.id.levelup_image);
+        levelup_description = (TextView) findViewById(R.id.levelup_description);
+        levelup_adds_new_skillpoint = findViewById(R.id.levelup_adds_new_skillpoint);
 
         Button b;
         
@@ -79,12 +79,24 @@ public final class LevelUpActivity extends Activity {
                        }
                });
         b.setText(getString(R.string.levelup_add_blockchance, Constants.LEVELUP_EFFECT_DEF_CH));
-        
-        View v = findViewById(R.id.levelup_adds_new_skillpoint);
+    }
+    
+    @Override
+    protected void onResume() {
+       super.onResume();
+       final Resources res = getResources();
+       
+       if (!player.canLevelup()) {
+               this.finish();
+               return;
+       }
+       
+       world.tileManager.setImageViewTile(levelup_image, player);
+        levelup_description.setText(res.getString(R.string.levelup_description, player.level+1));
         if (player.nextLevelAddsNewSkillpoint()) {
-               v.setVisibility(View.VISIBLE);
+               levelup_adds_new_skillpoint.setVisibility(View.VISIBLE);
         } else {
-               v.setVisibility(View.GONE);
+               levelup_adds_new_skillpoint.setVisibility(View.GONE);
         }
     }
 
index 68cb5075bd2143822428e40faa8152f3c116e7f0..c6030e2a97234522edb31d516485a6eba2585ab0 100644 (file)
@@ -30,6 +30,7 @@ public final class MonsterInfoActivity extends Activity {
        private TraitsInfoView monsterinfo_currenttraits;\r
        private ItemEffectsView monsterinfo_onhiteffects;\r
     private TextView monsterinfo_currentconditions_title;\r
+    private TextView monsterinfo_immune_criticals;\r
     private ActorConditionList monsterinfo_currentconditions;\r
        private RangeBar hp;\r
        private WorldContext world;\r
@@ -47,6 +48,7 @@ public final class MonsterInfoActivity extends Activity {
         monsterinfo_image = (ImageView) findViewById(R.id.monsterinfo_image);\r
         monsterinfo_title = (TextView) findViewById(R.id.monsterinfo_title);\r
         monsterinfo_difficulty = (TextView) findViewById(R.id.monsterinfo_difficulty);\r
+        monsterinfo_immune_criticals = (TextView) findViewById(R.id.monsterinfo_immune_criticals);\r
         \r
         Button b = (Button) findViewById(R.id.monsterinfo_close);\r
         b.setOnClickListener(new OnClickListener() {\r
@@ -93,6 +95,7 @@ public final class MonsterInfoActivity extends Activity {
                        monster.actorTraits.onHitEffects == null ? null : Arrays.asList(monster.actorTraits.onHitEffects), \r
                        null);\r
         hp.update(monster.health);\r
+        monsterinfo_immune_criticals.setVisibility(monster.isImmuneToCriticalHits ? View.VISIBLE : View.GONE);\r
     }\r
 \r
        public static int getMonsterDifficultyResource(WorldContext world, Monster monster) {\r
index 1d25b4f669fe2c11980a1b0ef04493581b89a20a..ab12a0941416e795c9faa35024aa7fc9df3d9dab 100644 (file)
@@ -411,9 +411,16 @@ public final class CombatController implements VisualEffectCompletedCallback {
        context.mainActivity.updateStatus();
        }
        
+       private static boolean hasCriticalAttack(Actor attacker, Actor target) {
+               if (!attacker.combatTraits.hasCriticalAttacks()) return false;
+               if (target.isImmuneToCriticalHits) return false;
+               return true;
+       }
        private static float getAverageDamagePerHit(Actor attacker, Actor target) {
                float result = (float) (getAttackHitChance(attacker.combatTraits, target.combatTraits)) * attacker.combatTraits.damagePotential.average() / 100;
-               result += (float) attacker.combatTraits.criticalChance * result * attacker.combatTraits.criticalMultiplier / 100;
+               if (hasCriticalAttack(attacker, target)) {
+                       result += (float) attacker.combatTraits.criticalChance * result * attacker.combatTraits.criticalMultiplier / 100;
+               }
                result -= target.combatTraits.damageResistance;
                return result;
        }
@@ -421,7 +428,7 @@ public final class CombatController implements VisualEffectCompletedCallback {
                return getAverageDamagePerHit(attacker, target) * attacker.getAttacksPerTurn();
        }
        private static int getTurnsToKillTarget(Actor attacker, Actor target) {
-               if (attacker.combatTraits.hasCriticalAttacks()) {
+               if (hasCriticalAttack(attacker, target)) {
                        if (attacker.combatTraits.damagePotential.max * attacker.combatTraits.criticalMultiplier <= target.combatTraits.damageResistance) return 999;
                } else {
                        if (attacker.combatTraits.damagePotential.max <= target.combatTraits.damageResistance) return 999;
@@ -466,7 +473,7 @@ public final class CombatController implements VisualEffectCompletedCallback {
                
                int damage = Constants.rollValue(attacker.combatTraits.damagePotential);
                boolean isCriticalHit = false;
-               if (attacker.combatTraits.hasCriticalAttacks()) {
+               if (hasCriticalAttack(attacker, target)) {
                        isCriticalHit = Constants.roll100(attacker.combatTraits.criticalChance);
                        if (isCriticalHit) {
                                damage *= attacker.combatTraits.criticalMultiplier;
index 59931177b25d3bb6cccb35b87fc27721d11875b8..b95ef106683fc1f03da4597ec45af5e85a917edf 100644 (file)
@@ -21,8 +21,9 @@ public class Actor {
        public final CoordRect rectPosition;
        public final ArrayList<ActorCondition> conditions = new ArrayList<ActorCondition>();
        public final boolean isPlayer;
+       public final boolean isImmuneToCriticalHits;
        
-       public Actor(ActorTraits actorTraits, boolean isPlayer) {
+       public Actor(ActorTraits actorTraits, boolean isPlayer, boolean isImmuneToCriticalHits) {
                this.combatTraits = new CombatTraits(actorTraits.baseCombatTraits);
                this.actorTraits = actorTraits;
                this.ap = new Range(actorTraits.maxAP, actorTraits.maxAP);
@@ -30,6 +31,7 @@ public class Actor {
                this.position = new Coord();
                this.rectPosition = new CoordRect(position, actorTraits.tileSize);
                this.isPlayer = isPlayer;
+               this.isImmuneToCriticalHits = isImmuneToCriticalHits;
        }
        
        public int getAttacksPerTurn() { return combatTraits.getAttacksPerTurn(actorTraits.maxAP); }
@@ -64,11 +66,13 @@ public class Actor {
                actorTraits.moveCost = actorTraits.baseMoveCost;
        }
 
+
        
        // ====== PARCELABLE ===================================================================
 
-       public Actor(DataInputStream src, WorldContext world, int fileversion, boolean isPlayer, ActorTraits actorTraits) throws IOException {
+       public Actor(DataInputStream src, WorldContext world, int fileversion, boolean isPlayer, boolean isImmuneToCriticalHits, ActorTraits actorTraits) throws IOException {
                this.isPlayer = isPlayer;
+               this.isImmuneToCriticalHits = isImmuneToCriticalHits;
                
                CombatTraits combatTraits = null;
                boolean readCombatTraits = true;
index 24d3cac7d29a8980b6f5e157345ec07c65dbc937..c4e73ea707b778d218515dfc18edccd0458861c6 100644 (file)
@@ -28,7 +28,7 @@ public final class Monster extends Actor {
        public final int monsterClass;
        
        public Monster(MonsterType monsterType, Coord position) {
-               super(monsterType, false);
+               super(monsterType, false, monsterType.isImmuneToCriticalHits());
                this.monsterTypeID = monsterType.id;
                this.position.set(position);
                this.millisecondsPerMove = Constants.MONSTER_MOVEMENT_TURN_DURATION_MS / monsterType.getMovesPerTurn();
@@ -68,7 +68,7 @@ public final class Monster extends Actor {
        }
 
        public Monster(DataInputStream src, WorldContext world, int fileversion, MonsterType monsterType) throws IOException {
-               super(src, world, fileversion, false, monsterType);
+               super(src, world, fileversion, false, monsterType.isImmuneToCriticalHits(), monsterType);
                this.monsterTypeID = monsterType.id;
                this.millisecondsPerMove = Constants.MONSTER_MOVEMENT_TURN_DURATION_MS / monsterType.getMovesPerTurn();
                this.nextPosition = new CoordRect(new Coord(), actorTraits.tileSize);
index ebcedf3eccf2b5e7e12425e97f52343183305094..3def8159d5c5fa20482bc015106243ba7ceccea2 100644 (file)
@@ -56,4 +56,11 @@ public final class MonsterType extends ActorTraits {
                this.isUnique = isUnique;
                this.monsterClass = monsterClass;
        }
+
+       public boolean isImmuneToCriticalHits() {
+               if (monsterClass == MONSTERCLASS_GHOST) return true;
+               else if (monsterClass == MONSTERCLASS_UNDEAD) return true;
+               else if (monsterClass == MONSTERCLASS_DEMON) return true;
+               return false;
+       }
 }
index ec64dc3dd9d6c5cfb78bf0e6556cbf95631d4301..71ac72866687d6b63e3b827b3a842bb7ca21f2b7 100644 (file)
@@ -40,7 +40,7 @@ public final class Player extends Actor {
        private final HashMap<String, Integer> alignments = new HashMap<String, Integer>();
        
        public Player() {
-               super(new ActorTraits(TileManager.CHAR_HERO, new Size(1, 1), new CombatTraits(), DEFAULT_PLAYER_MOVECOST, null), true);
+               super(new ActorTraits(TileManager.CHAR_HERO, new Size(1, 1), new CombatTraits(), DEFAULT_PLAYER_MOVECOST, null), true, false);
                this.lastPosition = new Coord();
                this.nextPosition = new Coord();
                this.levelExperience = new Range();
@@ -177,7 +177,7 @@ public final class Player extends Actor {
        // ====== PARCELABLE ===================================================================
 
        public Player(DataInputStream src, WorldContext world, int fileversion) throws IOException {
-               super(src, world, fileversion, true, null);
+               super(src, world, fileversion, true, false, null);
                this.lastPosition = new Coord(src, fileversion);
                this.nextPosition = new Coord(src, fileversion);
                this.level = src.readInt();
index e0a12111580c41096fa80f6ddf458f52dd6aa9bd..e24727b30b1cb86c5c479a784a865b1138e1cec5 100644 (file)
@@ -87,6 +87,12 @@ public class ItemContainer {
                }\r
                return null;\r
        }\r
+       public int findItemIndex(String itemTypeID) {\r
+               for (int i = 0; i < items.size(); ++i) {\r
+                       if (items.get(i).itemType.id.equals(itemTypeID)) return i;\r
+               }\r
+               return -1;\r
+       }\r
        public boolean hasItem(String itemTypeID) { return findItem(itemTypeID) != null; }\r
        public boolean hasItem(String itemTypeID, int minimumQuantity) { \r
                return getItemQuantity(itemTypeID) >= minimumQuantity;\r
@@ -97,6 +103,18 @@ public class ItemContainer {
                if (e == null) return 0;\r
                return e.quantity;\r
        }\r
+\r
+       public void sortToTop(String itemTypeID) {\r
+               int i = findItemIndex(itemTypeID);\r
+               if (i <= 0) return;\r
+               items.add(0, items.remove(i));\r
+       }\r
+\r
+       public void sortToBottom(String itemTypeID) {\r
+               int i = findItemIndex(itemTypeID);\r
+               if (i < 0) return;\r
+               items.add(items.remove(i));\r
+       }\r
        \r
        \r
        // ====== PARCELABLE ===================================================================\r