Ejemplo n.º 1
0
        // Return value:
        // - null = continue with default behaviour of hammer hit
        // - anything else: prevent default behaviour.
        private object HandleUpgradeRequest(BasePlayer player, ResearchTable researchTable)
        {
            if (UpgradeCost.Count > 0)
            {
                if (!player.CanCraft(UpgradeCost))
                {
                    StringBuilder builder = new StringBuilder();

                    foreach (var ingredient in UpgradeCost)
                    {
                        builder.AppendLine("- x" + ingredient.amount.ToString("0") + " " + ingredient.itemDef.displayName.english);
                    }

                    string ingredientsStr = builder.ToString();

                    player.ShowScreenMessage(Lang.Translate(player, "ingredients-missing-youneed") + "\n" + ingredientsStr, 10, TextAnchor.MiddleLeft);
                    return(true);
                }
            }

            float lastHit = lastHammerHit[player];

            if (Time.time - lastHit > Constants.HammerConfirmTime)             // Confirm the upgrade
            {
                lastHammerHit[player] = Time.time;
                player.ShowScreenMessage(Lang.Translate(player, "hammer-confirm-upgrade"), Constants.HammerConfirmTime);
                return(true);
            }

            lastHammerHit[player] = 0;             // Reset time

            foreach (var ingredient in UpgradeCost)
            {
                List <Item> takenItems = new List <Item>();
                player.inventory.Take(takenItems, ingredient.itemid, (int)ingredient.amount);
            }

            CrafterManager.CreateCrafter(researchTable);
            FxManager.PlayFx(researchTable.ServerPosition, Constants.UpgradeTopTierFxPrefab);
            player.HideScreenMessage();
            return(true);
        }