Пример #1
0
        private void AssignBuildingWorkers_PrepareData()
        {
            List <int> workerIds = Original.GetWorkerIds(this.partId, this.placeId);

            workerIds = workerIds.Where(workerId => !this.excludedWorkers.Contains(workerId)).ToList();

            Dictionary <int, List <BuildingWorkInfo> > attrBuildings = this.GetBuildingsNeedWorker();

            //
            this.buildings = new Dictionary <int, BuildingWorkInfo>();
            foreach (var currBuildingWorkInfos in attrBuildings.Values)
            {
                foreach (var info in currBuildingWorkInfos)
                {
                    this.buildings[info.buildingIndex] = info;
                }
            }

            //
            this.workerAttrs    = new Dictionary <int, Dictionary <int, int> >();
            this.attrCandidates = new Dictionary <int, List <int> >();

            foreach (int workerId in workerIds)
            {
                this.workerAttrs[workerId] = new Dictionary <int, int>();
            }

            foreach (int requiredAttrId in attrBuildings.Keys)
            {
                foreach (int workerId in workerIds)
                {
                    // 不需要资质时(厢房),放入好感和心情相对标准状态的差值
                    int attrValue = requiredAttrId != 0 ?
                                    int.Parse(DateFile.instance.GetActorDate(workerId, requiredAttrId)) :
                                    HumanResource.GetLackedMoodAndFavor(workerId);
                    this.workerAttrs[workerId][requiredAttrId] = attrValue;
                }

                List <int> sortedWorkerIds = this.workerAttrs
                                             .OrderByDescending(elem => elem.Value[requiredAttrId])
                                             .Select(elem => elem.Key)
                                             .ToList();
                this.attrCandidates[requiredAttrId] = sortedWorkerIds;
            }
        }
Пример #2
0
        /// <summary>
        /// 计算指定地区的工作人员统计信息
        /// </summary>
        /// <param name="partId"></param>
        /// <param name="placeId"></param>
        /// <returns></returns>
        public static WorkerStats GetWorkerStats(int partId, int placeId)
        {
            int        mainActorId = DateFile.instance.MianActorID();
            List <int> workerIds   = Original.GetWorkerIds(partId, placeId);
            var        stats       = new WorkerStats();

            foreach (int workerId in workerIds)
            {
                stats.avgHealthInjury      += 1f - TaiwuCommon.GetInjuryRate(workerId);
                stats.avgHealthCirculating += 1f - TaiwuCommon.GetCirculatingBlockingRate(workerId);
                stats.avgHealthPoison      += 1f - TaiwuCommon.GetPoisoningRate(workerId);
                stats.avgHealthLifespan    += 1f - TaiwuCommon.GetLifespanDamageRate(workerId);

                int mood        = int.Parse(DateFile.instance.GetActorDate(workerId, 4, false));
                int favor       = DateFile.instance.GetActorFavor(false, mainActorId, workerId);
                int favorLevel  = DateFile.instance.GetActorFavor(false, mainActorId, workerId, getLevel: true);
                int scaledFavor = Original.GetScaledFavor(favorLevel);
                scaledFavor              = Original.AdjustScaledFavorWithMood(scaledFavor, mood);
                stats.avgMood           += mood;
                stats.avgFriendliness   += favor;
                stats.avgWorkMotivation += Mathf.Max(scaledFavor, 0) / 100f;
            }

            if (workerIds.Count > 0)
            {
                stats.nWorkers              = workerIds.Count;
                stats.avgHealthInjury      /= workerIds.Count;
                stats.avgHealthCirculating /= workerIds.Count;
                stats.avgHealthPoison      /= workerIds.Count;
                stats.avgHealthLifespan    /= workerIds.Count;
                stats.avgCompositeHealth    = (stats.avgHealthInjury + stats.avgHealthCirculating + stats.avgHealthPoison + stats.avgHealthLifespan) / 4;
                stats.avgMood           /= workerIds.Count;
                stats.avgFriendliness   /= workerIds.Count;
                stats.avgWorkMotivation /= workerIds.Count;
            }
            return(stats);
        }