/// <summary> /// Gets a reference to a server game object currently in memory, i.e. previously loaded from the DB. /// </summary> /// <param name="id">id of the object being returned</param> /// <returns></returns> public ServerGameObject GetItem(Guid id, ServerGameObjectManager gom, bool includeDeleted = false) { ServerGameObject sgo = gom.GetGameObjectFromId(id) as ServerGameObject; if (sgo == null || (!includeDeleted && sgo.IsDeleted)) { return(null); } return(sgo); }
/// <summary> /// Loads an Item from the DB /// </summary> /// <param name="owner">owning account</param> /// <param name="id">the id for the Item to get</param> /// <returns></returns> public ServerGameObject LoadItem(Guid id, bool includeDeleted, string lockedByServerId, ref string rsultMsg, ServerGameObjectManager gom) { if (id == Guid.Empty) { return(null); } SqlConnection con = null; SqlTransaction tran = null; ServerGameObject sgo = null; if (gom != null) { sgo = gom.GetGameObjectFromId(id) as ServerGameObject; if (sgo != null) { return(sgo); } } try { Guid cown = Guid.Empty; if (DB.Instance.Item_Load(out sgo, id, includeDeleted, lockedByServerId, out tran, out con)) { ((ServerGameObject)sgo).IsDirty = false; ((ServerGameObject)sgo).IsGhost = false; tran.Commit(); bool isDeleted = false; isDeleted = ((ServerGameObject)sgo).IsDeleted; if (!isDeleted && lockedByServerId != null && lockedByServerId.Length > 0) { if (gom != null) { gom.RegisterGameObject(sgo, sgo.Context); } } } else { rsultMsg = "Item doesn't exist."; return(null); } } catch (Exception e) { return(null); } finally { if (con != null) { con.Close(); con.Dispose(); con = null; } if (tran != null) { tran.Dispose(); tran = null; } } return(sgo); }