// 对于每个需要厢房才能满效率的建筑,尝试找到邻接厢房,生成建筑列表和候选厢房列表 private static void GetBedroomsForWork_PrepareData(int partId, int placeId, Dictionary <int, BuildingWorkInfo> buildings, Dictionary <int, List <int> > attrCandidates, Dictionary <int, Dictionary <int, int> > workerAttrs, Dictionary <int, BuildingInfo> buildingsNeedBedroom, Dictionary <int, BedroomInfo> bedroomCandidates) { // 遍历所有建筑 foreach (var info in buildings.Values) { // 排除厢房 if (info.requiredAttrId == 0) { continue; } // 如果没有候选人,则不寻找邻接厢房 var sortedWorkerIds = attrCandidates[info.requiredAttrId]; if (sortedWorkerIds.Any()) { int workerId = sortedWorkerIds[0]; int attrMaxValue = workerAttrs[workerId][info.requiredAttrId]; // 凭单个候选人无法满效率 if (attrMaxValue < info.fullWorkingAttrValue) { // 找到邻接厢房,并创建供之后使用的数据结构 var adjacentBedrooms = Bedroom.GetAdjacentBedrooms(partId, placeId, info.buildingIndex); // 记录需要厢房的建筑信息 buildingsNeedBedroom[info.buildingIndex] = new BuildingInfo { buildingWorkInfo = info, adjacentBedrooms = adjacentBedrooms, }; // 记录候选厢房的信息 foreach (int bedroomBuildingIndex in adjacentBedrooms) { if (!bedroomCandidates.ContainsKey(bedroomBuildingIndex)) { bedroomCandidates[bedroomBuildingIndex] = new BedroomInfo { buildingIndex = bedroomBuildingIndex, buildingsNeedBedroom = new List <int>(), }; } bedroomCandidates[bedroomBuildingIndex].buildingsNeedBedroom.Add(info.buildingIndex); } } } } }
/// <summary> /// 获取邻接厢房对指定建筑的能力加成 /// </summary> /// <param name="partId"></param> /// <param name="placeId"></param> /// <param name="buildingIndex"></param> /// <param name="requiredAttrId"></param> /// <returns></returns> private static int GetAdjacentAttrBonus(int partId, int placeId, int buildingIndex, int requiredAttrId) { int totalAdjacentAttrValue = 0; foreach (int adjacentBuildingIndex in Bedroom.GetAdjacentBedrooms(partId, placeId, buildingIndex)) { if (!DateFile.instance.actorsWorkingDate.ContainsKey(partId) || !DateFile.instance.actorsWorkingDate[partId].ContainsKey(placeId) || !DateFile.instance.actorsWorkingDate[partId][placeId].ContainsKey(adjacentBuildingIndex)) { continue; } int adjacentActorId = DateFile.instance.actorsWorkingDate[partId][placeId][adjacentBuildingIndex]; int adjacentAttrValue = (requiredAttrId > 0) ? int.Parse(DateFile.instance.GetActorDate(adjacentActorId, requiredAttrId)) : 0; adjacentAttrValue = Original.ToStandardAttrValue(requiredAttrId, adjacentAttrValue); totalAdjacentAttrValue += adjacentAttrValue; } return(totalAdjacentAttrValue); }