public static void LogBuildingAndWorker(BuildingWorkInfo info, int selectedWorkerId, int partId, int placeId, TaiwuDate currDate, Dictionary <int, Dictionary <int, int> > workerAttrs, bool suppressNoWorkerWarnning) { var building = DateFile.instance.homeBuildingsDate[partId][placeId][info.buildingIndex]; int baseBuildingId = building[0]; int buildingLevel = building[1]; var baseBuilding = DateFile.instance.basehomePlaceDate[baseBuildingId]; string buildingName = baseBuilding[0]; string attrName = Output.GetRequiredAttrName(info.requiredAttrId); string logText = string.Format("{0}:{1} ({2}) {3} [{4}, {5}] - ", TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(info.priority.ToString("F0").PadLeft(4))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, Common.ToFullWidth(buildingName.PadRight(5))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(buildingLevel.ToString().PadLeft(2))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_RICE_WHITE, Common.ToFullWidth(attrName.PadRight(2))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(info.halfWorkingAttrValue.ToString().PadLeft(3))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(info.fullWorkingAttrValue.ToString().PadLeft(3)))); if (selectedWorkerId >= 0) { string workerName = DateFile.instance.GetActorName(selectedWorkerId); int attrValue = info.requiredAttrId != 0 ? workerAttrs[selectedWorkerId][info.requiredAttrId] : -1; int mood = int.Parse(DateFile.instance.GetActorDate(selectedWorkerId, 4, false)); int favor = DateFile.instance.GetActorFavor(false, DateFile.instance.MianActorID(), selectedWorkerId, getLevel: true); // 这里的工作效率并不一定等于最终工作效率,因为可能还有厢房未分配 int workEffectiveness = info.requiredAttrId != 0 ? Original.GetWorkEffectiveness(partId, placeId, info.buildingIndex, selectedWorkerId) : -1; string workEffectivenessStr = workEffectiveness >= 0 ? workEffectiveness / 2 + "%" : "N/A"; MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_LOW, logText + string.Format( "{0} 资质: {1} 心情: {2} 好感: {3} 工作效率: {4}", TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, Common.ToFullWidth(workerName.PadRight(5))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(attrValue.ToString().PadLeft(3))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(mood.ToString().PadLeft(4))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(favor.ToString().PadLeft(2))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, Common.ToFullWidth(workEffectivenessStr.PadLeft(4))))); } else { if (suppressNoWorkerWarnning) { MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_LOW, logText + TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, "无合适人选")); } else { MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_HIGH, logText + TaiwuCommon.SetColor(TaiwuCommon.COLOR_RED, "无合适人选")); } } }
/// <summary> /// 指派完厢房之后,继续指派其他建筑 /// /// 其实本轮指派开始时仍有可能包含厢房,本轮临近结束时也仍有可能尚未指派厢房。 /// 本轮最后厢房指派,不考虑是否达到心情好感阈值,只要还有人就往里放。 /// 上次分配后还有厢房剩下的原因:人太少,辅助性厢房装不满;心情都挺好,一般厢房装不满。 /// 本次分配后还有厢房剩下的原因:人太少。 /// /// 建筑类型优先级因子中的厢房因子依然不能控制此处的厢房指派优先级,所有厢房在最后阶段指派。 /// </summary> private void AssignLeftBuildings() { MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派主要建筑……")); var sortedBuildings = this.buildings.OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value); foreach (var info in sortedBuildings) { if (this.excludedBuildings.Contains(info.buildingIndex)) { continue; } if (info.IsBedroom()) { continue; } int selectedWorkerId = this.SelectBuildingWorker(info.buildingIndex, info.requiredAttrId); if (selectedWorkerId >= 0) { Original.SetBuildingWorker(this.partId, this.placeId, info.buildingIndex, selectedWorkerId); } Output.LogBuildingAndWorker(info, selectedWorkerId, this.partId, this.placeId, this.currDate, this.workerAttrs, suppressNoWorkerWarnning: false); } // 最后指派尚未指派的厢房 MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派尚未指派的厢房……")); sortedBuildings = this.buildings.OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value); foreach (var info in sortedBuildings) { if (this.excludedBuildings.Contains(info.buildingIndex)) { continue; } if (!info.IsBedroom()) { continue; } int selectedWorkerId = this.SelectLeftBedroomWorker(info.buildingIndex); if (selectedWorkerId >= 0) { Original.SetBuildingWorker(this.partId, this.placeId, info.buildingIndex, selectedWorkerId); } Output.LogBuildingAndWorker(info, selectedWorkerId, this.partId, this.placeId, this.currDate, this.workerAttrs, suppressNoWorkerWarnning: false); } }
public static void LogAuxiliaryBedroomAndWorker(int bedroomIndex, List <BuildingWorkInfo> relatedBuildings, int priority, int selectedWorkerId, int partId, int placeId, TaiwuDate currDate, Dictionary <int, Dictionary <int, int> > workerAttrs) { var building = DateFile.instance.homeBuildingsDate[partId][placeId][bedroomIndex]; int baseBuildingId = building[0]; int buildingLevel = building[1]; var baseBuilding = DateFile.instance.basehomePlaceDate[baseBuildingId]; string buildingName = baseBuilding[0]; var attrNames = new List <string>(); foreach (var info in relatedBuildings) { string attrName = Common.ToFullWidth(Output.GetRequiredAttrName(info.requiredAttrId).PadRight(2)); attrNames.Add(TaiwuCommon.SetColor(TaiwuCommon.COLOR_RICE_WHITE, attrName)); } string logText = string.Format("{0}:{1} ({2}) [{3}] - ", TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(priority.ToString().PadLeft(4))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, Common.ToFullWidth(buildingName.PadRight(5))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(buildingLevel.ToString().PadLeft(2))), string.Join(", ", attrNames.ToArray())); if (selectedWorkerId >= 0) { string workerName = DateFile.instance.GetActorName(selectedWorkerId); var attrValues = new List <string>(); foreach (var info in relatedBuildings) { string attrValue = Common.ToFullWidth(workerAttrs[selectedWorkerId][info.requiredAttrId].ToString().PadLeft(3)); attrValues.Add(TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, attrValue)); } int mood = int.Parse(DateFile.instance.GetActorDate(selectedWorkerId, 4, addValue: false)); int favor = DateFile.instance.GetActorFavor(false, DateFile.instance.MianActorID(), selectedWorkerId, getLevel: true); MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_LOW, logText + string.Format( "{0} 资质: [{1}] 心情: {2} 好感: {3}", TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, Common.ToFullWidth(workerName.PadRight(5))), string.Join(", ", attrValues.ToArray()), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(mood.ToString().PadLeft(4))), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, Common.ToFullWidth(favor.ToString().PadLeft(2))))); } else { MajordomoWindow.instance.AppendMessage(currDate, Message.IMPORTANCE_HIGH, logText + TaiwuCommon.SetColor(TaiwuCommon.COLOR_RED, "无合适人选")); } }
public string ToString(bool richText) { if (richText) { return(TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, string.Format("第 {0} 年 {1} 月", TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_BROWN, this.year.ToString()), TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_BROWN, (this.GetMonthIndex() + 1).ToString())))); } else { return(this.ToString()); } }
/// <summary> /// 获取当前综合工作指数 /// </summary> /// <returns></returns> private string GetCurrentCompositeWorkIndex() { string text; if (this.history.Count > 0) { var newestDate = this.history.Keys.Max(date => date); text = this.history[newestDate].compositeWorkIndex.ToString("F0"); } else { text = "???"; } return(TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, text)); }
/// <summary> /// 计算汇总统计信息 /// /// 计算过去一年内金钱收入等时,数据不足时会进行估算,至少有三个月数据才计算。 /// 如果数据中间有空缺月份,则计算跨度会大于一年。 /// </summary> private string[] GetSummaryStatsTexts() { const int MIN_CALCULATING_MONTHS = 3; const int N_EXPECTED_MONTHS = 12; string avgCompositeHealth, avgWorkMotivation, avgWorkEffectiveness, earnedMoneyOfLastYear, gdpOfLastYear; if (this.history.Count > 0) { var newestDate = this.history.Keys.Max(date => date); avgCompositeHealth = (this.history[newestDate].workerStats.avgCompositeHealth * 100).ToString("F2"); avgWorkMotivation = (this.history[newestDate].workerStats.avgWorkMotivation * 100).ToString("F2"); avgWorkEffectiveness = (this.history[newestDate].workingStats.avgWorkEffectiveness * 100).ToString("F2"); } else { avgCompositeHealth = "???"; avgWorkMotivation = "???"; avgWorkEffectiveness = "???"; } if (this.history.Count >= MIN_CALCULATING_MONTHS) { var datesWithin = this.history.OrderByDescending(entry => entry.Key).Take(N_EXPECTED_MONTHS); var earnedMoneyList = datesWithin.Select(entry => entry.Value.earningStats.earnedMoney); float earnedMoneyOfLastYear_ = (float)earnedMoneyList.Sum() / earnedMoneyList.Count() * N_EXPECTED_MONTHS; earnedMoneyOfLastYear = earnedMoneyOfLastYear_.ToString("F0"); var gdpList = datesWithin.Select(entry => entry.Value.earningStats.gdp); float gdpOfLastYear_ = (float)gdpList.Sum() / gdpList.Count() * N_EXPECTED_MONTHS; gdpOfLastYear = gdpOfLastYear_.ToString("F0"); } else { earnedMoneyOfLastYear = "???"; gdpOfLastYear = "???"; } return(new string[] { "平均综合健康: " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, avgCompositeHealth) + " %", "平均工作动力: " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, avgWorkMotivation) + " %", "平均工作效率: " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, avgWorkEffectiveness) + " %", "一年内银钱收入: " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, earnedMoneyOfLastYear), "一年内生产总值: " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, gdpOfLastYear), }); }
private static string GetHarvestedActorsDetails() { string details = ""; if (AutoHarvest.harvestedActors.Count == 0) { return(details); } foreach (var actorId in AutoHarvest.harvestedActors) { string name = DateFile.instance.GetActorName(actorId); string coloredName = TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, name); details += coloredName + "、"; } details = details.Substring(0, details.Length - 1) + "。"; return(details); }
private static string GetHarvestedResourcesSummary() { string summary = ""; if (AutoHarvest.harvestedResources.Count == 0) { return(summary); } foreach (var entry in AutoHarvest.harvestedResources) { int resourceIndex = entry.Key; int quantity = entry.Value; string name = DateFile.instance.resourceDate[resourceIndex][1]; summary += TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, name) + "\u00A0" + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, quantity.ToString()) + "、"; } summary = summary.Substring(0, summary.Length - 1) + "。\n"; return(summary); }
/// <summary> /// 计算过去一年内金钱收入 /// 数据不足时会进行估算,至少有三个月数据才计算 /// 如果数据中间有空缺月份,则计算跨度会大于一年 /// </summary> /// <returns></returns> private string GetEarnedMoneyOfLastYear() { const int MIN_CALCULATING_MONTHS = 3; const int N_EXPECTED_MONTHS = 12; string text; if (this.history.Count >= MIN_CALCULATING_MONTHS) { var earnedMoneyList = this.history.OrderByDescending(entry => entry.Key).Take(N_EXPECTED_MONTHS) .Select(entry => entry.Value.earnedMoney); float earnedMoneyOfLastYear = earnedMoneyList.Sum() / earnedMoneyList.Count() * N_EXPECTED_MONTHS; text = earnedMoneyOfLastYear.ToString("F0"); } else { text = "???"; } return(TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, text)); }
private static string GetHarvestedItemsSummary() { string summary = ""; if (AutoHarvest.harvestedItems.Count == 0) { return(summary); } int numDisplayedItems = 0; foreach (var items in AutoHarvest.harvestedItems.Reverse()) { int quality = items.Key; foreach (var item in items.Value) { int itemId = item.Key; int quantity = item.Value; string name = DateFile.instance.GetItemDate(itemId, 0, otherMassage: false); string coloredName = TaiwuCommon.SetColor(TaiwuCommon.COLOR_LOWEST_LEVEL + quality - 1, name); summary += coloredName + "、"; ++numDisplayedItems; if (numDisplayedItems >= MAX_DISPLAYED_ITEMS) { break; } } if (numDisplayedItems >= MAX_DISPLAYED_ITEMS) { break; } } summary = summary.Substring(0, summary.Length - 1) + "等\u00A0" + AutoHarvest.numharvestedItems + "\u00A0件物品。\n"; return(summary); }
/// <summary> /// 指派工作人员 /// </summary> public void AssignBuildingWorkers() { var workingStats = HumanResource.GetWorkingStats(this.partId, this.placeId); MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_NORMAL, TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_BLUE, "开始指派工作人员") + " - " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, "综合工作指数") + ": " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, workingStats.compositeWorkIndex.ToString())); Original.RemoveWorkersFromBuildings(this.partId, this.placeId, this.excludedBuildings, this.excludedWorkers); MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始第一轮指派……")); this.AssignBuildingWorkers_PrepareData(); this.AssignBedroomWorkers(); MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始第二轮指派……")); // 指派完厢房后,重新计算 this.AssignBuildingWorkers_PrepareData(); this.AssignLeftBuildings(); Original.UpdateAllBuildings(this.partId, this.placeId); var workerStats = HumanResource.GetWorkerStats(this.partId, this.placeId); MajordomoWindow.instance.SetWorkerStats(this.currDate, workerStats); workingStats = HumanResource.GetWorkingStats(this.partId, this.placeId); MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_NORMAL, TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_BLUE, "结束指派工作人员") + " - " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_BROWN, "综合工作指数") + ": " + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, workingStats.compositeWorkIndex.ToString())); MajordomoWindow.instance.SetWorkingStats(this.currDate, workingStats); }
private static string GetHarvestedResourcesDetails(ref EarningStats stats) { string details = ""; if (AutoHarvest.harvestedResources.Count == 0) { return(details); } foreach (var entry in AutoHarvest.harvestedResources) { int resourceIndex = entry.Key; int quantity = entry.Value; string name = DateFile.instance.resourceDate[resourceIndex][1]; details += TaiwuCommon.SetColor(TaiwuCommon.COLOR_YELLOW, name) + "\u00A0" + TaiwuCommon.SetColor(TaiwuCommon.COLOR_WHITE, quantity.ToString()) + "、"; switch (resourceIndex) { case ResourceMaintainer.RES_ID_MONEY: stats.earnedMoney += quantity; stats.gdp += quantity; break; case ResourceMaintainer.RES_ID_FAME: stats.earnedFame += quantity; stats.gdp += Mathf.RoundToInt(quantity * ResourceMaintainer.EXCHANGE_RATE_FAME); break; default: stats.gdp += Mathf.RoundToInt(quantity * ResourceMaintainer.EXCHANGE_RATE_DEFAULT); break; } } details = details.Substring(0, details.Length - 1) + "。"; return(details); }
/// <summary> /// 由于过早的月份的消息会被删除,故只显示最近的数个月的消息 /// </summary> private void UpdateMessage() { int baseDateIndex = Mathf.Max(this.history.Count - MajordomoWindow.MESSAGE_SHELF_LIFE, 0); var orderedDates = this.history.Keys.OrderByDescending(date => date) .Take(MajordomoWindow.MESSAGE_SHELF_LIFE).Reverse().ToList(); if (this.sortedDateIndex >= baseDateIndex && this.sortedDateIndex < this.history.Count) { var date = orderedDates[this.sortedDateIndex - baseDateIndex]; var record = this.history[date]; var messages = record.messages .Where(message => message.importance >= Main.settings.messageImportanceThreshold) .Select(message => TaiwuCommon.SetColor(TaiwuCommon.COLOR_LIGHT_GRAY, "·") + " " + message.content) .ToList(); this.CreateMessageContentItems(messages); } else { this.CreateMessageContentItems(new List <string>()); } this.textMessagePage.text = $"{this.sortedDateIndex - baseDateIndex + 1} / {orderedDates.Count}"; }
/// <summary> /// 为所有厢房安排工作人员 /// </summary> private void AssignBedroomWorkers() { // 厢房 ID -> 该厢房辅助的建筑信息列表 // bedroomIndex -> [BuildingWorkInfo, ] var bedroomsForWork = Bedroom.GetBedroomsForWork(this.partId, this.placeId, this.buildings, this.attrCandidates, this.workerAttrs); // 更新辅助类厢房的优先级 // 辅助类厢房优先级 = 基础优先级 + SUM(辅助建筑优先级) // bedroomIndex -> priority var auxiliaryBedroomsPriorities = new Dictionary <int, int>(); foreach (var entry in bedroomsForWork) { int bedroomIndex = entry.Key; var relatedBuildings = entry.Value; int basePriority = 7; int priority = basePriority * WORKING_PRIORITY_STEP_SIZE + relatedBuildings.Select(info => info.priority).Sum(); auxiliaryBedroomsPriorities[bedroomIndex] = priority; } // 对于辅助类厢房,按优先级依次分配合适的人选 MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派辅助类厢房……")); var sortedAuxiliaryBedrooms = auxiliaryBedroomsPriorities.OrderByDescending(entry => entry.Value).Select(entry => entry.Key); foreach (int bedroomIndex in sortedAuxiliaryBedrooms) { int selectedWorkerId = this.SelectAuxiliaryBedroomWorker(bedroomIndex, bedroomsForWork[bedroomIndex]); if (selectedWorkerId >= 0) { Original.SetBuildingWorker(this.partId, this.placeId, bedroomIndex, selectedWorkerId); } Output.LogAuxiliaryBedroomAndWorker(bedroomIndex, bedroomsForWork[bedroomIndex], auxiliaryBedroomsPriorities[bedroomIndex], selectedWorkerId, this.partId, this.placeId, this.currDate, this.workerAttrs); } // 对于一般厢房,按优先级依次分配合适的人选 MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派一般厢房……")); var sortedBedrooms = this.buildings.Where(entry => entry.Value.IsBedroom()) .OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value); foreach (var info in sortedBedrooms) { if (this.excludedBuildings.Contains(info.buildingIndex)) { continue; } int selectedWorkerId = this.SelectBuildingWorker(info.buildingIndex, info.requiredAttrId); if (selectedWorkerId >= 0) { Original.SetBuildingWorker(this.partId, this.placeId, info.buildingIndex, selectedWorkerId); } Output.LogBuildingAndWorker(info, selectedWorkerId, this.partId, this.placeId, this.currDate, this.workerAttrs); } }