-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpsDrugWars.ps1
5381 lines (4852 loc) · 216 KB
/
psDrugWars.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Requires -Version 5.1
param (
[switch]$SkipConsoleSizeCheck
)
[float]$script:GameVersion = 0.42
########################
#region Class Definitions
##########################
class GameStats {
[int]$DrugsBought
[int]$DrugsSold
[int]$CitiesVisited
[int]$FlightsTaken
[int]$GunsBought
[int]$CopFights
[int]$EventsExperienced
[int]$MostCashAtOnce
hidden [string[]]$TravelPath
# Constructor to initialize all properties to 0 or empty array
GameStats() {
$this.DrugsBought = 0
$this.DrugsSold = 0
$this.CitiesVisited = 0
$this.FlightsTaken = 0
$this.GunsBought = 0
$this.CopFights = 0
$this.EventsExperienced = 0
$this.MostCashAtOnce = 0
$this.TravelPath = @()
}
# Method to get all numeric properties as an array of strings
# This method filters the properties of the GameStats object and returns only those with numeric values (int or double).
# Each property name is formatted to split PascalCase or camelCase names, and the result is returned as an array of strings (in the order they are defined in the class).
[string[]] GetPropertiesAsStrings() {
# Get the properties of the GameStats object
$properties = $this.PSObject.Properties
# Create an array to hold the property values as strings
$result = @()
foreach ($property in $properties) {
# Check if the property value is numeric
if ($property.Value -is [int] -or $property.Value -is [double]) {
# Perform the replacement inline to split PascalCase or camelCase names
$formattedName = $property.Name -creplace '([a-z])([A-Z])', '$1 $2'
$result += ('{0}: {1}' -f $formattedName, $property.Value)
}
}
return $result
}
# Method to set the MostCashAtOnce property if it's lower than the provided amount
[void] UpdateMostCashAtOnce([int]$Cash) {
if ($Cash -gt $this.MostCashAtOnce) {
$this.MostCashAtOnce = $Cash
}
}
# Method to add a city (name) to the list of visited cities
[void] AddVisitedCity([City]$City) {
if ($null -ne $City -and -not [string]::IsNullOrEmpty($City.Name)) {
$this.TravelPath += $City.Name
$this.CitiesVisited = ($this.GetVisitedCityNames()).Count
$this.FlightsTaken = $this.TravelPath.Count - 1
}
else {
throw "City object or its Name property cannot be null or empty."
}
}
# Method to retrieve the full list of visited city names, in the order visited.
[string[]] GetTravelPath() {
return $this.TravelPath
}
# Method to return the list of (unique) city names visited
[string[]] GetVisitedCityNames() {
return $this.TravelPath | Sort-Object -Unique
}
}
class Drug {
[string]$Name
[string]$Code
[string]$Description
[int]$BasePrice
[int[]]$PriceRange
[float]$PriceMultiplier
[int]$Quantity
# Constructor that takes a drug name
Drug([string]$Name) {
$this.Name = $Name
$this.Code = $script:DrugCodes.Keys | Where-Object { $script:DrugCodes[$_] -eq $Name }
$this.Description = $script:DrugsInfo[$this.Code]['History']
$this.PriceRange = $script:DrugsInfo[$this.Code]['PriceRange']
$this.PriceMultiplier = 1.0
$this.Quantity = 0
$this.SetRandomBasePrice()
}
# Method to set the hidden BasePrice value to a random value from the drugs PriceRange, rounded to the nearest 10 dollars (Bankers' rounding).
[void]SetRandomBasePrice() {
$this.BasePrice = [int][math]::Round((Get-Random -Minimum $this.PriceRange[0] -Maximum $this.PriceRange[1]) / 10) * 10
}
# Calculate the price based on BasePrice and PriceMultiplier, rounded to the nearest 5 dollars (Bankers' rounding).
[int]get_Price() {
$price = [int][math]::Round($this.BasePrice * $this.PriceMultiplier / 5) * 5
if ($price -lt 5) {
$price = 5
}
return $price
}
}
class City {
[string]$Name
[Drug[]]$Drugs
[int]$MaxDrugCount
[string[]]$HomeDrugNames
[float]$HomeDrugSaleMultiplier
[Gun[]]$GunsForSale
[string]$GunShopName
# Default constructor
City() {
# Drugs are assigned upon visiting the city (so they change each visit)
$this.Drugs = @()
# Guns are assigned after city is created
$this.GunsForSale = @()
# No name until a gun is added
$this.GunShopName = $null
# Assign 1 or 2 random 'Home Drugs' to each city
$homeDrugCount = Get-Random -Minimum 1 -Maximum 3
$this.HomeDrugNames = $script:DrugCodes.Keys | Get-Random -Count $homeDrugCount
# Home Drugs are drugs that are always sold at a discount (if in stock). Default is 20% of the base price.
$this.HomeDrugSaleMultiplier = .20
}
# Method to add a gun to the city's GunsForSale collection
[void]AddGunToShop([Gun]$Gun) {
$this.GunsForSale += $Gun
$gunShopNames = @(
'Aim High Ammunition Alley',
'Ammo-nation',
'Angry Hank''s Shot Shack',
'Barrel of Laughs Gun Depot',
'Bullet Bonanza Emporium',
'Glock ''n Roll Firearms',
'Guns ''n'' Giggles',
'Laugh ''n'' Load Gunsmiths',
'Lock, Stock, and Two Smokin'' Barrels',
'Pistol Puns & Rifled Laughs',
'Shoots & Ladders Armoury',
'The Bang Theory Firearms',
'The Bang-Bang Boutique',
'The Trigger Happy Gun Shop',
'Trigger Treats Gun Emporium'
)
if (-not $this.GunShopName) {
$this.GunShopName = Get-Random -InputObject $gunShopNames
}
}
# Method ot return if the city has guns for sale
[bool]HasGunShop() {
return $this.GunsForSale.Count -gt 0
}
}
class Player {
[string[]]$Clothing
[City]$City
[int]$Cash
[Drug[]]$Drugs
[int]$GameDay
hidden [Gun[]]$Guns
[string]$Initials
hidden [int]$Pockets
hidden [string[]]$starterClothes = @(
'Bell-bottom pants',
'Flannel shirt (buttoned Cholo-style)',
'"I''m with Stupid ->" T-shirt',
'Over-sized athletic jersey',
'Pink Floyd T-shirt',
'Smelly socks',
'Smelly socks with a hole in them',
'Terry-cloth bath robe',
'Underwear, hanging out',
'Velour track suit',
'Wife-beater'
)
# Default constructor
Player() {
$this.Drugs = @()
$this.Guns = @()
$this.Clothing = $this.starterClothes | Get-Random
$this.Pockets = 0
$this.GameDay = 1
}
# FreePockets method returns the number of pockets minus the total Quntity of all Drugs
[int]get_FreePocketCount() {
$totalQuantity = $this.get_DrugCount()
return $this.Pockets - $totalQuantity
}
# Method to get pocket count
[int]get_PocketCount() {
return $this.Pockets
}
# Method to set pocket count
[void]set_PocketCount([int]$Pockets) {
$this.Pockets = $Pockets
}
# Method to get total drug count from inventory
[int]get_DrugCount() {
$totalQuantity = 0
$this.Drugs | ForEach-Object { $totalQuantity += $_.Quantity }
return $totalQuantity
}
# Method to get guns
[Gun[]]get_Guns() {
return $this.Guns
}
# Method to dump all guns
[void]DumpGuns() {
$this.Guns = @()
}
[bool]AddGun([Gun]$Gun) {
return $this.AddGun($Gun, $false)
}
# Method to add a gun to inventory
[bool]AddGun([Gun]$Gun, [bool]$Silent = $false) {
# Maximum two guns
if ($this.Guns.Count -ge 2) {
$tooManyGunsExpressions = @(
"Whoa, slow down, Rambo! Two strapped guns are your limit, fam.`r`nWe don't want you to take off like a helicopter now.",
"Hold your horses, cowboy! You're already packing a pair of heat, pal.`r`nAdding more would be like juggling flaming marshmallows - not a good idea, see?",
"Easy there, gunslinger! Two guns are the magic number, amico.`r`nAdding more would be like trying to salsa dance with three left feet, capisce?",
"Chill, action hero! You've already got a dynamic duo of guns, homey.`r`nAdding more would be like trying to breakdance on a tightrope, playa.",
"Steady on, sharpshooter! You've got a couple of guns already, fella.`r`nAdding another one would be like trying to balance a porcupine on your nose, you hear?",
"Whoa, trigger happy! Two guns are your lucky number, homey.`r`nAdding another one would be like trying to fit a giraffe into a phone booth."
)
$parts = (Get-Random -InputObject $tooManyGunsExpressions) -split "`r`n"
$firstPart += $parts[0]
$secondPart += $parts[1]
Write-Centered ($firstPart) -ForegroundColor Red
Start-Sleep 2
Write-Host
Write-Centered ($secondPart) -ForegroundColor DarkGray
Start-Sleep 2
Write-Host
return $false
}
if (-not $Silent) {
$newGunExpressions = @(
('You got a {0}! Nice! Just remember, with great firepower comes great responsibility.' -f $Gun.Name),
('You got a {0}! Keep it strapped, fam! It''s like having a Swiss Army knife, but, you know, for the streets or some shit.' -f $Gun.Name),
('Big man! Packin'' heat with a {0}! Who needs biceps when you''ve got barrels, am I right?' -f $Gun.Name),
('Say hello to my little friend! "Hello {0}."' -f $Gun.Name),
('Congrats, sharpshooter! You snagged a {0}! The only thing hotter than the barrel is your style.' -f $Gun.Name),
('Hasta la vista, budget constraints! You''re now the proud owner of a {0}! Pew-pew dreams do come true.' -f $Gun.Name),
('Well, look who''s the proud parent of a bouncing baby {0}! Parenthood, gun-style, fam.' -f $Gun.Name),
('You got a {0}! Time to start practicing your action movie one-liners. "Yippee-ki-yay, {0}-lover!"' -f $Gun.Name),
('Boom shakalaka! You''ve upgraded to a {0}! Watch out, world - you''re armed and hilarious.' -f $Gun.Name),
('Woo-hoo! You got a {0}! It''s like winning the lottery, but with more pew-pew and fewer numbers.' -f $Gun.Name)
)
Write-Centered (Get-Random -InputObject $newGunExpressions)
Start-Sleep 2
}
$this.Guns += $Gun
return $true
}
# Method to remove a gun from inventory
[void]RemoveGun([Gun]$Gun) {
$this.Guns = $this.Guns | Where-Object { $_.Name -ne $Gun.Name }
}
# Method to Buy a gun
[void]BuyGun([Gun]$Gun) {
# If the player doesn't have enough cash, print a message and return
if ($Gun.Price -gt $this.Cash) {
$gunPurchasePhrases = @(
"Oops! Your wallet's on a diet - can't afford that fancy {0} right now.`r`nTime to channel your inner magpie, my friend!",
"Uh-oh! Your cash stash is more elusive than Bigfoot when it comes to buying a {0}, homey.`r`nGet those brainstorming wheels turning, pal!",
"Houston, we have a cash-flow problem! Buying a {0}, fam, requires some next-level haggling skills.`r`nPrepare for liftoff, friend!",
"Breaking news: Your wallet just declared bankruptcy in the face of that {0}, pal.`r`nLet's brainstorm ways to turn pocket lint into gold, buddy!",
"Ay caramba! Your dinero isn't playing nice with the idea of a {0}, amigo.`r`nTime for a financial fiesta, compadre!",
"Eh, capisce? Your wallet's playing hard to get with that {0}.`r`nLet's hustle, my nonna-lovin' friend - maybe she's got a secret stash!"
)
$parts = (Get-Random -InputObject $gunPurchasePhrases) -split "`r`n"
$firstPart += $parts[0]
$secondPart += $parts[1]
Write-Centered ($firstPart -f $Gun.Name) -ForegroundColor Yellow
Start-Sleep 1
Write-Centered ($secondPart) -ForegroundColor DarkGray
Start-Sleep 2
Write-Host
return
}
# If the player has enough cash, and can add the gun to their inventory, buy the gun.
if ($this.AddGun($Gun)) {
# Pay for gun
$this.Cash -= $Gun.Price
# Track gun purchase in Game Statistics
$script:GameStats.GunsBought++
Write-Host
Write-Centered ('You bought a {0} for ${1}.' -f $Gun.Name, $Gun.Price) -ForegroundColor Green
Start-Sleep -Milliseconds 1500
Write-Host
# Display the gun's description and history
Write-Centered $Gun.Description -ForegroundColor White
Start-Sleep -Milliseconds 1500
Write-Centered $Gun.History -ForegroundColor DarkGray
}
Start-Sleep 3
}
# Method to sell a gun
[void]SellGun([Gun]$Gun) {
# Find the first gun in the player's inventory that matches the given name
$gunToSell = $this.Guns | Where-Object { $_.Name -eq $Gun.Name } | Select-Object -First 1
Write-Host
# If the gun was found
if ($gunToSell) {
# Increase the player's cash by 70% of the gun's price
$gunSellPrice = $gunToSell.Price * 0.70
$this.Cash += $gunSellPrice
# Update MostCashAtOnce stats by comparing player's current cash
$script:GameStats.UpdateMostCashAtOnce($this.Cash)
# Remove the sold gun from the player's inventory.
$this.Guns = $this.Guns | Where-Object { $_.Name -ne $gunToSell.Name } | Select-Object -First 1
Write-Centered ('You sold your {0} for ${1}.' -f $gunToSell.Name, $gunSellPrice) -ForegroundColor Green
}
else {
Write-Centered ('You don''t have a {0} to sell.' -f $gunToSell.Name) -ForegroundColor Red
}
Start-Sleep 3
Write-Host
}
# Method to get total stopping power of all guns
[int]get_StoppingPower() {
$stoppingPower = 0
foreach ($gun in $this.Guns) {
$stoppingPower += $gun.StoppingPower
}
return $stoppingPower
}
# Method to adjust pocket count up or down
[void]AdjustPocketCount([int]$Pockets) {
if ($Pockets -lt 0) {
# Remove specified number of pockets (by adding the negative amount provided)
$this.Pockets += $Pockets
# Get a count of all drugs in the player's inventory
$totalQuantity = 0
$this.Drugs | ForEach-Object { $totalQuantity += $_.Quantity }
# If the player has more drugs than pockets, remove some excess drugs
if ($totalQuantity -gt $this.Pockets) {
Write-Centered 'You don''t have enough pockets to hold all your drugs!' -ForegroundColor Yellow
Start-Sleep -Seconds 2
$difference = $totalQuantity - $this.Pockets
# While the difference is greater than 0, cycle through the drugs in inventory, removing 1 of each until the difference is 0.
while ($difference -gt 0) {
foreach ($drug in $this.Drugs) {
$this.RemoveDrugs($drug, 1)
Write-Centered ('You had to throw away 1 {0}.' -f $drug.Name) -ForegroundColor DarkRed
$difference -= 1
if ($difference -le 0) {
break
}
}
}
}
}
else {
$this.Pockets += $Pockets
}
}
# Method to add drugs to the player's Drugs collection.
[void]AddDrugs([Drug]$Drug) {
# Minimum Add is 1
if ($Drug.Quantity -lt 1) {
Write-Host 'You must add at least 1 of a drug.'
return
}
# Check if there's enough free pockets
if ($this.get_FreePocketCount() -ge $Drug.Quantity) {
# If the player already has some of the drug, add the quantity to the existing drug, otherwise add the drug to the player's Drugs collection.
$myMatchingDrug = $this.Drugs | Where-Object { $_.Name -eq $Drug.Name }
if ($myMatchingDrug) {
$myMatchingDrug.Quantity += $Drug.Quantity
}
else {
$this.Drugs += $Drug
}
}
else {
Write-Host "Not enough free pockets to add this drug."
}
}
# Method to remove drugs from the player's Drugs collection.
[void]RemoveDrugs([Drug]$Drug, [int]$Quantity) {
# If the player has some of the drug, remove the quantity from the existing drug, otherwise do nothing.
$myMatchingDrug = $this.Drugs | Where-Object { $_.Name -eq $Drug.Name }
if ($myMatchingDrug) {
$myMatchingDrug.Quantity -= $Quantity
if ($myMatchingDrug.Quantity -le 0) {
# None left, remove the Drug object from the Drugs collection.
$this.Drugs = $this.Drugs | Where-Object { $_.Name -ne $Drug.Name }
}
}
else {
Write-Host 'You don''t have any of that drug.'
}
}
# Method to buy drugs.
[void]BuyDrugs([Drug]$Drug) {
# Get the drug from the city's drug list (if it's available)
$cityDrug = $this.City.Drugs | Where-Object { $_.Name -eq $Drug.Name }
# Use a switch statement to handle different conditions (run teh first block that's "True")
switch ($true) {
# If the drug is not available in the city, print a message and return
(-not $cityDrug) {
$wachoo = @('Whutchoo talkin'' about, Willis?', 'Are you high?', 'You''re trippin''!', 'You drunk?')
Write-Host ('{0} {1} is not available in {2}.' -f (Get-Random -InputObject $wachoo), $Drug.Name, $this.City.Name)
break
}
# If the quantity is less than 1, print a message and return
($Drug.Quantity -lt 1) {
Write-Host ('You really trying to buy {0} drugs...?' -f $Drug.Quantity)
$whoyou = @('M.C. Escher', 'Salvador Dali', 'David Blaine', 'Doug Henning')
Write-Host ('Who are you? {0} or some shit?' -f (Get-Random -InputObject $whoyou))
break
}
# If the drug is available and the quantity is valid, proceed to buy
default {
# Calculate the total price
$totalPrice = $Drug.Quantity * $Drug.get_Price()
# If the player doesn't have enough cash, print a message and return
if ($totalPrice -gt $this.Cash) {
Write-Host ('You don''t have enough cash to buy that much {0}.' -f $Drug.Name)
break
}
# If the quantity being bought is greater than the number of free pockets, print a message and return
$freePockets = $this.get_FreePocketCount()
if ($Drug.Quantity -gt $freePockets) {
Write-Host ('You don''t have enough free pockets to hold that much {0}.' -f $Drug.Name)
break
}
# If the player has enough cash and free pockets, buy the drugs
$this.Cash -= $totalPrice
Write-Host ('You bought {0} {1} for ${2}.' -f $Drug.Quantity, $Drug.Name, $totalPrice)
$this.AddDrugs($Drug)
# Track drug purchase in Game Statistics
$script:GameStats.DrugsBought += $Drug.Quantity
}
}
# Pause for 3 seconds before returning
Start-Sleep 3
}
# Method to sell drugs.
[void]SellDrugs([Drug]$Drug, [int]$Quantity) {
# Look up the drug by name in the current City's drug list.
$cityDrug = $this.City.Drugs | Where-Object { $_.Name -eq $Drug.Name }
# Calculate the total price (using the city's price for the drug)
$totalPrice = $cityDrug.get_Price() * $Quantity
# Check if the player has enough quantity of the drug
$drugToSell = $this.Drugs | Where-Object { $_.Name -eq $Drug.Name }
if ($drugToSell.Quantity -lt $Quantity) {
Write-Host ('You don''t have enough {0} to sell.' -f $Drug.Name)
return
}
# If the player has enough quantity of the drug, sell the drugs
$this.RemoveDrugs($Drug, $Quantity)
$this.Cash += $totalPrice
Write-Host ('You sold {0} {1} for ${2}.' -f $Quantity, $Drug.Name, $totalPrice)
# Track drug sale in Game Statistics
$script:GameStats.DrugsSold += $Quantity
# Update MostCashAtOnce stats by comparing player's current cash
$script:GameStats.UpdateMostCashAtOnce($script:Player.Cash)
}
# Method to add items to the player's Clothing collection.
[bool]AddClothing([string]$Item) {
# If the player already has the item, return false
if ($this.Clothing -contains $Item) {
return $false
}
# Otherwise, add the item to the player's Clothing and return true.
else {
$this.Clothing += $Item
return $true
}
}
# Method to change base outfit.
[string]ChangeOutfit() {
$currentStarterClothes = $this.starterClothes | Where-Object { $this.Clothing -contains $_ }
# Remove any clothing that is in the starterClothes list.
$this.Clothing = $this.Clothing | Where-Object { $this.starterClothes -notcontains $_ }
# Put on a random new one, that isn't in $currentStarterClothes
$newClothing = $this.starterClothes | Where-Object { $_ -notin $currentStarterClothes } | Get-Random
# Add the new clothing to the top of the list
$otherClothes = $this.Clothing
$this.Clothing = @($newClothing)
# Add the other clothing back to the list (unless it's null)
if ($otherClothes) {
$this.Clothing += $otherClothes
}
# Return the new clothing
return $newClothing
}
}
class Gun {
[string]$Name
[string]$Type
[int]$Price
[int]$StoppingPower
[string]$Description
[string]$History
Gun ($gunInfo) {
$this.Name = $gunInfo.Name
$this.Type = $gunInfo.Type
$this.Price = $gunInfo.Price
$this.StoppingPower = $gunInfo.StoppingPower
$this.Description = $gunInfo.Description
$this.History = $gunInfo.History
}
}
###########################
#endregion Class Definitions
#############################
##########################################
#region Define Script-Wide Lists and Tables
############################################
# Define drugs names and codes
$script:DrugCodes = @{
'AD' = 'Angel Dust'
'CD' = 'Codeine'
'CN' = 'Cocaine'
'CK' = 'Crack'
'DM' = 'DMT'
'EC' = 'Ecstasy'
'FT' = 'Fentanyl'
'HN' = 'Heroin'
'HS' = 'Hash'
'KM' = 'Ketamine'
'LD' = 'LSD'
'LU' = 'Ludes'
'MC' = 'Mescaline'
'MN' = 'Morphine'
'MT' = 'Meth'
'OP' = 'Opium'
'OX' = 'Oxy'
'PA' = 'Peyote'
'PO' = 'Poppers'
'RT' = 'Ritalin'
'SH' = 'Shrooms'
'SP' = 'Speed'
'VI' = 'Vicodin'
'WD' = 'Weed'
'XN' = 'Xanax'
}
# Define information about each drug
$script:DrugsInfo = @{
'AD' = @{
'Name' = 'Angel Dust'
'StreetNames' = @('PCP', 'Sherm', 'Embalming Fluid')
'History' = 'Developed as a dissociative anesthetic, Angel Dust gained popularity in the 1960s. Discontinued for medical use due to its unpredictable and severe side effects.'
'Effects' = 'Hallucinations, distorted perceptions of reality, increased strength, and a dissociative state.'
'PriceRange' = @(500, 2000)
}
'CD' = @{
'Name' = 'Codeine'
'StreetNames' = @('Lean', 'Purple Drank', 'Sizzurp')
'History' = 'Codeine is an opiate used for pain relief. It has been used recreationally, often mixed with soda and candy, particularly in hip-hop culture.'
'Effects' = 'Euphoria, relaxation, and mild sedation.'
'PriceRange' = @(20, 150)
}
'CN' = @{
'Name' = 'Cocaine'
'StreetNames' = @('Coke', 'Blow', 'Snow')
'History' = 'Derived from coca plants, cocaine became popular in the 1970s and 1980s as a recreational stimulant. Its use is associated with a high risk of addiction.'
'Effects' = 'Increased energy, alertness, and euphoria.'
'PriceRange' = @(100, 500)
}
'CK' = @{
'Name' = 'Crack'
'StreetNames' = @('Freebase', 'Rock', 'Base')
'History' = 'Crack cocaine is a crystallized form of cocaine. It emerged in the 1980s, contributing to the "crack epidemic" in the United States.'
'Effects' = 'Intense, short-lived euphoria, increased heart rate, and heightened alertness.'
'PriceRange' = @(50, 300)
}
'DM' = @{
'Name' = 'DMT'
'StreetNames' = @('Dimitri', 'Businessman''s Trip')
'History' = 'DMT is a naturally occurring psychedelic compound found in certain plants. Its use in shamanic rituals dates back centuries.'
'Effects' = 'Intense, short-lasting hallucinations, a sense of entering otherworldly realms.'
'PriceRange' = @(100, 1000)
}
'EC' = @{
'Name' = 'Ecstasy'
'StreetNames' = @('MDMA', 'Molly', 'E', 'X')
'History' = 'Originally used in psychotherapy, ecstasy gained popularity in the 1980s as a recreational drug.'
'Effects' = 'Enhanced sensory perception, increased empathy, and heightened emotions.'
'PriceRange' = @(5, 50)
}
'FT' = @{
'Name' = 'Fentanyl'
'StreetNames' = @('China White', 'Apache', 'Dance Fever')
'History' = 'Developed as a potent painkiller, fentanyl has been linked to a surge in opioid-related overdoses due to its high potency.'
'Effects' = 'Intense euphoria, drowsiness, and respiratory depression.'
'PriceRange' = @(100, 500)
}
'HN' = @{
'Name' = 'Heroin'
'StreetNames' = @('Smack', 'Junk', 'H')
'History' = 'Derived from morphine, heroin was initially marketed as a non-addictive alternative. Its recreational use rose in the mid-20th century.'
'Effects' = 'Euphoria, sedation, pain relief.'
'PriceRange' = @(50, 300)
}
'HS' = @{
'Name' = 'Hash'
'StreetNames' = @('Hashish', 'Hash Oil', 'Dabs')
'History' = 'Hash is a concentrated form of cannabis resin. It has a long history of use in various cultures for spiritual and recreational purposes.'
'Effects' = 'Relaxation, euphoria, altered perception of time.'
'PriceRange' = @(10, 100)
}
'KM' = @{
'Name' = 'Ketamine'
'StreetNames' = @('Special K', 'K', 'Vitamin K')
'History' = 'Initially used as an anesthetic, ketamine gained popularity as a recreational drug with dissociative effects.'
'Effects' = 'Hallucinations, dissociation, altered perception of time and space.'
'PriceRange' = @(50, 500)
}
'LD' = @{
'Name' = 'LSD'
'StreetNames' = @('Acid', 'Tabs', 'Blotter')
'History' = 'Discovered in the 1930s, LSD became popular in the 1960s counter-culture. It''s known for its profound psychedelic effects.'
'Effects' = 'Hallucinations, altered perception of reality, heightened sensory experiences.'
'PriceRange' = @(50, 300)
}
'LU' = @{
'Name' = 'Ludes'
'StreetNames' = @('Quaaludes', 'Disco Biscuits')
'History' = 'Methaqualone, commonly known as Quaaludes, was a sedative-hypnotic drug popular in the 1970s. It was later classified as a controlled substance.'
'Effects' = 'Muscle relaxation, sedation, euphoria.'
'PriceRange' = @(100, 800)
}
'MC' = @{
'Name' = 'Mescaline'
'StreetNames' = @('Peyote', 'Buttons', 'Cactus')
'History' = 'Mescaline is a naturally occurring psychedelic found in certain cacti, notably peyote. It has been used in Native American rituals for centuries.'
'Effects' = 'Visual hallucinations, altered perception, and enhanced sensory experiences.'
'PriceRange' = @(50, 500)
}
'MN' = @{
'Name' = 'Morphine'
'StreetNames' = @('Dreamer', 'Mister Blue')
'History' = 'Derived from opium, morphine has been used for pain relief since the 19th century. It remains a powerful opioid analgesic.'
'Effects' = 'Pain relief, euphoria, sedation.'
'PriceRange' = @(50, 300)
}
'MT' = @{
'Name' = 'Meth'
'StreetNames' = @('Crystal', 'Ice', 'Glass')
'History' = 'Methamphetamine, a potent stimulant, gained popularity for recreational use and as an illicit substance in the mid-20th century.'
'Effects' = 'Increased energy, alertness, euphoria.'
'PriceRange' = @(50, 500)
}
'OP' = @{
'Name' = 'Opium'
'StreetNames' = @('Dopium', 'Chinese Tobacco', 'Midnight Oil')
'History' = 'Opium has a long history of use dating back centuries. It was widely used for medicinal and recreational purposes, leading to addiction issues.'
'Effects' = 'Pain relief, relaxation, euphoria.'
'PriceRange' = @(100, 800)
}
'OX' = @{
'Name' = 'Oxy'
'StreetNames' = @('Oxycodone', 'Hillbilly Heroin', 'OxyContin')
'History' = 'Oxycodone, commonly known as Oxy, is a prescription opioid. It became widely abused for its pain-relieving and euphoric effects.'
'Effects' = 'Pain relief, relaxation, euphoria.'
'PriceRange' = @(50, 300)
}
'PA' = @{
'Name' = 'Peyote'
'StreetNames' = @('Mescaline', 'Buttons', 'Cactus')
'History' = 'Peyote is a small, spineless cactus containing mescaline. It has been used in Native American religious ceremonies for centuries.'
'Effects' = 'Visual hallucinations, altered perception, and enhanced sensory experiences.'
'PriceRange' = @(100, 800)
}
'PO' = @{
'Name' = 'Poppers'
'StreetNames' = @('Rush', 'Locker Room', 'Snappers')
'History' = 'Poppers are a type of alkyl nitrite inhalant. They have been used recreationally, especially in club and party scenes, for their brief but intense effects.'
'Effects' = 'Head rush, warm sensations, and intensified sensory experiences.'
'PriceRange' = @(5, 50)
}
'RT' = @{
'Name' = 'Ritalin'
'StreetNames' = @('Rids', 'Vitamin R', 'Skittles')
'History' = 'Ritalin, or methylphenidate, was developed in the 1950s as a treatment for attention deficit hyperactivity disorder (ADHD). FDA-approved, it has since been prescribed for ADHD and narcolepsy.'
'Effects' = 'Stimulant effects include increased focus, alertness, and energy.'
'PriceRange' = @(5, 50)
}
'SH' = @{
'Name' = 'Shrooms'
'StreetNames' = @('Magic Mushrooms', 'Psilocybin', 'Caps')
'History' = 'Psychedelic mushrooms, or shrooms, have been used in various cultures for their hallucinogenic properties. They gained popularity in the counterculture movements of the 1960s.'
'Effects' = 'Altered perception, visual hallucinations, introspective experiences.'
'PriceRange' = @(20, 200)
}
'SP' = @{
'Name' = 'Speed'
'StreetNames' = @('Amphetamine', 'Uppers', 'Dexies')
'History' = 'Amphetamines have a long history of medical use and gained popularity as stimulants in the mid-20th century.'
'Effects' = 'Increased energy, alertness, heightened focus.'
'PriceRange' = @(50, 500)
}
'VI' = @{
'Name' = 'Vicodin'
'StreetNames' = @('Hydro', 'Vikes', 'Watsons')
'History' = 'Vicodin is a combination of hydrocodone and acetaminophen used for pain relief. It has been widely prescribed but is associated with the risk of addiction.'
'Effects' = 'Pain relief, relaxation, mild euphoria.'
'PriceRange' = @(100, 800)
}
'WD' = @{
'Name' = 'Weed'
'StreetNames' = @('Marijuana', 'Cannabis', 'Pot')
'History' = 'Cannabis has been used for various purposes for thousands of years. It gained popularity for recreational use in the 20th century.'
'Effects' = 'Relaxation, euphoria, altered sensory perception.'
'PriceRange' = @(10, 100)
}
'XN' = @{
'Name' = 'Xanax'
'StreetNames' = @('Bars', 'Benzos', 'Zannies')
'History' = 'Xanax, a benzodiazepine, is prescribed for anxiety. Its recreational use has become a concern due to the risk of dependence.'
'Effects' = 'Relaxation, sedation, anti-anxiety effects.'
'PriceRange' = @(50, 300)
}
}
# Define available cities
$script:CityNames = @(
"Acapulco, Mexico",
"Amsterdam, Netherlands",
"Bangkok, Thailand",
"Hong Kong, China",
"Istanbul, Turkey",
"Lisbon, Portugal",
"London, UK",
"Marseilles, France",
"Medellin, Colombia",
"Mexico City, Mexico",
"Miami, USA",
"Marrakesh, Morocco",
"New York City, USA",
"Panama City, Panama",
"Phuket, Thailand",
"San Francisco, USA",
"Sydney, Australia",
"Tehran, Iran",
"Tijuana, Mexico",
"Toronto, Canada",
"Vancouver, Canada"
)
# Define random events
$script:RandomEvents = @(
@{
"Name" = "Busted"
"Description" = 'You were busted by the cops!'
"Effect" = {
Start-Sleep -Seconds 3
# If player has no drugs on them, the cops leave them alone
if ($script:Player.Drugs.Count -eq 0) {
Write-Centered 'You were searched, but you didn''t have any drugs on you!'
Write-Host
# If the player has any guns, select a random gun from the player's inventory,
# remove it, and display a message indicating which gun was taken.
if ($script:Player.Guns.Count -gt 0) {
$randomIndex = Get-Random -Minimum 0 -Maximum $script:Player.Guns.Count
$gunTaken = $script:Player.Guns[$randomIndex]
$script:Player.RemoveGun($gunTaken)
Write-Centered ('The cops let you go with a warning, but they confiscated your {0}!' -f $gunTaken.Name) -ForegroundColor DarkRed
}
else {
Write-Centered 'The cops let you go with a warning.' -ForegroundColor DarkGreen
}
$randomNumber = Get-Random -Minimum 1 -Maximum 101
if (($randomNumber -le 80) -and ($script:Player.Cash -gt 50)) {
Start-Sleep -Seconds 2
# Cops let you go, but take 5% of your cash (or $50, whichever is higher)
Write-Centered '...and give you a bit of a shake-down.' -ForegroundColor Yellow
Start-Sleep -Seconds 3
$loss = [math]::Max([int]([math]::Round($script:Player.Cash * 0.05)), 50)
$script:Player.Cash = $script:Player.Cash - $loss
Write-Host
Write-Centered ('They took ${0}!' -f $loss) -ForegroundColor DarkRed
}
Start-Sleep -Seconds 3
return
}
# Calculate the bust chance. The base chance is 0%, and it increases by 5% for each $1000 the player has. Capped at 60%.
[float]$bustChance = 0.0
if ($script:Player.Cash -gt 0) {
$bustChance = [Math]::Min($script:Player.Cash / 1000 * 0.05, 0.6)
}
# Generate a random decimal number between 0 and 1
[float]$randomNumber = Get-Random -Minimum 0.0 -Maximum 1.0
# If the random number is less than or equal to the bust chance, the cops bust the player
if ($randomNumber -le $bustChance) {
if ($script:Player.get_Guns().Count -gt 0) {
Write-Centered 'You spent the night in jail and lost all your drugs and guns.' -ForegroundColor Red
}
else {
Write-Centered 'You spent the night in jail and lost all your drugs.' -ForegroundColor Red
}
# Remove all drugs from the player's possession
$script:Player.Drugs = @()
# Remove all the player's guns.
$script:Player.DumpGuns()
# Increment the game day
AdvanceGameDay -SkipPriceUpdate
}
else {
# Create an array of messages
$messages = @(
'They searched you, but you got away!',
'You were searched, but managed to slip away!',
'They tried to catch you, but you were too quick!',
'You were almost caught, but you escaped!',
'They attempted to search you, but you evaded them!',
'You narrowly avoided being searched!',
'They let you go with a warning!',
'You played hide and seek with the search party, and you won!',
'You turned the search into a dance-off and moonwalked out of trouble!',
'They tried to catch you, but you hit them with your "Invisible Cloak of Inconspicuousness"(tm)!',
'You transformed the search into a magic show and disappeared in a puff of glitter!',
'You were almost caught, but you executed the perfect ninja smoke bomb escape!',
'They attempted to search you, but you pulled out a trombone and started a parade distracting them!',
'You narrowly avoided being searched by unleashing your inner contortionist and slipping through their fingers!',
'They let you go with a warning, probably because they were impressed by your interpretive dance routine!'
)
# Select a random message
$message = Get-Random -InputObject $messages
# Display the message
Write-Host
Write-Centered $message -ForegroundColor DarkGreen
}
Start-Sleep -Seconds 3
}
},
@{
"Name" = "Flash Back"
"Description" = "You trip out and lose a day!"
"Effect" = {
Tripout
AdvanceGameDay -SkipPriceUpdate
}
},
@{
"Name" = "Marrakesh Express"
"Description" = "The Marrakesh Express has arrived in town!"
"Effect" = {
# Add some random "Hash" Drugs to the player's inventory, if they already have Hash, just add to its quantity.
$giveAwayQuantity = Get-Random -Minimum 5 -Maximum 26
Write-Centered ('They''re giving out {0} pockets of free Hash!' -f $giveAwayQuantity)
Write-Host
# If they have free pockets to hold the Hash, add as much to their inventory as possible.
if ($script:Player.get_FreePocketCount() -ge 1) {
if ($script:Player.get_FreePocketCount() -lt $giveAwayQuantity) {
Write-Centered ('You only have room for {0} pockets of free Hash.' -f $script:Player.get_FreePocketCount()) -ForegroundColor Yellow
Start-Sleep -Seconds 2
Write-Centered 'But that''s still better than a kick in the ass''! :)'
$giveAwayQuantity = $script:Player.get_FreePocketCount()
}
$freeHash = $script:Player.Drugs | Where-Object { $_.Name -eq 'Hash' }
if ($freeHash) {
$freeHash.Quantity += $giveAwayQuantity
}
else {
$freeHash = [Drug]::new('Hash')
$freeHash.Quantity = $giveAwayQuantity
$script:Player.AddDrugs($freeHash)
}
Write-Centered ('Filled {0} pockets with free Hash!' -f $giveAwayQuantity) -ForegroundColor DarkGreen
}
else {
Write-Centered 'Bummer! You don''t have any empty pockets to hold the free Hash.'
Start-Sleep -Seconds 3
Write-Host
if ((Write-BlockLetters '** BURN!! **' -ForegroundColor Black -BackgroundColor DarkRed -Align Center -VerticalPadding 1) -eq $false) {
Write-Centered ' ' -BackgroundColor DarkRed
Write-Centered '** BURN!! **' -ForegroundColor Black -BackgroundColor DarkRed
Write-Centered ' ' -BackgroundColor DarkRed
}
Start-Sleep -Seconds 2
}
}
},
@{
"Name" = "Bad Batch"
"Description" = "You got a bad batch of drugs. You lose 10% of your cash trying to get rid of it."
"Effect" = {
# Calculate 10% of the player's cash, rounded to the nearest dollar
$loss = [int]([math]::Round($script:Player.Cash * 0.10))
# Subtract the loss from the player's cash.
$script:Player.Cash -= $loss
Start-Sleep -Seconds 2
Write-Host
Write-Centered ('You lost ${0}.' -f $loss) -ForegroundColor DarkRed
Start-Sleep -Seconds 2
}
},
@{
"Name" = 'The Shadow'
"Description" = 'A shadowy figure approaches you and whispers, "Psst... I know when the next Home Drug Sale Day is..."'
"Effect" = {
# Figure out when next Home Drug sale day is from $script:HomeDrugSaleDays list
$nextSaleDay = $script:HomeDrugSaleDays | Sort-Object | Where-Object { $_ -gt $script:Player.GameDay } | Select-Object -First 1
$daysUntilNextSale = $nextSaleDay - $script:Player.GameDay
Start-Sleep -Seconds 3
Write-Host
if ($nextSaleDay) {