Drop loop?

04/13/2013 16:54 LordGragen.#1
hey guys, so last night i was working on my monster drop system and i found something that's kinda confused me.

so here is how i make my monsters drop the things i want them.

Code:
 #region GreenCobra ston drop 

            if (Name == "GreenCobra" || Name == "Protector" || Name == "GhostFinder" && ServerBase.Kernel.percentSuccess(15))
            {

                uint Uid = 0;
                byte type = (byte)ServerBase.Kernel.Random.Next(1, 5);
                switch (type)
                {
                    case 1: Uid = 727851; break;
                    case 2: Uid = 727851; break;
                    case 3: Uid = 727851; break;
                    case 4: Uid = 1458958; break;
                    case 5: Uid = 1458958; break;

                }

                if (Uid != 0)
                {
                    ushort X = Owner.X, Y = Owner.Y;
                    Game.Map Map = ServerBase.Kernel.Maps[Owner.MapID];
                    if (Map.SelectCoordonates(ref X, ref Y))
                    {
                        Network.GamePackets.FloorItem floorItem = new Network.GamePackets.FloorItem(true);
                        floorItem.Item = new Network.GamePackets.ConquerItem(true);
                        floorItem.Item.ID = Uid;
                        floorItem.Item.MaximDurability = floorItem.Item.Durability = 65535;
                        floorItem.Item.MobDropped = true;
                        floorItem.Item.StackSize = 1;
                        floorItem.Item.MaxStackSize = 65535;
                        floorItem.Item.UID = Network.GamePackets.ConquerItem.ItemUID.Next;
                        floorItem.ValueType = Network.GamePackets.FloorItem.FloorValueType.Item;
                        floorItem.ItemID = Uid;
                        floorItem.MapID = Owner.MapID;
                        floorItem.MapObjType = Game.MapObjectType.Item;
                        floorItem.X = X;
                        floorItem.Y = Y;
                        floorItem.Type = Network.GamePackets.FloorItem.Drop;
                        floorItem.OnFloor = Time32.Now;
                        floorItem.ItemColor = floorItem.Item.Color;
                        floorItem.UID = Network.GamePackets.FloorItem.FloorUID.Next;
                        while (Map.Npcs.ContainsKey(floorItem.UID))
                            floorItem.UID = Network.GamePackets.FloorItem.FloorUID.Next;
                        Map.AddFloorItem(floorItem);
                        SendScreenSpawn(floorItem);
                    }
                }
            }
            #endregion

but somehow when i add more then 1 monster in this code , it start to loop. as you can see it says 15% only but when i kill the monster its 100% drop on all of them.

but if i make the code use only 1 monster not 3 it works fine.
04/13/2013 17:25 pro4never#2
Your logic is wrong...

You need to put all your OR code in brackets.

if pheasant AND chancesuccess

that means it has to be both

if pheasant OR turtledove AND chancesuccess

this means pheasants will give 100 percent droprates and turtledoves will give chancesuccess drop rate.


(turtledove OR pheasant OR robin) AND chancesuccess

that's what you're looking for
04/13/2013 17:41 urgabel#3
Quote:
Originally Posted by LordGragen. View Post
Code:
                byte type = (byte)ServerBase.Kernel.Random.Next(1, 5);
                switch (type)
                {
                    case 1: Uid = 727851; break;
                    case 2: Uid = 727851; break;
                    case 3: Uid = 727851; break;
                    case 4: Uid = 1458958; break;
                    case 5: Uid = 1458958; break;
                }
case 5 will never trigger, as you get a random less than 5, not including 5.
04/13/2013 18:24 LordGragen.#4
thank you pro4never.

@urgabel thank you i didn't even notice that i just checked you where right.

when you get a bit of free time please do explain little more XD like what changes i may do to make it work. no need to give out codes if you don't want just clear words will put me in the right position.
04/13/2013 18:33 _tao4229_#5
&& binds more closely than ||

[Only registered and activated users can see links. Click Here To Register...]
04/13/2013 19:39 pro4never#6
Quote:
Originally Posted by LordGragen. View Post
thank you pro4never.

@urgabel thank you i didn't even notice that i just checked you where right.

when you get a bit of free time please do explain little more XD like what changes i may do to make it work. no need to give out codes if you don't want just clear words will put me in the right position.
Tao already answered your question but here's a somewhat simplified version.

Think of it like in math.

1 + 10 * 5

In that case * takes precedence and the answer can be thought of as 1 + 50 because you perform the multiplication first. BEDMAS and all that random highschool math crap

Order of operations - Wikipedia, the free encyclopedia

The same is true of boolean operations with AND statements taking priority over OR statements. As such you have to put in your own brackets to force the logic to flow the way you want.

He already provided a link explaining it so I'll leave you to your reading ^^

if((mob.name == "Pheasant" || mob.name == "Turtledove") && chanceSuccess(15))
{
//run
}

That's what you're looking for in this case.