示例#1
0
        public ActionResult SkillCreatePartialJobPosting(JobPosting model)
        {
            SkillRequirement Skill     = new SkillRequirement();
            List <Trait>     listItems = new List <Trait>();

            foreach (var prop in from s in Skill.GetType().GetProperties() select s)
            {
                if (!prop.PropertyType.Equals(typeof(int?)))
                {
                    continue;
                }
                Trait item = new Trait
                {
                    DisplayName  = prop.Name,
                    PropertyName = prop.Name
                };
                listItems.Add(item);
            }
            SkillCreateViewModel viewModel = new SkillCreateViewModel
            {
                CreatorType = SkillCreatorType.JobPosting,
                CreatorId   = model.Id,
                Traits      = listItems
            };

            return(PartialView("SkillCreatePartial", viewModel));
        }
示例#2
0
    public void removeRQ(SkillRequirement position)
    {
        SkillRequirement remove = this.requirement.Find(x => x.getTypeRQ() == position.getTypeRQ());

        this.requirement.Remove(remove);
        this.requirements--;
    }
示例#3
0
        public async Task <SkillRequirement> AddAsync(SkillRequirement skillRequirement)
        {
            var res = await _uow.SkillRequirements.AddAsync(skillRequirement);

            await _uow.SaveChangesAsync();

            return(res);
        }
示例#4
0
 private Job StartOrResumeBillJob(Pawn pawn, IBillGiver giver)
 {
     for (int i = 0; i < giver.BillStack.Count; i++)
     {
         Bill bill = giver.BillStack[i];
         if ((bill.recipe.requiredGiverWorkType != null && bill.recipe.requiredGiverWorkType != def.workType) || (Find.TickManager.TicksGame < bill.lastIngredientSearchFailTicks + ReCheckFailedBillTicksRange.RandomInRange && FloatMenuMakerMap.makingFor != pawn))
         {
             continue;
         }
         bill.lastIngredientSearchFailTicks = 0;
         if (!bill.ShouldDoNow() || !bill.PawnAllowedToStartAnew(pawn))
         {
             continue;
         }
         SkillRequirement skillRequirement = bill.recipe.FirstSkillRequirementPawnDoesntSatisfy(pawn);
         if (skillRequirement != null)
         {
             JobFailReason.Is("UnderRequiredSkill".Translate(skillRequirement.minLevel), bill.Label);
             continue;
         }
         Bill_ProductionWithUft bill_ProductionWithUft = bill as Bill_ProductionWithUft;
         if (bill_ProductionWithUft != null)
         {
             if (bill_ProductionWithUft.BoundUft != null)
             {
                 if (bill_ProductionWithUft.BoundWorker == pawn && pawn.CanReserveAndReach(bill_ProductionWithUft.BoundUft, PathEndMode.Touch, Danger.Deadly) && !bill_ProductionWithUft.BoundUft.IsForbidden(pawn))
                 {
                     return(FinishUftJob(pawn, bill_ProductionWithUft.BoundUft, bill_ProductionWithUft));
                 }
                 continue;
             }
             UnfinishedThing unfinishedThing = ClosestUnfinishedThingForBill(pawn, bill_ProductionWithUft);
             if (unfinishedThing != null)
             {
                 return(FinishUftJob(pawn, unfinishedThing, bill_ProductionWithUft));
             }
         }
         if (!TryFindBestBillIngredients(bill, pawn, (Thing)giver, chosenIngThings))
         {
             if (FloatMenuMakerMap.makingFor != pawn)
             {
                 bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame;
             }
             else
             {
                 JobFailReason.Is(MissingMaterialsTranslated, bill.Label);
             }
             chosenIngThings.Clear();
             continue;
         }
         Job haulOffJob;
         Job result = TryStartNewDoBillJob(pawn, bill, giver, chosenIngThings, out haulOffJob);
         chosenIngThings.Clear();
         return(result);
     }
     chosenIngThings.Clear();
     return(null);
 }
示例#5
0
        // GET: Skills
        public ActionResult SkillDetailsPartial(Guid?SkillRequirementId)
        {
            //Create a new Db context
            ApplicationDbContext context = new ApplicationDbContext();
            SkillRequirement     model   = (from s in context.SkillRequirements
                                            where s.Id == SkillRequirementId
                                            select s).FirstOrDefault();

            return(PartialView("SkillDetailsPartial", model));
        }
 private Job StartOrResumeBillJob(Pawn pawn, IBillGiver giver, LocalTargetInfo target)
 {
     for (int i = 0; i < giver.BillStack.Count; i++)
     {
         Bill bill = giver.BillStack[i];
         if ((bill.recipe == TechDefOf.DocumentTech || bill.recipe == TechDefOf.DocumentTechDigital) && bill.ShouldDoNow() && bill.PawnAllowedToStartAnew(pawn))
         {
             SkillRequirement skillRequirement = bill.recipe.FirstSkillRequirementPawnDoesntSatisfy(pawn);
             if (skillRequirement != null)
             {
                 JobFailReason.Is("UnderRequiredSkill".Translate(skillRequirement.minLevel), bill.Label);
             }
             else
             {
                 if (bill.recipe.UsesUnfinishedThing)
                 {
                     Bill_ProductionWithUft bill_ProductionWithUft = bill as Bill_ProductionWithUft;
                     if (bill_ProductionWithUft != null)
                     {
                         if (bill_ProductionWithUft.BoundUft != null)
                         {
                             if (bill_ProductionWithUft.BoundWorker == pawn && pawn.CanReserveAndReach(bill_ProductionWithUft.BoundUft, PathEndMode.Touch, Danger.Deadly, 1, -1, null, false) && !bill_ProductionWithUft.BoundUft.IsForbidden(pawn))
                             {
                                 return(FinishUftJob(pawn, bill_ProductionWithUft.BoundUft, bill_ProductionWithUft));
                             }
                             return(null);
                         }
                         else
                         {
                             MethodInfo      ClosestUftInfo  = AccessTools.Method(typeof(WorkGiver_DoBill), "ClosestUnfinishedThingForBill");
                             UnfinishedThing unfinishedThing = (UnfinishedThing)ClosestUftInfo.Invoke(this, new object[] { pawn, bill_ProductionWithUft });
                             if (unfinishedThing != null)
                             {
                                 return(FinishUftJob(pawn, unfinishedThing, bill_ProductionWithUft));
                             }
                         }
                     }
                     return(new Job(TechJobDefOf.DocumentTech, target)
                     {
                         bill = bill
                     });
                 }
                 else
                 {
                     return(new Job(TechJobDefOf.DocumentTechDigital, target)
                     {
                         bill = bill
                     });
                 }
             }
         }
     }
     return(null);
 }
示例#7
0
        public override bool CheckSkills(Mobile from)
        {
            if (!base.CheckSkills(from))
            {
                return(false);
            }

            BaseWeapon weapon = from.Weapon as BaseWeapon;

            if (weapon != null)
            {
                SkillName req = weapon.AbilitySkill;

                Skill bushido  = from.Skills[SkillName.Bushido];
                Skill ninjitsu = from.Skills[SkillName.Ninjitsu];

                bool enoughBushido  = bushido != null && bushido.Value >= SkillRequirement;
                bool enoughNinjitsu = ninjitsu != null && ninjitsu.Value >= SkillRequirement;

                bool ok = false;

                int message = -1;

                if (req == SkillName.Bushido)
                {
                    message = 1070768;                     // You need ~1_SKILL_REQUIREMENT~ Bushido skill to perform that attack!
                    ok      = enoughBushido;
                }
                else if (req == SkillName.Ninjitsu)
                {
                    message = 1063352;                     // You need ~1_SKILL_REQUIREMENT~ Ninjitsu skill to perform that attack!
                    ok      = enoughNinjitsu;
                }
                else
                {
                    message = 1063347;                     // You need ~1_SKILL_REQUIREMENT~ Bushido or Ninjitsu skill to perform that attack!
                    ok      = enoughBushido || enoughNinjitsu;
                }

                if (!ok)
                {
                    from.SendLocalizedMessage(message, SkillRequirement.ToString());
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
        public static string MinSkillString(IEnumerable <SkillRequirement> skillRequirements)
        {
            StringBuilder stringBuilder = new StringBuilder();
            bool          flag          = false;

            if (skillRequirements != null)
            {
                for (int index = 0; index < skillRequirements.Count(); ++index)
                {
                    SkillRequirement skillRequirement = skillRequirements.ElementAt(index);
                    stringBuilder.AppendLine("   " + skillRequirement.skill.skillLabel.CapitalizeFirst() + ": " + (object)skillRequirement.minLevel);
                    flag = true;
                }
            }
            if (!flag)
            {
                stringBuilder.AppendLine("   (" + "NoneLower".Translate() + ")");
            }
            return(stringBuilder.ToString());
        }
示例#9
0
        private Job TryStartJob(Pawn pawn, Building_CokeFurnace furnace)
        {
            SkillRequirement skillRequirement = furnace.SelectedRecipe.FirstSkillRequirementPawnDoesntSatisfy(pawn);

            if (skillRequirement != null)
            {
                JobFailReason.Is("UnderRequiredSkill".Translate(skillRequirement.minLevel), furnace.Label);
                return(null);
            }

            if (!TryFindBestBillIngredients(pawn, furnace, chosenIngThings))
            {
                JobFailReason.Is("MissingMaterials".Translate(), furnace.Label);
                chosenIngThings.Clear();
                return(null);
            }
            Job result = TryStartNewDoBillJob(pawn, furnace);

            chosenIngThings.Clear();
            return(result);
        }
示例#10
0
        protected override void WriteDataXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            ele.TryPathTo("Effect", true, out subEle);
            Effect.WriteXML(subEle, master);

            ele.TryPathTo("SkillRequirement", true, out subEle);
            subEle.Value = SkillRequirement.ToString("G15");

            ele.TryPathTo("DamageMult", true, out subEle);
            subEle.Value = DamageMult.ToString("G15");

            ele.TryPathTo("APCost", true, out subEle);
            subEle.Value = APCost.ToString("G15");

            ele.TryPathTo("IsSilent", true, out subEle);
            subEle.Value = IsSilent.ToString();

            ele.TryPathTo("RequiresMod", true, out subEle);
            subEle.Value = RequiresMod.ToString();

            WriteUnusedXML(ele, master);
        }
示例#11
0
        override protected void Initialize()
        {
            _formulaToggle        = CreateSetting(nameof(_formulaToggle), false);
            _formulaCoeffsByLevel = new Dictionary <SlotLevel, ModSetting <Vector4> >();
            foreach (var level in Utility.GetEnumValues <SlotLevel>())
            {
                Vector4 initialPrice = Vector4.zero;
                switch (level)
                {
                case SlotLevel.Basic: initialPrice.x = 50; break;

                case SlotLevel.Breakthrough: initialPrice.x = 500; break;

                case SlotLevel.Advanced: initialPrice.x = 600; break;
                }
                _formulaCoeffsByLevel.Add(level, CreateSetting(nameof(_formulaCoeffsByLevel) + level, initialPrice));
            }
            _formulaType = CreateSetting(nameof(_formulaType), FormulaType.Linear);
            _learnMutuallyExclusiveSkills = CreateSetting(nameof(_learnMutuallyExclusiveSkills), false);
            _exclusiveSkillCostsTsar      = CreateSetting(nameof(_exclusiveSkillCostsTsar), false);
            _exclusiveSkillCostMultiplier = CreateSetting(nameof(_exclusiveSkillCostMultiplier), 300, IntRange(100, 500));

            _exclusiveSkillRequirement = new SkillRequirement("Tsar Stone");
        }
示例#12
0
 public async Task UpdateAsync(SkillRequirement skillRequirement)
 {
     _uow.SkillRequirements.Update(skillRequirement);
     await _uow.SaveChangesAsync();
 }
示例#13
0
 public async Task RemoveAsync(SkillRequirement skillRequirement)
 {
     _uow.SkillRequirements.Remove(skillRequirement);
     await _uow.SaveChangesAsync();
 }
        public async Task <IActionResult> Post(SkillRequirement skillRequirement)
        {
            await _skillRequirementService.AddAsync(skillRequirement);

            return(Ok());
        }
        public async Task <IActionResult> Put(Guid id, SkillRequirement skillRequirement)
        {
            await _skillRequirementService.UpdateAsync(skillRequirement);

            return(Ok());
        }
示例#16
0
        private static bool CanStartOrResumeBillJob(WorkGiver_DoBill __instance, Pawn pawn, IBillGiver giver)
        {
            for (int i = 0; i < giver.BillStack.Count; i++)
            {
                Bill bill = giver.BillStack[i];
                if ((bill.recipe.requiredGiverWorkType != null && bill.recipe.requiredGiverWorkType != __instance.def.workType) ||
                    (Find.TickManager.TicksGame < bill.lastIngredientSearchFailTicks + WorkGiver_DoBill.ReCheckFailedBillTicksRange.RandomInRange && FloatMenuMakerMap.makingFor != pawn))
                {
                    continue;
                }

                bill.lastIngredientSearchFailTicks = 0;
                if (!bill.ShouldDoNow() || !bill.PawnAllowedToStartAnew(pawn))
                {
                    continue;
                }

                SkillRequirement skillRequirement = bill.recipe.FirstSkillRequirementPawnDoesntSatisfy(pawn);
                if (skillRequirement != null)
                {
                    JobFailReason.Is("UnderRequiredSkill".Translate(skillRequirement.minLevel), bill.Label);
                    continue;
                }

                if (bill is Bill_Medical && ((Bill_Medical)bill).IsSurgeryViolationOnExtraFactionMember(pawn))
                {
                    JobFailReason.Is("SurgeryViolationFellowFactionMember".Translate());
                    continue;
                }

                Bill_ProductionWithUft bill_ProductionWithUft = bill as Bill_ProductionWithUft;
                if (bill_ProductionWithUft != null)
                {
                    if (bill_ProductionWithUft.BoundUft != null)
                    {
                        if (bill_ProductionWithUft.BoundWorker == pawn && pawn.CanReserveAndReach(bill_ProductionWithUft.BoundUft, PathEndMode.Touch, Danger.Deadly) && !bill_ProductionWithUft.BoundUft.IsForbidden(pawn))
                        {
                            return(true);
                        }

                        continue;
                    }

                    if (AnyUnfinishedThingForBill(__instance, pawn, bill_ProductionWithUft))
                    {
                        return(true);
                    }
                }
                List <ThingCount> chosenIngThings = new List <ThingCount>();
                if (!TryFindAnyBillIngredients(__instance, bill, pawn, (Thing)giver, chosenIngThings))
                {
                    if (FloatMenuMakerMap.makingFor != pawn)
                    {
                        bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame;
                    }

                    continue;
                }

                return(true);
            }

            return(false);
        }
示例#17
0
        private void AddSkillRequirements()
        {
            var skills          = _context.Skills.ToArray();
            var knowledgeLevels = _context.KnowledgeLevels.ToArray();
            var vacancies       = _context.Vacancies.ToArray();
            var experience      = _context.Experiences.AsNoTracking().ToArray();

            var skillRequirements = new SkillRequirement[]
            {
                new SkillRequirement
                {
                    Weight    = 25, ExperienceId = experience[0].Id, IsDeleted = false,
                    SkillId   = skills[0].Id, KnowledgeLevelId = knowledgeLevels[0].Id,
                    VacancyId = vacancies[0].Id
                },
                new SkillRequirement
                {
                    Weight    = 80, ExperienceId = experience[2].Id, IsDeleted = false,
                    SkillId   = skills[1].Id, KnowledgeLevelId = knowledgeLevels[2].Id,
                    VacancyId = vacancies[2].Id
                },
                new SkillRequirement
                {
                    Weight    = 70, ExperienceId = experience[3].Id, IsDeleted = false,
                    SkillId   = skills[2].Id, KnowledgeLevelId = knowledgeLevels[2].Id,
                    VacancyId = vacancies[0].Id
                },
                new SkillRequirement
                {
                    Weight    = 70, ExperienceId = experience[1].Id, IsDeleted = false,
                    SkillId   = skills[0].Id, KnowledgeLevelId = knowledgeLevels[5].Id,
                    VacancyId = vacancies[1].Id
                },
                new SkillRequirement
                {
                    Weight    = 30, ExperienceId = experience[1].Id, IsDeleted = false,
                    SkillId   = skills[19].Id, KnowledgeLevelId = knowledgeLevels[5].Id,
                    VacancyId = vacancies[1].Id
                },
                new SkillRequirement
                {
                    Weight    = 30, ExperienceId = experience[3].Id, IsDeleted = false,
                    SkillId   = skills[1].Id, KnowledgeLevelId = knowledgeLevels[6].Id,
                    VacancyId = vacancies[1].Id
                },
                new SkillRequirement
                {
                    Weight    = 75, ExperienceId = experience[3].Id, IsDeleted = false,
                    SkillId   = skills[4].Id, KnowledgeLevelId = knowledgeLevels[6].Id,
                    VacancyId = vacancies[1].Id
                },
                new SkillRequirement
                {
                    Weight    = 50, ExperienceId = experience[3].Id, IsDeleted = false,
                    SkillId   = skills[5].Id, KnowledgeLevelId = knowledgeLevels[7].Id,
                    VacancyId = vacancies[1].Id
                },
                new SkillRequirement
                {
                    Weight    = 50, ExperienceId = experience[3].Id, IsDeleted = false,
                    SkillId   = skills[3].Id, KnowledgeLevelId = knowledgeLevels[7].Id,
                    VacancyId = vacancies[1].Id
                }
            };

            _context.SkillRequirements.AddRange(skillRequirements);
            _context.SaveChanges();
        }
 private IntInputWidget <SkillRequirement> CreateSkillRequirements(SkillRequirement skillRequirement)
 {
     return(new IntInputWidget <SkillRequirement>(skillRequirement, skillRequirement.skill.label, (sr) => sr.minLevel, (sr, i) => sr.minLevel = i));
 }
示例#19
0
        private Job StartOrResumeBillJob(Pawn pawn, IBillGiver giver, Thing thing)
        {
            for (int i = 0; i < giver.BillStack.Count; i++)
            {
                Bill bill = giver.BillStack[i];
                if ((bill.recipe.requiredGiverWorkType == null || bill.recipe.requiredGiverWorkType == def.workType) && (Find.TickManager.TicksGame >= bill.lastIngredientSearchFailTicks + ReCheckFailedBillTicksRange.RandomInRange || FloatMenuMakerMap.makingFor == pawn))
                {
                    bill.lastIngredientSearchFailTicks = 0;
                    if (bill.ShouldDoNow() && bill.PawnAllowedToStartAnew(pawn))
                    {
                        bool issueBill = true;
                        this.magicCircle = thing as Building_TMMagicCircleBase;

                        List <Pawn> billPawns = new List <Pawn>();
                        billPawns.Clear();
                        if (bill.recipe is MagicRecipeDef)
                        {
                            MagicRecipeDef       magicRecipe = bill.recipe as MagicRecipeDef;
                            CompAbilityUserMagic compMagic   = pawn.TryGetComp <CompAbilityUserMagic>();
                            if (magicCircle.IsActive)
                            {
                                issueBill = false;
                            }
                            if (!magicCircle.CanEverDoBill(bill, out billPawns, magicRecipe))
                            {
                                issueBill = false;
                            }
                            if (!billPawns.Contains(pawn))
                            {
                                issueBill = false;
                            }
                        }

                        if (issueBill)
                        {
                            SkillRequirement skillRequirement = bill.recipe.FirstSkillRequirementPawnDoesntSatisfy(pawn);
                            if (skillRequirement != null)
                            {
                                JobFailReason.Is("UnderRequiredSkill".Translate(skillRequirement.minLevel), bill.Label);
                            }
                            else
                            {
                                Bill_ProductionWithUft bill_ProductionWithUft = bill as Bill_ProductionWithUft;
                                if (bill_ProductionWithUft != null)
                                {
                                    if (bill_ProductionWithUft.BoundUft != null)
                                    {
                                        if (bill_ProductionWithUft.BoundWorker == pawn && pawn.CanReserveAndReach(bill_ProductionWithUft.BoundUft, PathEndMode.Touch, Danger.Deadly) && !bill_ProductionWithUft.BoundUft.IsForbidden(pawn))
                                        {
                                            return(FinishUftJob(pawn, bill_ProductionWithUft.BoundUft, bill_ProductionWithUft));
                                        }
                                        continue;
                                    }
                                    UnfinishedThing unfinishedThing = ClosestUnfinishedThingForBill(pawn, bill_ProductionWithUft);
                                    if (unfinishedThing != null)
                                    {
                                        return(FinishUftJob(pawn, unfinishedThing, bill_ProductionWithUft));
                                    }
                                }
                                if (TryFindBestBillIngredients(bill, pawn, (Thing)giver, chosenIngThings))
                                {
                                    this.magicCircle = thing as Building_TMMagicCircle;
                                    if (this.magicCircle != null && bill.recipe is MagicRecipeDef)
                                    {
                                        this.magicCircle.magicRecipeDef = bill.recipe as MagicRecipeDef;
                                        this.magicCircle.MageList.Clear();
                                        magicCircle.MageList.Add(pawn);
                                        //Log.Message("assigning magic bill to " + pawn.LabelShort);
                                        if (bill.recipe is MagicRecipeDef && billPawns.Count > 1)
                                        {
                                            for (int j = 0; j < billPawns.Count; j++)
                                            {
                                                if (billPawns[j] != pawn)
                                                {
                                                    magicCircle.MageList.Add(billPawns[j]);
                                                    magicCircle.IssueAssistJob(billPawns[j]);
                                                    //Log.Message("assisting magic bill to " + billPawns[j].LabelShort);
                                                }
                                            }
                                        }
                                        this.magicCircle.IsPending = true;
                                    }
                                    Job result = TryStartNewDoBillJob(pawn, bill, giver);
                                    chosenIngThings.Clear();
                                    return(result);
                                }
                                if (FloatMenuMakerMap.makingFor != pawn)
                                {
                                    bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame;
                                }
                                else
                                {
                                    JobFailReason.Is(MissingMaterialsTranslated, bill.Label);
                                }
                                chosenIngThings.Clear();
                            }
                        }
                    }
                }
            }
            chosenIngThings.Clear();
            return(null);
        }
示例#20
0
        /// <summary>
        /// Creates a Droid template.
        /// </summary>
        /// <param name="raceDef">ThingDef to use as race.</param>
        /// <param name="pawnKindDef">PawnKindDef to use as kind.</param>
        /// <param name="faction">Faction that owns this Droid.</param>
        /// <param name="map">Map to spawn in.</param>
        /// <returns>New Pawn if successful. Null if not.</returns>
        public static Pawn MakeDroidTemplate(PawnKindDef pawnKindDef, Faction faction, int tile, List <SkillRequirement> skills = null, int defaultSkillLevel = 6)
        {
            Map map = null;

            if (tile > -1)
            {
                map = Current.Game?.FindMap(tile);
            }

            //Log.Message("Map: " + map);

            //Manually craft a Droid Pawn.
            Pawn pawnBeingCrafted = (Pawn)ThingMaker.MakeThing(pawnKindDef.race);

            if (pawnBeingCrafted == null)
            {
                return(null);
            }

            //Kind, Faction and initial Components.
            pawnBeingCrafted.kindDef = pawnKindDef;
            if (faction != null)
            {
                pawnBeingCrafted.SetFactionDirect(faction);
            }
            PawnComponentsUtility.CreateInitialComponents(pawnBeingCrafted);

            //Gender
            pawnBeingCrafted.gender = Gender.Male;

            //Set Needs at initial levels.
            pawnBeingCrafted.needs.SetInitialLevels();

            //Set age
            pawnBeingCrafted.ageTracker.AgeBiologicalTicks    = 0;
            pawnBeingCrafted.ageTracker.AgeChronologicalTicks = 0;

            //Set Story
            if (pawnBeingCrafted.RaceProps.Humanlike)
            {
                DroidSpawnProperties spawnProperties = pawnKindDef.race.GetModExtension <DroidSpawnProperties>();

                if (spawnProperties != null)
                {
                    pawnBeingCrafted.gender = spawnProperties.gender;
                    pawnBeingCrafted.playerSettings.hostilityResponse = spawnProperties.hostileResponse;
                }

                //Appearance
                pawnBeingCrafted.story.melanin   = 1f;
                pawnBeingCrafted.story.crownType = CrownType.Average;

                if (spawnProperties != null && spawnProperties.generateHair)
                {
                    IEnumerable <HairDef> source = from hair in DefDatabase <HairDef> .AllDefs
                                                   where hair.hairTags.SharesElementWith(spawnProperties.hairTags)
                                                   select hair;
                    HairDef resultHair = source.RandomElementByWeightWithFallback((hair) => HairChoiceLikelihoodFor(hair, pawnBeingCrafted), DefDatabase <HairDef> .GetNamed("Shaved"));

                    pawnBeingCrafted.story.hairDef = resultHair;

                    if (pawnBeingCrafted.def is ThingDef_AlienRace alienRaceDef)
                    {
                        pawnBeingCrafted.story.hairColor = alienRaceDef.alienRace?.generalSettings?.alienPartGenerator?.colorChannels.FirstOrDefault(channel => channel.name == "hair").first?.NewRandomizedColor() ?? new UnityEngine.Color(1f, 1f, 1f, 1f);
                    }
                }
                else
                {
                    pawnBeingCrafted.story.hairColor = new UnityEngine.Color(1f, 1f, 1f, 1f);
                    pawnBeingCrafted.story.hairDef   = DefDatabase <HairDef> .GetNamed("Shaved");
                }


                if (spawnProperties != null && spawnProperties.bodyType != null)
                {
                    pawnBeingCrafted.story.bodyType = spawnProperties.bodyType;
                }
                else
                {
                    pawnBeingCrafted.story.bodyType = BodyTypeDefOf.Thin;
                }

                PortraitsCache.SetDirty(pawnBeingCrafted);

                //Backstory
                Backstory backstory = null;
                if (spawnProperties != null && spawnProperties.backstory != null)
                {
                    BackstoryDatabase.TryGetWithIdentifier(spawnProperties.backstory.defName, out backstory);
                }
                else
                {
                    BackstoryDatabase.TryGetWithIdentifier("ChJAndroid_Droid", out backstory);
                }

                pawnBeingCrafted.story.childhood = backstory;

                //Skills
                if (skills == null || skills.Count <= 0)
                {
                    if (spawnProperties != null)
                    {
                        //Set all skills to default first.
                        foreach (SkillDef skillDef in DefDatabase <SkillDef> .AllDefsListForReading)
                        {
                            SkillRecord skill = pawnBeingCrafted.skills.GetSkill(skillDef);
                            skill.Level = spawnProperties.defaultSkillLevel;
                        }

                        //Set skills and passions.
                        foreach (DroidSkill droidSkill in spawnProperties.skills)
                        {
                            SkillRecord skill = pawnBeingCrafted.skills.GetSkill(droidSkill.def);
                            if (skill != null)
                            {
                                skill.Level   = droidSkill.level;
                                skill.passion = droidSkill.passion;
                            }
                        }
                    }
                    else
                    {
                        List <SkillDef> allDefsListForReading = DefDatabase <SkillDef> .AllDefsListForReading;
                        for (int i = 0; i < allDefsListForReading.Count; i++)
                        {
                            SkillDef    skillDef = allDefsListForReading[i];
                            SkillRecord skill    = pawnBeingCrafted.skills.GetSkill(skillDef);

                            if (skillDef == SkillDefOf.Shooting || skillDef == SkillDefOf.Melee || skillDef == SkillDefOf.Mining || skillDef == SkillDefOf.Plants)
                            {
                                skill.Level = 8;
                            }
                            else
                            if (skillDef == SkillDefOf.Medicine || skillDef == SkillDefOf.Crafting || skillDef == SkillDefOf.Cooking)
                            {
                                skill.Level = 4;
                            }
                            else
                            {
                                skill.Level = 6;
                            }
                            skill.passion = Passion.None;
                        }
                    }
                }
                else
                {
                    List <SkillDef> allDefsListForReading = DefDatabase <SkillDef> .AllDefsListForReading;
                    for (int i = 0; i < allDefsListForReading.Count; i++)
                    {
                        SkillDef    skillDef = allDefsListForReading[i];
                        SkillRecord skill    = pawnBeingCrafted.skills.GetSkill(skillDef);

                        SkillRequirement skillRequirement = skills.First(sr => sr.skill == skillDef);
                        if (skillRequirement != null)
                        {
                            skill.Level = skillRequirement.minLevel;
                        }
                        else
                        {
                            skill.Level = defaultSkillLevel;
                        }

                        skill.passion = Passion.None;
                    }
                }
            }

            //Work settings
            if (pawnBeingCrafted.workSettings != null)
            {
                pawnBeingCrafted.workSettings.EnableAndInitialize();
            }

            //Name
            if (map != null && faction.IsPlayer)
            {
                var names = from pawn in map.mapPawns.FreeColonists
                            select pawn.Name;

                if (names != null)
                {
                    int    droidNameCount = names.Count(name => name.ToStringShort.ToLower().StartsWith(pawnKindDef.race.label.ToLower()));
                    string finalShortName = pawnKindDef.race.LabelCap + " " + droidNameCount;
                    pawnBeingCrafted.Name = MakeDroidName(finalShortName);
                }
                else
                {
                    pawnBeingCrafted.Name = MakeDroidName(null);
                }
            }
            else
            {
                pawnBeingCrafted.Name = MakeDroidName(null);
            }

            return(pawnBeingCrafted);
        }
示例#21
0
 private Job StartOrResumeBillJob(Pawn pawn, IBillGiver giver)
 {
     for (int i = 0; i < giver.BillStack.Count; i++)
     {
         Bill bill = giver.BillStack[i];
         //Log.Message("Processing: " + bill.recipe.defName);
         if ((bill.recipe.requiredGiverWorkType != null && bill.recipe.requiredGiverWorkType != def.workType) || (Find.TickManager.TicksGame < bill.lastIngredientSearchFailTicks + ReCheckFailedBillTicksRange.RandomInRange && FloatMenuMakerMap.makingFor != pawn))
         {
             continue;
         }
         bill.lastIngredientSearchFailTicks = 0;
         if (!bill.ShouldDoNow() || !bill.PawnAllowedToStartAnew(pawn))
         {
             continue;
         }
         SkillRequirement skillRequirement = bill.recipe.FirstSkillRequirementPawnDoesntSatisfy(pawn);
         if (skillRequirement != null)
         {
             JobFailReason.Is("UnderRequiredSkill".Translate(skillRequirement.minLevel), bill.Label);
             continue;
         }
         Bill_ProductionWithUft bill_ProductionWithUft = bill as Bill_ProductionWithUft;
         if (bill_ProductionWithUft != null)
         {
             if (bill_ProductionWithUft.BoundUft != null)
             {
                 if (bill_ProductionWithUft.BoundWorker == pawn && pawn.CanReserveAndReach(bill_ProductionWithUft.BoundUft, PathEndMode.Touch, Danger.Deadly) && !bill_ProductionWithUft.BoundUft.IsForbidden(pawn))
                 {
                     return(FinishUftJob(pawn, bill_ProductionWithUft.BoundUft, bill_ProductionWithUft));
                 }
                 continue;
             }
             UnfinishedThing unfinishedThing = ClosestUnfinishedThingForBill(pawn, bill_ProductionWithUft);
             if (unfinishedThing != null)
             {
                 return(FinishUftJob(pawn, unfinishedThing, bill_ProductionWithUft));
             }
         }
         if (!TryFindBestBillIngredients(bill, pawn, (Thing)giver, chosenIngThings))
         {
             if (FloatMenuMakerMap.makingFor != pawn)
             {
                 bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame;
             }
             else
             {
                 JobFailReason.Is(MissingMaterialsTranslated, bill.Label);
             }
             chosenIngThings.Clear();
             continue;
         }
         Job haulOffJob;
         Job result = TryStartNewDoBillJob(pawn, bill, giver, chosenIngThings, out haulOffJob);
         chosenIngThings.Clear();
         if (giver is Building_СontainmentBreach building_WorkTable)
         {
             JobDef jobDef = null;
             if (bill.recipe != null &&
                 ReservationUtility.CanReserveAndReach
                     (pawn, building_WorkTable, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(pawn)
                     , 1, -1, null, false) && building_WorkTable.HasJobOnRecipe(result, out jobDef) &&
                 (result.targetB.Thing == null ||
                  building_WorkTable.innerContainer.Contains(result.targetB.Thing) ||
                  ReservationUtility.CanReserveAndReach
                      (pawn, result.targetB.Thing, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(pawn)
                      , 1, -1, null, false)) &&
                 jobDef != null)
             {
                 try
                 {
                     Log.Message(pawn + " - SUCCESS - " + result.bill.recipe.defName, true);
                 }
                 catch
                 {
                 }
                 result = new Job(jobDef, result.targetA, result.targetB)
                 {
                     targetQueueB = result.targetQueueB,
                     countQueue   = result.countQueue,
                     haulMode     = result.haulMode,
                     bill         = result.bill
                 };
                 return(result);
             }
             else
             {
                 if (result?.bill.recipe != null)
                 {
                     try
                     {
                         //Log.Message("FAIL: " + result.bill.recipe.defName, true);
                         //Log.Message("TARGET A: " + result.targetA.Thing, true);
                         //Log.Message("TARGET B: " + result.targetB.Thing, true);
                         //Log.Message("1" + (result?.RecipeDef != null).ToString());
                         //Log.Message("3" + (ReservationUtility.CanReserveAndReach
                         //(pawn, building_WorkTable, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(pawn)
                         //, 1, -1, null, false)).ToString());
                         //Log.Message("4" + building_WorkTable.HasJobOnRecipe(result, out jobDef).ToString());
                         //Log.Message("5" + (building_WorkTable.innerContainer.Contains(result.targetB.Thing) || ReservationUtility.CanReserveAndReach
                         //(pawn, result.targetB.Thing, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(pawn)
                         //, 1, -1, null, false)).ToString());
                         //Log.Message("6" + (jobDef != null).ToString());
                     }
                     catch
                     {
                     }
                     //Log.Message("----------------", true);
                 }
                 continue;
             }
         }
         return(result);
     }
     chosenIngThings.Clear();
     return(null);
 }
示例#22
0
 private Job StartOrResumeBillJob(Pawn pawn, IBillGiver giver)
 {
     for (int i = 0; i < giver.BillStack.Count; i++)
     {
         Bill bill = giver.BillStack[i];
         if (bill.recipe.requiredGiverWorkType == null || bill.recipe.requiredGiverWorkType == this.def.workType)
         {
             if (Find.TickManager.TicksGame >= bill.lastIngredientSearchFailTicks + WorkGiver_DoBill.ReCheckFailedBillTicksRange.RandomInRange || FloatMenuMakerMap.makingFor == pawn)
             {
                 bill.lastIngredientSearchFailTicks = 0;
                 if (bill.ShouldDoNow())
                 {
                     if (bill.PawnAllowedToStartAnew(pawn))
                     {
                         SkillRequirement skillRequirement = bill.recipe.FirstSkillRequirementPawnDoesntSatisfy(pawn);
                         if (skillRequirement != null)
                         {
                             JobFailReason.Is("UnderRequiredSkill".Translate(skillRequirement.minLevel), bill.Label);
                         }
                         else
                         {
                             Bill_ProductionWithUft bill_ProductionWithUft = bill as Bill_ProductionWithUft;
                             if (bill_ProductionWithUft != null)
                             {
                                 if (bill_ProductionWithUft.BoundUft != null)
                                 {
                                     if (bill_ProductionWithUft.BoundWorker != pawn || !pawn.CanReserveAndReach(bill_ProductionWithUft.BoundUft, PathEndMode.Touch, Danger.Deadly, 1, -1, null, false) || bill_ProductionWithUft.BoundUft.IsForbidden(pawn))
                                     {
                                         goto IL_1D0;
                                     }
                                     return(WorkGiver_DoBill.FinishUftJob(pawn, bill_ProductionWithUft.BoundUft, bill_ProductionWithUft));
                                 }
                                 else
                                 {
                                     UnfinishedThing unfinishedThing = WorkGiver_DoBill.ClosestUnfinishedThingForBill(pawn, bill_ProductionWithUft);
                                     if (unfinishedThing != null)
                                     {
                                         return(WorkGiver_DoBill.FinishUftJob(pawn, unfinishedThing, bill_ProductionWithUft));
                                     }
                                 }
                             }
                             if (WorkGiver_DoBill.TryFindBestBillIngredients(bill, pawn, (Thing)giver, this.chosenIngThings))
                             {
                                 Job result = this.TryStartNewDoBillJob(pawn, bill, giver);
                                 this.chosenIngThings.Clear();
                                 return(result);
                             }
                             if (FloatMenuMakerMap.makingFor != pawn)
                             {
                                 bill.lastIngredientSearchFailTicks = Find.TickManager.TicksGame;
                             }
                             else
                             {
                                 JobFailReason.Is(WorkGiver_DoBill.MissingMaterialsTranslated, bill.Label);
                             }
                             this.chosenIngThings.Clear();
                         }
                     }
                 }
             }
         }
         IL_1D0 :;
     }
     this.chosenIngThings.Clear();
     return(null);
 }
示例#23
0
    void OnGUI()
    {
        {
            switch (step)
            {
            case 0:


                if (GUILayout.Button("New Skill", GUILayout.Height(40)))
                {
                    step = 1;
                }
                else if (GUILayout.Button("Delete/Edit Skill", GUILayout.Height(40)))
                {
                    step = 2;
                }

                break;

            case 1:
                // Creando una habilidad, definimos nombre, descripcion y tipo de daño que va a hacer
                skillName        = EditorGUILayout.TextField("Skill name", skillName);
                skillDescription = EditorGUILayout.TextField("Skill description", skillDescription);
                manaCost         = EditorGUILayout.DoubleField("Mana Cost", manaCost);

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Type of skill");
                selectedSpellType = EditorGUILayout.Popup(selectedSpellType, spelltype);
                GUILayout.EndHorizontal();


                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Skill cast type");
                selectedSkillType = EditorGUILayout.Popup(selectedSkillType, skillType);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Skill effect type");
                selectedEffect = EditorGUILayout.Popup(selectedEffect, skillEffect);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Type of damage");
                selectedSkillType1 = EditorGUILayout.Popup(selectedSkillType1, skillType1);
                GUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Damage:");
                damage = EditorGUILayout.IntField(damage);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Distance:");
                distance = EditorGUILayout.IntField(distance);
                EditorGUILayout.EndHorizontal();

                /*
                 * //Mostramos previsualización del rango de la habilidad.
                 * active = EditorGUILayout.Foldout(active, "Previsual");
                 * if (distance > 0 && active)
                 * {
                 *  EditorGUILayout.BeginHorizontal(GUILayout.Width(1));
                 *
                 *  for (int i = 0; i < distance + distance + 1; i++)
                 *  {
                 *      EditorGUILayout.BeginVertical(GUILayout.Width(1));
                 *      for (int j = 0; j < distance + distance + 1; j++)
                 *      {
                 *          if (i == distance && j == distance)
                 *          {
                 *              GUI.backgroundColor = Color.white;
                 *              GUILayout.Box("", GUILayout.Width(15), GUILayout.Height(15));
                 *          }
                 *          else
                 *          {
                 *              var box = new Vector2(i - distance, j - distance);
                 *              selectColor(activeBoxes.Contains(box));
                 *              GUILayout.Box("", GUILayout.Width(15), GUILayout.Height(15));
                 *          }
                 *      }
                 *      EditorGUILayout.EndVertical();
                 *  }
                 *  EditorGUILayout.EndHorizontal();
                 * }
                 * GUI.backgroundColor = Color.white;
                 */



                //Mostramos previsualización del rango de la habilidad.
                if (GUILayout.Button("Draw area range"))
                {
                    area = 1;
                }

                if (area > 0)
                {
                    //Mostramos previsualización del rango de la habilidad.
                    active = EditorGUILayout.Foldout(active, "Previsual");

                    if (distance > 0 && active)
                    {
                        EditorGUILayout.BeginHorizontal(GUILayout.Width(1));

                        for (int i = 0; i < distance + distance + 1; i++)
                        {
                            EditorGUILayout.BeginVertical(GUILayout.Width(1));
                            for (int j = 0; j < distance + distance + 1; j++)
                            {
                                if (i == distance && j == distance)
                                {
                                    GUI.backgroundColor = Color.white;
                                    GUILayout.Box("", GUILayout.Width(15), GUILayout.Height(15));
                                }
                                else
                                {
                                    var box = new Vector2(i - distance, j - distance);
                                    selectColor(activeBoxes.Contains(box));
                                    GUILayout.Box("", GUILayout.Width(15), GUILayout.Height(15));
                                }

                                if (Event.current.type == EventType.mouseDown &&
                                    Event.current.button == 0 &&
                                    GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                                {
                                    var box = new Vector2(i - distance, j - distance);
                                    if (activeBoxes.Contains(box))
                                    {
                                        activeBoxes.Remove(box);
                                    }
                                    else
                                    {
                                        activeBoxes.Add(box);
                                    }
                                    Repaint();
                                }
                            }
                            EditorGUILayout.EndVertical();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    GUI.backgroundColor = Color.white;
                }



                //requisitos para la habilidad
                activeRequirements = EditorGUILayout.Foldout(activeRequirements, "Requirements");

                if (activeRequirements)
                {
                    if (GUILayout.Button("Add Requirement"))
                    {
                        numberRequirements = numberRequirements + 1;
                    }

                    if (numberRequirements > 0)
                    {
                        for (int i = 0; i < numberRequirements; i++)
                        {
                            EditorGUILayout.BeginHorizontal();
                            selectedRequirement[i] = EditorGUILayout.Popup(selectedRequirement[i], requirements);
                            requisitos[i]          = EditorGUILayout.TextField(requisitos[i]);

                            SkillRequirement require = new SkillRequirement(selectedRequirement[i], requisitos[i]);


                            if (GUILayout.Button("X", GUILayout.Width(30), GUILayout.Height(30)))
                            {
                                //Ha pulsado borrar boton
                                skillRequirements.Remove(require);
                                numberRequirements--;
                            }

                            if (GUILayout.Button("Save", GUILayout.Width(50), GUILayout.Height(30)))
                            {
                                skillRequirements.Add(require);
                            }



                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }


                //fin de la creación de habilidad
                EditorGUILayout.BeginHorizontal("Box");
                if (GUILayout.Button("Cancel", GUILayout.Width(100), GUILayout.Height(50)))
                {
                    setDefaults();
                    step = 0;
                }
                else if (GUILayout.Button("Create Skill", GUILayout.Width(100), GUILayout.Height(50)))
                {
                    // Mensaje de salvado! -> aceptar -> step 1
                    saveSkill();
                    setDefaults();
                    step = 0;
                }


                break;


            //SELECCIONA EDITAR UNA HABILIDAD
            case 2:
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name");
                EditorGUILayout.LabelField("Description");
                EditorGUILayout.LabelField("Type of skill");
                EditorGUILayout.LabelField("Skill cast type");
                EditorGUILayout.LabelField("Spell Effect");
                EditorGUILayout.LabelField("Damage");
                EditorGUILayout.LabelField("Distance");
                EditorGUILayout.EndHorizontal();

                Skill[] savedSkills = SkillsDB.Instance.getSavedSkills();
                selectedSkillTypes  = new int[savedSkills.Length];
                selectedCastTypes   = new int[savedSkills.Length];
                selectedSpellEffect = new int[savedSkills.Length];

                int[,] selectedRequirements       = new int[savedSkills.Length, MAX_REQUIREMENTS];
                string[,] descriptionRequirements = new string[savedSkills.Length, MAX_REQUIREMENTS];
                for (int i = 0; i < savedSkills.Length; i++)
                {
                    Skill skill = savedSkills[i];
                    EditorGUILayout.BeginHorizontal();
                    //el nombre no se puede modificar porque es la clave de la base de datos
                    EditorGUILayout.LabelField(skill.getName());

                    //changing the description
                    string skillDescription1 = EditorGUILayout.TextField(skill.getDescription());
                    skill.changeDescription(skillDescription1);

                    //changing type of skill type
                    selectedSkillTypes[i] = EditorGUILayout.Popup(skill.getTypeCast(), spelltype);
                    skill.changeTypeSkill(selectedSkillTypes[i]);

                    //changing casting character
                    selectedCastTypes[i] = EditorGUILayout.Popup(skill.getCastCharacter(), skillType);
                    skill.changeCastSkill(selectedCastTypes[i]);

                    //changing the spell effect:
                    selectedSpellEffect[i] = EditorGUILayout.Popup(skill.getSkillEffect(), skillEffect);
                    skill.changeSkillEffect(selectedSpellEffect[i]);


                    //changing amount of damage
                    int damage1 = EditorGUILayout.IntField(skill.getDamage());
                    skill.changeSkillDamage(damage1);
                    //changing distance
                    int distance1 = EditorGUILayout.IntField(skill.getDistance());
                    skill.changeDistance(distance1);



                    //requisitos para la habilidad
                    EditorGUILayout.BeginVertical();
                    activeRequirements = EditorGUILayout.Foldout(activeRequirements, "Requirements");


                    if (activeRequirements)
                    {
                        if (skill.numberRequirements() > 0)
                        {
                            for (int j = 0; j < skill.numberRequirements(); j++)
                            {
                                EditorGUILayout.BeginHorizontal();

                                selectedRequirements[i, j] = skill.getTypeRQ(j);
                                selectedRequirements[i, j] = EditorGUILayout.Popup(selectedRequirements[i, j], requirements);
                                skill.changeTypeRQ(selectedRequirements[i, j], j);

                                descriptionRequirements[i, j] = skill.getDescRQ(j);
                                descriptionRequirements[i, j] = EditorGUILayout.TextField(skill.getDescRQ(j));
                                skill.changeDescRQ(descriptionRequirements[i, j], j);

                                SkillRequirement require = new SkillRequirement(skill.getTypeRQ(j), skill.getDescRQ(j));

                                if (GUILayout.Button("X", GUILayout.Width(30), GUILayout.Height(30)))
                                {
                                    skill.removeRQ(require);
                                    numberRequirements--;
                                    SkillsDB.Instance.updateSkill(skill);
                                }

                                EditorGUILayout.EndHorizontal();
                            }
                        }
                    }


                    SkillsDB.Instance.updateSkill(skill);


                    EditorGUILayout.EndVertical();

                    if (GUILayout.Button("X", GUILayout.Width(30), GUILayout.Height(30)))
                    {
                        //Ha pulsado borrar boton
                        this.skills.deleteSkill(skill);
                        SkillsDB.Instance.deleteSkill(skill);
                    }


                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.BeginHorizontal("Box");
                if (GUILayout.Button("Back to Menu", GUILayout.Width(100), GUILayout.Height(50)))
                {
                    setDefaults();
                    step = 0;
                }

                break;

            default:
                break;
            }
        }
    }
示例#24
0
        // Token: 0x06000037 RID: 55 RVA: 0x00003458 File Offset: 0x00001658
        public static Pawn MakeDroidTemplate(ThingDef raceDef, PawnKindDef pawnKindDef, Faction faction, Map map, List <SkillRequirement> skills = null, int defaultSkillLevel = 6)
        {
            Pawn pawn2 = (Pawn)ThingMaker.MakeThing(raceDef, null);
            bool flag  = pawn2 == null;
            Pawn result;

            if (flag)
            {
                result = null;
            }
            else
            {
                pawn2.kindDef = pawnKindDef;
                pawn2.SetFactionDirect(faction);
                PawnComponentsUtility.CreateInitialComponents(pawn2);
                pawn2.gender = Gender.Male;
                pawn2.needs.SetInitialLevels();
                bool humanlike = pawn2.RaceProps.Humanlike;
                if (humanlike)
                {
                    pawn2.story.melanin   = 1f;
                    pawn2.story.crownType = CrownType.Average;
                    pawn2.story.hairColor = new Color(1f, 1f, 1f, 1f);
                    pawn2.story.hairDef   = DefDatabase <HairDef> .GetNamed("Shaved", true);

                    pawn2.story.bodyType = BodyType.Thin;
                    PortraitsCache.SetDirty(pawn2);
                    Backstory childhood = null;
                    BackstoryDatabase.TryGetWithIdentifier("ChJAndroid_Droid", out childhood);
                    pawn2.story.childhood = childhood;
                    bool flag2 = skills == null || skills.Count <= 0;
                    if (flag2)
                    {
                        List <SkillDef> allDefsListForReading = DefDatabase <SkillDef> .AllDefsListForReading;
                        for (int i = 0; i < allDefsListForReading.Count; i++)
                        {
                            SkillDef    skillDef2 = allDefsListForReading[i];
                            SkillRecord skill     = pawn2.skills.GetSkill(skillDef2);
                            bool        flag3     = skillDef2 == SkillDefOf.Shooting || skillDef2 == SkillDefOf.Melee || skillDef2 == SkillDefOf.Mining || skillDef2 == SkillDefOf.Growing;
                            if (flag3)
                            {
                                skill.Level = 8;
                            }
                            else
                            {
                                bool flag4 = skillDef2 == SkillDefOf.Medicine || skillDef2 == SkillDefOf.Crafting || skillDef2 == SkillDefOf.Cooking;
                                if (flag4)
                                {
                                    skill.Level = 4;
                                }
                                else
                                {
                                    skill.Level = 6;
                                }
                            }
                            skill.passion = Passion.None;
                        }
                    }
                    else
                    {
                        List <SkillDef> allDefsListForReading2 = DefDatabase <SkillDef> .AllDefsListForReading;
                        for (int j = 0; j < allDefsListForReading2.Count; j++)
                        {
                            SkillDef         skillDef         = allDefsListForReading2[j];
                            SkillRecord      skill2           = pawn2.skills.GetSkill(skillDef);
                            SkillRequirement skillRequirement = skills.First((SkillRequirement sr) => sr.skill == skillDef);
                            bool             flag5            = skillRequirement != null;
                            if (flag5)
                            {
                                skill2.Level = skillRequirement.minLevel;
                            }
                            else
                            {
                                skill2.Level = defaultSkillLevel;
                            }
                            skill2.passion = Passion.None;
                        }
                    }
                }
                bool flag6 = pawn2.workSettings != null;
                if (flag6)
                {
                    pawn2.workSettings.EnableAndInitialize();
                }
                bool flag7 = map != null;
                if (flag7)
                {
                    IEnumerable <Name> enumerable = from pawn in map.mapPawns.FreeColonists
                                                    select pawn.Name;
                    bool flag8 = enumerable != null;
                    if (flag8)
                    {
                        int    num      = enumerable.Count((Name name) => name.ToStringShort.ToLower().StartsWith("droid"));
                        string nickName = "Droid " + num;
                        pawn2.Name = DroidUtility.MakeDroidName(nickName);
                    }
                    else
                    {
                        pawn2.Name = DroidUtility.MakeDroidName(null);
                    }
                }
                else
                {
                    pawn2.Name = DroidUtility.MakeDroidName(null);
                }
                result = pawn2;
            }
            return(result);
        }
        static StaticConstructorClass()
        {
            var recipes = new List <RecipeDef>();

            // Go through each minifiable building's def that is buildable by the player, requires materials, doesn't already have a recipeMaker
            foreach (ThingDef buildingDef in DefDatabase <ThingDef> .AllDefs.Where(d => d.IsBuildingArtificial && d.Minifiable && d.BuildableByPlayer && (d.MadeFromStuff || !d.costList.NullOrEmpty()) && d.recipeMaker == null))
            {
                // Create the new Recipe Def
                var newRecipe = new RecipeDef()
                {
                    defName            = $"{GeneratedRecipeDefPrefix}_{buildingDef.defName}",
                    modContentPack     = CT_RecipeDefOf.BaseCarpentersTableRecipe.modContentPack,
                    label              = $"[{buildingDef.designationCategory.label.ToUpper()}] - {"RecipeMake".Translate(buildingDef.label).CapitalizeFirst()}",
                    jobString          = "RecipeMakeJobString".Translate(buildingDef.label),
                    workSpeedStat      = StatDefOf.ConstructionSpeed,
                    workSkill          = SkillDefOf.Construction,
                    unfinishedThingDef = CT_ThingDefOf.UnfinishedBuilding,
                    recipeUsers        = new List <ThingDef>()
                    {
                        CT_ThingDefOf.TableCarpenter
                    },
                    defaultIngredientFilter = CT_RecipeDefOf.BaseCarpentersTableRecipe.defaultIngredientFilter,
                    effectWorking           = EffecterDefOf.ConstructMetal,
                    soundWorking            = SoundDefOf.Building_Complete,
                    factionPrerequisiteTags = DetermineRecipeFactionPrerequisiteTags(buildingDef.minTechLevelToBuild, buildingDef.maxTechLevelToBuild)
                };

                // Add construction skill requirement if there is any
                if (buildingDef.constructionSkillPrerequisite > 0)
                {
                    var constructionRequirement = new SkillRequirement();
                    constructionRequirement.skill    = SkillDefOf.Construction;
                    constructionRequirement.minLevel = buildingDef.constructionSkillPrerequisite;
                    newRecipe.skillRequirements      = new List <SkillRequirement>()
                    {
                        constructionRequirement
                    };
                }

                // Add ingredient count for building's stuff if applicable
                if (buildingDef.MadeFromStuff)
                {
                    var stuffIngredientCount = new IngredientCount();
                    stuffIngredientCount.SetBaseCount(buildingDef.costStuffCount);
                    stuffIngredientCount.filter.SetAllowAllWhoCanMake(buildingDef);
                    newRecipe.ingredients.Add(stuffIngredientCount);
                    newRecipe.fixedIngredientFilter.SetAllowAllWhoCanMake(buildingDef);
                    newRecipe.productHasIngredientStuff = true;
                }

                // Add ingredient counts for other required materials if applicable
                if (!buildingDef.costList.NullOrEmpty())
                {
                    foreach (ThingDefCountClass normalMaterialCost in buildingDef.costList)
                    {
                        var materialIngredientCount = new IngredientCount();
                        materialIngredientCount.SetBaseCount(normalMaterialCost.count * normalMaterialCost.thingDef.VolumePerUnit);
                        materialIngredientCount.filter.SetAllow(normalMaterialCost.thingDef, true);
                        newRecipe.ingredients.Add(materialIngredientCount);
                    }
                }

                // Add building as the recipe def's product
                newRecipe.products.Add(new ThingDefCountClass(buildingDef, 1));

                // Add the new recipe def to the list of recipes
                recipes.Add(newRecipe);
            }

            // Sort the list of recipes alphabetically and add to the database
            recipes.Sort((d1, d2) => d1.label.CompareTo(d2.label));
            DefDatabase <RecipeDef> .Add(recipes);
        }
        public RecipeWidget(RecipeDef d, DefType type) : base(d, type)
        {
            if (base.Def.skillRequirements == null)
            {
                base.Def.skillRequirements = new List <SkillRequirement>();
            }
            if (base.Def.forceHiddenSpecialFilters == null)
            {
                base.Def.forceHiddenSpecialFilters = new List <SpecialThingFilterDef>();
            }
            if (base.Def.recipeUsers == null)
            {
                base.Def.recipeUsers = new List <ThingDef>();
            }
            if (base.Def.appliedOnFixedBodyParts == null)
            {
                base.Def.appliedOnFixedBodyParts = new List <BodyPartDef>();
            }

            this.inputWidgets = new List <IInputWidget>()
            {
                new FloatInputWidget <RecipeDef>(base.Def, "Work Amount", (RecipeDef def) => d.workAmount, (RecipeDef def, float f) => d.workAmount = f),
                new BoolInputWidget <RecipeDef>(base.Def, "Allow Mixing Ingredients", (RecipeDef def) => d.allowMixingIngredients, (RecipeDef def, bool b) => d.allowMixingIngredients = b),
                new BoolInputWidget <RecipeDef>(base.Def, "Auto Strip Corpses", (RecipeDef def) => d.autoStripCorpses, (RecipeDef def, bool b) => d.autoStripCorpses = b),
                new BoolInputWidget <RecipeDef>(base.Def, "Product Has Ingredient Stuff", (RecipeDef def) => d.productHasIngredientStuff, (RecipeDef def, bool b) => d.productHasIngredientStuff = b),
                new IntInputWidget <RecipeDef>(base.Def, "Target Count Adjustment", (RecipeDef def) => d.targetCountAdjustment, (RecipeDef def, int i) => d.targetCountAdjustment   = i),
                new FloatInputWidget <RecipeDef>(base.Def, "Work Skill Learn Factor", (RecipeDef def) => d.workSkillLearnFactor, (RecipeDef def, float f) => d.workSkillLearnFactor = f),
                new BoolInputWidget <RecipeDef>(base.Def, "Hide Body Part Names", (RecipeDef def) => d.hideBodyPartNames, (RecipeDef def, bool b) => d.hideBodyPartNames            = b),
                new BoolInputWidget <RecipeDef>(base.Def, "Is Violation", (RecipeDef def) => d.isViolation, (RecipeDef def, bool b) => d.isViolation = b),
                new FloatInputWidget <RecipeDef>(base.Def, "Surgery Success Chance Factor", (RecipeDef def) => d.surgerySuccessChanceFactor, (RecipeDef def, float f) => d.surgerySuccessChanceFactor  = f),
                new FloatInputWidget <RecipeDef>(base.Def, "Death On Failed Surgery Chance", (RecipeDef def) => d.deathOnFailedSurgeryChance, (RecipeDef def, float f) => d.deathOnFailedSurgeryChance = f),
                new BoolInputWidget <RecipeDef>(base.Def, "Targets Body Part", (RecipeDef def) => d.targetsBodyPart, (RecipeDef def, bool b) => d.targetsBodyPart = b),
                new BoolInputWidget <RecipeDef>(base.Def, "Anesthetize", (RecipeDef def) => d.anesthetize, (RecipeDef def, bool b) => d.anesthetize = b),
                new BoolInputWidget <RecipeDef>(base.Def, "Dont Show If Any Ingredient Missing", (RecipeDef def) => d.dontShowIfAnyIngredientMissing, (RecipeDef def, bool b) => d.dontShowIfAnyIngredientMissing = b),
                new DefInputWidget <RecipeDef, ResearchProjectDef>(base.Def, "Research Prerequisite", 200, def => def.researchPrerequisite, (def, v) => def.researchPrerequisite = v, true),
                new DefInputWidget <RecipeDef, WorkTypeDef>(base.Def, "Required Giver Work Type", 200, def => def.requiredGiverWorkType, (def, v) => def.requiredGiverWorkType   = v, true),
                new DefInputWidget <RecipeDef, ThingDef>(base.Def, "Unfinished Thing Def", 200, def => def.unfinishedThingDef, (def, v) => def.unfinishedThingDef = v, true),
                new DefInputWidget <RecipeDef, SoundDef>(base.Def, "Sound Working", 200, def => def.soundWorking, (def, v) => def.soundWorking      = v, true),
                new DefInputWidget <RecipeDef, StatDef>(base.Def, "Work Speed Stat", 200, def => def.workSpeedStat, (def, v) => def.workSpeedStat   = v, true),
                new DefInputWidget <RecipeDef, StatDef>(base.Def, "Efficiency Stat", 200, def => def.efficiencyStat, (def, v) => def.efficiencyStat = v, true),
                new DefInputWidget <RecipeDef, StatDef>(base.Def, "Work Table Efficiency Stat", 200, def => def.workTableEfficiencyStat, (def, v) => def.workTableEfficiencyStat = v, true),
                new DefInputWidget <RecipeDef, StatDef>(base.Def, "Work Table Speed Stat", 200, def => def.workTableSpeedStat, (def, v) => def.workTableSpeedStat = v, true),
                //new DefInputWidget<RecipeDef, HediffDef>(base.Def, "Adds Hediff", 200, def => def.addsHediff, (def, v) => def.addsHediff = v, true),
                //new DefInputWidget<RecipeDef, HediffDef>(base.Def, "Removes Hediff", 200, def => def.removesHediff, (def, v) => def.removesHediff = v, true),
                new DefInputWidget <RecipeDef, SkillDef>(base.Def, "Work Skill", 200, def => def.workSkill, (def, v) => def.workSkill = v, true),
                new DefInputWidget <RecipeDef, EffecterDef>(base.Def, "Effect Working", 200, def => def.effectWorking, (def, v) => def.effectWorking = v, true),
            };

            this.specialProducts = new PlusMinusArgs <SpecialProductType>()
            {
                allItems       = Enum.GetValues(typeof(SpecialProductType)).OfType <SpecialProductType>().ToList(),
                beingUsed      = () => base.Def.specialProducts,
                onAdd          = (spt) => base.Def.specialProducts = Util.AddTo(base.Def.specialProducts, spt),
                onRemove       = (spt) => base.Def.specialProducts = Util.RemoveFrom(base.Def.specialProducts, spt, true),
                getDisplayName = (spt) => spt.ToString()
            };

            this.forceHiddenSpecialFilters = new PlusMinusArgs <SpecialThingFilterDef>()
            {
                allItems       = DefDatabase <SpecialThingFilterDef> .AllDefs,
                beingUsed      = () => base.Def.forceHiddenSpecialFilters,
                onAdd          = (def) => base.Def.forceHiddenSpecialFilters = Util.AddTo(base.Def.forceHiddenSpecialFilters, def),
                onRemove       = (def) => base.Def.forceHiddenSpecialFilters = Util.RemoveFrom(base.Def.forceHiddenSpecialFilters, def, false),
                getDisplayName = (def) => def.label
            };

            this.recipeUsers = new PlusMinusArgs <ThingDef>()
            {
                allItems       = DefDatabase <ThingDef> .AllDefs,
                beingUsed      = () => base.Def.recipeUsers,
                onAdd          = (def) => base.Def.recipeUsers.Add(def),
                onRemove       = (def) => base.Def.recipeUsers.Remove(def),
                getDisplayName = (def) => def.label
            };

            this.appliedOnFixedBodyParts = new PlusMinusArgs <BodyPartDef>()
            {
                allItems       = DefDatabase <BodyPartDef> .AllDefs,
                beingUsed      = () => base.Def.appliedOnFixedBodyParts,
                onAdd          = (def) => base.Def.appliedOnFixedBodyParts = Util.AddTo(base.Def.appliedOnFixedBodyParts, def),
                onRemove       = (def) => base.Def.appliedOnFixedBodyParts = Util.RemoveFrom(base.Def.appliedOnFixedBodyParts, def, false),
                getDisplayName = (def) => def.label
            };

            this.skillRequirementsPlusMinusArgs = new PlusMinusArgs <SkillDef>()
            {
                allItems    = DefDatabase <SkillDef> .AllDefs,
                isBeingUsed = delegate(SkillDef sd)
                {
                    foreach (var v in base.Def.skillRequirements)
                    {
                        if (v.skill == sd)
                        {
                            return(true);
                        }
                    }
                    return(false);
                },
                onAdd = delegate(SkillDef sd)
                {
                    SkillRequirement sr = new SkillRequirement()
                    {
                        skill = sd, minLevel = 0
                    };
                    base.Def.skillRequirements = Util.AddTo(base.Def.skillRequirements, sr);
                    this.skillRequirements.Add(this.CreateSkillRequirements(sr));
                },
                onRemove = delegate(SkillDef sd)
                {
                    base.Def.skillRequirements.RemoveAll((sr) => sr.skill == sd);
                    this.skillRequirements.RemoveAll((sr) => sr.Parent.skill == sd);
                },
                getDisplayName = (en) => en.ToString()
            };


            /*this.productsPlusMinusArgs = new PlusMinusArgs<ThingDef>()
             * {
             *      allItems = DefDatabase<ThingDef>.AllDefs,
             *      isBeingUsed = delegate (ThingDef td)
             *      {
             *              foreach (var v in base.Def.products)
             *                      if (v.thingDef == td)
             *                              return true;
             *              return false;
             *      },
             *      onAdd = delegate (ThingDef td)
             *      {
             *              ThingDefCountClass tdc = new ThingDefCountClass(td, 0);
             *              base.Def.products = Util.AddAndCreateIfNeeded(base.Def.products, tdc);
             *              this.products.Add(this.CreateThingDefCountClass(tdc));
             *      },
             *      onRemove = delegate (ThingDef def)
             *      {
             *              base.Def.products.RemoveAll((tdc) => tdc.thingDef == def);
             *              base.Def.products = Util.NullIfNeeded(base.Def.products);
             *              this.products.RemoveAll((input) => input.Parent.thingDef == def);
             *      },
             *      getDisplayName = (en) => en.ToString()
             * };*/

            this.Rebuild();
        }
示例#27
0
        public async Task <ActionResult> SkillCreatePartial(SkillCreatePostModel result)
        {
            //Parse the data and configure a Skill model
            SkillRequirement model = new SkillRequirement();

            foreach (TraitRank rank in result.Selection)
            {
                model.GetType().GetProperty(rank.PropertyName).SetValue(model, rank.Rank);
            }
            model.Id = Guid.NewGuid();

            //Create a new Db context
            ApplicationDbContext context = new ApplicationDbContext();

            //Store the model
            context.SkillRequirements.Add(model);
            await context.SaveChangesAsync();

            //Update the appropriate account
            switch (result.CreatorType)
            {
            case (SkillCreatorType.SeekerAccount):
            {
                SeekerAccount account = (from s in context.SeekerAccounts
                                         where s.Id == result.CreatorId
                                         select s).FirstOrDefault();
                if (account == null)
                {
                    break;
                }

                context.SeekerAccounts.Attach(account);
                var entry = context.Entry(account);
                entry.Reference(e => e.SkillRequirement).CurrentValue = model;
                await context.SaveChangesAsync();

                return(RedirectToAction("Index", "Seeker", new { area = "" }));
            }

            case (SkillCreatorType.JobPosting):
            {
                JobPosting account = (from s in context.JobPostings
                                      where s.Id == result.CreatorId
                                      select s).FirstOrDefault();
                if (account == null)
                {
                    break;
                }

                context.JobPostings.Attach(account);
                var entry = context.Entry(account);
                entry.Reference(e => e.SkillRequirement).CurrentValue = model;
                await context.SaveChangesAsync();

                break;
            }

            default:
            {
                break;
            }
            }

            return(null);
        }
示例#28
0
        // GET: JobsPage
        public ActionResult Index()
        {
            string id   = User.Identity.GetUserId();
            var    user = (from s in db.Users
                           where s.Id == id
                           select s).FirstOrDefault();

            if (user != null)
            {
                if (user.Role == Role.Seeker &&
                    user.SeekerAccount != null)
                {
                    SeekerAccount account = user.SeekerAccount;
                    if (account.CultureId != null &&
                        account.SkillRequirementId != null)
                    {
                        Culture culture = (from s in db.Cultures
                                           where s.Id == account.CultureId
                                           select s).FirstOrDefault();

                        SkillRequirement skill = (from sk in db.SkillRequirements
                                                  where sk.Id == account.SkillRequirementId
                                                  select sk).FirstOrDefault();

                        List <JobPosting> jobs = (from j in db.JobPostings
                                                  where j.Culture != null &&
                                                  j.SkillRequirement != null
                                                  select j).ToList();

                        int      cultureSize = culture.MapSize;
                        double[] cultureMap  = culture.Map;

                        int      skillSize = skill.MapSize;
                        double[] skillMap  = skill.Map;

                        KDTree <JobPosting> cultureTree = new KDTree <JobPosting>(cultureSize);
                        KDTree <JobPosting> skillTree   = new KDTree <JobPosting>(skillSize);

                        foreach (JobPosting job in jobs)
                        {
                            Culture jobCulture = (from c in db.Cultures
                                                  where c.Id == job.CultureId
                                                  select c).FirstOrDefault();
                            if (culture == null)
                            {
                                continue;
                            }

                            cultureTree.AddPoint(jobCulture.Map, job);
                        }

                        List <JobPosting> results = new List <JobPosting>();

                        var closest = cultureTree.NearestNeighbors(cultureMap, 5);
                        for (; closest.MoveNext();)
                        {
                            SkillRequirement jobSkill = (from js in db.SkillRequirements
                                                         where js.Id == closest.Current.SkillRequirementId
                                                         select js).FirstOrDefault();
                            if (jobSkill == null)
                            {
                                continue;
                            }
                            if (closest.CurrentDistance < 500)
                            {
                                skillTree.AddPoint(jobSkill.Map, closest.Current);
                            }
                        }

                        var sorted = skillTree.NearestNeighbors(skillMap, 5);
                        for (; sorted.MoveNext();)
                        {
                            results.Add(sorted.Current);
                        }

                        return(View(results));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Seeker"));
                    }
                }
                else if (user.Role == Role.Poster)
                {
                    var jobs = (from j in db.JobPostings
                                where j.UserId.Equals(user.Id)
                                select j).ToList();
                    return(View("JobListPartialView", jobs));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
            var jobPostings = db.JobPostings.Include(j => j.Culture).Include(j => j.SkillRequirement).Include(j => j.User);

            return(View(jobPostings.ToList()));
        }