Some buy shop code

Forum closed. All further discussion to be discussed at https://github.com/OpenKore/

Moderator: Moderators

Message
Author
Motivus
Developers
Developers
Posts: 157
Joined: 04 Apr 2008, 13:33
Noob?: Yes

Some buy shop code

#1 Post by Motivus »

NOTE: None of this was designed to be put in the bot. It doesn't follow the convention used by other functions. I use this for my market site. If anyone was looking to write it maybe they can devour some parts of mine, because most of the groundwork is laid out. I made use of klab's structs, and I can guarantee all the functions shown work on iRO.

Code: Select all

		'0813' => ['bshop_open_item_list', 'v a4 V a*', [qw(len selfID max_zeny item_list)]], # -1
		'0814' => ['bshop_present', 'a4 A80', [qw(makerID title)]],
		'0816' => ['bshop_lost', 'a4', [qw(makerID)]],
		'0818' => ['bshop_item_list', 'v a4 a4 V a*', [qw(len makerID storeID max_zeny item_list)]], #-1 0x0 int price, 0x4 short count, 0x6 uchar type, 0x7 ushort id
		'081A' => ['bshop_failed_buy', 'v', [qw(result)]],
		'081B' => ['bshop_update_item', 'a2 v V', [qw(item_id count zeny)]],
		'081C' => ['bshop_delete_item', 'v v V', [qw(ind count zeny)]], 



sub bshop_present {
	my ($self, $args) = @_;
	my $ID = $args->{makerID};
	
	my $str_id = unpack('l', $ID);
	
	if (!$venderLists{$ID} || !%{$venderLists{$ID}}) {
		binAdd(\@venderListsID, $ID);
		Plugins::callHook('packet_bshop', {ID => $ID});
	}
	$venderLists{$ID}{title} = bytesToString($args->{title});
	$venderLists{$ID}{id} = $ID;

}
sub bshop_lost {
	my ($self, $args) = @_;

	my $ID = $args->{makerID};
	binRemove(\@venderListsID, $ID);
	delete $venderLists{$ID};
}

sub bshop_item_list {
	my ($self, $args) = @_;
	
	my $headerlen = 16;
	
	undef @venderItemList;
	undef $venderID;

	$venderID = $args->{makerID};
	#$venderCID = $args->{venderCID} if exists $args->{venderCID};
	my $player = Actor::get($venderID);
		
	my $index=0;
	for (my $i = $headerlen; $i < $args->{RAW_MSG_SIZE}; $i+=9) {
		my $item = {};
		
		($item->{price},
		$item->{amount},
		$item->{type},
		$item->{nameID})	= unpack('V v C v', substr($args->{RAW_MSG}, $i, 9));
		
		$item->{name} = itemName($item);
		$venderItemList[$index] = $item;
		$index++;
		message(TF("\n Item added to Vender Store: %s - %d z - %d x\n", $item->{name}, $item->{price}, $item->{amount}) , "bshop");

		Plugins::callHook('packet_bshop_store', {
			venderID => $venderID,
			number => $index,
			name => $item->{name},
			amount => $item->{amount},
			price => $item->{price},
			type => $item->{type}
		});

	}
	
	Plugins::callHook('packet_bshop_store2', {
		venderID => $venderID,
		itemList => \@venderItemList
	});
}
and for send

Code: Select all

sub sendViewBshop {
	my ($self, $makerID) = @_;
	my $msg = pack("C*", 0x17, 0x08) . $makerID;
	$self->sendToServer($msg);
}
Oh no.

User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: Some buy shop code

#2 Post by kLabMouse »

Buy Shop is a good Feature.
But... It also needs a few things:
1) Same looking system as Sell shop
2) Console commands
3) Some abstraction layer to integrate "Sell" and "Buy" shop system into one.

DrKN
Developers
Developers
Posts: 79
Joined: 06 Oct 2010, 09:22
Noob?: No

Re: Some buy shop code

#3 Post by DrKN »

yeah i was doing on that.
lets have a test on yours code

Locked