-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
logic.php
3941 lines (3370 loc) · 123 KB
/
logic.php
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
<?php
/**
* Quest access check.
* @param $update
* @param $data
* @return bool
*/
function quest_access_check($update, $data, $permission, $return_result = false)
{
// Default: Deny access to quests
$quest_access = false;
// Build query.
$rs = my_query(
"
SELECT user_id
FROM quests
WHERE id = {$data['id']}
"
);
$quest = $rs->fetch_assoc();
// Check permissions
if ($update['callback_query']['from']['id'] != $quest['user_id']) {
// Check "-all" permission
$permission = $permission . '-all';
$quest_access = bot_access_check($update, $permission, $return_result);
} else {
// Check "-own" permission
$permission = $permission . '-own';
$quest_access = bot_access_check($update, $permission, $return_result);
}
// Return result
return $quest_access;
}
/**
* Quest duplication check.
* @param $pokestop_id
* @return array
*/
function quest_duplication_check($pokestop_id)
{
// Check if quest already exists for this pokestop.
// Exclude unnamed pokestops with pokestop_id 0.
$rs = my_query(
"
SELECT id, pokestop_id
FROM quests
WHERE quest_date > UTC_DATE()
AND quest_date < UTC_DATE() + INTERVAL 1 DAY
AND pokestop_id > 0
AND pokestop_id = {$pokestop_id}
"
);
// Get the row.
$quest = $rs->fetch_assoc();
debug_log($quest);
return $quest;
}
/**
* Invasion access check.
* @param $update
* @param $data
* @return bool
*/
function invasion_access_check($update, $data, $permission, $return_result = false)
{
// Default: Deny access to invasions
$quest_access = false;
// Build query.
$rs = my_query(
"
SELECT user_id
FROM invasions
WHERE id = {$data['id']}
"
);
$invasion = $rs->fetch_assoc();
// Check permissions
if ($update['callback_query']['from']['id'] != $invasion['user_id']) {
// Check "-all" permission
$permission = $permission . '-all';
$invasion_access = bot_access_check($update, $permission, $return_result);
} else {
// Check "-own" permission
$permission = $permission . '-own';
$invasion_access = bot_access_check($update, $permission, $return_result);
}
// Return result
return $invasion_access;
}
/**
* Invasion duplication check.
* @param $pokestop_id
* @return array
*/
function invasion_duplication_check($pokestop_id)
{
// Check if invasion already exists for this pokestop.
// Exclude unnamed pokestops with pokestop_id 0.
$rs = my_query(
"
SELECT id, pokestop_id
FROM invasions
WHERE end_time > UTC_TIMESTAMP()
AND pokestop_id > 0
AND pokestop_id = {$pokestop_id}
"
);
// Get the row.
$invasion = $rs->fetch_assoc();
debug_log($invasion);
return $invasion;
}
/**
* Get invasion.
* @param $invasion_id
* @return array
*/
function get_invasion($invasion_id)
{
// Get the invasion data by id.
$rs = my_query(
"
SELECT invasions.*,
users.name,
pokestops.pokestop_name, pokestops.lat, pokestops.lon, pokestops.address
FROM invasions
LEFT JOIN users
ON invasions.user_id = users.user_id
LEFT JOIN pokestops
ON invasions.pokestop_id = pokestops.id
WHERE invasions.id = {$invasion_id}
"
);
// Get the row.
$invasion = $rs->fetch_assoc();
debug_log($invasion);
return $invasion;
}
/**
* Get invasion as formatted string.
* @param $invasion array
* @param $add_creator bool
* @param $add_timestamp bool
* @param $compact_format bool
* @param $override_language bool
* @param $inline_format bool
* @return array
*/
function get_formatted_invasion($invasion, $add_creator = false, $add_timestamp = false, $compact_format = false, $override_language = false, $inline_format = false)
{
/** Example:
* Invasion: 13:05 to approx. 13:35
* Pokestop: Reward-Stop Number 1
* Invasion-Street 5, 13579 Poke-City
* Info: Snorlax (Snorlax, Snorlax and Dragonite battle)
*/
global $config;
// Get translation type
if($override_language == true) {
$getTypeTranslation = 'getPublicTranslation';
} else {
$getTypeTranslation = 'getTranslation';
}
// Pokestop name and address.
$pokestop_name = '<b>' . (!empty($invasion['pokestop_name']) ? ($invasion['pokestop_name']) : ($getTypeTranslation('unnamed_pokestop'))) . '</b>' . CR;
// Get pokestop info.
$stop = get_pokestop($invasion['pokestop_id']);
// Add google maps link.
if(!empty($stop['address'])) {
$pokestop_address = '<a href="https://maps.google.com/?daddr=' . $stop['lat'] . ',' . $stop['lon'] . '">' . $stop['address'] . '</a>';
} else if(!empty($invasion['address'])) {
$pokestop_address = '<a href="https://maps.google.com/?daddr=' . $invasion['lat'] . ',' . $invasion['lon'] . '">' . $invasion['address'] . '</a>';
} else {
$pokestop_address = '<a href="http://maps.google.com/maps?q=' . $invasion['lat'] . ',' . $invasion['lon'] . '">http://maps.google.com/maps?q=' . $invasion['lat'] . ',' . $invasion['lon'] . '</a>';
}
// Build invasion message
$msg = '';
if($compact_format == false) {
$msg .= '<b>' . $getTypeTranslation('invasion') . SP . dt2time($invasion['start_time']) . SP . $getTypeTranslation('until_approx') . SP . dt2time($invasion['end_time']) . '</b>' . CR;
$msg .= $getTypeTranslation('pokestop') . ': ' . $pokestop_name . $pokestop_address;
} else if ($inline_format == true) {
$msg .= dt2time($invasion['start_time']) . SP . $getTypeTranslation('until_approx') . SP . dt2time($invasion['end_time']);
} else {
$msg .= dt2time($invasion['start_time']) . SP . $getTypeTranslation('until_approx') . SP . dt2time($invasion['end_time']) . CR . $pokestop_name . $pokestop_address;
}
// Add comment to message.
if(!empty($invasion['comment'])) {
$msg .= CR . $getTypeTranslation('info') . ': ' . '<b>' . $invasion['comment'] . '</b>';
}
//Add custom message from the config.
if($compact_format == false && !empty($config->MAP_URL)) {
$msg .= CR . CR . $config->MAP_URL;
} else if($compact_format == false) {
$msg .= CR;
}
// Display creator.
$msg .= ($invasion['user_id'] && $add_creator == true) ? (CR . $getTypeTranslation('created_by') . ': <a href="tg://user?id=' . $invasion['user_id'] . '">' . htmlspecialchars($invasion['name']) . '</a>') : '';
// Add update time and invasion id to message.
if($add_timestamp == true) {
$msg .= CR . '<i>' . $getTypeTranslation('updated') . ': ' . dt2time('now', 'H:i:s') . '</i>';
// Commented without the little dirty hack:
//$msg .= ' ' . substr(strtoupper($config->BOT_ID), 0, 1) . '-ID = ' . $invasion['id']; // DO NOT REMOVE! --> NEEDED FOR $config->CLEANUP PREPARATION!
// Dirty hack: Make invasion ID negative, so we can differ from quest id.
$msg .= ' ' . substr(strtoupper($config->BOT_ID), 0, 1) . '-ID = -' . $invasion['id']; // DO NOT REMOVE! --> NEEDED FOR $config->CLEANUP PREPARATION!
}
return $msg;
}
/**
* Get current invasions as formatted string.
* @return string
*/
function get_current_formatted_invasions()
{
// Get the invasion data by id.
$rs = my_query(
"
SELECT id
FROM invasions
WHERE end_time > UTC_TIMESTAMP()
"
);
// Init empty message and counter.
$msg = '';
$count = 0;
// Get the invasions.
while ($current_invasions = $rs->fetch_assoc()) {
$invasion = get_invasion($current_invasions['id']);
$msg .= CR . get_formatted_invasion($invasion, false, false, true, false);
$msg .= CR;
$count = $count + 1;
}
// No invasions currently?
if($count == 0) {
$msg = getTranslation('no_invasions_currently');
} else {
// Add update time to message.
$msg .= CR . '<i>' . getTranslation('updated') . ': ' . dt2time('now', 'H:i:s') . '</i>';
}
return $msg;
}
/**
* Delete invasion.
* @param $invasion_id
*/
function delete_invasion($invasion_id)
{
global $db;
// Delete telegram messages for invasion.
$rs = my_query(
"
SELECT *
FROM qleanup
WHERE quest_id = '-{$invasion_id}'
AND chat_id <> 0
"
);
// Counter
$counter = 0;
// Delete every telegram message
while ($row = $rs->fetch_assoc()) {
// Delete telegram message.
debug_log('Deleting telegram message ' . $row['message_id'] . ' from chat ' . $row['chat_id'] . ' for invasion ' . $row['quest_id']);
delete_message($row['chat_id'], $row['message_id']);
$counter = $counter + 1;
}
// Nothing to delete on telegram.
if ($counter == 0) {
debug_log('Invasion with ID ' . $invasion_id . ' was not found in the cleanup table! Skipping deletion of telegram messages!');
}
// Delete invasion from cleanup table.
debug_log('Deleting invasion ' . $invasion_id . ' from the cleanup table:');
$rs_cleanup = my_query(
"
DELETE FROM qleanup
WHERE quest_id = '-{$invasion_id}'
OR cleaned = '-{$invasion_id}'
"
);
// Delete invasion from invasions table.
debug_log('Deleting invasion ' . $invasion_id . ' from the invasions table:');
$rs_invasions = my_query(
"
DELETE FROM invasions
WHERE id = '{$invasion_id}'
"
);
}
/**
* Get local name of pokemon.
* @param $pokedex_id
* @param $override_language
* @return string
*/
function get_local_pokemon_name($pokedex_id, $override_language = false)
{
// Get translation type
if($override_language == true) {
$getTypeTranslation = 'getPublicTranslation';
} else {
$getTypeTranslation = 'getTranslation';
}
// Init pokemon name and get translation
$pokemon_name = '';
$pokemon_name = $getTypeTranslation('pokemon_id_' . $pokedex_id);
return $pokemon_name;
}
/**
* Get questlist entry.
* @param $questlist_id
* @return array
*/
function get_questlist_entry($questlist_id)
{
// Get the questlist entry by id.
$rs = my_query(
"
SELECT *
FROM questlist
WHERE id = {$questlist_id}
"
);
// Get the row.
$ql_entry = $rs->fetch_assoc();
debug_log($ql_entry);
return $ql_entry;
}
/**
* Get quest.
* @param $quest_id
* @return array
*/
function get_quest($quest_id)
{
// Get the quest data by id.
$rs = my_query(
"
SELECT quests.*,
users.name,
pokestops.pokestop_name, pokestops.lat, pokestops.lon, pokestops.address,
questlist.quest_event, questlist.quest_type, questlist.quest_quantity, questlist.quest_action, questlist.quest_pokedex_ids, questlist.quest_poketypes,
rewardlist.reward_type, rewardlist.reward_quantity,
encounterlist.pokedex_ids
FROM quests
LEFT JOIN users
ON quests.user_id = users.user_id
LEFT JOIN pokestops
ON quests.pokestop_id = pokestops.id
LEFT JOIN questlist
ON quests.quest_id = questlist.id
LEFT JOIN rewardlist
ON quests.reward_id = rewardlist.id
LEFT JOIN encounterlist
ON quests.quest_id = encounterlist.quest_id
WHERE quests.id = {$quest_id}
"
);
// Get the row.
$quest = $rs->fetch_assoc();
debug_log($quest);
return $quest;
}
/**
* Get formatted quest from questlist.
* @param quest_id
* @param hide_id
* @return string
*/
function get_formatted_questlist_entry($quest_id, $hide_id = false)
{
// Get quest from questlist.
$ql_entry = get_questlist_entry($quest_id);
// Init empty questlist message.
$msg_questlist = '';
// Build message.
$qty_action = get_quest_action($ql_entry);
if($hide_id == false) {
$msg_questlist .= '<b>ID: ' . $ql_entry['id'] . '</b> — ';
}
// Event?
if($ql_entry['quest_event'] > 0) {
$msg_questlist .= getTranslation('quest_event_'. $ql_entry['quest_event']) . ':' . SP . getTranslation('quest_type_'. $ql_entry['quest_type']) . SP . $qty_action;
} else {
$msg_questlist .= getTranslation('quest_type_'. $ql_entry['quest_type']) . SP . $qty_action;
}
return $msg_questlist;
}
/**
* Get all quests in questlist.
* @param hide_encounter
* @return string
*/
function get_all_questlist_entries($hide_encounter = false)
{
// Get all quests from questlist.
$rs = my_query(
"
SELECT *
FROM questlist
ORDER BY quest_event, id
"
);
// Init empty questlist message.
$msg_questlist = '';
// Build message.
while ($questlist = $rs->fetch_assoc()) {
// Hide quests with encounters if requested and found.
$el_entry = get_encounterlist_entry($questlist['id']);
if($hide_encounter == true && $el_entry) continue;
// Get quest action.
$qty_action = get_quest_action($questlist);
// Build questlist message.
$msg_questlist .= '<b>ID: ' . $questlist['id'] . '</b> — ';
// Event?
if($questlist['quest_event'] > 0) {
$msg_questlist .= '<b>' . getTranslation('quest_event_'. $questlist['quest_event']) . ':</b>' . SP . getTranslation('quest_type_'. $questlist['quest_type']) . SP . $qty_action . CR;
} else {
$msg_questlist .= getTranslation('quest_type_'. $questlist['quest_type']) . SP . $qty_action . CR;
}
}
return $msg_questlist;
}
/**
* Get keys for all quests in questlist.
* @param action
* @param arg
* @param hide_encounter
* @return array
*/
function get_all_questlist_keys($action, $arg, $hide_encounter = false)
{
// Get all quests from questlist.
$rs = my_query(
"
SELECT id
FROM questlist
ORDER BY quest_event, id
"
);
// Init empty keys array.
$keys = array();
// Add key for each quest
while ($ql_entry = $rs->fetch_assoc()) {
// Hide quests with encounters if requested and found.
$el_entry = get_encounterlist_entry($ql_entry['id']);
if($hide_encounter == true && $el_entry) continue;
$keys[] = array(
'text' => $ql_entry['id'],
'callback_data' => $ql_entry['id'] . ':' . $action . ':' . $arg
);
}
// Add quick selection keys.
$keys = inline_key_array($keys, 5);
//debug_log($keys);
return $keys;
}
/**
* Get all encounters in encounterlist.
* @return string
*/
function get_all_encounterlist_entries()
{
// Get all encounters from encounterlist.
$rs = my_query(
"
SELECT *
FROM encounterlist
"
);
// Init empty encounterlist message.
$msg_enclist = '';
// Build message.
while ($enclist = $rs->fetch_assoc()) {
// Get quest.
$msg_quest = get_formatted_questlist_entry($enclist['quest_id'], true);
// Get encounters
$quest_pokemons = explode(',', $enclist['pokedex_ids']);
// Get local pokemon name
$msg_poke = '';
foreach($quest_pokemons as $pokedex_id) {
$msg_poke .= get_local_pokemon_name($pokedex_id);
$msg_poke .= ' / ';
}
// Trim last slash
$msg_poke = rtrim($msg_poke,' / ');
// Build encounterlist message.
$msg_enclist .= '<b>ID: ' . $enclist['id'] . '</b> — ';
$msg_enclist .= $msg_quest;
$msg_enclist .= SP . '(<b>' . $msg_poke . '</b>)' . CR;
}
return $msg_enclist;
}
/**
* Get formatted encounter from encounterlist.
* @param encounter_id
* @param hide_id
* @param hide_quest
* @return string
*/
function get_formatted_encounterlist_entry($encounter_id, $hide_id = false, $hide_quest = false)
{
// Get encounters from encounterlist.
$rs = my_query(
"
SELECT *
FROM encounterlist
WHERE id = '{$encounter_id}'
"
);
// Init empty encounterlist message.
$msg_enclist = '';
// Build message.
while ($enclist = $rs->fetch_assoc()) {
// Get quest.
$msg_quest = get_formatted_questlist_entry($enclist['quest_id'], true);
// Get encounters
$quest_pokemons = explode(',', $enclist['pokedex_ids']);
// Get local pokemon name
$msg_poke = '';
foreach($quest_pokemons as $pokedex_id) {
$msg_poke .= get_local_pokemon_name($pokedex_id);
$msg_poke .= ' / ';
}
// Trim last slash
$msg_poke = rtrim($msg_poke,' / ');
// Build encounterlist message.
if($hide_id != true) {
$msg_enclist .= '<b>ID: ' . $enclist['id'] . '</b> — ';
}
if($hide_quest != true) {
$msg_enclist .= $msg_quest;
$msg_enclist .= SP . '(<b>' . $msg_poke . '</b>)' . CR;
} else {
$msg_enclist .= '<b>' . $msg_poke . '</b>' . CR;
}
}
return $msg_enclist;
}
/**
* Get keys for all encounters in encounterlist.
* @param $action
* @param $arg
* @return array
*/
function get_all_encounterlist_keys($action, $arg)
{
global $config;
// Get all encounters from encounterlist.
$rs = my_query(
"
SELECT id
FROM encounterlist
"
);
// Init empty keys array.
$keys = array();
// Add key for each encounters
while ($enc_entry = $rs->fetch_assoc()) {
$keys[] = array(
'text' => $enc_entry['id'],
'callback_data' => $enc_entry['id'] . ':' . $action . ':' . $arg
);
}
// Set keys.
$keys = inline_key_array($keys, 5);
//debug_log($keys);
return $keys;
}
/**
* Get all rewards in rewardlist.
* @param $skip
* @param $show_hidden
* @param $quest_id
* @param $w_column
* @param $w_operator
* @param $w_value
* @return string
*/
function get_all_rewardlist_entries($skip = false, $show_hidden = true, $quest_id = 0, $w_column = 'id', $w_operator = '>', $w_value = 0)
{
// Build WHERE.
$where = $w_column . SP . $w_operator . SP . $w_value;
// Get all rewards.
$rs = my_query(
"
SELECT id, reward_type
FROM rewardlist
WHERE $where
"
);
// Init empty message.
$msg_rewardlist = '';
// Hidden rewards
$hide_rewards = array();
$hide_rewards = ($config->QUEST_HIDE_REWARDS == true && !empty($config->QUEST_HIDDEN_REWARDS)) ? (explode(',', $config->QUEST_HIDDEN_REWARDS)) : '';
// Build message.
while ($rewardlist = $rs->fetch_assoc()) {
// Skip reward pokemon to avoid deletion.
if($skip == true && $rewardlist['id'] == 1) continue;
// Skip hidden rewards.
if($show_hidden == false && $config->QUEST_HIDE_REWARDS && in_array($rewardlist['reward_type'], $hide_rewards)) continue;
// Build message.
$msg_rewardlist .= get_formatted_rewardlist_entry($rewardlist['id'], $quest_id) . CR;
}
return $msg_rewardlist;
}
/**
* Get formatted reward from rewardlist.
* @param reward_id
* @param quest_id
* @param hide_id
* @return string
*/
function get_formatted_rewardlist_entry($reward_id, $quest_id = 0, $hide_id = false)
{
// Get reward from rewardlist.
$rl_entry = get_rewardlist_entry($reward_id);
// Init empty rewardlist message.
$msg_rewardlist = '';
// No reward forecast.
//if($quest_id > 0) {
if($quest_id == 0) {
// Reward type: Singular or plural?
$reward_type = explode(":", getTranslation('reward_type_' . $rl_entry['reward_type']));
$reward_type_singular = $reward_type[0];
$reward_type_plural = $reward_type[1];
$qty_reward = $rl_entry['reward_quantity'] . SP . (($rl_entry['reward_quantity'] > 1) ? ($reward_type_plural) : ($reward_type_singular));
// Build message.
if($hide_id == false) {
$msg_rewardlist .= '<b>ID: ' . $rl_entry['id'] . '</b> — ';
}
$msg_rewardlist .= $qty_reward;
// Get reward pokemon forecast.
} else {
$ql_entry = get_questlist_entry($quest_id);
// Rewardlist entry.
$rl_entry = get_rewardlist_entry($reward_id);
// Reward type: Singular or plural?
$reward_type = explode(":", getTranslation('reward_type_' . $rl_entry['reward_type']));
$reward_type_singular = $reward_type[0];
$reward_type_plural = $reward_type[1];
$qty_reward = $rl_entry['reward_quantity'] . SP . (($rl_entry['reward_quantity'] > 1) ? ($reward_type_plural) : ($reward_type_singular));
// Reward pokemon forecast?
$msg_poke = '';
if($rl_entry['reward_type'] == 1) {
$el_entry = get_encounterlist_entry($ql_entry['id']);
$quest_pokemons = explode(',', $el_entry['pokedex_ids']);
// Get local pokemon name
foreach($quest_pokemons as $pokedex_id) {
$msg_poke .= get_local_pokemon_name($pokedex_id);
$msg_poke .= ' / ';
}
// Trim last slash
$msg_poke = rtrim($msg_poke,' / ');
$msg_poke = (!empty($msg_poke) ? $msg_poke : '');
}
// Forecast reward text.
if($hide_id == false) {
$msg_rewardlist .= '<b>ID: ' . $rl_entry['id'] . '</b> — ';
}
$msg_rewardlist .= (!empty($msg_poke) ? $msg_poke : $qty_reward);
}
return $msg_rewardlist;
}
/**
* Get keys for all rewards in rewardlist.
* @param $action
* @param $arg
* @param $skip
* @param $show_hidden
* @return array
*/
function get_all_rewardlist_keys($action, $arg, $skip = false, $show_hidden = true)
{
global $config;
// Get all rewards from rewardlist.
$rs = my_query(
"
SELECT id, reward_type
FROM rewardlist
"
);
// Init empty keys array.
$keys = array();
// Hidden rewards
$hide_rewards = array();
$hide_rewards = ($config->QUEST_HIDE_REWARDS && !empty($config->QUEST_HIDDEN_REWARDS)) ? (explode(',', $config->QUEST_HIDDEN_REWARDS)) : '';
// Add key for each reward
while ($rl_entry = $rs->fetch_assoc()) {
// Skip reward pokemon to avoid deletion.
if($skip == true && $rl_entry['id'] == 1) continue;
// Skip hidden rewards.
if($show_hidden == false && $config->QUEST_HIDE_REWARDS && in_array($rl_entry['reward_type'], $hide_rewards)) continue;
// Add keys.
$keys[] = array(
'text' => $rl_entry['id'],
'callback_data' => $rl_entry['id'] . ':' . $action . ':' . $arg
);
}
// Add quick selection keys.
$keys = inline_key_array($keys, 5);
//debug_log($keys);
return $keys;
}
/**
* Get keys for all entries in quicklist.
* @param action
* @param arg
* @param id_type
* @return array
*/
function get_all_quicklist_keys($action, $arg, $id_type = 'quest_id')
{
// Get all entries from quicklist.
$rs = my_query(
"
SELECT id, quest_id
FROM quick_questlist
"
);
// Init empty keys array.
$keys = array();
// Get id type for keys text.
if($id_type != 'quest_id') {
$id_value = 'id';
} else {
$id_value = 'quest_id';
}
// Add key for each quicklist entry
while ($ql_entry = $rs->fetch_assoc()) {
$keys[] = array(
'text' => $ql_entry[$id_value],
'callback_data' => $ql_entry['id'] . ':' . $action . ':' . $arg
);
}
// Add quick selection keys.
$keys = inline_key_array($keys, 5);
//debug_log($keys);
return $keys;
}
/**
* Get all entries in quicklist.
* @param reward
* @param hide_id
* @param show_qq_id
* @return string
*/
function get_all_quicklist_entries($reward = false, $hide_id = false, $show_qq_id = false)
{
// Get all quicklist entries.
$rs = my_query(
"
SELECT *
FROM quick_questlist
"
);
// Init empty message.
$msg_quicklist = '';
// Build message.
while ($quicklist = $rs->fetch_assoc()) {
// Show quick questlist id.
if($show_qq_id == true) {
$msg_quicklist .= '<b>ID: ' . $quicklist['id'] . '</b> — ';
}
$msg_quicklist .= get_formatted_questlist_entry($quicklist['quest_id'], $hide_id);
// Get reward.
if($reward == true) {
$msg_quicklist .= SP . ' (' . get_formatted_rewardlist_entry($quicklist['reward_id'], $quicklist['quest_id'], true) . ')' . CR;
} else {
$msg_quicklist .= CR;
}
}
return $msg_quicklist;
}
/**
* Get quicklist entry.
* @param $quicklist_id
* @return array
*/
function get_quicklist_entry($quicklist_id)
{
// Get the quicklist entry by id.
$rs = my_query(
"
SELECT *
FROM quick_questlist
WHERE id = {$quicklist_id}
"
);
// Get the row.
$ql_entry = $rs->fetch_assoc();
debug_log($ql_entry);
return $ql_entry;
}
/**
* Get quest action.
* @param $quest
* @param $override_language
* @return string
*/
function get_quest_action($quest, $override_language = false)
{
// Get translation type
if($override_language == true) {
$getTypeTranslation = 'getPublicTranslation';
} else {
$getTypeTranslation = 'getTranslation';
}
// Init Quantity Action Var.
$qty_action = '';
// Quest action - Translation?
if($quest['quest_action'] != '0') {
// Quest action: Singular or plural?
$quest_action = explode(":", $getTypeTranslation('quest_action_' . $quest['quest_action']));
$quest_action_singular = $quest_action[0];
$quest_action_plural = $quest_action[1];
$qty_action = $quest['quest_quantity'] . SP . (($quest['quest_quantity'] > 1) ? ($quest_action_plural) : ($quest_action_singular));
// Quest action - Pokemons?
} else if($quest['quest_pokedex_ids'] != '0') {
// Init pokemon names.
$poke_names = '';
$quest_pokemons = explode(',', $quest['quest_pokedex_ids']);
// Get local pokemon names.
foreach($quest_pokemons as $pokedex_id) {
$poke_names .= get_local_pokemon_name($pokedex_id, $override_language);
$poke_names .= ', ';
}
// Trim last comma
$comma = ', ';
$poke_names = rtrim($poke_names,$comma);
// Get position of last comma and replace it with 'or' in case of multiple Pokemon names
$pos = strrpos($poke_names, $comma);
if($pos !== false)
{
$poke_names = substr_replace($poke_names, SP . $getTypeTranslation('or') . SP, $pos, strlen($comma));
}
$qty_action = $quest['quest_quantity'] . SP . (!empty($poke_names) ? $poke_names : '');
// Quest action - Pokemon Types?
} else if($quest['quest_poketypes'] != '0') {
// Init pokemon types.
$poke_types = '';
$quest_poketypes = explode(',', $quest['quest_poketypes']);
// Get local pokemon names.
foreach($quest_poketypes as $poketype_id) {
$poke_types .= $getTypeTranslation('pokemon_type_' . $poketype_id);
$poke_types .= ', ';
}
// Trim last comma
$comma = ', ';
$poke_types = rtrim($poke_types,$comma);