コード例 #1
0
ファイル: CompBarracks.cs プロジェクト: AKreedz/ra2inRW
        private Pawn getTanya()
        {
            PawnGenerationRequest request = new PawnGenerationRequest(DefDatabase <PawnKindDef> .GetNamed("ra2_AlliedTanya", true), Faction.OfPlayer, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, true, 1f, false, true, true, false, false, false, false, null, null, null, null, null, Gender.Female, null, null);
            Pawn item = PawnGenerator.GeneratePawn(request);

            Pawn_StoryTracker ps   = item.story;
            HairDef           hair = DefDatabase <HairDef> .GetNamed("Curly");

            ps.childhood        = null;
            ps.adulthood        = null;
            ps.traits.allTraits = new List <Trait>();
            ps.traits.GainTrait(new Trait(DefDatabase <TraitDef> .GetNamed("ra2_MakeSoldier", true)));
            ps.traits.GainTrait(new Trait(TraitDefOf.Psychopath));
            Pawn_WorkSettings pws = item.workSettings;

            pws.DisableAll();

            NameTriple triple = NameTriple.FromString(item.kindDef.label);

            triple.ResolveMissingPieces("Adams".Translate());
            item.Name = triple;

            Pawn_SkillTracker skt = item.skills;

            foreach (SkillRecord sr in skt.skills)
            {
                sr.Level = 20;
            }

            item.inventory.DestroyAll();
            ps.bodyType  = BodyTypeDefOf.Female;
            ps.hairDef   = hair;
            ps.hairColor = new UnityEngine.Color(1, 0.8f, 0);

            //st.SkinColor = new UnityEngine.Color(0.98f,0.76f,0.71f);
            ps.melanin = 0f;


            Pawn_EquipmentTracker pe = item.equipment;

            pe.Remove(pe.Primary);
            pe.AddEquipment((ThingWithComps)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Gun_Tanya", true)));


            //item.story = st;
            return(item);
        }
コード例 #2
0
ファイル: RealmPawn.cs プロジェクト: mitchfizz05/Phi
        public Pawn FromRealmPawn(RealmData realmData)
        {
            // This code is mainly a copy/paste of what happens in
            // PawnGenerator.DoGenerateNakedPawn()
            PawnKindDef kindDef = DefDatabase <PawnKindDef> .GetNamed(kindDefName);

            Pawn pawn = (Pawn)ThingMaker.MakeThing(kindDef.race);

            pawn.kindDef = kindDef;
            pawn.SetFactionDirect(Faction.OfPlayer);
            PawnComponentsUtility.CreateInitialComponents(pawn);
            pawn.gender = gender;

            // What is done in GenerateRandomAge()
            pawn.ageTracker.AgeBiologicalTicks    = ageBiologicalTicks;
            pawn.ageTracker.AgeChronologicalTicks = ageChronologicalTicks;

            // Ignored SetInitialLevels()
            // Ignored GenerateInitialHediffs()
            // Ignored GeneratePawnRelations()

            Pawn_StoryTracker story = pawn.story;

            story.melanin   = melanin;
            story.crownType = crownType;
            story.hairColor = new Color(hairColor[0], hairColor[1], hairColor[2], hairColor[3]);

            // What is done in GiveAppropriateBio()
            Name nameObj = pawn.Name;

            switch (name.Count())
            {
            case 1:
                nameObj = new NameSingle(name[0]);
                break;

            case 2:
                nameObj = new NameTriple(name[0], name[1], name[1]);
                break;

            case 3:
                nameObj = new NameTriple(name[0], name[1], name[2]);
                break;
            }
            pawn.Name = nameObj;

            if (!BackstoryDatabase.TryGetWithIdentifier(childhoodKey, out story.childhood))
            {
                throw new Exception(string.Format("Couldn't find backstory '{0}'", childhoodKey));
            }
            if (!BackstoryDatabase.TryGetWithIdentifier(adulthoodKey, out story.adulthood))
            {
                throw new Exception(string.Format("Couldn't find backstory '{0}'", adulthoodKey));
            }

            story.hairDef = DefDatabase <HairDef> .GetNamed(hairDefName);

            // Done in GiveRandomTraits()
            foreach (RealmTrait trait in traits)
            {
                TraitDef traitDef = DefDatabase <TraitDef> .GetNamed(trait.traitDefName);

                story.traits.GainTrait(new Trait(traitDef, trait.degree));
            }

            // We attribute the skills level
            foreach (RealmSkillRecord rec in skills.AsEnumerable())
            {
                SkillDef skillDef = DefDatabase <SkillDef> .AllDefs.First((def) => def.label == rec.skillDefLabel);

                SkillRecord skill = pawn.skills.GetSkill(skillDef);
                skill.Level   = rec.level;
                skill.passion = rec.passion;
            }

            pawn.workSettings.EnableAndInitialize();

            // Once we've generated a new solid pawn, we generate the gear of it
            // GenerateStartingApparelFor()
            Pawn_ApparelTracker apparelTracker = pawn.apparel;

            foreach (RealmThing realmThing in apparels)
            {
                Apparel apparel = (Apparel)realmData.FromRealmThing(realmThing);

                apparelTracker.Wear(apparel);
            }

            // TryGenerateWeaponFor()
            Pawn_EquipmentTracker equipmentTracker = pawn.equipment;

            foreach (RealmThing realmThing in equipments)
            {
                ThingWithComps thingWithComps = (ThingWithComps)realmData.FromRealmThing(realmThing);

                equipmentTracker.AddEquipment(thingWithComps);
            }

            // GenerateInventoryFor()
            Pawn_InventoryTracker inventoryTracker = pawn.inventory;

            foreach (RealmThing realmThing in inventory)
            {
                Thing thing = realmData.FromRealmThing(realmThing);

                inventoryTracker.innerContainer.TryAdd(thing);
            }

            return(pawn);
        }
コード例 #3
0
        public override void CompPostTick(ref float severityAdjustment)
        {
            base.CompPostTick(ref severityAdjustment);



            {
                Pawn_EquipmentTracker pe = base.Pawn.equipment;
                Pawn_ApparelTracker   pa = base.Pawn.apparel;
                if (base.Pawn.Faction == Faction.OfPlayer)
                {
                    if (base.Pawn.kindDef.defName == "ra2_AlliedTanya")
                    {
                    }
                    else if (pe.Primary == null || pe.Primary.def != getDefaultGun(base.Pawn.kindDef.defName))
                    {
                        pe.Remove(pe.Primary);
                        pe.AddEquipment((ThingWithComps)ThingMaker.MakeThing(getDefaultGun(base.Pawn.kindDef.defName)));
                    }

                    if (base.Pawn.kindDef.defName == "ra2_AlliedChrono")
                    {
                        bool hasHat = false;
                        foreach (Apparel ap in base.Pawn.apparel.WornApparel)
                        {
                            if (ap.def.defName == "ra2_Hat_Chrono")
                            {
                                hasHat = true;
                                break;
                            }
                        }
                        if (!hasHat)
                        {
                            base.Pawn.apparel.Wear((Apparel)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Hat_Chrono", true)));
                        }
                    }

                    if (pa.WornApparel == null)
                    {
                        pa.Wear((Apparel)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Belt", true)));
                    }

                    bool hasBelt = false;
                    foreach (Apparel ap in pa.WornApparel)
                    {
                        if (ap.def.defName.Equals("ra2_Belt"))
                        {
                            hasBelt = true;
                            break;
                        }
                    }
                    if (!hasBelt)
                    {
                        pa.Wear((Apparel)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Belt", true)));
                    }
                }
            }

            if (base.Pawn.apparel.WornApparel.Find(x => x.TryGetComp <CompDownToDie>() != null) == null)
            {
                base.Pawn.health.RemoveHediff(base.parent);
            }


            if ((base.Pawn.Downed && !base.Pawn.Dead) || base.Pawn.IsPrisoner)
            {
                //Apparel ap = base.Pawn.apparel.WornApparel.Find(x => x.TryGetComp<CompDownToDie>() != null);
                //ap.Destroy(DestroyMode.Vanish);
                //base.Pawn.apparel.Remove(ap);
                DamageInfo dinfo    = new DamageInfo(DamageDefOf.Crush, 100, 0, 0, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown);
                HediffSet  bodypart = base.Pawn.health.hediffSet;
                foreach (BodyPartRecord record in bodypart.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
                {
                    if (record.def.tags.Contains(BodyPartTagDefOf.BloodPumpingSource))
                    {
                        dinfo.SetHitPart(record);
                        break;
                    }
                }

                base.Pawn.TakeDamage(dinfo);
            }
        }
コード例 #4
0
        public override IEnumerable <Gizmo> GetWornGizmos()
        {
            //  base.GetWornGizmos();
            if (Find.Selector.SingleSelectedThing != base.Wearer)
            {
                yield break;
            }

            //tanya
            if (base.Wearer.kindDef.defName == "ra2_AlliedTanya")
            {
                yield return new Command_Action
                       {
                           icon          = ContentFinder <Texture2D> .Get(!tanyaHandWeapon()?DefDatabase <ThingDef> .GetNamed("ra2_Gun_Tanya", true).graphicData.texPath : DefDatabase <ThingDef> .GetNamed("ra2_TanyaC4Bomb", true).graphicData.texPath, true),
                           defaultLabel  = "TanyaChangeWeapon".Translate(),
                           activateSound = DefDatabase <SoundDef> .GetNamed("ra2_tanya_select", true),
                           action        = delegate
                           {
                               Pawn_EquipmentTracker pe = base.Wearer.equipment;
                               ThingDef tempDef         = DefDatabase <ThingDef> .GetNamed(tanyaHandWeapon()? "ra2_TanyaC4Bomb" : "ra2_Gun_Tanya", true);

                               pe.Remove(pe.Primary);
                               pe.AddEquipment((ThingWithComps)ThingMaker.MakeThing(tempDef));
                           }
                       }
            }
            ;

            //chrono
            TargetingParameters tp = new TargetingParameters();

            tp.canTargetBuildings = false;
            tp.canTargetFires     = false;
            tp.canTargetLocations = true;
            tp.canTargetPawns     = false;
            tp.canTargetSelf      = false;


            if (base.Wearer.kindDef.defName == "ra2_AlliedChrono")
            {
                yield return new Command_TargetPlus
                       {
                           icon            = ContentFinder <Texture2D> .Get("ra2/Things/Misc/ChTeleport", true),
                           defaultLabel    = "ChronoTeleport".Translate(),
                           activateSound   = DefDatabase <SoundDef> .GetNamed("ra2_Chrono_select", true),
                           targetingParams = tp,
                           hotKey          = KeyBindingDefOf.Misc4,
                           disabled        = !base.Wearer.drafter.Drafted || base.Wearer.stances.stunner.Stunned,
                           aimIcon         = ContentFinder <Texture2D> .Get("ra2/Things/Misc/ChTeleport", true),
                           action          = delegate(LocalTargetInfo target)
                           {
                               Pawn casterPawn = base.Wearer;
                               Map  map        = base.Wearer.Map;

                               IEnumerable <Thing> thi = map.thingGrid.ThingsAt(target.Cell);
                               foreach (Thing th in thi)
                               {
                                   if (th is Building)
                                   {
                                       Messages.Message("ChronoNotToBuild".Translate(), MessageTypeDefOf.RejectInput);
                                       return;
                                   }
                               }

                               MoteMaker.ThrowExplosionCell(target.Cell, map, ThingDefOf.Mote_ExplosionFlash, new UnityEngine.Color(1, 1, 1));
                               // MoteMaker.ThrowExplosionCell(target.Cell, map, ThingDefOf.Mote_ExplosionFlash, new UnityEngine.Color(1,1,1));
                               for (int asd = 0; asd < 60; asd++)
                               {
                                   MoteMaker.ThrowExplosionCell(casterPawn.Position, map, ThingDefOf.Mote_ExplosionFlash, new UnityEngine.Color(1f - asd * 0.1f, asd * 0.1f, 1f - asd * 0.05f));
                               }


                               double dist = Math.Sqrt(Math.Pow(casterPawn.Position.x - target.Cell.x, 2) + Math.Pow(casterPawn.Position.z - target.Cell.z, 2));

                               if (dist < 20)
                               {
                                   dist = 20;
                               }


                               ThingSelectionUtility.SelectNextColonist();
                               base.Wearer.DeSpawn(DestroyMode.Vanish);
                               GenSpawn.Spawn(casterPawn, target.Cell, map, WipeMode.Vanish);
                               casterPawn.drafter.Drafted = true;
                               ThingSelectionUtility.SelectPreviousColonist();
                               SoundStarter.PlayOneShot(DefDatabase <SoundDef> .GetNamed("ra2_Chrono_move", true), casterPawn);
                               SoundStarter.PlayOneShotOnCamera(DefDatabase <SoundDef> .GetNamed("ra2_Chrono_movesay", true));

                               DamageInfo dinfo = new DamageInfo(DamageDefOf.Stun, (int)(dist * 0.1), -1, 1, null, null, base.Wearer.equipment.Primary.def, DamageInfo.SourceCategory.ThingOrUnknown, casterPawn);
                               casterPawn.TakeDamage(dinfo);
                               // Log.Warning(target+"VV");
                           }
                       }
            }
            ;

            //yuri
            bool isYuri = false;

            if (this.Wearer != null)
            {
                Pawn pawn = this.Wearer;

                if (pawn.kindDef.defName.EqualsIgnoreCase("ra2_yuriyuri"))
                {
                    isYuri = true;
                }
            }

            if (isYuri)
            {
                bool canCast = this.ticks <= 0 && this.Wearer.drafter.Drafted && !this.Wearer.stances.stunner.Stunned;
                yield return(new Command_YuriAction
                {
                    defaultLabel = "YuriExpTitle".Translate(),
                    icon = ContentFinder <Texture2D> .Get("ra2/Things/Misc/yuriExpIcon", true),
                    disabled = !canCast,
                    caster = this.Wearer,
                    hotKey = KeyBindingDefOf.Misc4,
                    action = delegate
                    {
                        Pawn pawn = this.Wearer;
                        DamageDef df = DefDatabase <DamageDef> .GetNamed("YuriExp", true);

                        foreach (IntVec3 cell in CellsAround(pawn.Position, pawn.Map, 7))
                        {
                            // if (!cell.IsValid) continue;
                            List <Thing> list = (pawn.Map.thingGrid.ThingsListAt(cell));
                            try
                            {
                                if (list.Count < 1)
                                {
                                    continue;
                                }
                                for (int i = 0; i < list.Count; i++)
                                {
                                    Pawn p;
                                    if ((p = (list[i] as Pawn)) != null)
                                    {
                                        if (p.kindDef.defName.EqualsIgnoreCase("ra2_yuriyuri"))
                                        {
                                            continue;
                                        }
                                        if (p.RaceProps.IsFlesh)
                                        {
                                            {
                                                p.Kill(new DamageInfo(df, 0, 0, -1, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null), null);
                                            }

                                            if (!(p.Faction == Faction.OfPlayer && p.kindDef.defName.StartsWith("ra2_")))
                                            {
                                                p.Corpse.Kill(null);
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception e) { Log.Warning(e + "233"); }
                        }

                        pawn.stances.stunner.StunFor(120, null);
                        this.ticks = 300;
                        GenExplosion.DoExplosion(pawn.Position, pawn.Map, 7f, df, pawn, 0, -1, null, null, null, null, null, 0, 1, false, null, 0, 1, 0, false);
                    }
                });
            }



            yield break;
        }
    }
}
コード例 #5
0
ファイル: RealmPawn.cs プロジェクト: emipa606/PhiClient
        // Token: 0x06000038 RID: 56 RVA: 0x000030B0 File Offset: 0x000012B0
        public Pawn FromRealmPawn(RealmData realmData)
        {
            var named = DefDatabase <PawnKindDef> .GetNamed(kindDefName);

            var pawn = (Pawn)ThingMaker.MakeThing(named.race);

            foreach (var pawn2 in Find.WorldPawns.ForcefullyKeptPawns)
            {
                var   health = pawn2.health;
                float?num;
                if (health == null)
                {
                    num = null;
                }
                else
                {
                    var hediffSet = health.hediffSet;
                    if (hediffSet == null)
                    {
                        num = null;
                    }
                    else
                    {
                        var firstHediffOfDef = hediffSet.GetFirstHediffOfDef(PhiHediffDefOf.Phi_Key);
                        num = firstHediffOfDef != null ? new float?(firstHediffOfDef.Severity) : null;
                    }
                }

                var   num2 = num ?? -1f;
                var   list = hediffs;
                float?num3;
                if (list == null)
                {
                    num3 = null;
                }
                else
                {
                    var realmHediff = list.First(h => h.hediffDefName == PhiHediffDefOf.Phi_Key.defName);
                    num3 = realmHediff != null ? new float?(realmHediff.severity) : null;
                }

                if (num2 != num3)
                {
                    continue;
                }

                pawn = pawn2;
                break;
            }

            pawn.kindDef = named;
            pawn.SetFactionDirect(Faction.OfPlayer);
            PawnComponentsUtility.CreateInitialComponents(pawn);
            var pawnName = pawn.Name;

            switch (name.Length)
            {
            case 1:
                pawnName = new NameSingle(name[0]);
                break;

            case 2:
                pawnName = new NameTriple(name[0], name[1], name[1]);
                break;

            case 3:
                pawnName = new NameTriple(name[0], name[1], name[2]);
                break;
            }

            pawn.Name   = pawnName;
            pawn.gender = gender;
            pawn.ageTracker.AgeBiologicalTicks    = ageBiologicalTicks;
            pawn.ageTracker.AgeChronologicalTicks = ageChronologicalTicks;
            var story = pawn.story;

            if (story != null)
            {
                story.melanin   = melanin;
                story.crownType = crownType;
                story.hairColor = new Color(hairColor[0], hairColor[1], hairColor[2], hairColor[3]);
                if (!BackstoryDatabase.TryGetWithIdentifier(childhoodKey, out story.childhood))
                {
                    throw new Exception($"Couldn't find backstory '{childhoodKey}'");
                }

                if (!string.IsNullOrEmpty(adulthoodKey) &&
                    !BackstoryDatabase.TryGetWithIdentifier(adulthoodKey, out story.adulthood))
                {
                    throw new Exception($"Couldn't find backstory '{adulthoodKey}'");
                }

                story.bodyType = DefDatabase <BodyTypeDef> .GetNamed(bodyTypeDefName);

                story.hairDef = DefDatabase <HairDef> .GetNamed(hairDefName);

                story.traits.allTraits.Clear();
                foreach (var realmTrait in traits)
                {
                    var named2 = DefDatabase <TraitDef> .GetNamed(realmTrait.traitDefName);

                    story.traits.GainTrait(new Trait(named2, realmTrait.degree));
                }
            }

            if (skills != null)
            {
                using var enumerator3 = skills.AsEnumerable().GetEnumerator();
                while (enumerator3.MoveNext())
                {
                    var item2    = enumerator3.Current;
                    var skillDef = DefDatabase <SkillDef> .AllDefs.First(def => def.label == item2?.skillDefLabel);

                    var skill = pawn.skills.GetSkill(skillDef);
                    if (item2 == null)
                    {
                        continue;
                    }

                    skill.Level   = item2.level;
                    skill.passion = item2.passion;
                }
            }

            var workSettings = pawn.workSettings;

            workSettings?.EnableAndInitialize();

            if (apparels != null)
            {
                var pawn_ApparelTracker = new Pawn_ApparelTracker(pawn);
                foreach (var realmThing in apparels)
                {
                    var apparel = (Apparel)realmData.FromRealmThing(realmThing);
                    pawn_ApparelTracker.Wear(apparel);
                }
            }

            if (equipments != null)
            {
                var pawn_EquipmentTracker = new Pawn_EquipmentTracker(pawn);
                foreach (var realmThing2 in equipments)
                {
                    var newEq = (ThingWithComps)realmData.FromRealmThing(realmThing2);
                    pawn_EquipmentTracker.AddEquipment(newEq);
                }
            }

            if (inventory != null)
            {
                var pawn_InventoryTracker = pawn.inventory;
                foreach (var realmThing3 in inventory)
                {
                    var item = realmData.FromRealmThing(realmThing3);
                    pawn_InventoryTracker.innerContainer.TryAdd(item);
                }
            }

            if (hediffs == null)
            {
                Log.Warning("RealmHediffs is null in received colonist");
            }

            foreach (var realmHediff2 in hediffs ?? new List <RealmHediff>())
            {
                var named3 = DefDatabase <HediffDef> .GetNamed(realmHediff2.hediffDefName);

                BodyPartRecord part = null;
                if (realmHediff2.bodyPartIndex != -1)
                {
                    part = pawn.RaceProps.body.GetPartAtIndex(realmHediff2.bodyPartIndex);
                }

                pawn.health.AddHediff(named3, part);
                var hediff = pawn.health.hediffSet.hediffs.Last();
                hediff.source = realmHediff2.sourceDefName == null
                    ? null
                    : DefDatabase <ThingDef> .GetNamedSilentFail(realmHediff2.sourceDefName);

                hediff.ageTicks = realmHediff2.ageTicks;
                hediff.Severity = realmHediff2.severity;
                if (float.IsNaN(realmHediff2.immunity) || pawn.health.immunity.ImmunityRecordExists(named3))
                {
                    continue;
                }

                var immunity = pawn.health.immunity;
                immunity.GetType().GetMethod("TryAddImmunityRecord", BindingFlags.Instance | BindingFlags.NonPublic)
                .Invoke(immunity, new object[]
                {
                    named3
                });
                immunity.GetImmunityRecord(named3).immunity = realmHediff2.immunity;
            }

            if (training != null)
            {
                pawn.training = new Pawn_TrainingTracker(pawn);
                foreach (var realmTrainingRecord in training)
                {
                    var named4 = DefDatabase <TrainableDef> .GetNamed(realmTrainingRecord.trainingDefLabel);

                    if (realmTrainingRecord.wanted)
                    {
                        pawn.training.SetWantedRecursive(named4, false);
                    }

                    if (realmTrainingRecord.learned)
                    {
                        pawn.training.Train(named4, null, true);
                    }
                }
            }

            var field = pawn.health.GetType().GetField("healthState", BindingFlags.Instance | BindingFlags.NonPublic);

            if (field == null)
            {
                Log.Error("Unable to find healthState field");
            }
            else
            {
                field.SetValue(pawn.health, healthState);
            }

            if (workPriorities == null)
            {
                return(pawn);
            }

            foreach (var keyValuePair in workPriorities ?? new Dictionary <string, int>())
            {
                var namedSilentFail = DefDatabase <WorkTypeDef> .GetNamedSilentFail(keyValuePair.Key);

                if (namedSilentFail == null)
                {
                    Log.Warning($"Ignoring unknown workType: {keyValuePair.Key}");
                }
                else
                {
                    pawn.workSettings.SetPriority(namedSilentFail, keyValuePair.Value);
                }
            }

            return(pawn);
        }
コード例 #6
0
        public static bool TryExecuteWorker(IncidentParms parms)
        {
            StringBuilder builder = new StringBuilder();

            if (parms.faction.def.defName.EqualsIgnoreCase("ra2_soviet"))
            {
                Find.MusicManagerPlay.ForceStartSong(DefDatabase <SongDef> .GetNamed("ra2_soviet_music", true), false);

                // Log.Warning("your points is :"+ parms.points);
                if (parms.points >= 600)
                {
                    spawnSpecialPawn(parms, "ra2_SovietEngineer");
                }

                if (parms.points >= 3600)
                {
                    Pawn apoTank = spawnSpecialPawn(parms, "ra2_ApoTank");
                    SoundStarter.PlayOneShotOnCamera(DefDatabase <SoundDef> .GetNamed("ra2_apo_enter"), (Map)parms.target);
                    String text = Translator.Translate("DangerousunitMsg", new object[] { parms.faction.Name, apoTank.def.label });
                    builder.AppendLine(text);

                    Find.LetterStack.ReceiveLetter(Translator.Translate("Dangerousunit"), builder.ToString(), LetterDefOf.Death, apoTank);

                    //  Messages.Message(text+apoTank,MessageTypeDefOf.PawnDeath);
                }


                return(true);
            }
            else
            if (parms.faction.def.defName.EqualsIgnoreCase("ra2_allied"))
            {
                Find.MusicManagerPlay.ForceStartSong(DefDatabase <SongDef> .GetNamed("ra2_allied_music", true), false);

                if (parms.points >= 600)
                {
                    spawnSpecialPawn(parms, "ra2_AlliedEngineer");
                }

                if (parms.points >= 3600)
                {
                    Pawn item = getTanya(parms);
                    Pawn_EquipmentTracker et = item.equipment;
                    Random nr     = new Random((int)parms.points);
                    int    result = nr.Next(100);
                    et.AddEquipment((ThingWithComps)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed(result > 33 ? "ra2_Gun_Tanya" : "ra2_TanyaC4Bomb", true)));


                    IntVec3 loc = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, (Map)parms.target, 8, null);
                    Pawn    pp  = (Pawn)(GenSpawn.Spawn(item, loc, (Map)parms.target, parms.spawnRotation, WipeMode.Vanish, false));
                    //Lord ld = LordMaker.MakeNewLord(parms.faction, new LordJob_AssaultColony(parms.faction, false, false, true, false, true), (Map)parms.target);
                    //ld.AddPawn(pp);
                    List <Pawn> pl = new List <Pawn>();
                    pl.Add(pp);
                    parms.raidStrategy.Worker.MakeLords(parms, pl);

                    SoundStarter.PlayOneShotOnCamera(DefDatabase <SoundDef> .GetNamed("ra2_tanya_enter"), (Map)parms.target);

                    String text = Translator.Translate("DangerousunitMsg", new object[] { parms.faction.Name, item.Name });
                    builder.AppendLine(text);
                    builder.AppendLine("TanyaWeaponUse".Translate() + ":" + DefDatabase <ThingDef> .GetNamed(result > 33 ? "ra2_Gun_Tanya" : "ra2_TanyaC4Bomb", true).label);

                    Find.LetterStack.ReceiveLetter(Translator.Translate("Dangerousunit"), builder.ToString(), LetterDefOf.Death, pp);
                }


                return(true);
            }
            else
            if (parms.faction.def.defName.EqualsIgnoreCase("ra2_yuri"))
            {
                Find.MusicManagerPlay.ForceStartSong(DefDatabase <SongDef> .GetNamed("ra2_yuri_music", true), false);

                // Log.Warning("your points is :"+ parms.points);
                if (parms.points >= 500)
                {
                    spawnSpecialPawn(parms, "ra2_YuriEngineer");
                }
                return(true);
            }



            return(false);
        }
コード例 #7
0
        public Pawn FromRealmPawn(RealmData realmData)
        {
            // This code is mainly a copy/paste of what happens in
            // PawnGenerator.DoGenerateNakedPawn()
            PawnKindDef kindDef = DefDatabase <PawnKindDef> .GetNamed(kindDefName);

            Pawn pawn = (Pawn)ThingMaker.MakeThing(kindDef.race);

            pawn.kindDef = kindDef;
            pawn.SetFactionDirect(Faction.OfPlayer);
            PawnComponentsUtility.CreateInitialComponents(pawn);
            pawn.gender = gender;

            // What is done in GenerateRandomAge()
            pawn.ageTracker.AgeBiologicalTicks    = ageBiologicalTicks;
            pawn.ageTracker.AgeChronologicalTicks = ageChronologicalTicks;

            // Ignored SetInitialLevels()
            // Ignored GenerateInitialHediffs()
            // Ignored GeneratePawnRelations()

            Pawn_StoryTracker story = pawn.story;

            story.melanin   = melanin;
            story.crownType = crownType;
            story.hairColor = new Color(hairColor[0], hairColor[1], hairColor[2], hairColor[3]);

            // What is done in GiveAppropriateBio()
            Name nameObj = pawn.Name;

            switch (name.Count())
            {
            case 1:
                nameObj = new NameSingle(name[0]);
                break;

            case 2:
                nameObj = new NameTriple(name[0], name[1], name[1]);
                break;

            case 3:
                nameObj = new NameTriple(name[0], name[1], name[2]);
                break;
            }
            pawn.Name = nameObj;

            if (!BackstoryDatabase.TryGetWithIdentifier(childhoodKey, out story.childhood))
            {
                throw new Exception(string.Format("Couldn't find backstory '{0}'", childhoodKey));
            }
            if (!string.IsNullOrEmpty(adulthoodKey) && !BackstoryDatabase.TryGetWithIdentifier(adulthoodKey, out story.adulthood))
            {
                throw new Exception(string.Format("Couldn't find backstory '{0}'", adulthoodKey));
            }

            story.hairDef = DefDatabase <HairDef> .GetNamed(hairDefName);

            // Done in GiveRandomTraits()
            foreach (RealmTrait trait in traits)
            {
                TraitDef traitDef = DefDatabase <TraitDef> .GetNamed(trait.traitDefName);

                story.traits.GainTrait(new Trait(traitDef, trait.degree));
            }

            // We attribute the skills level
            foreach (RealmSkillRecord rec in skills.AsEnumerable())
            {
                SkillDef skillDef = DefDatabase <SkillDef> .AllDefs.First((def) => def.label == rec.skillDefLabel);

                SkillRecord skill = pawn.skills.GetSkill(skillDef);
                skill.Level   = rec.level;
                skill.passion = rec.passion;
            }

            pawn.workSettings.EnableAndInitialize();

            // Once we've generated a new solid pawn, we generate the gear of it
            // GenerateStartingApparelFor()
            Pawn_ApparelTracker apparelTracker = pawn.apparel;

            foreach (RealmThing realmThing in apparels)
            {
                Apparel apparel = (Apparel)realmData.FromRealmThing(realmThing);

                apparelTracker.Wear(apparel);
            }

            // TryGenerateWeaponFor()
            Pawn_EquipmentTracker equipmentTracker = pawn.equipment;

            foreach (RealmThing realmThing in equipments)
            {
                ThingWithComps thingWithComps = (ThingWithComps)realmData.FromRealmThing(realmThing);

                equipmentTracker.AddEquipment(thingWithComps);
            }

            // GenerateInventoryFor()
            Pawn_InventoryTracker inventoryTracker = pawn.inventory;

            foreach (RealmThing realmThing in inventory)
            {
                Thing thing = realmData.FromRealmThing(realmThing);

                inventoryTracker.innerContainer.TryAdd(thing);
            }

            // GenerateHediffsFor()
            if (hediffs == null)
            {
                Log.Warning("RealmHediffs is null in received colonist");
            }

            foreach (RealmHediff hediff in hediffs ?? new List <RealmHediff>())
            {
                var definition = DefDatabase <HediffDef> .GetNamed(hediff.hediffDefName);

                BodyPartRecord bodypart = null;
                if (hediff.bodyPartIndex != -1)
                {
                    bodypart = pawn.RaceProps.body.GetPartAtIndex(hediff.bodyPartIndex);
                }

                pawn.health.AddHediff(definition, bodypart);
                var newdiff = pawn.health.hediffSet.hediffs.Last();
                newdiff.source   = (hediff.sourceDefName == null ? null : DefDatabase <ThingDef> .GetNamedSilentFail(hediff.sourceDefName));
                newdiff.ageTicks = hediff.ageTicks;
                newdiff.Severity = hediff.severity;

                if (!float.IsNaN(hediff.immunity) && !pawn.health.immunity.ImmunityRecordExists(definition))
                {
                    var handler = pawn.health.immunity;
                    handler.GetType().GetMethod("TryAddImmunityRecord", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(handler, new object[] { definition });
                    var record = handler.GetImmunityRecord(definition);
                    record.immunity = hediff.immunity;
                }
            }

            var healthStateField = pawn.health.GetType().GetField("healthState", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            if (healthStateField == null)
            {
                Log.Error("Unable to find healthState field");
            }
            else
            {
                healthStateField.SetValue(pawn.health, healthState);
            }

            // GenerateHediffsFor()
            if (workPriorities == null)
            {
                Log.Warning("WorkPriorities is null in received colonist");
            }

            foreach (KeyValuePair <string, int> priority in workPriorities ?? new Dictionary <string, int>())
            {
                var def = DefDatabase <WorkTypeDef> .GetNamedSilentFail(priority.Key);

                if (def == null)
                {
                    Log.Warning(String.Format("Ignoring unknown workType: {0}", priority.Key));
                    continue;
                }
                pawn.workSettings.SetPriority(def, priority.Value);
            }

            return(pawn);
        }