コード例 #1
0
 public static HopeWorker MakeNewWorkerFromDef(HopeDef def, Pawn pawn)
 {
     if (def != null)
     {
         Type       testType   = typeof(HopeWorker);
         HopeWorker calculator = (HopeWorker)Activator.CreateInstance(testType);
         calculator.pawn = pawn;
         return(calculator);
     }
     return(null);
 }
コード例 #2
0
        private void InitializeHopeWorkersFromDefs()
        {
            expectedMaxHopeRange = 0;
            allHopeWorkers       = new List <HopeWorker>();
            foreach (HopeDef checkingHopeDef in DefDatabase <HopeDef> .AllDefsListForReading)
            {
                //EdgeOfAbyssMain.LogError("Looping through HopeDef " + checkingHopeDef.defName);
                //EdgeOfAbyssMain.LogError("It has target type = " + checkingHopeDef.hopeWorker);

                expectedMaxHopeRange += checkingHopeDef.ExpectedRange;
                Type hopeWorkerType = checkingHopeDef.hopeWorker;
                if (hopeWorkerType != null)
                {
                    HopeWorker newWorker = (HopeWorker)Activator.CreateInstance(checkingHopeDef.hopeWorker, pawn);
                    newWorker.def = checkingHopeDef;
                    newWorker.InitializeFromDef();
                    allHopeWorkers.Add(newWorker);
                }
            }
            allHopeWorkers.Sort(Comparer_HopeWorker_ByDisplayOrder);
        }
コード例 #3
0
        private void CompareAndApplyHopeWorkers(List <HopeWorker> listFromDefs, List <HopeWorker> listFromFile)
        {
            // 1. Make new list
            List <HopeWorker> validWorkers = new List <HopeWorker>();

            // 2. Add all valid workers from file
            foreach (HopeWorker worker in listFromFile)
            {
                if (worker.def == null)
                {
                    continue;
                }
                if (!worker.HopeIsApplicableToCreature)
                {
                    continue;
                }
                validWorkers.Add(worker);
            }

            // 3. Add all workers from constructor (must not exist in the list)
            foreach (HopeWorker workerFromDef in listFromDefs)
            {
                // Find the 1st one, if exists
                HopeWorker existingWorker = listFromFile.Where((HopeWorker workerFromFile) => workerFromFile.GetType() == workerFromDef.GetType()).FirstOrDefault();
                if (existingWorker == null)
                {
                    // Does not already exist; this must be a new worker.
                    if (workerFromDef.HopeIsApplicableToCreature)
                    {
                        validWorkers.Add(workerFromDef);
                    }
                }
            }

            // 4. Apply changes
            allHopeWorkers = validWorkers;

            // 5. Sort the list, so we can display them as we wish.
            allHopeWorkers.Sort(Comparer_HopeWorker_ByDisplayOrder);
        }
コード例 #4
0
 private static int Comparer_HopeWorker_ByDisplayOrder(HopeWorker a, HopeWorker b)
 {
     return(a.DisplayOrder - b.DisplayOrder);
 }