Ejemplo n.º 1
0
    public void Sell(Grid_N grid, int num)
    {
        //lz-2016.08.10 执行Sell的时候重置包裹当前的操作Item
        GameUI.Instance.mItemPackageCtrl.ResetCurOpItem();

        if (null == grid || null == grid.ItemObj)
        {
            Debug.LogError("Sell item is null");
            return;
        }

        int proid         = grid.ItemObj.protoId;
        int instanceid    = grid.ItemObj.instanceId;
        int maxStackCount = grid.ItemObj.GetStackMax();
        int cost          = grid.ItemObj.GetSellPrice();//(int)(grid.ItemObj.prototypeData.m_CurrencyValue * num * (0.8f * grid.ItemObj.Durability / grid.ItemObj.DurabilityMax + 0.2f));

        //        string itemname = grid.ItemObj.protoData.GetName();


        if (npc == null)
        {
            return;
        }

        NpcPackageCmpt npcpc = npc.GetCmpt <NpcPackageCmpt>();

        if (npcpc == null)
        {
            return;
        }

        cost *= num;

        if (cost > npcpc.money.current)
        {
            string         errInfo = "";
            EntityInfoCmpt cmpt    = npc.GetCmpt <EntityInfoCmpt>();
            if (cmpt != null)
            {
                string _name = "";
//                if (npc.entityProto.proto == EEntityProto.RandomNpc)
//                {
//                    _name = cmpt.characterName.fullName;
//                }
//                else if (npc.entityProto.proto == EEntityProto.Npc)
//                {
//                    _name = cmpt.characterName.givenName;
//                }
                _name = cmpt.characterName.fullName;
                //lz-2016.10.31 have no money to pay for you!
                errInfo = _name + " " + PELocalization.GetString(8000853);
            }
            else
            {
                //lz-2016.10.31 have no money to pay for you!
                errInfo = npc.name + " " + PELocalization.GetString(8000853);
            }
            new PeTipMsg(errInfo, PeTipMsg.EMsgLevel.Error);
            return;
        }

        //Add money to player
        if (PeGameMgr.IsMulti)
        {
            PlayerNetwork.mainPlayer.RequestSell(npc.Id, instanceid, num);
        }
        else
        {
            npcpc.money.current -= cost;


            ItemObject SellItemObj;
            if (maxStackCount == 1)
            {
                SellItemObj = grid.ItemObj;
            }
            else
            {
                SellItemObj = ItemMgr.Instance.CreateItem(proid);
            }
            PlayerPackageCmpt pkg = PeCreature.Instance.mainPlayer.GetCmpt <PlayerPackageCmpt>();
            if (null == pkg)
            {
                return;
            }
            if (maxStackCount == 1)
            {
                pkg.Remove(SellItemObj);
            }
            else
            {
                pkg.DestroyItem(instanceid, num);
            }
            //if (grid.ItemObj.GetCount() > num)
            //{
            //    SellItemObj = ItemMgr.Instance.CreateItem(grid.ItemObj.protoId); // single
            //    SellItemObj.IncreaseStackCount(num);
            //    grid.ItemObj.DecreaseStackCount(num);
            //}
            //else
            //{
            //    SellItemObj = grid.ItemObj;
            //    PlayerFactory.mMainPlayer.GetItemPackage().RemoveItem(grid.ItemObj);
            //    GameUI.Instance.mUIItemPackageCtrl.ResetItem();
            //}
            //SellItemObj.SetProperty(ItemProperty.SellItemMark, 1f);
            AddRepurchase(SellItemObj, num);

            //            if (cost != 0 && !PeCreature.Instance.mainPlayer.AddToPkg(StroyManager.PRICE_ID, cost))
            //            {
            //                return;
            //            }

            pkg.money.current += cost;
            ResetItem();
        }


        //GameGui_N.Instance.mChatGUI.AddChat(PromptData.PromptType.PromptType_14, itemname, num, cost);

        mOpItem.SetItem(null);
        mOpGrid = null;
        mSellOpLayer.gameObject.SetActive(false);

        return;
    }
Ejemplo n.º 2
0
    public void SellItem(int instanceId, int count)
    {
        ItemObject itemObj = ItemAsset.ItemMgr.Instance.Get(instanceId);

        if (itemObj == null)
        {
            Debug.LogError("Sell item is null");
            return;
        }

        if (count > itemObj.GetCount())
        {
            Debug.LogError("not enough count");
            return;
        }

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

        if (null == pkg)
        {
            return;
        }

        int protoId = itemObj.protoId;
        int cost    = itemObj.GetSellPrice() * count;

        if (colonyMoney < cost)
        {
            //lz-2016.10.31 The TradePost has no money to pay for you!
            new PeTipMsg(PELocalization.GetString(8000858), PeTipMsg.EMsgLevel.Error);
            return;
        }


        if (PeGameMgr.IsMulti)
        {
            _ColonyObj._Network.RPCServer(EPacketType.PT_CL_TRD_SellItem, instanceId, count);
            return;
        }
        else
        {
            colonyMoney -= cost;
            ItemObject SellItemObj;
            if (count == itemObj.stackCount)
            {
                SellItemObj = itemObj;
                pkg.Remove(itemObj);
            }
            else
            {
                SellItemObj = ItemMgr.Instance.CreateItem(protoId);
                SellItemObj.SetStackCount(count);
                pkg.DestroyItem(instanceId, count);
            }

            AddRepurchase(SellItemObj);
            pkg.money.current += cost;            //Add money to player
        }

        //--to do: updateUI
        UpdateRepurchaseDataToUI();
    }