2 Questions, Selecting multiple coord & multiple inventory items

02/05/2013 16:20 ajstyles316#1
Need a hand with 2 things ive been tryin to work out but not had much luck so far.

1:Took this example from mining which sets the specific map, But how can you set multiple coords on the map so the action can only been done when standing in those coords rather then the entire map?


Code:
switch (client.Entity.MapID) 
{
case 1002:
                    {

                        Mine(700011, 700001, 700021, 700071, 1072010, 1072050, 1072031, 0, client);

                        break;

                    }
default:
 {
                        client.Send(new Message("You cannot mine here. You must go inside a mine.", System.Drawing.Color.Red, Message.TopLeft));

                        client.Mining = false;

                        break;

                    }

2: Below is the basic code for selecting if someone has a certain amount of a specific item in there bag and there removing them, How would you go about checking if they had multiple different items between a certain item number range, Say between item numbers 10000 and 10010 but which ever they had as long as there combined amount = say 10 u would remove them from there inventory?

For Example you could have:

10000 x3
10003 x4
10009 x3

or

10001 x2
10003 x6
10007 x3


Code:
if (client.Inventory.Contains(723467, 10))

                                    {

              client.Inventory.Remove(723467, 10);
02/05/2013 16:37 Super Aids#2
1. Just do a conditional statement for checking the coords of the character.
Ex.
Code:
if (client.X == 400 && client.Y == 400)
{
// mine
}
2.

If itemids are in a range and there is no id skips then you could do something like this:
Code:
bool allmatch = true;
for (int itemid = 1000; i < 1010; i++)
{
   if (!client.Inventory.Contains(itemid, 10))
        allmatch = false;
}

if (allmatch)
{
    // contains all
}
If you just want to remove based on that do:
Code:
for (int itemid = 1000; i < 1010; i++)
{
  if (client.Inventory.Contains(itemid, 10);
   client.Inventory.Remove(itemid, 10);
}
If the range does have skips then just do an array like:
Code:
uint[] itemids = new uint[]
{
    1000,
    1001,
    1003
    1010
};
foreach (int itemid in itemids)
{
    if (client.Inventory.Contains(itemid, 10))
       client.Inventory.Remove(itemid, 10);
}
And I could go on....
You get the idea.
02/05/2013 16:38 derpingson#3
so what i understood is that you're trying to make a condition for a specific map coords,

if you want to check for 1 map,x,y you may use
PHP Code:
if (client.Entity.MapID == 1002 && client.Entity.== 312 && client.Entity.== 121
and for multiple ones, just duplicate the code and separate it by || which means "OR"

PHP Code:
if ((client.Entity.MapID == 1002 && client.Entity.== 312 && client.Entity.== 121) || (client.Entity.MapID == 1002 && client.Entity.== 322 && client.Entity.== 131) || (client.Entity.MapID == 1002 && client.Entity.== 112 && client.Entity.== 121)) 
i don't know if this is what you're looking for, but i hope that this helped you


same idea for items

PHP Code:
if ((client.Inventory.Contains(ItemIDNUMBER) && (client.Inventory.Contains(ItemIDNUMBER) && (client.Inventory.Contains(ItemIDNUMBER)) 
PHP Code:
PS: || can mean OR  , && can mean AND 
Edit: Super Aids posted 10sec before me , his code may be more useful and practical than mine
02/05/2013 17:27 ajstyles316#4
yeah that looks like what im after, Thanks guys :)
02/05/2013 17:48 pro4never#5
If you want that sort of a mining system I'd suggest doing a collection of MapID, Points

Implementation would be different in various sources but inside your map class you could do List<Point> or you could have a Dictionary<ushort, List<Point>> where the key is the map id


Then when you receive the mining packet you say...


if(ValidMiningLocations.ContainsKey(user.MapID) && ValidMiningLocations[user.MapID].Contains(user.Location))
allowmining
else
no mining allowed here


This assumes you are using a Point style system for player coords but you can adjust it to suit your source and your needs.


As for your second question, it depends on how your source handles things.

Are you allowing stackable items? Here's an example based on my albetros source.

Code:
        public int ItemCountByIDRange(uint startID, uint endID)
        {
            var Items = from I in this.Inventory.Values where I.StaticID >= startID && I.StaticID <= endID select I;
            int count = 0;
            foreach (Structures.ItemInfo item in Items)
                count += Math.Max(1, (int)item.Amount);
            return count;
        }

LINQ is very useful
02/05/2013 18:55 ajstyles316#6
The main idea behind the mining one was a kind of fishing system, Using the rod accessory and the swingaxe action, so was going to be using the pier in bi for instance, marking off the coords around there so it would only work there, i guess to expand that to include multiple shore lines maybe the list<point> would work better for so many coordinates....
Only issue im havin so far is to do with the items, created a new item at 562002 next to hoe and pickaxe using the fishin rod and copied texture, mesh.c3 & weapon.c3 across but it dosent seem to want to show on the character when equipped, and the accessory wont work with 562000 pickaxe item range, Would there be a way to break that so the accessory could be equipped with the pick axe? From testin it seems the swingaxe action is locked into the 562000 range also as i cant get it to activate with another item number range?
02/05/2013 20:48 derpingson#7
adding a new item requires adding it in DBC files, which is something that you won't love to do.

if you can do that, i'd suggest an ID close to 2 handed weapons
02/05/2013 21:11 ajstyles316#8
Ahhh i see, Ive added lots of new items but nothing that you would equip as yet untill now, I had a quick browse thru the files and saw texture.dds mesh.c3 and weapon.c3 were all linked so did them but guess there is more to it with equipped items, Shall have to have a deeper dive into that side now.