internal SerializableCustomEntity(string typeName, CustomEntityCore core, IList <CustomEntityComponent> components, string playerUid) : base(null) { this.MyTypeName = typeName; this.Core = core; this.Components = components; this.OwnerPlayerUID = playerUid; this.OwnerPlayerWho = PlayerIdentityHelpers.GetPlayerByProperId(playerUid)?.whoAmI ?? -1; }
internal static CustomEntity CreateRaw(Type mytype, CustomEntityCore core, IList <CustomEntityComponent> components, string ownerUid = "") { var ent = (CustomEntity)Activator.CreateInstance(mytype, BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { }, null); ent.Core = core; ent.Components = components; ent.OwnerPlayerWho = -1; ent.OwnerPlayerUID = ownerUid; Player plr = PlayerIdentityHelpers.GetPlayerByProperId(ownerUid); if (plr != null) { ent.OwnerPlayerWho = plr.whoAmI; } ent.OnClone(); return(ent); }
//////////////// internal void RefreshOwnerWho() { if (Main.netMode == 1) { throw new HamstarException("No client."); } if (string.IsNullOrEmpty(this.OwnerPlayerUID)) { this.OwnerPlayerWho = -1; return; } Player ownerPlr = PlayerIdentityHelpers.GetPlayerByProperId(this.OwnerPlayerUID); if (ownerPlr == null) { LogHelpers.Alert("No player found with UID " + this.OwnerPlayerUID); } this.OwnerPlayerWho = ownerPlr == null ? -1 : ownerPlr.whoAmI; }