Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 20:06

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Formula for randomized dropping?

Discussion on Formula for randomized dropping? within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 920
Formula for randomized dropping?

I need a formula for random coordinate dropping (players/monsters, items/gold) around a variable radius. The number of coordinates shouldn't be greater than 33 (4*8+1).

I've had many ideas, and the best I could come up with is creating an array of length radius*8+1, initializing the values in the array to the corresponding array index, and shuffling the values in the array using the Fisher-Yates shuffle algorithm (O(nlogn)). This is extremely time consuming as far as writing the code since I have to test each value in the array for equality 33 times and increment/decrement the testing x and y coordinates for each test.

Is this the most efficient way of doing this? If not, is there an algorithm for a array with a maximum of 33 values that sorts in faster time than Fisher-Yates?
Lateralus is offline  
Old 01/09/2011, 20:43   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,383
I think I'm completely missing the point here but are you not just wanting to pull random coords near a certain location?... Why would you go through all that trouble of generating all possible coords, shuffling them and then pulling one?


Just do a rand.next using bound X/Y and how far you want the spread.

Sorry if I'm missing the point of doing a more complex version but it does sound to me like you want to just pull a random coord nearby.

I've done a few versions of this... one being pull random coord and then check if it is free but you could just as easily do a for X for Y loop, check if it's free/valid and then return a list of valid coords...
pro4never is offline  
Old 01/09/2011, 23:50   #3
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 920
Quote:
Originally Posted by pro4never View Post
I think I'm completely missing the point here but are you not just wanting to pull random coords near a certain location?... Why would you go through all that trouble of generating all possible coords, shuffling them and then pulling one?


Just do a rand.next using bound X/Y and how far you want the spread.

Sorry if I'm missing the point of doing a more complex version but it does sound to me like you want to just pull a random coord nearby.

I've done a few versions of this... one being pull random coord and then check if it is free but you could just as easily do a for X for Y loop, check if it's free/valid and then return a list of valid coords...
That's what I want to do, but, and correct me if I'm wrong, doing a for X for Y loop, wouldn't exactly randomize the item/gold dropping, and pulling a random coordinate can be inefficient if there are few available spaces on the ground for the item/gold to drop onto.

Actually, do you know which method the official servers use? I assumed that it was randomized, but I'm not 100%.
Lateralus is offline  
Old 01/10/2011, 00:49   #4
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,383
I'm not sure what method the tq servers use but as for the 'most efficient' way of doing this... probably interfaces + some sort of data structuring the ground items.


The for x/y loop would obviously still need to be randomized (you'd receive a list of valid coords for dropping and then just randomize those which it seems is what you are already doing... but if you wanted to 'cheat' a bit you could store them as an array and just pull a random element 0-elementcount to avoid having some intensive randomization process (we're talking item drop locations here... it's not gotta be absolutely perfectly random lol!)


Personally I like the idea of doing that as it deals with crowded map floors easily.


My map system right now holds a dictionary of ground items using the structure <Coord, list<object>>. That way I ONLY pull coords that have elements on them (mob, player, items, etc) and can write simple methods to pull a list of items on screen or you could reverse that and find empty/non item'd coords.
pro4never is offline  
Thanks
1 User
Old 01/10/2011, 05:44   #5
 
elite*gold: 0
Join Date: Feb 2006
Posts: 550
Received Thanks: 82
this what your after?

Code:
public static Point validDropTile(int x, int y, int map) {
	int[][] dirs = {{x, y}, {x - 1, y}, {x, y - 1}, {x - 1, y - 1}, {x + 1, y + 1}, {x, y + 1}, {x + 1, y}, {x + 1, y - 1}, {x - 1, y + 1}};
	for(int i=0; i < dirs.length; i++) {
	    if(!isTileBlocked(map, dirs[i][0], dirs[i][1]) && !tileHasItem(dirs[i][0], dirs[i][1], map))
		return new Point(dirs[i][0], dirs[i][1]);
	}
	return null;
    }

    public static boolean tileHasItem(int x, int y, int map) {
	for(GroundItem i : World.getWorld().getMaps().get(map).getGroundItems()) {
	    if(i.getX() == x && i.getY() == y)
		return true;
	}
	return false;
    }
Code:
    if (player.getCharacter().getInventory().hasItem(uid)) {
		Item i = player.getCharacter().getInventory().getItem(uid);
		Point valid = Formula.validDropTile(player.getCharacter().getX(), player.getCharacter().getY(), player.getCharacter().getMapid());
		if (valid == null) {
		    return;
		}
		int map = player.getCharacter().getMapid();
		final GroundItem gi = new GroundItem(i.getUID(), i.getID(), i.getPlus(), i.getBless(), i.getEnchant(), i.getSoc1(), i.getSoc2(), (int) valid.getX(), (int) valid.getY(), map);
		player.getMap().addGroundItem(gi, valid, map);
		player.getCharacter().getInventory().removeItem(i);
		player.getActionSender().removeItem(i);
		World.getWorld().getTimerService().add(new Timer(90000, null) {

		    public void execute() {
			if (gi != null) {
			    World.getWorld().getMaps().get(gi.getMap()).getGroundItems().remove(gi);
			    for (Player p : World.getWorld().getMaps().get(gi.getMap()).getPlayers().values()) {
				if (Formula.inView(gi.getX(), gi.getY(), p.getCharacter().getX(), p.getCharacter().getY())) {
				    p.getCharacter().getItemsInView().remove(gi);
				    p.getActionSender().removeGroundItem(gi);

				}
			    }
			}
		    }
		});

	    }
ChingChong23 is offline  
Thanks
2 Users
Old 01/11/2011, 03:41   #6
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 920
Thank both of you very much, got it working!
Lateralus is offline  
Reply


Similar Threads Similar Threads
Release: Spontane sinnlose Idee! Randomized Teleport!
07/29/2010 - Diablo 2 Programming - 6 Replies
Imitiert einen Spieler der mit einzelnen Klicks auf sein Ziel zuteleportiert anstatt im Bot-Style direckt drauf zuzuhechten. Viel spaß beim ausprobieren und zuschauen. (K.A. ob es auf 3.0 version läuft, sollte aber denke ich.) Das 3.0 "MyCS_CatchShrine();" fehlt müsst ihr halt noch reinbasteln.
Can you help me? Attack formula !!
01/31/2010 - Aion - 0 Replies
- I want to ask about the attack's formula in INFO of the Character when equip weapon . - And how many defense i need to increase in order to decrease 1 damage. :confused:
Formula for Steeds Please
07/30/2009 - Conquer Online 2 - 3 Replies
What is the accurate formula for steed breeding (the 0.9+0.1 rough estimate isnt gonna cut it for rare steeds). Dont need a calculator either
Steed Formula
07/30/2009 - CO2 Private Server - 1 Replies
What is the accurate formula for steed breeding (the 0.9+0.1 rough estimate isnt gonna cut it for rare steeds). Dont need a calculator either
[Help]formula.ini function
01/31/2009 - Dekaron Private Server - 2 Replies
can any1 help me to explain the function of each line pls..i only know a little such as exp ratio, lvl and stat..it will be much easier for me if i know each of them..where can i edit my server DF time..? thanks wMaxLevel ,170 wMinLevelToLoseExp ,0 byStatPointPerLevel ,10 wDropMaxDistance ,180 fItemRatio ,0.5 fSTRDamageRatio ,0.4



All times are GMT +2. The time now is 20:06.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.