Redux v2 - Official 5065 Classic Source

03/28/2014 02:30 Aceking#1171
Quote:
Originally Posted by U2_Caparzo View Post
if there are few cases, you could code it in a switch statment, for example

int n = random.Next(3);
switch(n)
{
case 1: //50% {..}
case 2: //50% {...}
}

just noticed that Ace gave you a better example :p

if you got a bigger list of items with their drop chance you could write a simple class to handle those chances by you and then load them, just wrote this
Code:
public class ProbabilityManager<T>
    {
        private SafeRandom random;
        private SortedDictionary<int, T> probabilitiesPool;
        private int amountOfCases;

        public ProbabilityManager()
        {
            amountOfCases = 0;
            random = new SafeRandom();
            probabilitiesPool = new SortedDictionary<int, T>();
        }

        public void Add(T TObject, int probability)
        {
            amountOfCases += probability * 100;
            probabilitiesPool.Add(amountOfCases, TObject);
        }

        public bool Get(out T value)
        {
            int seed = random.Next(amountOfCases + 1);
            int accumulativeIndex = 0;
            value = default(T);
            for (int i = 0; i < probabilitiesPool.Count; i++)
            {
                var elementAtIndex = probabilitiesPool.ElementAt(i);
                accumulativeIndex += elementAtIndex.Key;
                if (elementAtIndex.Key >= seed)
                {
                    value = elementAtIndex.Value;
                    return true;
                }
            }
            return false;
        }
    }
note that in the class the probability of get one object is based on the amount of cases, for example, if you add
Add(T1, 2);
Add(T2, 3);

~60% of times that you use Get() you will get T2, and ~40% T1

you could create a new method to add "empty chance" so for example a mob could drop one of 4 items or none of them, i was lazy to code that
If the method was going to be used alot, then I would definitely go with a similar approach to yours where a class handles all the chance calculations and rewards etc.

But for an item or two, I think a simple if/else if structure works just fine.
03/28/2014 02:33 InsomniacPro#1172
So how come no one just uses ChanceSuccess? So easy.
03/28/2014 02:39 Aceking#1173
Quote:
Originally Posted by InsomniacPro View Post
So how come no one just uses ChanceSuccess? So easy.
Depends on the situation.

ChanceSuccess 'rolls' the dice each call. (Yes thats a metaphor).

In this situation, 'rolling' 5 different times wouldn't give you an accurate chance percentage.

He wants to give out an item based on a fixed percentage of one 'roll'.
03/28/2014 05:50 pro4never#1174
Quote:
Originally Posted by InsomniacPro View Post
So how come no one just uses ChanceSuccess? So easy.

It doesn't fit for this type of application.

Each roll is independent of eachother so doing

if(chanceSuccess(40))
action1
else if(chanceSuccess(40))
action 2

In that case action 1 has 40 percent chance to occur but action 2 has only a 24 percent chance to be triggered because it has a 40 percent chance during 60 percent of cases.
03/28/2014 05:58 InsomniacPro#1175
Yeah I realized after Ace made logical sense with the dice rolling analogy.
03/28/2014 12:59 -Zo#1176
thanks ace and other guys that helped me a lot :) i hope im not too annoying, at least the thread isn't death than :D
03/28/2014 23:17 patcac-patcac#1177
em ive been trying to do this the past day and it just wont work but how do i dublicate a map ? just inserting it in the database wont work ( I want the map for a quest )
03/28/2014 23:19 pro4never#1178
Quote:
Originally Posted by patcac-patcac View Post
em ive been trying to do this the past day and it just wont work but how do i dublicate a map ? just inserting it in the database wont work ( I want the map for a quest )
GameMap.dat controls what maps exist and links map ID with the tinymap file.
03/28/2014 23:27 patcac-patcac#1179
mhh ive added it to the databse addet it to GameMap.dat duplicated the file of the map 1014.tinymap but still it says map does not exists
03/29/2014 00:30 turk55#1180
Quote:
Originally Posted by patcac-patcac View Post
mhh ive added it to the databse addet it to GameMap.dat duplicated the file of the map 1014.tinymap but still it says map does not exists
Delete the tinymap folder and debug the source so it will recreate the files including the folder.
03/29/2014 03:12 Aceking#1181
You could create a dynamic map system, it's not hard to modify the current system honestly.

You just need to add the parameter for the dynamic ID.
You load the map files with the dynamic ID, and the spawns and NPC by the new map ID.
03/29/2014 11:31 patcac-patcac#1182
sadly i have no idea how to do that is there just a way to do it by still using the tinymap thingy ?
03/29/2014 11:46 -Zo#1183
#edited

solved that prob..
03/29/2014 14:40 pro4never#1184
Quote:
Originally Posted by Aceking View Post
You could create a dynamic map system, it's not hard to modify the current system honestly.

You just need to add the parameter for the dynamic ID.
You load the map files with the dynamic ID, and the spawns and NPC by the new map ID.
Pretty sure it already supports dynamic maps in this map system. Just need to convert it to load maps from the maps table rather than the game map file (only needed to export the original tinymap compressed resources).

The map table creates a list of mapIDs and links them to dmapIDs for lack of a better term. Standard maps such as twin city in this setup would have the same mapID as dmapID but maps which are duplicates would be be missmatched (just linking map ID used for spawns/portals/commands with the map file)



So yes, just find where the source loads its list of maps to be loaded and convert that to be using the maps table (which is already loaded by the server iirc)
03/29/2014 17:23 -Zo#1185
Sometimes if i hunt it tells me that a meteor has been dropped but i didn't see one.. what's wrong with that code?=O

Code:
            if (Common.PercentSuccess(DropManager.CHANCE_METEOR))
            {
                var killer = Map.Search<Player>(_killer);
                if (killer != null && killer.Character.LuckyTimeExpires > DateTime.Now)
                {
                    DropItemByID(1088001, _killer);
                    killer.Send(new TalkPacket(ChatType.Whisper, "[LuckyTime] Meteor has been dropped!"));
                }
            }