當前位置: 首頁>>代碼示例>>C#>>正文


C# BasePlayer.GiveItem方法代碼示例

本文整理匯總了C#中BasePlayer.GiveItem方法的典型用法代碼示例。如果您正苦於以下問題:C# BasePlayer.GiveItem方法的具體用法?C# BasePlayer.GiveItem怎麽用?C# BasePlayer.GiveItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BasePlayer的用法示例。


在下文中一共展示了BasePlayer.GiveItem方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EventReward

        void EventReward(BasePlayer player)
        {
            EventWinner winner = player.GetComponent<EventWinner>();

            if (winner != null)
            {
                clearGUI(player);

                player.GiveItem(ItemManager.CreateByPartialName("supply.signal", winner.amount));

                UnityEngine.GameObject.Destroy(winner);

                PrintChat(player, "Your reward has been added to your inventory.");
            }
            else
            {
                PrintChat(player, "You haven't won the event.");
            }
        }
開發者ID:danniehansen,項目名稱:EdgePlugins,代碼行數:19,代碼來源:SkyEvent.cs

示例2: SalvageItem

        void SalvageItem(BasePlayer player, Item item) {
            //check player can craft item
        	bool canCraft = player.blueprints.CanCraft(item.info.itemid, 0);

            //if can't craft or broken, else salvage
        	if(!canCraft || (item.hasCondition && item.condition == 0)) {
        		player.ChatMessage("This item is not salvageable.");
        	} else {
                //remove the item from the container
        	    item.RemoveFromContainer();
                
                //get bp
        		ItemBlueprint itemBp = blueprints[item.info.shortname];
                
                //set ratios
        		double refundRatio = 0.5;
                //if item.hasCondition then conditionRatio == item.conditionNormalized else conditionRatio = 1
                double conditionRatio = item.hasCondition ? item.conditionNormalized : 1;
                
                /*
                    itemBp.amountToCreate is the number of items made by the act of crafting (3x 5.56)
                    ingredient.amount is the number of that material required (100 wood for campfire)
                    ingredient.itemDef.stackable is the max stack size of that ingredient
                */
                foreach(ItemAmount ingredient in itemBp.ingredients) {
                    //calculate refund amount
                    double refundAmount = ingredient.amount / itemBp.amountToCreate;
                    refundAmount = refundAmount * refundRatio * conditionRatio * item.amount;
                    refundAmount = Math.Ceiling(refundAmount);
                    if(refundAmount < 1)
                        refundAmount = 1;
                        
                    //calculate how many stacks to split the refund into (no super stacks)
                    double refundStacks = refundAmount / ingredient.itemDef.stackable;
                    if(refundStacks < 1)
                        refundStacks = 1;
                    
                    //refund ingredient
                    for(int i = 0; i < refundStacks; i++) {
                        int amt;
                        
                        //calculate how much to give in this stack
                        if (refundAmount <= ingredient.itemDef.stackable)
                            amt = (int)refundAmount;
                        else
                            amt = ingredient.itemDef.stackable;
                        
                        //reduce the pending refund amount by how much we're about to give out
                        refundAmount = refundAmount - amt;
                        
                        //create and give this stack
                        Item newItem = ItemManager.Create(ingredient.itemDef, amt);
                        player.GiveItem(newItem);
                    }
                }
        	}
        }
開發者ID:Randactyl,項目名稱:Salvage,代碼行數:57,代碼來源:Salvage.cs


注:本文中的BasePlayer.GiveItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。