Quantcast

Jump to content


Photo

Item Handling in NCC


  • Please log in to reply
9 replies to this topic

#1 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 26 November 2009 - 05:55 AM

Now... I know you guys are seriously itching to see more of NCC... and I should probably give the same treatment to people who just read the forum to the people who are in IRC.

This is how NCC is going to handle items on Neopets. Just a short example and explanation here.

http://pastebin.com/m4b6d8648

As you can see, I've created my Item class here which holds the item name and description (the description is always held in the ALT text of an item image).
I've created a class called MainShopItem that derives from Item (and therefore holds all of the same properties as Item) with a few extended properties specific to a MainShopItem including BuyLink, NumInStock and Price.

You can also see a method I've defined there, GrabMainShopItems - this returns a list of MainShopItems and you can pass in a ShopID.
So - it'll return you a list of MainShopItems - each with the BuyLink, NumInStock, Price, Name and Description - from which you can then search your specified list and figure out whether you need to go onto the next step and actually buy the item.

Let's say the 5th item in the shop is "Cloud Kau Morphing Potion" and I want to buy it.
I could then use my other method BuyItem and pass in the required parameters - the item I want to buy and for what price (for price, you can enter your own Haggle algorithm or I might include a few of my own.)

The full code for an example can be found at the link below:

http://pastebin.com/m1e297296

#2 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 26 November 2009 - 06:19 AM

Could you not use the List.FindAll function for the item matching? Then you'll only have to loop through the buylist items rather than looping through the buylist items for every shop list item, right?

#3 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 26 November 2009 - 07:20 AM

Could you not use the List.FindAll function for the item matching? Then you'll only have to loop through the buylist items rather than looping through the buylist items for every shop list item, right?


Yeah you could, but an even better solution would be to use LINQ, it was meant as a ... readable example.

 	MainShops.GrabMainShopItems(2)
 	.Any(i => i.Name == "Starry Kau Morphing Potion");
to search for specifically "Starry Kau Morphing Potion"

You could also experiment more with LINQ - it has quite a few fun functions like that - just lambdas might be a bit .. confusing for the newbies :p

#4 Backslash

Backslash
  • 47 posts

Posted 26 November 2009 - 12:47 PM

I never knew C# looked so much like Javascript. :p

#5 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 27 November 2009 - 03:02 AM

I never knew C# looked so much like Javascript. :p


You have much to learn, young padawan. ;)

#6 Adam

Adam
  • Coffee God


  • 4771 posts


Users Awards

Posted 27 November 2009 - 07:32 AM

You have much to learn, young padawan. ;)


!!! I'm the only padawan :( I just have been REAL busy lately.

#7 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 27 November 2009 - 04:51 PM

!!! I'm the only padawan :( I just have been REAL busy lately.


Come on IRC more :p I miss you, student!

#8 Backslash

Backslash
  • 47 posts

Posted 29 November 2009 - 11:30 AM

Ive always wanted to ask, whats IRC?

#9 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2009 - 11:39 AM

http://www.neocodex.us/forum/ircChat/

#10 LittleOne

LittleOne
  • 153 posts

Posted 29 November 2009 - 12:48 PM

Ive always wanted to ask, whats IRC?


IRC is basically a chatrrom!

we have a lot of gigles in there as well as assisting each other with anything there is a forum in 'chit-chat' of the fun times we all have in there

but its location is a guarded secret.....apparently!!!!


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users