/
RepairBench.cs
766 lines (631 loc) · 25.8 KB
/
RepairBench.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
using Server.ContextMenus;
using Server.Engines.Craft;
using Server.Engines.VeteranRewards;
using Server.Gumps;
using Server.Multis;
using Server.Network;
using Server.Targeting;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Server.Items
{
public class RepairBenchComponent : LocalizedAddonComponent
{
public override bool ForceShowProperties => true;
public RepairBenchComponent(int id)
: base(id, 1158860) // Repair Bench
{
}
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
{
base.GetContextMenuEntries(from, list);
SetSecureLevelEntry.AddTo(from, Addon, list);
}
public RepairBenchComponent(Serial serial)
: base(serial)
{
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // Version
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
}
public class RepairBenchAddon : BaseAddon, ISecurable
{
public List<RepairBenchDefinition> Tools;
public static RepairBenchDefinition[] Definitions =
{
new RepairBenchDefinition(DefTinkering.CraftSystem, RepairSkillType.Tinkering, 1044097, 0, 0),
new RepairBenchDefinition(DefBlacksmithy.CraftSystem, RepairSkillType.Smithing, 1044067, 0, 0),
new RepairBenchDefinition(DefCarpentry.CraftSystem, RepairSkillType.Carpentry, 1044071, 0, 0),
new RepairBenchDefinition(DefTailoring.CraftSystem, RepairSkillType.Tailoring, 1044094, 0, 0),
new RepairBenchDefinition(DefMasonry.CraftSystem, RepairSkillType.Masonry, 1072392, 0, 0),
new RepairBenchDefinition(DefGlassblowing.CraftSystem, RepairSkillType.Glassblowing, 1072393, 0, 0),
new RepairBenchDefinition(DefBowFletching.CraftSystem, RepairSkillType.Fletching, 1015156, 0, 0)
};
public static RepairBenchDefinition GetInfo(RepairSkillType type)
{
List<RepairBenchDefinition> list = new List<RepairBenchDefinition>();
for (var index = 0; index < Definitions.Length; index++)
{
var definition = Definitions[index];
list.Add(definition);
}
return list.Find(x => x.Skill == type);
}
[CommandProperty(AccessLevel.GameMaster)]
public bool IsRewardItem { get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public SecureLevel Level { get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public Mobile User { get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public bool Using
{
get
{
if (User != null)
{
if (User.InRange(Location, 2))
{
return true;
}
User = null;
}
return false;
}
}
public override bool HandlesOnMovement => User != null;
public override void OnMovement(Mobile m, Point3D oldLocation)
{
if (m == User && !m.InRange(GetWorldLocation(), 2))
{
User = null;
m.CloseGump(typeof(ConfirmRemoveGump));
m.CloseGump(typeof(RepairBenchGump));
Target.Cancel(m);
}
}
[Constructable]
public RepairBenchAddon(DirectionType type, List<RepairBenchDefinition> tools)
{
switch (type)
{
case DirectionType.South:
AddComponent(new RepairBenchComponent(0xA278), 0, 0, 0);
break;
case DirectionType.East:
AddComponent(new RepairBenchComponent(0xA27F), 0, 0, 0);
break;
}
if (tools == null)
{
Tools = new List<RepairBenchDefinition>();
for (var index = 0; index < Definitions.ToList().Count; index++)
{
var x = Definitions.ToList()[index];
Tools.Add(x);
}
}
else
{
Tools = tools;
}
}
public RepairBenchAddon(Serial serial)
: base(serial)
{
}
public void AccessibleFailMessage(Mobile from)
{
AddonComponent first = null;
foreach (var component in Components)
{
first = component;
break;
}
if (first != null)
{
first.SendLocalizedMessageTo(from, 1061637); // You are not allowed to access this.
}
}
public bool CheckAccessible(Mobile from, Item item)
{
if (from.AccessLevel >= AccessLevel.GameMaster)
return true; // Staff can access anything
BaseHouse house = BaseHouse.FindHouseAt(item);
if (house == null)
return false;
switch (Level)
{
case SecureLevel.Owner: return house.IsOwner(from);
case SecureLevel.CoOwners: return house.IsCoOwner(from);
case SecureLevel.Friends: return house.IsFriend(from);
case SecureLevel.Anyone: return true;
case SecureLevel.Guild: return house.IsGuildMember(from);
}
return false;
}
public override BaseAddonDeed Deed
{
get
{
RepairBenchDeed deed = new RepairBenchDeed(Tools)
{
IsRewardItem = IsRewardItem
};
return deed;
}
}
public override void OnComponentUsed(AddonComponent c, Mobile from)
{
if (from.InRange(c.Location, 2))
{
BaseHouse house = BaseHouse.FindHouseAt(from);
if (house != null)
{
if (CheckAccessible(from, this))
{
if (from.HasGump(typeof(RepairBenchGump)))
return;
if (!Using || from == User)
{
User = from;
from.CloseGump(typeof(RepairBenchGump));
from.SendGump(new RepairBenchGump(from, this));
}
else
{
from.SendLocalizedMessage(500291); // Someone else is using that.
}
}
else
{
AccessibleFailMessage(from);
}
}
else
{
from.SendLocalizedMessage(502092); // You must be in your house to do this.
}
}
else
{
from.SendLocalizedMessage(500325); // I am too far away to do that.
}
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(1);
writer.Write((int)Level);
writer.Write(IsRewardItem);
writer.Write(Tools == null ? 0 : Tools.Count);
if (Tools != null)
{
for (var index = 0; index < Tools.Count; index++)
{
var x = Tools[index];
writer.Write((int) x.Skill);
writer.Write((int) x.SkillValue);
writer.Write(x.Charges);
}
}
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
if (version != 0)
Level = (SecureLevel)reader.ReadInt();
IsRewardItem = reader.ReadBool();
Tools = new List<RepairBenchDefinition>();
int toolcount = reader.ReadInt();
for (int x = 0; x < toolcount; x++)
{
RepairSkillType skill = (RepairSkillType)reader.ReadInt();
int skillvalue = reader.ReadInt();
int charge = reader.ReadInt();
Tools.Add(new RepairBenchDefinition(GetInfo(skill).System, skill, GetInfo(skill).Cliloc, skillvalue, charge));
}
}
}
public class RepairBenchDeed : BaseAddonDeed, IRewardItem, IRewardOption
{
public override int LabelNumber => 1158860; // Repair Bench
public override BaseAddon Addon
{
get
{
RepairBenchAddon addon = new RepairBenchAddon(_Direction, Tools)
{
IsRewardItem = m_IsRewardItem
};
return addon;
}
}
private DirectionType _Direction;
private bool m_IsRewardItem;
[CommandProperty(AccessLevel.GameMaster)]
public bool IsRewardItem
{
get => m_IsRewardItem;
set
{
m_IsRewardItem = value;
InvalidateProperties();
}
}
public List<RepairBenchDefinition> Tools;
[Constructable]
public RepairBenchDeed()
: this(null)
{
}
[Constructable]
public RepairBenchDeed(List<RepairBenchDefinition> tools)
{
Tools = tools;
LootType = LootType.Blessed;
}
public RepairBenchDeed(Serial serial)
: base(serial)
{
}
public override void GetProperties(ObjectPropertyList list)
{
base.GetProperties(list);
if (m_IsRewardItem)
list.Add(1076221); // 5th Year Veteran Reward
if (Tools != null)
{
int[] value = Tools.Select(x => x.Charges).ToArray();
list.Add(1158899, $"{value[0]}\t{value[1]}\t{value[2]}\t{value[3]}\t{value[4]}\t{value[5]}\t{value[6]}"); // Tinkering: ~1_CHARGES~<br>Blacksmithing: ~2_CHARGES~<br>Carpentry: ~3_CHARGES~<br>Tailoring: ~4_CHARGES~<br>Fletching: ~5_CHARGES~<br>Masonry: ~6_CHARGES~<br>Glassblowing: ~7_CHARGES~
}
}
public void GetOptions(RewardOptionList list)
{
list.Add((int)DirectionType.South, 1075386); // South
list.Add((int)DirectionType.East, 1075387); // East
}
public void OnOptionSelected(Mobile from, int choice)
{
_Direction = (DirectionType)choice;
if (!Deleted)
base.OnDoubleClick(from);
}
public override void OnDoubleClick(Mobile from)
{
if (IsChildOf(from.Backpack))
{
from.CloseGump(typeof(AddonOptionGump));
from.SendGump(new AddonOptionGump(this, 1154194)); // Choose a Facing:
}
else
{
from.SendLocalizedMessage(1062334); // This item must be in your backpack to be used.
}
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
writer.Write(m_IsRewardItem);
writer.Write(Tools == null ? 0 : Tools.Count);
if (Tools != null)
{
for (var index = 0; index < Tools.Count; index++)
{
var x = Tools[index];
writer.Write((int) x.Skill);
writer.Write((int) x.SkillValue);
writer.Write(x.Charges);
}
}
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
reader.ReadInt();
m_IsRewardItem = reader.ReadBool();
int toolcount = reader.ReadInt();
if (toolcount != 0)
{
Tools = new List<RepairBenchDefinition>();
}
for (int x = 0; x < toolcount; x++)
{
RepairSkillType skill = (RepairSkillType)reader.ReadInt();
int skillvalue = reader.ReadInt();
int charge = reader.ReadInt();
Tools.Add(new RepairBenchDefinition(RepairBenchAddon.GetInfo(skill).System, skill, RepairBenchAddon.GetInfo(skill).Cliloc, skillvalue, charge));
}
}
}
public class RepairBenchDefinition
{
public CraftSystem System { get; }
public RepairSkillType Skill { get; }
public double SkillValue { get; set; }
public int Charges { get; set; }
public int Cliloc { get; }
public RepairBenchDefinition(CraftSystem system, RepairSkillType skill, int cliloc, double value, int charges)
{
System = system;
Skill = skill;
Cliloc = cliloc;
SkillValue = value;
Charges = charges;
}
}
public class ConfirmRemoveGump : Gump
{
private readonly RepairBenchAddon m_Addon;
private readonly RepairSkillType m_Skill;
public ConfirmRemoveGump(RepairBenchAddon addon, RepairSkillType skill)
: base(340, 340)
{
m_Addon = addon;
m_Skill = skill;
AddPage(0);
AddBackground(0, 0, 291, 113, 0x13BE);
AddImageTiled(5, 5, 280, 80, 0xA40);
AddHtmlLocalized(9, 9, 272, 80, 1158874, $"#{addon.Tools.Find(x => x.Skill == skill).Cliloc}", 0x7FFF, false, false); // Are you sure you wish to remove all the ~1_SKILL~ charges from the bench? This action will delete all existing charges and will not refund any deeds.
AddButton(5, 87, 0xFB1, 0xFB2, 0, GumpButtonType.Reply, 0);
AddHtmlLocalized(40, 89, 100, 20, 1060051, 0x7FFF, false, false); // CANCEL
AddButton(160, 87, 0xFB7, 0xFB8, 1, GumpButtonType.Reply, 0);
AddHtmlLocalized(195, 89, 120, 20, 1006044, 0x7FFF, false, false); // OK
}
public override void OnResponse(NetState sender, RelayInfo info)
{
if (m_Addon == null || m_Addon.Deleted)
return;
Mobile m = sender.Mobile;
int index = info.ButtonID;
switch (index)
{
case 0: { m_Addon.User = null; break; }
case 1:
{
RepairBenchDefinition tool = m_Addon.Tools.Find(x => x.Skill == m_Skill);
tool.SkillValue = 0;
tool.Charges = 0;
m.SendLocalizedMessage(1158873, $"#{tool.Cliloc}"); // You clear all the ~1_SKILL~ charges from the bench.
m.SendGump(new RepairBenchGump(m, m_Addon));
break;
}
}
}
}
public class RepairBenchGump : Gump
{
private readonly RepairBenchAddon m_Addon;
private Timer m_Timer;
public RepairBenchGump(Mobile from, RepairBenchAddon addon)
: base(100, 100)
{
m_Addon = addon;
StopTimer(from);
m_Timer = Timer.DelayCall(TimeSpan.FromMinutes(1), CloseGump, from);
AddPage(0);
AddBackground(0, 0, 370, 470, 0x6DB);
AddImage(82, 0, 0x6E4);
AddHtmlLocalized(10, 10, 350, 18, 1114513, "#1158860", 0x0, false, false); // <DIV ALIGN=CENTER>~1_TOKEN~</DIV>
AddHtmlLocalized(70, 57, 120, 20, 1114513, "#1158878", 0x7FE0, false, false); // <DIV ALIGN=CENTER>~1_TOKEN~</DIV>
AddHtmlLocalized(213, 57, 190, 20, 1158879, 0x7FE0, false, false); // Charges
AddItem(20, 80, 0x1EB8);
AddTooltip(1044097);
AddButton(70, 97, 0x15E1, 0x15E5, 12, GumpButtonType.Reply, 0);
AddLabel(113, 97, 0x5F, $"{GetSkillValue(RepairSkillType.Tinkering):F1}");
AddLabel(218, 97, 0x5F, $"{GetCharges(RepairSkillType.Tinkering)}");
AddButton(318, 97, 0x2716, 0x2716, 22, GumpButtonType.Reply, 0);
AddItem(20, 125, 0x0FB4);
AddTooltip(1044067);
AddButton(70, 137, 0x15E1, 0x15E5, 10, GumpButtonType.Reply, 0);
AddLabel(113, 137, 0x5F, $"{GetSkillValue(RepairSkillType.Smithing):F1}");
AddLabel(218, 137, 0x5F, $"{GetCharges(RepairSkillType.Smithing)}");
AddButton(318, 137, 0x2716, 0x2716, 20, GumpButtonType.Reply, 0);
AddItem(20, 170, 0x1034);
AddTooltip(1044071);
AddButton(70, 177, 0x15E1, 0x15E5, 13, GumpButtonType.Reply, 0);
AddLabel(113, 177, 0x5F, $"{GetSkillValue(RepairSkillType.Carpentry):F1}");
AddLabel(218, 177, 0x5F, $"{GetCharges(RepairSkillType.Carpentry)}");
AddButton(318, 177, 0x2716, 0x2716, 23, GumpButtonType.Reply, 0);
AddItem(20, 215, 0x0F9D);
AddTooltip(1044094);
AddButton(70, 217, 0x15E1, 0x15E5, 11, GumpButtonType.Reply, 0);
AddLabel(113, 217, 0x5F, $"{GetSkillValue(RepairSkillType.Tailoring):F1}");
AddLabel(218, 217, 0x5F, $"{GetCharges(RepairSkillType.Tailoring)}");
AddButton(318, 217, 0x2716, 0x2716, 21, GumpButtonType.Reply, 0);
AddItem(20, 260, 0x12B3);
AddTooltip(1072392);
AddButton(70, 257, 0x15E1, 0x15E5, 15, GumpButtonType.Reply, 0);
AddLabel(113, 257, 0x5F, $"{GetSkillValue(RepairSkillType.Masonry):F1}");
AddLabel(218, 257, 0x5F, $"{GetCharges(RepairSkillType.Masonry)}");
AddButton(318, 257, 0x2716, 0x2716, 25, GumpButtonType.Reply, 0);
AddItem(20, 305, 0x182D);
AddTooltip(1072393);
AddButton(70, 297, 0x15E1, 0x15E5, 16, GumpButtonType.Reply, 0);
AddLabel(113, 297, 0x5F, $"{GetSkillValue(RepairSkillType.Glassblowing):F1}");
AddLabel(218, 297, 0x5F, $"{GetCharges(RepairSkillType.Glassblowing)}");
AddButton(318, 297, 0x2716, 0x2716, 26, GumpButtonType.Reply, 0);
AddItem(20, 350, 0x1022);
AddTooltip(1015156);
AddButton(70, 337, 0x15E1, 0x15E5, 14, GumpButtonType.Reply, 0);
AddLabel(113, 337, 0x5F, $"{GetSkillValue(RepairSkillType.Fletching):F1}");
AddLabel(218, 337, 0x5F, $"{GetCharges(RepairSkillType.Fletching)}");
AddButton(318, 337, 0x2716, 0x2716, 24, GumpButtonType.Reply, 0);
AddButton(70, 407, 0x15E1, 0x15E5, 1, GumpButtonType.Reply, 0);
AddHtmlLocalized(95, 407, 200, 30, 1153100, 0x7FFF, false, false); // Add Charges
}
public void CloseGump(object state)
{
Mobile from = state as Mobile;
StopTimer(from);
m_Addon.User = null;
if (from != null && !from.Deleted)
{
from.CloseGump(typeof(RepairBenchGump));
}
}
public void StopTimer(Mobile from)
{
if (m_Timer != null)
{
m_Timer.Stop();
m_Timer = null;
}
}
private double GetSkillValue(RepairSkillType skill)
{
return m_Addon.Tools.Find(x => x.Skill == skill).SkillValue;
}
private int GetCharges(RepairSkillType skill)
{
return m_Addon.Tools.Find(x => x.Skill == skill).Charges;
}
public class InternalTarget : Target
{
private readonly RepairBenchAddon m_Addon;
private readonly RepairBenchGump m_Gump;
public InternalTarget(Mobile from, RepairBenchGump g, RepairBenchAddon addon)
: base(-1, false, TargetFlags.None)
{
m_Addon = addon;
m_Gump = g;
}
protected override void OnTarget(Mobile from, object targeted)
{
if (m_Addon == null || m_Addon.Deleted || targeted is Item item && !from.InRange(item.GetWorldLocation(), 2))
{
return;
}
if (!m_Addon.CheckAccessible(from, m_Addon))
{
m_Addon.User = null;
m_Addon.AccessibleFailMessage(from);
return;
}
if (targeted is RepairDeed repairDeed)
{
if (m_Addon.Tools.Any(x => x.Skill == repairDeed.RepairSkill && x.Charges >= 500))
{
from.SendLocalizedMessage(1158778); // This would exceed the maximum charges allowed on this magic item.
from.Target = new InternalTarget(from, m_Gump, m_Addon);
}
else if (m_Addon.Tools.Any(x => x.Skill == repairDeed.RepairSkill && x.Charges != 0 && x.SkillValue != repairDeed.SkillLevel))
{
from.SendLocalizedMessage(1158866); // The repair bench contains deeds that do not match the skill of the deed you are trying to add.
from.Target = new InternalTarget(from, m_Gump, m_Addon);
}
else
{
RepairBenchDefinition tool = m_Addon.Tools.Find(x => x.Skill == repairDeed.RepairSkill);
tool.SkillValue = repairDeed.SkillLevel;
tool.Charges++;
repairDeed.Delete();
from.Target = new InternalTarget(from, m_Gump, m_Addon);
}
}
else if (targeted is Container c)
{
for (int i = c.Items.Count - 1; i >= 0; --i)
{
if (i < c.Items.Count && c.Items[i] is RepairDeed)
{
RepairDeed deed = (RepairDeed)c.Items[i];
if (m_Addon.Tools.Any(x => x.Skill == deed.RepairSkill && x.Charges >= 500))
{
from.SendLocalizedMessage(1158778); // This would exceed the maximum charges allowed on this magic item.
}
else if (m_Addon.Tools.Any(x => x.Skill == deed.RepairSkill && x.SkillValue == deed.SkillLevel))
{
RepairBenchDefinition tool = m_Addon.Tools.Find(x => x.Skill == deed.RepairSkill);
tool.SkillValue = deed.SkillLevel;
tool.Charges++;
deed.Delete();
}
}
}
}
else
{
from.SendLocalizedMessage(1158865); // That is not a valid repair contract or container.
}
if (m_Addon != null && !m_Addon.Deleted && from.InRange(m_Addon.GetWorldLocation(), 2))
{
m_Gump.StopTimer(from);
from.CloseGump(typeof(RepairBenchGump));
from.SendGump(new RepairBenchGump(from, m_Addon));
}
}
protected override void OnTargetCancel(Mobile from, TargetCancelType cancelType)
{
if (m_Addon != null && !m_Addon.Deleted && from.InRange(m_Addon.GetWorldLocation(), 2))
{
m_Gump.StopTimer(from);
from.CloseGump(typeof(RepairBenchGump));
from.SendGump(new RepairBenchGump(from, m_Addon));
}
}
}
public override void OnResponse(NetState sender, RelayInfo info)
{
Mobile from = sender.Mobile;
int index = info.ButtonID;
if (m_Addon != null && !m_Addon.Deleted && from.InRange(m_Addon.GetWorldLocation(), 2))
{
if (index == 0)
{
m_Addon.User = null;
}
else if (index == 1)
{
StopTimer(from);
from.SendLocalizedMessage(1158871); // Which repair deed or container of repair deeds do you wish to add to the repair bench?
from.Target = new InternalTarget(from, this, m_Addon);
}
else if (index >= 10 && index < 20)
{
StopTimer(from);
int skillIndex = index - 10;
Repair.Do(from, RepairSkillInfo.GetInfo((RepairSkillType)skillIndex).System, m_Addon);
}
else
{
BaseHouse house = BaseHouse.FindHouseAt(m_Addon);
if (house != null && house.IsOwner(from))
{
StopTimer(from);
int skillIndex = index - 20;
from.SendGump(new ConfirmRemoveGump(m_Addon, (RepairSkillType)skillIndex));
}
else
{
from.SendLocalizedMessage(1005213); // You can't do that
if (m_Addon != null)
{
m_Addon.User = null;
}
}
}
}
else
{
if (m_Addon != null)
{
m_Addon.User = null;
}
from.CloseGump(typeof(RepairBenchGump));
from.SendLocalizedMessage(500295); // You are too far away to do that.
}
}
}
}