Ejemplo n.º 1
0
        public override bool Run()
        {
            Definition interactionDefinition = base.InteractionDefinition as Definition;

            if (interactionDefinition == null)
            {
                return(false);
            }
            ObjectGuid mObject = interactionDefinition.mObject;
            int        mCost   = interactionDefinition.mCost;

            if (mObject == ObjectGuid.InvalidObjectGuid)
            {
                List <ObjectGuid> objectsICanBuyInDisplay = DisplayHelper.GetObjectsICanBuyInDisplay(base.Actor, base.Target);
                if (!Autonomous && Actor.IsSelectable)
                {
                    List <ObjectPicker.RowInfo> list = new List <ObjectPicker.RowInfo>();
                    foreach (ObjectGuid current in objectsICanBuyInDisplay)
                    {
                        GameObject           obj  = GlobalFunctions.ConvertGuidToObject <GameObject>(current);
                        ObjectPicker.RowInfo item = new ObjectPicker.RowInfo(current, new List <ObjectPicker.ColumnInfo>
                        {
                            new ObjectPicker.ThumbAndTextColumn(obj.GetThumbnailKey(), obj.GetLocalizedName()),
                            new ObjectPicker.MoneyColumn(DisplayHelper.ComputeFinalPriceOnObject(obj, true))
                        });
                        list.Add(item);
                    }
                    List <ObjectPicker.HeaderInfo> list2 = new List <ObjectPicker.HeaderInfo>();
                    List <ObjectPicker.TabInfo>    list3 = new List <ObjectPicker.TabInfo>();
                    list2.Add(new ObjectPicker.HeaderInfo(ShoppingRegister.sLocalizationKey + ":BuyFoodColumnName", ShoppingRegister.sLocalizationKey + ":BuyFoodColumnTooltip", 200));
                    list2.Add(new ObjectPicker.HeaderInfo("Ui/Caption/Shopping/Cart:Price", "Ui/Tooltip/Shopping/Cart:Price"));
                    list3.Add(new ObjectPicker.TabInfo("", ShoppingRegister.LocalizeString("AvailableFoods"), list));
                    List <ObjectPicker.RowInfo> list4 = SimplePurchaseDialog.Show(ShoppingRegister.LocalizeString("BuyFoodTitle"), Actor.FamilyFunds, list3, list2, true);
                    if (list4 == null || list4.Count != 1)
                    {
                        return(false);
                    }
                    mObject = (ObjectGuid)list4[0].Item;
                    mCost   = ((ObjectPicker.MoneyColumn)list4[0].ColumnInfo[1]).Value;
                }
                else
                {
                    RandomUtil.RandomizeListOfObjects <ObjectGuid>(objectsICanBuyInDisplay);
                    int familyFunds = base.Actor.FamilyFunds;
                    for (int i = 0; i < objectsICanBuyInDisplay.Count; i++)
                    {
                        int cost = DisplayHelper.ComputeFinalPriceOnObject(objectsICanBuyInDisplay[i]);
                        if (cost <= familyFunds)
                        {
                            //Definition continuationDefinition = new Definition(objectsICanBuyInDisplay[i], cost, false);
                            //base.TryPushAsContinuation(continuationDefinition);
                            //return true;
                            mObject = objectsICanBuyInDisplay[i];
                            mCost   = cost;
                            break;
                        }
                    }
                    //return false;
                }
            }
            if (mObject == ObjectGuid.InvalidObjectGuid)
            {
                return(false);
            }
            if (!base.Actor.RouteToObjectRadialRange(base.Target, 0f, base.Target.MaxProximityBeforeSwiping()))
            {
                return(false);
            }
            base.Actor.RouteTurnToFace(base.Target.Position);
            if (!DisplayHelper.GetObjectsICanBuyInDisplay(base.Actor, base.Target).Contains(mObject))
            {
                return(false);
            }
            if (base.Actor.FamilyFunds < mCost)
            {
                return(false);
            }
            GameObject target = GlobalFunctions.ConvertGuidToObject <GameObject>(mObject);

            if (target == null)
            {
                return(false);
            }

            base.StandardEntry();
            base.BeginCommodityUpdates();
            string swipeAnimationName = base.Target.GetSwipeAnimationName(target);

            if (Actor.SimDescription.Child)
            {
                swipeAnimationName = "c" + swipeAnimationName.Substring(1);
            }
            base.Actor.PlaySoloAnimation(swipeAnimationName, true);
            VisualEffect effect = VisualEffect.Create(base.Target.GetSwipeVfxName());
            Vector3      zero   = Vector3.Zero;
            Vector3      axis   = Vector3.Zero;

            if (Slots.AttachToBone(effect.ObjectId, base.Target.ObjectId, ResourceUtils.HashString32("transformBone"), false, ref zero, ref axis, 0f) == TransformParentingReturnCode.Success)
            {
                effect.SetAutoDestroy(true);
                effect.Start();
            }
            else
            {
                effect.Dispose();
                effect = null;
            }
            //bool flag = false;
            //bool flag2 = false;
            bool   succeeded       = false;
            bool   addInteractions = true;
            string tnsKey          = null;

            if (target.IsLiveDraggingEnabled() && !target.InUse && (interactionDefinition.mPushEat || (target.ItemComp != null && target.ItemComp.CanAddToInventory(base.Actor.Inventory) && base.Actor.Inventory.CanAdd(target)))) //&& base.Actor.Inventory.TryToAdd(target)))
            {
                ServingContainerGroup groupServing = null;
                if (interactionDefinition.mSingleServing)
                {
                    groupServing = target as ServingContainerGroup;
                    if (groupServing != null)
                    {
                        target          = groupServing.CookingProcess.CreateSingleServingOfFood(groupServing, true, true);
                        addInteractions = false;
                    }
                }
                if (interactionDefinition.mPushEat)
                {
                    target.SetOpacity(0f, 0f);
                    if (Actor.ParentToRightHand(target))
                    {
                        succeeded = true;
                        CarrySystem.EnterWhileHolding(Actor, target as ICarryable);
                    }
                    target.FadeIn();
                }
                else if (Actor.Inventory.TryToAdd(target))
                {
                    succeeded = true;
                    tnsKey    = "PlacedInPersonalInventory";
                }
                if (succeeded)
                {
                    if (groupServing != null)
                    {
                        groupServing.DecrementServings();
                        if (groupServing.NumServingsLeft == 0)
                        {
                            groupServing.FadeOut(false, true);
                        }
                    }
                }
                else if (groupServing != null && target != null)
                {
                    target.Destroy();
                }
            }
            else if (!target.InUse && base.Actor.Household.SharedFamilyInventory.Inventory.TryToAdd(target))
            {
                succeeded = true;
                tnsKey    = "PlacedInFamilyInventory";
            }
            //bool succeeded = flag || flag2;
            if (succeeded)
            {
                if (addInteractions)
                {
                    Target.OnHandToolChildUnslotted(target, Slot.None);
                    if (target is Snack)
                    {
                        target.AddInteraction(Sims3.Gameplay.Objects.CookingObjects.Eat.Singleton, true);
                        target.AddInteraction(Snack_CleanUp.Singleton, true);
                    }
                }

                /*if (flag2)
                 * {
                 *  base.Actor.ShowTNSIfSelectable(CraftersConsignment.LocalizeString(base.Actor.IsFemale, "PlacedInFamilyInventory", new object[] { base.Actor, target }), StyledNotification.NotificationStyle.kGameMessagePositive);
                 * }
                 * else
                 * {
                 *  base.Actor.ShowTNSIfSelectable(CraftersConsignment.LocalizeString(base.Actor.IsFemale, "PlacedInPersonalInventory", new object[] { base.Actor, target }), StyledNotification.NotificationStyle.kGameMessagePositive);
                 * }*/
                if (tnsKey != null)
                {
                    Actor.ShowTNSIfSelectable(CraftersConsignment.LocalizeString(Actor.IsFemale, tnsKey, new object[] { Actor, target }), StyledNotification.NotificationStyle.kGameMessagePositive);
                }
                base.Target.GiveMarkupBuffs(base.Actor, mObject);
                base.Actor.ModifyFunds(-mCost);
                base.Target.GiveLotOwnerMoney(mCost, base.Actor);
                base.Target.AccumulateRevenue(mCost);
                if (interactionDefinition.mPushEat)
                {
                    (target as IFoodContainer).PushEatHeldFoodInteraction(Actor);
                }
            }
            base.EndCommodityUpdates(succeeded);
            base.StandardExit();
            return(succeeded);
        }
Ejemplo n.º 2
0
        public BaseFoodStand.BaseFoodData ShowBuyConcessionsFoodDialog(bool autonomous)
        {
            List <ushort> availibleFoodGuids = GetAvailibleFoodGuids(BaseFoodStand.FoodType.None, base.Actor);

            ThumbnailKey thumbnail           = ThumbnailKey.kInvalidThumbnailKey;
            string       text                = string.Empty;
            List <ObjectPicker.RowInfo> list = new List <ObjectPicker.RowInfo>();

            List <BaseFoodStand.BaseFoodData> foods = new List <BaseFoodStand.BaseFoodData>();

            foreach (ushort current in availibleFoodGuids)
            {
                BaseFoodStand.BaseFoodData baseFoodData = null;
                if (ConcessionsStand.SeasonalFoodData.sSeasonalFoodData.TryGetValue(current, out baseFoodData))
                {
                    List <ObjectPicker.ColumnInfo> list2 = new List <ObjectPicker.ColumnInfo>();
                    bool addToList = false;
                    switch (baseFoodData.FoodType)
                    {
                    case ConcessionsStand.FoodType.HotBeverage:
                    {
                        thumbnail = GetThumbnailKeyForDrink(baseFoodData.FoodType == BaseFoodStand.FoodType.HotBeverage);
                        text      = Localization.LocalizeString(ConcessionsStand.sBaseBeverageLocKey + baseFoodData.DrinkNameLocKey, new object[0]);
                        addToList = true;
                        foods.Add(baseFoodData);
                        break;
                    }
                    }
                    if (addToList)
                    {
                        list2.Add(new ObjectPicker.ThumbAndTextColumn(thumbnail, text));
                        int num = AddMenuItem.ReturnCoffeePrice();

                        list2.Add(new ObjectPicker.MoneyColumn(num));
                        ObjectPicker.RowInfo item = new ObjectPicker.RowInfo(current, list2);
                        list.Add(item);
                    }
                }
            }
            BaseFoodStand.BaseFoodData foodData = null;

            if (!autonomous)
            {
                List <ObjectPicker.HeaderInfo> list3 = new List <ObjectPicker.HeaderInfo>();
                List <ObjectPicker.TabInfo>    list4 = new List <ObjectPicker.TabInfo>();
                list3.Add(new ObjectPicker.HeaderInfo(ShoppingRegister.sLocalizationKey + ":BuyConcessionsFoodColumnName", ShoppingRegister.sLocalizationKey + ":BuyConcessionsFoodColumnTooltip", 200));
                list3.Add(new ObjectPicker.HeaderInfo("Ui/Caption/Shopping/Cart:Price", "Ui/Tooltip/Shopping/Cart:Price"));
                list4.Add(new ObjectPicker.TabInfo("coupon", ShoppingRegister.LocalizeString("AvailableConcessionsFoods", new object[0]), list));
                List <ObjectPicker.RowInfo> list5 = SimplePurchaseDialog.Show(ShoppingRegister.LocalizeString("BuyConcessionsFoodTitle", new object[0]), base.Actor.Household.FamilyFunds, list4, list3, true);
                if (list5 == null || list5.Count != 1)
                {
                    return(null);
                }
                foodData = list5[0].Item as  BaseFoodStand.BaseFoodData;

                CommonMethods.ShowMessage(list5.Count.ToString());
                CommonMethods.ShowMessage(list5[0].Item.ToString());

                if (foodData == null)
                {
                    CommonMethods.ShowMessage("foodData null");
                }
            }
            else
            {
                foodData = RandomUtil.GetRandomObjectFromList <BaseFoodStand.BaseFoodData>(foods);
            }
            return(foodData);
        }