當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。