コード例 #1
0
        public static GameObject RecreateSoldObject(RestockItem restockItem, SimDescription actor)
        {
            try
            {
                IGameObject      gameObject       = null;
                bool             restockBuyMode   = false;
                bool             restockCraftable = false;
                StoreSetRegister register         = null;

                bool         isRug;
                StoreSetBase shopBase = ReturnStoreSetBase(restockItem, out isRug);

                if (shopBase != null)
                {
                    if (shopBase.Info.RegisterId != ObjectGuid.InvalidObjectGuid)
                    {
                        register = CMStoreSet.ReturnRegister(shopBase.Info.RegisterId, shopBase.LotCurrent);
                    }

                    restockBuyMode   = shopBase.Info.RestockBuyMode;
                    restockCraftable = shopBase.Info.RestockCraftable;

                    #region Find the slot

                    bool slotFound = false;
                    Slot slot      = Slot.ContainmentSlot_0;
                    if (!isRug)
                    {
                        Slot[] containmentSlots = shopBase.GetContainmentSlots();

                        if (containmentSlots != null)
                        {
                            for (int i = 0; i < containmentSlots.Length; i++)
                            {
                                GameObject o = shopBase.GetContainedObject(containmentSlots[i]) as GameObject;

                                if (o != null && o.ObjectId == restockItem.ObjectId)
                                {
                                    slotFound = true;
                                    slot      = containmentSlots[i];
                                    break;
                                }
                            }
                        }
                    }
                    #endregion

                    //Restock from inventory only, if not buy object and linked to register
                    bool restockFromInventory = RestockFromInventory(restockItem, restockCraftable);

                    //Restock from buy mode
                    #region Buy Mode
                    if (!restockFromInventory)
                    {
                        if (restockItem.info.Type == ItemType.Buy || restockItem.info.Type == ItemType.Craftable)
                        {
                            gameObject = GlobalFunctions.CreateObject(restockItem.info.Key, restockItem.Position, restockItem.mLevel, restockItem.ForwardVector);
                            if (!(gameObject is FailureObject))
                            {
                                if (!string.IsNullOrEmpty(restockItem.info.DesignPreset))
                                {
                                    SortedList <string, bool>     enabledStencils = new SortedList <string, bool>();
                                    SortedList <string, Complate> patterns        = StoreHelperClass.ExtractPatterns(restockItem.info.DesignPreset, enabledStencils);
                                    DesignModeSwap designModeSwap = Complate.SetupDesignSwap(gameObject.ObjectId, patterns, false, enabledStencils);
                                    if (designModeSwap != null)
                                    {
                                        designModeSwap.ApplyToObject();
                                    }
                                }
                            }
                        }
                        else
                        {
                            gameObject = ReturnShoppingObject(restockItem, actor, register);
                            gameObject.AddToWorld();
                            gameObject.SetPosition(restockItem.Position);
                        }
                        #region Pay for Restock

                        //Reduce from base owner or register's owner
                        if (shopBase.Info.Owner != 0uL)
                        {
                            SimDescription sd = CMStoreSet.ReturnSim(shopBase.Info.Owner);
                            if (sd != null)
                            {
                                sd.ModifyFunds(-restockItem.info.Price);
                            }
                            else
                            {
                                CMStoreSet.PrintMessage("Couldn't find owner sim");
                            }
                        }
                        else if (shopBase.Info.RegisterId != ObjectGuid.InvalidObjectGuid)
                        {
                            //StoreSetRegister register = CMStoreSet.ReturnRegister(shopBase.Info.RegisterId, shopBase.LotCurrent);
                            if (register != null && register.Info.OwnerId != 0uL)
                            {
                                SimDescription sd = CMStoreSet.ReturnSim(register.Info.OwnerId);
                                if (sd != null)
                                {
                                    sd.ModifyFunds(-restockItem.info.Price);
                                }
                            }
                        }

                        #endregion
                    }
                    #endregion Buy Mode

                    #region Inventory
                    else
                    {
                        //Restock from Inventory
                        if (shopBase != null && shopBase.Info.RegisterId != ObjectGuid.InvalidObjectGuid)
                        {
                            gameObject = ReturnRestocableObject(restockItem, shopBase.Info.RegisterId);

                            if (gameObject != null)
                            {
                                gameObject.AddToWorld();
                                gameObject.SetPosition(restockItem.Position);
                                gameObject.SetForward(restockItem.ForwardVector);
                            }
                            else
                            {
                                CMStoreSet.PrintMessage("Restockable object null");
                            }
                        }
                    }
                    #endregion Inventory

                    //Delete restock object
                    if (restockItem != null)
                    {
                        restockItem.Destroy();
                    }

                    //Add restocked item back to slot
                    if (slotFound)
                    {
                        IGameObject io = (IGameObject)shopBase;
                        gameObject.ParentToSlot(io, slot);
                    }


                    return((GameObject)gameObject);
                }
                else
                {
                    return(null);
                }
            }
            catch (System.Exception ex)
            {
                CMStoreSet.PrintMessage("RecreateSoldObject: " + ex.Message);
                return(null);
            }
        }