Exemplo n.º 1
0
 public void SendAllItemToPlayer()
 {
     if (GameConfig.IsMultiMode)
     {
         if (null != mNetWork)
         {
             mNetWork.GetAllItem();
         }
     }
     else
     {
         foreach (int itemObjID in mItemList)
         {
             ItemObject itemObj = ItemMgr.Instance.Get(itemObjID);
             //if(PlayerFactory.mMainPlayer.AddItem(itemObj))
             //    mItemList.Remove(itemObj.instanceId);
             //else
             //{
             //    ResetUI();
             //    break;
             //}
             if (null != Pathea.MainPlayerCmpt.gMainPlayer)
             {
                 Pathea.PlayerPackageCmpt pPC = Pathea.MainPlayerCmpt.gMainPlayer.GetComponent <Pathea.PlayerPackageCmpt>();
                 pPC.Add(itemObj);
             }
         }
         mItemList.Clear();
         CheckDestroy();
     }
 }
Exemplo n.º 2
0
    void OnRightMouseCliked(Grid_N grid)
    {
        ActiveWnd();
        GameUI.Instance.mItemPackageCtrl.Show();

        if (grid.ItemObj != null && playerPackage != null)
        {
            if (PeGameMgr.IsMulti)
            {
                if (_wareObj != null)
                {
                    _wareObj._objNet.GetItem(grid.ItemObj.instanceId);
                }
            }
            else
            {
                if (playerPackage.Add(grid.ItemObj))
                {
                    SetItemWithIndex(null, grid.ItemIndex);
                }
                else //lz-2016.09.14 提示背包已满
                {
                    PeTipMsg.Register(PELocalization.GetString(9500312), PeTipMsg.EMsgLevel.Warning);
                }
            }
        }
    }
Exemplo n.º 3
0
    void OnRightMouseClicked(Grid_N grid)
    {
        if (grid.Item == null)
        {
            return;
        }

        if (onCheckItem != null && !onCheckItem(null, ECheckItemType.RightMounseClick))
        {
            return;
        }

        if (GameConfig.IsMultiMode)
        {
            OnRightMouseClickedMulti(grid, m_Index);
            return;
        }

        ItemObject oldItem = grid.ItemObj;

        Pathea.PlayerPackageCmpt package = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PlayerPackageCmpt>();

        if (package.package.CanAdd(grid.ItemObj))
        {
            package.Add(grid.ItemObj);
            GameUI.Instance.mItemPackageCtrl.ResetItem();
            grid.SetItem(null);

            if (OnItemChanged != null)
            {
                OnItemChanged(null, oldItem, m_Index);
            }
        }
        else
        {
            CSUI_MainWndCtrl.ShowStatusBar(UIMsgBoxInfo.mNotEnoughGrid.GetString(), Color.red);
        }
    }
Exemplo n.º 4
0
    /// <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);
    }
Exemplo n.º 5
0
 bool Replicator.IHandler.CreateItem(int itemId, int count)
 {
     return(mPackage.Add(itemId, count));
 }
Exemplo n.º 6
0
    // ---------------------------------
    //  Callback
    // ---------------------------------

    void OnCompoudClick(CSUI_CompoundItem ci)
    {
        if (!GameConfig.IsMultiMode)
        {
            int index = m_CompoudItems.FindIndex(item0 => item0 == ci);
            if (index != -1)
            {
                if (!CSUI_MainWndCtrl.IsWorking())
                {
                    return;
                }

                if (m_Factory.CompoudItemsCount <= index)
                {
                    return;
                }

                Pathea.PlayerPackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PlayerPackageCmpt>();
                if (pkg == null)
                {
                    Debug.LogError("CSUI_Factory.OnCompoundClick: pkg is null!");
                    return;
                }

                CompoudItem ci_data = null;
                ItemProto   item_data;
                if (!m_Factory.GetTakeAwayCompoundItem(index, out ci_data))
                {
                    if (ci_data != null)
                    {
                        item_data = ItemProto.GetItemData(ci_data.itemID);
                        CSUI_MainWndCtrl.ShowStatusBar(CSUtils.GetNoFormatString(UIMsgBoxInfo.mIsCompounding.GetString(), item_data.GetName()), Color.red);
                    }
                    return;
                }

                item_data = ItemProto.GetItemData(ci_data.itemID);

                int pacakgeEmptyCount = pkg.package.GetSlotList(ci_data.itemID).vacancyCount;
                if (!pkg.package.CanAdd(m_Factory.Data.m_CompoudItems[index].itemID, ci.Count))
                {
                    // Status bar
                    //lz-2016.07.16 背包空间不足这条提示是基地复制器和玩家复制器通用的,在基地用的时候,基地的提示只能显示一行,不能换行
                    string tip = PELocalization.GetString(8000050).Replace("\\n", " ");
                    CSUI_MainWndCtrl.ShowStatusBar(tip, Color.red);
                    if (item_data.maxStackNum > 1 || pacakgeEmptyCount == 0)
                    {
                        return;
                    }
                }

                int originalCount = ci_data.itemCnt;
                int addCount      = originalCount;
                if (item_data.maxStackNum > 1)
                {
                    pkg.Add(ci_data.itemID, ci_data.itemCnt);
                }
                else
                {
                    if (originalCount > pacakgeEmptyCount)
                    {
                        addCount = pacakgeEmptyCount;
                    }
                    pkg.Add(ci_data.itemID, addCount);
                }

                ci_data.itemCnt = originalCount - addCount;
                if (ci_data.itemCnt == 0)
                {
                    m_Factory.TakeAwayCompoudItem(index);
                    CSUI_MainWndCtrl.ShowStatusBar(CSUtils.GetNoFormatString(UIMsgBoxInfo.mTakeAwayCompoundItem.GetString(), item_data.GetName()));
                }
            }
        }
        else
        {
            int index = m_CompoudItems.FindIndex(item0 => item0 == ci);
            if (index != -1)
            {
                if (m_Factory.CompoudItemsCount <= index ||
                    m_Factory.Data.m_CompoudItems[index] == null ||
                    m_Factory.Data.m_CompoudItems[index].curTime < m_Factory.Data.m_CompoudItems[index].time)
                {
                    return;
                }
                m_Factory._ColonyObj._Network.FCT_Fetch(index);
            }
        }
    }