Advertisement
Slowhand-VI

TUT: LOCKPICK TIMER/MECHANIC - lockers.fos

Jan 7th, 2016
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.87 KB | None | 0 0
  1. SOMEWHERE IN FUNCTION: bool UseSkillOnLocker(Critter& cr, Item& locker, int skill)
  2. ...
  3.         if(cr.Timeout[TO_SK_LOCKPICK] > 0)
  4.         {
  5.             cr.SayMsg(SAY_NETMSG, TEXTMSG_GAME, STR_SKILL_WEARINESS);
  6.             return true;
  7.         }
  8.  
  9.         if(locker.LockerId == 0 || FLAG(locker.LockerCondition, LOCKER_ISOPEN))
  10.         {
  11.             cr.SayMsg(SAY_NETMSG, TEXTMSG_GAME, STR_USE_NOTHING);
  12.             return true;
  13.         }
  14.  
  15.         int    base = cr.Skill[SK_LOCKPICK] - locker.LockerComplexity;
  16.         uint8  mode = 0;
  17.         uint16 activePid = cr.GetSlotProto(SLOT_HAND1, mode).ProtoId;
  18.         Item@  lockpicks = _CritGetItemHand(cr);
  19.  
  20.         //  Replace starts here //
  21.  
  22.         if(valid(lockpicks) && lockpicks.Proto.Misc_ToolSkillNum == SK_LOCKPICK)
  23.         {
  24.             base += lockpicks.Proto.Misc_ToolSkillBonus;
  25.         }
  26.         // Todo: PID_ELECTRONIC_LOCKPICKS, PID_ELEC_LOCKPICK_MKII
  27.  
  28.         int timeout;
  29.         int roll = Random(1, 100);
  30.         //  value of "base" is kept for timeout calculations
  31.         int clampedBase = CLAMP(base, 0, 95);
  32.         if(clampedBase >= roll)
  33.         {
  34.             int minTimeout = LOCKPICK_TIMEOUT(cr) / 4;
  35.             int maxTimeout = LOCKPICK_TIMEOUT(cr) * 3 / 4;
  36.             int factor = 50;    //  magic number, values around 50 are good in current setup, should be between an normal and an expanded lock pick set.
  37.             //  The formula below generates a fluid transition from min to max, depending on base (player skill, tools, lock complexity) and roll.
  38.             timeout = CLAMP(minTimeout + ((maxTimeout - minTimeout) * (factor - base + roll) / factor), minTimeout, maxTimeout);
  39.             if(locker.Proto.Container_Changeble && !LockerOpen(locker))
  40.                 Log("ERR: something wrong with this locker: " + locker.MapId + "," + locker.HexX + "," + locker.HexY + " pid " + locker.GetProtoId());
  41.             locker.LockerId = 0;
  42.             locker.LockerComplexity = 0;
  43.             // TODO: OnOpen ??
  44.             if(locker.GetType() == ITEM_TYPE_CONTAINER)
  45.                 cr.ShowContainer(null, locker, locker.Proto.GroundLevel ? TRANSFER_HEX_CONT_DOWN : TRANSFER_HEX_CONT_UP);
  46.             cr.StatBase[ST_EXPERIENCE] += 50;
  47.             LogExperience(cr, 50, SK_LOCKPICK, "Locker", locker.GetProtoId());
  48.             AddScore(cr, SCORE_CRACKER, 1);
  49.         }
  50.         else
  51.         {
  52.             //  Critical failure roll, if lock picks used, they will break.
  53.             if (roll > 95)
  54.             {
  55.                 if(valid(lockpicks) && lockpicks.Proto.Misc_ToolSkillNum == SK_LOCKPICK)
  56.                 {
  57.                     timeout = LOCKPICK_TIMEOUT(cr);
  58.                     cr.DeleteItem(lockpicks.GetProtoId(), 1);
  59.                     cr.Say(SAY_NETMSG, "Damn! You broke your lock picks!");
  60.                 }
  61.                 else
  62.                 {
  63.                     timeout = LOCKPICK_TIMEOUT(cr) * Random(2,5);
  64.                     cr.StatBase[ST_CURRENT_HP] -= Random(0, 5);
  65.                     cr.Say(SAY_NETMSG, "Ouch! You fingers hurt already!");
  66.                 }
  67.             //  failed critical "success", warn the player, that it will be very hard or impossible to open this lock.
  68.             else if (roll <= 5)
  69.             {
  70.                 timeout = LOCKPICK_TIMEOUT(cr);
  71.                 if (base <= 0)
  72.                 {
  73.                     cr.Say(SAY_NETMSG, "This lock seems impossible to pick!");
  74.                 }
  75.                 else
  76.                 {
  77.                     cr.Say(SAY_NETMSG, "Damn! You were so close!");
  78.                 }
  79.             }
  80.             //  normal failure
  81.             else
  82.             {
  83.                 cr.SayMsg(SAY_NETMSG, TEXTMSG_GAME, STR_SKILL_LOCKPICK_FAIL);
  84.                 timeout = LOCKPICK_TIMEOUT(cr);
  85.             }
  86.         }
  87.         _SetTimeout(cr, TO_SK_LOCKPICK, timeout);
  88.     }
  89.     //  Replace ends here   //
  90.     else if(skill == SK_SCIENCE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement