private void HourlyTick() { Town[] remove = new Town[ToolMakers.Count]; int index = 0; foreach (var pair in ToolMakers) { if (MoreSettlementActionHelper.OwnsWorkshop(pair.Key, "smithy") == 0) { remove[index] = pair.Key; } index++; } for (int i = 0; i < remove.Length; i++) { if (remove[i] != null) { ToolMakers.Remove(remove[i]); } } }
private void ToolMakerMenuItems(CampaignGameStarter campaignGameStarter) { campaignGameStarter.AddGameMenuOption("town", "town_tool_maker", "Visit tool maker at your smithy", (GameMenuOption.OnConditionDelegate)(args => { if (MoreSettlementActionHelper.OwnsWorkshop(Settlement.CurrentSettlement.Town, "smithy") == 0) { return(false); } args.optionLeaveType = GameMenuOption.LeaveType.Craft; args.IsEnabled = true; return(true); }), (GameMenuOption.OnConsequenceDelegate)(args => { GameMenu.SwitchToMenu("town_tool_maker_menu"); }), index: 1); campaignGameStarter.AddGameMenu("town_tool_maker_menu", "The tool maker can turn various metal ingots into tools. Smeltable items in the stockpile will be melted down if there are no ingots avalible. Hardwood in stockpile will be refined into charcoal when there is not enough charcoal. If the import material option is turned on iron ore and hardwood will be imported from owned slave estates producing iron ore and hardwood when none is left in the inventory of the tool maker but is avalible at the slave estates. The import cost is 5 gold per unit delievered. Building can be upgraded, with each level increasing building base production by 50%", (OnInitDelegate)(args => { ToolMaker toolMaker; if (!ToolMakers.TryGetValue(Settlement.CurrentSettlement.Town, out toolMaker)) { return; } MBTextManager.SetTextVariable("LEVEL", "(Current Level: " + toolMaker.UpgradeLevel.ToString() + ")", false); }), GameOverlays.MenuOverlayType.SettlementWithBoth); campaignGameStarter.AddGameMenuOption("town_tool_maker_menu", "tool_maker_upgrade", "Upgrade Buildings {LEVEL}", (GameMenuOption.OnConditionDelegate)(args => { ToolMaker toolMaker; if (!ToolMakers.TryGetValue(Settlement.CurrentSettlement.Town, out toolMaker)) { return(false); } int itemNumber = PartyBase.MainParty.ItemRoster.GetItemNumber(MBObjectManager.Instance.GetObject <ItemObject>("hardwood")); string tooltipText = ""; if (itemNumber < 100 * (toolMaker.UpgradeLevel + 2)) { args.IsEnabled = false; tooltipText = tooltipText + "you lack the " + (100 * (toolMaker.UpgradeLevel + 2)).ToString() + " hardwood needed to upgrade to next level. "; } else { tooltipText = tooltipText + (100 * (toolMaker.UpgradeLevel + 2)).ToString() + " hardwood needed to upgrade to next level. "; } if (toolMaker.UpgradeLevel == 0) { tooltipText = tooltipText + "This currently has no bonuses"; } else { tooltipText = tooltipText + "This building has a " + (50 * toolMaker.UpgradeLevel).ToString() + "% bounus to base daily work rate"; } args.Tooltip = new TextObject(tooltipText); args.optionLeaveType = GameMenuOption.LeaveType.Manage; return(true); }), (GameMenuOption.OnConsequenceDelegate)(args => { ToolMaker toolMaker; ToolMakers.TryGetValue(Settlement.CurrentSettlement.Town, out toolMaker); _startTime = CampaignTime.Now; int partySize = MobileParty.MainParty.Army == null ? MobileParty.MainParty.Party.NumberOfAllMembers : (int)MobileParty.MainParty.Army.TotalManCount; int engineeringSkill = Hero.MainHero.GetSkillValue(DefaultSkills.Engineering); int partyEngineeringSum = MoreSettlementActionHelper.GetSkillTotalForParty(DefaultSkills.Engineering); _Duration = 1000 * (toolMaker.UpgradeLevel + 2); _upgrade_cost = 100 * (toolMaker.UpgradeLevel + 2); _Duration = _Duration / ((100 + engineeringSkill) / 100 * (partySize + (partyEngineeringSum / 100))); GameMenu.SwitchToMenu("tool_maker_upgrade_wait"); })); campaignGameStarter.AddWaitGameMenu("tool_maker_upgrade_wait", "Your party is upgrading your toolmaker workshop", (OnInitDelegate)(args => { args.MenuContext.GameMenu.SetTargetedWaitingTimeAndInitialProgress(_Duration, 0.0f); args.MenuContext.GameMenu.SetMenuAsWaitMenuAndInitiateWaiting(); }), (TaleWorlds.CampaignSystem.GameMenus.OnConditionDelegate)(args => { args.MenuContext.GameMenu.SetMenuAsWaitMenuAndInitiateWaiting(); args.optionLeaveType = GameMenuOption.LeaveType.Wait; return(true); }), (TaleWorlds.CampaignSystem.GameMenus.OnConsequenceDelegate)(args => { ToolMaker toolMaker; ToolMakers.TryGetValue(Settlement.CurrentSettlement.Town, out toolMaker); PartyBase.MainParty.ItemRoster.AddToCounts(MBObjectManager.Instance.GetObject <ItemObject>("hardwood"), (int)(-1 * _upgrade_cost)); toolMaker.UpgradeLevel++; InformationManager.DisplayMessage(new InformationMessage("Toolmaker workshop in the slave estate at " + Settlement.CurrentSettlement.Town.Name.ToString() + " has been upgraded to level " + toolMaker.UpgradeLevel.ToString())); GameMenu.SwitchToMenu("town_tool_maker_menu"); }), (OnTickDelegate)((args, dt) => args.MenuContext.GameMenu.SetProgressOfWaitingInMenu(_startTime.ElapsedHoursUntilNow / _Duration)), GameMenu.MenuAndOptionType.WaitMenuShowOnlyProgressOption); campaignGameStarter.AddGameMenuOption("tool_maker_upgrade_wait", "tool_maker_upgrade_wait_leave", "Stop and Leave", (GameMenuOption.OnConditionDelegate)(args => { args.optionLeaveType = GameMenuOption.LeaveType.Leave; return(true); }), (GameMenuOption.OnConsequenceDelegate)(args => { InformationManager.DisplayMessage(new InformationMessage("You stopped builing before the job was done.")); GameMenu.SwitchToMenu("village"); })); campaignGameStarter.AddGameMenuOption("town_tool_maker_menu", "town_tool_maker_menu_leave_companion", "Leave companion to assist tool maker", (GameMenuOption.OnConditionDelegate)(args => { args.optionLeaveType = GameMenuOption.LeaveType.Recruit; return(true); }), (GameMenuOption.OnConsequenceDelegate)(args => { LeaveCompanion(); })); campaignGameStarter.AddGameMenuOption("town_tool_maker_menu", "town_tool_maker_menu_take_companion", "Take companion to party", (GameMenuOption.OnConditionDelegate)(args => { args.optionLeaveType = GameMenuOption.LeaveType.Recruit; ToolMaker toolMaker; if (ToolMakers.TryGetValue(Settlement.CurrentSettlement.Town, out toolMaker)) { return(toolMaker.Assistants.Count > 0); } else { return(false); } }), (GameMenuOption.OnConsequenceDelegate)(args => { TakeCompanion(); })); campaignGameStarter.AddGameMenuOption("town_tool_maker_menu", "town_tool_maker_menu_manage_stockpile", "Manage Inventory", (GameMenuOption.OnConditionDelegate)(args => { args.optionLeaveType = GameMenuOption.LeaveType.Trade; return(true); }), (GameMenuOption.OnConsequenceDelegate)(args => { ToolMaker toolMaker; if (!ToolMakers.TryGetValue(Settlement.CurrentSettlement.Town, out toolMaker)) { toolMaker = new ToolMaker(); ToolMakers.Add(Settlement.CurrentSettlement.Town, toolMaker); } if (ToolMakers.TryGetValue(Settlement.CurrentSettlement.Town, out toolMaker)) { InventoryManager.OpenScreenAsStash(toolMaker.StockPile); } })); campaignGameStarter.AddGameMenuOption("town_tool_maker_menu", "town_tool_maker_menu_import_materials_on", "Import Materials : off", (GameMenuOption.OnConditionDelegate)(args => { if (ImportMaterials) { return(false); } args.optionLeaveType = GameMenuOption.LeaveType.Trade; args.Tooltip = new TextObject("click to turn on"); return(true); }), (GameMenuOption.OnConsequenceDelegate)(args => { ImportMaterials = true; GameMenu.SwitchToMenu("town"); })); campaignGameStarter.AddGameMenuOption("town_tool_maker_menu", "town_tool_maker_menu_import_materials_off", "Import Materials : on", (GameMenuOption.OnConditionDelegate)(args => { if (!ImportMaterials) { return(false); } args.optionLeaveType = GameMenuOption.LeaveType.Trade; args.Tooltip = new TextObject("click to turn off"); return(true); }), (GameMenuOption.OnConsequenceDelegate)(args => { ImportMaterials = false; GameMenu.SwitchToMenu("town"); })); campaignGameStarter.AddGameMenuOption("town_tool_maker_menu", "town_tool_maker_menu_leave", "Back", (GameMenuOption.OnConditionDelegate)(args => { args.optionLeaveType = GameMenuOption.LeaveType.Leave; return(true); }), (GameMenuOption.OnConsequenceDelegate)(args => { GameMenu.SwitchToMenu("town"); })); }