Exemplo n.º 1
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 = Gets.GetComponentInParent <DadCell>(transform);
            if (dadCell != null)
            {
                dadCell.RemoveItem();
            }
            else
            {
                Destroy(gameObject);
            }
        }
    }
 /// <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);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
            public static void Get(GetInterceptor interceptor)
            {
                Type type = interceptor.GetType();

                if (Gets.ContainsKey(type))
                {
                    return;
                }
                Gets.Add(type, interceptor);
            }
Exemplo n.º 4
0
    /// <summary>
    /// Remove quick item.
    /// </summary>
    public void Remove()
    {
        DadCell dadCell = Gets.GetComponentInParent <DadCell>(transform);

        if (dadCell != null)
        {
            dadCell.RemoveItem();
        }
        else
        {
            Destroy(gameObject);
        }
    }
Exemplo n.º 5
0
 private float GetPrice(float offPrice, Item item, Gets get, int leftCount)
 {
     if (leftCount < get.Quantity)
     {
         offPrice += leftCount * item.Price;
     }
     else
     {
         offPrice  += get.Off.Fixed;
         leftCount -= get.Quantity;
         offPrice   = GetPrice(offPrice, item, get, leftCount);
     }
     return(offPrice);
 }
Exemplo n.º 6
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 = Gets.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);
    }
Exemplo n.º 7
0
        private float ComputeOffPrice(Item item, Gets get)
        {
            if (get.Off.Discount != 0)
            {
                return((item.Price * item.Quantity) * (1 - get.Off.Discount / 100));
            }
            else
            {
                float offPrice  = get.Off.Fixed;
                int   leftCount = item.Quantity - get.Quantity;
                offPrice = GetPrice(offPrice, item, get, leftCount);

                return(offPrice);
            }
        }
Exemplo n.º 8
0
        private List <MarkedItem> ApplyGet(Gets get, List <MarkedItem> markedItems, Promotion promo)
        {
            foreach (var m in markedItems)
            {
                if (m.Item.Sku == get.Sku)
                {
                    var isMarkedBuy = m.MarkedBuys.ContainsKey(promo.Id);
                    var isMarkedGet = m.MarkedGets.ContainsKey(promo.Id);

                    if (isMarkedBuy && !isMarkedGet)
                    {
                        m.MarkedGets[promo.Id] = ComputeOffPrice(m.Item, get);
                    }
                }
            }
            return(markedItems);
        }
Exemplo n.º 9
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)
        {
            StackGroup sourceStackGroup = Gets.GetComponentInParent <StackGroup>(stackItem.transform);
            // Try to distribute item inside group's items and cells
            res += DistributeAnywhere(stackItem, limit, null);
            // Send stack event notification
            SendNotification(sourceStackGroup != null ? sourceStackGroup.gameObject : null, gameObject);
            if (res > 0)
            {
                PlaySound(stackItem.sound);
            }
        }
        return(res);
    }
Exemplo n.º 10
0
        public string ToDfnSyntax()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("table " + Name + " {\r\n");
            if (ExistingName != null)
            {
                sb.Append("  existing as " + ExistingName + ";\r\n");
            }
            foreach (string renamed in RenamedFrom)
            {
                sb.Append("  renamed from " + renamed + ";\r\n");
            }
            sb.Append(Fields.DfnSyntaxBlock("  fields", true));
            sb.Append(Gets.DfnSyntaxList(true));
            sb.Append(References.DfnSyntaxList(true));
            sb.Append(BeforeStatements.DfnSyntaxList(true));
            sb.Append("};");
            return(sb.ToString());
        }
Exemplo n.º 11
0
    /// <summary>
    /// Raises the DaD group 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 = Gets.GetComponentInParent <StackGroup>(desc.sourceCell.transform);
                StackGroup destStackControl   = Gets.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
                StartCoroutine(EventHandler(desc));
            }
            break;
        }
    }
Exemplo n.º 12
0
 /// <summary>
 /// Gets the stack cell of this item.
 /// </summary>
 /// <returns>The stack cell.</returns>
 public StackCell GetStackCell()
 {
     return(Gets.GetComponentInParent <StackCell>(transform));
 }
Exemplo n.º 13
0
        // 注册类库
        private void RegLibrary(string path)
        {
            Program.Println($"    正在注册类库 {path} ...");

            // 加载类库
            Assembly assembly = Assembly.LoadFile(path);

            // 遍历类库中的所有类
            var tps = assembly.GetTypes();

            foreach (var tp in tps)
            {
                // 遍历类型特性,判断类是否满足条件
                var attrs = tp.GetCustomAttributes();
                foreach (var attr in attrs)
                {
                    if (attr.GetType().FullName == "dpz3.Modular.ModularAttribute")
                    {
                        // 重建模块化特性
                        dpz3.Modular.ModularAttribute modular = (dpz3.Modular.ModularAttribute)attr;
                        // 找到Api定义类
                        switch (modular.ModularType)
                        {
                        case ModularTypes.Api:
                        case ModularTypes.Session:
                        case ModularTypes.SessionApi:
                            // 读取路由地址定义
                            string route = modular.Route.Replace("{ControllerName}", tp.Name);
                            // 确定类名称
                            string className = "";
                            switch (modular.ModularType)
                            {
                            case ModularTypes.Api: className = "ControllerBase"; break;

                            case ModularTypes.Session: className = "SessionControllerBase"; break;

                            case ModularTypes.SessionApi: className = "JttpSessionControllerBase"; break;
                            }
                            // 遍历所有的函数定义
                            var methods = tp.GetMethods();
                            foreach (var method in methods)
                            {
                                // 遍历函数特性,判断函数是否满足条件
                                var methodAttrs = method.GetCustomAttributes();
                                foreach (var methodAttr in methodAttrs)
                                {
                                    if (methodAttr.GetType().FullName == "dpz3.Modular.ModularAttribute")
                                    {
                                        // 重建模块化特性
                                        dpz3.Modular.ModularAttribute methodModular = (dpz3.Modular.ModularAttribute)methodAttr;
                                        string            routeNew   = $"{route}/{methodModular.Route}".ToLower();
                                        ModularMethodInfo methodInfo = new ModularMethodInfo()
                                        {
                                            Method    = method,
                                            Assembly  = assembly,
                                            Type      = tp,
                                            Route     = routeNew,
                                            ClassName = className,
                                        };
                                        switch (methodModular.ModularType)
                                        {
                                        case dpz3.Modular.ModularTypes.Post:
                                            // 添加一条POST接口信息
                                            Program.Println($"[@] POST /{this.Name}{routeNew} ...");
                                            Posts.Add(methodInfo);
                                            break;

                                        case dpz3.Modular.ModularTypes.Get:
                                            // 添加一条GET接口信息
                                            Program.Println($"[@] GET /{this.Name}{routeNew} ...");
                                            Gets.Add(methodInfo);
                                            // 处理特殊的首页
                                            if (routeNew.EndsWith("/index"))
                                            {
                                                routeNew = routeNew.Substring(0, routeNew.Length - 5);
                                                // 添加一条GET接口信息
                                                Program.Println($"[@] GET /{this.Name}{routeNew} ...");
                                                Gets.Add(new ModularMethodInfo()
                                                {
                                                    Method    = method,
                                                    Assembly  = assembly,
                                                    Type      = tp,
                                                    Route     = routeNew,
                                                    ClassName = className,
                                                });
                                            }
                                            break;
                                        }
                                        // 结束特性循环
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                        // 结束特性循环
                        break;
                    }
                }
            }
        }
 public IDictionary <string, object> Get(DocumentTable table, string key)
 {
     Gets.Add(Tuple.Create(table, key));
     return(store.Get(table, key));
 }
Exemplo n.º 15
0
    /// <summary>
    /// Stack event handler.
    /// </summary>
    /// <returns>The handler.</returns>
    /// <param name="desc">Desc.</param>
    private IEnumerator EventHandler(DadCell.DadEventDescriptor desc)
    {
        StackGroup sourceStackGroup = Gets.GetComponentInParent <StackGroup>(desc.sourceCell.transform);
        StackGroup destStackGroup   = Gets.GetComponentInParent <StackGroup>(desc.destinationCell.transform);

        if (sourceStackGroup == null || destStackGroup == null)
        {
            desc.groupPermission = false;
            // Send stack event notification
            SendNotification(sourceStackGroup != null ? sourceStackGroup.gameObject : null, destStackGroup != null ? destStackGroup.gameObject : null);
            myState = MyState.WaitForRequest;
            yield break;
        }

        StackCell myStackCell    = desc.destinationCell.GetComponent <StackCell>();
        StackCell theirStackCell = desc.sourceCell.GetComponent <StackCell>();

        if (myStackCell == null || theirStackCell == null)
        {
            desc.groupPermission = false;
            // Send stack event notification
            SendNotification(sourceStackGroup.gameObject, destStackGroup.gameObject);
            myState = MyState.WaitForRequest;
            yield break;
        }

        StackItem myStackItem    = myStackCell.GetStackItem();
        StackItem theirStackItem = theirStackCell.GetStackItem();

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

        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 in 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
        {
            PlaySound(itemSound);
        }
        myState = MyState.WaitForRequest;
    }
Exemplo n.º 16
0
 /// <summary>
 /// Gets DaD cell which contains this item.
 /// </summary>
 /// <returns>The cell.</returns>
 public DadCell GetCell()
 {
     return(Gets.GetComponentInParent <DadCell>(transform));
 }
Exemplo n.º 17
0
 private void 词法分析ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Gets.LineNo = 1;                           //初始化行号
     Gets.errors = 0;                      //初始化错误个数
     Gets.text5 = "";
     string text1 = richTextBox1.Text + '\0';
     Gets getstring = new Gets();
     text2 = getstring.GetString(text1);
     richTextBox2.Text = "*****************Token串生成表如下********************" + "\r\n" + text2;
     textBox2.Text = getstring.ErrorN0();
 }