Get One-Handed Ranged Weapons

slyz

Developer
I think this should work:
Code:
boolean has_ranged()
{
    foreach s in $slots[ weapon, off-hand ]
        if ( s.equipped_item().weapon_type() == $stat[ Moxie ] )
            return true;
    return false;
}
I'll try to check for any exceptions.

EDIT: "weapon_type() returns the equip requirement stat even if the weapon does not have any stat requirements". The kolwiki page for ranged weapons shows that all ranged weapons have a moxie requirement, except for a few that don't have any requirement. Mafia returns $stat[Moxie] for those since equipment.txt has a 0 Moxie requirement for them.

The melee weapons can have Muscle or Mysticality requirements (Myst weapons work like melee weapons), but a Moxie requirement always means a ranged weapon and all ranged weapons have a Moxie requirement in Mafia.

To resume: the above snippet works (and doesn't even need to be a function, you could just have:
Code:
boolean has_ranged = ( weapon_type( equipped_item( $slot[ weapon ] ) ) == $stat[ Moxie ] || weapon_type( equipped_item( $slot[ off-hand ] ) ) == $stat[ Moxie ] );

EDIT 2: I completely missed the "One-Handed" part in "One-Handed Ranged Weapons" :D
Code:
boolean has_1h_ranged()
{
    foreach s in $slots[ weapon, off-hand ]
        if ( s.equipped_item().weapon_type() == $stat[ Moxie ] && s.equipped_item().weapon_hands() == 1 )
            return true;
    return false;
}
or
Code:
boolean has_1h_ranged = ( equipped_item( $slot[ weapon ] ).weapon_hands() == 1 && ( weapon_type( equipped_item( $slot[ weapon ] ) ) == $stat[ Moxie ] || weapon_type( equipped_item( $slot[ off-hand ] ) ) == $stat[ Moxie ] ) );
 
Last edited:

StDoodle

Minion
I figured BCC meant "in my inventory, or equipped" by "on me." If this is true, couple that with this code to get a list of in-inventory 1hrw's (doesn't include stuff equipped):
Code:
void main() {
    int [item] my_stuff = get_inventory();
    boolean [item] ohr;            //one handed ranged weapons map
    foreach it in my_stuff {
        if ((weapon_type(it) == $stat[Moxie]) && (weapon_hands(it) == 1)) {
            ohr[it] = true;
        }
    }

    if (count(ohr) > 0) {
        print("One-handed ranged weapons:", "blue");
        foreach it in ohr {
            print(it.to_string());
        }
    }
}
 

slyz

Developer
In this simple case, philmasterplus' item_search.ash is a little overkill, but I just wanted pointed out how powerful/flexible it can be. With a slight modification (so it knows if a weapon is melee/ranged), you can do this:

PHP:
import <item_search.ash>

// 1. Create a list of items you want to check
boolean [ item ] item_list;
foreach it in get_inventory()
	item_list[ it ] = false;

// 2. create the item_search
item_search my_ims = create_item_search( item_list );


// search for the '1-handed' and 'ranged' keywords
// and take appropriate action
boolean has_1h_ranged = false;
foreach it in my_ims.search( "1-handed" ).search( "ranged" ).current_selection
{
	has_1h_ranged = true;
}

print( has_1h_ranged );
The obvious advantage is that you can very simply add as many keywords as item_search.ash supports!

And no, I do not own any share in that script.
 

Raven434

Member
I had one wrinkle about this I wanted to ask. Does maximize support a 1H vs 2H option? If no, I'll post a feature request because many times I would like to keep the offhand I am using but get maximize to evaluate just 1H options for weapons.

Thanks!
 

zarqon

Well-known member
Here's Doodle's code in CLI-aliasable format, if you like. Add can_equip(it) to the if check if you only want a list of the items you can actually use.

PHP:
ashq print("One-handed ranged weapons:"); foreach it in get_inventory() if ((weapon_type(it) == $stat[moxie]) && (weapon_hands(it) == 1)) print(doodad+" ("+get_power(it)+")");
 
Top