private bool TryPlace(VM vm, VMAvatar caller) { var internalMode = caller == null; if (Mode != PurchaseMode.Donate && !vm.PlatformState.CanPlaceNewUserObject(vm)) { return(false); } if (Mode == PurchaseMode.Donate && !vm.PlatformState.CanPlaceNewDonatedObject(vm)) { return(false); } VMStandaloneObjectMarshal state; var catalog = Content.Content.Get().WorldCatalog; var item = catalog.GetItemByGUID(Info.GUID); if (caller != null && (item?.DisableLevel ?? 0) > 2) { //object cannot be placed (disable level 3) return(false); } if ((Info.Data?.Length ?? 0) == 0) { state = null; } else { state = new VMStandaloneObjectMarshal(); try { using (var reader = new BinaryReader(new MemoryStream(Info.Data))) { state.Deserialize(reader); } foreach (var e in state.Entities) { ((VMGameObjectMarshal)e).Disabled = 0; } } catch (Exception) { //failed to restore state state = null; } } if (state != null) { CreatedGroup = state.CreateInstance(vm, false); CreatedGroup.ChangePosition(new LotTilePos(x, y, level), dir, vm.Context, VMPlaceRequestFlags.UserPlacement); CreatedGroup.ExecuteEntryPoint(11, vm.Context); //User Placement if (CreatedGroup.Objects.Count == 0) { return(false); } if (CreatedGroup.BaseObject.Position == LotTilePos.OUT_OF_WORLD && !internalMode) { return(false); } } else { CreatedGroup = vm.Context.CreateObjectInstance(Info.GUID, LotTilePos.OUT_OF_WORLD, dir); if (CreatedGroup == null) { return(false); } CreatedGroup.ChangePosition(new LotTilePos(x, y, level), dir, vm.Context, VMPlaceRequestFlags.UserPlacement); CreatedGroup.ExecuteEntryPoint(11, vm.Context); //User Placement if (CreatedGroup.Objects.Count == 0) { return(false); } if (CreatedGroup.BaseObject.Position == LotTilePos.OUT_OF_WORLD && !internalMode) { return(false); } } foreach (var obj in CreatedGroup.Objects) { var tsostate = (obj.PlatformState as VMTSOObjectState); if (tsostate != null) { if (caller != null) { tsostate.OwnerID = caller.PersistID; } bool reinitRequired = false; if (Info.UpgradeLevel > tsostate.UpgradeLevel) { tsostate.UpgradeLevel = Info.UpgradeLevel; reinitRequired = true; } obj.UpdateTuning(vm); if (reinitRequired) { VMNetUpgradeCmd.TryReinit(obj, vm, tsostate.UpgradeLevel); } } obj.PersistID = ObjectPID; ((VMGameObject)obj).DisableIfTSOCategoryWrong(vm.Context); } vm.Context.ObjectQueries.RegisterMultitilePersist(CreatedGroup, ObjectPID); //is this my sim's object? try remove it from our local inventory representaton if (((VMTSOObjectState)CreatedGroup.BaseObject.TSOState).OwnerID == vm.MyUID && Info.RestoreType != VMInventoryRestoreType.CopyOOW) { var index = vm.MyInventory.FindIndex(x => x.ObjectPID == ObjectPID); if (index != -1) { vm.MyInventory.RemoveAt(index); } } if (Mode == PurchaseMode.Donate) { //this object should be donated. (CreatedGroup.BaseObject.TSOState as VMTSOObjectState).Donate(vm, CreatedGroup.BaseObject); } if (caller != null) { vm.SignalChatEvent(new VMChatEvent(caller, VMChatEventType.Arch, caller.Name, vm.GetUserIP(caller.PersistID), "placed (from inventory) " + CreatedGroup.BaseObject.ToString() + " at (" + x / 16f + ", " + y / 16f + ", " + level + ")" )); } return(true); }
private bool TryPlace(VM vm, VMAvatar caller) { if (Mode != PurchaseMode.Donate && !vm.PlatformState.CanPlaceNewUserObject(vm)) { return(false); } if (Mode == PurchaseMode.Donate && !vm.PlatformState.CanPlaceNewDonatedObject(vm)) { return(false); } var catalog = Content.Content.Get().WorldCatalog; var item = catalog.GetItemByGUID(GUID); var group = vm.Context.CreateObjectInstance(GUID, LotTilePos.OUT_OF_WORLD, dir); if (group == null) { return(false); } group.ChangePosition(new LotTilePos(x, y, level), dir, vm.Context, VMPlaceRequestFlags.UserPlacement); group.ExecuteEntryPoint(11, vm.Context); //User Placement if (group.Objects.Count == 0) { return(false); } if (group.BaseObject.Position == LotTilePos.OUT_OF_WORLD) { group.Delete(vm.Context); return(false); } if (!vm.TS1) { foreach (var obj in group.Objects) { if (obj is VMGameObject) { var state = ((VMTSOObjectState)obj.TSOState); state.OwnerID = caller.PersistID; if (TargetUpgradeLevel > 0) { state.UpgradeLevel = TargetUpgradeLevel; obj.UpdateTuning(vm); VMNetUpgradeCmd.TryReinit(obj, vm, TargetUpgradeLevel); } } } } CreatedGroup = group; if (Mode == PurchaseMode.Donate) { //this object should be donated. (CreatedGroup.BaseObject.TSOState as VMTSOObjectState).Donate(vm, CreatedGroup.BaseObject); } vm.SignalChatEvent(new VMChatEvent(caller, VMChatEventType.Arch, caller?.Name ?? "Unknown", vm.GetUserIP(caller?.PersistID ?? 0), "placed " + group.BaseObject.ToString() + " at (" + x / 16f + ", " + y / 16f + ", " + level + ")" )); return(true); }