ArcEmu: [Applied]Fix Gold Loot - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read http://arcemu.org/fo...showtopic=26903
dfighter  : (01 January 2013 - 05:56 PM) Arcemu wishes you all a happy new year!
Hasbro  : (12 September 2012 - 10:01 AM) Please excuse our outage from the web! Our web host had a major malfunction!
dfighter  : (01 September 2012 - 04:05 PM) Since the spam bots just don't want to stop, I've enabled admin verification when registering.
dfighter  : (23 January 2012 - 09:56 PM) Please note that from now on you will need to confirm your email on the wiki in order to edit it!
Hasbro  : (31 December 2011 - 12:50 PM) Happy New Years all!
Navid  : (26 December 2011 - 04:09 AM) Merry Christmas !!!!!! Happy holidays all :)
WAmadeus  : (24 December 2011 - 03:54 PM) Merry Christmas to all!
dfighter  : (24 December 2011 - 11:05 AM) The Arcemu team wishes y'all a Merry Christmukkah!
Hasbro  : (05 October 2011 - 12:53 PM) Looking for web designers for upcoming web related project. If you're interested in designing user interfaces contact me
dfighter  : (02 September 2011 - 03:47 PM) So who here wants vehicles in Arcemu? :P http://arcemu.org/fo...showtopic=25440
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to irc.freenode.net join channel #arcemu /server irc.freenode.net:6667 /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check http://arcemu.org/fo...showtopic=25274
Hasbro  : (20 May 2011 - 05:27 PM) Looking for people experienced with CMake configuration and setup! Contact me asap
Hasbro  : (15 May 2011 - 05:03 PM) ArcEmu is recruiting C++ programmers, contact Hasbro if interested.
paroxysm  : (03 May 2011 - 06:26 PM) Updated luabridge gossip example to describe the whole gossip creation process rather than just how to create menu. Gossip tutorial
paroxysm  : (23 April 2011 - 11:35 AM) Lua writers can refer to the Luabridge Tutorials section in the Wiki to learn how to write gossip code correctly.
Hasbro  : (20 April 2011 - 05:22 PM) Thank you for your continuous contribution of bug reports, we are working on them.
Hasbro  : (17 April 2011 - 03:20 AM) Please consider donating to support our bills. Donations can be sent using PayPal to donations@arcemu.org - Thank you for your support.
paroxysm  : (10 April 2011 - 12:43 AM) Refer to the Luabridge Tutorials section in the Wiki to learn the new syntax of luabridge.
Resize Shouts Area

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Applied]Fix Gold Loot when money=0

#1 User is offline   Sadikum 

  • Interested
  • PipPipPipPip
  • Group: Members
  • Posts: 367
  • Joined: 16-June 08
  • Gender:Male

Posted 10 August 2010 - 08:38 AM

Patch Title: fix_goldloot.patch
What bug does this patch fix: It clean a bit the function generateLoot() and remove the part that generate a random amount of gold when money = 0 in DB
How to reproduce: Kill a rabbit, he'll drop money ><.

Index: Creature.cpp
===================================================================
--- Creature.cpp	(révision 3599)
+++ Creature.cpp	(copie de travail)
@@ -425,23 +425,16 @@
 void Creature::generateLoot()
 {
 
-	if( isCritter()  )
+	if( isCritter() || !loot.items.empty() )
 		return;
 
-	if ( !loot.items.empty() )
-		return;
-
-	if( m_mapMgr != NULL )
-		lootmgr.FillCreatureLoot( &loot, GetEntry(), m_mapMgr->iInstanceMode );
-	else
-		lootmgr.FillCreatureLoot( &loot, GetEntry(), 0 );
-
+	lootmgr.FillCreatureLoot( &loot, GetEntry(), m_mapMgr ? m_mapMgr->iInstanceMode : 0 );
 	loot.gold = proto->money;
 
 	// Master Looting Ninja Checker
 	if( sWorld.antiMasterLootNinja )
 	{
-		Player *looter = objmgr.GetPlayer((uint32)this->TaggerGuid);
+		Player *looter = objmgr.GetPlayer( static_cast<uint32>(TaggerGuid) );
 		if( looter && looter->GetGroup() && looter->GetGroup()->GetMethod() == PARTY_LOOT_MASTER )
 		{
 			uint16 lootThreshold = looter->GetGroup()->GetThreshold();
@@ -456,7 +449,7 @@
 				const char* itemColours[8] = { "9d9d9d", "ffffff", "1eff00", "0070dd", "a335ee", "ff8000", "e6cc80", "e6cc80" };
 				char buffer[256];
 				sprintf(buffer, "\174cff%s\174Hitem:%u:0:0:0:0:0:0:0\174h[%s]\174h\174r", itemColours[itr->item.itemproto->Quality], itr->item.itemproto->ItemId, itr->item.itemproto->Name1);
-				this->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, buffer);
+				SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, buffer);
 			}
 		}
 	}
@@ -472,26 +465,20 @@
 	 * (hopefully) get 24 random bits, which is then used to create a
 	 * normal distribution over 1/24th of the difference.
 	 */
-	if (( loot.gold > 0 ) && ( loot.gold < 12 ))
+	if( loot.gold >= 12 )
 	{
-		/* Don't use the below formula for very small cash - rouding
-		 * errors will be too bad.. */
-	}
-	else if ( loot.gold >= 12 )
-	{
-		uint32 random_bits;
-		double chunk_size;
-		double gold_fp;
+		uint32 random_bits = 0;
+		double chunk_size = 0.0;
+		double gold_fp = 0.0;
 
 		/* Split up the difference into 12 chunks.. */
-		chunk_size = ((double) loot.gold) / 12.0;
+		chunk_size = loot.gold / 12.0;
 
 		/* Get 24 random bits. We use the low order bits, because we're
 		 * too lazy to check how many random bits the system actually
 		 * returned. */
 		random_bits = rand () & 0x00ffffff;
 
-		gold_fp = 0.0;
 		while (random_bits != 0)
 		{
 			/* If last bit is one .. */
@@ -505,8 +492,7 @@
 
 		/* To hide your discrete values a bit, add another random
 		 * amount between -(chunk_size/2) and +(chunk_size/2). */
-		gold_fp += chunk_size
-			* ((((double) rand ()) / (((double) RAND_MAX) + 1.0)) - .5);
+		gold_fp += chunk_size * (rand() / (RAND_MAX + 1.0) - 0.5);
 
 		/*
 		 * In theory we can end up with a negative amount. Give at
@@ -518,23 +504,10 @@
 
 		/* Convert the floating point gold value to an integer again
 		 * and we're done. */
-		loot.gold = (uint32) (.5 + gold_fp);
+		loot.gold = static_cast<uint32>(0.5 + gold_fp);
 	}
-	else /* if(!loot.gold) */
-	{
-		CreatureInfo *info=GetCreatureInfo();
-		if (info->Type != UNIT_TYPE_BEAST)
-		{
-			if(m_uint32Values[UNIT_FIELD_MAXHEALTH] <= 1667)
-				//generate copper
-				loot.gold = (uint32)((info->Rank+1)*getLevel()*(rand()%5 + 1)); 
-			else
-				loot.gold = (uint32)((info->Rank+1)*getLevel()*(rand()%5 + 1)*(this->GetMaxHealth()*0.0006)); //generate copper
-		}
-	}
 
-	if ( loot.gold )
-		loot.gold = int32(float ( loot.gold ) * sWorld.getRate( RATE_MONEY ));
+	loot.gold *= static_cast<uint32>( sWorld.getRate( RATE_MONEY ) );
 }
 
 void Creature::SaveToDB()

Attached File(s)


Sorry for my english, I'm french.
0

#2 User is offline   dfighter 

  • Titles are overrated
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Administrator
  • Posts: 5,189
  • Joined: 14-June 08
  • IRC:dfighter
  • Gender:Male
  • Server OS:Linux

Posted 10 August 2010 - 01:06 PM

They don't drop money on the test realm, but that ofc doesn't mean that your patch is wrong per se. We will look into it ^^
Btw are you sure the rabbit you killed wasn't the easter rabbit? Maybe next year it wanted to give money to the kids instead of eggs :P
"The demand for free goods is infinite."
0

#3 User is offline   MesoX 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 296
  • Joined: 15-June 08
  • Gender:Male
  • Location:Czech Republic
  • Interests:pc & girls & parties

Posted 10 August 2010 - 02:13 PM

I think it should be redone like mangos have it (2 columns in DB instead of 1) because on retail you get random amount of money also from low lvl mob (for example range from 1 - 12 coopers) which is not done by current money generator. Anyway this system which is currently in ArcEmu is very complicated, slow and un-needed. I think generating random money between min and max value, which will be specified in DB is many times better then this proccess.
Posted Image
0

#4 User is offline   jackpoz 

  • ArcEmu Lemon Priest
  • PipPipPipPipPipPipPipPip
  • Group: Developers
  • Posts: 2,153
  • Joined: 19-June 08
  • Gender:Male
  • Location:Italy
  • Server OS:Windows

Posted 04 September 2011 - 06:39 AM

View PostSadikum, on 10 August 2010 - 08:38 AM, said:

How to reproduce: Kill a rabbit, he'll drop money ><.

void Creature::generateLoot()
{

	if(isCritter())
		return;

http://old.wowhead.com/npc=721

Quote

Name: Rabbit
Type: Database > NPCs > Critters

So those "how to reproduce" steps are wrong.

also using
loot.gold *= static_cast<uint32>( sWorld.getRate( RATE_MONEY ) );

rounds the float value returned by sWorld.getRate( RATE_MONEY ) to integer, increasing the round errors. It's much better to first multiply all the float values and then, at the end, cast to integer.
The patch is full of codestyle changes that shouldn't be included in a patch that is meant to just fix a bug.
Posted Image We develop dreams. Your dreams ;)
Posted ImagePosted Image
0

#5 User is offline   jackpoz 

  • ArcEmu Lemon Priest
  • PipPipPipPipPipPipPipPip
  • Group: Developers
  • Posts: 2,153
  • Joined: 19-June 08
  • Gender:Male
  • Location:Italy
  • Server OS:Windows

Posted 04 September 2011 - 07:06 AM

- Applied.
- Moved to applied patches.
Posted Image We develop dreams. Your dreams ;)
Posted ImagePosted Image
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users