public override bool Verify(VM vm, VMAvatar caller)
        {
            if (Verified)
            {
                return(true);     //set internally when transaction succeeds. trust that the verification happened.
            }
            if (caller == null || //caller must be on lot, have owner permissions
                ((VMTSOAvatarState)caller.TSOState).Permissions < VMTSOAvatarPermissions.Owner)
            {
                return(false);
            }

            var exState   = vm.TSOState.Size;
            var exSize    = exState & 255;
            var exStories = (exState >> 8) & 255;

            LotSize    = Math.Min(LotSize, (byte)(VMBuildableAreaInfo.BuildableSizes.Length - 1));
            LotStories = Math.Min(LotStories, (byte)3);

            if ((exSize == LotSize && exStories == LotStories) || LotSize < exSize || LotStories < exStories)
            {
                //cannot size down. cannot stay same size (no-op)
                return(false);
            }
            else
            {
                var totalOld    = exSize + exStories;
                var totalTarget = LotSize + LotStories;
                var baseCost    = VMBuildableAreaInfo.CalculateBaseCost(totalOld, totalTarget);
                var roomieCost  = VMBuildableAreaInfo.CalculateRoomieCost(vm.TSOState.Roommates.Count, totalOld, totalTarget);

                //perform the transaction. If it succeeds, requeue the command
                vm.GlobalLink.PerformTransaction(vm, false, caller.PersistID, uint.MaxValue, baseCost + roomieCost,
                                                 (bool success, int transferAmount, uint uid1, uint budget1, uint uid2, uint budget2) =>
                {
                    if (success)
                    {
                        Verified = true;
                        vm.ForwardCommand(this);
                    }
                    vm.SendCommand(new VMNetAsyncResponseCmd(0, new VMTransferFundsState
                    {     //update budgets on clients. id of 0 means there is no target thread.
                        Responded      = true,
                        Success        = success,
                        TransferAmount = transferAmount,
                        UID1           = uid1,
                        Budget1        = budget1,
                        UID2           = uid2,
                        Budget2        = budget2
                    }));
                });
                return(false);
            }
        }
Exemple #2
0
        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;
            }
        }
Exemple #3
0
        public void SetPage(int page)
        {
            if (CatalogItems != null)
            {
                for (int i = 0; i < CatalogItems.Length; i++)
                {
                    Remove(CatalogItems[i]);
                }
            }

            int index = page * PageSize;

            if (Selected == null)
            {
                return;
            }
            CatalogItems = new UICatalogItem[Math.Min(PageSize, Math.Max(Selected.Count - index, 0))];
            int halfPage = PageSize / 2;

            for (int i = 0; i < CatalogItems.Length; i++)
            {
                var sel  = Selected[index++];
                var elem = new UICatalogItem(false);
                if (sel.Item.GUID == uint.MaxValue)
                {
                    elem.Visible = false;
                }
                elem.Index          = index - 1;
                elem.Info           = sel;
                elem.Info.CalcPrice = (int)elem.Info.Item.Price;

                if (elem.Info.Item.GUID != 0)
                {
                    var price      = (int)elem.Info.Item.Price;
                    var dcPercent  = VMBuildableAreaInfo.GetDiscountFor(elem.Info.Item, ActiveVM);
                    var finalPrice = price * (100 - dcPercent) / 100;
                    elem.Info.CalcPrice = finalPrice;
                }

                elem.Icon          = (elem.Info.Special?.Res != null)?elem.Info.Special.Res.GetIcon(elem.Info.Special.ResID):GetObjIcon(elem.Info.Item.GUID);
                elem.Tooltip       = (elem.Info.CalcPrice > 0)?("$" + elem.Info.CalcPrice.ToString()):null;
                elem.X             = i % halfPage * 45 + 2;
                elem.Y             = i / halfPage * 45 + 2;
                elem.OnMouseEvent += new ButtonClickDelegate(InnerSelect);
                elem.SetDisabled(elem.Info.CalcPrice > Budget);
                CatalogItems[i] = elem;
                Add(elem);
            }
            Page = page;
        }
Exemple #4
0
        public void UpdateCost()
        {
            var lotInfo   = LotControl.vm.TSOState;
            var lotSize   = lotInfo.Size & 255;
            var lotFloors = (lotInfo.Size >> 8) & 255;
            var lotDir    = lotInfo.Size >> 16;

            OldLotSize = lotInfo.Size;

            UpdateSizeTarget   = Math.Min(Math.Max(lotSize, UpdateSizeTarget), VMBuildableAreaInfo.BuildableSizes.Length - 1);
            UpdateFloorsTarget = Math.Min(Math.Max(lotFloors, UpdateFloorsTarget), 3);
            var totalTarget = UpdateFloorsTarget + UpdateSizeTarget;
            var totalOld    = lotSize + lotFloors;

            AcceptButton.Disabled = totalTarget == totalOld; //no upgrade selected

            var baseCost   = VMBuildableAreaInfo.CalculateBaseCost(totalOld, totalTarget);
            var roomieCost = VMBuildableAreaInfo.CalculateRoomieCost(lotInfo.Roommates.Count, totalOld, totalTarget);

            if (baseCost + roomieCost > (LotControl.ActiveEntity?.TSOState.Budget.Value ?? 0))
            {
                AcceptButton.Disabled = true;                                                                                //can't afford
            }
            //TODO: read from uiscript
            TotalCostLabel.CaptionStyle.Color = AcceptButton.Disabled?new Color(255, 125, 125):TextStyle.DefaultLabel.Color;

            var targetTiles = VMBuildableAreaInfo.BuildableSizes[UpdateSizeTarget];

            string[][] applyText = new string[][]
            {
                new string[] { },
                new string[] { targetTiles.ToString(), targetTiles.ToString() + "x" + (UpdateFloorsTarget + 2) },
                new string[] { baseCost.ToString() },
                new string[] { roomieCost.ToString() },
                new string[] { (baseCost + roomieCost).ToString() },
                new string[] { Math.Min(8, totalTarget + 1).ToString() },
                new string[] { UpdateSizeTarget + 1 + "+" + UpdateFloorsTarget }
            };

            for (int i = 0; i < Labels.Count; i++)
            {
                Labels[i].Caption = GetArgsString(SavedInitialText[i], applyText[i]);
            }
            TargetSize = LotControl.vm.Context.GetTSOBuildableArea(UpdateSizeTarget | (UpdateFloorsTarget << 8) | (lotDir << 16));
            RenderPreview(VMBuildableAreaInfo.BuildableSizes[lotSize], lotFloors + 2, targetTiles, UpdateFloorsTarget + 2);
        }
Exemple #5
0
        //variables used locally for deferred avatar loading

        public override bool Execute(VM vm)
        {
            if (vm.TS1)
            {
                if (vm.CurrentFamily == null)
                {
                    return(true);
                }
                var gameState = Content.Content.Get().Neighborhood.GameState;
                var control   = vm.Entities.FirstOrDefault(x => x is VMAvatar && !((VMAvatar)x).IsPet && ((VMAvatar)x).GetPersonData(VMPersonDataVariable.TS1FamilyNumber) == vm.CurrentFamily?.ChunkID);
                if (control == null)
                {
                    control = vm.Context.CreateObjectInstance((gameState.DowntownSimGUID == 0)?0x32AA2056:gameState.DowntownSimGUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH)?.BaseObject;
                    control?.SetPosition(LotTilePos.FromBigTile(1, 1, 1), Direction.NORTH, vm.Context);
                }
                if (control != null)
                {
                    var ava = (VMAvatar)control;
                    ava.PersistID = ActorUID;
                    ((VMTSOAvatarState)(ava.TSOState)).Permissions = VMTSOAvatarPermissions.Admin;
                    ava.TSOState.Budget.Value = 1000000;
                    vm.Context.ObjectQueries.RegisterAvatarPersist(ava, ava.PersistID);
                    vm.SetGlobalValue(3, control.ObjectID);
                }
                return(true);
            }

            var name    = AvatarState.Name.Substring(0, Math.Min(AvatarState.Name.Length, 64));
            var sim     = vm.Context.CreateObjectInstance(VMAvatar.TEMPLATE_PERSON, LotTilePos.OUT_OF_WORLD, Direction.NORTH).Objects[0];
            var mailbox = vm.Entities.FirstOrDefault(x => (x.Object.OBJ.GUID == 0xEF121974 || x.Object.OBJ.GUID == 0x1D95C9B0));

            if (VM.UseWorld)
            {
                FSO.HIT.HITVM.Get().PlaySoundEvent("lot_enter");
            }
            if (mailbox != null)
            {
                VMFindLocationFor.FindLocationFor(sim, mailbox, vm.Context, VMPlaceRequestFlags.Default);
            }
            else
            {
                sim.SetPosition(LotTilePos.FromBigTile(3, 3, 1), Direction.NORTH, vm.Context);
            }
            sim.PersistID = ActorUID;

            VMAvatar avatar = (VMAvatar)sim;

            AvatarState.Apply(avatar);

            var oldRoomCount = vm.TSOState.Roommates.Count;

            //some off lot changes may have occurred. Keep things up to date if we're caught between database sync points (TODO: right now never, but should happen on every roomie change).
            if (AvatarState.Permissions > VMTSOAvatarPermissions.Visitor && AvatarState.Permissions < VMTSOAvatarPermissions.Admin)
            {
                if (!vm.TSOState.Roommates.Contains(AvatarState.PersistID))
                {
                    vm.TSOState.Roommates.Add(AvatarState.PersistID);
                    if (AvatarState.Permissions > VMTSOAvatarPermissions.Roommate)
                    {
                        vm.TSOState.BuildRoommates.Add(AvatarState.PersistID);
                    }
                    else
                    {
                        vm.TSOState.BuildRoommates.Remove(AvatarState.PersistID);
                    }
                    VMBuildableAreaInfo.UpdateOverbudgetObjects(vm);
                }
            }
            else if (AvatarState.Permissions != VMTSOAvatarPermissions.Admin)
            {
                if (vm.TSOState.Roommates.Contains(AvatarState.PersistID))
                {
                    vm.TSOState.Roommates.Remove(AvatarState.PersistID);
                    vm.TSOState.BuildRoommates.Remove(AvatarState.PersistID);
                    VMBuildableAreaInfo.UpdateOverbudgetObjects(vm);
                }
            }

            if (oldRoomCount != vm.TSOState.Roommates.Count)
            {
                //mark objects not owned by roommates for inventory transfer
                foreach (var ent in vm.Entities)
                {
                    if (ent is VMGameObject && ent.PersistID > 0 && ((VMTSOObjectState)ent.TSOState).OwnerID == avatar.PersistID)
                    {
                        var old = ((VMGameObject)ent).Disabled;
                        if (AvatarState.Permissions < VMTSOAvatarPermissions.Roommate)
                        {
                            ((VMGameObject)ent).Disabled |= VMGameObjectDisableFlags.PendingRoommateDeletion;
                        }
                        else
                        {
                            ((VMGameObject)ent).Disabled &= ~VMGameObjectDisableFlags.PendingRoommateDeletion;
                        }
                        if (old != ((VMGameObject)ent).Disabled)
                        {
                            vm.Scheduler.RescheduleInterrupt(ent);
                        }
                        ((VMGameObject)ent).RefreshLight();
                    }
                }
            }

            vm.Context.ObjectQueries.RegisterAvatarPersist(avatar, avatar.PersistID);
            if (ActorUID == uint.MaxValue - 1)
            {
                avatar.SetValue(VMStackObjectVariable.Hidden, 1);
                avatar.SetPosition(LotTilePos.OUT_OF_WORLD, Direction.NORTH, vm.Context);
                avatar.SetFlag(VMEntityFlags.HasZeroExtent, true);
                avatar.SetPersonData(VMPersonDataVariable.IsGhost, 1); //oooooOOooooOo
            }

            vm.SignalChatEvent(new VMChatEvent(avatar.PersistID, VMChatEventType.Join, avatar.Name));

            return(true);
        }
Exemple #6
0
        public void SetInfo(VM vm, VMEntity entity, bool bought)
        {
            ActiveEntity = entity;
            var obj = entity.Object;
            var def = entity.MasterDefinition;

            if (def == null)
            {
                def = entity.Object.OBJ;
            }

            var item = Content.Content.Get().WorldCatalog.GetItemByGUID(def.GUID);

            var ndesc = GetObjName(entity);

            DescriptionText.CurrentText = ndesc.Item1 + "\r\n" + ndesc.Item2;
            ObjectNameText.Caption      = ndesc.Item1;

            IAmOwner      = ((entity.TSOState as VMTSOObjectState)?.OwnerID ?? 0) == vm.MyUID;
            Ghost         = entity.GhostImage;
            LastSalePrice = entity.MultitileGroup.SalePrice;
            CanSell       = (item?.DisableLevel ?? 0) < 2;

            int price      = def.Price;
            int finalPrice = price;
            int dcPercent  = 0;

            if (item != null)
            {
                price      = (int)item.Value.Price;
                dcPercent  = VMBuildableAreaInfo.GetDiscountFor(item.Value, vm);
                finalPrice = (price * (100 - dcPercent)) / 100;
            }

            StringBuilder motivesString = new StringBuilder();

            if (dcPercent > 0)
            {
                motivesString.Append(GameFacade.Strings.GetString("206", "36", new string[] { dcPercent.ToString() + "%" }) + "\r\n");
                motivesString.AppendFormat(GameFacade.Strings.GetString("206", "37") + "${0}\r\n", finalPrice);
                motivesString.AppendFormat(GameFacade.Strings.GetString("206", "38") + "${0}\r\n", price);
            }
            else
            {
                motivesString.AppendFormat(GameFacade.Strings.GetString("206", "19") + "${0}\r\n", price);
            }
            if (def.RatingHunger != 0)
            {
                motivesString.AppendFormat(AdStrings[0], def.RatingHunger);
            }
            if (def.RatingComfort != 0)
            {
                motivesString.AppendFormat(AdStrings[1], def.RatingComfort);
            }
            if (def.RatingHygiene != 0)
            {
                motivesString.AppendFormat(AdStrings[2], def.RatingHygiene);
            }
            if (def.RatingBladder != 0)
            {
                motivesString.AppendFormat(AdStrings[3], def.RatingBladder);
            }
            if (def.RatingEnergy != 0)
            {
                motivesString.AppendFormat(AdStrings[4], def.RatingEnergy);
            }
            if (def.RatingFun != 0)
            {
                motivesString.AppendFormat(AdStrings[5], def.RatingFun);
            }
            if (def.RatingRoom != 0)
            {
                motivesString.AppendFormat(AdStrings[6], def.RatingRoom);
            }

            var sFlags = def.RatingSkillFlags;

            for (int i = 0; i < 7; i++)
            {
                if ((sFlags & (1 << i)) > 0)
                {
                    motivesString.Append(AdStrings[i + 7]);
                }
            }

            MotivesText.CurrentText = motivesString.ToString();

            string owner = "Nobody";

            if (entity is VMGameObject && ((VMTSOObjectState)entity.TSOState).OwnerID > 0)
            {
                var ownerID  = ((VMTSOObjectState)entity.TSOState).OwnerID;
                var ownerEnt = vm.GetAvatarByPersist(ownerID);
                owner = (ownerEnt != null) ? owner = ownerEnt.Name : "(offline user)";
            }

            ObjectOwnerText.Caption = (!entity.GhostImage)?GameFacade.Strings.GetString("206", "24", new string[] { owner }):"";

            SpecificTabButton.Disabled = !bought;

            if (bought)
            {
                ObjectValueText.Caption   = GameFacade.Strings.GetString("206", "25", new string[] { " $" + entity.MultitileGroup.Price });
                ObjectValueText.Alignment = TextAlignment.Center;
                ObjectValueText.X         = ObjectNameText.X;
                ObjectValueText.Size      = new Vector2(260, 1);
            }

            if (LastSalePrice > -1)
            {
                ForSalePrice.CurrentText = "$" + entity.MultitileGroup.SalePrice;
                ForSalePrice.Alignment   = TextAlignment.Center;
                //ForSalePrice.SetSize(250, ForSalePrice.Height);
                SellBackButton.Disabled = (entity.PersistID == 0);
            }
            else
            {
                ForSalePrice.CurrentText = "";
            }

            if (entity is VMGameObject)
            {
                WearProgressBar.Value   = 100 - ((VMTSOObjectState)entity.TSOState).Wear / 4;
                WearProgressBar.Caption = ((VMTSOObjectState)entity.MultitileGroup.BaseObject.TSOState).Broken? GameFacade.Strings.GetString("206", "34") : null;
                WearValueText.Caption   = ((VMTSOObjectState)entity.TSOState).Wear / 4 + "%";
                var objects = entity.MultitileGroup.Objects;
                ObjectComponent[] objComps = new ObjectComponent[objects.Count];
                for (int i = 0; i < objects.Count; i++)
                {
                    objComps[i] = (ObjectComponent)objects[i].WorldUI;
                }

                if (Thumbnail.Texture != null)
                {
                    Thumbnail.Texture.Dispose();
                }
                if (Thumb3D != null)
                {
                    Thumb3D.Dispose();
                }
                Thumb3D = null; Thumbnail.Texture = null;
                if (FSOEnvironment.Enable3D)
                {
                    Thumb3D = new UI3DThumb(entity);
                }
                else
                {
                    var thumb = World.GetObjectThumb(objComps, entity.MultitileGroup.GetBasePositions(), GameFacade.GraphicsDevice);
                    Thumbnail.Texture = thumb;
                }
                UpdateImagePosition();
            }
            else
            {
                WearProgressBar.Value = 0;
                WearValueText.Caption = "0%";
                if (Thumbnail.Texture != null)
                {
                    Thumbnail.Texture.Dispose();
                }
                if (Thumb3D != null)
                {
                    Thumb3D.Dispose();
                }
                Thumb3D           = null;
                Thumbnail.Texture = null;
            }

            if (bought)
            {
                FSOFacade.Hints.TriggerHint("ui:querypanel");
            }
        }
        public override bool Execute(VM vm)
        {
            var obj          = vm.GetAvatarByPersist(TargetUID);
            var roomieChange = false;

            if (Mode == VMChangePermissionsMode.OBJECTS_ONLY)
            {
                roomieChange = true;
            }
            else
            {
                var ownerSwitch = Mode == VMChangePermissionsMode.OWNER_SWITCH || Mode == VMChangePermissionsMode.OWNER_SWITCH_WITH_OBJECTS;
                if (ownerSwitch)
                {
                    ChangeUserLevel(vm, vm.TSOState.OwnerID, VMTSOAvatarPermissions.Visitor);
                    if (vm.TSOState.CommunityLot)
                    {
                        vm.TSOState.Roommates.Clear();
                        vm.TSOState.BuildRoommates.Clear();
                    }
                }
                roomieChange = ChangeUserLevel(vm, TargetUID, Level);
                if (ownerSwitch)
                {
                    roomieChange = true;
                }
            }

            //mark objects not owned by roommates for inventory transfer
            if (roomieChange)
            {
                VMBuildableAreaInfo.UpdateOverbudgetObjects(vm);
                var roomies = (vm.TSOState.CommunityLot)?new HashSet <uint>()
                {
                    vm.TSOState.OwnerID
                }:vm.TSOState.Roommates;
                foreach (var ent in vm.Entities)
                {
                    if (ent is VMGameObject && ent.PersistID > 0)
                    {
                        var owner = ((VMTSOObjectState)ent.TSOState).OwnerID;
                        if (Mode == VMChangePermissionsMode.OWNER_SWITCH_WITH_OBJECTS && owner == ReplaceUID && ReplaceUID != 0)
                        {
                            var item = Content.Content.Get().WorldCatalog.GetItemByGUID((ent.MasterDefinition ?? ent.Object.OBJ).GUID);
                            if (item == null || item.Value.DisableLevel < 2) //do not trade objects that are untradable.
                            {
                                ((VMTSOObjectState)ent.TSOState).OwnerID = TargetUID;
                                owner = TargetUID;
                            }
                        }
                        var wasDisabled = (((VMGameObject)ent).Disabled & VMGameObjectDisableFlags.PendingRoommateDeletion) > 0;

                        var toBeDisabled = !roomies.Contains(owner) && !((VMTSOObjectState)ent.TSOState).ObjectFlags.HasFlag(VMTSOObjectFlags.FSODonated);

                        if (wasDisabled != toBeDisabled)
                        {
                            if (toBeDisabled)
                            {
                                ((VMGameObject)ent).Disabled |= VMGameObjectDisableFlags.PendingRoommateDeletion;
                            }
                            else
                            {
                                ((VMGameObject)ent).Disabled &= ~VMGameObjectDisableFlags.PendingRoommateDeletion;
                            }
                            vm.Scheduler.RescheduleInterrupt(ent);
                            ((VMGameObject)ent).RefreshLight();
                        }
                    }
                }
            }
            return(base.Execute(vm));
        }
Exemple #8
0
        public override bool Execute(VM vm)
        {
            var obj          = vm.GetAvatarByPersist(TargetUID);
            var roomieChange = false;

            if (obj == null)
            {
                //todo: changing owner for off-lot users, though you really shouldn't be doing that.
                vm.TSOState.BuildRoommates.Remove(TargetUID);
                if (vm.TSOState.Roommates.Contains(TargetUID))
                {
                    roomieChange = true;
                }
                vm.TSOState.Roommates.Remove(TargetUID);
                if (Level >= VMTSOAvatarPermissions.Roommate && Level < VMTSOAvatarPermissions.Admin)
                {
                    roomieChange = !roomieChange;
                    vm.TSOState.Roommates.Add(TargetUID);
                    if (Level > VMTSOAvatarPermissions.Roommate)
                    {
                        vm.TSOState.BuildRoommates.Add(TargetUID);
                    }
                }
            }
            else
            {
                var oldState = ((VMTSOAvatarState)obj.TSOState).Permissions;

                /*if (vm.GlobalLink != null && oldState >= VMTSOAvatarPermissions.Admin)
                 *  ((VMTSOGlobalLinkStub)vm.GlobalLink).Database.Administrators.Remove(obj.PersistID);*/

                if (oldState >= VMTSOAvatarPermissions.Roommate)
                {
                    vm.TSOState.Roommates.Remove(obj.PersistID);
                    roomieChange = !roomieChange;
                    ((VMTSOAvatarState)obj.TSOState).Flags |= VMTSOAvatarFlags.CanBeRoommate;
                }
                if (oldState >= VMTSOAvatarPermissions.BuildBuyRoommate)
                {
                    vm.TSOState.BuildRoommates.Remove(obj.PersistID);
                }
                ((VMTSOAvatarState)obj.TSOState).Permissions = Level;
                if (Level >= VMTSOAvatarPermissions.Roommate)
                {
                    ((VMTSOAvatarState)obj.TSOState).Flags &= ~VMTSOAvatarFlags.CanBeRoommate;
                    roomieChange = !roomieChange; //flips roomie change back
                    vm.TSOState.Roommates.Add(obj.PersistID);
                }
                if (Level >= VMTSOAvatarPermissions.BuildBuyRoommate)
                {
                    vm.TSOState.BuildRoommates.Add(obj.PersistID);
                }

                /*if (vm.GlobalLink != null && Level >= VMTSOAvatarPermissions.Admin)
                 *  ((VMTSOGlobalLinkStub)vm.GlobalLink).Database.Administrators.Add(obj.PersistID);*/
            }

            //mark objects not owned by roommates for inventory transfer
            if (roomieChange)
            {
                VMBuildableAreaInfo.UpdateOverbudgetObjects(vm);
                foreach (var ent in vm.Entities)
                {
                    if (ent is VMGameObject && ent.PersistID > 0 && ((VMTSOObjectState)ent.TSOState).OwnerID == TargetUID)
                    {
                        var old = ((VMGameObject)ent).Disabled;
                        if (Level < VMTSOAvatarPermissions.Roommate)
                        {
                            ((VMGameObject)ent).Disabled |= VMGameObjectDisableFlags.PendingRoommateDeletion;
                        }
                        else
                        {
                            ((VMGameObject)ent).Disabled &= ~VMGameObjectDisableFlags.PendingRoommateDeletion;
                        }
                        if (old != ((VMGameObject)ent).Disabled)
                        {
                            vm.Scheduler.RescheduleInterrupt(ent);
                        }
                        ((VMGameObject)ent).RefreshLight();
                    }
                }
            }
            return(base.Execute(vm));
        }
Exemple #9
0
        public void SetInfo(VM vm, VMEntity entity, bool bought)
        {
            var sameEntity = entity == ActiveEntity;

            ActiveEntity = entity;
            var obj = entity.Object;
            var def = entity.MasterDefinition;

            if (def == null)
            {
                def = entity.Object.OBJ;
            }

            var item = Content.Content.Get().WorldCatalog.GetItemByGUID(def.GUID);

            var ndesc = GetObjName(vm, entity);

            DescriptionText.CurrentText = ndesc.Item1 + "\r\n" + ndesc.Item2;
            ObjectNameText.Caption      = ndesc.Item1;

            IAmOwner      = ((entity.TSOState as VMTSOObjectState)?.OwnerID ?? 0) == vm.MyUID;
            Ghost         = entity.GhostImage;
            LastSalePrice = entity.MultitileGroup.SalePrice;
            CanSell       =
                vm.PlatformState.Validator.CanManageAsyncSale((VMAvatar)LotParent.ActiveEntity, ActiveEntity as VMGameObject) &&
                (item?.DisableLevel ?? 0) < 2;

            var upgrades = Content.Content.Get().Upgrades.GetFile(entity.Object.Resource.MainIff.Filename);

            if (!sameEntity)
            {
                SetHasUpgrades(upgrades != null, bought);
            }

            var upgradeLevel = (entity.PlatformState as VMTSOObjectState)?.UpgradeLevel ?? 0;
            int price        = def.Price;
            int finalPrice   = price;
            int dcPercent    = 0;

            if (item != null)
            {
                price = (int)item.Value.Price;
                if (upgradeLevel > 0)
                {
                    price = entity.MultitileGroup.InitialPrice;
                }
                dcPercent  = VMBuildableAreaInfo.GetDiscountFor(item.Value, vm);
                finalPrice = (price * (100 - dcPercent)) / 100;
                if (LotParent.ObjectHolder.DonateMode)
                {
                    finalPrice -= (finalPrice * 2) / 3;
                    dcPercent   = 66;
                }
            }

            StringBuilder motivesString = new StringBuilder();

            if (dcPercent > 0)
            {
                motivesString.Append(GameFacade.Strings.GetString("206", "36", new string[] { dcPercent.ToString() + "%" }) + "\r\n");
                motivesString.AppendFormat(GameFacade.Strings.GetString("206", "37") + "${0}\r\n", finalPrice);
                motivesString.AppendFormat(GameFacade.Strings.GetString("206", "38") + "${0}\r\n", price);
            }
            else
            {
                motivesString.AppendFormat(GameFacade.Strings.GetString("206", "19") + "${0}\r\n", price);
            }

            var catFlags = def.LotCategories;

            for (int i = 1; i < 12; i++)
            {
                if ((catFlags & (1 << i)) > 0)
                {
                    motivesString.AppendLine(CategoryStrings[i - 1]);
                }
            }

            if (def.RatingHunger != 0)
            {
                motivesString.AppendFormat(AdStrings[0], (short)def.RatingHunger);
            }
            if (def.RatingComfort != 0)
            {
                motivesString.AppendFormat(AdStrings[1], (short)def.RatingComfort);
            }
            if (def.RatingHygiene != 0)
            {
                motivesString.AppendFormat(AdStrings[2], (short)def.RatingHygiene);
            }
            if (def.RatingBladder != 0)
            {
                motivesString.AppendFormat(AdStrings[3], (short)def.RatingBladder);
            }
            if (def.RatingEnergy != 0)
            {
                motivesString.AppendFormat(AdStrings[4], (short)def.RatingEnergy);
            }
            if (def.RatingFun != 0)
            {
                motivesString.AppendFormat(AdStrings[5], (short)def.RatingFun);
            }
            if (def.RatingRoom != 0)
            {
                motivesString.AppendFormat(AdStrings[6], (short)def.RatingRoom);
            }

            var sFlags = def.RatingSkillFlags;

            for (int i = 0; i < 7; i++)
            {
                if ((sFlags & (1 << i)) > 0)
                {
                    motivesString.Append(AdStrings[i + 7]);
                }
            }

            MotivesText.CurrentText = motivesString.ToString();

            string owner      = "Nobody";
            var    ownerTable = "206";
            var    ownerEntry = "24";

            if (entity is VMGameObject && ((VMTSOObjectState)entity.TSOState).OwnerID > 0)
            {
                var ownerID = ((VMTSOObjectState)entity.TSOState).OwnerID;
                owner = (vm.TSOState.Names.GetNameForID(vm, ownerID));
                if (((VMTSOObjectState)entity.TSOState).ObjectFlags.HasFlag(VMTSOObjectFlags.FSODonated))
                {
                    ownerTable = "f114";
                    ownerEntry = "1";
                }
            }

            ObjectOwnerText.Caption = (!entity.GhostImage)?GameFacade.Strings.GetString(ownerTable, ownerEntry, new string[] { owner }):"";

            SpecificTabButton.Disabled = !bought;

            if (bought)
            {
                ObjectValueText.Caption   = GameFacade.Strings.GetString("206", "25", new string[] { " $" + entity.MultitileGroup.Price });
                ObjectValueText.Alignment = TextAlignment.Center;
                ObjectValueText.X         = ObjectNameText.X;
                ObjectValueText.Size      = new Vector2(260, 1);
            }

            if (LastSalePrice > -1)
            {
                ForSalePrice.CurrentText = "$" + entity.MultitileGroup.SalePrice;
                ForSalePrice.Alignment   = TextAlignment.Center;
                //ForSalePrice.SetSize(250, ForSalePrice.Height);
                SellBackButton.Disabled = (entity.PersistID == 0);
            }
            else
            {
                ForSalePrice.CurrentText = "";
            }

            if (entity is VMGameObject)
            {
                WearProgressBar.Value   = 100 - ((VMTSOObjectState)entity.TSOState).Wear / 4;
                WearProgressBar.Caption = ((VMTSOObjectState)entity.MultitileGroup.BaseObject.TSOState).Broken? GameFacade.Strings.GetString("206", "34") : null;
                WearValueText.Caption   = ((VMTSOObjectState)entity.TSOState).Wear / 4 + "%";
                var objects = entity.MultitileGroup.Objects;
                ObjectComponent[] objComps = new ObjectComponent[objects.Count];
                for (int i = 0; i < objects.Count; i++)
                {
                    objComps[i] = (ObjectComponent)objects[i].WorldUI;
                }

                if (Thumbnail.Texture != null)
                {
                    Thumbnail.Texture.Dispose();
                }
                if (Thumb3D != null)
                {
                    Thumb3D.Dispose();
                }
                Thumb3D = null; Thumbnail.Texture = null;
                if (World.State.CameraMode == LotView.Model.CameraRenderMode._3D)
                {
                    Thumb3D = new UI3DThumb(entity);
                }
                else
                {
                    var thumb = World.GetObjectThumb(objComps, entity.MultitileGroup.GetBasePositions(), GameFacade.GraphicsDevice);
                    Thumbnail.Texture = thumb;
                }
                UpdateImagePosition();
            }
            else
            {
                WearProgressBar.Value = 0;
                WearValueText.Caption = "0%";
                if (Thumbnail.Texture != null)
                {
                    Thumbnail.Texture.Dispose();
                }
                if (Thumb3D != null)
                {
                    Thumb3D.Dispose();
                }
                Thumb3D           = null;
                Thumbnail.Texture = null;
            }

            if (bought)
            {
                FSOFacade.Hints.TriggerHint("ui:querypanel");
            }
        }
        public override bool Verify(VM vm, VMAvatar caller)
        {
            if (Verified)
            {
                return(true); //set internally when transaction succeeds. trust that the verification happened.
            }
            value = 0;        //do not trust value from net
            if (!vm.TS1)
            {
                Mode = vm.PlatformState.Validator.GetPurchaseMode(Mode, caller, GUID, false);
                if (Mode == PurchaseMode.Disallowed)
                {
                    return(false);
                }
                if (Mode == PurchaseMode.Normal && !vm.PlatformState.CanPlaceNewUserObject(vm))
                {
                    return(false);
                }
                if (Mode == PurchaseMode.Donate && !vm.PlatformState.CanPlaceNewDonatedObject(vm))
                {
                    return(false);
                }
            }

            //TODO: error feedback for client
            var catalog = Content.Content.Get().WorldCatalog;
            var objects = Content.Content.Get().WorldObjects;
            var item    = catalog.GetItemByGUID(GUID);

            if (item != null)
            {
                var price = (int)item.Value.Price;

                if (TargetUpgradeLevel > 0)
                {
                    var obj = objects.Get(GUID);
                    if (obj != null)
                    {
                        var upgradePrice = Content.Content.Get().Upgrades.GetUpgradePrice(obj.Resource.MainIff.Filename, GUID, TargetUpgradeLevel);
                        if (upgradePrice == null)
                        {
                            return(false);                      //invalid upgrade level
                        }
                        price = upgradePrice.Value;
                    }
                }

                var dcPercent = VMBuildableAreaInfo.GetDiscountFor(item.Value, vm);
                value = (price * (100 - dcPercent)) / 100;
                if (Mode == PurchaseMode.Donate)
                {
                    value -= (value * 2) / 3;
                }
            }

            //TODO: fine grained purchase control based on user status

            //perform the transaction. If it succeeds, requeue the command
            vm.GlobalLink.PerformTransaction(vm, false, caller?.PersistID ?? uint.MaxValue, uint.MaxValue, value,
                                             (bool success, int transferAmount, uint uid1, uint budget1, uint uid2, uint budget2) =>
            {
                if (success)
                {
                    Verified = true;
                    vm.ForwardCommand(this);
                }
            });

            return(false);
        }
Exemple #11
0
        public override bool Verify(VM vm, VMAvatar caller)
        {
            if (Verified)
            {
                return(true);     //set internally when transaction succeeds. trust that the verification happened.
            }
            value = 0;            //do not trust value from net
            if (caller == null || //caller must be on lot, have build permissions
                ((VMTSOAvatarState)caller.TSOState).Permissions < VMTSOAvatarPermissions.Roommate ||
                !vm.TSOState.CanPlaceNewUserObject(vm))
            {
                return(false);
            }

            //get entry in catalog. first verify if it can be bought at all. (if not, error out)
            //TODO: error feedback for client
            var catalog   = Content.Content.Get().WorldCatalog;
            var item      = catalog.GetItemByGUID(GUID);
            var whitelist = (((VMTSOAvatarState)caller.TSOState).Permissions == VMTSOAvatarPermissions.Roommate) ? RoomieWhiteList : BuilderWhiteList;

            if (item == null || !whitelist.Contains(item.Value.Category))
            {
                if (((VMTSOAvatarState)caller.TSOState).Permissions == VMTSOAvatarPermissions.Admin)
                {
                    return(true);
                }
                return(false); //not purchasable
            }

            if (item != null)
            {
                var price     = (int)item.Value.Price;
                var dcPercent = VMBuildableAreaInfo.GetDiscountFor(item.Value, vm);
                value = (price * (100 - dcPercent)) / 100;
            }

            //TODO: fine grained purchase control based on user status

            //perform the transaction. If it succeeds, requeue the command
            vm.GlobalLink.PerformTransaction(vm, false, caller.PersistID, uint.MaxValue, value,
                                             (bool success, int transferAmount, uint uid1, uint budget1, uint uid2, uint budget2) =>
            {
                if (success)
                {
                    Verified = true;
                    vm.ForwardCommand(this);
                }
                vm.SendCommand(new VMNetAsyncResponseCmd(0, new VMTransferFundsState
                {     //update budgets on clients. id of 0 means there is no target thread.
                    Responded      = true,
                    Success        = success,
                    TransferAmount = transferAmount,
                    UID1           = uid1,
                    Budget1        = budget1,
                    UID2           = uid2,
                    Budget2        = budget2
                }));
            });

            return(false);
        }