当前位置: 首页>>代码示例>>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;未经允许,请勿转载。