-
Notifications
You must be signed in to change notification settings - Fork 3
/
TaskSystem.cs
904 lines (818 loc) · 45.3 KB
/
TaskSystem.cs
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
using Microsoft.Xna.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.Localization;
using TerrariaApi.Server;
using TShockAPI;
namespace POBC.TaskSystem
{
namespace TaskSystem
{
[ApiVersion(2, 1)]
public class TaskSystem : TerrariaPlugin
{
/// <summary>
/// Gets the author(s) of this plugin
/// </summary>
public override string Author => "欲情";
/// <summary>
/// Gets the description of this plugin.
/// A short, one lined description that tells people what your plugin does.
/// </summary>
public override string Description => "POBC 任务系统";
/// <summary>
/// Gets the name of this plugin.
/// </summary>
public override string Name => "POBC.TaskSystem";
/// <summary>
/// Gets the version of this plugin.
/// </summary>
public override Version Version => new Version(1, 0, 0, 1);
public string ConfigPath { get { return Path.Combine(TShock.SavePath, "POBCTask.json"); } }
public TaskConfig MainTaskLists = new TaskConfig();
/// <summary>
/// Initializes a new instance of the TestPlugin class.
/// This is where you set the plugin's order and perfrom other constructor logic
/// </summary>
public TaskSystem(Main game) : base(game)
{
}
/// <summary>
/// Handles plugin initialization.
/// Fired when the server is started and the plugin is being loaded.
/// You may register hooks, perform loading procedures etc here.
/// </summary>
public override void Initialize()
{
File();
Db.Connect();
ServerApi.Hooks.GameInitialize.Register(this, OnInitialize);
ServerApi.Hooks.NpcKilled.Register(this, NpcKill);
}
private void NpcKill(NpcKilledEventArgs args)
{
if (args.npc.lastInteraction == 255) return;
if (Model.MainTaskLists.Count == 0) return;
if (Model.RegionalTaskLists.Count == 0) return;
var player = TShock.Players[args.npc.lastInteraction];
DBData dBData = new DBData();
if (Db.Queryuser(player.Name))
{
dBData = Db.QueryData(player.Name);
}
else return;
if (dBData.MianTaskUser == null & dBData.RegionalTaskUser ==null) return;
if (dBData.MianTaskUser!=null)
{
if (Model.MainTaskLists.Find(x => x.Name == dBData.MianTaskUser).Conditions.Any(x => x.TaskType == "2" ))
{
var task = Model.MainTaskLists.Find(x => x.Name == dBData.MianTaskUser).Conditions.Where(x => x.TaskType == "2").FirstOrDefault();
var Coordinate = task.Condition.Split(',');
if (Coordinate[0]==args.npc.netID.ToString())
{
dBData.MianTaskData += 1;
Db.UPData(dBData);
player.SendInfoMessage("[主线任务]你击杀了 " + args.npc.FullName + " ,已击杀" + dBData.MianTaskData + "个怪物,任务需要击杀" + Coordinate[1] + "个怪物");
}
}
}
if (dBData.RegionalTaskUser != null)
{
if (Model.RegionalTaskLists.Find(x => x.Name == dBData.RegionalTaskUser).Conditions.Any(x => x.TaskType == "2"))
{
var task = Model.RegionalTaskLists.Find(x => x.Name == dBData.RegionalTaskUser).Conditions.Where(x => x.TaskType == "2").FirstOrDefault();
var Coordinate = task.Condition.Split(',');
if (Coordinate[0] == args.npc.netID.ToString())
{
dBData.RegionalTaskData += 1;
Db.UPData(dBData);
player.SendInfoMessage("[支线任务]你击杀了 " + args.npc.FullName + " ,已击杀" + dBData.RegionalTaskData + "个怪物,任务需要击杀" + Coordinate[1] + "个怪物");
}
}
}
}
private void OnInitialize(EventArgs args)
{
Commands.ChatCommands.Add(new Command("TaskSystem.user", _TaskSystem, "task","任务") //测试完成
{
HelpText = " POBC 任务系统"
});
Commands.ChatCommands.Add(new Command("TaskSystem.user", _TaskSystemList, "tasklist","任务列表" ) //测试完成
{
HelpText = " POBC 任务系统 所有任务"
});
Commands.ChatCommands.Add(new Command("TaskSystem.user", _TaskSystemQuery, "taskquery", "查询任务") //测试完成
{
HelpText = " POBC 任务系统 通过id或任务名称 查询任务信息"
});
Commands.ChatCommands.Add(new Command("TaskSystem.user", _TaskSystemPick, "tasklist", "接受任务") //测试完成
{
HelpText = "接受任务时 随机5项任务选择1项 可以接受单个任务,为了提高任务的难度放弃任务和刷新可接受任务有CD时间 /n 主线任务默认接取"
});
Commands.ChatCommands.Add(new Command("TaskSystem.user", _TaskSystemf5, "taskf5", "刷新任务") //测试完成
{
HelpText = "刷新随机支线任务可接取列表,注意刷新时间冷却 .主线任务不可刷新"
});
Commands.ChatCommands.Add(new Command("TaskSystem.user", _TaskSystemGive, "taskgive", "放弃任务")
{
HelpText = "放弃任务时 ,为了提高任务的难度放弃任务和刷新可接受任务有CD时间 /n 主线任务不可放弃"
});
Commands.ChatCommands.Add(new Command("TaskSystem.user", _TaskSystemOver, "taskover", "完成任务")
{
HelpText = "完成任务 , 并获取奖励"
});
}
private void _TaskSystemQuery(CommandArgs args)
{
if (args.Parameters.Count < 1)
{
args.Player.SendErrorMessage("语法错误,正确语法: /查询任务 id或任务名称");
return;
}
var AllTask = Model.MainTaskLists.Concat(Model.RegionalTaskLists).ToList<_TaskList>();
var Task = AllTask.FirstOrDefault(x => x.Name == args.Parameters[0] || x.ID.ToString() == args.Parameters[0]);
if (Task == null)
{
args.Player.SendErrorMessage("没有找到任务");
return;
}
args.Player.SendInfoMessage("任务ID:" + Task.ID);
args.Player.SendInfoMessage("任务类型:" + Task.Type);
args.Player.SendInfoMessage("任务名称:" + Task.Name);
args.Player.SendInfoMessage("任务描述:" + Task.Info);
args.Player.SendInfoMessage("详细信息:" + Task.DetailedInfo);
// args.Player.SendInfoMessage("任务条件:" + Task.Conditions.ToString());
//args.Player.SendInfoMessage("任务奖励:" + Task.Reward);
}
private void _TaskSystemOver(CommandArgs args)
{
//完成任务
if (args.Parameters.Count < 1)
{
args.Player.SendErrorMessage("语法错误,正确语法:/完成任务 主线 (/完成任务 支线)");
return;
}
switch (args.Parameters[0])
{
case "主线":
{
if (Model.MainTaskLists.Count == 0)
{
args.Player.SendErrorMessage("没有主线任务");
return;
}
if (!Db.Queryuser(args.Player.Name))
{
args.Player.SendErrorMessage("没有接受的主线任务");
return;
}
if (Db.QueryData(args.Player.Name).MianTaskUser == null)
{
args.Player.SendErrorMessage("没有接受的主线任务");
return;
}
//获取主线任务
var _DBData = Db.QueryData(args.Player.Name);
var _MainTask = Model.MainTaskLists.Where(x => x.Name == _DBData.MianTaskUser).FirstOrDefault();
Tasklogic(args, _MainTask);
_DBData.MianTaskUser = null;
_DBData.MianTaskData = 0;
_DBData.MianTaskCompleted += 1;
Db.UPData(_DBData);
args.Player.SendErrorMessage("主线任务 完成 : 任务名" + _MainTask.Name + " ID:" + _MainTask.ID);
}
break;
case "支线":
{
if (Model.RegionalTaskLists.Count == 0)
{
args.Player.SendErrorMessage("没有支线任务");
return;
}
if (!Db.Queryuser(args.Player.Name))
{
args.Player.SendErrorMessage("没有接受的支线任务");
return;
}
if (Db.QueryData(args.Player.Name).RegionalTaskUser == null)
{
args.Player.SendErrorMessage("没有接受的支线任务");
return;
}
//获取支线任务
var _DBData = Db.QueryData(args.Player.Name);
var _RegionalTask = Model.RegionalTaskLists.Where(x => x.Name == Db.QueryData(args.Player.Name).RegionalTaskUser).FirstOrDefault();
if(Tasklogic(args, _RegionalTask))
{
_DBData.RegionalTaskUser = null;
_DBData.RegionalTaskData = 0;
_DBData.RegionalCompleted += 1;
Db.UPData(_DBData);
args.Player.SendErrorMessage("支线任务 完成 : 任务名" + _RegionalTask.Name + " ID:" + _RegionalTask.ID);
}
}
break;
}
}
//任务判定与任务类型 奖励给予等逻辑核心
private bool Tasklogic(CommandArgs args ,_TaskList Tasklist)
{
foreach (var item in Tasklist.Conditions)
{
switch (item.TaskType)
{
//任务类型0 消耗物品完成任务
case "0":
{
var _item = item.Condition.Split(',');
bool item_bool = false;
for (int i = 10; i < 49; i++) //背包从第二排开始到最后一个背包位置
{
if (args.TPlayer.inventory[i].netID == Convert.ToInt32(_item[0]))
{
if (args.TPlayer.inventory[i].stack >= Convert.ToInt32(_item[1]))
{
item_bool = true;
break;
}
else
{
args.Player.SendErrorMessage("没有足够的物品");
return false;
}
}
}
if (!item_bool)
{
Item _item1 = new Item();
_item1.netID = Convert.ToInt32(_item[0]);
args.Player.SendErrorMessage("您的背包中没有任务物品" + _item1.Name);
args.Player.SendInfoMessage("任务物品请不要放在背包最上排中");
return false;
}
}
break;
//任务类型1 背包中是否有指定物品 //测试完成
case "1":
{
bool item_bool = false;
for (int i = 0; i < 49; i++) //背包从第二排开始到最后一个背包位置
{
if (args.TPlayer.inventory[i].netID.ToString() == item.Condition)
{
item_bool = true;
break;
}
}
if (!item_bool)
{
Item _item1 = new Item();
_item1.netID = Convert.ToInt32( int.Parse(item.Condition));
args.Player.SendErrorMessage("您的背包中没有任务物品:" + _item1.Name + " " + item.Condition);
return false;
}
}
break;
//任务类型2 是否击杀指定NPC //测试完成
case "2":
{
var _item = item.Condition.Split(',');
if (Db.QueryData(args.Player.Name).MianTaskData >= int.Parse(_item[1]) | Db.QueryData(args.Player.Name).RegionalTaskData >= int.Parse(_item[1]))
{
continue;
}
else
{
args.Player.SendErrorMessage("您没有击杀指定NPC或击杀数量不足(" + new NPC() {netID= int.Parse(_item[0]) }.FullName + ") :任务数量" + int.Parse(_item[1]) + " 实际数量" + Db.QueryData(args.Player.Name).MianTaskData);
return false;
}
}
//任务类型3 到达指定地图区域 //测试完成
case "3":
{
var Coordinate = item.Condition.Split(',');
int x = int.Parse(Coordinate[0]);
int y = int.Parse(Coordinate[1]);
int deviation = int.Parse(Coordinate[2]);
if (args.Player.X/16 >= (x - deviation) && args.Player.X/16 <= (x + deviation) && args.Player.Y/16 >= (y - deviation) && args.Player.Y/16 <= (y + deviation))
{
continue;
}
else
{
args.Player.SendErrorMessage("您没有到达指定地图区域:您的坐标" + args.Player.X/16 + "," + args.Player.Y/16 + " 指定区域" + x + "," + y + " 允许偏差" + deviation );
return false;
}
}
//穿戴或拿起指定装备 //测试完成
case "4":
{
bool item_bool = false;
for (int i = 50; i < 99; i++)
{
if (args.TPlayer.inventory[i].netID.ToString() == item.Condition)
{
item_bool = true;
break;
}
}
if (!item_bool)
{
Item _item1 = new Item();
_item1.netID = int.Parse(item.Condition);
args.Player.SendErrorMessage("您未穿戴或拿起指定装备:" + _item1.Name + " " + item.Condition);
return false;
}
}
break;
//拥有指定buff
case "5":
{
if (args.TPlayer.buffType.Contains(int.Parse(item.Condition)))
{
continue;
}
else
{
args.Player.SendErrorMessage("您没有拥有指定buff: BUFF ID:" + item.Condition);
return false;
}
}
default:
{
args.Player.SendErrorMessage("请确认配置文件中 TaskType 值是否正确");
return false;
}
}
}
//消耗任务物品
var _itemTask = Tasklist.Conditions.Where(x => x.TaskType == "0");
foreach (var item in _itemTask)
{
var _item = item.Condition.Split(',');
for (int i = 10; i < 49; i++) //背包从第二排开始到最后一个背包位置
{
if (args.TPlayer.inventory[i].netID == Convert.ToInt32(_item[0]))
{
if (args.TPlayer.inventory[i].stack >= Convert.ToInt32(_item[1]))
{
var stack = args.TPlayer.inventory[i].stack -= Convert.ToInt32(_item[1]);
PlayItemSet(args.Player.Index, i, Convert.ToInt32(_item[0]), stack);
break;
}
else
{
args.Player.SendErrorMessage("没有足够的物品");
return false;
}
}
}
}
//给与奖励
//给与奖励物品
foreach (var item in Tasklist.Reward)
{
Commands.HandleCommand(TSPlayer.Server, item.Replace("{name}", args.Player.Name));
}
return true;
}
private void _TaskSystemGive(CommandArgs args)
{
//放弃支线任务
if (!Db.Queryuser(args.Player.Name))
{
args.Player.SendErrorMessage("您没有接受支线任务");
return;
}
if (Db.QueryData(args.Player.Name).RegionalTaskUser == null)
{
args.Player.SendErrorMessage("您没有接受支线任务");
return;
}
if (!Model.RandomTasks.Exists(x=>x.Name==args.Player.Name))
{
args.Player.SendErrorMessage("支线任务信息未刷新 请先刷新支线任务");
return;
}
DateTime now = DateTime.Now;
if (!Model.RandomTasks.Exists(x=>x.GiveTime==null))
{
Model.RandomTasks.Find(t => t.Name == args.Player.Name).GiveTime = now;
DBData dBData = Db.QueryData(args.Player.Name);
dBData.RegionalTaskUser = null;
dBData.RegionalTaskData = 0;
Db.UPData(dBData);
args.Player.SendWarningMessage("您已放弃任务,CD时间已更新");
return;
}
if (Model.RandomTasks.Find(t => t.Name == args.Player.Name).GiveTime.AddSeconds(10) < now)
{
Model.RandomTasks.Find(t => t.Name == args.Player.Name).GiveTime = now;
DBData dBData = Db.QueryData(args.Player.Name);
dBData.RegionalTaskUser = null;
dBData.RegionalTaskData = 0;
Db.UPData(dBData);
args.Player.SendWarningMessage("您已放弃任务,CD时间已更新");
return;
}
else
{
TimeSpan ts = Model.RandomTasks.Find(t => t.Name == args.Player.Name).GiveTime.AddSeconds(10) - now;
args.Player.SendWarningMessage("放弃任务冷却中 上次放弃时间" + Model.RandomTasks.Find(t => t.Name == args.Player.Name).GiveTime + "剩余 CD时间 " + ts.Seconds + "秒");
return;
}
}
private void _TaskSystemf5(CommandArgs args)
{
if (!Model.RandomTasks.Exists(t => t.Name == args.Player.Name)) //刷新任务
{
var Random = getRadom(5, 1, Model.RegionalTaskLists.Count());
Random = Random.Where((x, i) => Random.FindIndex(z => z == x) == i).ToList();
Model.RandomTasks.Add(new RandomTask() { Name = args.Player.Name, Reward = Random, F5Time = DateTime.Now });
args.Player.SendErrorMessage("任务已刷新");
foreach (int item in Random)
{
args.Player.SendErrorMessage("任务ID" + item + " 任务名称" + Model.RegionalTaskLists.Find(t => t.ID == item).Name + " 任务信息" + Model.RegionalTaskLists.Find(t => t.ID == item).Info);
}
return;
}
DateTime Date = DateTime.Now;
if (Model.RandomTasks.Find(t => t.Name == args.Player.Name).F5Time.AddSeconds(10) < Date)
{
Model.RandomTasks.Find(t => t.Name == args.Player.Name).F5Time = Date;
var Random = getRadom(5, 1, Model.RegionalTaskLists.Count());
Model.RandomTasks.Find(t => t.Name == args.Player.Name).Reward = Random;
args.Player.SendErrorMessage("任务已刷新");
foreach (int item in Random)
{
args.Player.SendErrorMessage("任务ID" + item + " 任务名称" + Model.RegionalTaskLists.Find(t => t.ID == item).Name + " 任务信息" + Model.RegionalTaskLists.Find(t => t.ID == item).Info);
}
return;
}
else
{
//剩余时间
TimeSpan ts = Model.RandomTasks.Find(t => t.Name == args.Player.Name).F5Time.AddSeconds(10) - Date;
args.Player.SendErrorMessage("任务刷新时间冷却中,剩余时间" + ts.Seconds + "秒");
return;
}
}
private void _TaskSystemPick(CommandArgs args)
{
if (args.Parameters.Count < 1)
{
args.Player.SendErrorMessage("/接受任务 主线 接受主线任务");
args.Player.SendErrorMessage("/接受任务 支线 查看可接受支线任务");
args.Player.SendErrorMessage("/接受任务 支线 [任务ID] 接受支线任务");
return;
}
switch (args.Parameters[0])
{
case "主线":
{
//接受主线任务
if (args.Parameters.Count == 1)
{
if (Model.MainTaskLists.Count() == 0)
{
args.Player.SendErrorMessage("没有主线任务");
return;
}
//接受任务
try
{
if (!Db.Queryuser(args.Player.Name))
{
Db.Adduser(new DBData() { UserName = args.Player.Name, MianTaskUser = Model.MainTaskLists[0].Name, MianTaskData = 0, MianTaskCompleted = 0, RegionalTaskUser = null, RegionalTaskData = 0, RegionalCompleted = 0 });
args.Player.SendErrorMessage("当前接受主线任务为" + Model.MainTaskLists[0].Name + " 任务ID:"+Model.MainTaskLists[0].ID);
args.Player.SendErrorMessage("任务信息:" + Model.MainTaskLists[0].Info);
return;
}
DBData dBData = Db.QueryData(args.Player.Name);
if (dBData.UserName != null)
{
args.Player.SendErrorMessage("您已接受任务" + dBData.MianTaskUser +" 任务ID: "+Model.MainTaskLists[0].ID + " 不能再次领取任务");
args.Player.SendErrorMessage("任务信息:" + Model.MainTaskLists[dBData.RegionalCompleted].Info);
return;
}
dBData.MianTaskUser = Model.MainTaskLists[dBData.MianTaskCompleted].Name;
dBData.MianTaskData = 0;
Db.UPData(dBData);
args.Player.SendErrorMessage("当前接受主线任务为" + Model.MainTaskLists[dBData.MianTaskCompleted].Name +" 任务ID:"+ Model.MainTaskLists[dBData.MianTaskCompleted].ID);
args.Player.SendErrorMessage("任务信息:" + Model.MainTaskLists[dBData.MianTaskCompleted].Info);
return;
}
catch (Exception ex)
{
args.Player.SendErrorMessage("任务接受失败");
TShock.Log.ConsoleError("[POBCTask] 任务接受失败!\n{0}".SFormat(ex.ToString()));
throw;
}
}
break;
}
case "支线":
{
if (Model.MainTaskLists.Count() == 0)
{
args.Player.SendErrorMessage("没有支线任务");
return;
}
if (args.Parameters.Count == 1)
{
if (!Model.RandomTasks.Exists(t => t.Name == args.Player.Name)) //刷新任务
{
//var Random = getRadom(5, 0, Model.RegionalTaskLists.Count());
//Model.RandomTasks.Add(new RandomTask() { Name = args.Player.Name, Reward = Random, F5Time = DateTime.Now });
args.Player.SendErrorMessage("随机任务未刷新,请先刷新随机任务列表");
return;
}
args.Player.SendErrorMessage("当前可接受支线任务为:");
foreach (int item in Model.RandomTasks.Find(x=>x.Name==args.Player.Name).Reward)
{
args.Player.SendErrorMessage("任务ID" + item + " 任务名称" + Model.RegionalTaskLists.Find(t => t.ID == item).Name + " 任务信息" + Model.RegionalTaskLists.Find(t => t.ID == item).Info);
}
return;
}
//接受支线任务
if (args.Parameters.Count == 2)
{
if (!int.TryParse(args.Parameters[1], out int tmp))
{
args.Player.SendErrorMessage("请输入正确的任务ID");
return;
}
//接受任务
try
{
int taskid = int.Parse(args.Parameters[1]);
if (!Model.RandomTasks.Find(t => t.Name == args.Player.Name).Reward.Contains(taskid))
{
args.Player.SendErrorMessage("请输入正确的任务ID");
return;
}
//查询数据库没有用户时添加用户
if (!Db.Queryuser(args.Player.Name))
{
Db.Adduser(new DBData() { UserName = args.Player.Name, MianTaskUser = null, MianTaskData = 0, MianTaskCompleted = 0, RegionalTaskUser = Model.RegionalTaskLists.Find(t => t.ID == taskid).Name, RegionalTaskData = 0, RegionalCompleted = 0 });
args.Player.SendInfoMessage("当前接受支线任务为" + Model.RegionalTaskLists.Find(t => t.ID == taskid).Name);
args.Player.SendInfoMessage("任务信息:" + Model.RegionalTaskLists.Find(t => t.ID == taskid).Info);
Model.RandomTasks.Find(t => t.Name == args.Player.Name).Reward.Remove(taskid);
return;
}
DBData dBData = Db.QueryData(args.Player.Name);
if (dBData.RegionalTaskUser != null)
{
args.Player.SendInfoMessage("您已接受任务" + dBData.RegionalTaskUser + "不能再次领取任务");
args.Player.SendInfoMessage("任务信息:" + Model.RegionalTaskLists.Find(t => t.ID == taskid).Info);
return;
}
dBData.RegionalTaskUser = Model.RegionalTaskLists.Find(t => t.ID == taskid).Name;
dBData.RegionalTaskData = 0;
Db.UPData(dBData);
args.Player.SendInfoMessage("当前接受支线任务为" + Model.RegionalTaskLists.Find(t => t.ID == taskid).Name);
args.Player.SendInfoMessage("任务信息:" + Model.RegionalTaskLists.Find(t => t.ID == taskid).Info);
Model.RandomTasks.Find(t => t.Name == args.Player.Name).Reward.Remove(taskid);
return;
}
catch (Exception ex)
{
args.Player.SendErrorMessage("任务接受失败");
TShock.Log.ConsoleError("[POBCTask] 任务接受失败!\n{0}".SFormat(ex.ToString()));
throw;
}
}
else
{
args.Player.SendErrorMessage("语法错误 正确语法 /接受任务 支线 <任务ID>");
}
break;
}
}
}
/// <summary>
/// 产生随机数
/// </summary>
/// <param name="len">产生随机数的个数</param>
/// <param name="min">随机数的下界</param>
/// <param name="max">随机数的上界</param>
/// <returns></returns>
private List<int> getRadom(int len, int min, int max)
{
Random r = new Random();
List<int> al = new List<int>();
for (int i = 0; i < len; i++)
{
al.Add(r.Next(min, max));
}
return al;
}
private void _TaskSystemList(CommandArgs args)
{
if (args.Parameters.Count < 1)
{
args.Player.SendErrorMessage("/任务列表 主线 [页数] 或者 /task list main [page]显示主线任务 \r\n/任务列表 支线 [页数]或者 /task list Regional [page]显示支线任务");
return;
}
switch (args.Parameters[0])
{
case "主线":
{
if (Model.MainTaskLists.Count() == 0)
{
args.Player.SendErrorMessage("没有主线任务");
return;
}
// 5项一页显示 Model.MainTaskLists
int page = 1;
if (args.Parameters.Count > 1)
{
if (!int.TryParse(args.Parameters[1], out page))
{
args.Player.SendErrorMessage("/任务列表 主线 [页数] 或者 /task list main [page]显示主线任务 \r\n/任务列表 支线 [页数]或者 /task list Regional [page]显示支线任务");
return;
}
}
int maxPage = (int)Math.Ceiling(Model.MainTaskLists.Count() / 5.0);
if (page < 1)
{
page = 1;
}
if (page > maxPage)
{
page = maxPage;
}
args.Player.SendInfoMessage("主线任务列表 第" + page + "页 共" + maxPage + "页");
for (int i = (page - 1) * 5; i < page * 5; i++)
{
if (i >= Model.MainTaskLists.Count())
{
break;
}
args.Player.SendInfoMessage("任务ID " + Model.MainTaskLists[i].ID +" 任务名: " + Model.MainTaskLists[i].Name + " 简略描述: " + Model.MainTaskLists[i].Info);
}
break;
}
case "支线":
{
if (Model.RegionalTaskLists.Count() == 0)
{
args.Player.SendErrorMessage("没有支线任务");
return;
}
//5项一页显示 Model.RegionalTaskLists
int page = 1;
if (args.Parameters.Count > 1)
{
if (!int.TryParse(args.Parameters[1], out page))
{
args.Player.SendErrorMessage("/任务列表 主线 [页数] 或者 /task list main [page]显示主线任务 \r\n/任务列表 支线 [页数]或者 /task list Regional [page]显示支线任务");
return;
}
}
int maxPage = (int)Math.Ceiling(Model.RegionalTaskLists.Count() / 5.0);
if (page < 1)
{
page = 1;
}
if (page > maxPage)
{
page = maxPage;
}
args.Player.SendInfoMessage("支线任务列表 第" + page + "页 共" + maxPage + "页");
for (int i = (page - 1) * 5; i < page * 5; i++)
{
if (i >= Model.RegionalTaskLists.Count())
{
break;
}
args.Player.SendInfoMessage("任务ID: " + Model.RegionalTaskLists[i].ID +" 任务名: " + Model.RegionalTaskLists[i].Name + " 简略描述: " + Model.RegionalTaskLists[i].Info );
}
break;
}
default:
{ args.Player.SendErrorMessage("语法错误,正确语法:/任务列表 主线 [页数] 显示主线任务 \r\n/任务列表 支线 [页数] 显示支线任务"); }
break;
}
}
private void _TaskSystem(CommandArgs args)
{
if (args.Parameters.Count < 1)
{
args.Player.SendErrorMessage("命令如下 /任务列表 /接受任务 /刷新任务 /完成任务 /放弃任务");
return;
}
}
/// <summary>
/// Handles plugin disposal logic.
/// *Supposed* to fire when the server shuts down.
/// You should deregister hooks and free all resources here.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
ServerApi.Hooks.GameInitialize.Deregister(this, OnInitialize);
}
base.Dispose(disposing);
}
public void File()
{
try
{
MainTaskLists = TaskConfig.Read(ConfigPath).Write(ConfigPath);
foreach (var item in MainTaskLists.TaskList)
{
if (item.Type=="主线")
{
Model.MainTaskLists.Add(item);
}
}
foreach (var item in MainTaskLists.TaskList)
{
if (item.Type == "支线")
{
Model.RegionalTaskLists.Add(item);
}
}
}
catch (Exception ex)
{
MainTaskLists = new TaskConfig();
TShock.Log.ConsoleError("[POBCTask] 读取配置文件发生错误!\n{0}".SFormat(ex.ToString()));
}
}
// 给与玩家物品
public void PlayItemSet(int ID, int slot, int Item, int stack)//ID 玩家ID,slot 格子ID,Item 物品ID,stack 物品堆叠
{
TSPlayer player = new TSPlayer(ID);
int index;
Item item = TShock.Utils.GetItemById(Item);
item.stack = stack;
//Inventory slots
if (slot < NetItem.InventorySlots)
{
index = slot;
player.TPlayer.inventory[slot] = item;
NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.inventory[index].Name), player.Index, slot, player.TPlayer.inventory[index].prefix);
NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.inventory[index].Name), player.Index, slot, player.TPlayer.inventory[index].prefix);
}
//Armor & Accessory slots
else if (slot < NetItem.InventorySlots + NetItem.ArmorSlots)
{
index = slot - NetItem.InventorySlots;
player.TPlayer.armor[index] = item;
NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.armor[index].Name), player.Index, slot, player.TPlayer.armor[index].prefix);
NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.armor[index].Name), player.Index, slot, player.TPlayer.armor[index].prefix);
}
//Dye slots
else if (slot < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots)
{
index = slot - (NetItem.InventorySlots + NetItem.ArmorSlots);
player.TPlayer.dye[index] = item;
NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.dye[index].Name), player.Index, slot, player.TPlayer.dye[index].prefix);
NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.dye[index].Name), player.Index, slot, player.TPlayer.dye[index].prefix);
}
//Misc Equipment slots
else if (slot < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots)
{
index = slot - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots);
player.TPlayer.miscEquips[index] = item;
NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.miscEquips[index].Name), player.Index, slot, player.TPlayer.miscEquips[index].prefix);
NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.miscEquips[index].Name), player.Index, slot, player.TPlayer.miscEquips[index].prefix);
}
//Misc Dyes slots
else if (slot < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots)
{
index = slot - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots);
player.TPlayer.miscDyes[index] = item;
NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(player.TPlayer.miscDyes[index].Name), player.Index, slot, player.TPlayer.miscDyes[index].prefix);
NetMessage.SendData((int)PacketTypes.PlayerSlot, player.Index, -1, NetworkText.FromLiteral(player.TPlayer.miscDyes[index].Name), player.Index, slot, player.TPlayer.miscDyes[index].prefix);
}
}
public int Stack(int userid)
{
int x = -1;
for (int i = 0; i < 50; i++)
{
if (TShock.Players[userid].TPlayer.inventory[i].netID == 0)
{
x = i;
break;
}
else
{
x = -1;
}
}
return x;
}
}
}
}