Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Plugins & Mods

Quests::Plugins & Mods Completed plugins for public use as well as modifications.

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2012, 12:49 AM
Drajor's Avatar
Drajor
Developer
 
Join Date: Nov 2012
Location: Halas
Posts: 355
Default Class Utils

Hello all. This plugin is mostly for improving code readability and reducing the chances of human error when typing class names.

Code:
### Drajor from Drajorian Guard - DrajorEQ@gmail.com
### Dependencies: the val() method is used from globals.pl
### This plugin contains some simple methods for dealing with class types.
### A special thanks to Akkadius for advice!:)

# defined in classes.h
use constant {
	WARRIOR			=> 1,
	CLERIC			=> 2,
	PALADIN			=> 3,
	RANGER			=> 4,
	SHADOWKNIGHT	=> 5,
	DRUID			=> 6,
	MONK			=> 7,
	BARD			=> 8,
	ROGUE			=> 9,
	SHAMAN			=> 10,
	NECROMANCER		=> 11,
	WIZARD			=> 12,
	MAGICIAN		=> 13,
	ENCHANTER		=> 14,
	BEASTLORD		=> 15,
	BERSERKER		=> 16
};

%CLASSES = (
	"Warrior", WARRIOR,
	"Cleric", CLERIC,
	"Paladin", PALADIN,
	"Ranger", RANGER,
	"Shadowknight", SHADOWKNIGHT,
	"Druid", DRUID,
	"Monk", MONK,
	"Bard", BARD,
	"Rogue", ROGUE,
	"Shaman", SHAMAN,
	"Necromancer", NECROMANCER,
	"Wizard", WIZARD,
	"Magician", MAGICIAN,
	"Enchanter", ENCHANTER,
	"Beastlord", BEASTLORD,
	"Berserker", BERSERKER
);

# Returns the numerical class ID for the character.
sub getClassID {
	return $CLASSES{plugin::val('$class')};
}

# Check if the character is a specific class.
sub isWarrior { return ( plugin::getClassID() == WARRIOR ); }
sub isCleric { return ( plugin::getClassID() == CLERIC ); }
sub isPaladin { return ( plugin::getClassID() == PALADIN ); }
sub isRanger { return ( plugin::getClassID() == RANGER ); }
sub isShadowknight { return ( plugin::getClassID() == SHADOWKNIGHT ); }
sub isDruid { return ( plugin::getClassID() == WARRIOR ); }
sub isMonk { return ( plugin::getClassID() == MONK ); }
sub isBard { return ( plugin::getClassID() == BARD ); }
sub isRogue { return ( plugin::getClassID() == ROGUE ); }
sub isShaman { return ( plugin::getClassID() == SHAMAN ); }
sub isNecromancer { return ( plugin::getClassID() == NECROMANCER ); }
sub isWizard { return ( plugin::getClassID() == WIZARD ); }
sub isMagician { return ( plugin::getClassID() == MAGICIAN ); }
sub isEnchanter { return ( plugin::getClassID() == ENCHANTER ); }
sub isBeastlord { return ( plugin::getClassID() == BEASTLORD ); }
sub isBerserker { return ( plugin::getClassID() == BERSERKER ); }

# Check if the character is a plate wearing class.
sub isPlateClass {
	$myclass = plugin::getClassID();
	return (
		$myclass == WARRIOR or
		$myclass == CLERIC or
		$myclass == PALADIN or
		$myclass == SHADOWKNIGHT or
		$myclass == BARD
	) ? 1 : 0;
}
# Check if the character is a chain wearing class.
sub isChainClass {
	$myclass = plugin::getClassID();
	return (
		$myclass == RANGER or
		$myclass == ROGUE or
		$myclass == SHAMAN or
		$myclass == BERSERKER
	) ? 1 : 0;
}
# Check if the character is a leather wearing class.
sub isLeatherClass {
	$myclass = plugin::getClassID();
	return (
		$myclass == DRUID or
		$myclass == MONK or
		$myclass == BEASTLORD
	) ? 1 : 0;
}
# Check if the character is a cloth wearing class.
sub isClothClass {
	$myclass = plugin::getClassID();
	return (
		$myclass == NECROMANCER or
		$myclass == WIZARD or
		$myclass == MAGICIAN or
		$myclass == ENCHANTER
	) ? 1 : 0;
}
# Check if the character is a spell caster.
sub isSpellCaster {
	$myclass = plugin::getClassID();
	return (
		$myclass != WARRIOR and
		$myclass != ROGUE and
		$myclass != BERSERKER
	) ? 1 : 0;
}
# Check if the character is pure melee.
sub isMelee {
	return !plugin::isSpellCaster();
}
Reply With Quote
  #2  
Old 12-08-2012, 08:16 AM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

here's something along the same line. it uses regular expressions to match the class passed (long form or abbreviation, case insensitive) and returns the type (hybrid, melee, caster, or priest). returns 'other' if no match was found.

Code:
use List::Util qw(first);

# usage plugin::ClassType($class)
sub ClassType
{
    my $class = lc(shift);
    my %type  = (
        hybrid => qr/^b(a)?rd|b(eastlord|st)|pal(adin)?|r(anger|ng)|sh(adowknight|d)$/,
        melee  => qr/^war(rior)?|m(o)?nk|ber(serker)?|rog(ue)?$/,
        caster => qr/^nec(romancer)?|wiz(ard)?|enc(hanter)?|mag(ician)?$/,
        priest => qr/^cl(eric|r)|sh(aman|m)|dru(id)?$/
    );
    (first { $class =~ $type{$_} } keys %type) // 'other';
}

1;
here is an example use in quests/templates/global_player.pl

before:
Code:
sub EVENT_COMBINE_SUCCESS {
  if (($recipe_id == 10904) || ($recipe_id == 10905) || ($recipe_id == 10906) || ($recipe_id == 10907)) {
    $client->Message(1, "The gem resonates with power as the shards placed within glow unlocking some of the stone's power. You were successful in assembling most of the stone but there are four slots left to fill, where could those four pieces be?");
  }
  if ($recipe_id == 10903) {
    if (($class eq "Bard") || ($class eq "Beastlord") || ($class eq "Paladin") || ($class eq "Ranger") ||  ($class eq "Shadowknight")) {
      quest::summonitem(67666);
      quest::summonitem(67704);
    }
    elsif (($class eq "Warrior") || ($class eq "Monk") || ($class eq "Berserker")  || ($class eq "Rogue"))  {
      quest::summonitem(67665);
      quest::summonitem(67704);
    }
    elsif (($class eq "Cleric") || ($class eq "Shaman") || ($class eq "Druid")) {
      quest::summonitem(67667);  
      quest::summonitem(67704);
    }
    elsif (($class eq "Necromancer") || ($class eq "Wizard") || ($class eq "Enchanter")  || ($class eq "Magician")) {
      quest::summonitem(67668);
      quest::summonitem(67704);
    }
    $client->Message(1,"Success");
  }
  if ($recipe_id == 10346) {
    if (($class eq "Bard") || ($class eq "Beastlord") || ($class eq "Paladin") || ($class eq "Ranger") ||  ($class eq "Shadowknight")) {
      quest::summonitem(67661);
      quest::summonitem(67704);
    }
    elsif (($class eq "Warrior") || ($class eq "Monk") || ($class eq "Berserker")  || ($class eq "Rogue"))  {
      quest::summonitem(67660);
      quest::summonitem(67704);
    }
    elsif (($class eq "Cleric") || ($class eq "Shaman") || ($class eq "Druid")) {
      quest::summonitem(67662);  
      quest::summonitem(67704);
    }
    elsif (($class eq "Necromancer") || ($class eq "Wizard") || ($class eq "Enchanter")  || ($class eq "Magician")) {
      quest::summonitem(67663);
      quest::summonitem(67704);
    }
    $client->Message(1,"Success");
  }
  if ($recipe_id == 10334) {
    if (($class eq "Bard") || ($class eq "Beastlord") || ($class eq "Paladin") || ($class eq "Ranger") ||  ($class eq "Shadowknight")) {
      quest::summonitem(67654);
      quest::summonitem(67704);
    }
    elsif (($class eq "Warrior") || ($class eq "Monk") || ($class eq "Berserker")  || ($class eq "Rogue"))  {
      quest::summonitem(67653);
      quest::summonitem(67704);
    }
    elsif (($class eq "Cleric") || ($class eq "Shaman") || ($class eq "Druid")) {
      quest::summonitem(67655);  
      quest::summonitem(67704);
    }
    elsif (($class eq "Necromancer") || ($class eq "Wizard") || ($class eq "Enchanter")  || ($class eq "Magician")) {
      quest::summonitem(67656);
      quest::summonitem(67704);
    }
    $client->Message(1,"Success");
  }
}
after:
Code:
sub EVENT_COMBINE_SUCCESS
{
    if ($recipe_id =~ /^1090[4-7]$/) {
        $client->Message(1,
            "The gem resonates with power as the shards placed within glow unlocking some of the stone's power. ".
            "You were successful in assembling most of the stone but there are four slots left to fill, ".
            "where could those four pieces be?"
        );
    }
    elsif ($recipe_id =~ /^10(903|346|334)$/) {
        my %reward = (
            melee  => {
                10903 => 67665,
                10346 => 67660,
                10334 => 67653
            },
            hybrid => {
                10903 => 67666,
                10346 => 67661,
                10334 => 67654
            },
            priest => {
                10903 => 67667,
                10346 => 67662,
                10334 => 67655
            },
            caster => {
                10903 => 67668,
                10346 => 67663,
                10334 => 67656
            }
        );
        my $type = plugin::ClassType($class);
        quest::summonitem($reward{$type}{$recipe_id});
        quest::summonitem(67704);
        $client->Message(1,"Success");
    }
}
note: i used a single complex data structure and a couple of regular expressions to eliminate the repetitive conditionals in the subroutine.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 06:15 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3