OSDN Git Service

[Refactor] #1644 Reshaped execute() in ObjectZapWandEntity
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 25 Sep 2021 13:43:19 +0000 (22:43 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Wed, 29 Sep 2021 13:39:15 +0000 (22:39 +0900)
src/object-use/zapwand-execution.cpp

index d46edfe..78a5c04 100644 (file)
@@ -35,78 +35,69 @@ ObjectZapWandEntity::ObjectZapWandEntity(player_type *player_ptr)
  */
 void ObjectZapWandEntity::execute(INVENTORY_IDX item)
 {
-    DEPTH lev;
-    int ident, chance;
-    DIRECTION dir;
-    object_type *o_ptr;
-    bool old_target_pet = target_pet;
-
-    o_ptr = ref_item(this->player_ptr, item);
-
-    /* Mega-Hack -- refuse to aim a pile from the ground */
+    auto old_target_pet = target_pet;
+    auto *o_ptr = ref_item(this->player_ptr, item);
     if ((item < 0) && (o_ptr->number > 1)) {
         msg_print(_("まずは魔法棒を拾わなければ。", "You must first pick up the wands."));
         return;
     }
 
-    /* Allow direction to be cancelled for free */
-    if (o_ptr->is_aware() && (o_ptr->sval == SV_WAND_HEAL_MONSTER || o_ptr->sval == SV_WAND_HASTE_MONSTER))
+    if (o_ptr->is_aware() && (o_ptr->sval == SV_WAND_HEAL_MONSTER || o_ptr->sval == SV_WAND_HASTE_MONSTER)) {
         target_pet = true;
+    }
+
+    DIRECTION dir;
     if (!get_aim_dir(this->player_ptr, &dir)) {
         target_pet = old_target_pet;
         return;
     }
-    target_pet = old_target_pet;
 
+    target_pet = old_target_pet;
     PlayerEnergy(this->player_ptr).set_player_turn_energy(100);
 
-    /* Get the level */
-    lev = k_info[o_ptr->k_idx].level;
-    if (lev > 50)
+    auto lev = k_info[o_ptr->k_idx].level;
+    if (lev > 50) {
         lev = 50 + (lev - 50) / 2;
+    }
 
-    /* Base chance of success */
-    chance = this->player_ptr->skill_dev;
-
-    /* Confusion hurts skill */
-    if (this->player_ptr->confused)
+    auto chance = this->player_ptr->skill_dev;
+    if (this->player_ptr->confused) {
         chance = chance / 2;
+    }
 
-    /* Hight level objects are harder */
     chance = chance - lev;
-
-    /* Give everyone a (slight) chance */
     if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1)) {
         chance = USE_DEVICE;
     }
 
-    if (cmd_limit_time_walk(this->player_ptr))
+    if (cmd_limit_time_walk(this->player_ptr)) {
         return;
+    }
 
-    /* Roll for usage */
     if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (this->player_ptr->pclass == CLASS_BERSERKER)) {
-        if (flush_failure)
+        if (flush_failure) {
             flush();
+        }
+
         msg_print(_("魔法棒をうまく使えなかった。", "You failed to use the wand properly."));
         sound(SOUND_FAIL);
         return;
     }
 
-    /* The wand is already empty! */
     if (o_ptr->pval <= 0) {
-        if (flush_failure)
+        if (flush_failure) {
             flush();
+        }
+
         msg_print(_("この魔法棒にはもう魔力が残っていない。", "The wand has no charges left."));
         o_ptr->ident |= IDENT_EMPTY;
         this->player_ptr->update |= PU_COMBINE | PU_REORDER;
         this->player_ptr->window_flags |= PW_INVEN;
-
         return;
     }
 
     sound(SOUND_ZAP);
-
-    ident = wand_effect(this->player_ptr, o_ptr->sval, dir, false, false);
+    auto ident = wand_effect(this->player_ptr, o_ptr->sval, dir, false, false);
 
     /*
      * Temporarily remove the flags for updating the inventory so
@@ -115,17 +106,13 @@ void ObjectZapWandEntity::execute(INVENTORY_IDX item)
      */
     BIT_FLAGS inventory_flags = (PU_COMBINE | PU_REORDER | (this->player_ptr->update & PU_AUTODESTROY));
     reset_bits(this->player_ptr->update, PU_COMBINE | PU_REORDER | PU_AUTODESTROY);
-
     if (!(o_ptr->is_aware())) {
         chg_virtue(this->player_ptr, V_PATIENCE, -1);
         chg_virtue(this->player_ptr, V_CHANCE, 1);
         chg_virtue(this->player_ptr, V_KNOWLEDGE, -1);
     }
 
-    /* Mark it as tried */
     object_tried(o_ptr);
-
-    /* Apply identification */
     if (ident && !o_ptr->is_aware()) {
         object_aware(this->player_ptr, o_ptr);
         gain_exp(this->player_ptr, (lev + (this->player_ptr->lev >> 1)) / this->player_ptr->lev);
@@ -133,10 +120,7 @@ void ObjectZapWandEntity::execute(INVENTORY_IDX item)
 
     set_bits(this->player_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_PLAYER | PW_FLOOR_ITEM_LIST);
     set_bits(this->player_ptr->update, inventory_flags);
-
-    /* Use a single charge */
     o_ptr->pval--;
-
     if (item >= 0) {
         inven_item_charges(this->player_ptr, item);
         return;