Skip to content

Commit

Permalink
fix payout not cheating
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvd committed Mar 1, 2023
1 parent d600b7f commit c8f6d21
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion About/Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.2
1.0.3
40 changes: 33 additions & 7 deletions Source/SlotMachineJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected override IEnumerable<Toil> MakeNewToils()
{
var cash = pawn.inventory.innerContainer?.FirstOrDefault(t => t?.def == ThingDefOf.Silver);
if (cash != null && cash.stackCount >= vendingMachine.CurrentPrice){
comp.TotalRevenue += vendingMachine.CurrentPrice;
vendingMachine.ReceivePayment(pawn.inventory.innerContainer, cash);
}
else
Expand Down Expand Up @@ -89,21 +90,21 @@ protected override IEnumerable<Toil> MakeNewToils()
if (comp.eventManager.outcome == SlotGameOutcome.Single)
{
int silverRewarded = vendingMachine.CurrentPrice;
comp.TotalPayout += silverRewarded;
if (JobJoyHelper.CheckIfShouldPay(pawn, TargetThingA))
{
comp.TotalPayout += silverRewarded;
JobJoyHelper.GiveRewardToPawn(pawn, silverRewarded, pawn.Faction != TargetThingA.Faction, ThingDefOf.Silver, vendingMachine);
}
extraJoy += 0.2f;
}
if (comp.eventManager.outcome == SlotGameOutcome.Double)
{
int silverRewarded = vendingMachine.CurrentPrice*2;
comp.TotalPayout += silverRewarded;
if (silverRewarded > 0)
{
if (JobJoyHelper.CheckIfShouldPay(pawn, TargetThingA))
{
comp.TotalPayout += silverRewarded;
JobJoyHelper.GiveRewardToPawn(pawn, silverRewarded, pawn.Faction != TargetThingA.Faction, ThingDefOf.Silver, vendingMachine);
}
}
Expand All @@ -115,7 +116,6 @@ protected override IEnumerable<Toil> MakeNewToils()

int silverRewarded = 10*vendingMachine.CurrentPrice;
if (comp.eventManager.slotType==0) {
silverRewarded = 100*vendingMachine.CurrentPrice;
pawn.needs.mood.thoughts.memories.TryGainMemory(MyDefs.HC_WonSlotMachineGame);
extraJoy += 1f;
}
Expand All @@ -137,11 +137,15 @@ protected override IEnumerable<Toil> MakeNewToils()
{
if (JobJoyHelper.CheckIfShouldPay(pawn, TargetThingA))
{
comp.TotalPayout += silverRewarded;
JobJoyHelper.GiveRewardToPawn(pawn, silverRewarded, pawn.Faction != TargetThingA.Faction, ThingDefOf.Silver, vendingMachine);
}
extraJoy += 5f;
}
}
//Log.Message(" revenue=" + comp.TotalRevenue);
//Log.Message(" payout=" + comp.TotalPayout);

// pawn stops after 10 games
if (++comp.eventManager.gamesPlayed > 10) {
comp.eventManager.EndGame();
Expand Down Expand Up @@ -220,10 +224,32 @@ public static int CountSilver(Pawn pawn)
}
public static void GiveRewardToPawn(Pawn pawn, int amount, bool isGuest, ThingDef rewardDef, CompVendingMachine vendingMachine)
{
var cash = vendingMachine.MainContainer?.FirstOrDefault(t => t?.def == ThingDefOf.Silver);
if (cash == null) return;
var payAmount = Mathf.Min(cash.stackCount, amount);
var paid = vendingMachine.MainContainer.TryTransferToContainer(cash, pawn.inventory.innerContainer, payAmount);
int payFromMachine;
int payFromStorage;
var cashOnMachine = vendingMachine.MainContainer?.FirstOrDefault(t => t?.def == ThingDefOf.Silver);
if (cashOnMachine == null) {
payFromMachine = 0;
payFromStorage = amount;
} else {
payFromMachine = Mathf.Min(cashOnMachine.stackCount, amount);
payFromStorage = amount - payFromMachine;
}
if (payFromMachine > 0) {
vendingMachine.MainContainer.TryTransferToContainer(cashOnMachine, pawn.inventory.innerContainer, payFromMachine);
}
if (payFromStorage > 0) {
// pay rest from silver in storage
var silverList = pawn.Map.listerThings.ThingsOfDef(ThingDefOf.Silver)
.Where(x => !x.Position.Fogged(x.Map) && (pawn.Map.areaManager.Home[x.Position] || x.IsInAnyStorage())).ToList();
var value = payFromStorage;
while (value > 0)
{
var silver = silverList.First(t => t.stackCount > 0);
var num = Mathf.Min(value, silver.stackCount);
silver.SplitOff(num).Destroy();
value -= num;
}
}
}
}
}
11 changes: 7 additions & 4 deletions Source/SlotMachineThing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override void PostSpawnSetup(bool respawningAfterLoad)
eventManager.reels[i] = new SlotReel();
Vector3 middle = parent.Position.ToVector3() + new Vector3(0.5045f, 0f, 0.5f);
Vector3 offset = new Vector3(0.2f, 0f, 0f);
middle.z += 0.3f;
middle.z += 0.31f;
eventManager.reels[0].drawLocation = middle - offset;
eventManager.reels[1].drawLocation = middle;
eventManager.reels[2].drawLocation = middle + offset;
Expand Down Expand Up @@ -151,17 +151,20 @@ public void CalculateNewEvents()
float houseCut = 6f; // always between 0 and 12, default 6
outcome = SlotGameOutcome.Loss;
float random = Rand.Range(0f, 1f);
if (slotType==0) {
if (slotType==0) { // default
if (random <= 0.455f) outcome = SlotGameOutcome.Single; // 34% chance of single bet win = 1s
if (random <= (0.105f + Mathf.Lerp(+0.005f,-0.005f,(houseCut*100f/12f)))) outcome = SlotGameOutcome.Double; // 5.5 to 4.5% (variable depending on house cut 0-12%) chance of double bet win = 2s
if (random <= (0.05f + Mathf.Lerp(+0.0005f,-0.0005f,(houseCut*100f/12f)))) outcome = SlotGameOutcome.Jackpot; // 0.55 to 0.45% (variable depending on house cut 0-12%) chance of jackpot = all in machine, capped to 100s
}
if (slotType==1 || slotType==2) {
if (slotType==1) { // 10x lower chance on jackpot
if (random <= 0.395f) outcome = SlotGameOutcome.Single; // 34% chance of single bet win = 1s
if (random <= (0.055f + Mathf.Lerp(+0.005f,-0.005f,(houseCut*100f/12f)))) outcome = SlotGameOutcome.Double; // 5.5 to 4.5% (variable depending on house cut 0-12%) chance of double bet win = 2s
if (random <= (0.005f + Mathf.Lerp(+0.0005f,-0.0005f,(houseCut*100f/12f)))) outcome = SlotGameOutcome.Jackpot; // 0.055 to 0.045% (variable depending on house cut 0-12%) chance of jackpot = all in machine, capped to 100s
}
if (slotType==2) { // only (big) jackpot
if (random <= (0.005f + Mathf.Lerp(+0.0005f,-0.0005f,(houseCut*100f/12f)))) outcome = SlotGameOutcome.Jackpot; // 0.55 to 0.45% (variable depending on house cut 0-12%) chance of jackpot = all in machine, capped to 100s
}
Log.Message("CalculateNewEvents outcome=" + outcome);
//Log.Message("CalculateNewEvents outcome=" + outcome);
switch(outcome) {
case SlotGameOutcome.Loss:
// TODO any random combination where no 3 same
Expand Down

0 comments on commit c8f6d21

Please sign in to comment.