void Catalog_OnSelectionChange(int selection) { var item = CurrentCategory[selection]; if (LotController.ActiveEntity != null && item.Price > LotController.ActiveEntity.TSOState.Budget.Value) { HIT.HITVM.Get().PlaySoundEvent(Model.UISounds.Error); return; } if (OldSelection != -1) { Catalog.SetActive(OldSelection, false); } Catalog.SetActive(selection, true); BuyItem = vm.Context.CreateObjectInstance(item.GUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true); if (BuyItem == null) { return; //uh } QueryPanel.SetInfo(LotController.vm, BuyItem.Objects[0], false); QueryPanel.Mode = 1; QueryPanel.Tab = 0; QueryPanel.Active = true; Holder.SetSelected(BuyItem); OldSelection = selection; }
public void RegisterMultitilePersist(VMMultitileGroup mul, uint persistID) { if (persistID != 0) { MultitileByPersist[persistID] = mul; } }
public void MoveToInventory(VM vm, VMMultitileGroup obj, VMAsyncInventorySaveCallback callback, bool runSync) { var objectPID = obj.BaseObject.PersistID; var objb = obj.BaseObject; uint guid = objb.Object.OBJ.GUID; if (objb.MasterDefinition != null) { guid = objb.MasterDefinition.GUID; } var isNew = objectPID == 0; var state = new VMStandaloneObjectMarshal(obj); var dbState = GenerateObjectPersist(obj); dbState.lot_id = null; //we're removing this object from the lot if (runSync) { SaveInventoryState(isNew, objectPID, state, dbState, guid, callback, true); } else { Host.InBackground(() => { SaveInventoryState(isNew, objectPID, state, dbState, guid, callback, false); }); } }
void Catalog_OnSelectionChange(int selection) { Holder.ClearSelected(); var item = CurrentCategory[selection]; if (OldSelection != -1) { Catalog.SetActive(OldSelection, false); } Catalog.SetActive(selection, true); if (LotController.CustomControl != null) { LotController.CustomControl.Release(); LotController.CustomControl = null; } if (item.Special != null) { QueryPanel.Active = false; LotController.CustomControl = (UICustomLotControl)Activator.CreateInstance(item.Special.Control, vm, LotController.World, LotController, item.Special.Parameters); } else { BuyItem = vm.Context.CreateObjectInstance(item.GUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true); QueryPanel.SetInfo(BuyItem.Objects[0], false); QueryPanel.Mode = 1; QueryPanel.Tab = 0; QueryPanel.Active = true; Holder.SetSelected(BuyItem); } OldSelection = selection; }
public void SetSelected(VMMultitileGroup Group) { if (Holding != null) { ClearSelected(); } Holding = new UIObjectSelection(); Holding.Group = Group; Holding.PreviousTile = Holding.Group.BaseObject.Position; Holding.Dir = Group.Objects[0].Direction; VMEntity[] CursorTiles = new VMEntity[Group.Objects.Count]; for (int i = 0; i < Group.Objects.Count; i++) { var target = Group.Objects[i]; target.SetRoom(65534); if (target is VMGameObject) { ((ObjectComponent)target.WorldUI).ForceDynamic = true; } CursorTiles[i] = vm.Context.CreateObjectInstance(0x00000437, new LotTilePos(target.Position), FSO.LotView.Model.Direction.NORTH, true).Objects[0]; CursorTiles[i].SetPosition(new LotTilePos(0, 0, 1), Direction.NORTH, vm.Context); ((ObjectComponent)CursorTiles[i].WorldUI).ForceDynamic = true; } Holding.TilePosOffset = new Vector2(0, 0); Holding.CursorTiles = CursorTiles; }
public void SetGUIDLocal(uint id, VM TempVM) { oldGUID = id; GUID = id; if (TempVM != null) { if (TargetOBJ != null) { TargetOBJ.Delete(TempVM.Context); } //create our master, center camera on target object var objDefinition = FSO.Content.Content.Get().WorldObjects.Get(GUID); if (objDefinition != null) { var masterID = id; var notMaster = objDefinition.OBJ.MasterID != 0 && objDefinition.OBJ.SubIndex != -1; if (notMaster) { //find the master var master = objDefinition.Resource.List <OBJD>().FirstOrDefault(x => x.MasterID == objDefinition.OBJ.MasterID && x.SubIndex == -1); if (master != null) { masterID = master.GUID; } } TargetOBJ = TempVM.Context.CreateObjectInstance(masterID, LotTilePos.OUT_OF_WORLD, Direction.SOUTH, true); TargetOBJ.SetVisualPosition(new Vector3(0.5f, 0.5f, 0f), Direction.SOUTH, TempVM.Context); TempVM.Entities = TargetOBJ.Objects; if (TargetOBJ == null) { return; } TargetTile = TargetOBJ.Objects.FirstOrDefault(x => x.Object.OBJ.GUID == id); if (TargetTile == null) { TargetTile = TargetOBJ.BaseObject; } if (TargetTile == null) { TargetOBJ = null; return; } var tile = TargetTile.VisualPosition; TempVM.Context.World.State.CenterTile = new Vector2(tile.X, tile.Y) - new Vector2(2.5f, 2.5f); foreach (var obj in TargetOBJ.Objects) { if (obj is VMGameObject) { ((ObjectComponent)obj.WorldUI).RenderInfo.Layer = WorldObjectRenderLayer.DYNAMIC; } if (notMaster && obj.Object.OBJ.GUID != id) { obj.SetRoom(2); } } } } }
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) { ((VMTSOObjectState)obj.TSOState).OwnerID = caller.PersistID; } } } 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); }
public UIGrassPaint(VM vm, LotView.World world, UILotControl parent, List <int> parameters) { this.vm = vm; World = parent.World; Parent = parent; WallCursor = vm.Context.CreateObjectInstance(0x2F39B7A6, LotTilePos.OUT_OF_WORLD, FSO.LotView.Model.Direction.NORTH, true); ((ObjectComponent)WallCursor.Objects[0].WorldUI).ForceDynamic = true; }
/// <summary> /// Creates an instance of this (multitile) object in the target VM, out of world. /// </summary> /// <param name="vm"></param> public VMMultitileGroup CreateInstance(VM vm, bool ghost) { int i = 0; var objs = new VMEntity[Entities.Length]; foreach (var ent in Entities) { VMEntity realEnt; var objDefinition = Content.GameContent.Get.WorldObjects.Get(ent.GUID); var worldObject = vm.Context.MakeObjectComponent(objDefinition); var obj = new VMGameObject(objDefinition, worldObject); obj.Load((VMGameObjectMarshal)ent); obj.Contained = new VMEntity[ent.Contained.Length]; //we aren't loading slot data, but we need to initialize this. obj.Position = LotTilePos.OUT_OF_WORLD; if (VM.UseWorld) { vm.Context.Blueprint.AddObject((ObjectComponent)obj.WorldUI); vm.Context.Blueprint.ChangeObjectLocation((ObjectComponent)obj.WorldUI, obj.Position); } realEnt = obj; obj.FetchTreeByName(vm.Context); if (!ghost) { obj.Thread = new VMThread(vm.Context, obj, obj.Object.OBJ.StackSize); vm.AddEntity(obj); } else { objs[i] = obj; } obj.GhostImage = ghost; MultitileGroup.Objects[i++] = obj.ObjectID; //update saved group, in multitile group order (as saved) if (VM.UseWorld) { obj.WorldUI.ObjectID = obj.ObjectID; } if (!ghost) { vm.Scheduler.ScheduleTickIn(obj, 1); } } VMMultitileGroup multi; if (ghost) { multi = new VMMultitileGroup(); multi.LoadGhost(MultitileGroup, vm.Context, objs); } else { multi = new VMMultitileGroup(MultitileGroup, vm.Context); } return(multi); //should self register }
public static Texture2D GenerateThumb(VMMultitileGroup obj, VM vm) { var gd = GameFacade.GraphicsDevice; var objects = obj.Objects; ObjectComponent[] objComps = new ObjectComponent[objects.Count]; for (int i = 0; i < objects.Count; i++) { objComps[i] = (ObjectComponent)objects[i].WorldUI; } var thumb = vm.Context.World.GetObjectThumb(objComps, obj.GetBasePositions(), GameFacade.GraphicsDevice); var data = new Color[thumb.Width * thumb.Height]; thumb.GetData(data); thumb.Dispose(); var newAgain = new Texture2D(GameFacade.GraphicsDevice, thumb.Width, thumb.Height, true, SurfaceFormat.Color); TextureUtils.UploadWithMips(newAgain, GameFacade.GraphicsDevice, data); var sb = new SpriteBatch(GameFacade.GraphicsDevice); var result = new RenderTarget2D(GameFacade.GraphicsDevice, 74, 37); var oldRts = gd.GetRenderTargets(); gd.SetRenderTarget(result); gd.Clear(Color.Black); sb.Begin(blendState: BlendState.AlphaBlend); var minScale = Math.Min(37f / newAgain.Width, 37f / newAgain.Height); if (minScale > 1) { minScale = 1; } var rect = new Rectangle( (int)(newAgain.Width * minScale / -2 + 18), (int)(newAgain.Height * minScale / -2 + 19), (int)(minScale * newAgain.Width), (int)(minScale * newAgain.Height)); var px = TextureGenerator.GetPxWhite(GameFacade.GraphicsDevice); sb.Draw(px, new Rectangle(0, 0, 37, 37), new Color(56, 88, 120)); sb.Draw(px, new Rectangle(37, 0, 37, 37), new Color(184, 212, 240)); sb.Draw(newAgain, rect, Color.White); rect.Offset(37, 0); sb.Draw(newAgain, rect, Color.White); sb.End(); gd.SetRenderTargets(oldRts); newAgain.Dispose(); return(result); }
public UITerrainFlatten(VM vm, World world, UILotControl parent, List <int> parameters) { this.vm = vm; World = parent.World; Parent = parent; WallCursor = vm.Context.CreateObjectInstance(0x2F39B7A6, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true); WallCursor2 = vm.Context.CreateObjectInstance(0x2F39B7A6, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true); ((ObjectComponent)WallCursor.Objects[0].WorldUI).ForceDynamic = true; ((ObjectComponent)WallCursor2.Objects[0].WorldUI).ForceDynamic = true; }
public void SetSelected(VMMultitileGroup Group) { if (Holding != null) { ClearSelected(); } Holding = new UIObjectSelection(); Holding.Group = Group; Holding.PreviousTile = Holding.Group.BaseObject.Position; Holding.Dir = Group.Objects[0].Direction; VMEntity[] CursorTiles = new VMEntity[Group.Objects.Count]; for (int i = 0; i < Group.Objects.Count; i++) { var target = Group.Objects[i]; target.ExecuteEntryPoint(10, vm.Context, true, target); target.SetRoom(65534); if (target is VMGameObject) { ((ObjectComponent)target.WorldUI).ForceDynamic = true; } CursorTiles[i] = vm.Context.CreateObjectInstance(0x00000437, new LotTilePos(target.Position), FSO.LotView.Model.Direction.NORTH, true).Objects[0]; CursorTiles[i].SetPosition(new LotTilePos(0, 0, 1), Direction.NORTH, vm.Context); CursorTiles[i].SetRoom(65535); ((ObjectComponent)CursorTiles[i].WorldUI).ForceDynamic = true; } Holding.TilePosOffset = new Vector2(0, 0); Holding.CursorTiles = CursorTiles; uint guid; var bobj = Group.BaseObject; guid = bobj.Object.OBJ.GUID; if (bobj.MasterDefinition != null) { guid = bobj.MasterDefinition.GUID; } var catalogItem = Content.Content.Get().WorldCatalog.GetItemByGUID(guid); if (catalogItem != null) { var price = Group.InitialPrice; //(int)catalogItem.Value.Price; var dcPercent = VMBuildableAreaInfo.GetDiscountFor(catalogItem.Value, vm); var finalPrice = (price * (100 - dcPercent)) / 100; if (DonateMode) { finalPrice -= (finalPrice * 2) / 3; } Holding.Price = finalPrice; Group.InitialPrice = finalPrice; Group.BeforeDCPrice = price; } }
public UIWallPainter(VM vm, LotView.World world, UILotControl parent, List <int> parameters) { Pattern = (ushort)parameters[0]; this.vm = vm; World = parent.World; Parent = parent; WallCursor = vm.Context.CreateObjectInstance(0x00000439, LotTilePos.OUT_OF_WORLD, FSO.LotView.Model.Direction.NORTH, true); ((ObjectComponent)WallCursor.Objects[0].WorldUI).ForceDynamic = true; Commands = new List <VMArchitectureCommand>(); SetCursorGraphic(2); }
void Catalog_OnSelectionChange(int selection) { Holder.ClearSelected(); var item = CurrentCategory[selection]; if (LotController.ActiveEntity != null && item.Price > LotController.ActiveEntity.TSOState.Budget.Value) { TSO.HIT.HITVM.Get().PlaySoundEvent(UISounds.Error); return; } if (OldSelection != -1) { Catalog.SetActive(OldSelection, false); } Catalog.SetActive(selection, true); if (LotController.CustomControl != null) { LotController.CustomControl.Release(); LotController.CustomControl = null; } if (item.Special != null) { var res = item.Special.Res; var resID = item.Special.ResID; QueryPanel.SetInfo(res.GetIcon(resID), res.GetName(resID), res.GetDescription(resID), res.GetPrice(resID)); QueryPanel.Mode = 1; QueryPanel.Tab = 0; QueryPanel.Active = true; LotController.CustomControl = (UICustomLotControl)Activator.CreateInstance(item.Special.Control, vm, LotController.World, LotController, item.Special.Parameters); } else { BuyItem = vm.Context.CreateObjectInstance(item.GUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true); if (BuyItem != null) { QueryPanel.SetInfo(LotController.vm, BuyItem.Objects[0], false); QueryPanel.Mode = 1; QueryPanel.Tab = 0; QueryPanel.Active = true; Holder.SetSelected(BuyItem); } } OldSelection = selection; }
public void UpdateObjectPersist(VM vm, VMMultitileGroup obj, VMAsyncInventorySaveCallback callback) { var objectPID = obj.BaseObject.PersistID; var dbState = GenerateObjectPersist(obj); Host.InBackground(() => { using (var db = DAFactory.Get()) { //todo: race where inventory object could potentially be placed on the lot before the old instance of it is deleted //probably just block objects with same persist id from being placed. db.Objects.UpdatePersistState(objectPID, dbState); callback(true, objectPID); } }); }
public VMStandaloneObjectMarshal(VMMultitileGroup group) { if (group.BaseObject is VMAvatar) { return; //do not attempt to create standalone object marshals for avatars. } Entities = new VMEntityMarshal[group.Objects.Count]; MultitileGroup = group.Save(); int i = 0; foreach (var ent in group.Objects) { var sent = ((VMGameObject)ent).Save(); sent.Contained = new short[sent.Contained.Length]; Entities[i++] = sent; } }
void Catalog_OnSelectionChange(int selection) { if (OldSelection != -1) { Catalog.SetActive(OldSelection, false); } Catalog.SetActive(selection, true); BuyItem = vm.Context.CreateObjectInstance(CurrentCategory[selection].GUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true); if (BuyItem == null) { return; //uh } QueryPanel.SetInfo(BuyItem.Objects[0], false); QueryPanel.Mode = 1; QueryPanel.Tab = 0; QueryPanel.Active = true; Holder.SetSelected(BuyItem); OldSelection = selection; }
public VMMultitileGroup GhostCopyGroup(VMMultitileGroup group) { var newGroup = CreateObjectInstance(((group.MultiTile) ? group.BaseObject.MasterDefinition.GUID : group.BaseObject.Object.OBJ.GUID), LotTilePos.OUT_OF_WORLD, group.BaseObject.Direction, true); if (newGroup != null) { for (int i = 0; i < Math.Min(newGroup.Objects.Count, group.Objects.Count); i++) { newGroup.Objects[i].SetValue(VMStackObjectVariable.Graphic, group.Objects[i].GetValue(VMStackObjectVariable.Graphic)); newGroup.Objects[i].DynamicSpriteFlags = group.Objects[i].DynamicSpriteFlags; newGroup.Objects[i].SetDynamicSpriteFlag(0, group.Objects[i].IsDynamicSpriteFlagSet(0)); if (newGroup.Objects[i] is VMGameObject) { ((VMGameObject)newGroup.Objects[i]).RefreshGraphic(); } } } return(newGroup); }
public void SetSelected(VMMultitileGroup Group) { if (Holding != null) { ClearSelected(); } Holding = new UIObjectSelection(); Holding.Group = Group; Holding.PreviousTile = Holding.Group.BaseObject.Position; Holding.Dir = Group.Objects[0].Direction; VMEntity[] CursorTiles = new VMEntity[Group.Objects.Count]; for (int i = 0; i < Group.Objects.Count; i++) { var target = Group.Objects[i]; target.SetRoom(65534); if (target is VMGameObject) { ((ObjectComponent)target.WorldUI).ForceDynamic = true; } CursorTiles[i] = vm.Context.CreateObjectInstance(0x00000437, new LotTilePos(target.Position), FSO.LotView.Model.Direction.NORTH, true).Objects[0]; CursorTiles[i].SetPosition(new LotTilePos(0, 0, 1), Direction.NORTH, vm.Context); ((ObjectComponent)CursorTiles[i].WorldUI).ForceDynamic = true; } Holding.TilePosOffset = new Vector2(0, 0); Holding.CursorTiles = CursorTiles; uint guid; var bobj = Group.BaseObject; guid = bobj.Object.OBJ.GUID; if (bobj.MasterDefinition != null) { guid = bobj.MasterDefinition.GUID; } var catalogItem = Content.Content.Get().WorldCatalog.GetItemByGUID(guid); if (catalogItem != null) { Holding.Price = (int)catalogItem.Price; } }
public void SetGUIDLocal(uint id) { oldGUID = id; GUID = id; if (TempVM != null) { if (TargetOBJ != null) { TargetOBJ.Delete(TempVM.Context); } TargetOBJ = TempVM.Context.CreateObjectInstance(GUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true); if (TargetOBJ != null && TargetOBJ.BaseObject is VMGameObject) { UpdateThumb(); } else { Thumb = null; } } }
private DbObject GenerateObjectPersist(VMMultitileGroup obj) { var bobj = obj.BaseObject; uint?owner = ((VMTSOObjectState)obj.BaseObject.TSOState).OwnerID; if (owner == 0) { owner = null; } return(new DbObject() { object_id = obj.BaseObject.PersistID, owner_id = owner, lot_id = Context.DbId, dyn_obj_name = obj.Name, graphic = (ushort)bobj.GetValue(VMStackObjectVariable.Graphic), value = (uint)obj.Price, dyn_flags_1 = bobj.DynamicSpriteFlags, dyn_flags_2 = bobj.DynamicSpriteFlags2, //type and shard id never need to be updated. }); }
public UIWallPlacer(VM vm, LotView.World world, ILotControl parent, List <int> parameters) { Pattern = (ushort)parameters[0]; Style = (ushort)parameters[1]; if (Style == 1) { DrawPattern = 255; DrawStyle = 255; } else { DrawPattern = Pattern; DrawStyle = Style; } this.vm = vm; World = parent.World; Parent = parent; WallCursor = vm.Context.CreateObjectInstance(0x00000439, LotTilePos.OUT_OF_WORLD, FSO.LotView.Model.Direction.NORTH, true); ((ObjectComponent)WallCursor.Objects[0].WorldUI).ForceDynamic = true; }
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 void MoveToInventory(VM vm, VMMultitileGroup obj, VMAsyncInventorySaveCallback callback) { MoveToInventory(vm, obj, callback, false); }
//0: up //1: down //2: error //3: anchor //4: level public void SetCursorGraphic(short id, VMMultitileGroup group) { group.Objects[0].SetValue(VMStackObjectVariable.Graphic, id); ((VMGameObject)group.Objects[0]).RefreshGraphic(); }
public void UpdateObjectPersist(VM vm, VMMultitileGroup obj, VMAsyncInventorySaveCallback callback) { }
public void PurchaseFromOwner(VM vm, VMMultitileGroup obj, uint purchaserPID, VMAsyncInventorySaveCallback callback, VMAsyncTransactionCallback tcallback) { callback(true, obj.BaseObject.PersistID); //todo: nice stub for this using database? }
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 void PurchaseFromOwner(VM vm, VMMultitileGroup obj, uint purchaserPID, VMAsyncInventorySaveCallback callback, VMAsyncTransactionCallback tcallback) { var objectPID = obj.BaseObject.PersistID; var objb = obj.BaseObject; uint guid = objb.Object.OBJ.GUID; if (objb.MasterDefinition != null) { guid = objb.MasterDefinition.GUID; } var isNew = objectPID == 0; var state = new VMStandaloneObjectMarshal(obj); var dbState = GenerateObjectPersist(obj); var salePrice = obj.SalePrice; var owner = ((VMTSOObjectState)objb.TSOState).OwnerID; //object will stay on lot for now. Host.InBackground(() => { using (var da = DAFactory.Get()) { SaveInventoryState(isNew, objectPID, state, dbState, guid, (bool success, uint objPID) => { if (success) { //todo: transaction-ify this whole thing? might need a large scale rollback... var tresult = da.Avatars.Transaction(purchaserPID, owner, salePrice, 0); if (tresult == null) { tresult = new Database.DA.Avatars.DbTransactionResult() { success = false } } ; //update the budgets of the respective characters. var finalAmount = salePrice; tcallback(tresult.success, tresult.amount, purchaserPID, (uint)tresult.source_budget, owner, (uint)tresult.dest_budget); if (tresult.success) { dbState.owner_id = purchaserPID; dbState.lot_id = null; da.Objects.UpdatePersistState(objPID, dbState); //perform the final object transfer. todo: logging callback(true, objPID); } else { callback(false, objPID); } } else { callback(false, objPID); } }, true); } }); }
public void MoveToInventory(VM vm, VMMultitileGroup obj, VMAsyncInventorySaveCallback callback) { callback(true, obj.BaseObject.PersistID); //todo: nice stub for this using database? }