diff Player.cpp @ 917:ae9e2a339b09

disappear items fix
author Ritor1
date Fri, 26 Apr 2013 17:35:19 +0600
parents 897b10712a1a
children a78f08dbeb88
line wrap: on
line diff
--- a/Player.cpp	Thu Apr 25 17:37:00 2013 +0600
+++ b/Player.cpp	Fri Apr 26 17:35:19 2013 +0600
@@ -234,7 +234,7 @@
   v6 = p2DEvents[a4 - 1].fPriceMultiplier;
   //v6 = p2DEvents_minus1__20[13 * a4];
   v7 = ((ItemGen *)(v5 + 532))->GetValue();
-  v8 = _4B8102(v7, v6);
+  v8 = GetPriceSell(v7, v6);
   if ( v5[552] & 2 )
     v8 = 1;
   if ( v8 < 1 )
@@ -340,14 +340,14 @@
 }
 
 //----- (004B8102) --------------------------------------------------------
-int Player::_4B8102(int a2, float a3)
+int Player::GetPriceSell(int uRealValue, float price_multiplier)
 {
   signed int v3; // esi@1
   signed int result; // eax@3
 
-  v3 = (unsigned __int64)(signed __int64)((double)a2 / (a3 + 2.0)) + a2 * GetMerchant() / 100;
-  if ( v3 > a2 )
-    v3 = a2;
+  v3 = (unsigned __int64)(signed __int64)((double)uRealValue / (price_multiplier + 2.0)) + uRealValue * GetMerchant() / 100;
+  if ( v3 > uRealValue )
+    v3 = uRealValue;
   result = 1;
   if ( v3 >= 1 )
     result = v3;
@@ -1794,124 +1794,180 @@
 
 //identf
 //----- (00490EEE) --------------------------------------------------------
-int Player::_490EEE(ItemGen *pItem, int a3, int a4, int a5)
-{
-  int v5; // eax@1
-  int result; // eax@1
-  unsigned int v7; // edx@1
-  unsigned int v8; // ecx@1
-  signed int v9; // esi@1
-  char v10; // zf@14
-  unsigned __int8 v11; // zf@22
-  char v12; // sf@22
-  unsigned __int8 v13; // of@22
-  float *v14; // esi@26
-  float v15; // ST04_4@26
-  signed int v16; // eax@26
-  int v17; // edi@26
-  float v18; // ST04_4@30
-  signed int v19; // eax@30
-  float v20; // ST04_4@34
-  signed int v21; // eax@34
-  signed int v22; // eax@34
-  float v23; // ST04_4@37
-  signed int v24; // eax@37
-  int v26; // [sp+10h] [bp-8h]@1
-  Player *v27; // [sp+14h] [bp-4h]@1
-
-  v27 = this;
-  v5 = GetActualSkillLevel(PLAYER_SKILL_MERCHANT);
-  v26 = v5;
-  result = 4;
-  v7 = pItem->uItemID;
-  v8 = pItem->uItemID;
-  v9 = pItemsTable->pItems[v8].uEquipType;
-  if ( (a3 != 4 || (signed int)v7 < 740 || (signed int)v7 > 771)
-    && ((signed int)v7 >= 600 || (signed int)v7 >= 529 && (signed int)v7 <= 599) )
+int Player::SelectPhrasesTransaction(ItemGen *pItem, int building_type, int BuildID_2Events, int ShopMenuType)
+{
+  int pSkillLevel; // eax@1
+  int NotBuy; // eax@1
+  int result;
+  signed int pEquipType; // esi@1
+  float *pPriceMultiplier; // esi@26
+  int pPriceItemService; // edi@26
+
+  pSkillLevel = GetActualSkillLevel(PLAYER_SKILL_MERCHANT);
+  NotBuy = 4;
+  pEquipType = pItemsTable->pItems[pItem->uItemID].uEquipType;
+  if ( (building_type != 4 || (signed int)pItem->uItemID < 740 || (signed int)pItem->uItemID > 771)
+    && ((signed int)pItem->uItemID >= 600 || (signed int)pItem->uItemID >= 529 && (signed int)pItem->uItemID <= 599) )
     return 5;
-  if ( a3 == 1 )
-  {
-    v13 = __OFSUB__(v9, 2);
-    v11 = v9 == 2;
-    v12 = v9 - 2 < 0;
-    goto LABEL_24;
-  }
-  if ( a3 == 2 )
-  {
-    if ( v9 < 3 )
-      return result;
-    v13 = __OFSUB__(v9, 9);
-    v11 = v9 == 9;
-    v12 = v9 - 9 < 0;
-LABEL_24:
-    if ( !((unsigned __int8)(v12 ^ v13) | v11) )
+  if ( building_type == BildingType_WeaponShop )
+  {
+    if ( pEquipType > EQUIP_BOW )
+      return NotBuy;
+    if (pItem->Stolen())
+      return 6;
+  }
+  if ( building_type == BildingType_ArmorShop )
+  {
+    if ( pEquipType < 3 && pEquipType > 9 )
+      return NotBuy;
+    if (pItem->Stolen())
+      return 6;
+  }
+  if ( building_type == BildingType_MagicShop )
+  {
+    if ( pItemsTable->pItems[pItem->uItemID].uSkillType == 38 )
+    {
+      if (pItem->Stolen())
+        return 6;
+      pPriceMultiplier = &p2DEvents[BuildID_2Events - 1].fPriceMultiplier;
+      pPriceItemService = GetBuyingPrice(pItem->GetValue(), *pPriceMultiplier);
+      if ( ShopMenuType == 3 )//Sell
+      {
+        pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier);
+        if (!pItem->Broken())
+        {
+          if ( pSkillLevel )
+            result = (pPriceItemService == pItem->GetValue()) + 2;
+          else
+            result = 1;
+          return result;
+        }
+        pPriceItemService = 1;
+        if ( pSkillLevel )
+          result = (pPriceItemService == pItem->GetValue()) + 2;
+        else
+          result = 1;
+        return result;
+      }
+      if ( ShopMenuType == 4 )//Identify
+      {
+        pPriceItemService = this->GetPriceIdentification(*pPriceMultiplier);
+        if ( pSkillLevel )
+          result = (pPriceItemService == pItem->GetValue()) + 2;
+        else
+          result = 1;
+        return result;
+      }
+      if ( ShopMenuType == 5 )//Repair
+      {
+        pPriceItemService = this->GetPriceRepair(pItem->GetValue(), *pPriceMultiplier);
+        if ( pSkillLevel )
+          result = (pPriceItemService == pItem->GetValue()) + 2;
+        else
+          result = 1;
+        return result;
+      }
+      if ( ShopMenuType != 6 )//Buy and ???
+      {
+        if ( pSkillLevel )
+          result = (pPriceItemService == pItem->GetValue()) + 2;
+        else
+          result = 1;
+        return result;
+      }
+      pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier) / 2;
+      if (pItem->Broken())
+        pPriceItemService = 1;
+      if ( pPriceItemService >= 1 )
+      {
+        if ( pSkillLevel )
+          result = (pPriceItemService == pItem->GetValue()) + 2;
+        else
+          result = 1;
+        return result;
+      }
+      pPriceItemService = 1;
+      if ( pSkillLevel )
+        result = (pPriceItemService == pItem->GetValue()) + 2;
+      else
+        result = 1;
       return result;
-    goto LABEL_16;
-  }
-  if ( a3 == 3 )
-  {
-    if ( pItemsTable->pItems[v8].uSkillType == 38 )
-      goto LABEL_16;
-    v10 = v9 == 16;
-    goto LABEL_15;
-  }
-  if ( a3 != 4 )
-    goto LABEL_26;
-  if ( v9 < 13 )
-    return result;
-  if ( v9 > 14 )
-  {
-    v10 = v9 == 17;
-LABEL_15:
-    if ( !v10 )
+    }
+    if ( pEquipType != EQUIP_BOOK )
+      return NotBuy;
+  }
+  if ( building_type == BildingType_AlchemistShop )
+  {
+    if ( pEquipType < EQUIP_REAGENT )
+      return NotBuy;
+    if ( pEquipType > EQUIP_POTION )
+    {
+      if ( pEquipType != EQUIP_MESSAGE_SCROLL )
+        return NotBuy;
+    }
+    if (pItem->Stolen())
+      return 6;
+  }
+  pPriceMultiplier = &p2DEvents[BuildID_2Events - 1].fPriceMultiplier;
+  pPriceItemService = GetBuyingPrice(pItem->GetValue(), *pPriceMultiplier);
+  if ( ShopMenuType == 3 )//Sell
+  {
+    pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier);
+    if (!pItem->Broken())
+    {
+      if ( pSkillLevel )
+        result = (pPriceItemService == pItem->GetValue()) + 2;
+      else
+        result = 1;
       return result;
-  }
-LABEL_16:
-  if (pItem->Stolen())
-    return 6;
-LABEL_26:
-  //v14 = &p2DEvents_minus1__20[13 * a4];
-  v14 = &p2DEvents[a4 - 1].fPriceMultiplier;
-  v15 = *v14;
-  v16 = pItem->GetValue();
-  v17 = GetBuyingPrice(v16, v15);
-  if ( a5 == 3 )
-  {
-    v23 = *v14;
-    v24 = pItem->GetValue();
-    v17 = v27->_4B8102(v24, v23);
-    if (!pItem->Broken())
-      goto LABEL_39;
-    goto LABEL_38;
-  }
-  if ( a5 == 4 )
-  {
-    v22 = v27->GetPriceIdentification(*v14);
-    goto LABEL_35;
-  }
-  if ( a5 == 5 )
-  {
-    v20 = *v14;
-    v21 = pItem->GetValue();
-    v22 = v27->GetPriceRepair(v21, v20);
-LABEL_35:
-    v17 = v22;
-    goto LABEL_39;
-  }
-  if ( a5 != 6 )
-    goto LABEL_39;
-  v18 = *v14;
-  v19 = pItem->GetValue();
-  v17 = v27->_4B8102(v19, v18) / 2;
+    }
+    pPriceItemService = 1;
+    if ( pSkillLevel )
+      result = (pPriceItemService == pItem->GetValue()) + 2;
+    else
+      result = 1;
+    return result;
+  }
+  if ( ShopMenuType == 4 )//Identify
+  {
+    pPriceItemService = this->GetPriceIdentification(*pPriceMultiplier);
+    if ( pSkillLevel )
+      result = (pPriceItemService == pItem->GetValue()) + 2;
+    else
+      result = 1;
+    return result;
+  }
+  if ( ShopMenuType == 5 )//Repair
+  {
+    pPriceItemService = this->GetPriceRepair(pItem->GetValue(), *pPriceMultiplier);
+    if ( pSkillLevel )
+      result = (pPriceItemService == pItem->GetValue()) + 2;
+    else
+      result = 1;
+    return result;
+  }
+  if ( ShopMenuType != 6 )//Buy and ???
+  {
+    if ( pSkillLevel )
+      result = (pPriceItemService == pItem->GetValue()) + 2;
+    else
+      result = 1;
+    return result;
+  }
+  pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier) / 2;
   if (pItem->Broken())
-    v17 = 1;
-  if ( v17 >= 1 )
-    goto LABEL_39;
-LABEL_38:
-  v17 = 1;
-LABEL_39:
-  if ( v26 )
-    result = (v17 == pItem->GetValue()) + 2;
+    pPriceItemService = 1;
+  if ( pPriceItemService >= 1 )
+  {
+    if ( pSkillLevel )
+      result = (pPriceItemService == pItem->GetValue()) + 2;
+    else
+      result = 1;
+    return result;
+  }
+  pPriceItemService = 1;
+  if ( pSkillLevel )
+    result = (pPriceItemService == pItem->GetValue()) + 2;
   else
     result = 1;
   return result;