Ejemplo n.º 1
0
        public TLDocumentHeaderListView()
        {
            // isolatedStorageProvider = new IsolatedStorageProvider();

            InitializeComponent();

            Loaded += (s, ea) =>
            {
                _accessUtility = SmObjectFactory.Container.GetInstance <AccessUtility>();

                _viewModel = DataContext as TLDocumentHeaderListViewModel;
                RadGridView1.SelectedItem = null;

                _viewModel.Error       += OnError;
                _viewModel.Information += OnInformation;
                _viewModel.Deleting    += OnDeleting;
                _viewModel.Deleted     += OnDeleted;

                //  isolatedStorageProvider.LoadFromStorage();
            };
            Unloaded += (s, ea) =>
            {
                _viewModel.Error       -= OnError;
                _viewModel.Information -= OnInformation;

                _viewModel.Deleting -= OnDeleting;
                _viewModel.Deleted  -= OnDeleted;

                //  isolatedStorageProvider.SaveToStorage();
            };
        }
Ejemplo n.º 2
0
Archivo: DaDI.cs Proyecto: TFM-AEIS/TFM
    /// <summary>
    /// On menu item select.
    /// </summary>
    static void Skill()
    {
        DadCell res = null;

        if (Selection.activeGameObject != null)
        {
            res = AccessUtility.GetComponentInParent <DadCell>(Selection.activeGameObject.transform);
        }

        if (res != null)
        {
            // Create skill from prefab
            string     prefabName = "Demo/Skill";
            GameObject prefab     = Resources.Load <GameObject>(prefabName);
            if (prefab != null)
            {
                GameObject go = Instantiate(prefab, res.transform);
                go.name = prefab.name;
                go.transform.SetAsFirstSibling();
            }
            else
            {
                Debug.Log("Can't find needed prefab in Resources folder: " + prefabName);
            }
        }
        else
        {
            Debug.Log("Please choose any DaD cell on scene before add this element");
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Updates stack's condition.
    /// </summary>
    private void UpdateCondition()
    {
        int stack = GetStack();

        if (stack > 1)
        {
            ShowStack();
        }
        else if (stack == 1)
        {
            // Hide stack text if stack == 0
            HideStack();
        }
        else
        {
            // Stack <= 0
            DadCell dadCell = AccessUtility.GetComponentInParent <DadCell>(transform);
            if (dadCell != null)
            {
                dadCell.RemoveItem();
            }
            else
            {
                Destroy(gameObject);
            }
        }
    }
Ejemplo n.º 4
0
 public override bool IsAuthorized(AuthFilterContext context)
 {
     if (DomainUtility.IsTestEnvironment)
     {
         return(true);
     }
     using (APIAccessService apiAccessService = new APIAccessService())
     {
         //when a client is calling main api ,they have to put token,which is password, in header named token
         if (context.ActionContext.Request.Headers.Contains("token"))
         {
             return(apiAccessService.HasAccess(ApiUtility.GetIPAddress(), context.ActionContext.Request.Headers.GetValues("token").FirstOrDefault()));
         }
         else
         {
             if (AccessUtility.CalledByLocalSA(HttpContext.Current.Request))
             {
                 //it is called from single action module in same server with same ip.
                 return(true);
             }
             else
             {
                 //when bpms user panel is calling engine api,every request should have formToken in its parameters.
                 string formToken = context.ActionContext.RequestContext.Url.Request.GetHttpContext().Request.QueryString[FormTokenUtility.FormToken];
                 return(FormTokenUtility.ValidateFormToken(formToken, HttpContext.Current.Session.SessionID));
             }
         }
     }
 }
Ejemplo n.º 5
0
    void Start()
    {
        this.AddResourcesToInventory
        (
            "Inventory/Resources/res_cloth",
            "Inventory/Resources/res_cloth",
            "Inventory/Resources/res_cotton",
            "Inventory/Resources/res_cotton",
            "Inventory/Resources/res_cotton"
        );

        // Crea el inventario con el número de casillas especificado
        for (int i = 1; i <= maxSlots; i++)
        {
            Instantiate(slotPrefab, slotsContainer.transform).name = "Slot " + i;
        }

        // Llena el inventario de objetos
        foreach (KeyValuePair <string, int> entry in inventory)
        {
            // Aquí se debe comprobar el número máximo de recursos agrupables.
            // Si por ejemplo hay 78 unidades de tela y se pueden agrupar máximo en grupos de 30,
            // se deberán agrupar en 3 casillas diferentes así: tela x30, tela x30 y tela x18
            Debug.Log(this.AddResource(entry.Key, entry.Value));
        }

        // Init existing items's internal state on scene start
        foreach (StackItem stackItem in AccessUtility.FindObjectsOfType <StackItem>())
        {
            stackItem.Init();
        }

        this.AddRecipe("Inventory/Recipes/rec_shirt");
    }
Ejemplo n.º 6
0
    /// <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);
    }
Ejemplo n.º 7
0
        // private ICompanyInformationsService companyInformationsService;

        public GLListView()
        {
            isolateStorageProvider = new IsolatedStorageProvider();

            _gLsService = SmObjectFactory.Container.GetInstance <IGLsService>();
            //    companyInformationsService = SmObjectFactory.Container.GetInstance<ICompanyInformationsService>();
            InitializeComponent();
            Loaded += (s, ea) =>
            {
                _accessUtility = SmObjectFactory.Container.GetInstance <AccessUtility>();

                _viewModel         = DataContext as GLListViewModel;
                _viewModel.Failed += OnFailed;
                _viewModel.Error  += OnError;
                _viewModel.LoadGLs();
                GLDataForm.CommandProvider = new CustomCommandProvider();
                //
                //GLDataForm.AddNewItem();
                GLRadGridView.SelectedItem  = null;
                detailRadTabItem.IsSelected = true;

                //  isolateStorageProvider.LoadFromStorage();
            };
            Unloaded += (s, ea) =>
            {
                _viewModel.Failed -= OnFailed;
                _viewModel.Error  -= OnError;

                //  isolateStorageProvider.SaveToStorage();
            };
        }
Ejemplo n.º 8
0
    /// <summary>
    /// This item is dropped.
    /// </summary>
    /// <param name="eventData"></param>
    public void OnEndDrag(PointerEventData eventData)
    {
        ResetConditions();
        // Check for cells under cursor
        bool             emptyDrop   = true;
        PointerEventData pointerData = new PointerEventData(EventSystem.current);

        pointerData.position = Input.mousePosition;
        List <RaycastResult> hits = new List <RaycastResult>();

        EventSystem.current.RaycastAll(pointerData, hits);
        if (hits.Count > 0)
        {
            foreach (RaycastResult hit in hits)
            {
                DadCell dadCell = hit.gameObject.GetComponent <DadCell>();
                if (dadCell != null)
                {
                    emptyDrop = false;
                    break;
                }
            }
        }
        if (emptyDrop == true)
        {
            DadCell.DadEventDescriptor desc = new DadCell.DadEventDescriptor();
            desc.sourceCell  = GetCell();
            desc.triggerType = DadCell.TriggerType.EmptyDrop;
            AccessUtility.SendMessageUpwards(transform, "OnDadGroupEvent", desc);
        }
    }
        public TLListView()
        {
            isolatedStorageProvider = new IsolatedStorageProvider();

            _tLsService = SmObjectFactory.Container.GetInstance <ITLsService>();

            InitializeComponent();
            Loaded += (s, ea) =>
            {
                _accessUtility = SmObjectFactory.Container.GetInstance <AccessUtility>();

                _viewModel        = DataContext as TLListViewModel;
                _viewModel.Error += OnError;
                _viewModel.LoadTLs();
                //  RaiseCanExecuteChanged();
                //NavStateFalse();
                //var addNewTLCommand = RadDataFormCommands.AddNew as RoutedUICommand;
                TLDataForm.CommandProvider = new CustomCommandProvider();

                //addNewTLCommand.Execute(null, TLDataForm);
                TLRadGridView.SelectedItem  = null;
                detailRadTabItem.IsSelected = true;
                //   DataContext = _viewModel;

                isolatedStorageProvider.LoadFromStorage();
            };
            Unloaded += (s, ea) =>
            {
                _viewModel.Error -= OnError;

                isolatedStorageProvider.SaveToStorage();
            };
        }
        public TLDocumentItemListView()
        {
            InitializeComponent();
            Loaded += (s, ea) =>
            {
                _accessUtility = SmObjectFactory.Container.GetInstance <AccessUtility>();

                _viewModel = DataContext as TLDocumentItemListViewModel;
                RadGridView1.SelectedItem = null;
            };
        }
Ejemplo n.º 11
0
    private PriceGroup priceGroup;                                                                                      // Player's price group

    /// <summary>
    /// Start this instance.
    /// </summary>
    void Start()
    {
        // Init existing items's internal state on scene start
        foreach (StackItem stackItem in AccessUtility.FindObjectsOfType <StackItem>())
        {
            stackItem.Init();
        }

        priceGroup = GetComponent <PriceGroup>();
        Debug.Assert(equipment && inventory && vendor && skills && inventoryStackGroup && equipmentStackGroup && vendorStackGroup && clickEquipInventory && priceGroup, "Wrong settings");
        priceGroup.ShowPrices(vendor.activeSelf);
    }
Ejemplo n.º 12
0
        // GET: Audits
        public ActionResult Index(int?id)
        {
            var audits = from s in db.Audits select s;

            if (id != null)
            {
                audits = audits.Where(audit => audit.ProjectId == id);
            }

            ViewBag.IsCreateEnable = AccessUtility.IsCreateEnable(db, User.Identity.Name);
            return(View(audits.Include(a => a.Project).ToList()));
        }
Ejemplo n.º 13
0
    /// <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);
    }
Ejemplo n.º 14
0
    /// <summary>
    /// Remove quick item.
    /// </summary>
    public void Remove()
    {
        DadCell dadCell = AccessUtility.GetComponentInParent <DadCell>(transform);

        if (dadCell != null)
        {
            dadCell.RemoveItem();
        }
        else
        {
            Destroy(gameObject);
        }
    }
Ejemplo n.º 15
0
        public TreeAccountListView()
        {
            _systemAccountingSettingsService = SmObjectFactory.Container.GetInstance <ISystemAccountingSettingsService>();
            _gLsService = SmObjectFactory.Container.GetInstance <IGLsService>();
            InitializeComponent();
            Loaded += (s, ea) =>
            {
                _accessUtility = SmObjectFactory.Container.GetInstance <AccessUtility>();

                _vm = DataContext as TreeAccountListViewModel;
                _vm.Load();
            };
        }
Ejemplo n.º 16
0
    /// <summary>
    /// Unites item in stack with this cell.
    /// </summary>
    /// <returns>The stack.</returns>
    /// <param name="stackItem">Stack item.</param>
    /// <param name="limit">Stack limit.</param>
    public int UniteStack(StackItem stackItem, int limit)
    {
        int res = 0;

        if (stackItem != null)
        {
            int       allowedSpace = GetAllowedSpace();
            StackItem myStackItem  = GetStackItem();
            if (myStackItem == null)                                                                            // Cell has no item
            {
                if (SortCell.IsSortAllowed(gameObject, stackItem.gameObject) == true)                           // Item type is allowed for this cell
                {
                    if (stackItem.GetStack() == limit && allowedSpace >= limit)                                 // Cell has anough space for all item's stack
                    {
                        // Totaly place item in new cell
                        DadCell sourceDadCell = AccessUtility.GetComponentInParent <DadCell>(stackItem.transform);
                        if (sourceDadCell != null)
                        {
                            DadCell.SwapItems(gameObject, sourceDadCell.gameObject);
                        }
                        else
                        {
                            DadCell.AddItem(gameObject, stackItem.gameObject);
                        }
                        res = limit;
                    }
                    else                                                                                                                                                        // Only part of item stack will be placed into new cell
                    {
                        // Create new stack item to put it into this cell
                        StackItem newStackItem = Instantiate(stackItem);
                        newStackItem.name = stackItem.name;
                        DadCell.AddItem(gameObject, newStackItem.gameObject);
                        // Check the correct amout of united item
                        int stackDelta = Mathf.Min(stackItem.GetStack(), allowedSpace, limit);
                        newStackItem.SetStack(stackDelta);
                        stackItem.ReduceStack(stackDelta);
                        res = stackDelta;
                    }
                }
            }
            else if (HasSameItem(stackItem) == true)                                                                                            // Cell has same item
            {
                int stackDelta = Mathf.Min(stackItem.GetStack(), allowedSpace, limit);
                myStackItem.AddStack(stackDelta);
                stackItem.ReduceStack(stackDelta);
                res = stackDelta;
            }
        }
        return(res);
    }
Ejemplo n.º 17
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);
         }
     }
 }
Ejemplo n.º 18
0
        // GET: Projects/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var project = db.Projects.Find(id);

            if (project == null)
            {
                return(HttpNotFound());
            }

            ViewBag.IsEditEnable   = AccessUtility.IsEditEnable(db, User.Identity.Name);
            ViewBag.IsDeleteEnable = AccessUtility.IsDeleteEnable(db, User.Identity.Name);
            return(View(project));
        }
Ejemplo n.º 19
0
    /// <summary>
    /// Uses the item.
    /// </summary>
    public void UseItem()
    {
        bool res = true;

        CooldownItem cooldown = GetComponent <CooldownItem>();

        if (cooldown != null && cooldown.timeLeft > 0f)
        {
            res = false;
        }
        // Use item if there is no active cooldown
        if (res == true)
        {
            // Notify application about item use
            AccessUtility.SendMessageUpwards(transform, "OnItemUse", gameObject);
        }
    }
Ejemplo n.º 20
0
        // GET: Audits/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var audit = db.Audits.Include(s => s.Project).Include(s => s.Files).SingleOrDefault(s => s.AuditId == id);

            if (audit == null)
            {
                return(HttpNotFound());
            }

            ViewBag.IsAddResultEnable = AccessUtility.IsAddResultEnable(db, User.Identity.Name) &&
                                        (audit.Status == AuditStatuses.Planned || audit.Status == AuditStatuses.InProgress);
            ViewBag.IsEditEnable   = AccessUtility.IsEditEnable(db, User.Identity.Name);
            ViewBag.IsDeleteEnable = AccessUtility.IsDeleteEnable(db, User.Identity.Name);
            return(View(audit));
        }
Ejemplo n.º 21
0
        public UserListView()
        {
            InitializeComponent();
            Loaded += (s, ea) =>
            {
                _accessUtility = SmObjectFactory.Container.GetInstance <AccessUtility>();

                _viewModel = DataContext as UserListViewModel;
                radGridView.SelectedItem = null;
                _viewModel.Deleting     += OnDeleting;
                _viewModel.Deleted      += OnDeleted;
                _viewModel.Failed       += OnFailed;
            };
            Unloaded += (s, ea) =>
            {
                _viewModel.Deleting -= OnDeleting;
                _viewModel.Deleted  -= OnDeleted;
                _viewModel.Failed   -= OnFailed;
            };
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Removes quick slot items if they have no source or source is not in permitted groups
 /// </summary>
 public void RemoveUnresolvedItems()
 {
     foreach (QuickItem quickItem in GetComponentsInChildren <QuickItem>(true))
     {
         bool hit = false;
         // Chek if item source is child of this GO
         foreach (Transform parentTransform in AccessUtility.GetComponentsInParent <Transform>(quickItem.itemSource.transform))
         {
             if (permittedSources.Contains(parentTransform.gameObject) == true)
             {
                 hit = true;
                 break;
             }
         }
         if (hit == false)
         {
             // If item source was moved outside or deleted - remove quick item
             quickItem.Remove();
         }
     }
 }
Ejemplo n.º 23
0
    /// <summary>
    /// Raises the DaD group event.
    /// </summary>
    /// <param name="desc">Desc.</param>
    public 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 = AccessUtility.GetComponentInParent <StackGroup>(desc.sourceCell.transform);
                StackGroup destStackControl   = AccessUtility.GetComponentInParent <StackGroup>(desc.destinationCell.transform);
                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
                eventHandkerCoroutine = coroutineContainer.StartCoroutine(EventHandler(desc));
            }
            break;
        }
    }
Ejemplo n.º 24
0
 /// <summary>
 /// Sends the stack event notification.
 /// </summary>
 /// <param name="desc">Event descriptor.</param>
 private void SendNotification(StackGroupEventDescriptor desc)
 {
     if (desc.sourceGroup != null)
     {
         // Send notification to source GO
         AccessUtility.SendMessageUpwards(desc.sourceGroup.transform, "OnStackGroupEvent", desc);
         foreach (GameObject receiver in desc.sourceGroup.eventAdditionalReceivers)
         {
             // Send notification to additionaly specified GOs
             AccessUtility.SendMessage(receiver.transform, "OnStackGroupEvent", desc);
         }
     }
     if (desc.destinationGroup != null && desc.sourceGroup != desc.destinationGroup && desc.destinationGroup.trashBinMode == false)
     {
         // Send notification to destination GO
         AccessUtility.SendMessageUpwards(desc.destinationGroup.transform, "OnStackGroupEvent", desc);
         foreach (GameObject receiver in desc.destinationGroup.eventAdditionalReceivers)
         {
             // Send notification to additionaly specified GOs
             AccessUtility.SendMessage(receiver.transform, "OnStackGroupEvent", desc);
         }
     }
 }
Ejemplo n.º 25
0
        public CloseProfitLossAccountListView()
        {
            isolatedStorageProvider = new IsolatedStorageProvider();

            InitializeComponent();
            Loaded += (s, ea) =>
            {
                _accessUtility = SmObjectFactory.Container.GetInstance <AccessUtility>();

                _viewModel = DataContext as CloseProfitLossAccountListViewModel;
                RadGridView1.SelectedItem = null;
                _viewModel.Error         += OnError;
                _viewModel.Information   += OnInformation;

                isolatedStorageProvider.LoadFromStorage();
            };
            Unloaded += (s, ea) =>
            {
                _viewModel.Error       -= OnError;
                _viewModel.Information -= OnInformation;

                isolatedStorageProvider.SaveToStorage();
            };
        }
Ejemplo n.º 26
0
        // GET: Projects
        public ActionResult Index(string sortOrder, string searchString)
        {
            ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";

            var projects = from s in db.Projects select s;

            if (!string.IsNullOrEmpty(searchString))
            {
                projects = projects.Where(s => s.Name.Contains(searchString));
            }

            var audits = from s in db.Audits select s;

            var projectView = HelperForProject.CreateProjectView(projects.ToList(), audits.ToList());

            switch (sortOrder)
            {
            case "name_desc":
                projectView = projectView.OrderByDescending(s => s.Project.Name);
                break;

            //case "Date":
            //    projects = projects.OrderBy(s => s.PlannedDate);
            //    break;
            //case "date_desc":
            //    projects = projects.OrderByDescending(s => s.PlannedDate);
            //    break;
            default:
                projectView = projectView.OrderBy(s => s.Project.Name);
                break;
            }

            ViewBag.IsCreateEnable = AccessUtility.IsCreateEnable(db, User.Identity.Name);
            return(View(projectView.ToList()));
        }
Ejemplo n.º 27
0
    /// <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;
    }
Ejemplo n.º 28
0
 /// <summary>
 /// Gets the stack cell of this item.
 /// </summary>
 /// <returns>The stack cell.</returns>
 public StackCell GetStackCell()
 {
     return(AccessUtility.GetComponentInParent <StackCell>(transform));
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Gets DaD cell which contains this item.
 /// </summary>
 /// <returns>The cell.</returns>
 public DadCell GetCell()
 {
     return(AccessUtility.GetComponentInParent <DadCell>(transform));
 }