当前位置: 首页>>代码示例>>C#>>正文


C# BasePlayer.CanBuild方法代码示例

本文整理汇总了C#中BasePlayer.CanBuild方法的典型用法代码示例。如果您正苦于以下问题:C# BasePlayer.CanBuild方法的具体用法?C# BasePlayer.CanBuild怎么用?C# BasePlayer.CanBuild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BasePlayer的用法示例。


在下文中一共展示了BasePlayer.CanBuild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnStructureRepair

        void OnStructureRepair(BaseCombatEntity entity, BasePlayer player)
        {
            BuildingBlock block = entity as BuildingBlock;

            if (PlayerHasFlag(player.userID, PlayerFlags.PLUGIN_DISABLED) || block == null)
                return;

            if (playersInfo[player.userID].upgradeInfo == BuildingGrade.Enum.Count
                || playersInfo[player.userID].upgradeInfo <= block.currentGrade.gradeBase.type
                || !player.CanBuild())
            {
                if (playersInfo[player.userID].upgradeInfo != BuildingGrade.Enum.Count && playersInfo[player.userID].upgradeInfo <= block.currentGrade.gradeBase.type)
                {
                    if(!PlayerHasFlag(player.userID, PlayerFlags.MESSAGES_DISABLED))
                        SendReply(player, pluginPrefix + "You are now in REPAIR mode.");
                    playersInfo[player.userID].upgradeInfo = BuildingGrade.Enum.Count;
                    RenderMode(player, true);
                }
                else if (!player.CanBuild())
                {
                    SendReply(player, pluginPrefix + "Building is blocked!");
                }
            }
            else
            {
                BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
                MethodInfo dynMethod = block.GetType().GetMethod("CanChangeToGrade", flags);
                bool canChangeGrade = (bool)dynMethod.Invoke(block, new object[] { playersInfo[player.userID].upgradeInfo, player });

                if (!canChangeGrade)
                {
                    SendReply(player, pluginPrefix + "You can't upgrade it, something is blocking it's way.");
                    return;
                }

                if (block.name.ToLower().Contains("wall.external"))
                {
                    SendReply(player, pluginPrefix + "Can't upgrade walls! Switching to REPAIR mode.");
                    playersInfo[player.userID].upgradeInfo = BuildingGrade.Enum.Count;
                    return;
                }
                float currentHealth = block.health;
                var currentGradeType = block.currentGrade.gradeBase.type;
                block.SetGrade(playersInfo[player.userID].upgradeInfo);
                var TwigsDecay = plugins.Find("TwigsDecay");
                TwigsDecay?.Call("OnStructureUpgrade", block, player, playersInfo[player.userID].upgradeInfo);
				block.UpdateSkin(false);
                var cost = block.currentGrade.gradeBase.baseCost;
                int hasEnough = 0;
                foreach (var itemCost in cost)
                {
                    int itemCostAmount = Convert.ToInt32((float)itemCost.amount*block.blockDefinition.costMultiplier);
                    var foundItems = player.inventory.FindItemIDs(itemCost.itemid);
                    var amountFound = foundItems?.Sum(item => item.amount) ?? 0;
                    if (amountFound >= itemCostAmount)
                        hasEnough++;
                }
                if (hasEnough >= cost.Count)
                {
                    foreach (var itemCost in cost)
                    {
                        int itemCostAmount = Convert.ToInt32((float)itemCost.amount * block.blockDefinition.costMultiplier);
                        var foundItems = player.inventory.FindItemIDs(itemCost.itemid);
                        player.inventory.Take(foundItems, itemCost.itemid, itemCostAmount);
                    }
                    block.SetHealthToMax();
                    block.SetFlag(BaseEntity.Flags.Reserved1, true); // refresh rotation
                    block.Invoke("StopBeingRotatable", 600f);
                    Effect.server.Run("assets/bundled/prefabs/fx/build/promote_" + playersInfo[player.userID].upgradeInfo.ToString().ToLower() + ".prefab", block, 0u, Vector3.zero, Vector3.zero, null, false);
                }
                else
                {
                    block.SetGrade(currentGradeType);
                    TwigsDecay?.Call("OnStructureUpgrade", block, player, currentGradeType);
                    block.UpdateSkin(false);
                    block.health = currentHealth;
                    SendReply(player, pluginPrefix + "Can't afford to upgrade!");
                }
            }

            RefreshTimer(player);
        }
开发者ID:Arkoudaphobia,项目名称:ArkoudaphobiaConfig,代码行数:82,代码来源:EnhancedHammer.cs


注:本文中的BasePlayer.CanBuild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。