____ ___ ___ __ __ __ __ __ __ ___ __ __ ___ ___ File UOEntity cs Crea

  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
// **************************************************
// * ____ _ _ _ _ _ _ ___ *
// * | _ \ ___| |__ (_)_ __| |_| |__ | | | |/ _ \ *
// * | |_) / _ \ '_ \| | '__| __| '_ \| | | | | | | *
// * | _ < __/ |_) | | | | |_| | | | |_| | |_| | *
// * |_| \_\___|_.__/|_|_| \__|_| |_|\___/ \___/ *
// **************************************************
// * File : UOEntity.cs
// * Created : 22 06 2015
// * Updated : 22 06 2015
// * Website : www.RebirthUO.com
// **************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using ScriptDotNet2;
using ScriptDotNet2.Data;
namespace ScriptSDK
{
public enum UOEntityData
{
Serial,
Parent,
RootParent,
ObjectValidation,
Map,
Distance,
ToolTip,
ToolTipParsingDelay,
Direction,
Layer,
Location,
Properties,
ContextMenu,
Hue,
ObjectType
}
public enum Map : byte
{
Felucca = 0,
Trammel = 1,
Ilshenar = 2,
Malas = 3,
Tokuno = 4,
TerMur = 5,
#region RebirthUO
EventFelucca = 33,
EventTrammel = 34,
EventIlshenar = 35,
EventMalas = 36,
EventTokuno = 37,
EventTerMur = 38,
#endregion
Internal = 0x7F
}
public enum Direction : byte
{
North = 0x0,
Right = 0x1,
East = 0x2,
Down = 0x3,
South = 0x4,
Left = 0x5,
West = 0x6,
Up = 0x7
}
public class UOEntity : Entity
{
public UOEntity(uint value)
{
Initialize();
RegisterData(UOEntityData.Serial, new Serial(value));
}
public UOEntity(Serial serial)
: this(serial != null ? serial.Value : 0)
{
}
public int ToolTipParserDelay
{
get { return GetValue<int>(UOEntityData.ToolTipParsingDelay); }
set { SetValue(UOEntityData.ToolTipParsingDelay, value); }
}
public virtual string Tooltip
{
get { return GetValue<string>(UOEntityData.ToolTip); }
}
public Serial Serial
{
get { return GetValue<Serial>(UOEntityData.Serial); }
set
{
SetValue(UOEntityData.Serial, value);
Initialize();
}
}
public virtual Layer Layer
{
get { return GetValue<Layer>(UOEntityData.Layer); }
}
public virtual UOEntity Parent
{
get { return GetValue<UOEntity>(UOEntityData.Parent); }
}
public virtual UOEntity RootParent
{
get { return GetValue<UOEntity>(UOEntityData.RootParent); }
}
public virtual Point3D Location
{
get { return GetValue<Point3D>(UOEntityData.Location); }
}
public virtual Map Map
{
get { return GetValue<Map>(UOEntityData.Map); }
}
public virtual bool Valid
{
get { return GetValue<bool>(UOEntityData.ObjectValidation); }
}
public virtual Direction Direction
{
get { return GetValue<Direction>(UOEntityData.Direction); }
}
public virtual ContextMenu ContextMenu
{
get { return GetValue<ContextMenu>(UOEntityData.ContextMenu); }
}
public virtual ushort Color
{
get { return GetValue<ushort>(UOEntityData.Hue); }
}
public virtual ushort ObjectType
{
get { return GetValue<ushort>(UOEntityData.ObjectType); }
}
public virtual int Distance
{
get { return GetValue<int>(UOEntityData.Distance); }
}
public virtual List<ClilocItemRec> Properties
{
get { return GetValue<List<ClilocItemRec>>(UOEntityData.Properties); }
}
protected override bool CanReadBaseValue(Enum key)
{
if (key is UOEntityData)
{
var k = (UOEntityData) key;
if (k.Equals(UOEntityData.ToolTipParsingDelay))
return false;
if (k.Equals(UOEntityData.Serial))
return false;
}
return base.CanReadBaseValue(key);
}
protected override object GetBaseValue(Enum key)
{
if (key is UOEntityData)
{
var k = (UOEntityData) key;
switch (k)
{
case UOEntityData.ToolTip:
{
return Stealth.Default.GetTooltip(Serial.Value);
}
case UOEntityData.ObjectValidation:
{
return Stealth.Default.IsObjectExists(Serial.Value);
}
case UOEntityData.Map:
{
if (!GetValue<bool>(UOEntityData.ObjectValidation))
return Map.Internal;
var b = Stealth.Default.GetWorldNum();
var l = Enum.GetValues(typeof (Map)) as byte[];
if (l == null)
return Map.Internal;
if (l.Contains(b))
return (Map) b;
return Map.Internal;
}
case UOEntityData.Distance:
{
return Stealth.Default.GetDistance(Serial.Value);
}
case UOEntityData.Direction:
{
return (Direction) Stealth.Default.GetDirection(Serial.Value);
}
case UOEntityData.Layer:
{
var b = Stealth.Default.GetLayer(Serial.Value);
var l = Enum.GetValues(typeof (Layer)) as byte[];
if (l == null)
return Layer.Invalid;
if (l.Contains(b))
return (Layer) b;
return Layer.Invalid;
}
case UOEntityData.Location:
{
return new Point3D(Stealth.Default.GetX(Serial.Value), Stealth.Default.GetY(Serial.Value),
Stealth.Default.GetZ(Serial.Value));
}
case UOEntityData.Parent:
{
return new UOEntity(Stealth.Default.GetParent(Serial.Value));
//GenerateVersion(Config.Options.Version,new Serial(Stealth.Default.GetParent(Serial.Value)));//TODO : Coming Soon
}
case UOEntityData.RootParent:
{
var p = Parent;
while (!p.Serial.Value.Equals(0))
{
var item = p;
if (item.Parent.Serial.Value.Equals(0))
{
p = item;
break;
}
p = item.Parent;
}
return p;
//GenerateVersion(Config.Options.Version,new Serial(Stealth.Default.GetParent(Serial.Value))); //TODO : Coming Soon
}
case UOEntityData.Properties:
{
return Stealth.Default.GetClilocRec(Serial.Value);
}
case UOEntityData.ContextMenu:
{
((ContextMenu) _datatable[key]).Update();
return _datatable[key];
}
case UOEntityData.ObjectType:
{
return Stealth.Default.GetType(Serial.Value);
}
case UOEntityData.Hue:
{
return Stealth.Default.GetColor(Serial.Value);
}
}
}
return base.GetBaseValue(key);
}
protected override void Initialize()
{
base.Initialize();
RegisterData(UOEntityData.ToolTip, "");
RegisterData(UOEntityData.ToolTipParsingDelay, 200);
RegisterData(UOEntityData.ObjectValidation, false);
RegisterData(UOEntityData.Map, Map.Internal);
RegisterData(UOEntityData.Distance, 0);
RegisterData(UOEntityData.Direction, Direction.Down);
RegisterData(UOEntityData.Layer, Layer.Invalid);
RegisterData(UOEntityData.Location, new Point3D(0, 0, 0));
RegisterData(UOEntityData.Parent, 0);
RegisterData(UOEntityData.RootParent, 0);
RegisterData(UOEntityData.Properties, new List<ClilocItemRec>());
RegisterData(UOEntityData.ObjectType, 0);
RegisterData(UOEntityData.Hue, 0);
RegisterData(UOEntityData.ContextMenu, new ContextMenu(this));
}
public static UOEntity GenerateVersion(Version version, Serial serial)
{
if (serial.Value > 0 && serial.Value < 0x40000000)
return new UOEntity(serial); //TODO cast return Item.GenerateVersion(version, serial);
if (serial.Value >= 0x40000000 && serial.Value <= 0x7FFFFFFF)
return new UOEntity(serial); //TODO cast Mobile.GenerateVersion(serial);
return new UOEntity(serial);
}
public virtual bool Click()
{
if (!GetValue<bool>(UOEntityData.ObjectValidation)) return false;
Stealth.Default.ClickOnObject(Serial.Value);
return true;
}
public virtual bool Use()
{
if (!GetValue<bool>(UOEntityData.ObjectValidation)) return false;
Stealth.Default.UseObject(Serial.Value);
return true;
}
public override void Update()
{
if (!EntityMode.Equals(EntityMode.Refresh))
return;
_datatable[UOEntityData.Properties] = GetBaseValue(UOEntityData.Properties);
base.Update();
}
}
}
// **************************************************
// * ____ _ _ _ _ _ _ ___ *
// * | _ \ ___| |__ (_)_ __| |_| |__ | | | |/ _ \ *
// * | |_) / _ \ '_ \| | '__| __| '_ \| | | | | | | *
// * | _ < __/ |_) | | | | |_| | | | |_| | |_| | *
// * |_| \_\___|_.__/|_|_| \__|_| |_|\___/ \___/ *
// **************************************************
// * File : Entity.cs
// * Created : 22 06 2015
// * Updated : 22 06 2015
// * Website : www.RebirthUO.com
// **************************************************
using System;
using System.Collections.Generic;
using System.Linq;
namespace ScriptSDK
{
public enum EntityData
{
EntityMode
}
public enum EntityMode
{
Store,
Refresh
}
public class Entity
{
/// <summary>
/// Root Constructor, if this is not called by inheritence the whole system will have trouble!!!
/// </summary>
public Entity()
{
_datatable = new Dictionary<Enum, object>();
Initialize();
}
/// <summary>
/// Entity Mode decides how the Object will read the properties.
///
/// Refresh :
/// + Faster when require single informations on fly
/// + Always updated informations
/// - Slow when calling tons of Cliloc Properties
/// - Not suited for a full Checkup if you need properties multiple times
///
/// Store :
/// + Update() will store all data via API
/// + You can reread the stored data anytime (even import\export)
/// - Slow because of many API-Calls at once
/// - Not suited for Time Critical Handlings
/// - Requires the Call of "Update()" in order to get Data
/// </summary>
public EntityMode EntityMode
{
get { return GetValue<EntityMode>(EntityData.EntityMode); }
set { SetValue(EntityData.EntityMode, value); }
}
/// <summary>
/// Object wich stores data, avoid using this directly
/// </summary>
protected Dictionary<Enum, object> _datatable { get; set; }
/// <summary>
/// Initializer of propertys to data map.Except propertys you want for copy data you should move all new propertys here
/// </summary>
protected virtual void Initialize()
{
RegisterData(EntityData.EntityMode, EntityMode.Refresh);
}
/// <summary>
/// Simple way to register a new property. Will fill data with an object dummy
/// </summary>
/// <param name="key"></param>
protected void RegisterData(Enum key)
{
if (_datatable == null)
_datatable = new Dictionary<Enum, object>();
if (!_datatable.ContainsKey(key))
_datatable.Add(key, new object());
}
/// <summary>
/// Returns the ObjectType as String
/// </summary>
/// <returns></returns>
public override string ToString()
{
return GetType().ToString();
}
/// <summary>
/// Method to register a new property together with a value
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
protected void RegisterData<T>(Enum key, T value)
{
RegisterData(key);
SetValue(key, value);
}
/// <summary>
/// This method provides the API-Calls (or alternative databuilds). When you call Update() or EntityMode is Refresh,
/// this method describes where to get the data
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
protected virtual object GetBaseValue(Enum key)
{
return null;
}
/// <summary>
/// Generic Setter Method for datamapping
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
protected void SetValue<T>(Enum key, T value)
{
if (_datatable == null) return;
if (_datatable.ContainsKey(key))
_datatable[key] = value;
}
/// <summary>
/// This Method allows to ignore the "GetBaseValue" call. Sometimes there are attributes, wich could do trouble
/// deadlocks on recursive calls(such as EntityMode) or you just never want to call the api for that. Then you can
/// Check the Key and disable the GetBaseValue call. Instead of GetBaseValue it will just do _datatable[key] and returns the stored value.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
protected virtual bool CanReadBaseValue(Enum key)
{
return !(key is EntityData);
}
/// <summary>
/// The Same Idea as CanReadBaseValue but as reverted. If you have something Cliloc related you can return true and it forwards
/// to method GetBaseClilocValue where you can handle forwardly. On Update i integrated a Property Update before calling the Cliloc stuff,
/// this reduce the calls of Api for parsing Cliloc-Property data from Properties.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
protected virtual bool IsClilocData(Enum key)
{
return false;
}
/// <summary>
/// Whenever IsClilocData returns true this method will be called instead of GetBaseValue. Theoreticly it should work the same way as
/// GetBaseValue, but it depends on you, how you update cliloc related data with given Properties.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
protected virtual object GetBaseClilocValue(Enum key)
{
return null;
}
/// <summary>
/// Generic Getter for datamapping, allows to read either
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <returns></returns>
protected T GetValue<T>(Enum key)
{
if (!(CanReadBaseValue(key)))
return (T)_datatable[key];
if (_datatable == null)
return IsClilocData(key) ? (T)GetBaseClilocValue(key) : (T)GetBaseValue(key);
if (!_datatable.ContainsKey(key))
RegisterData(key, IsClilocData(key) ? (T)GetBaseClilocValue(key) : (T)GetBaseValue(key));
else if (EntityMode.Equals(EntityMode.Refresh))
_datatable[key] = (IsClilocData(key) ? (T)GetBaseClilocValue(key) : (T)GetBaseValue(key));
return (T)_datatable[key];
}
/// <summary>
/// Update Method for Store-driven EntityMode (Slow but updated all data)
/// </summary>
public virtual void Update()
{
if (!EntityMode.Equals(EntityMode.Refresh))
return;
if (_datatable == null)
return;
SetValue(EntityData.EntityMode, EntityMode.Refresh);
var keys = _datatable.Keys.ToList();
foreach (var k in keys.Where(k => _datatable.ContainsKey(k)).Where(CanReadBaseValue))
{
SetValue(k, GetBaseValue(k));
}
SetValue(EntityData.EntityMode, EntityMode.Store);
}
/// <summary>
/// Lowlevel Object Cloning while setting the Cloned Enity-Mode to "Store".
/// You want to save some data? this maybe your friend...
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T Clone<T>() where T : Entity
{
const EntityData att = EntityData.EntityMode;
var val = GetValue<EntityMode>(att);
if (val.Equals(EntityMode.Refresh))
EntityMode = EntityMode.Store;
var obj = new Entity() as T;
if (obj != null)
{
foreach (var o in _datatable.Keys)
{
var k = o;
obj._datatable[k] = _datatable[k];
}
obj.EntityMode = (val.Equals(EntityMode.Refresh)) ? EntityMode.Refresh : EntityMode.Store;
}
if (val.Equals(EntityMode.Refresh))
EntityMode = EntityMode.Refresh;
return obj;
}
}
}