Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expansion of RPG module LIMITED_AMMO_WEAPON: RELOADABLE_AMMO_WEAPON #98

Open
Kln95130 opened this issue Apr 2, 2023 · 0 comments
Open

Comments

@Kln95130
Copy link

Kln95130 commented Apr 2, 2023

Hello Pix,

I experiment this week-end on your RPG module. I thought that mixing what I had worked in my previous project with your LIMITED_AMMO_WEAPON would be interesting.

As it is, this template allows the use of ammo, but once the ammo is spent, the weapon is useless. Behold, the RELOADABLE_AMMO_WEAPON template and its associated command, which now allows rogues to resplenish their quivers, and special agents to reload their handguns.

Feel free to use the code in any way, shape, or form.

lang.verbs.reload = "Reload";

commands.push(
    new Cmd('Reload', {
        regex:/^(?:reload) (.+)$/,
        rules:[cmdRules.isHeld, cmdRules.testManipulate],
        objects:[
          {scope:parser.isHeld, multiple:true},
        ],
        script:function(objects) {
            const weapon = objects[0][0];
            if (!weapon.ammoName) {
                msg("{nv:item:do:true} not have any valid ammunition.", {item: weapon});
                return world.FAILED;
            }
            const ammo = w[weapon.ammoName];
            const ammoHeld = ammo.countAtLoc("me");
            if (ammoHeld == 0) {
                msg("{pv:player:do:true} not have any {nm:item} on you.", {item: ammo});
                return world.FAILED;
            }
            const quantityToFill = weapon.capacity - weapon.ammo;
            if (ammoHeld >= quantityToFill) {
                ammo.countableLocs['me'] -= quantityToFill;
                weapon.ammo = weapon.capacity;
                msg("{pv:player:do:true} use {show:quantity} {nm:ammo} to reload {nm:weapon}.", {weapon: weapon, ammo: ammo, quantity: quantityToFill})
            } else {
                ammo.countableLocs['me'] = false;
                weapon.ammo += ammoHeld;
                msg("{pv:player:do:true} use your {show:quantity} remaining {nm:ammo} to reload {nm:weapon}.", {weapon: weapon, ammo: ammo, quantity: ammoHeld})
            }


            return  world.SUCCESS
        },
    })
)

const RELOADABLE_AMMO_WEAPON = function(damage, ammo){
    const res = Object.assign({}, LIMITED_AMMO_WEAPON(damage, ammo))
    
    res.capacity=ammo;
    res.ammoName = false;

    res.afterCreation =  function(o) {
        //o.oldRpgOnCreation(o)
        o.verbFunctions.push(function(o, verbList) {
          if (o.isAtLoc(player)) {
            verbList.push(lang.verbs.reload)
          }
        })
    }

    return res;
}

createItem("handgun", RELOADABLE_AMMO_WEAPON("1d3+3", 6),  {
    loc: "me",
    synonyms: ['gun', 'pistol'],
    examine: "a nifty gun. It has {show:handgun:ammo} ammunition",
    ammoName: "handgunAmmo",
});

createItem("handgunAmmo", COUNTABLE({me: 7}),  {
    regex:/^(\d+ )?(handgun round|rounds)?$/,

    alias: "handgun round",
    examine: "ammunition for the gun.",
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant