public async Task UpdateInRangeObject(IObjectImpl obj, List <ObjectGUID> ignoreGuids) { List <Task> tasks = new List <Task>(); var posx = await obj.GetPositionX(); var posy = await obj.GetPositionY(); var cellx = GetCellX(posx); var celly = GetCellY(posy); var player = await obj.IsPlayer(); if (player) { ServerLog.Debug("Map", "Updating inrange for player"); } for (var x = cellx - 1; x <= cellx + 1; ++x) { for (var y = celly - 1; y <= celly + 1; ++y) { var cell = await GetCellDirect(x, y); if (cell != null) { tasks.Add(cell.UpdateInRange(obj, ignoreGuids)); } } } await Task.WhenAll(tasks); }
public async Task Deactivate() { var map = _GetMap(); if (map == null) throw new Exception("Attempting to activate a cell which has no map"); ServerLog.Debug("MapCell", "Deactivating cell {0}, {1}", State.CellX, State.CellY); await map.OnCellDeactivate(this); }
public async Task <MapAddResult> AddObject(IObjectImpl obj) { List <Task> tasks = new List <Task>(); var guid = await obj.GetGUID(); if ((await obj.IsOnMap())) { var currentmap = await obj.GetMap(); if (currentmap != this) { //could be doing a map quick-change await currentmap.RemoveObject(guid, obj); } } if (State.ObjectList.Contains(guid)) { return(MapAddResult.AlreadyOnMap); } var isactivator = await obj.IsCellActivator(); var posx = await obj.GetPositionX(); var posy = await obj.GetPositionY(); var cellkey = GetCellKey(posx, posy); var cell = await GetCell(cellkey, true); ServerLog.Debug("Map", "Adding {0} to map {1} instance {2} at {3}, {4}", guid.ToUInt64(), State.MapID, State.InstanceID, posx, posy); if (cell == null) { return(MapAddResult.InvalidPosition); } tasks.Add(obj.SetMap(this)); State.ObjectList.Add(guid); _objectCache.Add(guid, obj); tasks.Add(cell.AddObject(guid, obj)); if (isactivator) { State.ActiveObjects.Add(guid); tasks.Add(AddRefCells(posx, posy)); } await Task.WhenAll(tasks); return(MapAddResult.OK); }
public async Task SetRefs(Int64 refs) { var oldrefs = State.Refs; State.Refs = refs; ServerLog.Debug("MapCell", "Setting refs {0} to {1} on {2}, {3}", oldrefs, refs, State.CellX, State.CellY); if (oldrefs == 0 && State.Refs > 0) await Activate(); if (oldrefs > 0 && State.Refs == 0) await Deactivate(); }
public static T ToObject <T>(Dictionary <string, object> dict) { object obj = Activator.CreateInstance(typeof(T)); var type = typeof(T); var tests = type.GetFields(BindingFlags.Instance | BindingFlags.Public); foreach (var tmp in dict) { if (tmp.Value is DBNull) { continue; //nothing to see here } var objField = type.GetField(tmp.Key, BindingFlags.Instance | BindingFlags.Public); if (objField != null) { var objFieldType = objField.FieldType; try { objField.SetValue(obj, Convert.ChangeType(tmp.Value, objFieldType)); } catch (Exception e) { ServerLog.Debug("MySQLHelper", "Exception setting {0} to {1} in {2}, details:\n{3}", tmp.Key, tmp.Value, type.ToString(), e.ToString()); } } else { ServerLog.Debug("MySQLHelper", "Cannot set {0} to {1} in type {2} as field does not exist", tmp.Key, tmp.Value, type.ToString()); } } return((T)obj); }
public async Task Load(string path) { await Task.Factory.StartNew(() => { LoadImpl(path); }); ServerLog.Debug("DBCStore", "Loaded {0} entries from {1}", NumRecords, path); }
public async Task Load(string constring) { await LoadImpl(await CreateConnection(constring)); ServerLog.Debug("DataStore", "Loaded {0} entries from {1}", NumRecords, TableName); }