Crafting Bug

All Helbreath Server Source Discussion here.
Post Reply
Aliviar
noob
Posts: 13
Joined: Thu Jun 22, 2006 12:01 pm
Location: Denmark
Contact:

Post by Aliviar »

Hey i wonder if anyone would help me with my problem.. I have added Crafting to my server but it keeps says: Not enough ressources.. I cant find the error..

Code: Select all

  // Crafting
	case DEF_NOTIFY_CRAFTING_FAIL:  //reversed by Snoopy: 0x0BF1:
  ip  = (int *)cp;
  *ip = (int)sV1;
  cp += 4;
  iRet = m_pClientList[iToH]->m_pXSock->iSendMsg(cData, 10);
  break;

Code: Select all

	case DEF_NOTIFY_CRAFTING_SUCCESS:  //reversed by Snoopy: 0x0BF0
	case DEF_NOTIFY_PORTIONSUCCESS:
	case DEF_NOTIFY_LOWPORTIONSKILL:
	case DEF_NOTIFY_PORTIONFAIL:
	case DEF_NOTIFY_NOMATCHINGPORTION:
  // ÀÃ￾Ä¡ÇÃ￾´Â Æ÷¼Ç Ã￾¶ÇÕÀÌ ¾ø´Ù.
  iRet = m_pClientList[iToH]->m_pXSock->iSendMsg(cData, 6);
  break;

Code: Select all

  if (m_pCraftingConfigList[i] != NULL) delete m_pCraftingConfigList[i];	// Crafting
	}

Code: Select all

BOOL CGame::_bDecodePortionConfigFileContents(char *pData, DWORD dwMsgSize)
{char * pContents, * token, cTxt[120];
 char seps[] = "= \t\n";
 char cReadModeA = 0;
 char cReadModeB = 0;
 int  iPortionConfigListIndex = 0;
 int  iCraftingConfigListIndex = 0;
 class CStrTok * pStrTok;

	pContents = new char[dwMsgSize+1];
	ZeroMemory(pContents, dwMsgSize+1);
	memcpy(pContents, pData, dwMsgSize);
	pStrTok = new class CStrTok(pContents, seps);
	token = pStrTok->pGet();
	while( token != NULL ) {
  if (cReadModeA != 0) {
  	switch (cReadModeA) {
  	case 1:
    switch (cReadModeB) {

Code: Select all

case 2: // Crafting
    switch (cReadModeB) {
    case 1:	// 
    	if (_bGetIsStringIsNumber(token) == FALSE) 
    	{	PutLogList("(!!!) CRITICAL ERROR! CRAFTING configuration file error - Wrong Data format(1).");
      delete pContents; delete pStrTok; return FALSE;
    	}    	
    	if (m_pCraftingConfigList[atoi(token)] != NULL) 
    	{	PutLogList("(!!!) CRITICAL ERROR! CRAFTING configuration file error - Duplicate crafting number.");
      delete pContents; delete pStrTok; return FALSE;
    	}
    	m_pCraftingConfigList[atoi(token)] = new class CPortion;
    	iCraftingConfigListIndex = atoi(token);
    	cReadModeB = 2;
    	break;

    case 2:
    	ZeroMemory(m_pCraftingConfigList[iCraftingConfigListIndex]->m_cName, sizeof(m_pCraftingConfigList[iCraftingConfigListIndex]->m_cName));
    	memcpy(m_pCraftingConfigList[iCraftingConfigListIndex]->m_cName, token, strlen(token));
    	cReadModeB = 3;
    	break;

    default: // m_sArray[0~10]
    	if (_bGetIsStringIsNumber(token) == FALSE) 
    	{	PutLogList("(!!!) CRITICAL ERROR! CRAFTING configuration file error - Wrong Data format.");
      delete pContents; delete pStrTok; return FALSE;
    	}
    	m_pCraftingConfigList[iCraftingConfigListIndex]->m_sArray[cReadModeB - 3] = atoi(token);
    	cReadModeB++;
    	break;

    case 14: // m_sArray[11]
    	if (_bGetIsStringIsNumber(token) == FALSE) 
    	{	PutLogList("(!!!) CRITICAL ERROR! CRAFTING configuration file error - Wrong Data format.");
      delete pContents; delete pStrTok; return FALSE;
    	}
    	m_pCraftingConfigList[iCraftingConfigListIndex]->m_sArray[11] = atoi(token);
    	cReadModeB = 15;
    	break;

    case 15: // 
    	if (_bGetIsStringIsNumber(token) == FALSE) 
    	{	PutLogList("(!!!) CRITICAL ERROR! CRAFTING configuration file error - Wrong Data format.");
      delete pContents; delete pStrTok; return FALSE;
    	}
    	m_pCraftingConfigList[iCraftingConfigListIndex]->m_iSkillLimit = atoi(token);
    	cReadModeB = 16;
    	break;
	
    case 16:// 
    	if (_bGetIsStringIsNumber(token) == FALSE) 
    	{	PutLogList("(!!!) CRITICAL ERROR! CRAFTING configuration file error - Wrong Data format.");
      delete pContents; delete pStrTok; return FALSE;
    	}
    	m_pCraftingConfigList[iCraftingConfigListIndex]->m_iDifficulty = atoi(token);
    	cReadModeA = 0;
    	cReadModeB = 0;
    	break;

Code: Select all

  	if (memcmp(token, "crafting", 8) == 0) 
  	{	cReadModeA = 2;
    cReadModeB = 1;
  	}  	

Code: Select all

///  Crafting functions copyed on Alchemy functions...
//////////////////////////////////////////////////////////////////////////////////////////////////////
void CGame::ReqCreateCraftingHandler(int iClientH, char *pData)
{
 DWORD * dwp;
 WORD  * wp;
 char  * cp, cI[6], cCraftingName[21], cData[120];
 int    iRet, i, j, iEraseReq, iRiskLevel, iDifficulty, iNeededContrib = 0;
 short * sp, sTemp;
 short  sItemIndex[6], sItemPurity[6], sItemNumber[6], sItemArray[12];
 BOOL   bDup, bFlag, bNeedLog;
 class  CItem * pItem;

	if (m_pClientList[iClientH] == NULL) return;
	m_pClientList[iClientH]->m_iSkillMsgRecvCount++;

	for (i = 0; i < 6; i++) 
	{	cI[i] = -1;
  sItemIndex[i]  = -1;
  sItemNumber[i] = 0;
  sItemPurity[i] = -1;
	}
	cp = (char *)(pData + 11);
	cp += 20;
	cI[0] = *cp;
	cp++;
	cI[1] = *cp;
	cp++;
	cI[2] = *cp;
	cp++;
	cI[3] = *cp;
	cp++;
	cI[4] = *cp;
	cp++;
	cI[5] = *cp;
	cp++;

	for (i = 0; i < 6; i++) 
	{	if (cI[i] >= DEF_MAXITEMS) return;
  if ((cI[i] >= 0) && (m_pClientList[iClientH]->m_pItemList[cI[i]] == NULL)) return;
	}

	for (i = 0; i < 6; i++)
	if (cI[i] >= 0) 
	{	bDup = FALSE;
  for (j = 0; j < 6; j++) 
  if (sItemIndex[j] == cI[i]) 
  {	sItemNumber[j]++;
  	bDup = TRUE;
  }
  if (bDup == FALSE) 
  {	for (j = 0; j < 6; j++) 
  	if (sItemIndex[j] == -1) 
  	{	sItemIndex[j] = cI[i];
    sItemNumber[j]++;
    goto RCPH_LOOPBREAK;
  	}
RCPH_LOOPBREAK:;	
	}	}

	
	for (i = 0; i < 6; i++) 
	if (sItemIndex[i] != -1) 
	{	if (sItemIndex[i] < 0) return;
  if ((sItemIndex[i] >= 0) && (sItemIndex[i] >= DEF_MAXITEMS)) return;
  if (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]] == NULL) return;
  if (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_dwCount < sItemNumber[i]) return;
  sItemPurity[i] = m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_sItemSpecEffectValue2;
  if (   (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_cItemType == DEF_ITEMTYPE_NONE)
  	&& (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_sSprite == 6)
  	&& (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_sSpriteFrame == 129))
  {	sItemPurity[i] = 100; // Merien stones considered 100% purity.
  }  
  if (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_cItemType == DEF_ITEMTYPE_CONSUME)
  {	sItemPurity[i] = -1; // Diamonds / Emeralds.etc.. never have purity
  }
  if (sItemNumber[i] > 1) // No purity for stacked items
  {	sItemPurity[i] = -1;
  }
  /*wsprintf(G_cTxt, "Crafting: %d x %s (%d)"
  	, sItemNumber[i]
  	, m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_cName
  	, m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_sIDnum);
  PutLogList(G_cTxt);*/

  if (   (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_cItemType == DEF_ITEMTYPE_EQUIP)
  	&& (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_cEquipPos == DEF_EQUIPPOS_NECK))
  {	iNeededContrib = 10; // Necks Crafting requires 10 contrib
	}	}

	// Bubble Sort
	bFlag = TRUE;
	while (bFlag == TRUE) 
	{	bFlag = FALSE;
  for (i = 0; i < 5; i++) 
  if ((sItemIndex[i] != -1) && (sItemIndex[i+1] != -1)) 
  {	if ((m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_sIDnum) < (m_pClientList[iClientH]->m_pItemList[sItemIndex[i+1]]->m_sIDnum)) 
  	{	sTemp = sItemIndex[i+1];
    sItemIndex[i+1] = sItemIndex[i];
    sItemIndex[i] = sTemp;
    sTemp = sItemPurity[i+1];
    sItemPurity[i+1] = sItemPurity[i];
    sItemPurity[i] = sTemp;
    sTemp = sItemNumber[i+1];
    sItemNumber[i+1] = sItemNumber[i];
    sItemNumber[i] = sTemp;
    bFlag = TRUE;
	}	}	}
	j = 0;
	for (i = 0; i < 6; i++)
	{	if (sItemIndex[i] != -1)
    sItemArray[j] = m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_sIDnum;
  else sItemArray[j] = sItemIndex[i];
  sItemArray[j+1] = sItemNumber[i];
  j += 2;
	}

	// Search Crafting you wanna build
	ZeroMemory(cCraftingName, sizeof(cCraftingName));
	for (i = 0; i < DEF_MAXPORTIONTYPES; i++) 
	if (m_pCraftingConfigList[i] != NULL) 
	{	bFlag = FALSE;
  for (j = 0; j < 12; j++) 
  {	if (m_pCraftingConfigList[i]->m_sArray[j] != sItemArray[j]) bFlag = TRUE; // one item mismatch	
  }
  if (bFlag == FALSE) // good Crafting receipe
  {	ZeroMemory(cCraftingName, sizeof(cCraftingName));
  	memcpy(cCraftingName, m_pCraftingConfigList[i]->m_cName, 20);
  	iRiskLevel  = m_pCraftingConfigList[i]->m_iSkillLimit;  	// % to loose item if crafting fails
  	iDifficulty = m_pCraftingConfigList[i]->m_iDifficulty;
	}	}


	// Check if recipe is OK
	if (strlen(cCraftingName) == 0) 
	{	SendNotifyMsg(NULL, iClientH, DEF_NOTIFY_CRAFTING_FAIL, 1, NULL, NULL, NULL); // "There is not enough material"
  return;
	}
	// Check for Contribution
	if (m_pClientList[iClientH]->m_iContribution < iNeededContrib)
	{	SendNotifyMsg(NULL, iClientH, DEF_NOTIFY_CRAFTING_FAIL, 2, NULL, NULL, NULL); // "There is not enough Contribution Point"	
  return;
	}
	// Check possible Failure
	if (iDice(1,100) > iDifficulty) 
	{	SendNotifyMsg(NULL, iClientH, DEF_NOTIFY_CRAFTING_FAIL, 3, NULL, NULL, NULL); // "Crafting failed"
  // Remove parts...
  pItem = NULL;
  pItem = new class CItem;
  if (pItem == NULL) return;
  for (i = 0; i < 6; i++)
  if (sItemIndex[i] != -1) 
  {	// Deplete any Merien Stone
  	if (   (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_cItemType == DEF_ITEMTYPE_NONE)
    && (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_sSprite == 6)
    && (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_sSpriteFrame == 129))
  	{	ItemDepleteHandler(iClientH, sItemIndex[i], FALSE, FALSE);
  	}else 
  	// Risk to deplete any other items (not stackable ones) // DEF_ITEMTYPE_CONSUME
  	if (   (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_cItemType == DEF_ITEMTYPE_EQUIP)
    || (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_cItemType == DEF_ITEMTYPE_MATERIAL))
  	{	if (iDice(1,100) < iRiskLevel)	
    {	ItemDepleteHandler(iClientH, sItemIndex[i], FALSE, FALSE);
  }	}	}
  return;
	}

	// Purity
	int iPurity, iTot = 0, iCount = 0;
	for (i = 0; i < 6; i++) 
	{	if (sItemIndex[i] != -1) 
  {	if (sItemPurity[i] != -1) 
  	{	iTot += sItemPurity[i];
    iCount ++;
	}	}	}
	if (iCount == 0 ) 
	{	iPurity = 20 + iDice(1,80);  	// Wares have random purity (20%..100%)
  bNeedLog = FALSE;
	}else 
	{	iPurity = iTot/iCount;
  iTot    = (iPurity*4)/5;
  iCount  = iPurity - iTot;
  iPurity = iTot + iDice(1,iCount);	// Jewel completion depends off Wares purity
  bNeedLog = TRUE;
	}
	if (iNeededContrib != 0) 
	{	iPurity = 0;      // Necks require contribution but no purity/completion
  bNeedLog = TRUE;
	}
	//CalculateSSN_SkillIndex(iClientH, 12, 1);

	if (strlen(cCraftingName) != 0) 
	{	pItem = NULL;
  pItem = new class CItem;
  if (pItem == NULL) return;
  for (i = 0; i < 6; i++)
  {	if (sItemIndex[i] != -1) 
  	{	if (m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_cItemType == DEF_ITEMTYPE_CONSUME)
    {	SetItemCount(iClientH, sItemIndex[i], 
      m_pClientList[iClientH]->m_pItemList[sItemIndex[i]]->m_dwCount - sItemNumber[i]);    	
    }else // So if item is not Type 5 (stackable items), you deplete item
    {	ItemDepleteHandler(iClientH, sItemIndex[i], FALSE, FALSE);
  }	}	}
  if (iNeededContrib !=0)
  {	m_pClientList[iClientH]->m_iContribution -= iNeededContrib;   
  	// No known msg to send info to client, so client will compute shown Contrib himself.  
  }

  SendNotifyMsg(NULL, iClientH, DEF_NOTIFY_CRAFTING_SUCCESS, NULL, NULL, NULL, NULL);

  m_pClientList[iClientH]->m_iExpStock += iDice(2, 100);

  if ((_bInitItemAttr(pItem, cCraftingName) == TRUE))

Code: Select all

  	// SNOOPY log anything above WAREs
  	if (bNeedLog)  	
  	{	wsprintf(G_cTxt, "PC(%s) Crafting (%s) Purity(%d)"
    	, m_pClientList[iClientH]->m_cCharName
    	, pItem->m_cName
    	, pItem->m_sItemSpecEffectValue2);	
Please help me..

Arah
Regular
Posts: 51
Joined: Mon Aug 07, 2006 1:51 pm
Location: FROM HELL

Post by Arah »

I have this problem too but i have no idea how to fix that.
<span style='color:#F7F7F7'>If you read this you are dumb ;-Þ</span>
Charles
Loyal fan
Posts: 418
Joined: Wed Nov 26, 2003 8:20 pm

Post by Charles »

don't touch it if you don't know how it works -.-
<i>"Always write good code. Feel bad to write bad code."</i>
diuuude
Outpost bitch
Posts: 592
Joined: Wed Dec 28, 2005 11:57 pm

Post by diuuude »

I recently used some of snoopy's crafting code but it was really shitty, i had alot of things to edit or recode, but it's still a great basis to start addinf crafting.

I don't load the ingredients the same way as he does and i added a new class for it, but if i remember well, one side handles each item separately (neck + neck + xxx) and the other one handles it like (2 necks + XXX). It's easy to fix, printing all the crafting operations in a file, client and server side. This way you should be able to trace the problem.
<a href='http://www.technohell.net' target='_blank'><b><span style='color:red'>>>> Helbreath Ressources Website Here <<<</span></b></a><br>C++ Sources, Tools, Server Files, Help on Forum, C++ Snippets, Toplist... Updated often, come visit us !
Charles
Loyal fan
Posts: 418
Joined: Wed Nov 26, 2003 8:20 pm

Post by Charles »

sorry for off-topic, but hi diuuude lol
<i>"Always write good code. Feel bad to write bad code."</i>
Arah
Regular
Posts: 51
Joined: Mon Aug 07, 2006 1:51 pm
Location: FROM HELL

Post by Arah »

diuuude wrote:I recently used some of snoopy's crafting code but it was really shitty, i had alot of things to edit or recode, but it's still a great basis to start addinf crafting.

I don't load the ingredients the same way as he does and i added a new class for it, but if i remember well, one side handles each item separately (neck + neck + xxx) and the other one handles it like (2 necks + XXX). It's easy to fix, printing all the crafting operations in a file, client and server side. This way you should be able to trace the problem.
[irony]Ah, yes, thank you. Now i understand everything. I didnt try to fix this problem, and now with ur help (???) i can fix it. Its so easy to trace and fix this problem :D[/irony]

Hmm your comment didn't help a lot lol.
<span style='color:#F7F7F7'>If you read this you are dumb ;-Þ</span>
Charles
Loyal fan
Posts: 418
Joined: Wed Nov 26, 2003 8:20 pm

Post by Charles »

thinking way back wasn't there a fault in it that didn't read all the numbers in the cfg? i could be wrong though, have to search through topics and can't right now lol.
<i>"Always write good code. Feel bad to write bad code."</i>
Aliviar
noob
Posts: 13
Joined: Thu Jun 22, 2006 12:01 pm
Location: Denmark
Contact:

Post by Aliviar »

diuuude wrote: I recently used some of snoopy's crafting code but it was really shitty, i had alot of things to edit or recode, but it's still a great basis to start addinf crafting.

I don't load the ingredients the same way as he does and i added a new class for it, but if i remember well, one side handles each item separately (neck + neck + xxx) and the other one handles it like (2 necks + XXX). It's easy to fix, printing all the crafting operations in a file, client and server side. This way you should be able to trace the problem.
Okay thank you. I try it out.. :)
Post Reply