-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQuests.cs
More file actions
3440 lines (3042 loc) · 157 KB
/
Quests.cs
File metadata and controls
3440 lines (3042 loc) · 157 KB
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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
// ToDo: ZLevels integration (waiting for ZLevels api implementation)
// ToDo: Add Cooldown option for Delivery
namespace Oxide.Plugins
{
[Info("Quests", "Gonzi", "2.4.2")]
[Description("Creates quests for players to go on to earn rewards, complete with a GUI menu")]
public class Quests : RustPlugin
{
#region Fields
[PluginReference] Plugin HumanNPC;
[PluginReference] Plugin ServerRewards;
[PluginReference] Plugin Economics;
[PluginReference] Plugin LustyMap;
[PluginReference] Plugin EventManager;
[PluginReference] Plugin HuntRPG;
[PluginReference] Plugin PlayerChallenges;
[PluginReference] Plugin BetterChat;
ConfigData configData;
QuestData questData;
PlayerData playerData;
NPCData vendors;
ItemNames itemNames;
private DynamicConfigFile Quest_Data;
private DynamicConfigFile Player_Data;
private DynamicConfigFile Quest_Vendors;
private DynamicConfigFile Item_Names;
private Dictionary<ulong, PlayerQuestData> PlayerProgress;
private Dictionary<QuestType, Dictionary<string, QuestEntry>> Quest;
private Dictionary<string, ItemDefinition> ItemDefs;
private Dictionary<string, string> DisplayNames = new Dictionary<string, string>();
private Dictionary<ulong, QuestCreator> ActiveCreations = new Dictionary<ulong, QuestCreator>();
private Dictionary<ulong, QuestCreator> ActiveEditors = new Dictionary<ulong, QuestCreator>();
private Dictionary<ulong, bool> AddVendor = new Dictionary<ulong, bool>();
private Dictionary<QuestType, List<string>> AllObjectives = new Dictionary<QuestType, List<string>>();
private Dictionary<uint, Dictionary<ulong, int>> HeliAttackers = new Dictionary<uint, Dictionary<ulong, int>>();
private Dictionary<ulong, List<string>> OpenUI = new Dictionary<ulong, List<string>>();
private Dictionary<uint, ulong> Looters = new Dictionary<uint, ulong>();
private List<ulong> StatsMenu = new List<ulong>();
private List<ulong> OpenMenuBind = new List<ulong>();
static string UIMain = "UIMain";
static string UIPanel = "UIPanel";
static string UIEntry = "UIEntry";
static string permission_manage = "quests.manage";
static string permission_use = "quests.use";
private string textPrimary;
private string textSecondary;
#endregion
#region Classes
class PlayerQuestData
{
public Dictionary<string, PlayerQuestInfo> Quests = new Dictionary<string, PlayerQuestInfo>();
public List<QuestInfo> RequiredItems = new List<QuestInfo>();
public ActiveDelivery CurrentDelivery = new ActiveDelivery();
}
class PlayerQuestInfo
{
public QuestStatus Status;
public QuestType Type;
public int AmountCollected = 0;
public bool RewardClaimed = false;
public double ResetTime = 0;
}
class QuestEntry
{
public string QuestName;
public string Description;
public string Objective;
public string ObjectiveName;
public int AmountRequired;
public int Cooldown;
public bool ItemDeduction;
public List<RewardItem> Rewards;
}
class NPCInfo
{
public float x;
public float z;
public string ID;
public string Name;
}
class DeliveryInfo
{
public string Description;
public NPCInfo Info;
public RewardItem Reward;
public float Multiplier;
}
class ActiveDelivery
{
public string VendorID;
public string TargetID;
public float Distance;
}
class QuestInfo
{
public string ShortName;
public QuestType Type;
}
class RewardItem
{
public bool isRP = false;
public bool isCoins = false;
public bool isHuntXP = false;
public string DisplayName;
public string ShortName;
public int ID;
public float Amount;
public bool BP;
public ulong Skin;
}
class QuestCreator
{
public QuestType type;
public QuestEntry entry;
public DeliveryInfo deliveryInfo;
public RewardItem item;
public string oldEntry;
public int partNum;
}
class ItemNames
{
public Dictionary<string, string> DisplayNames = new Dictionary<string, string>();
}
enum QuestType
{
Kill,
Craft,
Gather,
Loot,
Delivery
}
enum QuestStatus
{
Pending,
Completed,
Open
}
#endregion
#region UI Creation
class QUI
{
public static bool disableFade;
static public CuiElementContainer CreateElementContainer(string panelName, string color, string aMin, string aMax, bool cursor = false)
{
var NewElement = new CuiElementContainer()
{
{
new CuiPanel
{
Image = {Color = color},
RectTransform = {AnchorMin = aMin, AnchorMax = aMax},
CursorEnabled = cursor
},
new CuiElement().Parent = "Overlay",
panelName
}
};
return NewElement;
}
static public void CreatePanel(ref CuiElementContainer container, string panel, string color, string aMin, string aMax, bool cursor = false)
{
container.Add(new CuiPanel
{
Image = { Color = color },
RectTransform = { AnchorMin = aMin, AnchorMax = aMax },
CursorEnabled = cursor
},
panel);
}
static public void CreateLabel(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter, float fadein = 1.0f)
{
if (disableFade)
fadein = 0;
container.Add(new CuiLabel
{
Text = { Color = color, FontSize = size, Align = align, FadeIn = fadein, Text = text },
RectTransform = { AnchorMin = aMin, AnchorMax = aMax }
},
panel);
}
static public void CreateButton(ref CuiElementContainer container, string panel, string color, string text, int size, string aMin, string aMax, string command, TextAnchor align = TextAnchor.MiddleCenter, float fadein = 1.0f)
{
if (disableFade)
fadein = 0;
container.Add(new CuiButton
{
Button = { Color = color, Command = command, FadeIn = fadein },
RectTransform = { AnchorMin = aMin, AnchorMax = aMax },
Text = { Text = text, FontSize = size, Align = align }
},
panel);
}
static public void LoadImage(ref CuiElementContainer container, string panel, string png, string aMin, string aMax)
{
container.Add(new CuiElement
{
Parent = panel,
Components =
{
new CuiRawImageComponent {Png = png},
new CuiRectTransformComponent {AnchorMin = aMin, AnchorMax = aMax}
}
});
}
static public void CreateTextOverlay(ref CuiElementContainer container, string panel, string text, string color, int size, string aMin, string aMax, TextAnchor align = TextAnchor.MiddleCenter, float fadein = 1.0f)
{
if (disableFade)
fadein = 0;
container.Add(new CuiLabel
{
Text = { Color = color, FontSize = size, Align = align, FadeIn = fadein, Text = text },
RectTransform = { AnchorMin = aMin, AnchorMax = aMax }
},
panel);
}
static public string Color(string hexColor, float alpha)
{
if (hexColor.StartsWith("#"))
hexColor = hexColor.TrimStart('#');
int red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
int green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
int blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
return $"{(double)red / 255} {(double)green / 255} {(double)blue / 255} {alpha}";
}
}
#endregion
#region Oxide Hooks
void Loaded()
{
permission.RegisterPermission(permission_use, this);
permission.RegisterPermission(permission_manage, this);
Quest_Data = Interface.Oxide.DataFileSystem.GetFile("Quests/quests_data");
Player_Data = Interface.Oxide.DataFileSystem.GetFile("Quests/quests_players");
Quest_Vendors = Interface.Oxide.DataFileSystem.GetFile("Quests/quests_vendors");
Item_Names = Interface.Oxide.DataFileSystem.GetFile("Quests/quests_itemnames");
lang.RegisterMessages(Localization, this);
}
void OnServerInitialized()
{
LoadVariables();
LoadData();
QUI.disableFade = configData.DisableUI_FadeIn;
textPrimary = $"<color={configData.Colors.TextColor_Primary}>";
textSecondary = $"<color={configData.Colors.TextColor_Secondary}>";
ItemDefs = ItemManager.itemList.ToDictionary(i => i.shortname);
FillObjectiveList();
AddMapIcons();
timer.Once(900, () => SaveLoop());
}
void Unload()
{
foreach (var player in BasePlayer.activePlayerList)
DestroyUI(player);
SavePlayerData();
}
void OnPlayerConnected(BasePlayer player)
{
if (configData.KeybindOptions.Autoset_KeyBind)
{
if (!string.IsNullOrEmpty(configData.KeybindOptions.KeyBind_Key))
{
player.Command("bind " + configData.KeybindOptions.KeyBind_Key + " QUI_OpenQuestMenu");
}
}
}
#region Objective Hooks
//Kill
void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
{
try
{
if (entity == null || info == null) return;
string entname = entity?.ShortPrefabName;
if (entname == "testridablehorse")
{
entname = "horse";
}
if ((entname.Contains("scientist")) && (!entname.Contains("corpse")))
{
entname = "scientist";
}
BasePlayer player = null;
if (info.InitiatorPlayer != null)
player = info.InitiatorPlayer;
else if (entity.GetComponent<BaseHelicopter>() != null)
player = BasePlayer.FindByID(GetLastAttacker(entity.net.ID));
if (player != null)
{
if (entity.ToPlayer() != null && entity.ToPlayer() == player) return;
if (isPlaying(player)) return;
if (hasQuests(player.userID) && isQuestItem(player.userID, entname, QuestType.Kill))
ProcessProgress(player, QuestType.Kill, entname);
}
}
catch (Exception ex)
{
PrintWarning("Error at hook OnEntityDeath:\n" + ex);
}
}
void OnEntityTakeDamage(BaseCombatEntity victim, HitInfo info)
{
if (victim.GetComponent<BaseHelicopter>() != null && info?.Initiator?.ToPlayer() != null)
{
var heli = victim.GetComponent<BaseHelicopter>();
var player = info.Initiator.ToPlayer();
if (isPlaying(player)) return;
NextTick(() =>
{
if (heli == null) return;
if (!HeliAttackers.ContainsKey(heli.net.ID))
HeliAttackers.Add(heli.net.ID, new Dictionary<ulong, int>());
if (!HeliAttackers[heli.net.ID].ContainsKey(player.userID))
HeliAttackers[heli.net.ID].Add(player.userID, 0);
HeliAttackers[heli.net.ID][player.userID]++;
});
}
}
// Gather
void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item)
{
BasePlayer player = entity?.ToPlayer();
if (player != null)
if (hasQuests(player.userID) && isQuestItem(player.userID, item.info.shortname, QuestType.Gather))
ProcessProgress(player, QuestType.Gather, item.info.shortname, item.amount);
}
void OnDispenserBonus(ResourceDispenser dispenser, BaseEntity entity, Item item) => OnDispenserGather(dispenser, entity, item);
void OnGrowableGather(GrowableEntity growable, Item item, BasePlayer player)
{
if (player != null)
if (hasQuests(player.userID) && isQuestItem(player.userID, item.info.shortname, QuestType.Gather))
ProcessProgress(player, QuestType.Gather, item.info.shortname, item.amount);
}
void OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player)
{
if (player != null)
foreach (ItemAmount itemAmount in collectible.itemList)
if (hasQuests(player.userID) && isQuestItem(player.userID, itemAmount.itemDef.shortname, QuestType.Gather))
ProcessProgress(player, QuestType.Gather, itemAmount.itemDef.shortname, (int)itemAmount.amount);
}
//Craft
void OnItemCraftFinished(ItemCraftTask task, Item item)
{
var player = task.owner;
if (player != null)
if (hasQuests(player.userID) && isQuestItem(player.userID, item.info.shortname, QuestType.Craft))
ProcessProgress(player, QuestType.Craft, item.info.shortname, item.amount);
}
//Loot
void OnItemAddedToContainer(ItemContainer container, Item item)
{
if (Looters.ContainsKey(item.uid))
{
if (container.playerOwner != null)
{
if (Looters[item.uid] != container.playerOwner.userID)
{
if (hasQuests(container.playerOwner.userID) && isQuestItem(container.playerOwner.userID, item.info.shortname, QuestType.Loot))
{
ProcessProgress(container.playerOwner, QuestType.Loot, item.info.shortname, item.amount);
Looters.Remove(item.uid);
}
}
}
}
else if (container.playerOwner != null) Looters.Add(item.uid, container.playerOwner.userID);
}
void OnItemRemovedFromContainer(ItemContainer container, Item item)
{
ulong id = 0U;
if (container.entityOwner != null)
id = container.entityOwner.OwnerID;
else if (container.playerOwner != null)
id = container.playerOwner.userID;
if (!Looters.ContainsKey(item.uid))
Looters.Add(item.uid, id);
}
// Delivery and Vendors
void OnUseNPC(BasePlayer npc, BasePlayer player)
{
if (player == null || npc == null) return;
CheckPlayerEntry(player);
var npcID = npc.UserIDString;
if (vendors.QuestVendors.ContainsKey(npcID) && configData.UseNPCVendors)
{
CreateMenu(player);
return;
}
if (vendors.DeliveryVendors.ContainsKey(npcID))
{
if (hasQuests(player.userID) && PlayerProgress[player.userID].CurrentDelivery.TargetID == npc.UserIDString)
AcceptDelivery(player, npcID, 1);
if (hasQuests(player.userID) && string.IsNullOrEmpty(PlayerProgress[player.userID].CurrentDelivery.TargetID))
AcceptDelivery(player, npcID);
else SendMSG(player, LA("delInprog", player.UserIDString), LA("Quests", player.UserIDString));
}
}
#endregion
object OnPlayerChat(BasePlayer player, string message)
{
if (BetterChat) return null;
if (player == null) return null;
if (ActiveEditors.ContainsKey(player.userID) || ActiveCreations.ContainsKey(player.userID) || AddVendor.ContainsKey(player.userID))
{
QuestChat(player, message.Split(' '));
return false;
}
return null;
}
object OnBetterChat(Dictionary<string, object> dict)
{
var player = (dict["Player"] as IPlayer).Object as BasePlayer;
if (player == null) return null;
string message = dict["Message"].ToString();
if (ActiveEditors.ContainsKey(player.userID) || ActiveCreations.ContainsKey(player.userID) || AddVendor.ContainsKey(player.userID))
{
QuestChat(player, message.Split(' '));
dict["CancelOption"] = 2;
return dict;
}
return dict;
}
void QuestChat(BasePlayer player, string[] arg)
{
bool isEditing = false;
bool isCreating = false;
QuestCreator Creator = new QuestCreator();
QuestEntry Quest = new QuestEntry();
// remove all html codes from the message (needed for colored chat messages)
System.Text.RegularExpressions.Regex rmHTML = new System.Text.RegularExpressions.Regex("<[^>]*>");
var args = rmHTML.Replace(string.Join(" ", arg), "");
var argsForNumbers = rmHTML.Replace(arg[0], "");
if (ActiveEditors.ContainsKey(player.userID))
{
isEditing = true;
Creator = ActiveEditors[player.userID];
Quest = Creator.entry;
}
else if (ActiveCreations.ContainsKey(player.userID))
{
isCreating = true;
Creator = ActiveCreations[player.userID];
Quest = Creator.entry;
}
if (AddVendor.ContainsKey(player.userID) && string.Join(" ", arg).Contains("exit"))
{
ExitQuest(player, true);
return;
}
if (!isEditing && !isCreating)
return;
if (args.Contains("exit"))
{
ExitQuest(player, isCreating);
return;
}
if (args.Contains("quest item"))
{
var item = GetItem(player);
if (item != null)
{
if (Creator.type != QuestType.Delivery)
{
Quest.Rewards.Add(item);
Creator.partNum++;
if (isCreating)
CreationHelp(player, 7);
else if (isEditing)
{
SaveRewardsEdit(player);
CreationHelp(player, 10);
}
}
else
{
Creator.deliveryInfo.Reward = item;
DeliveryHelp(player, 4);
}
}
else SendMSG(player, $"{LA("noAItem", player.UserIDString)}'quest item'", LA("QC", player.UserIDString));
return;
}
switch (Creator.partNum)
{
case 0:
foreach (var type in questData.Quest)
{
if (type.Value.ContainsKey(args))
{
SendMSG(player, LA("nameExists", player.UserIDString), LA("QC", player.UserIDString));
return;
}
}
Quest.QuestName = args;
SendMSG(player, args, "Name:");
Creator.partNum++;
if (isCreating)
CreationHelp(player, 1);
else CreationHelp(player, 6);
return;
case 2:
{
int amount;
if (!int.TryParse(argsForNumbers, out amount))
{
SendMSG(player, LA("objAmount", player.UserIDString), LA("QC", player.UserIDString));
return;
}
Quest.AmountRequired = amount;
SendMSG(player, argsForNumbers, LA("OA", player.UserIDString));
Creator.partNum++;
if (isCreating)
CreationHelp(player, 3);
else CreationHelp(player, 6);
}
return;
case 3:
{
if (Creator.type == QuestType.Delivery)
{
Creator.deliveryInfo.Description = args;
SendMSG(player, args, LA("Desc", player.UserIDString));
DeliveryHelp(player, 6);
return;
}
Quest.Description = args;
SendMSG(player, args, LA("Desc", player.UserIDString));
Creator.partNum++;
if (isCreating)
CreationHelp(player, 4);
else CreationHelp(player, 6);
}
return;
case 5:
{
if (Creator.type == QuestType.Delivery)
{
float amount;
if (!float.TryParse(argsForNumbers, out amount))
{
SendMSG(player, LA("noRM", player.UserIDString), LA("QC", player.UserIDString));
return;
}
Creator.deliveryInfo.Multiplier = amount;
SendMSG(player, argsForNumbers, LA("RM", player.UserIDString));
Creator.partNum++;
DeliveryHelp(player, 5);
}
else
{
int amount;
if (!int.TryParse(argsForNumbers, out amount))
{
SendMSG(player, LA("noRA", player.UserIDString), LA("QC", player.UserIDString));
return;
}
Creator.item.Amount = amount;
Quest.Rewards.Add(Creator.item);
Creator.item = new RewardItem();
SendMSG(player, argsForNumbers, LA("RA", player.UserIDString));
Creator.partNum++;
if (isCreating)
CreationHelp(player, 7);
else if (isEditing)
{
SaveRewardsEdit(player);
}
}
return;
}
case 6:
{
int amount;
if (!int.TryParse(argsForNumbers, out amount))
{
SendMSG(player, LA("noCD", player.UserIDString), LA("QC", player.UserIDString));
return;
}
Creator.entry.Cooldown = amount;
SendMSG(player, argsForNumbers, LA("CD1", player.UserIDString));
CreationHelp(player, 6);
}
return;
default:
break;
}
}
#endregion
#region External Calls
private bool isPlaying(BasePlayer player)
{
if (EventManager)
{
var inEvent = EventManager?.Call("isPlaying", player);
if (inEvent is bool && (bool)inEvent)
return true;
}
return false;
}
private void CloseMap(BasePlayer player)
{
if (LustyMap)
{
LustyMap.Call("DisableMaps", player);
}
}
private void OpenMap(BasePlayer player)
{
if (LustyMap)
{
LustyMap.Call("EnableMaps", player);
}
}
private void AddMapMarker(float x, float z, string name, string icon = "special", float r = 0)
{
if (LustyMap)
LustyMap.Call("AddMarker", x, z, name, icon);
}
private void RemoveMapMarker(string name)
{
if (LustyMap)
LustyMap.Call("RemoveMarker", name);
}
private object CanTeleport(BasePlayer player)
{
if (!PlayerProgress.ContainsKey(player.userID)) return null;
if (!string.IsNullOrEmpty(PlayerProgress[player.userID].CurrentDelivery.TargetID))
{
return LA("NoTP", player.UserIDString);
}
else
return null;
}
#endregion
#region Objective Lists
private void FillObjectiveList()
{
AllObjectives.Add(QuestType.Loot, new List<string>());
AllObjectives.Add(QuestType.Craft, new List<string>());
AllObjectives.Add(QuestType.Kill, new List<string>());
AllObjectives.Add(QuestType.Gather, new List<string>());
AllObjectives.Add(QuestType.Delivery, new List<string>());
GetAllCraftables();
GetAllItems();
GetAllKillables();
GetAllResources();
foreach (var category in AllObjectives)
category.Value.Sort();
if (itemNames.DisplayNames == null || itemNames.DisplayNames.Count < 1)
{
foreach (var item in ItemDefs)
{
if (!DisplayNames.ContainsKey(item.Key))
DisplayNames.Add(item.Key, item.Value.displayName.translated);
}
SaveDisplayNames();
}
else DisplayNames = itemNames.DisplayNames;
}
private void GetAllItems()
{
foreach (var item in ItemManager.itemList)
AllObjectives[QuestType.Loot].Add(item.shortname);
}
private void GetAllCraftables()
{
foreach (var bp in ItemManager.bpList)
if (bp.userCraftable)
AllObjectives[QuestType.Craft].Add(bp.targetItem.shortname);
}
private void GetAllResources()
{
AllObjectives[QuestType.Gather] = new List<string>
{
"wood",
"stones",
"metal.ore",
"hq.metal.ore",
"sulfur.ore",
"cloth",
"bone.fragments",
"crude.oil",
"fat.animal",
"leather",
"skull.wolf",
"skull.human",
"chicken.raw",
"mushroom",
"meat.boar",
"bearmeat",
"humanmeat.raw",
"wolfmeat.raw"
};
}
private void GetAllKillables()
{
AllObjectives[QuestType.Kill] = new List<string>
{
"bear",
"boar",
"bradleyapc",
"chicken",
"horse",
"stag",
"wolf",
"autoturret_deployed",
"patrolhelicopter",
"player",
"scientist",
"murderer",
"tunneldweller",
"underwaterdweller",
"scarecrow",
"simpleshark"
};
DisplayNames.Add("bear", "Bear");
DisplayNames.Add("boar", "Boar");
DisplayNames.Add("bradleyapc", "BradleyAPC");
DisplayNames.Add("chicken", "Chicken");
DisplayNames.Add("horse", "Horse");
DisplayNames.Add("stag", "Stag");
DisplayNames.Add("wolf", "Wolf");
DisplayNames.Add("autoturret_deployed", "Auto-Turret");
DisplayNames.Add("patrolhelicopter", "Helicopter");
DisplayNames.Add("player", "Player");
DisplayNames.Add("scientist", "Scientist");
DisplayNames.Add("murderer", "Murderer");
DisplayNames.Add("tunneldweller", "Tunneldweller");
DisplayNames.Add("underwaterdweller", "Underwater Dweller");
DisplayNames.Add("scarecrow", "Scarecrow");
DisplayNames.Add("simpleshark", "Shark");
}
#endregion
#region Functions
private bool isAdmin(BasePlayer player)
{
if (configData.UseOxidePermissions == true && permission.UserHasPermission(player.UserIDString, permission_manage) || player.IsAdmin && configData.UsePlayerIsAdmin == true) return true;
else return false;
}
void AddMapIcons()
{
int deliveryCount = 1;
foreach (var vendor in vendors.DeliveryVendors)
{
AddMapMarker(vendor.Value.Info.x, vendor.Value.Info.z, vendor.Value.Info.Name, $"{configData.LustyMapIntegration.Icon_Delivery}_{deliveryCount}.png");
++deliveryCount;
}
foreach (var vendor in vendors.QuestVendors)
{
AddMapMarker(vendor.Value.x, vendor.Value.z, vendor.Value.Name, $"{configData.LustyMapIntegration.Icon_Vendor}.png");
}
}
private void ProcessProgress(BasePlayer player, QuestType questType, string type, int amount = 0)
{
if (string.IsNullOrEmpty(type)) return;
var data = PlayerProgress[player.userID];
if (data.RequiredItems.Count > 0)
{
foreach (var entry in data.Quests.Where(x => x.Value.Status == QuestStatus.Pending))
{
var quest = GetQuest(entry.Key);
if (quest != null)
{
if (type == quest.Objective)
{
if (amount > 0)
{
var amountRequired = quest.AmountRequired - entry.Value.AmountCollected;
if (amount > amountRequired)
amount = amountRequired;
entry.Value.AmountCollected += amount;
if (quest.ItemDeduction)
TakeQuestItem(player, type, amount);
}
else entry.Value.AmountCollected++;
if (entry.Value.AmountCollected >= quest.AmountRequired)
CompleteQuest(player, entry.Key);
return;
}
}
}
}
}
private void TakeQuestItem(BasePlayer player, string item, int amount)
{
if (ItemDefs.ContainsKey(item))
{
var itemDef = ItemDefs[item];
NextTick(() => player.inventory.Take(null, itemDef.itemid, amount));
}
else PrintWarning($"Unable to find definition for: {item}.");
}
private void CompleteQuest(BasePlayer player, string questName)
{
var data = PlayerProgress[player.userID].Quests[questName];
var items = PlayerProgress[player.userID].RequiredItems;
var quest = GetQuest(questName);
if (quest != null)
{
data.Status = QuestStatus.Completed;
data.ResetTime = GrabCurrentTime() + (quest.Cooldown * 60);
for (int i = 0; i < items.Count; i++)
{
if (items[i].ShortName == quest.Objective && items[i].Type == data.Type)
{
items.Remove(items[i]);
break;
}
}
SendMSG(player, "", $"{LA("qComple", player.UserIDString)} {questName}. {LA("claRew", player.UserIDString)}");
PlayerChallenges?.Call("CompletedQuest", player);
}
}
private ItemDefinition FindItemDefinition(string shortname)
{
ItemDefinition itemDefinition;
return ItemDefs.TryGetValue(shortname, out itemDefinition) ? itemDefinition : null;
}
private string GetRewardString(List<RewardItem> entry)
{
var rewards = "";
int i = 1;
foreach (var item in entry)
{
rewards = rewards + $"{(int)item.Amount}x {item.DisplayName}";
if (i < entry.Count)
rewards = rewards + ", ";
i++;
}
return rewards;
}
private bool GiveReward(BasePlayer player, List<RewardItem> rewards)
{
foreach (var reward in rewards)
{
if (reward.isCoins && Economics)
{
Economics.Call("Deposit", player.UserIDString, (double)reward.Amount);
}
else if (reward.isRP && ServerRewards)
{
ServerRewards.Call("AddPoints", player.userID, (int)reward.Amount);
}
else if (reward.isHuntXP)
{
HuntRPG?.Call("GiveEXP", player, (int)reward.Amount);
}
else
{
if (string.IsNullOrEmpty(reward.ShortName)) return true;
var definition = FindItemDefinition(reward.ShortName);
if (definition != null)
{
if (player.inventory.AllItems().Count() >= 30) return false;
var item = ItemManager.Create(definition, (int)reward.Amount, reward.Skin);
if (item != null)
{
player.inventory.GiveItem(item, player.inventory.containerMain);
}
}
else PrintWarning($"Quests: Error building item {reward.ShortName} for {player.displayName}");
}
}
return true;
}
private void ReturnItems(BasePlayer player, string itemname, int amount)
{
if (amount > 0)