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)
            {
                if (caller == null || //caller must be on lot, have build permissions
                    caller.AvatarState.Permissions < VMTSOAvatarPermissions.Roommate ||
                    !vm.PlatformState.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.GameContent.Get.WorldCatalog;
            var item    = catalog.GetItemByGUID(GUID);

            if (!vm.TS1)
            {
                var whitelist = (caller.AvatarState.Permissions == VMTSOAvatarPermissions.Roommate) ? RoomieWhiteList : BuilderWhiteList;
                if (item == null || !whitelist.Contains(item.Value.Category))
                {
                    if (caller.AvatarState.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, 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 #2
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 (!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 item    = catalog.GetItemByGUID(GUID);

            if (item != null)
            {
                var price     = (int)item.Value.Price;
                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 #3
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 #4
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 #5
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");
            }
        }
Exemple #6
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");
            }
        }
Exemple #7
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);
        }