internal static bool TryTransferEquipmentToContainer(this Pawn_EquipmentTracker _this, ThingWithComps eq, ThingContainer container, out ThingWithComps resultingEq)
        {
            // Fetch private fields
            Pawn pawn = (Pawn)pawnFieldInfo.GetValue(_this);

            if (!_this.AllEquipment.Contains(eq))
            {
                Log.Warning(pawn.LabelCap + " tried to transfer equipment he didn't have: " + eq);
                resultingEq = null;
                return(false);
            }
            if (container.TryAdd(eq, true))
            {
                resultingEq = null;
            }
            else
            {
                resultingEq = eq;
            }
            _this.Remove(eq);
            CE_Utility.TryUpdateInventory(pawn);   // Equipment was stored away, update inventory

            // Cancel current job (use verb, etc.)
            if (pawn.Spawned)
            {
                pawn.stances.CancelBusyStanceSoft();
            }

            return(resultingEq == null);
        }
 public static void Notify_PrimaryDestroyed(this Pawn_EquipmentTracker tracker)
 {
     if (tracker.Primary != null)
     {
         tracker.Remove(tracker.Primary);
     }
     if (tracker.pawn.Spawned)
     {
         tracker.pawn.stances.CancelBusyStanceSoft();
     }
 }
Exemplo n.º 3
0
 static void Prefix(Pawn_EquipmentTracker __instance, ThingWithComps eq)
 {
     if (eq.def.equipmentType == EquipmentType.Primary && __instance.Primary != null)
     {
         if (WorldComp.TryGetAssignedWeapons(__instance.pawn, out AssignedWeaponContainer c) &&
             c.Contains(eq))
         {
             __instance.Remove(eq);
         }
     }
 }
Exemplo n.º 4
0
        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);
        }
        internal static void Notify_PrimaryDestroyed(this Pawn_EquipmentTracker _this)
        {
            // Fetch private fields
            Pawn pawn = (Pawn)pawnFieldInfo.GetValue(_this);

            _this.Remove(_this.Primary);
            if (pawn.Spawned)
            {
                pawn.stances.CancelBusyStanceSoft();
            }

            CE_Utility.TryUpdateInventory(pawn);   // Equipment was destroyed, update inventory

            // Try switching to the next available weapon
            CompInventory inventory = pawn.TryGetComp <CompInventory>();

            if (inventory != null)
            {
                inventory.SwitchToNextViableWeapon(false);
            }
        }
Exemplo n.º 6
0
        static void Prefix(Pawn_EquipmentTracker __instance, ThingWithComps newEq)
        {
#if TRY_ADD_EQUIPMENT
            Log.Warning("Begin Pawn_EquipmentTracker.AddEquipment " + pawn.Name.ToStringShort);
#endif
            if (__instance.Primary != null)
            {
                __instance.Remove(__instance.Primary);
            }

            /*ThingWithComps primary = __instance.Primary;
             * if (primary != null)
             * {
             *  if (primary.def.IsWeapon)
             *  {
             *      AssignedWeaponContainer c;
             *      if (WorldComp.AssignedWeapons.TryGetValue(pawn, out c))
             *      {
             *          c.Add(primary);
             *
             *          ThingOwner<ThingWithComps> equipment = typeof(Pawn_EquipmentTracker).GetField("equipment", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) as ThingOwner<ThingWithComps>;
             *          if (equipment != null)
             *          {
             *              List<ThingWithComps> l = typeof(ThingOwner<ThingWithComps>).GetField("innerList", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(equipment) as List<ThingWithComps>;
             *              if (l != null)
             *              {
             *                  Log.Error("Removed: " + l.Remove(primary));
             *              }
             *          }
             *      }
             *  }
             *  else
             *  {
             *      __instance.TryDropEquipment(primary, out ThingWithComps dropped, pawn.Position);
             *  }
             * }*/
#if TRY_ADD_EQUIPMENT
            Log.Warning("End Pawn_EquipmentTracker.AddEquipment");
#endif
        }
        internal static bool TryDropEquipment(this Pawn_EquipmentTracker _this, ThingWithComps eq, out ThingWithComps resultingEq, IntVec3 pos, bool forbid = true)
        {
            // Fetch private fields
            Pawn pawn = (Pawn)pawnFieldInfo.GetValue(_this);

            if (!_this.AllEquipment.Contains(eq))
            {
                Log.Warning(pawn.LabelCap + " tried to drop equipment they didn't have: " + eq);
                resultingEq = null;
                return(false);
            }
            if (!pos.IsValid)
            {
                Log.Error(string.Concat(new object[]
                {
                    pawn,
                    " tried to drop ",
                    eq,
                    " at invalid cell."
                }));
                resultingEq = null;
                return(false);
            }
            _this.Remove(eq);
            Thing thing  = null;
            bool  result = GenThing.TryDropAndSetForbidden(eq, pos, pawn.MapHeld, ThingPlaceMode.Near, out thing, forbid);

            resultingEq = (thing as ThingWithComps);
            CE_Utility.TryUpdateInventory(pawn);       // Dropped equipment, update inventory

            // Cancel current job (use verb, etc.)
            if (pawn.Spawned)
            {
                pawn.stances.CancelBusyStanceSoft();
            }

            return(result);
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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;
        }
    }
}