public bool WeaponCanUse(IWeapon weapon)
        {
            if (!isMainPlayer && null != m_NPC && !m_NPC.HasConsume)
            {
                return(true);
            }
            PeSword sword = weapon as PeSword;

            if (null != sword)
            {
                return(true);
            }
            PEGun gun = weapon as PEGun;

            if (null != gun)
            {
                if (m_GunFire.m_IgnoreItem)
                {
                    return(true);
                }
                if (gun.m_AmmoType == AmmoType.Bullet)
                {
                    return(gun.durability > PETools.PEMath.Epsilon &&
                           (gun.magazineValue > PETools.PEMath.Epsilon || null == m_Package || m_Package.GetItemCount(gun.curItemID) > 0));
                }

                return(gun.durability > PETools.PEMath.Epsilon &&
                       (gun.magazineValue > PETools.PEMath.Epsilon || Entity.GetAttribute(AttribType.Energy) > PETools.PEMath.Epsilon));
            }
            PEBow bow = weapon as PEBow;

            if (null != bow)
            {
                if (m_BowShoot.m_IgnoreItem)
                {
                    return(true);
                }
                return(bow.durability > PETools.PEMath.Epsilon && null == m_Package || m_Package.GetItemCount(bow.curItemID) > 0);
            }

            return(true);
        }
 void Update()
 {
     if (Pathea.PeCreature.Instance.mainPlayer == null)
     {
         return;
     }
     // Has player enough items ?
     Pathea.PackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PackageCmpt>();
     if (mCbTexture.isChecked)
     {
         foreach (UIBuildWndItem item in mVoxelMatList)
         {
             item.SetNumber(pkg.GetItemCount(item.ItemId).ToString());
         }
     }
     else if (mCbBlock.isChecked)
     {
         foreach (UIBuildWndItem item in mBlockMatList)
         {
             item.SetNumber(pkg.GetItemCount(item.ItemId).ToString());
         }
     }
 }
    void Update()
    {
        if (DragObejct != null)
        {
            if (Input.GetMouseButtonUp(0))
            {
                Destroy(DragObejct);
                DragObejct = null;

                if (DragItem != null)
                {
                    if (DragItem.mItemType == UIBuildWndItem.ItemType.mMenu)
                    {
                        UIBlockSaver.Instance.RemoveData((mBoxBars.PageIndex - 1) * c_MaxMenuItems + DragItem.mIndex);
                        UpdateMenuItems(mBoxBars.PageIndex);
                        DragItem = null;
                    }
                }
            }
        }

        // ShortCut
        if (PeInput.Get(PeInput.LogicFunction.QuickBar1))
        {
            if (onQuickBarFunc != null)
            {
                onQuickBarFunc(mMenuList[0]);
            }
            mMenuList[0].PlayGridEffect();
        }
        else if (PeInput.Get(PeInput.LogicFunction.QuickBar2))
        {
            if (onQuickBarFunc != null)
            {
                onQuickBarFunc(mMenuList[1]);
            }
            mMenuList[1].PlayGridEffect();
        }
        else if (PeInput.Get(PeInput.LogicFunction.QuickBar3))
        {
            if (onQuickBarFunc != null)
            {
                onQuickBarFunc(mMenuList[2]);
            }
            mMenuList[2].PlayGridEffect();
        }
        else if (PeInput.Get(PeInput.LogicFunction.QuickBar4))
        {
            if (onQuickBarFunc != null)
            {
                onQuickBarFunc(mMenuList[3]);
            }
            mMenuList[3].PlayGridEffect();
        }
        else if (PeInput.Get(PeInput.LogicFunction.QuickBar5))
        {
            if (onQuickBarFunc != null)
            {
                onQuickBarFunc(mMenuList[4]);
            }
            mMenuList[4].PlayGridEffect();
        }
        else if (PeInput.Get(PeInput.LogicFunction.QuickBar6))
        {
            if (onQuickBarFunc != null)
            {
                onQuickBarFunc(mMenuList[5]);
            }
            mMenuList[5].PlayGridEffect();
        }
        else if (PeInput.Get(PeInput.LogicFunction.QuickBar7))
        {
            if (onQuickBarFunc != null)
            {
                onQuickBarFunc(mMenuList[6]);
            }
            mMenuList[6].PlayGridEffect();
        }
        else if (PeInput.Get(PeInput.LogicFunction.QuickBar8))
        {
            if (onQuickBarFunc != null)
            {
                onQuickBarFunc(mMenuList[7]);
            }
            mMenuList[7].PlayGridEffect();
        }
        else if (PeInput.Get(PeInput.LogicFunction.QuickBar9))
        {
            if (onQuickBarFunc != null)
            {
                onQuickBarFunc(mMenuList[8]);
            }
            mMenuList[8].PlayGridEffect();
        }
        else if (PeInput.Get(PeInput.LogicFunction.QuickBar10))
        {
            if (onQuickBarFunc != null)
            {
                onQuickBarFunc(mMenuList[9]);
            }
            mMenuList[9].PlayGridEffect();
        }

        // Short Cut For Brush
        if (PeInput.Get(PeInput.LogicFunction.Build_Shortcut1))
        {
            if (!mPointBtn.checkBox.isChecked)
            {
                mPointBtn.checkBox.isChecked = true;
                BtnBrush1_OnClick();
            }
        }
        else if (PeInput.Get(PeInput.LogicFunction.Build_Shortcut2))
        {
            if (!mBoxBtn.checkBox.isChecked)
            {
                mBoxBtn.checkBox.isChecked = true;
                BtnBrush2_OnClick();
            }
        }
        else if (PeInput.Get(PeInput.LogicFunction.Build_Shortcut3))
        {
            if (!mDiagonalBtn.checkBox.isChecked)
            {
                UISkillWndCtrl uiSkill = GameUI.Instance.mSkillWndCtrl;
                if (uiSkill._SkillMgr != null)
                {
                    if (!uiSkill._SkillMgr.CheckUnlockBuildBlockBevel())
                    {
                        return;
                    }
                }

                mDiagonalBtn.checkBox.isChecked = true;
                BtnBrush3_OnClick();
            }
        }
        else if (PeInput.Get(PeInput.LogicFunction.Build_Shortcut4))
        {
            if (!mSelectBtn.checkBox.isChecked)
            {
                mSelectBtn.checkBox.isChecked = true;
                BtnBrush4_OnClick();
            }
        }
        else if (PeInput.Get(PeInput.LogicFunction.Build_Shortcut5))
        {
            if (!mSelectBlockBtn.checkBox.isChecked)
            {
                mSelectBlockBtn.checkBox.isChecked = true;
                BtnBrush5_OnClick();
            }
        }
        else if (PeInput.Get(PeInput.LogicFunction.Build_Shortcut6))
        {
            BtnSaveOnClick();
        }
        else if (PeInput.Get(PeInput.LogicFunction.Build_Shortcut7))
        {
            BtnMenuOnClick();
        }

        if (PeInput.Get(PeInput.LogicFunction.PrevQuickBar))
        {
            mBoxBars.BtnPageUpOnClick();
        }

        if (PeInput.Get(PeInput.LogicFunction.NextQuickBar))
        {
            mBoxBars.BtnPageDnOnClick();
        }

        //if (Input.GetKeyDown(KeyCode.Tab))
        //{
        //	if (mPointBtn.checkBox.isChecked)
        //	{
        //		if (onQuickSwitchPointBrush != null)
        //			onQuickSwitchPointBrush();
        //	}
        //	//else if (mDiagonalBtn.checkBox.isChecked)
        //	//{
        //	//	if (onQuickSwitchDiagonalBrush != null)
        //	//		onQuickSwitchDiagonalBrush();
        //	//}
        //	else if (mBoxBtn.checkBox.isChecked)
        //	{
        //		if (onQuickSwitchBoxBrush != null)
        //			onQuickSwitchBoxBrush();
        //	}
        //}

        //
        if (Pathea.PeCreature.Instance.mainPlayer != null)
        {
            Pathea.PackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PackageCmpt>();
            foreach (UIBuildWndItem item in mMenuList)
            {
                if (item.mTargetItemType == UIBuildWndItem.ItemType.mBlockMat)
                {
                    item.SetNumber(pkg.GetItemCount(item.ItemId).ToString());
                }
                else if (item.mTargetItemType == UIBuildWndItem.ItemType.mVoxelType)
                {
                    int proto_id = PEBuildingMan.GetVoxelItemProtoID((byte)item.ItemId);
                    item.SetNumber(pkg.GetItemCount(proto_id).ToString());
                }
                else if (item.mTargetItemType == UIBuildWndItem.ItemType.mBlockPattern)
                {
                    item.SetNumber(mBulidWnd.mBlockPatternList[item.mTargetIndex].mNumber.text);
                }
                else
                {
                    item.SetNumber("");
                }
            }
        }
    }
    /// <summary>
    /// voxel modify check event before really undo and redo. Call by BSVoxelModify
    /// </summary>
    bool OnCheckVoxelModify(int opType, IntVector3[] indexes, BSVoxel[] voxels, BSVoxel[] oldvoxels, EBSBrushMode mode, IBSDataSource ds)
    {
        if (IsGod)
        {
            return(true);
        }

        if (Pathea.PeCreature.Instance.mainPlayer == null)
        {
            return(false);
        }

        bool result = true;


        if (mode == EBSBrushMode.Add)
        {
            Dictionary <int, int> items = new Dictionary <int, int>();
            // Calculate the needed items;
            int adder = 1;
            foreach (BSVoxel voxel in voxels)
            {
                int id = 0;
                if (ds == BuildingMan.Blocks)
                {
                    if (voxel.IsExtendable())
                    {
                        if (!voxel.IsExtendableRoot())
                        {
                            id    = GetBlockItemProtoID((byte)(voxel.materialType >> 2));
                            adder = 1;
                        }
                        else
                        {
                            adder = 0;
                        }
                    }
                    else
                    {
                        id = GetBlockItemProtoID(voxel.materialType);
                    }
                }
                else if (ds == BuildingMan.Voxels)
                {
                    id = GetVoxelItemProtoID(voxel.materialType);
                }

                if (id <= 0)
                {
                    continue;
                }

                if (id != 0)
                {
                    if (items.ContainsKey(id))
                    {
                        items[id] += adder;
                    }
                    else
                    {
                        items.Add(id, adder);
                    }
                }
            }
            _costsItems = items;

            float divisor = 1.0f;

            if (ds == BuildingMan.Blocks)
            {
                divisor = (float)(1 << BSBlock45Data.s_ScaleInverted);
            }

            // Has player enough items ?
            Pathea.PackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PackageCmpt>();

            _playerItems.Clear();
            foreach (KeyValuePair <int, int> kvp in items)
            {
                _playerItems.Add(kvp.Key, pkg.GetItemCount(kvp.Key));
                if (pkg.GetItemCount(kvp.Key) < Mathf.CeilToInt(kvp.Value / divisor))
                {
                    result = false;
                }
            }

            // now delete
            if (result)
            {
                if (GameConfig.IsMultiMode)
                {
                    if (null == PlayerNetwork.mainPlayer)
                    {
                        return(false);
                    }

                    if (!Pathea.PeGameMgr.IsMultiCoop && VArtifactUtil.IsInTownBallArea(PlayerNetwork.mainPlayer._pos))
                    {
                        new PeTipMsg(PELocalization.GetString(8000864), PeTipMsg.EMsgLevel.Warning);
                        return(false);
                    }

                    //if (!PlayerNetwork.OnLimitBoundsCheck(brushBound))
                    //{
                    //	new PeTipMsg(PELocalization.GetString(8000864), PeTipMsg.EMsgLevel.Warning);
                    //	return false;
                    //}

                    PlayerNetwork.mainPlayer.RequestRedo(opType, indexes, oldvoxels, voxels, mode, ds.DataType, ds.Scale);

                    DigTerrainManager.BlockClearGrass(ds, indexes);

                    return(true);
                }
                else
                {
                    string debug_log = "";

                    foreach (KeyValuePair <int, int> kvp in items)
                    {
                        if (pkg.Destory(kvp.Key, Mathf.CeilToInt(kvp.Value / divisor)))
                        {
                            debug_log += "\r\n Rmove Item from player package ID[" + kvp.Key.ToString() + "]" + " count - " + kvp.Value.ToString();
                        }
                    }

                    if (ds == BuildingMan.Blocks)
                    {
                        for (int i = 0; i < indexes.Length; i++)
                        {
                            Vector3 pos = new Vector3(indexes[i].x * ds.Scale, indexes[i].y * ds.Scale, indexes[i].z * ds.Scale) - ds.Offset;
                            PeGrassSystem.DeleteAtPos(pos);

                            PeGrassSystem.DeleteAtPos(new Vector3(pos.x, pos.y - 1, pos.z));

                            //PeGrassSystem.DeleteAtPos(new Vector3(pos.x, pos.y + 1, pos.z));
                        }
                    }
                    else if (ds == BuildingMan.Voxels)
                    {
                        for (int i = 0; i < indexes.Length; i++)
                        {
                            Vector3 pos = new Vector3(indexes[i].x, indexes[i].y, indexes[i].z);
                            PeGrassSystem.DeleteAtPos(pos);

                            PeGrassSystem.DeleteAtPos(new Vector3(pos.x, pos.y - 1, pos.z));

                            //PeGrassSystem.DeleteAtPos(new Vector3(pos.x, pos.y + 1, pos.z));
                        }
                    }

                    //Debug.LogWarning(debug_log);
                }
            }
            else
            {
                new PeTipMsg(PELocalization.GetString(821000001), PeTipMsg.EMsgLevel.Warning);
            }
        }
        else if (mode == EBSBrushMode.Subtract)
        {
            Dictionary <int, int> items = new Dictionary <int, int>();
            // Calculate the needed items;
            int adder = 1;
            foreach (BSVoxel voxel in oldvoxels)
            {
                int id = 0;
                if (ds == BuildingMan.Blocks)
                {
                    if (voxel.IsExtendable())
                    {
                        if (!voxel.IsExtendableRoot())
                        {
                            id    = GetBlockItemProtoID((byte)(voxel.materialType >> 2));
                            adder = 1;
                        }
                        else
                        {
                            adder = 0;
                        }
                    }
                    else
                    {
                        if (!BuildingMan.Blocks.VoxelIsZero(voxel, 0))
                        {
                            id = GetBlockItemProtoID((byte)(voxel.materialType));
                        }
                    }
                }
                else if (ds == BuildingMan.Voxels)
                {
                    if (!BuildingMan.Voxels.VoxelIsZero(voxel, 1))
                    {
                        id = GetVoxelItemProtoID(voxel.materialType);
                    }
                }

                if (id <= 0)
                {
                    continue;
                }

                if (items.ContainsKey(id))
                {
                    items[id] += adder;
                }
                else
                {
                    items.Add(id, adder);
                }
            }


            float divisor = 1.0f;

            if (ds == BuildingMan.Blocks)
            {
                divisor = (float)(1 << BSBlock45Data.s_ScaleInverted);
            }

            // Has player enough package ?
            Pathea.PlayerPackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PlayerPackageCmpt>();

            MaterialItem[] array = new MaterialItem[items.Count];

            int i = 0;
            foreach (KeyValuePair <int, int> kvp in items)
            {
                array[i] = new MaterialItem()
                {
                    protoId = kvp.Key,
                    count   = Mathf.FloorToInt(kvp.Value / divisor)
                };
                i++;
            }

            result = pkg.package.CanAdd(array);

            // Really add
            if (result)
            {
                if (GameConfig.IsMultiMode)
                {
                    if (null == PlayerNetwork.mainPlayer)
                    {
                        return(false);
                    }

                    //if (!PlayerNetwork.OnLimitBoundsCheck(brushBound))
                    //{
                    //	new PeTipMsg(PELocalization.GetString(8000864), PeTipMsg.EMsgLevel.Warning);
                    //	return false;
                    //}

                    PlayerNetwork.mainPlayer.RequestRedo(opType, indexes, oldvoxels, voxels, mode, ds.DataType, ds.Scale);
                    return(true);
                }
                else
                {
                    string debug_log = "";
                    foreach (MaterialItem mi in array)
                    {
                        if (mi.count != 0)
                        {
                            pkg.Add(mi.protoId, mi.count);
                        }
                        debug_log += "Add Item from player package ID[" + mi.protoId.ToString() + "]" + " count - " + mi.count.ToString() + "\r\n";
                    }

                    Debug.LogWarning(debug_log);
                }
            }
        }

        if (result)
        {
            if (onVoxelMotify != null)
            {
                onVoxelMotify(indexes, voxels, oldvoxels, mode, ds);
            }
        }

        return(result);
    }
    void Update()
    {
        if (_manipulator.BrushType == BuildingMan.EBrushType.Select)
        {
            // Select mode for voxels
            if (selectVoxel)
            {
                _manipulator.pattern = BSPattern.DefaultV1;
            }
            // Select mode for block
            else
            {
                _manipulator.pattern = BSPattern.DefaultB1;
            }
        }
        else if (_manipulator.BrushType == BuildingMan.EBrushType.Point ||
                 _manipulator.BrushType == BuildingMan.EBrushType.Box ||
                 _manipulator.BrushType == BuildingMan.EBrushType.B45Diagonal)
        {
                        #if TEST_CODE
            UpdateTest();
                        #endif

            if (m_Pattern != null)
            {
                _manipulator.pattern = m_Pattern;
            }
        }
        else
        {
            _manipulator.pattern = null;
        }

        if (_manipulator.BrushType == BuildingMan.EBrushType.Box)
        {
            BSBoxBrush brush = _manipulator.activeBrush as BSBoxBrush;
            if (brush != null)
            {
                Vector3 size  = brush.Size;
                int     count = Mathf.RoundToInt(size.x) * Mathf.RoundToInt(size.y) * Mathf.RoundToInt(size.z) * brush.pattern.size;

                if (Pathea.PeCreature.Instance.mainPlayer == null)
                {
                    return;
                }
                Pathea.PackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PackageCmpt>();
                if (brush.dataSource == BuildingMan.Blocks)
                {
                    int itemId = GetBlockItemProtoID((byte)(brush.materialType));
                    if (pkg.GetItemCount(itemId) >= (Mathf.CeilToInt((float)count / 4)))
                    {
                        brush.forceShowRemoveColor = false;
                    }
                    else
                    {
                        brush.forceShowRemoveColor = true;
                    }
                }
                else if (brush.dataSource == BuildingMan.Voxels)
                {
                    int itemId = GetVoxelItemProtoID(brush.materialType);
                    if (pkg.GetItemCount(itemId) >= count)
                    {
                        brush.forceShowRemoveColor = false;
                    }
                    else
                    {
                        brush.forceShowRemoveColor = true;
                    }
                }
            }
        }
    }