public virtual void SetPosition(short x,short y,sbyte level,Direction direction,VMContext context) { if (MultitileGroup != null) { MultitileGroup.ChangePosition(x,y,level,direction,context); } else { Direction = direction; if (this is VMGameObject) { context.Blueprint.ChangeObjectLocation((ObjectComponent)WorldUI,(short)x,(short)y,(sbyte)level); } else { Position = new Vector3(x + 0.5f,y + 0.5f,level * 3); } PositionChange(context); } }
private bool TryPlace(VM vm, VMAvatar caller) { if (!vm.TSOState.CanPlaceNewUserObject(vm)) { return(false); } VMStandaloneObjectMarshal state; if ((Data?.Length ?? 0) == 0) { state = null; } else { state = new VMStandaloneObjectMarshal(); try { using (var reader = new BinaryReader(new MemoryStream(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); CreatedGroup.ChangePosition(new LotTilePos(x, y, level), dir, vm.Context, VMPlaceRequestFlags.UserPlacement); if (CreatedGroup.Objects.Count == 0) { return(false); } if (CreatedGroup.BaseObject.Position == LotTilePos.OUT_OF_WORLD) { return(false); } } else { var catalog = Content.Content.Get().WorldCatalog; var item = catalog.GetItemByGUID(GUID); CreatedGroup = vm.Context.CreateObjectInstance(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) { return(false); } } foreach (var obj in CreatedGroup.Objects) { if (obj is VMGameObject) { ((VMTSOObjectState)obj.TSOState).OwnerID = caller.PersistID; } 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) { var index = vm.MyInventory.FindIndex(x => x.ObjectPID == ObjectPID); if (index != -1) { vm.MyInventory.RemoveAt(index); } } vm.SignalChatEvent(new VMChatEvent(caller.PersistID, VMChatEventType.Arch, caller.Name, vm.GetUserIP(caller.PersistID), "placed (from inventory) " + CreatedGroup.BaseObject.ToString() + " at (" + x / 16f + ", " + y / 16f + ", " + level + ")" )); return(true); }
public VMMultitileGroup CreateObjectInstance(UInt32 GUID, LotTilePos pos, Direction direction, short MainStackOBJ, short MainParam, bool ghostImage) { VMMultitileGroup group = new VMMultitileGroup(); var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(GUID); if (objDefinition == null) { return(null); } var master = objDefinition.OBJ.MasterID; if (master != 0 && objDefinition.OBJ.SubIndex == -1) { group.MultiTile = true; var objd = objDefinition.Resource.List <OBJD>(); for (int i = 0; i < objd.Count; i++) { if (objd[i].MasterID == master && objd[i].SubIndex != -1) //if sub-part of this object, make it! { var subObjDefinition = FSO.Content.Content.Get().WorldObjects.Get(objd[i].GUID); if (subObjDefinition != null) { var worldObject = new ObjectComponent(subObjDefinition); var vmObject = new VMGameObject(subObjDefinition, worldObject); vmObject.GhostImage = ghostImage; if (UseWorld) { Blueprint.AddObject(worldObject); } vmObject.MasterDefinition = objDefinition.OBJ; vmObject.UseTreeTableOf(objDefinition); vmObject.MainParam = MainParam; vmObject.MainStackOBJ = MainStackOBJ; group.AddObject(vmObject); vmObject.MultitileGroup = group; if (!ghostImage) { VM.AddEntity(vmObject); } } } } group.Init(this); VMPlacementError couldPlace = group.ChangePosition(pos, direction, this).Status; return(group); } else { if (objDefinition.OBJ.ObjectType == OBJDType.Person) //person { var vmObject = new VMAvatar(objDefinition); vmObject.MultitileGroup = group; group.AddObject(vmObject); vmObject.GhostImage = ghostImage; if (!ghostImage) { VM.AddEntity(vmObject); } if (UseWorld) { Blueprint.AddAvatar((AvatarComponent)vmObject.WorldUI); } vmObject.MainParam = MainParam; vmObject.MainStackOBJ = MainStackOBJ; group.Init(this); vmObject.SetPosition(pos, direction, this); return(group); } else { var worldObject = new ObjectComponent(objDefinition); var vmObject = new VMGameObject(objDefinition, worldObject); vmObject.MultitileGroup = group; group.AddObject(vmObject); vmObject.GhostImage = ghostImage; if (!ghostImage) { VM.AddEntity(vmObject); } if (UseWorld && Blueprint != null) { Blueprint.AddObject(worldObject); } vmObject.MainParam = MainParam; vmObject.MainStackOBJ = MainStackOBJ; group.Init(this); vmObject.SetPosition(pos, direction, this); return(group); } } }
public virtual VMPlacementResult SetPosition(LotTilePos pos,Direction direction,VMContext context) { return(MultitileGroup.ChangePosition(pos,direction,context)); }
public VMEntity CreateObjectInstance(UInt32 GUID, short x, short y, sbyte level, Direction direction) { var objDefinition = TSO.Content.Content.Get().WorldObjects.Get(GUID); if (objDefinition == null) { return(null); } var master = objDefinition.OBJ.MasterID; if (master != 0) { var objd = objDefinition.Resource.List <OBJD>(); VMMultitileGroup group = new VMMultitileGroup(); for (int i = 0; i < objd.Count; i++) { if (objd[i].MasterID == master && objd[i].SubIndex != -1) //if sub-part of this object, make it! { var subObjDefinition = TSO.Content.Content.Get().WorldObjects.Get(objd[i].GUID); if (subObjDefinition != null) { var worldObject = new ObjectComponent(subObjDefinition); var vmObject = new VMGameObject(subObjDefinition, worldObject); vmObject.MasterDefinition = objDefinition.OBJ; vmObject.UseTreeTableOf(objDefinition); group.Objects.Add(vmObject); VM.AddEntity(vmObject); vmObject.MultitileGroup = group; } } } group.ChangePosition(x, y, level, direction, this); return((VMGameObject)group.Objects[0]); } else { if (objDefinition.OBJ.ObjectType == OBJDType.Person) //person { var vmObject = new VMAvatar(objDefinition); VM.AddEntity(vmObject); //this.InitWorldComponent(vmObject.WorldUI); Blueprint.AddAvatar((AvatarComponent)vmObject.WorldUI); vmObject.SetPosition(x, y, level, direction, this); return(vmObject); } else { var worldObject = new ObjectComponent(objDefinition); var vmObject = new VMGameObject(objDefinition, worldObject); VM.AddEntity(vmObject); vmObject.SetPosition(x, y, level, direction, this); return(vmObject); } } }
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); }