private BasePart.PartTier GetPartTierFromAmount(int amount) { for (int i = 3; i > 0; i--) { if (amount == AlienCustomizationManager.GetPrice()) { return(BasePart.PartTier.Legendary); } GameConfigurationManager instance = Singleton <GameConfigurationManager> .Instance; string craft_PRICE_CONFIG_KEY = WorkshopMenu.CRAFT_PRICE_CONFIG_KEY; BasePart.PartTier partTier = (BasePart.PartTier)i; if (amount >= instance.GetValue <int>(craft_PRICE_CONFIG_KEY, partTier.ToString())) { return((BasePart.PartTier)i); } } return(BasePart.PartTier.Regular); }
public void CraftSelectedPart() { if (this.IsMachineLocked) { return; } this.queuedAddScrapActions = 0; BasePart.PartTier partTierFromAmount = this.GetPartTierFromAmount(GameProgress.GetInt("Machine_scrap_amount", 0, GameProgress.Location.Local, null)); Singleton <AudioManager> .Instance.Spawn2dOneShotEffect(this.gameData.commonAudioCollection.craftLeverCrank); if (partTierFromAmount == BasePart.PartTier.Regular) { this.SetMachineAnimation(this.insufficientScrapAnimationName, false, false, true); Singleton <AudioManager> .Instance.Spawn2dOneShotEffect(this.gameData.commonAudioCollection.craftEmpty); MaterialAnimation component = this.MachineLabel.GetComponent <MaterialAnimation>(); if (component != null) { component.PlayAnimation(true, 5); } return; } SnoutButton.Instance.EnableButton(false); int num = 0; BasePart basePart = null; if (partTierFromAmount == BasePart.PartTier.Legendary && AlienCustomizationManager.GetNextUnlockable(out basePart)) { num = AlienCustomizationManager.GetPrice(); } else if (partTierFromAmount != BasePart.PartTier.Legendary) { num = Singleton <GameConfigurationManager> .Instance.GetValue <int>(WorkshopMenu.CRAFT_PRICE_CONFIG_KEY, partTierFromAmount.ToString()); basePart = CustomizationManager.GetRandomCraftablePartFromTier(partTierFromAmount, true); } if (basePart && num > 0 && GameProgress.UseScrap(num)) { this.SetMachineAnimation((!this.IsAlienMachine) ? this.craftAnimationName : this.slimeCraftAnimationName, false, false, false); Singleton <AudioManager> .Instance.Spawn2dOneShotEffect(this.gameData.commonAudioCollection.craftPart); CustomizationManager.UnlockPart(basePart, "crafted"); this.RemoveScrap(num); this.SetMachineIdleSound(0); PlayerProgress.ExperienceType experienceType = PlayerProgress.ExperienceType.CommonPartCrafted; if (partTierFromAmount == BasePart.PartTier.Rare) { experienceType = PlayerProgress.ExperienceType.RarePartCrafted; } if (partTierFromAmount == BasePart.PartTier.Epic) { experienceType = PlayerProgress.ExperienceType.EpicPartCrafted; } if (partTierFromAmount == BasePart.PartTier.Legendary) { experienceType = PlayerProgress.ExperienceType.LegendaryPartCrafted; } PlayerProgressBar.Instance.DelayUpdate(); int exp = Singleton <PlayerProgress> .Instance.AddExperience(experienceType); this.ShowReward(basePart, exp); string key = "CraftCount" + basePart.m_partTier.ToString(); int @int = GameProgress.GetInt(key, 0, GameProgress.Location.Local, null); GameProgress.SetInt(key, @int + 1, GameProgress.Location.Local); if (Singleton <SocialGameManager> .IsInstantiated() && basePart.m_partTier == BasePart.PartTier.Epic) { Singleton <SocialGameManager> .Instance.ReportAchievementProgress("grp.CRAFT_PARTS", 100.0); } this.partsCraftedWhileInScreen++; EventManager.Send(new CraftingMachineEvent(WorkshopMenu.CraftingMachineAction.CraftPart, 0)); } else if (basePart) { } }