Skip to content

Commit

Permalink
Implement pickpocketing
Browse files Browse the repository at this point in the history
  • Loading branch information
Allofich committed Jul 25, 2017
1 parent 39e6c49 commit 3b3ed6e
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Assets/Scripts/Game/Formulas/FormulaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ public static int CalculateExteriorLockpickingChance(int lockvalue, int lockpick
return lockpickingChance;
}

// Calculate chance of successfully pickpocketing a target
public static int CalculatePickpocketingChance(Entity.PlayerEntity player, Entity.DaggerfallEntityBehaviour target)
{
int chance = player.Skills.Pickpocket;
// If target is an enemy mobile, apply level modifier.
if (target)
{
Entity.EnemyEntity enemyEntity = target.Entity as Entity.EnemyEntity;
chance += 5 * ((player.Level) - (enemyEntity.Level));
}
return Mathf.Clamp(chance, 5, 95);
}

// Calculate how many uses a skill needs before its value will rise.
public static int CalculateSkillUsesForAdvancement(int skillValue, int skillAdvancementMultiplier, float careerAdvancementMultiplier, int level)
{
Expand Down
101 changes: 101 additions & 0 deletions Assets/Scripts/Game/PlayerActivate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,38 @@ void Update()
}
}

// Check for mobile NPC hit
MobilePersonMotor mobileNpc;
if (MobilePersonMotorCheck(hits[i], out mobileNpc))
{
switch (currentMode)
{
case PlayerActivateModes.Info:
case PlayerActivateModes.Grab:
case PlayerActivateModes.Talk:
break;
case PlayerActivateModes.Steal:
Pickpocket();
break;
}
}

// Check for mobile enemy hit
DaggerfallEntityBehaviour mobileEnemy;
if (MobileEnemyCheck(hits[i], out mobileEnemy))
{
switch (currentMode)
{
case PlayerActivateModes.Info:
case PlayerActivateModes.Grab:
case PlayerActivateModes.Talk:
break;
case PlayerActivateModes.Steal:
Pickpocket(mobileEnemy);
break;
}
}

// Trigger general quest resource behaviour click
// Note: This will cause a second click on special NPCs, look into a way to unify this handling
QuestResourceBehaviour questResourceBehaviour;
Expand Down Expand Up @@ -317,6 +349,26 @@ private bool NPCCheck(RaycastHit hitInfo, out StaticNPC staticNPC)
return false;
}

// Check if raycast hit a mobile NPC
private bool MobilePersonMotorCheck(RaycastHit hitInfo, out MobilePersonMotor mobileNPC)
{
mobileNPC = hitInfo.transform.GetComponent<MobilePersonMotor>();
if (mobileNPC != null)
return true;
else
return false;
}

// Check if raycast hit a mobile enemy
private bool MobileEnemyCheck(RaycastHit hitInfo, out DaggerfallEntityBehaviour mobileEnemy)
{
mobileEnemy = hitInfo.transform.GetComponent<DaggerfallEntityBehaviour>();
if (mobileEnemy != null)
return true;
else
return false;
}

// Check if raycast hit a QuestResource
private bool QuestResourceBehaviourCheck(RaycastHit hitInfo, out QuestResourceBehaviour questResourceBehaviour)
{
Expand Down Expand Up @@ -527,5 +579,54 @@ void QuestorCheck(StaticNPC npc)
DaggerfallUI.Instance.UserInterfaceManager.PushWindow(guildWindow);
}
}

// Player has clicked on a pickpocket target in steal mode
void Pickpocket(DaggerfallEntityBehaviour target = null)
{
// Classic allows pickpocketing of NPC mobiles and enemy mobiles.
// In early versions the only enemy mobiles that can be pickpocketed are classes,
// but patch 1.07.212 allows pickpocketing of creatures.
// For now, the only enemy mobiles being allowed by DF Unity are classes.
if (target && (target.EntityType != EntityTypes.EnemyClass))
return;

const int foundNothingValuableTextId = 8999;

PlayerEntity player = GameManager.Instance.PlayerEntity;
player.TallySkill((short)Skills.Pickpocket, 1);

int chance = Formulas.FormulaHelper.CalculatePickpocketingChance(player, target);

if (UnityEngine.Random.Range(0, 101) <= chance)
{
if (UnityEngine.Random.Range(0, 101) >= 33)
{
int pinchedGoldPieces = UnityEngine.Random.Range(0, 6) + 1;
player.GoldPieces += pinchedGoldPieces;
string gotGold;
if (pinchedGoldPieces == 1)
{
// Classic doesn't have this string, it only has the plural one
gotGold = HardStrings.youPinchedGoldPiece;
}
else
{
gotGold = HardStrings.youPinchedGoldPieces;
gotGold = gotGold.Replace("%d", pinchedGoldPieces.ToString());
}
DaggerfallUI.MessageBox(gotGold);
}
else
{
string noGoldFound = DaggerfallUnity.Instance.TextProvider.GetRandomText(foundNothingValuableTextId);
DaggerfallUI.MessageBox(noGoldFound);
}
}
else
{
string notSuccessfulMessage = HardStrings.youAreNotSuccessful;
DaggerfallUI.Instance.PopupMessage(notSuccessfulMessage);
}
}
}
}
4 changes: 4 additions & 0 deletions Assets/Scripts/Game/UserInterfaceWindows/HardStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public class HardStrings
"You see a pathetic excuse for a lock...",
"This lock is an insult to your abilities..."};

public const string youPinchedGoldPiece = "You pinched 1 gold piece."; // Not in classic.
public const string youPinchedGoldPieces = "You pinched %d gold pieces.";
public const string youAreNotSuccessful = "You are not successful...";

public const string skillImprove = "Your %s skill has improved.";
public const string mustDistributeBonusPoints = "You must distribute all bonus points.";

Expand Down

0 comments on commit 3b3ed6e

Please sign in to comment.