View Single Post
  #4  
Old 02-25-2018, 06:38 AM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default AHEM! I'll just leave this here...

I like the some of the witty text you added... Especially in the header! (POW)

quests\items\script_8556.pl

Code:
###################
### START NOTES ###
###################

# NOTE: these are just to indicate what perl files are run for item events.
#       we will only be using EVENT_ITEM_CLICK_CAST here.

# EVENT_SCALE_CALC
# EVENT_ITEM_ENTERZONE
# quests\items\<charmfile>.pl

# EVENT_ITEM_CLICK
# EVENT_ITEM_CLICK_CAST
# quests\items\script_<scriptfileid>.pl

# i don't remember how these are used...
# quests\items\item_<id>.pl

##################
#### END NOTES ###
##################

# any item with the scriptfileid of 8556 triggers this event when right-clicked
# NOTE: scriptfieldid is a field in the items table of the database
sub EVENT_ITEM_CLICK_CAST {

	# itemid 35096 is a bloodmoon pick axe
	handle_35096()
	  if $itemid == 35096;

}

################################
### START bloodmoon pick axe ###
################################

# read data for mine-able areas from xml file
sub GetMiningAreas {

	our %mine
	  if not %mine;
	  
	return
	  if exists $mine{$zoneid};
	  
	use XML::Simple qw(:strict);
	my $data = XMLin(
		'script_8556_mine.xml',
		ForceArray => 1,
		KeyAttr    => {
			'zone' => 'id',
			[ 'area' => 'id' ]
		},
	);
	
	my @area = @{ $data->{zone}->{$zoneid}->{area} };
	
	undef $data;
	
	$mine{$zoneid} = [];
	
	for my $i ( 0 .. $#area ) {

		if ( $i != $area[$i]->{id} ) {
			warn( "area mismatch while reading data for "
				  . $data->{zone}->{$zoneid}->{sn} . " "
				  . "($i != $area[$i]->{id})" );
			next;
		}
		
		$mine{$zoneid}[$i] = {
			x => $area[$i]->{x},
			y => $area[$i]->{y},
			z => $area[$i]->{z}
		};
		
	}
	
}

# determine if client is in a defined mining area
sub inMiningArea {

	# clear any existing area
	$area = undef
	  if defined $area;

	# not in mining zone
	return 0
	  if not exists $mine{$zoneid};

	# check client loc against defined mining areas for current zone
	foreach my $i ( keys @{ $mine{$zoneid} } ) {

		# loc info for current mining area
		my $loc = $mine{$zoneid}[$i];

		# client in defined mining areas for current zone
		# NOTE: we're checking x & y plus or minus 10 and z plus or minus 5
		if (   int $client->GetX() ~~ [ $loc->{x} - 10 .. $loc->{x} + 10 ]
			&& int $client->GetY() ~~ [ $loc->{y} - 10 .. $loc->{y} + 10 ]
			&& int $client->GetZ() ~~ [ $loc->{z} - 05 .. $loc->{z} + 05 ] )
		{
			# set global variable for mining area
			# TO DO: determine if globals are trashed when zone is unloaded
			our $area = $i;
			return 1;
		}

	}

	# client not in defined mining areas for current zone
	return 0;
}

# check mining area for ore availability
sub isDepleted {

	# sanity check
	return 1
	  if not defined $area;

	# qglobal name
	my $mine = "mine$area";

	# depleted and timer not expired
	# NOTE: max mining yield for area is 10 (> 9)
	return 1
	  if defined $qglobals{$mine}
	  && $qglobals{$mine} > 9;

	# not depleted
	return 0;
	
}

# increment depletion counters for area
sub doneMining {

	# sanity check
	return
	  if not defined $area;

	# qglobal name
	my $mine = "mine$area";

	# register mining attempt made
	# NOTE: qglobal registered for all clients (3) and expires in 1 hour (H1).
	#       meaning any defined mining area will "refill" ores in one hour from
	#       the last successful mining activity in it.
	quest::setglobal( $mine, ++$qglobals{$mine}, 3, "H1" );
	
}

# handle click of bloodmoon pickaxe
sub handle_35096 {

	GetMiningAreas();

	# NOTE: if you don't call CastSpell(), the client will go screwy...
	#       (this is because we were called via EVENT_ITEM_CLICK_CAST)
	# spell "Use Ability" with cast time set to 3sec
	$client->CastSpell( 7652, 0, 10, 3000 );
	quest::doanim(87);

	# verify if client is in a valid area for mining
	return
	  if not inMiningArea();

	# check for depletion of ores in current area
	if ( isDepleted() ) {
		$client->Message( 15, "This area looks mined out..." );
		return;
	}

	# TO DO: check for chance of success here
	# NOTE: probably want to base this on a player's skill stored some place
	#       and item (tool) bonuses, etc...
	
	# TO DO: yield materials here
	# NOTE: can consider yielding bonuses based on skills and items as well
	
	# increment depletion counters
	doneMining();
	
}

##############################
### END bloodmoon pick axe ###
##############################
quests\items\script_8556_mine.xml
Code:
<?xml version="1.0" ?>
<mine>
    <zone id='188' sn='tutoriala'>
        <area id='0' x=  '0' y=  '0' z=  '0' />
        <area id='1' x='100' y='100' z='100' />
    </zone>
    <zone id='189' sn='tutorialb'>
        <area id='0' x= '18' y='-147' z= '20' />
        <area id='1' x='180' y='-247' z='102' />
    </zone>
</mine>
__________________
I muck about @ The Forge.
say(rand 99>49?'try '.('0x'.join '',map{unpack 'H*',chr rand 256}1..2):'incoherent nonsense')while our $Noport=1;