예제 #1
0
 // Use this for initialization
 void Start()
 {
     stackGroup = GetComponentInParent <StackGroup>();
     //GetInv();
     //ClearInv();
     //SetInv();
 }
 /// <summary>
 /// Raises the item click event.
 /// </summary>
 /// <param name="item">Item.</param>
 public void OnItemUse(GameObject item)
 {
     if (item != null)
     {
         StackItem stackItem = item.GetComponent <StackItem>();
         if (stackItem != null)
         {
             StackGroup sourceGroup = Gets.GetComponentInParent <StackGroup>(item.transform);
             if (sourceGroup != null && (sourceGroup == firstGroup || sourceGroup == secondGroup))
             {
                 StackGroup destinationGroup = sourceGroup == firstGroup ? secondGroup : firstGroup;
                 // Try to place item into free space of specified stack group
                 if (destinationGroup.AddItem(stackItem, stackItem.GetStack()) <= 0)
                 {
                     // If group have no free space for item
                     // Get similar items in that group
                     List <StackItem> similarItems = destinationGroup.GetSimilarStackItems(stackItem);
                     if (similarItems.Count > 0)
                     {
                         // Try to replace with first similar item
                         destinationGroup.ReplaceItems(similarItems[0], stackItem, sourceGroup);
                     }
                 }
             }
         }
     }
 }
예제 #3
0
파일: StackGroup.cs 프로젝트: TFM-AEIS/TFM
    /// <summary>
    /// Adds existing item.
    /// </summary>
    /// <returns>The item.</returns>
    /// <param name="stackItem">Stack item.</param>
    /// <param name="limit">Limit.</param>
    public int AddExistingItem(StackItem stackItem, int limit)
    {
        int res = 0;

        if (stackItem != null)
        {
            // Init internal state (just in case it was not initted before)
            stackItem.Init();

            StackGroup sourceStackGroup = AccessUtility.GetComponentInParent <StackGroup>(stackItem.transform);
            StackCell  sourceStackCell  = stackItem.GetStackCell();

            StackGroupEventDescriptor desc = new StackGroupEventDescriptor();
            // Try to distribute item inside group's items and cells
            DistributeResults distributeResults = DistributeAnywhere(stackItem, limit, null);
            res += distributeResults.amount;
            // Send stack event notification
            if (res > 0)
            {
                PlaySound(stackItem.sound);

                desc.sourceGroup      = sourceStackGroup;
                desc.destinationGroup = this;
                desc.sourceCell       = sourceStackCell;
                desc.destinationCells = distributeResults.cells;
                SendNotification(desc);
            }
        }
        return(res);
    }
예제 #4
0
파일: StackGroup.cs 프로젝트: TFM-AEIS/TFM
    /// <summary>
    /// Calls the drag and drop event manually from script.
    /// </summary>
    /// <param name="sourceCell">Source cell.</param>
    /// <param name="destinationGroup">Destination group.</param>
    public void CallDadEventManually(StackCell sourceCell, StackGroup destinationGroup)
    {
        Init();

        if (myState == MyState.WaitForRequest)
        {
            if (sourceCell != null && destinationGroup != null)
            {
                StackItem stackItem       = sourceCell.GetStackItem();
                StackCell destinationCell = null;
                if (stackItem != null)
                {
                    List <StackCell> destinationCells = new List <StackCell>();

                    // Check for not full cells with same items
                    foreach (StackItem similarStackItem in GetSimilarStackItems(stackItem))
                    {
                        if (similarStackItem.name == stackItem.name)
                        {
                            StackCell similarStackCell = similarStackItem.GetStackCell();
                            if (similarStackCell.GetAllowedSpace() > 0)
                            {
                                destinationCell = similarStackCell;
                                break;
                            }
                        }
                    }

                    if (destinationCell == null)
                    {
                        // Check for empty cells
                        destinationCells = GetFreeStackCells(stackItem);
                        if (destinationCells.Count > 0)
                        {
                            destinationCell = destinationCells[0];
                        }
                    }

                    if (destinationCell == null)
                    {
                        // Check for other cells with similar items
                        foreach (StackItem similarStackItem in GetSimilarStackItems(stackItem))
                        {
                            if (similarStackItem.name != stackItem.name)
                            {
                                destinationCell = similarStackItem.GetStackCell();
                                break;
                            }
                        }
                    }

                    if (destinationCell != null)
                    {
                        CallDadEventManually(sourceCell, destinationCell);
                    }
                }
            }
        }
    }
        /// <summary>
        /// 新增一个document
        /// </summary>
        /// <param name="document"></param>
        public void AddDocument(Document document)
        {
            this.widgetView1.Documents.Add(document);
            this._documents.Add(document);
            StackGroup stackGroupp = this.GetStackGroupPositionToAddDocument();

            stackGroupp.Items.Add(document);
        }
 /// <summary>
 /// 批量新增document,应保证之前document肯定不存在
 /// </summary>
 /// <param name="documents"></param>
 public void AddRangeDocument(IEnumerable <Document> documents)
 {
     this._documents.AddRange(documents);
     this.widgetView1.Documents.AddRange(documents);
     foreach (Document document in documents)
     {
         StackGroup stackGroupp = this.GetStackGroupPositionToAddDocument();
         stackGroupp.Items.Add(document);
     }
 }
예제 #7
0
    public void InitiateTrade()
    {
        tradeUI.SetActive(true);
        //playerInventoryManager.ClearInv();
        StackGroup stackGroup = playerInventoryManager.GetComponentInParent <StackGroup>();

        print(stackGroup);
        if (stackGroup != null)
        {
            playerInventoryManager.SetInv();
        }
    }
 /// <summary>
 /// 创建列
 /// </summary>
 /// <param name="count">列数量</param>
 /// <param name="pixels">列宽度像素点数量,缺省值200</param>
 public void CreateStackGroups(int count, double pixels = 200)
 {
     this.widgetView1.StackGroups.Clear();
     _stackGroups = new List <StackGroup>();
     for (int i = 0; i < count; i++)
     {
         StackGroup stackGroup = new StackGroup();
         stackGroup.Length = new Length(pixels);
         _stackGroups.Add(stackGroup);
     }
     this.widgetView1.StackGroups.AddRange(_stackGroups);
 }
예제 #9
0
파일: StackGroup.cs 프로젝트: TFM-AEIS/TFM
    /// <summary>
    /// Distribute destination item in source group than place source item in just vacated cell.
    /// </summary>
    /// <returns><c>true</c>, if item was replaced, <c>false</c> otherwise.</returns>
    /// <param name="sourceStackItem">Source stack item.</param>
    /// <param name="destinationStackItem">Destination stack item.</param>
    public bool ReplaceItems(StackItem sourceStackItem, StackItem destinationStackItem)
    {
        bool       res                  = false;
        StackCell  sourceStackCell      = sourceStackItem.GetStackCell();
        StackCell  destinationStackCell = destinationStackItem.GetStackCell();
        StackGroup sourceStackGroup     = AccessUtility.GetComponentInParent <StackGroup>(sourceStackItem.transform);

        if (sourceStackItem != null && destinationStackItem != null && sourceStackCell != null && destinationStackCell != null && sourceStackGroup != null)
        {
            StackGroupEventDescriptor distributeDesc = new StackGroupEventDescriptor();
            StackGroupEventDescriptor swapDesc       = new StackGroupEventDescriptor();

            // Try distribute item from destination cell into source group
            DistributeResults distributeResults = sourceStackGroup.DistributeAnywhere(destinationStackItem, destinationStackItem.GetStack(), null);

            if (distributeResults.amount > 0)
            {
                distributeDesc.sourceGroup      = this;
                distributeDesc.destinationGroup = sourceStackGroup;
                distributeDesc.sourceCell       = destinationStackCell;
                distributeDesc.destinationCells = distributeResults.cells;

                // If destination cell is empty now
                if (destinationStackCell.GetStackItem() == null)
                {
                    // Place source item into it
                    if (destinationStackCell.UniteStack(sourceStackItem, sourceStackItem.GetStack()) > 0)
                    {
                        PlaySound(sourceStackItem.sound);

                        swapDesc.sourceGroup      = sourceStackGroup;
                        swapDesc.destinationGroup = this;
                        swapDesc.sourceCell       = sourceStackCell;
                        swapDesc.destinationCells.Add(destinationStackCell);

                        res = true;
                    }
                }
            }

            if (distributeResults.amount > 0)
            {
                // Send distribute stack event notification
                SendNotification(distributeDesc);
                if (res == true)
                {
                    // Send swap stack item event notification
                    SendNotification(swapDesc);
                }
            }
        }
        return(res);
    }
        void AddDocumentManager()
        {
            DocumentManager dM = new DocumentManager(components);

            view    = new WidgetView();
            dM.View = view;
            view.AllowDocumentStateChangeAnimation = DevExpress.Utils.DefaultBoolean.True;
            group1 = new StackGroup();
            group2 = new StackGroup();
            group1.Length.UnitType  = LengthUnitType.Star;
            group1.Length.UnitValue = 2;
            view.StackGroups.AddRange(new StackGroup[] { group1, group2 });
            dM.ContainerControl = this;
        }
예제 #11
0
    /// <summary>
    /// Stack event handler.
    /// </summary>
    /// <returns>The handler.</returns>
    /// <param name="desc">Desc.</param>
    private IEnumerator EventHandler(DadCell.DadEventDescriptor desc)
    {
        StackGroup sourceStackGroup = desc.sourceCell.GetComponentInParent <StackGroup>();
        StackGroup destStackGroup   = desc.destinationCell.GetComponentInParent <StackGroup>();

        StackCell myStackCell    = desc.destinationCell.GetComponent <StackCell>();
        StackCell theirStackCell = desc.sourceCell.GetComponent <StackCell>();
        StackItem myStackItem    = myStackCell.GetStackItem();
        StackItem theirStackItem = theirStackCell.GetStackItem();

        //AudioClip itemSound = theirStackItem.sound;									// Item's SFX

        //int amount = theirStackItem.GetStack();                                     // Item's stack amount

        yield return(0);
    }
예제 #12
0
 /// <summary>
 /// Awake this instance.
 /// </summary>
 void Awake()
 {
     foreach (GameObject source in permittedSources)
     {
         StackGroup stackGroup = AccessUtility.GetComponentInParent <StackGroup>(source.transform);
         if (stackGroup == null)
         {
             stackGroup = source.GetComponentInChildren <StackGroup>(true);
         }
         if (stackGroup != null && stackGroup.eventAdditionalReceivers.Contains(gameObject) == false)
         {
             // Add quick slot group as stack events receiver
             stackGroup.eventAdditionalReceivers.Add(gameObject);
         }
     }
 }
예제 #13
0
        private void PaintStackGroup(StackGroup stackGroup)
        {
            float ox = Painter.OriginX;//***
            float oy = Painter.OriginY;

            int count = stackGroup.ChildCount;

            Painter.SetOrigin(stackGroup.Left + ox, stackGroup.Top + oy);
            _fromPaintHorizontal.Push(false);
            for (int i = 0; i < count; ++i)
            {
                Paint(stackGroup.GetChild(i));
            }
            _fromPaintHorizontal.Pop();
            Painter.SetOrigin(ox, oy);//restore
        }
예제 #14
0
    /// <summary>
    /// Adds the item.
    /// </summary>
    /// <returns>The item.</returns>
    /// <param name="stackItem">Stack item.</param>
    /// <param name="limit">Limit.</param>
    public int AddItem(StackItem stackItem, int limit)
    {
        int res = 0;

        if (stackItem != null)
        {
            // Try to distribute item inside group's items and cells
            res += DistributeAnywhere(stackItem, limit, null);
            StackGroup sourceStackGroup = stackItem.GetComponentInParent <StackGroup>();
            // Send stack event notification
            SendNotification(sourceStackGroup != null ? sourceStackGroup.gameObject : null, gameObject);
            if (res > 0)
            {
                PlaySound(stackItem.sound);
            }
        }
        return(res);
    }
예제 #15
0
    /// <summary>
    /// Swap items between groups.
    /// </summary>
    /// <returns><c>true</c>, if item was replaced, <c>false</c> otherwise.</returns>
    /// <param name="currentStackItem">Current stack item.</param>
    /// <param name="sourceStackItem">Source stack item.</param>
    /// <param name="sourceStackGroup">Source stack group.</param>
    public bool ReplaceItems(StackItem currentStackItem, StackItem sourceStackItem, StackGroup sourceStackGroup)
    {
        bool res = false;

        if (currentStackItem != null && sourceStackItem != null && sourceStackGroup != null)
        {
            StackCell currentStackCell = currentStackItem.GetStackCell();
            sourceStackGroup.DistributeAnywhere(currentStackItem, currentStackItem.GetStack(), null);
            if (currentStackCell.GetStackItem() == null)
            {
                currentStackCell.UniteStack(sourceStackItem, sourceStackItem.GetStack());
                PlaySound(sourceStackItem.sound);
                res = true;
            }
            // Send stack event notification
            SendNotification(sourceStackGroup.gameObject, gameObject);
        }
        return(res);
    }
예제 #16
0
파일: Pack.cs 프로젝트: 00mjk/HaloSharp
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = PackRules?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (FrontImage != null ? FrontImage.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (BackImage != null ? BackImage.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (BackImage4K != null ? BackImage4K.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (HighlightImage != null ? HighlightImage.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (HighlightImage4K != null ? HighlightImage4K.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (FrontImage4K != null ? FrontImage4K.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (StackGroup?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ InventorySortPriority;
         hashCode = (hashCode * 397) ^ (DisplayInfo != null ? DisplayInfo.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (MarketplaceProductId?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (ProductId?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
예제 #17
0
    /// <summary>
    /// Raises the DaD group event event.
    /// </summary>
    /// <param name="desc">Desc.</param>
    private void OnDadGroupEvent(DadCell.DadEventDescriptor desc)
    {
        switch (desc.triggerType)
        {
        case DadCell.TriggerType.DragGroupRequest:
        case DadCell.TriggerType.DropGroupRequest:
            if (myState == MyState.WaitForRequest)
            {
                // Disable standard DaD logic
                desc.groupPermission = false;
                myState = MyState.WaitForEvent;
            }
            break;

        case DadCell.TriggerType.DragEnd:
            if (myState == MyState.WaitForEvent)
            {
                StackGroup sourceStackControl = desc.sourceCell.GetComponentInParent <StackGroup>();
                StackGroup destStackControl   = desc.destinationCell.GetComponentInParent <StackGroup>();
                if (sourceStackControl != destStackControl)
                {
                    // If this group is source group - do nothing
                    myState = MyState.WaitForRequest;
                }
            }
            break;

        case DadCell.TriggerType.DropEnd:
            if (myState == MyState.WaitForEvent)
            {
                // If this group is destination group
                myState = MyState.Busy;
                // Operate item's drop
                StartCoroutine(EventHandler(desc));
            }
            break;
        }
    }
예제 #18
0
 public void AddStackGroup(StackGroup stackgroup)
 {
     this.widgetView1.StackGroups.Add(stackgroup);
 }
예제 #19
0
    /// <summary>
    /// Stack event handler.
    /// </summary>
    /// <returns>The handler.</returns>
    /// <param name="desc">Desc.</param>
    private IEnumerator EventHandler(DadCell.DadEventDescriptor desc)
    {
        StackGroup sourceStackGroup = desc.sourceCell.GetComponentInParent <StackGroup>();
        StackGroup destStackGroup   = desc.destinationCell.GetComponentInParent <StackGroup>();

        StackCell myStackCell    = desc.destinationCell.GetComponent <StackCell>();
        StackCell theirStackCell = desc.sourceCell.GetComponent <StackCell>();
        StackItem myStackItem    = myStackCell.GetStackItem();
        StackItem theirStackItem = theirStackCell.GetStackItem();

        PriceItem  priceItem = theirStackItem.GetComponent <PriceItem>();
        PriceGroup buyer     = desc.destinationCell.GetComponentInParent <PriceGroup>();
        PriceGroup seller    = desc.sourceCell.GetComponentInParent <PriceGroup>();

        AudioClip itemSound = theirStackItem.sound;                                                                             // Item's SFX

        int amount = theirStackItem.GetStack();                                                                                 // Item's stack amount

        if ((globalSplit == true) ||
            (sourceStackGroup != destStackGroup && (sourceStackGroup.splitOuter == true || destStackGroup.splitOuter == true)))
        {
            // Need to use split interface
            if (splitInterface != null)
            {
                if (priceItem != null && buyer != null && seller != null && buyer != seller)
                {
                    // Split with prices
                    splitInterface.ShowSplitter(theirStackItem, priceItem);
                }
                else
                {
                    // Split without prices
                    splitInterface.ShowSplitter(theirStackItem, null);
                }
                // Show split interface and wait while it is active
                while (splitInterface.gameObject.activeSelf == true)
                {
                    yield return(new WaitForEndOfFrame());
                }
                // Get splitted stack amount
                amount = splitInterface.GetRightAmount();
            }
        }

        if (amount > 0)
        {
            if (sourceStackGroup != destStackGroup &&
                (destStackGroup.arrangeMode == true || sourceStackGroup.arrangeMode == true))
            {
                // Split ain arrange mode between different stack groups
                if (priceItem != null && buyer != null && seller != null && buyer != seller)
                {
                    // Different price groups
                    if (buyer.GetCash() > priceItem.GetPrice() * amount)
                    {
                        // Has anough cash
                        int distributed = DistributeAnywhere(theirStackItem, amount, null);
                        if (distributed > 0)
                        {
                            int totalPrice = priceItem.GetPrice() * distributed;
                            seller.AddCash(totalPrice);
                            buyer.SpendCash(totalPrice);

                            buyer.UpdatePrices();
                        }
                    }
                }
                else
                {
                    // Same price group
                    DistributeAnywhere(theirStackItem, amount, null);
                }
            }
            else
            {
                // Inside same stack group transactions disabled in arrange mode
                if (arrangeMode == false)
                {
                    if (myStackItem != null)
                    {
                        // Check if items allowed for cells
                        if (SortCell.IsSortAllowed(myStackCell.gameObject, theirStackItem.gameObject) == true &&
                            SortCell.IsSortAllowed(theirStackCell.gameObject, myStackItem.gameObject) == true)
                        {
                            // Destination cell already has item
                            if (myStackCell.HasSameItem(theirStackItem) == true)
                            {
                                // Same item
                                myStackCell.UniteStack(theirStackItem, amount);
                            }
                            else
                            {
                                // Different items. Try to swap items between cells
                                if (myStackCell.SwapStacks(theirStackCell) == true)
                                {
                                    // Swap successful
                                    theirStackItem = theirStackCell.GetStackItem();
                                    if (theirStackItem != null)
                                    {
                                        // Distribute item after swap
                                        DistributeInItems(theirStackItem, theirStackItem.GetStack(), theirStackCell);
                                    }
                                }
                                else
                                {
                                    // Swap unsuccessful.
                                    // Try to distribute item between other cells to make cell free
                                    DistributeAnywhere(myStackItem, myStackItem.GetStack(), myStackCell);
                                    myStackItem = myStackCell.GetStackItem();
                                    if (myStackItem != null)
                                    {
                                        // Item still in cell. Try to place item in other group's cells
                                        sourceStackGroup.DistributeAnywhere(myStackItem, myStackItem.GetStack(), null);
                                        myStackItem = myStackCell.GetStackItem();
                                        if (myStackItem == null)
                                        {
                                            // Item was placed into other cell and now this cell is free
                                            // Place item into destination cell
                                            myStackCell.UniteStack(theirStackItem, amount);
                                        }
                                    }
                                    else
                                    {
                                        // Item was placed into other cell and now this cell is free
                                        // Place item into destination cell
                                        myStackCell.UniteStack(theirStackItem, amount);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // Destination cell has no item
                        // Place item into destination cell
                        myStackCell.UniteStack(theirStackItem, amount);
                    }
                }
            }
        }
        // Send stack event notification
        SendNotification(sourceStackGroup.gameObject, destStackGroup.gameObject);
        if (trashBinMode == true)
        {
            // In trash bin mode just destroy item
            desc.destinationCell.RemoveItem();
            PlaySound(trashBinSound);
        }
        else
        {
            audioSource.PlayOneShot(itemSound);
        }
        myState = MyState.WaitForRequest;
    }
예제 #20
0
        public void InitDocmentManager()
        {
            #region 加载设备Docment
            StackGroup groupGas = new StackGroup();
            StackGroup groupPM  = new StackGroup();
            StackGroup groupAir = new StackGroup();
            groupGas.Length.UnitType  = LengthUnitType.Star;
            groupGas.Length.UnitValue = 3;
            groupPM.Length.UnitType   = LengthUnitType.Star;
            groupPM.Length.UnitValue  = 3;
            groupAir.Length.UnitType  = LengthUnitType.Star;
            groupAir.Length.UnitValue = 3;
            ucDocmentManager1.AddStackGroup(groupGas);
            ucDocmentManager1.AddStackGroup(groupPM);
            ucDocmentManager1.AddStackGroup(groupAir);

            List <Document> mDocments = new List <Document>();
            if (SysGlobal.m_Device != null)
            {
                for (int i = 0; i < SysGlobal.m_Device.Count - 1; i++)
                {
                    Document devDocment = new Document();
                    devDocment.Caption = SysGlobal.m_Device.ElementAt(i).devChName;
                    devDocment.Properties.AllowClose    = DevExpress.Utils.DefaultBoolean.False;
                    devDocment.Properties.AllowDock     = DevExpress.Utils.DefaultBoolean.False;
                    devDocment.Properties.AllowFloat    = DevExpress.Utils.DefaultBoolean.False;
                    devDocment.Properties.AllowActivate = DevExpress.Utils.DefaultBoolean.False;
                    ucDocmentManager1.AddDocument(devDocment);
                    if (SysGlobal.m_Device[i].devType == 1)
                    {
                        groupGas.Items.Add(devDocment);
                    }
                    else if (SysGlobal.m_Device[i].devType == 2)
                    {
                        groupPM.Items.Add(devDocment);
                    }
                    else if (SysGlobal.m_Device[i].devType == 3)
                    {
                        groupAir.Items.Add(devDocment);
                    }
                }
            }

            for (int i = 0; i < 8; i++)
            {
                Document tempDocment = new Document();
                tempDocment.Caption = "二氧化硫";
                ucDocmentManager1.AddDocument(tempDocment);
                if (i < 3)
                {
                    groupPM.Items.Add(tempDocment);
                }
                else if (i >= 3 && i < 6)
                {
                    groupGas.Items.Add(tempDocment);
                }
                else
                {
                    groupAir.Items.Add(tempDocment);
                }
            }
            #endregion

            #region 加载状态Docment
            StackGroup groupState = new StackGroup();
            groupState.Length.UnitType  = LengthUnitType.Star;
            groupState.Length.UnitValue = 1;
            Document homeDocment = new Document();
            homeDocment.Caption = "系统状态";
            homeDocment.Properties.AllowClose    = DevExpress.Utils.DefaultBoolean.False;
            homeDocment.Properties.AllowDock     = DevExpress.Utils.DefaultBoolean.False;
            homeDocment.Properties.AllowFloat    = DevExpress.Utils.DefaultBoolean.False;
            homeDocment.Properties.AllowActivate = DevExpress.Utils.DefaultBoolean.False;


            Document statuesDocment = new Document();
            statuesDocment.Caption = "主页曲线";
            statuesDocment.Properties.AllowClose    = DevExpress.Utils.DefaultBoolean.False;
            statuesDocment.Properties.AllowDock     = DevExpress.Utils.DefaultBoolean.False;
            statuesDocment.Properties.AllowFloat    = DevExpress.Utils.DefaultBoolean.False;
            statuesDocment.Properties.AllowActivate = DevExpress.Utils.DefaultBoolean.False;

            groupState.Items.AddRange(new Document[] { homeDocment, statuesDocment });
            ucDocmentManager2.AddStackGroup(groupState);
            ucDocmentManager2.AddDocument(homeDocment);
            ucDocmentManager2.AddDocument(statuesDocment);
            #endregion
        }
예제 #21
0
    private StackGroup myStackGroup;                                                                                            // My stack group

    /// <summary>
    /// Awake this instance.
    /// </summary>
    void Awake()
    {
        myStackGroup = GetComponentInParent <StackGroup>();
        Debug.Assert(targetStackGroup && myStackGroup, "Wrong settings");
    }
예제 #22
0
파일: StackGroup.cs 프로젝트: TFM-AEIS/TFM
    /// <summary>
    /// Stack event handler.
    /// </summary>
    /// <returns>The handler.</returns>
    /// <param name="desc">Desc.</param>
    private IEnumerator EventHandler(DadCell.DadEventDescriptor dadDesc)
    {
        StackGroup sourceStackGroup = AccessUtility.GetComponentInParent <StackGroup>(dadDesc.sourceCell.transform);
        StackGroup destStackGroup   = AccessUtility.GetComponentInParent <StackGroup>(dadDesc.destinationCell.transform);

        if (sourceStackGroup == null || destStackGroup == null)
        {
            dadDesc.groupPermission = false;
            myState = MyState.WaitForRequest;
            yield break;
        }

        StackCell destStackCell   = dadDesc.destinationCell.GetComponent <StackCell>();
        StackCell sourceStackCell = dadDesc.sourceCell.GetComponent <StackCell>();

        if (destStackCell == null || sourceStackCell == null)
        {
            dadDesc.groupPermission = false;
            myState = MyState.WaitForRequest;
            yield break;
        }

        StackItem destStackItem   = destStackCell.GetStackItem();
        StackItem sourceStackItem = sourceStackCell.GetStackItem();

        StackGroupEventDescriptor stackDescPrimary = new StackGroupEventDescriptor();   // Stack event info

        stackDescPrimary.sourceGroup      = sourceStackGroup;
        stackDescPrimary.destinationGroup = destStackGroup;
        stackDescPrimary.sourceCell       = sourceStackCell;

        StackGroupEventDescriptor stackDescSecondary = new StackGroupEventDescriptor(); // One more stack event info in case if destination cell is not empty and items were swapped

        stackDescSecondary.sourceGroup      = destStackGroup;
        stackDescSecondary.destinationGroup = sourceStackGroup;
        stackDescSecondary.sourceCell       = destStackCell;

        DistributeResults distributeResults = new DistributeResults();                  // Info with results of stack item distribution in stack group

        PriceItem  priceItem = sourceStackItem.GetComponent <PriceItem>();
        PriceGroup buyer     = AccessUtility.GetComponentInParent <PriceGroup>(dadDesc.destinationCell.transform);
        PriceGroup seller    = AccessUtility.GetComponentInParent <PriceGroup>(dadDesc.sourceCell.transform);

        AudioClip itemSound = sourceStackItem.sound;                                    // Item's SFX

        int amount = sourceStackItem.GetStack();                                        // Item's stack amount

        if (amount > 1)
        {
            // If item's stack > 1 try to use split interface
            if ((globalSplit == true) ||
                (sourceStackGroup != destStackGroup && (sourceStackGroup.splitOuter == true || destStackGroup.splitOuter == true)))
            {
                // Need to use split interface
                if (splitInterface != null)
                {
                    if (priceItem != null && buyer != null && seller != null && buyer != seller)
                    {
                        // Split with prices
                        splitInterface.ShowSplitter(sourceStackItem, priceItem);
                    }
                    else
                    {
                        // Split without prices
                        splitInterface.ShowSplitter(sourceStackItem, null);
                    }
                    // Show split interface and wait while it is active
                    while (splitInterface.gameObject.activeSelf == true)
                    {
                        yield return(new WaitForEndOfFrame());
                    }
                    // Get splitted stack amount
                    amount = splitInterface.GetRightAmount();
                }
            }
        }

        if (amount > 0)
        {
            if (sourceStackGroup != destStackGroup &&
                (destStackGroup.arrangeMode == true || sourceStackGroup.arrangeMode == true))
            {
                // Split in arrange mode between different stack groups
                if (priceItem != null && buyer != null && seller != null && buyer != seller)
                {
                    // Different price groups
                    if ((long)buyer.GetCash() >= (long)priceItem.GetPrice() * amount)
                    {
                        // Has anough cash
                        distributeResults = DistributeAnywhere(sourceStackItem, amount, null);
                        if (distributeResults.amount > 0)
                        {
                            stackDescPrimary.destinationCells = distributeResults.cells;

                            int totalPrice = priceItem.GetPrice() * distributeResults.amount;
                            seller.AddCash(totalPrice);
                            buyer.SpendCash(totalPrice);

                            buyer.UpdatePrices();
                        }
                    }
                }
                else
                {
                    // Same price group
                    distributeResults = DistributeAnywhere(sourceStackItem, amount, null);
                    if (distributeResults.amount > 0)
                    {
                        stackDescPrimary.destinationCells = distributeResults.cells;
                    }
                }
            }
            else
            {
                // Inside same stack group transactions disabled in arrange mode
                if (arrangeMode == false)
                {
                    if (destStackItem != null)
                    {
                        // Check if items allowed for destination cell
                        if (SortCell.IsSortAllowed(destStackCell.gameObject, sourceStackItem.gameObject) == true)

                        {
                            // Destination cell already has same item
                            if (destStackCell.HasSameItem(sourceStackItem) == true)
                            {
                                if (destStackCell.UniteStack(sourceStackItem, amount) > 0)
                                {
                                    stackDescPrimary.destinationCells.Add(destStackCell);
                                }
                            }
                            // Check if items allowed for source cell
                            else if (SortCell.IsSortAllowed(sourceStackCell.gameObject, destStackItem.gameObject) == true)
                            {
                                // Different items. Try to swap items between cells
                                if (destStackCell.SwapStacks(sourceStackCell) == true)
                                {
                                    // Swap successful
                                    stackDescSecondary.destinationCells.Add(sourceStackCell);
                                    sourceStackItem = sourceStackCell.GetStackItem();
                                    if (sourceStackItem != null)
                                    {
                                        // Distribute item after swap
                                        distributeResults = DistributeInItems(sourceStackItem, sourceStackItem.GetStack(), destStackCell);
                                        if (distributeResults.amount > 0)
                                        {
                                            stackDescPrimary.destinationCells = distributeResults.cells;
                                        }
                                        if (destStackCell.GetStackItem() != null)
                                        {
                                            // If stack item (or part of it) in destination cell
                                            stackDescPrimary.destinationCells.Add(destStackCell);
                                        }
                                    }
                                }
                                else
                                {
                                    // Swap unsuccessful.
                                    // Try to distribute item between other cells to make cell free
                                    distributeResults = DistributeAnywhere(destStackItem, destStackItem.GetStack(), destStackCell);
                                    if (distributeResults.amount > 0)
                                    {
                                        stackDescSecondary.destinationCells = distributeResults.cells;
                                    }
                                    destStackItem = destStackCell.GetStackItem();
                                    if (destStackItem != null)
                                    {
                                        // Item still in cell. Try to place item in other group's cells
                                        distributeResults = sourceStackGroup.DistributeAnywhere(destStackItem, destStackItem.GetStack(), null);
                                        if (distributeResults.amount > 0)
                                        {
                                            stackDescSecondary.destinationCells.AddRange(distributeResults.cells);
                                        }
                                        destStackItem = destStackCell.GetStackItem();
                                        if (destStackItem == null)
                                        {
                                            // Item was placed into other cell and now this cell is free
                                            // Place item into destination cell
                                            if (destStackCell.UniteStack(sourceStackItem, amount) > 0)
                                            {
                                                stackDescPrimary.destinationCells.Add(destStackCell);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        // Item was placed into other cell and now this cell is free
                                        // Place item into destination cell
                                        if (destStackCell.UniteStack(sourceStackItem, amount) > 0)
                                        {
                                            stackDescPrimary.destinationCells.Add(destStackCell);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // Destination cell has no item
                        // Place item into destination cell
                        if (destStackCell.UniteStack(sourceStackItem, amount) > 0)
                        {
                            stackDescPrimary.destinationCells.Add(destStackCell);
                        }
                    }
                }
            }
        }

        // Send stack event notifications
        if (stackDescSecondary.destinationCells.Count > 0)
        {
            SendNotification(stackDescSecondary);
        }
        if (stackDescPrimary.destinationCells.Count > 0)
        {
            SendNotification(stackDescPrimary);
            if (trashBinMode == true)
            {
                // In trash bin mode just destroy item
                dadDesc.destinationCell.RemoveItem();
                PlaySound(trashBinSound);
            }
            else
            {
                PlaySound(itemSound);
            }
        }

        myState = MyState.WaitForRequest;
        eventHandkerCoroutine = null;
    }