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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
#![allow(deprecated)]
use enum_map::Enum;
use log::warn;
use num_derive::FromPrimitive;
use strum::EnumIter;
use crate::{
PlayerId,
gamestate::{
ShopPosition,
character::*,
dungeons::{CompanionClass, Dungeon},
fortress::*,
guild::{Emblem, GuildSkill},
idle::IdleBuildingType,
items::*,
legendary_dungeon::{
DoorType, DungeonEffectType, GemOfFateType,
LegendaryDungeonEventTheme, RPSChoice,
},
social::Relationship,
underworld::*,
unlockables::*,
},
};
/// A command, that can be sent to the sf server
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Command {
/// If there is a command you somehow know/reverse engineered, or need to
/// extend the functionality of one of the existing commands, this is the
/// command for you
Custom {
/// The thing in the command, that comes before the ':'
cmd_name: String,
/// The values this command gets as arguments. These will be joined
/// with '/'
arguments: Vec<String>,
},
/// Manually sends a login request to the server.
/// **WARN:** The behavior for a credentials mismatch, with the
/// credentials in the user is undefined. Use the login method instead
/// for a safer abstraction
#[deprecated = "Use the login method instead"]
Login {
/// The username of the player you are trying to login
username: String,
/// The sha1 hashed password of the player
pw_hash: String,
/// Honestly, I am not 100% sure what this is anymore, but it is
/// related to the amount of times you have logged in. Might be useful
/// for logging in again after error
login_count: u32,
},
/// Manually sends a login request to the server.
/// **WARN:** The behavior for a credentials mismatch, with the
/// credentials in the user is undefined. Use the login method instead for
/// a safer abstraction
#[cfg(feature = "sso")]
#[deprecated = "Use a login method instead"]
SSOLogin {
/// Identifies the S&F account, that has this character
uuid: String,
/// Identifies the specific character an account has
character_id: String,
/// The thing to authenticate with
bearer_token: String,
},
/// Registers a new normal character in the server. I am not sure about the
/// portrait, so currently this sets the same default portrait for every
/// char
#[deprecated = "Use the register method instead"]
Register {
/// The username of the new account
username: String,
/// The password of the new account
password: String,
/// The gender of the new character
gender: Gender,
/// The race of the new character
race: Race,
/// The class of the new character
class: Class,
},
/// Updates the current state of the entire gamestate. Also notifies the
/// guild, that the player is logged in. Should therefore be sent
/// regularly
Update,
/// Queries 51 Hall of Fame entries starting from the top. Starts at 0
///
/// **NOTE:** The server might return less than 51, if there is a "broken"
/// player encountered. This is NOT a library bug, this is a S&F bug and
/// will glitch out the UI, when trying to view the page in a browser.
// I assume this is because the player name contains some invalid
// character, because in the raw response string the last thing is a
// half written username "e(" in this case. I would guess that they
// were created before stricter input validation and never fixed. Might
// be insightful in the future to use the sequential id lookup in the
// playerlookat to see, if they can be viewed from there
HallOfFamePage {
/// The page of the Hall of Fame you want to query.
///
/// 0 => rank(0..=50), 1 => rank(51..=101), ...
page: usize,
},
/// Queries 51 Hall of Fame entries for the fortress starting from the top.
/// Starts at 0
HallOfFameFortressPage {
/// The page of the Hall of Fame you want to query.
///
/// 0 => rank(0..=50), 1 => rank(51..=101), ...
page: usize,
},
/// Looks at a specific player. Ident is either their name, or `player_id`.
/// The information about the player can then be found by using the
/// lookup_* methods on `HallOfFames`
ViewPlayer {
/// Either the name, or the `playerid.to_string()`
ident: String,
},
/// Buys a beer in the tavern
BuyBeer,
/// Starts one of the 3 tavern quests. **0,1,2**
StartQuest {
/// The position of the quest in the quest array
quest_pos: usize,
/// Has the player acknowledged, that their inventory is full and this
/// may lead to the loss of an item?
overwrite_inv: bool,
},
/// Cancels the currently running quest
CancelQuest,
/// Finishes the current quest, which starts the battle. This can be used
/// with a `QuestSkip` to skip the remaining time
FinishQuest {
/// If this is `Some()`, it will use the selected skip to skip the
/// remaining quest wait
skip: Option<TimeSkip>,
},
/// Goes working for the specified amount of hours (1-10)
StartWork {
/// The amount of hours you want to work
hours: u8,
},
/// Cancels the current guard job
CancelWork,
/// Collects the pay from the guard job
FinishWork,
/// Checks if the given name is still available to register
CheckNameAvailable {
/// The name to check
name: String,
},
/// Buys a mount, if the player has enough silver/mushrooms
BuyMount {
/// The mount you want to buy
mount: Mount,
},
/// Increases the given base attribute to the requested number. Should be
/// `current + 1`
IncreaseAttribute {
/// The attribute you want to increase
attribute: AttributeType,
/// The value you increase it to. This should be `current + 1`
increase_to: u32,
},
/// Removes the currently active potion 0,1,2
RemovePotion {
/// The position of the potion you want to remove
pos: usize,
},
/// Queries the currently available enemies in the arena
CheckArena,
/// Fights the selected enemy. This should be used for both arena fights
/// and normal fights. Note that this actually needs the name, not just the
/// id
Fight {
/// The name of the player you want to fight
name: String,
/// If the arena timer has not elapsed yet, this will spend a mushroom
/// and fight regardless. Currently the server ignores this and fights
/// always, but the client sends the correctly set command, so you
/// should too
use_mushroom: bool,
},
/// Collects the current reward from the calendar
CollectCalendar,
/// Collects the current door from the advent calendar
CollectAdventsCalendar,
/// Queries information about another guild. The information can bet found
/// in `hall_of_fames.other_guilds`
ViewGuild {
/// Either the id, or name of the guild you want to look at
guild_ident: String,
},
/// Founds a new guild
GuildFound {
/// The name of the new guild you want to found
name: String,
},
/// Invites a player with the given name into the players guild
GuildInvitePlayer {
/// The name of the player you want to invite
name: String,
},
/// Kicks a player with the given name from the players guild
GuildKickPlayer {
/// The name of the guild member you want to kick
name: String,
},
/// Promote a player from the guild into the leader role
GuildSetLeader {
/// The name of the guild member you want to set as the guild leader
name: String,
},
/// Toggles a member between officer and normal member
GuildToggleOfficer {
/// The name of the player you want to toggle the officer status for
name: String,
},
/// Loads a mushroom into the catapult
GuildLoadMushrooms,
/// Increases one of the guild skills by 1. Needs to know the current, not
/// the new value for some reason
GuildIncreaseSkill {
/// The skill you want to increase
skill: GuildSkill,
/// The current value of the guild skill
current: u16,
},
/// Joins the current ongoing attack
GuildJoinAttack,
/// Joins the defense of the guild
GuildJoinDefense,
/// Starts an attack in another guild
GuildAttack {
/// The name of the guild you want to attack
guild: String,
},
/// Starts the next possible raid
GuildRaid,
/// Battles the enemy in the guildportal
GuildPortalBattle,
/// Fetch the fightable guilds
GuildGetFightableTargets,
/// Flushes the toilet
ToiletFlush,
/// Opens the toilet door for the first time.
ToiletOpen,
/// Drops an item from one of the inventories into the toilet
ToiletDrop {
/// The place of the item, that you want to throw into the toilet.
/// You can use `BagPosition` and `EquipmentSlot` here by calling
/// `pos.into()`
item_pos: PlayerItemPosition,
},
/// Buys an item from the shop and puts it in the inventory slot specified
BuyShop {
/// The position of the item you want to buy. You get this from
/// `.iter()` on shop, or by constructing it yourself
shop_pos: ShopPosition,
/// The place where the new item should end up.
/// You can use `BagPosition` and `EquipmentSlot` here by calling
/// `pos.into()`
new_pos: PlayerItemPosition,
/// Identifies the source item to ensure it has not changed since
/// you looked at it (shop reroll, etc.). You can get this ident by
/// calling `.command_ident()` on any Item
item_ident: ItemCommandIdent,
},
/// Sells an item from the players inventory. To make this more convenient,
/// this picks a shop&item position to sell to for you
SellShop {
/// The position of the item you want to sell in the shop
/// You can use `BagPosition` and `EquipmentSlot` here by calling
/// `pos.into()`
item_pos: PlayerItemPosition,
/// Identifies the source item to ensure it has not changed since
/// you looked at it (shop reroll, etc.). You can get this ident by
/// calling `.command_ident()` on any Item
item_ident: ItemCommandIdent,
},
/// Moves an item from one player owned position to another
PlayerItemMove {
/// The position that you want to move the item from
/// You can use `BagPosition` and `EquipmentSlot` here by calling
/// `pos.into()`
from: PlayerItemPosition,
/// The position that you want to move the item to
/// You can use `BagPosition` and `EquipmentSlot` here by calling
/// `pos.into()`
to: PlayerItemPosition,
/// Identifies the source item to ensure it has not changed since
/// you looked at it (shop reroll, etc.). You can get this ident by
/// calling `.command_ident()` on any Item
item_ident: ItemCommandIdent,
},
/// Allows moving items from any position to any other position items can
/// be at. You should make sure, that the move makes sense (do not move
/// items from shop to shop)
ItemMove {
/// The place of thing you move the item from
from: ItemPosition,
/// The position of the item you want to move to
to: ItemPosition,
/// Identifies the source item to ensure it has not changed since
/// you looked at it (shop reroll, etc.). You can get this ident by
/// calling `.command_ident()` on any Item
item_ident: ItemCommandIdent,
},
/// Allows using a potion from any position
UsePotion {
/// The place of the potion you use from
from: ItemPosition,
/// Identifies the source item to ensure it has not changed since
/// you looked at it (shop reroll, etc.). You can get this ident by
/// calling `.command_ident()` on any Item
item_ident: ItemCommandIdent,
},
/// Opens the message at the specified index [0-100]
MessageOpen {
/// The index of the message in the inbox vec
pos: i32,
},
/// Deletes a single message, if you provide the index. -1 = all
MessageDelete {
/// The position of the message to delete in the inbox vec. If this is
/// -1, it deletes all
pos: i32,
},
/// Pulls up your scrapbook to reveal more info, than normal
ViewScrapbook,
/// Views a specific pet. This fetches its stats and places it into the
/// specified pet in the habitat
ViewPet {
/// The id of the pet, that you want to view
pet_id: u16,
},
/// Unlocks a feature. The these unlockables can be found in
/// `pending_unlocks` on `GameState`
UnlockFeature {
/// The thing to unlock
unlockable: Unlockable,
},
/// Starts a fight against the enemy in the players portal
FightPortal,
/// Updates the current state of the dungeons. This is equivalent to
/// clicking the Dungeon-Button in the game. It is strongly recommended to
/// call this before fighting, since `next_free_fight` and the dungeon
/// floors may not be updated otherwise. Notably, `FightDungeon` and
/// `Update` do NOT update these values, so you can end up in an endless
/// loop, if you are just relying on `next_free_fight` without calling
/// `UpdateDungeons`
UpdateDungeons,
/// Enters a specific dungeon. This works for all dungeons, except the
/// Tower, which you must enter via the `FightTower` command
FightDungeon {
/// The dungeon you want to fight in (except the tower). If you only
/// have a `LightDungeon`, or `ShadowDungeon`, you need to call
/// `into()` to turn them into a generic dungeon
dungeon: Dungeon,
/// If this is true, you will spend a mushroom, if the timer has not
/// run out. Note, that this is currently ignored by the server for
/// some reason
use_mushroom: bool,
},
/// Attacks the requested level of the tower
FightTower {
/// The current level you are on the tower
current_level: u8,
/// If this is true, you will spend a mushroom, if the timer has not
/// run out. Note, that this is currently ignored by the server for
/// some reason
use_mush: bool,
},
/// Fights the player opponent with your pet
FightPetOpponent {
/// The habitat opponent you want to attack the opponent in
habitat: HabitatType,
/// The id of the player you want to fight
opponent_id: PlayerId,
},
/// Fights the pet in the specified habitat dungeon
FightPetDungeon {
/// If this is true, you will spend a mushroom, if the timer has not
/// run out. Note, that this is currently ignored by the server for
/// some reason
use_mush: bool,
/// The habitat, that you want to fight in
habitat: HabitatType,
/// This is `explored + 1` of the given habitat. Note that 20 explored
/// is the max, so providing 21 here will return an err
enemy_pos: u32,
/// This `pet_id` is the id of the pet you want to send into battle.
/// The pet has to be from the same habitat, as the dungeon you are
/// trying
player_pet_id: u32,
},
/// Brews a potion at the witch. This will consume 10 fruit from the given
/// habitat
BrewPotion {
fruit_type: HabitatType,
},
/// Sets the guild info. Note the info about length limit from
/// `SetDescription` for the description
GuildSetInfo {
/// The description you want to set
description: String,
/// The emblem you want to set
emblem: Emblem,
},
/// Gambles the desired amount of silver. Picking the right thing is not
/// actually required. That just masks the determined result. The result
/// will be in `gamble_result` on `Tavern`
GambleSilver {
/// The amount of silver to gamble
amount: u64,
},
/// Gambles the desired amount of mushrooms. Picking the right thing is not
/// actually required. That just masks the determined result. The result
/// will be in `gamble_result` on `Tavern`
GambleMushrooms {
/// The amount of mushrooms to gamble
amount: u64,
},
/// Sends a message to another player
SendMessage {
/// The name of the player to send a message to
to: String,
/// The message to send
msg: String,
},
/// The description may only be 240 chars long, when it reaches the
/// server. The problem is, that special chars like '/' have to get
/// escaped into two chars "$s" before getting sent to the server.
/// That means this string can be 120-240 chars long depending on the
/// amount of escaped chars. We 'could' truncate the response, but
/// that could get weird with character boundaries in UTF8 and split the
/// escapes themselves, so just make sure you provide a valid value here
/// to begin with and be prepared for a server error
SetDescription {
/// The description to set
description: String,
},
/// Drop the item from the specified position into the witches cauldron
WitchDropCauldron {
/// The place of the item, that you want to drop into the cauldron.
/// You can use `BagPosition` and `EquipmentSlot` here by calling
/// `pos.into()`
item_pos: PlayerItemPosition,
},
/// Uses the blacksmith with the specified action on the specified item
Blacksmith {
/// The place of the item, that you want to use at the blacksmith.
/// You can use `BagPosition` and `EquipmentSlot` here by calling
/// `pos.into()`
item_pos: PlayerItemPosition,
/// The action you want to use on the item
action: BlacksmithAction,
/// Identifies the source item to ensure it has not changed since
/// you looked at it (shop reroll, etc.). You can get this ident by
/// calling `.command_ident()` on any Item
item_ident: ItemCommandIdent,
},
/// Sends the specified message in the guild chat
GuildSendChat {
/// The message to send
message: String,
},
/// Enchants the currently worn item, associated with this enchantment,
/// with the enchantment
WitchEnchant {
/// The enchantment to apply
enchantment: EnchantmentIdent,
},
/// Enchants the item the companion has equipped, which is associated with
/// this enchantment.
WitchEnchantCompanion {
/// The enchantment to apply
enchantment: EnchantmentIdent,
/// The companion you want to enchant the item of
companion: CompanionClass,
},
/// The recommended underworld enemy is dynamically fetched by the game
/// by querying the Hall of Fame with a special command. As such, the
/// result of this command will be parsed as a normal Hall of Fame lookup
/// in the `GameState`
UpdateLureSuggestion,
/// Looks up who the suggested player for the underworld actually is. The
/// result will be in `hall_of_fames.players`, since this command basically
/// just queries the Hall of Fame
ViewLureSuggestion {
/// The suggested enemy fetched using `UpdateLureSuggestion`
suggestion: LureSuggestion,
},
/// Spins the wheel. All information about when you can spin, or what you
/// won are in `game_state.specials.wheel`
SpinWheelOfFortune {
/// The resource you want to spend to spin the wheel
payment: FortunePayment,
},
/// Collects the reward for event points
CollectEventTaskReward {
/// One of [0,1,2], depending on which reward has been unlocked
pos: usize,
},
/// Collects the reward for collecting points.
CollectDailyQuestReward {
/// One of [0,1,2], depending on which chest you want to collect
pos: usize,
},
/// Moves an item from a normal inventory, into the equipmentslot of the
/// player. This can be used to equip items, but also to socket/replace
/// gems
Equip {
/// The position in the inventory, that you want to equip in the
/// equipment slot
from_pos: PlayerItemPosition,
/// The slot of the item you want to equip
to_slot: EquipmentSlot,
/// Identifies the source item to ensure it has not changed since
/// you looked at it (shop reroll, etc.). You can get this ident by
/// calling `.command_ident()` on any Item
item_ident: ItemCommandIdent,
},
/// Moves an item from a normal inventory, onto one of the companions
EquipCompanion {
/// The position in the inventory, that you want to equip in the
/// companion equipment slot
from_pos: PlayerItemPosition,
/// The slot of the companion you want to equip
to_slot: EquipmentSlot,
/// Identifies the source item to ensure it has not changed since
/// you looked at it (shop reroll, etc.). You can get this ident by
/// calling `.command_ident()` on any Item
item_ident: ItemCommandIdent,
/// The companion you want to equip
to_companion: CompanionClass,
},
/// Collects a specific resource from the fortress
FortressGather {
/// The type of resource you want to collect
resource: FortressResourceType,
},
/// Changes the fortress enemy to the counterattackable enemy
FortressChangeEnemy {
/// The id of the counter attack notification mail of the enemy, that
/// you want to change to
msg_id: i64,
},
/// Collects resources from the fortress secret storage
/// Note that the official client only ever collects either stone or wood
/// but not both at the same time
FortressGatherSecretStorage {
/// The amount of stone you want to collect
stone: u64,
/// The amount of wood you want to collect
wood: u64,
},
/// Builds, or upgrades a building in the fortress
FortressBuild {
/// The building you want to upgrade, or build
f_type: FortressBuildingType,
},
/// Cancels the current build/upgrade, of the specified building in the
/// fortress
FortressBuildCancel {
/// The building you want to cancel the upgrade, or build of
f_type: FortressBuildingType,
},
/// Finish building/upgrading a Building
/// When mushrooms != 0, mushrooms will be used to "skip" the upgrade
/// timer. However, this command also needs to be sent when not
/// skipping the wait, with mushrooms = 0, after the build/upgrade
/// timer has finished.
FortressBuildFinish {
f_type: FortressBuildingType,
mushrooms: u32,
},
/// Builds new units of the selected type
FortressBuildUnit {
unit: FortressUnitType,
count: u32,
},
/// Starts the search for gems
FortressGemStoneSearch,
/// Cancels the search for gems
FortressGemStoneSearchCancel,
/// Finishes the gem stone search using the appropriate amount of
/// mushrooms. The price is one mushroom per 600 sec / 10 minutes of time
/// remaining
FortressGemStoneSearchFinish {
mushrooms: u32,
},
/// Attacks the current fortress attack target with the provided amount of
/// soldiers
FortressAttack {
soldiers: u32,
},
/// Re-rolls the enemy in the fortress
FortressNewEnemy {
use_mushroom: bool,
},
/// Sets the fortress enemy to the counterattack target of the message
FortressSetCAEnemy {
msg_id: u32,
},
/// Upgrades the Hall of Knights to the next level
FortressUpgradeHallOfKnights,
/// Upgrades the given unit in the fortress using the smith
FortressUpgradeUnit {
/// The unit you want to upgrade
unit: FortressUnitType,
},
/// Sends a whisper message to another player
Whisper {
player_name: String,
message: String,
},
/// Collects the resources of the selected type in the underworld
UnderworldCollect {
resource: UnderworldResourceType,
},
/// Upgrades the selected underworld unit by one level
UnderworldUnitUpgrade {
unit: UnderworldUnitType,
},
/// Starts the upgrade of a building in the underworld
UnderworldUpgradeStart {
building: UnderworldBuildingType,
mushrooms: u32,
},
/// Cancels the upgrade of a building in the underworld
UnderworldUpgradeCancel {
building: UnderworldUnitType,
},
/// Finishes an upgrade after the time has run out (or before using
/// mushrooms)
UnderworldUpgradeFinish {
building: UnderworldBuildingType,
mushrooms: u32,
},
/// Lures a player into the underworld
UnderworldAttack {
player_id: PlayerId,
},
/// Rolls the dice. The first round should be all re-rolls, after that,
/// either re-roll again, or take some of the dice on the table
RollDice {
payment: RollDicePrice,
dices: [DiceType; 5],
},
/// Feeds one of your pets
PetFeed {
pet_id: u32,
fruit_idx: u32,
},
/// Fights with the guild pet against the hydra
GuildPetBattle {
use_mushroom: bool,
},
/// Upgrades an idle building by the requested amount
IdleUpgrade {
typ: IdleBuildingType,
amount: IdleUpgradeAmount,
},
/// Sacrifice all the money in the idle game for runes
IdleSacrifice,
/// Upgrades a skill to the requested attribute. Should probably be just
/// current + 1 to mimic a user clicking
UpgradeSkill {
attribute: AttributeType,
next_attribute: u32,
},
/// Spend 1 mushroom to update the inventory of a shop
RefreshShop {
shop: ShopType,
},
/// Fetches the Hall of Fame page for guilds
HallOfFameGroupPage {
page: u32,
},
/// Crawls the Hall of Fame page for the underworld
HallOfFameUnderworldPage {
page: u32,
},
HallOfFamePetsPage {
page: u32,
},
/// Switch equipment with the mannequin, if it is unlocked
SwapMannequin,
/// Updates your flag in the Hall of Fame
UpdateFlag {
flag: Option<Flag>,
},
/// Changes if you can receive invites or not
BlockGuildInvites {
block_invites: bool,
},
/// Changes if you want to get tips in the gui. Does nothing for the API
ShowTips {
show_tips: bool,
},
/// Change your password. Note that I have not tested this and this might
/// invalidate your session
ChangePassword {
username: String,
old: String,
new: String,
},
/// Changes your mail to another address
ChangeMailAddress {
old_mail: String,
new_mail: String,
password: String,
username: String,
},
/// Sets the language of the character. This should be basically
/// irrelevant, but is still included for completeness sake. Expects a
/// valid country code. I have not tested all, but it should be one of:
/// `ru,fi,ar,tr,nl,ja,it,sk,fr,ko,pl,cs,el,da,en,hr,de,zh,sv,hu,pt,es,
/// pt-br, ro`
SetLanguage {
language: String,
},
/// Sets the relation to another player
SetPlayerRelation {
player_id: PlayerId,
relation: Relationship,
},
/// I have no character with anything but the default (0) to test this
/// with. If I had to guess, they continue sequentially
SetPortraitFrame {
portrait_id: i64,
},
/// Swaps the runes of two items
SwapRunes {
from: ItemPlace,
from_pos: usize,
to: ItemPlace,
to_pos: usize,
},
/// Changes the look of the item to the selected `raw_model_id` for 10
/// mushrooms. Note that this is NOT the normal model id. it is the
/// `model_id + (class as usize) * 1000` if I remember correctly. Pretty
/// sure nobody will ever use this though, as it is only for looks.
ChangeItemLook {
inv: ItemPlace,
pos: usize,
raw_model_id: u16,
},
/// Continues the expedition by picking one of the <=3 encounters \[0,1,2\]
ExpeditionPickEncounter {
/// The position of the encounter you want to pick
pos: usize,
},
/// Continues the expedition, if you are currently in a situation, where
/// there is only one option. This can be starting a fighting, or starting
/// the wait after a fight (collecting the non item reward). Behind the
/// scenes this is just ExpeditionPickReward(0)
ExpeditionContinue,
/// If there are multiple items to choose from after fighting a boss, you
/// can choose which one to take here. \[0,1,2\]
ExpeditionPickReward {
/// The array position/index of the reward you want to take
pos: usize,
},
/// Starts one of the two expeditions \[0,1\]
ExpeditionStart {
/// The index of the expedition to start
pos: usize,
},
/// Starts the normal (not the ultimate) legendary dungeon
LegendaryDungeonEnter {
theme: LegendaryDungeonEventTheme,
},
/// Buy a curse in the `KeyToFailureShop`
LegendaryDungeonBuyCurse {
effect: DungeonEffectType,
keys: u32,
},
/// Buy a blessing in the `KeyMasterShop`
LegendaryDungeonBuyBlessing {
effect: DungeonEffectType,
keys: u32,
},
/// Interacts with the encounter. This is the default, just entered the
/// room and click on the thing, action for anything, that is not a fight
LegendaryDungeonEncounterInteract,
/// Escapes from an encounter, that is willing to fight and may attack you
/// for escaping
LegendaryDungeonEncounterEscape,
/// Leaves the encounter room without interacting with ever having
/// interacted with the encounter
LegendaryDungeonEncounterLeave,
LegendaryDungeonMerchantNewGoods,
/// Leaves non-encounter rooms
LegendaryDungeonRoomLeave,
/// Play Rock, Paper, Scissors with your provided choice. I don't think
/// this makes a difference, but you still have the option to choose one
LegendaryDungeonPlayRPC {
choice: RPSChoice,
},
LegendaryDungeonTakeItem {
/// The idx of the item in the dungeon, that you want to take, if there
/// are multiple. Should just be 0 in most cases
item_idx: usize,
/// The inventory you move the item to
inventory_to: PlayerItemPosition,
/// Identifies the source item to ensure it has not changed since
/// you looked at it (shop reroll, etc.). You can get this ident by
/// calling `.command_ident()` on any Item
item_ident: ItemCommandIdent,
},
/// You are in a (golden) room, that has some sort of gimmick. This could
/// be the locker room, or smth. else. In those cases you can either
/// interact, or leave
LegendaryDungeonRoomInteract,
/// The dungeon is in a state, that there is only one option, which the
/// official client will automatically do. This mainly happens, when you
/// Have interacted with the room and the game "automatically" continues,
/// because otherwise you would just awkwardly stand in the same room until
/// you "flee"
LegendaryDungeonForcedContinue,
/// You have defeated the monster. Collect the key, that it dropped to
/// continue
LegendaryDungeonMonsterCollectKey,
/// Picks either the left, or the right door
LegendaryDungeonPickDoor {
/// 0 => left, 1 => right
pos: usize,
/// The type of the door, that you want to enter
typ: DoorType,
},
LegendaryDungeonPickGem {
gem_type: GemOfFateType,
},
LegendaryDungeonInteract {
val: usize,
},
/// Skips the waiting period of the current expedition. Note that mushroom
/// may not always be possible
ExpeditionSkipWait {
/// The "currency" you want to skip the expedition
typ: TimeSkip,
},
/// This sets the "Questing instead of expeditions" value in the settings.
/// This will decide if you can go on expeditions, or do quests, when
/// expeditions are available. Going on the "wrong" one will return an
/// error. Similarly this setting can only be changed, when no Thirst for
/// Adventure has been used today, so make sure to check if that is full
/// and `beer_drunk == 0`
SetQuestsInsteadOfExpeditions {
/// The value you want to set
value: ExpeditionSetting,
},
HellevatorEnter,
HellevatorViewGuildRanking,
HellevatorFight {
use_mushroom: bool,
},
HellevatorBuy {
position: usize,
typ: HellevatorTreatType,
price: u32,
use_mushroom: bool,
},
HellevatorRefreshShop,
HellevatorJoinHellAttack {
use_mushroom: bool,
plain: usize,
},
HellevatorClaimDaily,
HellevatorClaimDailyYesterday,
HellevatorClaimFinal,
HellevatorPreviewRewards,
HallOfFameHellevatorPage {
page: usize,
},
ClaimablePreview {
msg_id: i64,
},
ClaimableClaim {
msg_id: i64,
},
/// Spend 1000 mushrooms to buy a gold frame
BuyGoldFrame,
LegendaryDungeonMonsterFight,
LegendaryDungeonMonsterEscape,
}
/// This is the "Questing instead of expeditions" value in the settings
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ExpeditionSetting {
/// When expeditions are available, this setting will enable expeditions to
/// be started. This will disable questing, until either this setting is
/// disabled, or expeditions have ended. Trying to start a quest with this
/// setting set will return an error
PreferExpeditions,
/// When expeditions are available, they will be ignored, until either this
/// setting is disabled, or expeditions have ended. Starting an
/// expedition with this setting set will error
#[default]
PreferQuests,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum BlacksmithAction {
Dismantle = 201,
SocketUpgrade = 202,
SocketUpgradeWithMushrooms = 212,
GemExtract = 203,
GemExtractWithMushrooms = 213,
Upgrade = 204,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum FortunePayment {
LuckyCoins = 0,
Mushrooms,
FreeTurn,
}
/// The price you have to pay to roll the dice
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum RollDicePrice {
Free = 0,
Mushrooms,
Hourglass,
}
/// The type of dice you want to play with.
#[derive(Debug, Clone, Copy, FromPrimitive, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(missing_docs)]
pub enum DiceType {
/// This means you want to discard whatever dice was previously at this
/// position. This is also the type you want to fill the array with, if you
/// start a game
ReRoll,
Silver,
Stone,
Wood,
Souls,
Arcane,
Hourglass,
}
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DiceReward {
/// The resource you have won
pub win_typ: DiceType,
/// The amounts of the resource you have won
pub amount: u32,
}
/// A type of attribute
#[derive(
Debug, Copy, Clone, PartialEq, Eq, Enum, FromPrimitive, Hash, EnumIter,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(missing_docs)]
pub enum AttributeType {
Strength = 1,
Dexterity = 2,
Intelligence = 3,
Constitution = 4,
Luck = 5,
}
/// A type of shop. This is a subset of `ItemPlace`
#[derive(Debug, Clone, Copy, PartialEq, Eq, Enum, EnumIter, Hash, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(missing_docs)]
pub enum ShopType {
#[default]
Weapon = 3,
Magic = 4,
}
/// The "currency" you want to use to skip a quest
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(missing_docs)]
pub enum TimeSkip {
Mushroom = 1,
Glass = 2,
}
/// The allowed amounts, that you can upgrade idle buildings by
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(missing_docs)]
pub enum IdleUpgradeAmount {
/// Upgrades as much as we can afford to
Max = -1,
/// Upgrades one building
One = 1,
/// Upgrades the building ten times
Ten = 10,
/// Upgrades the building twenty-five times
TwentyFive = 25,
/// Upgrades the building one hundred times
Hundred = 100,
}
impl Command {
/// Returns the unencrypted string, that has to be sent to the server to
/// perform the request
#[allow(deprecated, clippy::useless_format)]
#[cfg(feature = "session")]
pub(crate) fn request_string(
&self,
) -> Result<String, crate::error::SFError> {
const APP_VERSION: &str = "300000000000";
use crate::{
error::SFError,
gamestate::dungeons::{LightDungeon, ShadowDungeon},
misc::{HASH_CONST, sha1_hash, to_sf_string},
};
Ok(match self {
Command::Custom {
cmd_name,
arguments: values,
} => {
format!("{cmd_name}:{}", values.join("/"))
}
Command::Login {
username,
pw_hash,
login_count,
} => {
let full_hash = sha1_hash(&format!("{pw_hash}{login_count}"));
format!(
"AccountLogin:{username}/{full_hash}/{login_count}/\
unity3d_webglplayer//{APP_VERSION}///0/"
)
}
#[cfg(feature = "sso")]
Command::SSOLogin {
uuid, character_id, ..
} => format!(
"SFAccountCharLogin:{uuid}/{character_id}/unity3d_webglplayer/\
/{APP_VERSION}"
),
Command::Register {
username,
password,
gender,
race,
class,
} => {
// TODO: Custom portrait
format!(
"AccountCreate:{username}/{password}/{username}@playa.sso/\
{}/{}/{}/8,203,201,6,199,3,1,2,1/0//en",
*gender as usize + 1,
*race as usize,
*class as usize + 1
)
}
Command::Update => "Poll:".to_string(),
Command::HallOfFamePage { page } => {
let per_page = 51;
let pos = 26 + (per_page * page);
format!("PlayerGetHallOfFame:{pos}//25/25")
}
Command::HallOfFameFortressPage { page } => {
let per_page = 51;
let pos = 26 + (per_page * page);
format!("FortressGetHallOfFame:{pos}//25/25")
}
Command::HallOfFameGroupPage { page } => {
let per_page = 51;
let pos = 26 + (per_page * page);
format!("GroupGetHallOfFame:{pos}//25/25")
}
Command::HallOfFameUnderworldPage { page } => {
let per_page = 51;
let pos = 26 + (per_page * page);
format!("UnderworldGetHallOfFame:{pos}//25/25")
}
Command::HallOfFamePetsPage { page } => {
let per_page = 51;
let pos = 26 + (per_page * page);
format!("PetsGetHallOfFame:{pos}//25/25")
}
Command::ViewPlayer { ident } => format!("PlayerLookAt:{ident}"),
Command::BuyBeer => format!("PlayerBeerBuy:"),
Command::StartQuest {
quest_pos,
overwrite_inv,
} => {
format!(
"PlayerAdventureStart:{}/{}",
quest_pos + 1,
u8::from(*overwrite_inv)
)
}
Command::CancelQuest => format!("PlayerAdventureStop:"),
Command::FinishQuest { skip } => {
format!(
"PlayerAdventureFinished:{}",
skip.map_or(0, |a| a as u8)
)
}
Command::StartWork { hours } => format!("PlayerWorkStart:{hours}"),
Command::CancelWork => format!("PlayerWorkStop:"),
Command::FinishWork => format!("PlayerWorkFinished:"),
Command::CheckNameAvailable { name } => {
format!("AccountCheck:{name}")
}
Command::BuyMount { mount } => {
format!("PlayerMountBuy:{}", *mount as usize)
}
Command::IncreaseAttribute {
attribute,
increase_to,
} => format!(
"PlayerAttributIncrease:{}/{increase_to}",
*attribute as u8
),
Command::RemovePotion { pos } => {
format!("PlayerPotionKill:{}", pos + 1)
}
Command::CheckArena => format!("PlayerArenaEnemy:"),
Command::Fight { name, use_mushroom } => {
format!("PlayerArenaFight:{name}/{}", u8::from(*use_mushroom))
}
Command::CollectCalendar => format!("PlayerOpenCalender:"),
Command::UpgradeSkill {
attribute,
next_attribute,
} => format!(
"PlayerAttributIncrease:{}/{next_attribute}",
*attribute as i64
),
Command::RefreshShop { shop } => {
format!("PlayerNewWares:{}", *shop as usize - 2)
}
Command::ViewGuild { guild_ident } => {
format!("GroupLookAt:{guild_ident}")
}
Command::GuildFound { name } => format!("GroupFound:{name}"),
Command::GuildInvitePlayer { name } => {
format!("GroupInviteMember:{name}")
}
Command::GuildKickPlayer { name } => {
format!("GroupRemoveMember:{name}")
}
Command::GuildSetLeader { name } => {
format!("GroupSetLeader:{name}")
}
Command::GuildToggleOfficer { name } => {
format!("GroupSetOfficer:{name}")
}
Command::GuildLoadMushrooms => {
format!("GroupIncreaseBuilding:0")
}
Command::GuildIncreaseSkill { skill, current } => {
format!("GroupSkillIncrease:{}/{current}", *skill as usize)
}
Command::GuildJoinAttack => format!("GroupReadyAttack:"),
Command::GuildJoinDefense => format!("GroupReadyDefense:"),
Command::GuildAttack { guild } => {
format!("GroupAttackDeclare:{guild}")
}
Command::GuildRaid => format!("GroupRaidDeclare:"),
Command::ToiletFlush => format!("PlayerToilettFlush:"),
Command::ToiletOpen => format!("PlayerToilettOpenWithKey:"),
Command::FightTower {
current_level: progress,
use_mush,
} => {
format!("PlayerTowerBattle:{progress}/{}", u8::from(*use_mush))
}
Command::ToiletDrop { item_pos } => {
format!("PlayerToilettLoad:{item_pos}")
}
Command::GuildPortalBattle => format!("GroupPortalBattle:"),
Command::GuildGetFightableTargets => {
format!("GroupFightableTargets:")
}
Command::FightPortal => format!("PlayerPortalBattle:"),
Command::MessageOpen { pos: index } => {
format!("PlayerMessageView:{}", *index + 1)
}
Command::MessageDelete { pos: index } => format!(
"PlayerMessageDelete:{}",
match index {
-1 => -1,
x => *x + 1,
}
),
Command::ViewScrapbook => format!("PlayerPollScrapbook:"),
Command::ViewPet { pet_id: pet_index } => {
format!("PetsGetStats:{pet_index}")
}
Command::BuyShop {
shop_pos,
new_pos,
item_ident,
} => format!("PlayerItemMove:{shop_pos}/{new_pos}/{item_ident}"),
Command::SellShop {
item_pos,
item_ident,
} => {
let mut rng = fastrand::Rng::new();
let shop = if rng.bool() {
ShopType::Magic
} else {
ShopType::Weapon
};
let shop_pos = rng.u32(0..6);
format!(
"PlayerItemMove:{item_pos}/{}/{}/{item_ident}",
shop as usize,
shop_pos + 1,
)
}
Command::PlayerItemMove {
from,
to,
item_ident,
} => format!("PlayerItemMove:{from}/{to}/{item_ident}"),
Command::ItemMove {
from,
to,
item_ident,
} => format!("PlayerItemMove:{from}/{to}/{item_ident}"),
Command::UsePotion { from, item_ident } => {
format!("PlayerItemMove:{from}/1/0/{item_ident}")
}
Command::UnlockFeature { unlockable } => format!(
"UnlockFeature:{}/{}",
unlockable.main_ident, unlockable.sub_ident
),
Command::GuildSetInfo {
description,
emblem,
} => format!(
"GroupSetDescription:{}§{}",
emblem.server_encode(),
to_sf_string(description)
),
Command::SetDescription { description } => {
format!("PlayerSetDescription:{}", to_sf_string(description))
}
Command::GuildSendChat { message } => {
format!("GroupChat:{}", to_sf_string(message))
}
Command::GambleSilver { amount } => {
format!("PlayerGambleGold:{amount}")
}
Command::GambleMushrooms { amount } => {
format!("PlayerGambleCoins:{amount}")
}
Command::SendMessage { to, msg } => {
format!("PlayerMessageSend:{to}/{}", to_sf_string(msg))
}
Command::WitchDropCauldron { item_pos } => {
format!("PlayerWitchSpendItem:{item_pos}")
}
Command::Blacksmith {
item_pos,
action,
item_ident,
} => format!(
"PlayerItemMove:{item_pos}/{}/-1/{item_ident}",
*action as usize
),
Command::WitchEnchant { enchantment } => {
format!("PlayerWitchEnchantItem:{}/1", enchantment.0)
}
Command::WitchEnchantCompanion {
enchantment,
companion,
} => {
format!(
"PlayerWitchEnchantItem:{}/{}",
enchantment.0,
*companion as u8 + 101,
)
}
Command::UpdateLureSuggestion => {
format!("PlayerGetHallOfFame:-4//0/0")
}
Command::SpinWheelOfFortune {
payment: fortune_payment,
} => {
format!("WheelOfFortune:{}", *fortune_payment as usize)
}
Command::FortressGather { resource } => {
format!("FortressGather:{}", *resource as usize + 1)
}
Command::FortressGatherSecretStorage { stone, wood } => {
format!("FortressGatherTreasure:{wood}/{stone}")
}
Command::Equip {
from_pos,
to_slot,
item_ident,
} => format!(
"PlayerItemMove:{from_pos}/1/{}/{item_ident}",
*to_slot as usize
),
Command::EquipCompanion {
from_pos,
to_companion,
item_ident,
to_slot,
} => format!(
"PlayerItemMove:{from_pos}/{}/{}/{item_ident}",
*to_companion as u8 + 101,
*to_slot as usize
),
Command::FortressBuild { f_type } => {
format!("FortressBuildStart:{}/0", *f_type as usize + 1)
}
Command::FortressBuildCancel { f_type } => {
format!("FortressBuildStop:{}", *f_type as usize + 1)
}
Command::FortressBuildFinish { f_type, mushrooms } => format!(
"FortressBuildFinished:{}/{mushrooms}",
*f_type as usize + 1
),
Command::FortressBuildUnit { unit, count } => {
format!("FortressBuildUnitStart:{}/{count}", *unit as usize + 1)
}
Command::FortressGemStoneSearch => {
format!("FortressGemstoneStart:")
}
Command::FortressGemStoneSearchCancel => {
format!("FortressGemStoneStop:")
}
Command::FortressGemStoneSearchFinish { mushrooms } => {
format!("FortressGemstoneFinished:{mushrooms}")
}
Command::FortressAttack { soldiers } => {
format!("FortressAttack:{soldiers}")
}
Command::FortressNewEnemy { use_mushroom: pay } => {
format!("FortressEnemy:{}", usize::from(*pay))
}
Command::FortressSetCAEnemy { msg_id } => {
format!("FortressEnemy:0/{}", *msg_id)
}
Command::FortressUpgradeHallOfKnights => {
format!("FortressGroupBonusUpgrade:")
}
Command::FortressUpgradeUnit { unit } => {
format!("FortressUpgrade:{}", *unit as u8 + 1)
}
Command::Whisper {
player_name: player,
message,
} => format!(
"PlayerMessageWhisper:{}/{}",
player,
to_sf_string(message)
),
Command::UnderworldCollect { resource } => {
format!("UnderworldGather:{}", *resource as usize + 1)
}
Command::UnderworldUnitUpgrade { unit: unit_t } => {
format!("UnderworldUpgradeUnit:{}", *unit_t as usize + 1)
}
Command::UnderworldUpgradeStart {
building,
mushrooms,
} => format!(
"UnderworldBuildStart:{}/{mushrooms}",
*building as usize + 1
),
Command::UnderworldUpgradeCancel { building } => {
format!("UnderworldBuildStop:{}", *building as usize + 1)
}
Command::UnderworldUpgradeFinish {
building,
mushrooms,
} => {
format!(
"UnderworldBuildFinished:{}/{mushrooms}",
*building as usize + 1
)
}
Command::UnderworldAttack { player_id } => {
format!("UnderworldAttack:{player_id}")
}
Command::RollDice { payment, dices } => {
let mut dices = dices.iter().fold(String::new(), |mut a, b| {
if !a.is_empty() {
a.push('/');
}
a.push((*b as u8 + b'0') as char);
a
});
if dices.is_empty() {
// FIXME: This is dead code, right?
dices = "0/0/0/0/0".to_string();
}
format!("RollDice:{}/{}", *payment as usize, dices)
}
Command::PetFeed { pet_id, fruit_idx } => {
format!("PlayerPetFeed:{pet_id}/{fruit_idx}")
}
Command::GuildPetBattle { use_mushroom } => {
format!("GroupPetBattle:{}", usize::from(*use_mushroom))
}
Command::IdleUpgrade { typ: kind, amount } => {
format!("IdleIncrease:{}/{}", *kind as usize, *amount as i32)
}
Command::IdleSacrifice => format!("IdlePrestige:0"),
Command::SwapMannequin => format!("PlayerDummySwap:301/1"),
Command::UpdateFlag { flag } => format!(
"PlayerSetFlag:{}",
flag.map(Flag::code).unwrap_or_default()
),
Command::BlockGuildInvites { block_invites } => {
format!("PlayerSetNoGroupInvite:{}", u8::from(*block_invites))
}
Command::ShowTips { show_tips } => {
#[allow(clippy::unreadable_literal)]
{
format!(
"PlayerTutorialStatus:{}",
if *show_tips { 0 } else { 0xFFFFFFF }
)
}
}
Command::ChangePassword { username, old, new } => {
let old = sha1_hash(&format!("{old}{HASH_CONST}"));
let new = sha1_hash(&format!("{new}{HASH_CONST}"));
format!("AccountPasswordChange:{username}/{old}/106/{new}/")
}
Command::ChangeMailAddress {
old_mail,
new_mail,
password,
username,
} => {
let pass = sha1_hash(&format!("{password}{HASH_CONST}"));
format!(
"AccountMailChange:{old_mail}/{new_mail}/{username}/\
{pass}/106"
)
}
Command::SetLanguage { language } => {
format!("AccountSetLanguage:{language}")
}
Command::SetPlayerRelation {
player_id,
relation,
} => {
format!("PlayerFriendSet:{player_id}/{}", *relation as i32)
}
Command::SetPortraitFrame { portrait_id } => {
format!("PlayerSetActiveFrame:{portrait_id}")
}
Command::CollectDailyQuestReward { pos } => {
format!("DailyTaskClaim:1/{}", pos + 1)
}
Command::CollectEventTaskReward { pos } => {
format!("DailyTaskClaim:2/{}", pos + 1)
}
Command::SwapRunes {
from,
from_pos,
to,
to_pos,
} => {
format!(
"PlayerSmithSwapRunes:{}/{}/{}/{}",
*from as usize,
*from_pos + 1,
*to as usize,
*to_pos + 1
)
}
Command::ChangeItemLook {
inv,
pos,
raw_model_id: model_id,
} => {
format!(
"ItemChangePicture:{}/{}/{}",
*inv as usize,
pos + 1,
model_id
)
}
Command::ExpeditionPickEncounter { pos } => {
format!("ExpeditionProceed:{}", pos + 1)
}
Command::ExpeditionContinue => format!("ExpeditionProceed:1"),
Command::ExpeditionPickReward { pos } => {
format!("ExpeditionProceed:{}", pos + 1)
}
Command::ExpeditionStart { pos } => {
format!("ExpeditionStart:{}", pos + 1)
}
Command::LegendaryDungeonEnter { theme } => {
format!("IADungeonStart:{}/0", *theme as usize)
}
Command::LegendaryDungeonBuyBlessing { effect, keys } => {
format!("IADungeonMerchantBuy:{}/{}", *effect as i32, *keys)
}
Command::LegendaryDungeonBuyCurse { effect, keys } => {
format!(
"IADungeonDebuffMerchantBuy:{}/{}",
*effect as i32, *keys
)
}
Command::LegendaryDungeonMonsterCollectKey => {
"IADungeonInteract:60".into()
}
Command::LegendaryDungeonMerchantNewGoods => {
"IADungeonInteract:50".into()
}
Command::LegendaryDungeonInteract { val } => {
// Left door = 1
// Fight Monster => 20
// Open Chest => 40
// Interact Special => 50
// Run Special => 51
// FinishFight? => 60
// Finish Stage => 70
format!("IADungeonInteract:{val}")
}
Command::LegendaryDungeonMonsterFight => {
format!("IADungeonInteract:20")
}
Command::LegendaryDungeonMonsterEscape => {
format!("IADungeonInteract:21")
}
Command::LegendaryDungeonEncounterInteract => {
format!("IADungeonInteract:40")
}
Command::LegendaryDungeonEncounterEscape => {
format!("IADungeonInteract:41")
}
Command::LegendaryDungeonEncounterLeave => {
format!("IADungeonInteract:42")
}
Command::LegendaryDungeonRoomInteract => {
format!("IADungeonInteract:50")
}
Command::LegendaryDungeonRoomLeave => {
format!("IADungeonInteract:51")
}
Command::LegendaryDungeonForcedContinue => {
format!("IADungeonInteract:70")
}
Command::LegendaryDungeonPickDoor { pos, typ } => {
let mut id = pos + 1;
if matches!(
typ,
DoorType::LockedDoor
| DoorType::DoubleLockedDoor
| DoorType::EpicDoor
) {
id += 4;
}
format!("IADungeonInteract:{id}")
}
Command::LegendaryDungeonPlayRPC { choice } => {
format!("IADungeonInteract:{}", *choice as i32)
}
Command::LegendaryDungeonPickGem { gem_type } => {
format!("IADungeonSelectSoulStone:{}", *gem_type as u32)
}
Command::LegendaryDungeonTakeItem {
item_idx,
inventory_to,
item_ident,
} => {
format!(
"PlayerItemMove:401/{}/{inventory_to}/{item_ident}",
item_idx + 1
)
}
Command::FightDungeon {
dungeon,
use_mushroom,
} => match dungeon {
Dungeon::Light(name) => {
if *name == LightDungeon::Tower {
return Err(SFError::InvalidRequest(
"The tower must be fought with the FightTower \
command",
));
}
format!(
"PlayerDungeonBattle:{}/{}",
*name as usize + 1,
u8::from(*use_mushroom)
)
}
Dungeon::Shadow(name) => {
if *name == ShadowDungeon::Twister {
format!(
"PlayerDungeonBattle:{}/{}",
LightDungeon::Tower as u32 + 1,
u8::from(*use_mushroom)
)
} else {
format!(
"PlayerShadowBattle:{}/{}",
*name as u32 + 1,
u8::from(*use_mushroom)
)
}
}
},
Command::FightPetOpponent {
opponent_id,
habitat: element,
} => {
format!("PetsPvPFight:0/{opponent_id}/{}", *element as u32 + 1)
}
Command::BrewPotion { fruit_type } => {
format!("PlayerWitchBrewPotion:{}", *fruit_type as u8)
}
Command::FightPetDungeon {
use_mush,
habitat: element,
enemy_pos,
player_pet_id,
} => {
format!(
"PetsDungeonFight:{}/{}/{enemy_pos}/{player_pet_id}",
u8::from(*use_mush),
*element as u8 + 1,
)
}
Command::ExpeditionSkipWait { typ } => {
format!("ExpeditionTimeSkip:{}", *typ as u8)
}
Command::SetQuestsInsteadOfExpeditions { value } => {
let value = match value {
ExpeditionSetting::PreferExpeditions => 'a',
ExpeditionSetting::PreferQuests => 'b',
};
format!("UserSettingsUpdate:5/{value}")
}
Command::HellevatorEnter => format!("GroupTournamentJoin:"),
Command::HellevatorViewGuildRanking => {
format!("GroupTournamentRankingOwnGroup")
}
Command::HellevatorFight { use_mushroom } => {
format!("GroupTournamentBattle:{}", u8::from(*use_mushroom))
}
Command::HellevatorBuy {
position,
typ,
price,
use_mushroom,
} => {
format!(
"GroupTournamentMerchantBuy:{position}/{}/{price}/{}",
*typ as u32,
if *use_mushroom { 2 } else { 1 }
)
}
Command::HellevatorRefreshShop => {
format!("GroupTournamentMerchantReroll:")
}
Command::HallOfFameHellevatorPage { page } => {
let per_page = 51;
let pos = 26 + (per_page * page);
format!("GroupTournamentRankingAllGroups:{pos}//25/25")
}
Command::HellevatorJoinHellAttack {
use_mushroom,
plain: pos,
} => {
format!(
"GroupTournamentRaidParticipant:{}/{}",
u8::from(*use_mushroom),
*pos + 1
)
}
Command::HellevatorClaimDaily => {
format!("GroupTournamentClaimDaily:")
}
Command::HellevatorClaimDailyYesterday => {
format!("GroupTournamentClaimDailyYesterday:")
}
Command::HellevatorPreviewRewards => {
format!("GroupTournamentPreview:")
}
Command::HellevatorClaimFinal => format!("GroupTournamentClaim:"),
Command::ClaimablePreview { msg_id } => {
format!("PendingRewardView:{msg_id}")
}
Command::ClaimableClaim { msg_id } => {
format!("PendingRewardClaim:{msg_id}")
}
Command::BuyGoldFrame => {
format!("PlayerGoldFrameBuy:")
}
Command::UpdateDungeons => format!("PlayerDungeonOpen:"),
Command::CollectAdventsCalendar => {
format!("AdventsCalendarClaimReward:")
}
Command::ViewLureSuggestion { suggestion } => {
format!("PlayerGetHallOfFame:{}//0/0", suggestion.0)
}
Command::FortressChangeEnemy { msg_id } => {
format!("FortressEnemy:0/{msg_id}")
}
})
}
}
macro_rules! generate_flag_enum {
($($variant:ident => $code:expr),*) => {
/// The flag of a country, that will be visible in the Hall of Fame
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(missing_docs)]
pub enum Flag {
$(
$variant,
)*
}
impl Flag {
#[allow(unused)]
pub(crate) fn code(self) -> &'static str {
match self {
$(
Flag::$variant => $code,
)*
}
}
pub(crate) fn parse(value: &str) -> Option<Self> {
if value.is_empty() {
return None;
}
// Mapping from string codes to enum variants
match value {
$(
$code => Some(Flag::$variant),
)*
_ => {
warn!("Invalid flag value: {value}");
None
}
}
}
}
};
}
// Use the macro to generate the Flag enum and its methods
// Source: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
generate_flag_enum! {
Argentina => "ar",
Australia => "au",
Austria => "at",
Belgium => "be",
Bolivia => "bo",
Brazil => "br",
Bulgaria => "bg",
Canada => "ca",
Chile => "cl",
China => "cn",
Colombia => "co",
CostaRica => "cr",
Czechia => "cz",
Denmark => "dk",
DominicanRepublic => "do",
Ecuador => "ec",
ElSalvador =>"sv",
Finland => "fi",
France => "fr",
Germany => "de",
GreatBritain => "gb",
Greece => "gr",
Honduras => "hn",
Hungary => "hu",
India => "in",
Italy => "it",
Japan => "jp",
Lithuania => "lt",
Mexico => "mx",
Netherlands => "nl",
Panama => "pa",
Paraguay => "py",
Peru => "pe",
Philippines => "ph",
Poland => "pl",
Portugal => "pt",
Romania => "ro",
Russia => "ru",
SaudiArabia => "sa",
Slovakia => "sk",
SouthKorea => "kr",
Spain => "es",
Sweden => "se",
Switzerland => "ch",
Thailand => "th",
Turkey => "tr",
Ukraine => "ua",
UnitedArabEmirates => "ae",
UnitedStates => "us",
Uruguay => "uy",
Venezuela => "ve",
Vietnam => "vn"
}