Skip to content

Thieving

Allofich edited this page Oct 31, 2020 · 4 revisions

Looking at a lock & lockpick formula

void LookAtLock(unsigned short lockDifficulty)
{
  ThievingTargetDifficulty = lockDifficulty;
  if (TopOfScreenTextCounter == 0 || TopOfScreenText != "Failure...")
  {
    unsigned short chanceOfSuccess;
    AttemptThieving(chanceOfSuccess);
    chanceOfSuccess /= 5;
    int index = chanceOfSuccess - 6;
    if (chanceOfSuccess < 6)
    {
      index = 0;
    }
    if (index >= 12)
    {
      index = 12;
    }
    
    char[] displayString;
    if (lockDifficulty >= 20)
    {
      displayString = "This is a magically held lock...";
    }
    else
    {
      displayString = lockMessages[index];
    }
    TopOfScreenTextCounter = 15;
    TopOfScreenText = displayString;
  }
  return;
}

// The same function is used both to get the chance of success for showing the lockpicking message and for actual attempts. It is also used for pickpocketing.
bool AttemptThieving(unsigned short& chanceOfSuccess)
{
  unsigned char playerSkill = Convert256Valueto100Value(PlayerCurrentIntelligence + PlayerCurrentAgility);
  chanceOfSuccess = ((playerSkill / LockpickingDivisors[PlayerClass & ID_Mask] * (PlayerLevel + 1)) * 100) / (ThievingTargetDifficulty * 100);
  int random = rand() % 100;
  if (chanceOfSuccess < 0)
  {
    chanceOfSuccess = 0;
  }
  if (chanceOfSuccess > 100)
  {
    chanceOfSuccess = 100;
  }
  if (chanceOfSuccess < random)
  {
    return true; // Thieving failed
  }
  return false; // Thieving succeeded
}

Lockpicking messages @3B304.

Pickpocketing

void AttemptPickpocket(void)
{
  ThievingTargetDifficulty = 4 - CityType;
  unsigned short chanceOfSuccess;
  bool attemptFailed = AttemptThieving(chanceOfSuccess);
  if (!attemptFailed)
  {
    if (arenaRand() < 20000)
    {
      int random = randomBetweenMinMax(0,4);
      PlayerGold = PlayerGold + random + 1;
      TemplateDatIndex = random + 1379; // You stole -- gold pieces
    }
    else
    {
      TemplateDatIndex = 1384; // You stole useless item
    }
    // Show message from TEMPLATE.DAT
    return;
  }
  bool guardsCanSpawn = IsFailedStealNoticed(chanceOfSuccess); // TODO
  if (guardsCanSpawn) {
    SetGuardSpawningForTheft(); // TODO
    return;
  }
  TopOfScreenText = "You are not successful...";
  TopOfScreenTextCounter = 15;
  return;
}
Clone this wiki locally