protected override bool TryCastShot() { bool result = false; bool arg_40_0; Pawn pawn = this.CasterPawn; Map map = this.CasterPawn.Map; CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>(); MagicPowerSkill pwr = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_EnchantedBody.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_EnchantedBody_pwr"); if (pawn != null && !pawn.Downed) { if (pawn.health.hediffSet.HasHediff(TorannMagicDefOf.TM_EnchantedBodyHD)) { comp.MagicData.MagicPowersE.FirstOrDefault <MagicPower>((MagicPower x) => x.abilityDef == TorannMagicDefOf.TM_EnchantedBody).AutoCast = false; pawn.health.RemoveHediff(pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_EnchantedBodyHD, false)); MoteMaker.ThrowHeatGlow(pawn.Position, pawn.Map, 1f); } if (pawn.health.hediffSet.HasHediff(TorannMagicDefOf.TM_EnchantedAuraHD)) { comp.MagicData.MagicPowersStandalone.FirstOrDefault <MagicPower>((MagicPower x) => x.abilityDef == TorannMagicDefOf.TM_EnchantedAura).AutoCast = false; pawn.health.RemoveHediff(pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_EnchantedAuraHD, false)); MoteMaker.ThrowHeatGlow(pawn.Position, pawn.Map, 1f); } else { if (comp.maxMP >= TorannMagicDefOf.TM_EnchantedAura.upkeepEnergyCost) { comp.MagicData.MagicPowersStandalone.FirstOrDefault <MagicPower>((MagicPower x) => x.abilityDef == TorannMagicDefOf.TM_EnchantedAura).AutoCast = true; HealthUtility.AdjustSeverity(pawn, TorannMagicDefOf.TM_EnchantedAuraHD, .5f + pwr.level); for (int i = 0; i < 3; i++) { MoteMaker.ThrowSmoke(pawn.DrawPos, pawn.Map, Rand.Range(.6f, .8f)); } MoteMaker.ThrowLightningGlow(pawn.DrawPos, pawn.Map, 1f); } else { Messages.Message("TM_NotEnoughManaToSustain".Translate( pawn.LabelShort, TorannMagicDefOf.TM_EnchantedAura.label ), MessageTypeDefOf.RejectInput); } } arg_40_0 = true; } else { arg_40_0 = false; } bool flag = arg_40_0; if (flag) { } else { Log.Warning("failed to TryCastShot"); } this.burstShotsLeft = 0; return(result); }
protected override void Impact(Thing hitThing) { Map map = base.Map; base.Impact(hitThing); if (!initialized) { SpawnThings spawnThing = new SpawnThings(); pawn = this.launcher as Pawn; MagicPowerSkill pwr = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonElemental.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonElemental_pwr"); MagicPowerSkill ver = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonElemental.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonElemental_ver"); ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef(); pwrVal = pwr.level; verVal = ver.level; if (settingsRef.AIHardMode && !pawn.IsColonistPlayerControlled) { pwrVal = 3; verVal = 3; } CellRect cellRect = CellRect.CenteredOn(this.Position, 1); cellRect.ClipInsideMap(map); IntVec3 centerCell = cellRect.CenterCell; System.Random random = new System.Random(); random = new System.Random(); duration += (verVal * 900); int rnd = GenMath.RoundRandom(random.Next(0, 8)); if (rnd < 2) { spawnThing.factionDef = TorannMagicDefOf.TM_ElementalFaction; spawnThing.spawnCount = 1; spawnThing.temporary = false; if (pwrVal == 3) { for (int i = 0; i < 2; i++) { spawnThing.def = TorannMagicDefOf.TM_LesserEarth_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_LesserEarth_Elemental"); SingleSpawnLoop(spawnThing, centerCell, map); } spawnThing.def = TorannMagicDefOf.TM_GreaterEarth_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_GreaterEarth_Elemental"); } else if (pwrVal == 2) { spawnThing.def = TorannMagicDefOf.TM_GreaterEarth_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_GreaterEarth_Elemental"); } else if (pwrVal == 1) { spawnThing.def = TorannMagicDefOf.TM_Earth_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_Earth_Elemental"); } else { spawnThing.def = TorannMagicDefOf.TM_LesserEarth_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_LesserEarth_Elemental"); } MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, pwrVal); MoteMaker.ThrowMicroSparks(centerCell.ToVector3(), map); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); } else if (rnd >= 2 && rnd < 4) { spawnThing.factionDef = TorannMagicDefOf.TM_ElementalFaction; spawnThing.spawnCount = 1; spawnThing.temporary = false; if (pwrVal == 3) { for (int i = 0; i < 2; i++) { spawnThing.def = TorannMagicDefOf.TM_LesserFire_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_LesserFire_Elemental"); SingleSpawnLoop(spawnThing, centerCell, map); } spawnThing.def = TorannMagicDefOf.TM_GreaterFire_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_GreaterFire_Elemental"); } else if (pwrVal == 2) { spawnThing.def = TorannMagicDefOf.TM_GreaterFire_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_GreaterFire_Elemental"); } else if (pwrVal == 1) { spawnThing.def = TorannMagicDefOf.TM_Fire_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_Fire_Elemental"); } else { spawnThing.def = TorannMagicDefOf.TM_LesserFire_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_LesserFire_Elemental"); } MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, pwrVal); MoteMaker.ThrowMicroSparks(centerCell.ToVector3(), map); MoteMaker.ThrowFireGlow(centerCell, map, pwrVal); MoteMaker.ThrowHeatGlow(centerCell, map, pwrVal); } else if (rnd >= 4 && rnd < 6) { spawnThing.factionDef = TorannMagicDefOf.TM_ElementalFaction; spawnThing.spawnCount = 1; spawnThing.temporary = false; if (pwrVal == 3) { for (int i = 0; i < 2; i++) { spawnThing.def = TorannMagicDefOf.TM_LesserWater_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_LesserWater_Elemental"); SingleSpawnLoop(spawnThing, centerCell, map); } spawnThing.def = TorannMagicDefOf.TM_GreaterWater_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_GreaterWater_Elemental"); } else if (pwrVal == 2) { spawnThing.def = TorannMagicDefOf.TM_GreaterWater_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_GreaterWater_Elemental"); } else if (pwrVal == 1) { spawnThing.def = TorannMagicDefOf.TM_Water_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_Water_Elemental"); } else { spawnThing.def = TorannMagicDefOf.TM_LesserWater_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_LesserWater_Elemental"); } MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, pwrVal); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(centerCell.ToVector3(), map, pwrVal, Color.blue); MoteMaker.ThrowTornadoDustPuff(centerCell.ToVector3(), map, pwrVal, Color.blue); MoteMaker.ThrowTornadoDustPuff(centerCell.ToVector3(), map, pwrVal, Color.blue); } else { spawnThing.factionDef = TorannMagicDefOf.TM_ElementalFaction; spawnThing.spawnCount = 1; spawnThing.temporary = false; if (pwrVal == 3) { for (int i = 0; i < 2; i++) { spawnThing.def = TorannMagicDefOf.TM_LesserWind_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_LesserWind_Elemental"); SingleSpawnLoop(spawnThing, centerCell, map); } spawnThing.def = TorannMagicDefOf.TM_GreaterWind_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_GreaterWind_Elemental"); } else if (pwrVal == 2) { spawnThing.def = TorannMagicDefOf.TM_GreaterWind_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_GreaterWind_Elemental"); } else if (pwrVal == 1) { spawnThing.def = TorannMagicDefOf.TM_Wind_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_Wind_Elemental"); } else { spawnThing.def = TorannMagicDefOf.TM_LesserWind_ElementalR; spawnThing.kindDef = PawnKindDef.Named("TM_LesserWind_Elemental"); } MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, 1 + pwrVal * 2); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(centerCell.ToVector3(), map, pwrVal, Color.white); } SingleSpawnLoop(spawnThing, centerCell, map); this.age = this.duration; this.initialized = true; } }
public static void AdjustedArmorPenetration_RendingWeapon_Postfix(ref VerbProperties __instance, Tool tool, Pawn attacker, Thing equipment, HediffComp_VerbGiver hediffCompSource, ref float __result) { if (tool != null) { if (!tool.capacities.NullOrEmpty()) { if (tool.capacities.Any(x => x.defName.Contains("OG_RendingWeapon"))) { float RendingChance = 0.167f; if (equipment != null) { CompWeapon_MeleeSpecialRules _MeleeSpecialRules = equipment?.TryGetComp <CompWeapon_MeleeSpecialRules>(); if (_MeleeSpecialRules != null) { RendingChance = _MeleeSpecialRules.RendingChance; } } else { if (attacker != null) { foreach (Tool item in attacker.Tools.Where(x => x != tool)) { if (item.capacities.Any(x => x.defName.Contains("OG_RendingWeapon"))) { RendingChance += 0.167f; } } } } if (Rand.Chance(RendingChance)) { MoteMaker.ThrowText(attacker.Position.ToVector3(), attacker.MapHeld, "AMA_Rending_Strike".Translate(), 3f); __result = 2f; return; } } } } /* * if (__instance.EquipmentSource != null) * { * if (!__instance.EquipmentSource.AllComps.NullOrEmpty()) * { * if (__instance.EquipmentSource.GetComp<CompWeapon_MeleeSpecialRules>() != null) * { * if (__instance.EquipmentSource.GetComp<CompWeapon_MeleeSpecialRules>() is CompWeapon_MeleeSpecialRules WeaponRules) * { * if (AMASettings.Instance.AllowRendingMeleeEffect) * { * bool RendingAttack = __result.Any(x => x.Def.rendingWeapon()); * if (WeaponRules.RendingWeapon && RendingAttack && __instance.CasterPawn is Pawn Caster) * { * * } * } * } * } * } * } */ }
public override void Tick() { base.Tick(); AdjustPowerNeed(); if (!powerComp.PowerOn && soundSustainer != null && !soundSustainer.Ended) { soundSustainer.End(); } if (flickableComp == null || (flickableComp != null && flickableComp.SwitchIsOn)) { //State machine switch (printerStatus) { case CrafterStatus.Filling: { //Emit smoke if (powerComp.PowerOn && Current.Game.tickManager.TicksGame % 300 == 0) { MoteMaker.ThrowSmoke(Position.ToVector3(), Map, 1f); } //If we aren't being filled, then start. var pendingRequests = orderProcessor.PendingRequests(); bool startPrinting = pendingRequests == null; if (pendingRequests != null && pendingRequests.Count() == 0) { startPrinting = true; } if (startPrinting) { //Initiate printing phase. StartPrinting(); } } break; case CrafterStatus.Crafting: { if (powerComp.PowerOn) { //Emit smoke if (Current.Game.tickManager.TicksGame % 100 == 0) { MoteMaker.ThrowSmoke(Position.ToVector3(), Map, 1.33f); } //Visual effects if (Current.Game.tickManager.TicksGame % 250 == 0) { for (int i = 0; i < 3; i++) { MoteMaker.ThrowMicroSparks(Position.ToVector3() + new Vector3(Rand.Range(-1, 1), 0f, Rand.Range(-1, 1)), Map); } } //Sound effect if (soundSustainer == null || soundSustainer.Ended) { SoundDef soundDef = printerProperties.craftingSound; if (soundDef != null && soundDef.sustain) { SoundInfo info = SoundInfo.InMap(this, MaintenanceType.PerTick); soundSustainer = soundDef.TrySpawnSustainer(info); } } if (soundSustainer != null && !soundSustainer.Ended) { soundSustainer.Maintain(); } //Periodically use resources. nextResourceTick--; if (nextResourceTick <= 0) { nextResourceTick = printerProperties.resourceTick; //Deduct resources from each category. foreach (ThingOrderRequest thingOrderRequest in orderProcessor.requestedItems) { if (thingOrderRequest.nutrition) { //Food if (CountNutrition() > 0f) { //Grab first stack of Nutrition. Thing item = ingredients.First(thing => thing.def.IsIngestible); if (item != null) { int resourceTickAmount = (int)Math.Ceiling((thingOrderRequest.amount / ((double)(printerProperties.ticksToCraft + extraTimeCost) / printerProperties.resourceTick))); int amount = Math.Min(resourceTickAmount, item.stackCount); Thing outThing = null; Corpse outCorpse = item as Corpse; if (outCorpse != null) { if (outCorpse.IsDessicated()) { //If rotten, just drop it. ingredients.TryDrop(outCorpse, InteractionCell, Map, ThingPlaceMode.Near, 1, out outThing); } else { //Not rotten, dump all equipment. ingredients.TryDrop(outCorpse, InteractionCell, Map, ThingPlaceMode.Near, 1, out outThing); outCorpse.InnerPawn?.equipment?.DropAllEquipment(InteractionCell, false); outCorpse.InnerPawn?.apparel?.DropAll(InteractionCell, false); item.Destroy(); } } else { Thing takenItem = ingredients.Take(item, amount); takenItem.Destroy(); } } } } else { //Item if (ingredients.Any(thing => thing.def == thingOrderRequest.thingDef)) { //Grab first stack of Plasteel. Thing item = ingredients.First(thing => thing.def == thingOrderRequest.thingDef); if (item != null) { int resourceTickAmount = (int)Math.Ceiling((thingOrderRequest.amount / ((float)(printerProperties.ticksToCraft + extraTimeCost) / printerProperties.resourceTick))); int amount = Math.Min(resourceTickAmount, item.stackCount); Thing takenItem = ingredients.Take(item, amount); takenItem.Destroy(); } } } } } //Are we done yet? if (printingTicksLeft > 0) { printingTicksLeft--; } else { printerStatus = CrafterStatus.Finished; } } } break; case CrafterStatus.Finished: { if (pawnToPrint != null) { //Clear remaining materials. ingredients.ClearAndDestroyContents(); //Add effects FilthMaker.TryMakeFilth(InteractionCell, Map, RimWorld.ThingDefOf.Filth_Slime, 5); //Spawn GenSpawn.Spawn(pawnToPrint, InteractionCell, Map); pawnToPrint.health.AddHediff(RimWorld.HediffDefOf.CryptosleepSickness); pawnToPrint.needs.mood.thoughts.memories.TryGainMemory(NeedsDefOf.ChJAndroidSpawned); //Make and send letter. ChoiceLetter letter = LetterMaker.MakeLetter("AndroidPrintedLetterLabel".Translate(pawnToPrint.Name.ToStringShort), "AndroidPrintedLetterDescription".Translate(pawnToPrint.Name.ToStringFull), LetterDefOf.PositiveEvent, pawnToPrint); Find.LetterStack.ReceiveLetter(letter); //Reset pawnToPrint = null; printerStatus = CrafterStatus.Idle; extraTimeCost = 0; orderProcessor.requestedItems.Clear(); } } break; default: { if (soundSustainer != null && !soundSustainer.Ended) { soundSustainer.End(); } } break; } } }
protected override bool TryCastShot() { // Log.Message("TryCastShot"); this.TargetsAoE.Clear(); UpdateTargets(); int burstshots = this.ShotsPerBurst; if (this.warpverbprops.PsykerPowerCategory != PsykerPowerTargetCategory.TargetAoE && this.TargetsAoE.Count > 1) { this.TargetsAoE.RemoveRange(0, TargetsAoE.Count - 1); } // Log.Message("Targeting: " + TargetsAoE.Count.ToString()); for (int i = 0; i < TargetsAoE.Count; i++) { // Log.Message(TargetsAoE[i].Thing.Label); for (int j = 0; j < burstshots; j++) { ShootLine shootLine; bool flag = base.TryFindShootLineFromTo(this.caster.Position, TargetsAoE[i], out shootLine); if (this.verbProps.stopBurstWithoutLos && !flag) { return(false); } Vector3 drawPos = this.caster.DrawPos; Projectile projectile = (Projectile)GenSpawn.Spawn(this.verbProps.projectileDef, shootLine.Source, this.caster.Map); projectile.FreeIntercept = (this.canFreeInterceptNow && !projectile.def.projectile.flyOverhead); ShotReport shotReport = ShotReport.HitReportFor(this.caster, this, TargetsAoE[i]); if (!this.warpverbprops.AlwaysHits) { if (Rand.Value > shotReport.ChanceToNotGoWild_IgnoringPosture) { if (DebugViewSettings.drawShooting) { MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToWild", -1f); } shootLine.ChangeDestToMissWild(); if (TargetsAoE[i].HasThing) { projectile.ThingToNeverIntercept = TargetsAoE[i].Thing; } if (!projectile.def.projectile.flyOverhead) { projectile.InterceptWalls = true; } // Log.Message("LaunchingIntoWild"); projectile.Launch(this.caster, drawPos, shootLine.Dest, this.ownerEquipment); return(true); } if (Rand.Value > shotReport.ChanceToNotHitCover) { if (DebugViewSettings.drawShooting) { MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToCover", -1f); } if (TargetsAoE[i].Thing != null && TargetsAoE[i].Thing.def.category == ThingCategory.Pawn) { Thing randomCoverToMissInto = shotReport.GetRandomCoverToMissInto(); if (!projectile.def.projectile.flyOverhead) { projectile.InterceptWalls = true; } // Log.Message("LaunchingINtoCover"); projectile.Launch(this.caster, drawPos, randomCoverToMissInto, this.ownerEquipment); return(true); } } } if (DebugViewSettings.drawShooting) { MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToHit", -1f); } if (!projectile.def.projectile.flyOverhead) { projectile.InterceptWalls = (!TargetsAoE[i].HasThing || TargetsAoE[i].Thing.def.Fillage == FillCategory.Full); } if (TargetsAoE[i].Thing != null) { // Log.Message("Release Shot at: " + TargetsAoE[i].Thing.Label); if (this.warpverbprops.DrawProjectileOnTarget) { Projectile_WarpPower wprojectile = projectile as Projectile_WarpPower; if (wprojectile != null) { // Log.Message("Launched Warpprojectile"); wprojectile.selectedTarget = TargetsAoE[i].Thing; wprojectile.Caster = this.CasterPawn; wprojectile.Launch(this.caster, drawPos, TargetsAoE[i]); } } else { // Log.Message("Launched Projectile"); projectile.Launch(this.caster, drawPos, TargetsAoE[i]); } } else { if (this.warpverbprops.DrawProjectileOnTarget) { Projectile_WarpPower wprojectile = projectile as Projectile_WarpPower; wprojectile.targetVec = shootLine.Dest.ToVector3(); wprojectile.Launch(this.caster, drawPos, TargetsAoE[i]); } // Log.Message("LaunchingWild"); projectile.Launch(this.caster, drawPos, shootLine.Dest); } } psycomp.TicksToCast = this.warpverbprops.TicksToRecharge; psycomp.TicksToCastMax = this.warpverbprops.TicksToRecharge; } this.burstShotsLeft = 0; if (soul != null) { soul.GainNeed(0.01f * (-warpverbprops.CorruptionFactor)); } // PsykerUtility.PsykerShockEvents(psycomp, psycomp.curPower.PowerLevel); return(true); }
protected override IEnumerable <Toil> MakeNewToils() { //--Log.Message("[RJW]JobDriver_GettinLoved::MakeNewToils is called"); if (Partner.CurJob.def == xxx.nymph_rapin) { //this.KeepLyingDown(ibed); //yield return Toils_Reserve.Reserve(ipartner, 1, 0); //yield return Toils_Reserve.Reserve(ibed, Bed.SleepingSlotsCount, 0); //Toil get_loved = Toils_LayDown.LayDown(ibed, true, false, false, false); //get_loved.FailOn(() => (Partner.CurJob.def != xxx.nymph_rapin)); //get_loved.defaultCompleteMode = ToilCompleteMode.Never; //get_loved.initAction = delegate { // //--Log.Message("[RJW]JobDriver_GettinLoved::MakeNewToils - nymph section is called"); //}; //get_loved.AddPreTickAction(delegate { // if (pawn.IsHashIntervalTick(100)) // MoteMaker.ThrowMetaIcon(pawn.Position, pawn.Map, ThingDefOf.Mote_Heart); //}); //get_loved.socialMode = RandomSocialMode.Off; //yield return get_loved; this.FailOnDespawnedOrNull(ipartner); this.FailOn(() => !Partner.health.capacities.CanBeAwake); this.KeepLyingDown(ibed); yield return(Toils_Reserve.Reserve(ipartner, 1, 0)); yield return(Toils_Reserve.Reserve(ibed, Bed.SleepingSlotsCount, 0)); Toil get_loved = Toils_LayDown.LayDown(ibed, true, false, false, false); get_loved.FailOn(() => (Partner.CurJob == null) || (Partner.CurJob.def != xxx.nymph_rapin)); get_loved.defaultCompleteMode = ToilCompleteMode.Never; get_loved.AddPreTickAction(delegate { if (pawn.IsHashIntervalTick(100)) { MoteMaker.ThrowMetaIcon(pawn.Position, pawn.Map, ThingDefOf.Mote_Heart); } }); get_loved.socialMode = RandomSocialMode.Off; yield return(get_loved); } else if (Partner.CurJob.def == xxx.whore_is_serving_visitors) { this.FailOnDespawnedOrNull(ipartner); this.FailOn(() => !Partner.health.capacities.CanBeAwake || Partner.CurJob == null); yield return(Toils_Goto.GotoThing(ipartner, PathEndMode.OnCell)); yield return(Toils_Reserve.Reserve(ipartner, 1, 0)); Toil get_loved = new Toil(); get_loved.FailOn(() => (Partner.CurJob.def != xxx.whore_is_serving_visitors)); get_loved.defaultCompleteMode = ToilCompleteMode.Never; get_loved.initAction = delegate { //--Log.Message("[RJW]JobDriver_GettinLoved::MakeNewToils - w***e section is called"); }; get_loved.AddPreTickAction(delegate { if (pawn.IsHashIntervalTick(100)) { MoteMaker.ThrowMetaIcon(pawn.Position, pawn.Map, ThingDefOf.Mote_Heart); xxx.sexTick(pawn, Partner); } }); get_loved.socialMode = RandomSocialMode.Off; yield return(get_loved); } }
protected override bool TryCastShot() { CellRect cellRect = CellRect.CenteredOn(this.currentTarget.Cell, 1); Map map = base.CasterPawn.Map; cellRect.ClipInsideMap(map); IntVec3 centerCell = cellRect.CenterCell; //FlyingObject flyingPawn = new FlyingObject(); Pawn summonablePawn = new Pawn(); bool pflag = true; Thing summonableThing = centerCell.GetFirstPawn(map); if (summonableThing == null) { pflag = false; summonableThing = centerCell.GetFirstItem(map); } else { pVect = summonableThing.TrueCenter(); pVect.x = base.caster.TrueCenter().x; pVect.z = base.caster.TrueCenter().z; pVect.y = 0f; summonablePawn = summonableThing as Pawn; if (summonablePawn != base.CasterPawn) { //flyingPawn = (FlyingObject)GenSpawn.Spawn(ThingDef.Named("TM_SummonedPawn"), summonableThing.Position, summonableThing.Map); } else { //flyingPawn = null; summonableThing = null; Messages.Message("TM_CantSummonSelf".Translate(), MessageTypeDefOf.NegativeEvent); } } bool result = false; bool arg_40_0; if (this.currentTarget != null && base.CasterPawn != null) { arg_40_0 = this.currentTarget.Cell.IsValid; } else { arg_40_0 = false; } bool flag = arg_40_0; if (flag) { if (summonableThing != null) { if (pflag)// && flyingPawn != null) { //Thing p = summonablePawn; if (!summonablePawn.RaceProps.Humanlike || summonablePawn.Faction == this.CasterPawn.Faction) { summonablePawn.DeSpawn(); GenSpawn.Spawn(summonablePawn, base.CasterPawn.Position, map); } else if (summonablePawn.RaceProps.Humanlike && summonablePawn.Faction != this.CasterPawn.Faction && Rand.Chance(TM_Calc.GetSpellSuccessChance(this.CasterPawn, summonablePawn, true))) { //summonablePawn.DeSpawn(); //GenSpawn.Spawn(p, base.caster.Position, base.CasterPawn.Map, Rot4.North, false); //Pawn p = summonablePawn; summonablePawn.DeSpawn(); //p.SetPositionDirect(this.currentTarget.Cell); GenSpawn.Spawn(summonablePawn, base.CasterPawn.Position, map); //flyingPawn = null; if (summonablePawn.IsColonist && !base.CasterPawn.IsColonist) { TM_Action.SpellAffectedPlayerWarning(summonablePawn); } //summonablePawn.Position = base.CasterPawn.Position; //p.jobs.StopAll(false); } else { MoteMaker.ThrowText(summonablePawn.DrawPos, summonablePawn.Map, "TM_ResistedSpell".Translate(), -1); } } else { summonableThing.DeSpawn(DestroyMode.Vanish); GenPlace.TryPlaceThing(summonableThing, this.CasterPawn.Position, this.CasterPawn.Map, ThingPlaceMode.Near); //summonableThing.Position = base.CasterPawn.Position; //summonableThing.Rotation = Rot4.North; //summonableThing.SetPositionDirect(base.CasterPawn.InteractionCell); } result = true; } } else { Log.Warning("failed to TryCastShot"); } this.burstShotsLeft = 0; //this.ability.TicksUntilCasting = (int)base.UseAbilityProps.SecondsToRecharge * 60; return(result); }
public static bool Prefix(StunHandler __instance, DamageInfo dinfo, ref int ___EMPAdaptedTicksLeft, ref int ___stunTicksLeft, ref bool ___stunFromEMP) { Pawn pawn = __instance.parent as Pawn; float bodySize = 1.0f; if (pawn != null) { if (pawn.Downed || pawn.Dead) { return(false); } bodySize = pawn.BodySize; } if (dinfo.Def == DamageDefOf.EMP && __instance.parent is Pawn p && !(p.RaceProps?.IsFlesh ?? false)) { if (___EMPAdaptedTicksLeft > 0) { int newStunAdaptedTicks = Mathf.RoundToInt(dinfo.Amount * 45 * bodySize); int newStunTicks = Mathf.RoundToInt(dinfo.Amount * 30); float stunResistChance = ((float)___EMPAdaptedTicksLeft / (float)newStunAdaptedTicks) * 15; if (UnityEngine.Random.value > stunResistChance) { ___EMPAdaptedTicksLeft += Mathf.RoundToInt(dinfo.Amount * 45 * bodySize); if (___stunTicksLeft > 0 && newStunTicks > ___stunTicksLeft) { ___stunTicksLeft = newStunTicks; } else { __instance.StunFor(newStunTicks, dinfo.Instigator, true, true); } } else { MoteMaker.ThrowText(new Vector3((float)__instance.parent.Position.x + 1f, (float)__instance.parent.Position.y, (float)__instance.parent.Position.z + 1f), __instance.parent.Map, "Adapted".Translate(), Color.white, -1f); int adaptationReduction = Mathf.RoundToInt(Mathf.Sqrt(dinfo.Amount * 45)); if (adaptationReduction < ___EMPAdaptedTicksLeft) { ___EMPAdaptedTicksLeft -= adaptationReduction; } else { float adaptationReductionRatio = (adaptationReduction - ___EMPAdaptedTicksLeft) / adaptationReduction; newStunAdaptedTicks = Mathf.RoundToInt(newStunAdaptedTicks * adaptationReductionRatio); newStunTicks = Mathf.RoundToInt(newStunTicks * adaptationReductionRatio); if (___stunTicksLeft > 0 && newStunTicks > ___stunTicksLeft) { ___stunTicksLeft = newStunTicks; } else { __instance.StunFor(newStunTicks, dinfo.Instigator, true, true); } } } } else { __instance.StunFor(Mathf.RoundToInt(dinfo.Amount * 30f), dinfo.Instigator, true, true); ___EMPAdaptedTicksLeft = Mathf.RoundToInt(dinfo.Amount * 45 * bodySize); ___stunFromEMP = true; } } return(true); }
public void WeaponTick(int weaponIndex, WeaponDef weaponDef) { if ((weaponDef.ammoDef != null) && (this.weaponRemainingRounds[weaponIndex] == -1) && (this.shipToTargetDistance <= weaponDef.startShootingDistance)) { // Start shooting. this.weaponRemainingRounds[weaponIndex] = weaponDef.ammoQuantity; this.weaponNextShotTick[weaponIndex] = Find.TickManager.TicksGame; int firstShotSideAsInt = Rand.RangeInclusive(0, 1); if (firstShotSideAsInt == 1) { this.weaponShootRight[weaponIndex] = true; } else { this.weaponShootRight[weaponIndex] = false; } if (weaponDef.disableRainDurationInTicks > 0) { this.Map.weatherDecider.DisableRainFor(weaponDef.disableRainDurationInTicks); } } if ((this.weaponRemainingRounds[weaponIndex] > 0) && (Find.TickManager.TicksGame >= this.weaponNextShotTick[weaponIndex])) { // Shoot 1 round. float sign = 0; if ((weaponDef.isTwinGun == false) || this.weaponShootRight[weaponIndex]) { sign = 1f; } else { sign = -1f; } Vector3 roundOrigin = this.spaceshipExactPosition + new Vector3(sign * weaponDef.horizontalPositionOffset, 0f, weaponDef.verticalPositionOffset).RotatedBy(this.spaceshipExactRotation); Vector3 roundDestination = roundOrigin + new Vector3(0f, 0f, weaponDef.ammoTravelDistance).RotatedBy(this.spaceshipExactRotation); if (roundOrigin.InBounds(this.Map) && roundDestination.InBounds(this.Map)) { Projectile projectile = GenSpawn.Spawn(weaponDef.ammoDef, roundOrigin.ToIntVec3(), this.Map) as Projectile; if (weaponDef.soundCastDef != null) { weaponDef.soundCastDef.PlayOneShot(new TargetInfo(roundOrigin.ToIntVec3(), this.Map)); } MoteMaker.MakeStaticMote(roundOrigin, this.Map, ThingDefOf.Mote_ShotFlash, 10f); // Look for hostile pawn if weapon has a target acquire range. Pawn pawn = null; if (weaponDef.targetAcquireRange > 0f) { pawn = GetRandomeHostilePawnAround(roundDestination, weaponDef.targetAcquireRange); } if (pawn != null) { projectile.Launch(this, roundOrigin, pawn, pawn, ProjectileHitFlags.IntendedTarget); } else { roundDestination += new Vector3(Rand.Range(-weaponDef.targetAcquireRange, weaponDef.targetAcquireRange), 0f, 0f).RotatedBy(this.spaceshipExactRotation); projectile.Launch(this, roundOrigin, roundDestination.ToIntVec3(), roundDestination.ToIntVec3(), ProjectileHitFlags.None); } } this.weaponRemainingRounds[weaponIndex]--; this.weaponNextShotTick[weaponIndex] = Find.TickManager.TicksGame + weaponDef.ticksBetweenShots; this.weaponShootRight[weaponIndex] = !this.weaponShootRight[weaponIndex]; } }
public void ApplyHediffsAndMentalStates(Pawn victim) { try { //Log.Message("ApplyHediffsAndMentalStates"); if (localApplyMentalStates != null) { if (localApplyMentalStates.Count > 0) { foreach (var mentalStateGiver in localApplyMentalStates) { var success = false; var checkValue = Rand.Value; var str = localAbilityDef.LabelCap + " (" + Caster.LabelShort + ")"; if (checkValue <= mentalStateGiver.applyChance) { if (mentalStateGiver.mentalStateDef == MentalStateDefOf.Berserk && victim.RaceProps.intelligence < Intelligence.Humanlike) { if (Caster == victim || CanOverpower(Caster, victim)) { success = true; victim.mindState.mentalStateHandler.TryStartMentalState( MentalStateDefOf.Manhunter, str, true); } } else { if (Caster == victim || CanOverpower(Caster, victim)) { success = true; victim.mindState.mentalStateHandler.TryStartMentalState( mentalStateGiver.mentalStateDef, str, true); } } } if (success) { victim.Drawer.Notify_DebugAffected(); MoteMaker.ThrowText(victim.DrawPos, victim.Map, mentalStateGiver.mentalStateDef.LabelCap + ": " + StringsToTranslate.AU_CastSuccess, -1f); } else { MoteMaker.ThrowText(victim.DrawPos, victim.Map, mentalStateGiver.mentalStateDef.LabelCap + ": " + StringsToTranslate.AU_CastFailure, -1f); } } } } if (localApplyHediffs != null) { if (localApplyHediffs.Count > 0) { foreach (var hediffs in localApplyHediffs) { var success = false; if (Rand.Value <= hediffs.applyChance) { if (victim == Caster || CanOverpower(Caster, victim)) { HealthUtility.AdjustSeverity(victim, hediffs.hediffDef, hediffs.severity); //Hediff newHediff = HediffMaker.MakeHediff(hediffs.hediffDef, victim, null); //victim.health.AddHediff(newHediff, null, null); //newHediff.Severity = hediffs.severity; success = true; } } if (success) { victim.Drawer.Notify_DebugAffected(); MoteMaker.ThrowText(victim.DrawPos, victim.Map, hediffs.hediffDef.LabelCap + ": " + StringsToTranslate.AU_CastSuccess, -1f); } else { MoteMaker.ThrowText(victim.DrawPos, victim.Map, StringsToTranslate.AU_CastFailure, -1f); } } } } } catch (NullReferenceException e) { Log.Message(e.ToString()); } }
public void ApplyOverdriveHD(Pawn pawn) { ApplyHediffs(pawn); MoteMaker.ThrowLightningGlow(pawn.DrawPos, pawn.Map, 1.5f); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_PowerWave"), pawn.DrawPos, pawn.Map, .6f, .3f, 0, .3f, Rand.Range(-500, 500), 0, 0, Rand.Range(0, 360)); }
protected override bool TryCastShot() { Pawn p = this.CasterPawn; Map map = this.CasterPawn.Map; CompAbilityUserMagic comp = this.CasterPawn.GetComp <CompAbilityUserMagic>(); corpses.Clear(); pawns.Clear(); plants.Clear(); GenClamor.DoClamor(p, this.UseAbilityProps.TargetAoEProperties.range, ClamorDefOf.Ability); Effecter igniteED = TorannMagicDefOf.TM_IgniteED.Spawn(); igniteED.Trigger(new TargetInfo(this.currentTarget.Cell, map, false), new TargetInfo(this.currentTarget.Cell, map, false)); igniteED.Cleanup(); SoundInfo info = SoundInfo.InMap(new TargetInfo(this.currentTarget.Cell, map, false), MaintenanceType.None); info.pitchFactor = 1.1f; info.volumeFactor = 1.8f; TorannMagicDefOf.TM_FireWooshSD.PlayOneShot(info); TargetInfo ti = new TargetInfo(this.currentTarget.Cell, map, false); TM_MoteMaker.MakeOverlay(ti, TorannMagicDefOf.TM_Mote_PsycastAreaEffect, map, Vector3.zero, .2f, 0f, .1f, .4f, .4f, 4.3f); float classBonus = 1f; if (p.story != null && p.story.traits != null && p.story.traits.HasTrait(TorannMagicDefOf.InnerFire)) { classBonus = 1.5f; } if (this.currentTarget != null && p != null && comp != null) { this.arcaneDmg = comp.arcaneDmg; this.TargetsAoE.Clear(); this.FindTargets(); float energy = 200000 * this.arcaneDmg * classBonus; GenTemperature.PushHeat(this.currentTarget.Cell, p.Map, energy); ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef(); for (int i = 0; i < pawns.Count; i++) { if (!pawns[i].RaceProps.IsMechanoid) { float distanceModifier = (classBonus) / (pawns[i].Position - currentTarget.Cell).LengthHorizontal; if (distanceModifier > 1f) { distanceModifier = 1f; } if (Rand.Chance(TM_Calc.GetSpellSuccessChance(this.CasterPawn, pawns[i], true)) && Rand.Chance(distanceModifier)) { pawns[i].TryAttachFire(Rand.Range(distanceModifier / 2f, distanceModifier)); } } } for (int i = 0; i < corpses.Count; i++) { //if (corpses[i].CanEverAttachFire()) //{ float distanceModifier = 1f / (corpses[i].Position - currentTarget.Cell).LengthHorizontal; // corpses[i].TryAttachFire(Rand.Range(distanceModifier / 2f, distanceModifier)); FireUtility.TryStartFireIn(corpses[i].Position, map, Rand.Range(distanceModifier / 2f, distanceModifier)); //} } for (int i = 0; i < plants.Count; i++) { float distanceModifier = 1f / (plants[i].Position - currentTarget.Cell).LengthHorizontal; if (distanceModifier > 1f) { distanceModifier = 1f; } if (plants[i].def.plant.IsTree) { if (Rand.Chance(distanceModifier / 2f)) { plants[i].TryAttachFire(Rand.Range(distanceModifier / 3f, distanceModifier / 2f)); FireUtility.TryStartFireIn(plants[i].Position, map, Rand.Range(distanceModifier / 3f, distanceModifier / 2f)); } } else { if (Rand.Chance(distanceModifier)) { plants[i].TryAttachFire(Rand.Range(distanceModifier / 2f, distanceModifier)); FireUtility.TryStartFireIn(plants[i].Position, map, Rand.Range(distanceModifier / 2f, distanceModifier)); } } } List <IntVec3> cellList = GenRadial.RadialCellsAround(this.currentTarget.Cell, this.UseAbilityProps.TargetAoEProperties.range, true).ToList(); bool raining = map.weatherManager.RainRate > 0f || map.weatherManager.SnowRate > 0f; for (int i = 0; i < cellList.Count; i++) { cellList[i] = cellList[i].ClampInsideMap(map); if (cellList[i].GetSnowDepth(map) > 0f) { map.snowGrid.SetDepth(cellList[i], 0f); MoteMaker.ThrowSmoke(cellList[i].ToVector3Shifted(), map, Rand.Range(.8f, 1.6f)); Thing smoke = ThingMaker.MakeThing(ThingDefOf.Gas_Smoke, null); GenSpawn.Spawn(smoke, cellList[i], map, WipeMode.Vanish); } else if (raining || cellList[i].GetTerrain(map).IsWater) { Thing smoke = ThingMaker.MakeThing(ThingDefOf.Gas_Smoke, null); GenSpawn.Spawn(smoke, cellList[i], map, WipeMode.Vanish); } TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_AirPuff, cellList[i].ToVector3Shifted(), map, 2.5f, .05f, .05f, Rand.Range(2f, 3f), Rand.Range(-60, 60), .5f, -70, Rand.Range(0, 360)); } } this.burstShotsLeft = 0; return(true); }
public static bool PlaceItem(Thing t, IntVec3 cell, bool forbid, Map map, bool firstAbsorbStack = false) { Action <Thing> effect = (item) => { item.def.soundDrop.PlayOneShot(item); MoteMaker.ThrowDustPuff(item.Position, map, 0.5f); }; Func <bool> absorb = () => { cell.SlotGroupCells(map).SelectMany(c => c.GetThingList(map)).Where(i => i.def == t.def).ForEach(i => i.TryAbsorbStack(t, true)); if (t.stackCount == 0) { effect(t); return(true); } return(false); }; // fast check: if (!firstAbsorbStack && cell.GetThingList(map).Where(ti => ti.def.category == ThingCategory.Item).Count() == 0) { GenPlace.TryPlaceThing(t, cell, map, ThingPlaceMode.Direct); if (forbid) { t.SetForbidden(forbid); } effect(t); return(true); } if (absorb()) { return(true); } // IsValidStorageFor should also work for multi-storage mods if (StoreUtility.IsValidStorageFor(cell, map, t)) { GenPlace.TryPlaceThing(t, cell, map, ThingPlaceMode.Direct); if (forbid) { t.SetForbidden(forbid); } effect(t); return(true); } var o = cell.SlotGroupCells(map).Where(c => c.IsValidStorageFor(map, t)) .Where(c => c.GetThingList(map).Where(b => b.def.category == ThingCategory.Building).All(b => !(b is Building_BeltConveyor))) .FirstOption(); if (o.HasValue) { GenPlace.TryPlaceThing(t, o.Value, map, ThingPlaceMode.Near); if (forbid) { t.SetForbidden(forbid); } effect(t); return(true); } return(false); }
private DamageWorker.DamageResult ApplyToPawn(DamageInfo dinfo, Pawn pawn) { DamageWorker.DamageResult damageResult = new DamageWorker.DamageResult(); DamageWorker.DamageResult result; if (dinfo.Amount <= 0f) { result = damageResult; } else if (!DebugSettings.enablePlayerDamage && pawn.Faction == Faction.OfPlayer) { result = damageResult; } else { Map mapHeld = pawn.MapHeld; bool spawnedOrAnyParentSpawned = pawn.SpawnedOrAnyParentSpawned; if (dinfo.AllowDamagePropagation && dinfo.Amount >= (float)dinfo.Def.minDamageToFragment) { int num = Rand.RangeInclusive(2, 4); for (int i = 0; i < num; i++) { DamageInfo dinfo2 = dinfo; dinfo2.SetAmount(dinfo.Amount / (float)num); this.ApplyDamageToPart(dinfo2, pawn, damageResult); } } else { this.ApplyDamageToPart(dinfo, pawn, damageResult); this.ApplySmallPawnDamagePropagation(dinfo, pawn, damageResult); } if (damageResult.wounded) { DamageWorker_AddInjury.PlayWoundedVoiceSound(dinfo, pawn); pawn.Drawer.Notify_DamageApplied(dinfo); } if (damageResult.headshot && pawn.Spawned) { MoteMaker.ThrowText(new Vector3((float)pawn.Position.x + 1f, (float)pawn.Position.y, (float)pawn.Position.z + 1f), pawn.Map, "Headshot".Translate(), Color.white, -1f); if (dinfo.Instigator != null) { Pawn pawn2 = dinfo.Instigator as Pawn; if (pawn2 != null) { pawn2.records.Increment(RecordDefOf.Headshots); } } } if ((damageResult.deflected || damageResult.diminished) && spawnedOrAnyParentSpawned) { EffecterDef effecterDef; if (damageResult.deflected) { if (damageResult.deflectedByMetalArmor && dinfo.Def.canUseDeflectMetalEffect) { if (dinfo.Def == DamageDefOf.Bullet) { effecterDef = EffecterDefOf.Deflect_Metal_Bullet; } else { effecterDef = EffecterDefOf.Deflect_Metal; } } else if (dinfo.Def == DamageDefOf.Bullet) { effecterDef = EffecterDefOf.Deflect_General_Bullet; } else { effecterDef = EffecterDefOf.Deflect_General; } } else if (damageResult.diminishedByMetalArmor) { effecterDef = EffecterDefOf.DamageDiminished_Metal; } else { effecterDef = EffecterDefOf.DamageDiminished_General; } if (pawn.health.deflectionEffecter == null || pawn.health.deflectionEffecter.def != effecterDef) { if (pawn.health.deflectionEffecter != null) { pawn.health.deflectionEffecter.Cleanup(); pawn.health.deflectionEffecter = null; } pawn.health.deflectionEffecter = effecterDef.Spawn(); } pawn.health.deflectionEffecter.Trigger(pawn, dinfo.Instigator ?? pawn); if (damageResult.deflected) { pawn.Drawer.Notify_DamageDeflected(dinfo); } } if (!damageResult.deflected && spawnedOrAnyParentSpawned) { ImpactSoundUtility.PlayImpactSound(pawn, dinfo.Def.impactSoundType, mapHeld); } result = damageResult; } return(result); }
protected override bool TryCastShot() { bool flag = false; this.TargetsAoE.Clear(); //this.UpdateTargets(); this.FindTargets(); int shotsPerBurst = this.ShotsPerBurst; MagicPowerSkill pwr = base.CasterPawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SootheAnimal.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SootheAnimal_pwr"); MagicPowerSkill ver = base.CasterPawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SootheAnimal.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SootheAnimal_ver"); verVal = ver.level; pwrVal = pwr.level; if (base.CasterPawn.story.traits.HasTrait(TorannMagicDefOf.Faceless)) { MightPowerSkill mpwr = base.CasterPawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr"); MightPowerSkill mver = base.CasterPawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver"); pwrVal = mpwr.level; verVal = mver.level; } bool flag2 = this.UseAbilityProps.AbilityTargetCategory != AbilityTargetCategory.TargetAoE && this.TargetsAoE.Count > 1; if (flag2) { this.TargetsAoE.RemoveRange(0, this.TargetsAoE.Count - 1); } for (int i = 0; i < this.TargetsAoE.Count; i++) { if (this.TargetsAoE[i].Thing.Faction != this.CasterPawn.Faction) { Pawn newPawn = this.TargetsAoE[i].Thing as Pawn; bool flag1 = (newPawn.mindState.mentalStateHandler.CurStateDef == MentalStateDefOf.ManhunterPermanent) || (newPawn.mindState.mentalStateHandler.CurStateDef == MentalStateDefOf.Manhunter); if (flag1) { if (newPawn.kindDef.RaceProps.Animal) { newPawn.mindState.mentalStateHandler.Reset(); newPawn.jobs.StopAll(); MoteMaker.ThrowMicroSparks(newPawn.Position.ToVector3().normalized, newPawn.Map); float sev = Rand.Range(pwrVal, 2 * pwrVal); HealthUtility.AdjustSeverity(newPawn, TorannMagicDefOf.TM_AntiManipulation, sev); sev = Rand.Range(pwrVal, 2 * pwrVal); HealthUtility.AdjustSeverity(newPawn, TorannMagicDefOf.TM_AntiMovement, sev); sev = Rand.Range(pwrVal, 2 * pwrVal); HealthUtility.AdjustSeverity(newPawn, TorannMagicDefOf.TM_AntiBreathing, sev); sev = Rand.Range(pwrVal, 2 * pwrVal); HealthUtility.AdjustSeverity(newPawn, TorannMagicDefOf.TM_AntiSight, sev); if (pwrVal > 0) { TM_MoteMaker.ThrowSiphonMote(newPawn.Position.ToVector3(), newPawn.Map, 1f); } } } if (!flag1) { if (newPawn.kindDef.RaceProps.Animal) { newPawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent, null, true, false, null); float sev = Rand.Range(pwrVal, 2 * pwrVal); HealthUtility.AdjustSeverity(newPawn, TorannMagicDefOf.TM_Manipulation, sev); sev = Rand.Range(pwrVal, 2 * pwrVal); HealthUtility.AdjustSeverity(newPawn, TorannMagicDefOf.TM_Movement, sev); sev = Rand.Range(pwrVal, 2 * pwrVal); HealthUtility.AdjustSeverity(newPawn, TorannMagicDefOf.TM_Breathing, sev); sev = Rand.Range(pwrVal, 2 * pwrVal); HealthUtility.AdjustSeverity(newPawn, TorannMagicDefOf.TM_Sight, sev); MoteMaker.ThrowMicroSparks(newPawn.Position.ToVector3().normalized, newPawn.Map); if (pwrVal > 0) { TM_MoteMaker.ThrowManaPuff(newPawn.Position.ToVector3(), newPawn.Map, 1f); } } } } } this.PostCastShot(flag, out flag); return(flag); }
// RimWorld.Verb_MeleeAttack public static void DamageInfosToApply_PostFix(Verb_MeleeAttack __instance, ref IEnumerable <DamageInfo> __result, LocalTargetInfo target) { var newList = new List <DamageInfo>(); //__result = null; var ownerEquipment = __instance.ownerEquipment; if (ownerEquipment != null) { //Log.Message("1"); var comp = ownerEquipment.AllComps.FirstOrDefault(x => x is CompSlotLoadable); if (comp != null) { //Log.Message("2"); var compSlotLoadable = comp as CompSlotLoadable; if (compSlotLoadable.Slots != null && compSlotLoadable.Slots.Count > 0) { //Log.Message("3"); var statSlots = compSlotLoadable.Slots.FindAll(z => !z.IsEmpty() && ((SlotLoadableDef)z.def).doesChangeStats); if (statSlots != null && statSlots.Count > 0) { foreach (var slot in statSlots) { //Log.Message("5"); var slotBonus = slot.SlotOccupant.TryGetComp <CompSlottedBonus>(); if (slotBonus != null) { //Log.Message("6"); var superClass = __instance.GetType().BaseType; if (slotBonus.Props.damageDef != null) { //Log.Message("7"); var num = __instance.verbProps.AdjustedMeleeDamageAmount(__instance, __instance.CasterPawn, __instance.ownerEquipment); var def = __instance.verbProps.meleeDamageDef; BodyPartGroupDef weaponBodyPartGroup = null; HediffDef weaponHediff = null; if (__instance.CasterIsPawn) { if (num >= 1f) { weaponBodyPartGroup = __instance.verbProps.linkedBodyPartsGroup; if (__instance.ownerHediffComp != null) { weaponHediff = __instance.ownerHediffComp.Def; } } else { num = 1f; def = DamageDefOf.Blunt; } } //Log.Message("9"); ThingDef def2; if (__instance.ownerEquipment != null) { def2 = __instance.ownerEquipment.def; } else { def2 = __instance.CasterPawn.def; } //Log.Message("10"); var angle = (target.Thing.Position - __instance.CasterPawn.Position) .ToVector3(); //Log.Message("11"); var caster = __instance.caster; //Log.Message("12"); var newdamage = GenMath.RoundRandom(num); // Log.Message("applying damage "+newdamage+" out of "+num); var damageInfo = new DamageInfo(slotBonus.Props.damageDef, newdamage, slotBonus.Props.armorPenetration, -1f, caster, null, def2); damageInfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside); damageInfo.SetWeaponBodyPartGroup(weaponBodyPartGroup); damageInfo.SetWeaponHediff(weaponHediff); damageInfo.SetAngle(angle); //Log.Message("13"); newList.Add(damageInfo); __result = newList.AsEnumerable(); } var vampiricEffect = slotBonus.Props.vampiricHealChance; if (vampiricEffect != null) { //Log.Message("vampiricHealingCalled"); var randValue = Rand.Value; //Log.Message("randValue = " + randValue.ToString()); if (randValue <= vampiricEffect.chance) { MoteMaker.ThrowText(__instance.CasterPawn.DrawPos, __instance.CasterPawn.Map, "Vampiric Effect: Success", 6f); //MoteMaker.ThrowText(__instance.CasterPawn.DrawPos, __instance.CasterPawn.Map, "Success".Translate(), 6f); ApplyHealing(__instance.caster, vampiricEffect.woundLimit, target.Thing); } } } } } } } } }
protected new bool?TryLaunchProjectile(ThingDef projectileDef, LocalTargetInfo launchTarget) { DebugMessage(launchTarget.ToString()); var flag = TryFindShootLineFromTo(caster.Position, launchTarget, out var shootLine); if (verbProps.stopBurstWithoutLos && !flag) { DebugMessage("Targeting cancelled"); return(false); } var drawPos = caster.DrawPos; var projectile2 = (Projectile_AbilityBase)GenSpawn.Spawn(projectileDef, shootLine.Source, caster.Map); projectile2.extraDamages = UseAbilityProps.extraDamages; projectile2.localSpawnThings = UseAbilityProps.thingsToSpawn; verbProps.soundCast?.PlayOneShot(new TargetInfo(caster.Position, caster.Map, false)); verbProps.soundCastTail?.PlayOneShotOnCamera(); if (DebugViewSettings.drawShooting) { MoteMaker.ThrowText(caster.DrawPos, caster.Map, "ToHit", -1f); } if (this.verbProps.forcedMissRadius > 0.5f) { float num = VerbUtility.CalculateAdjustedForcedMiss(this.verbProps.forcedMissRadius, this.currentTarget.Cell - this.caster.Position); if (num > 0.5f) { int max = GenRadial.NumCellsInRadius(num); int num2 = Rand.Range(0, max); if (num2 > 0) { IntVec3 c = this.currentTarget.Cell + GenRadial.RadialPattern[num2]; this.ThrowDebugText("ToRadius"); this.ThrowDebugText("Rad\nDest", c); ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld; if (Rand.Chance(0.5f)) { projectileHitFlags = ProjectileHitFlags.All; } if (!this.canHitNonTargetPawnsNow) { projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns; } // projectile2.Launch(CasterPawn, drawPos, c, this.currentTarget, projectileHitFlags, caster, null); projectile2.Launch(caster, Ability.Def, drawPos, c, projectileHitFlags, null, UseAbilityProps.hediffsToApply, UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn); return(true); } } } ShotReport shotReport = ShotReport.HitReportFor(this.caster, this, this.currentTarget); Thing randomCoverToMissInto = shotReport.GetRandomCoverToMissInto(); ThingDef targetCoverDef = (randomCoverToMissInto == null) ? null : randomCoverToMissInto.def; if (!Rand.Chance(shotReport.AimOnTargetChance_IgnoringPosture)) { shootLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget); this.ThrowDebugText("ToWild" + ((!this.canHitNonTargetPawnsNow) ? string.Empty : "\nchntp")); this.ThrowDebugText("Wild\nDest", shootLine.Dest); ProjectileHitFlags projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld; if (Rand.Chance(0.5f) && this.canHitNonTargetPawnsNow) { projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns; } // projectile2.Launch(CasterPawn, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags2, caster, targetCoverDef); projectile2.Launch(caster, Ability.Def, drawPos, shootLine.Dest, projectileHitFlags2, null, UseAbilityProps.hediffsToApply, UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn); return(true); } if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn && !Rand.Chance(shotReport.PassCoverChance)) { this.ThrowDebugText("ToCover" + ((!this.canHitNonTargetPawnsNow) ? string.Empty : "\nchntp")); this.ThrowDebugText("Cover\nDest", randomCoverToMissInto.Position); ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld; if (this.canHitNonTargetPawnsNow) { projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns; } // projectile2.Launch(CasterPawn, drawPos, randomCoverToMissInto, this.currentTarget, projectileHitFlags3, caster, targetCoverDef); projectile2.Launch(caster, Ability.Def, drawPos, randomCoverToMissInto, projectileHitFlags3, null, UseAbilityProps.hediffsToApply, UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn); return(true); } ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget; if (this.canHitNonTargetPawnsNow) { projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns; } if (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full) { projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld; } this.ThrowDebugText("ToHit" + ((!this.canHitNonTargetPawnsNow) ? string.Empty : "\nchntp")); if (this.currentTarget.Thing != null) { // projectile2.Launch(CasterPawn, drawPos, this.currentTarget, this.currentTarget, projectileHitFlags4, caster, targetCoverDef); projectile2.Launch(caster, Ability.Def, drawPos, currentTarget, projectileHitFlags4, null, UseAbilityProps.hediffsToApply, UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn); this.ThrowDebugText("Hit\nDest", this.currentTarget.Cell); } else { // projectile2.Launch(CasterPawn, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags4, caster, targetCoverDef); projectile2.Launch(caster, Ability.Def, drawPos, shootLine.Dest, projectileHitFlags4, null, UseAbilityProps.hediffsToApply, UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn); this.ThrowDebugText("Hit\nDest", shootLine.Dest); } /* * ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget; * if (this.canHitNonTargetPawnsNow) * { * projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns; * } * if (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full) * { * projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld; * } * DebugMessage(launchTarget.ToString()); * projectile2.Launch(caster, Ability.Def, drawPos, launchTarget, projectileHitFlags4, null, * UseAbilityProps.hediffsToApply, * UseAbilityProps.mentalStatesToApply, UseAbilityProps.thingsToSpawn); */ return(true); }
protected override bool TryCastShot() { bool result = false; bool arg_40_0; Thing targetThing = this.currentTarget.Thing; if (this.currentTarget != null && base.CasterPawn != null) { IntVec3 arg_29_0 = this.currentTarget.Cell; Vector3 vector = this.currentTarget.CenterVector3; arg_40_0 = this.currentTarget.Cell.IsValid; arg_41_0 = vector.InBounds(base.CasterPawn.Map); arg_42_0 = targetThing is Pawn; } else { arg_40_0 = false; } bool flag = arg_40_0; bool flag2 = arg_41_0; bool flag3 = arg_42_0; if (flag) { if (flag2 & flag3) { Pawn p = this.CasterPawn; Pawn targetPawn = targetThing as Pawn; bool drafted = p.Drafted; bool tDrafted = false; if (targetThing is Pawn && targetPawn.IsColonist && targetPawn.Drafted) { tDrafted = true; } Map map = this.CasterPawn.Map; IntVec3 cell = this.CasterPawn.Position; IntVec3 targetCell = targetPawn.Position; try { if (this.CasterPawn.IsColonist) { this.CasterPawn.DeSpawn(); targetPawn.DeSpawn(); GenSpawn.Spawn(p, this.currentTarget.Cell, map); GenSpawn.Spawn(targetPawn, cell, map); p.drafter.Drafted = drafted; targetPawn.drafter.Drafted = tDrafted; CameraJumper.TryJumpAndSelect(p); CompAbilityUserMight comp = this.CasterPawn.GetComp <CompAbilityUserMight>(); MightPowerSkill ver = comp.MightData.MightPowerSkill_Transpose.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Transpose_ver"); if (ver.level < 1) { HealthUtility.AdjustSeverity(p, HediffDef.Named("TM_DisorientedVomit"), 1f); } HealthUtility.AdjustSeverity(p, TorannMagicDefOf.TM_ReversalHD, 2f + (ver.level)); if (targetPawn.HostileTo(this.CasterPawn) && targetPawn.needs.food != null) { if (Rand.Chance(TM_Calc.GetSpellSuccessChance(this.CasterPawn, targetPawn, true))) { HealthUtility.AdjustSeverity(targetPawn, HediffDef.Named("TM_DisorientedVomit"), 1f); } else { MoteMaker.ThrowText(targetPawn.DrawPos, targetPawn.Map, "TM_ResistedSpell".Translate(), -1); } } else { if (ver.level < 2 && targetPawn.needs.food != null) { HealthUtility.AdjustSeverity(targetPawn, HediffDef.Named("TM_DisorientedVomit"), 1f); } } } else { this.CasterPawn.DeSpawn(); targetPawn.DeSpawn(); GenSpawn.Spawn(p, this.currentTarget.Cell, map); GenSpawn.Spawn(targetPawn, cell, map); if (targetPawn.IsColonist && !p.IsColonist) { TM_Action.SpellAffectedPlayerWarning(targetPawn); } } } catch { Log.Message("Exception occured when trying to transpose - recovered pawns at original positions"); if (!this.CasterPawn.Spawned) { GenSpawn.Spawn(p, cell, map); } if (!targetPawn.Spawned) { GenSpawn.Spawn(targetPawn, targetCell, map); } } //this.Ability.PostAbilityAttempt(); //this.CasterPawn.SetPositionDirect(this.currentTarget.Cell); //base.CasterPawn.SetPositionDirect(this.currentTarget.Cell); //this.CasterPawn.pather.ResetToCurrentPosition(); result = true; } else { Messages.Message("InvalidTargetLocation".Translate(), MessageTypeDefOf.RejectInput); } } else { Log.Warning("failed to TryCastShot"); } this.burstShotsLeft = 0; //this.ability.TicksUntilCasting = (int)base.UseAbilityProps.SecondsToRecharge * 60; return(result); }
protected override Toil DoBill() { var tableThing = job.GetTarget(BillGiverInd).Thing as Building_WorkTable; var refuelableComp = tableThing.GetComp <CompRefuelable>(); var toil = new Toil(); toil.initAction = delegate { var objectThing = job.GetTarget(IngredientInd).Thing; job.bill.Notify_DoBillStarted(pawn); costHitPointsPerCycle = (int)(objectThing.MaxHitPoints * Settings.costFromMaxHitPoints); workCycleProgress = workCycle = Math.Max(job.bill.recipe.workAmount, 10f); }; toil.tickAction = delegate { var objectThing = job.GetTarget(IngredientInd).Thing; if (objectThing == null || objectThing.Destroyed) { pawn.jobs.EndCurrentJob(JobCondition.Incompletable); } workCycleProgress -= StatExtension.GetStatValue(pawn, StatDefOf.WorkToMake, true); tableThing.UsedThisTick(); if (!(tableThing.CurrentlyUsableForBills() && (refuelableComp == null || refuelableComp.HasFuel))) { pawn.jobs.EndCurrentJob(JobCondition.Incompletable); } if (workCycleProgress <= 0) { int remainingHitPoints = objectThing.MaxHitPoints - objectThing.HitPoints; if (remainingHitPoints > 0) { objectThing.HitPoints += (int)Math.Min(remainingHitPoints, costHitPointsPerCycle); } float skillPerc = 0.5f; var skillDef = job.RecipeDef.workSkill; if (skillDef != null) { var skill = pawn.skills.GetSkill(skillDef); if (skill != null) { skillPerc = (float)skill.Level / 20f; skill.Learn(0.11f * job.RecipeDef.workSkillLearnFactor); } } if (Settings.chances[objectThing.def.techLevel] > 1 - Mathf.Pow(Rand.Value, 1 + skillPerc * 3f)) { objectThing.HitPoints -= Rand.RangeInclusive(costHitPointsPerCycle, costHitPointsPerCycle * 4); MoteMaker.ThrowText(pawn.DrawPos, pawn.Map, "Failed"); } pawn.GainComfortFromCellIfPossible(); if (objectThing.HitPoints <= 0) { // recycling whats left... float skillFactor = Mathf.Lerp(0.5f, 1.5f, skillPerc); var list = JobDriverUtils.Reclaim(objectThing, skillFactor * 0.1f); pawn.Map.reservationManager.Release(job.targetB, pawn, job); objectThing.Destroy(DestroyMode.Vanish); if (list.Count > 1) { for (int j = 1; j < list.Count; j++) { if (!GenPlace.TryPlaceThing(list [j], pawn.Position, pawn.Map, ThingPlaceMode.Near, null)) { Log.Error("MendAndRecycle :: " + pawn + " could not drop recipe product " + list [j] + " near " + pawn.Position); } } } list[0].SetPositionDirect(pawn.Position); job.targetB = list[0]; job.bill.Notify_IterationCompleted(pawn, list); pawn.Map.reservationManager.Reserve(pawn, job, job.targetB, 1); ReadyForNextToil(); } else if (objectThing.HitPoints == objectThing.MaxHitPoints) { // fixed! if (Settings.removesDeadman && objectThing is Apparel mendApparel) { ApparelWornByCorpseInt.SetValue(mendApparel, false); } var list = new List <Thing> (); list.Add(objectThing); job.bill.Notify_IterationCompleted(pawn, list); ReadyForNextToil(); } else if (objectThing.HitPoints > objectThing.MaxHitPoints) { Log.Error("MendAndRecycle :: This should never happen! HitPoints > MaxHitPoints"); pawn.jobs.EndCurrentJob(JobCondition.Incompletable); } workCycleProgress = workCycle; } }; toil.defaultCompleteMode = ToilCompleteMode.Never; toil.WithEffect(() => job.bill.recipe.effectWorking, BillGiverInd); toil.PlaySustainerOrSound(() => toil.actor.CurJob.bill.recipe.soundWorking); toil.WithProgressBar(BillGiverInd, () => { var objectThing = job.GetTarget(IngredientInd).Thing; return((float)objectThing.HitPoints / (float)objectThing.MaxHitPoints); }, false, 0.5f); toil.FailOn(() => { var billGiver = job.GetTarget(BillGiverInd).Thing as IBillGiver; return(job.bill.suspended || job.bill.DeletedOrDereferenced || (billGiver != null && !billGiver.CurrentlyUsableForBills())); }); return(toil); }
public void SpawnCycle() { System.Random random = new System.Random(); random = new System.Random(); int rnd = GenMath.RoundRandom(random.Next(0, 8)); IntVec3 curCell; IEnumerable <IntVec3> targets = GenRadial.RadialCellsAround(this.Position, 2, true); for (int j = 0; j < targets.Count(); j++) { curCell = targets.ToArray <IntVec3>()[j]; if (curCell.InBounds(this.Map) && curCell.IsValid && curCell.Walkable(this.Map)) { SpawnThings rogueElemental = new SpawnThings(); if (rnd < 2) { if (Rand.Chance(0.01f)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1f); MoteMaker.ThrowMicroSparks(curCell.ToVector3(), this.Map); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); rogueElemental.def = TorannMagicDefOf.TM_GreaterEarth_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_GreaterEarth_Elemental"); } else if (Rand.Chance(0.035f)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1f); MoteMaker.ThrowMicroSparks(curCell.ToVector3(), this.Map); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); rogueElemental.def = TorannMagicDefOf.TM_Earth_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_Earth_Elemental"); } else if (Rand.Chance(0.12f)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1f); MoteMaker.ThrowMicroSparks(curCell.ToVector3(), this.Map); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); rogueElemental.def = TorannMagicDefOf.TM_LesserEarth_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_LesserEarth_Elemental"); } else { rogueElemental = null; } } else if (rnd >= 2 && rnd < 4) { if (Rand.Chance(0.01f)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1); MoteMaker.ThrowMicroSparks(curCell.ToVector3(), this.Map); MoteMaker.ThrowFireGlow(curCell, this.Map, 1); MoteMaker.ThrowHeatGlow(curCell, this.Map, 1); rogueElemental.def = TorannMagicDefOf.TM_GreaterFire_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_GreaterFire_Elemental"); } else if (Rand.Chance(0.035f)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1); MoteMaker.ThrowMicroSparks(curCell.ToVector3(), this.Map); MoteMaker.ThrowFireGlow(curCell, this.Map, 1); MoteMaker.ThrowHeatGlow(curCell, this.Map, 1); rogueElemental.def = TorannMagicDefOf.TM_Fire_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_Fire_Elemental"); } else if (Rand.Chance(0.12f)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1); MoteMaker.ThrowMicroSparks(curCell.ToVector3(), this.Map); MoteMaker.ThrowFireGlow(curCell, this.Map, 1); MoteMaker.ThrowHeatGlow(curCell, this.Map, 1); rogueElemental.def = TorannMagicDefOf.TM_LesserFire_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_LesserFire_Elemental"); } else { rogueElemental = null; } } else if (rnd >= 4 && rnd < 6) { if (Rand.Chance(0.01f)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.blue); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.blue); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.blue); rogueElemental.def = TorannMagicDefOf.TM_GreaterWater_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_GreaterWater_Elemental"); } else if (Rand.Chance(0.035f)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.blue); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.blue); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.blue); rogueElemental.def = TorannMagicDefOf.TM_Water_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_Water_Elemental"); } else if (Rand.Chance(0.12f)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.blue); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.blue); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.blue); rogueElemental.def = TorannMagicDefOf.TM_LesserWater_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_LesserWater_Elemental"); } else { rogueElemental = null; } } else { if (Rand.Chance(0.01f)) { rogueElemental.def = TorannMagicDefOf.TM_GreaterWind_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_GreaterWind_Elemental"); MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1 + 1 * 2); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.white); } else if (Rand.Chance(0.035f)) { rogueElemental.def = TorannMagicDefOf.TM_Wind_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_Wind_Elemental"); MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1 + 1 * 2); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.white); } else if (Rand.Chance(0.12f)) { rogueElemental.def = TorannMagicDefOf.TM_LesserWind_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_LesserWind_Elemental"); MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1 + 1 * 2); SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.white); } else { rogueElemental = null; } } if (rogueElemental != null) { SingleSpawnLoop(rogueElemental, curCell, this.Map); } } } }
protected override bool TryCastShot() { bool flag = false; this.TargetsAoE.Clear(); this.UpdateTargets(); MagicPowerSkill pwr = base.CasterPawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Polymorph.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Polymorph_pwr"); MagicPowerSkill ver = base.CasterPawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Polymorph.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Polymorph_ver"); verVal = ver.level; pwrVal = pwr.level; CompAbilityUserMagic comp = base.CasterPawn.GetComp <CompAbilityUserMagic>(); this.arcaneDmg = base.CasterPawn.GetComp <CompAbilityUserMagic>().arcaneDmg; this.duration += Mathf.RoundToInt(600 * verVal * this.arcaneDmg); if (base.CasterPawn.story.traits.HasTrait(TorannMagicDefOf.Faceless)) { MightPowerSkill mpwr = base.CasterPawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr"); MightPowerSkill mver = base.CasterPawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver"); pwrVal = mpwr.level; verVal = mver.level; } ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef(); if (settingsRef.AIHardMode && !this.CasterPawn.IsColonist) { verVal = 2; pwrVal = 3; } bool flag2 = this.UseAbilityProps.AbilityTargetCategory != AbilityTargetCategory.TargetAoE && this.TargetsAoE.Count > 1; if (flag2) { this.TargetsAoE.RemoveRange(0, this.TargetsAoE.Count - 1); } for (int i = 0; i < this.TargetsAoE.Count; i++) { Pawn newPawn = this.TargetsAoE[i].Thing as Pawn; if (newPawn != this.CasterPawn) { CompPolymorph compPoly = newPawn.GetComp <CompPolymorph>(); if (compPoly != null && compPoly.Original != null && compPoly.TicksLeft > 0) { compPoly.Temporary = true; compPoly.TicksLeft = 0; } else { float enchantChance = .5f; if (!TM_Calc.IsRobotPawn(newPawn)) { enchantChance = (.5f + (.1f * pwrVal) * TM_Calc.GetSpellSuccessChance(this.CasterPawn, newPawn)); } else { enchantChance = (.0f + (.2f * pwrVal) * TM_Calc.GetSpellSuccessChance(this.CasterPawn, newPawn)); } if (Rand.Chance(enchantChance) && newPawn.GetComp <CompPolymorph>() != null) { FactionDef fDef = null; if (newPawn.Faction != null) { fDef = newPawn.Faction.def; } SpawnThings spawnThing = new SpawnThings(); spawnThing.factionDef = fDef; spawnThing.spawnCount = 1; spawnThing.temporary = false; GetPolyMinMax(newPawn); spawnThing = TM_Action.AssignRandomCreatureDef(spawnThing, this.min, this.max); if (spawnThing.def == null || spawnThing.kindDef == null) { spawnThing.def = ThingDef.Named("Rat"); spawnThing.kindDef = PawnKindDef.Named("Rat"); Log.Message("random creature was null"); } Pawn polymorphedPawn = TM_Action.PolymorphPawn(this.CasterPawn, newPawn, newPawn, spawnThing, newPawn.Position, true, duration, newPawn.Faction); if (polymorphedPawn.Faction != this.CasterPawn.Faction && polymorphedPawn.mindState != null && Rand.Chance(Mathf.Clamp((.2f * this.pwrVal), 0f, .5f))) { polymorphedPawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Berserk, "wild beast!", true, false, null, true); } if (this.verVal >= 3) { polymorphedPawn.GetComp <CompPolymorph>().Temporary = false; } MoteMaker.ThrowSmoke(newPawn.DrawPos, newPawn.Map, 2); MoteMaker.ThrowMicroSparks(newPawn.DrawPos, newPawn.Map); MoteMaker.ThrowHeatGlow(newPawn.Position, newPawn.Map, 2); newPawn.DeSpawn(); if (polymorphedPawn.IsColonist && !base.CasterPawn.IsColonist) { TM_Action.SpellAffectedPlayerWarning(polymorphedPawn); } } else { MoteMaker.ThrowText(newPawn.DrawPos, newPawn.Map, "TM_ResistedSpell".Translate(), -1); } } } } this.PostCastShot(flag, out flag); return(flag); }
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; } } }
/// <summary> /// Generates a series of actions (toils) that the pawn should perform. /// </summary> /// <returns>Ienumerable of type Toil</returns> /// <remarks>Remember that, in the case of jobs, effectively the entire method is executed before any actual activity occurs.</remarks> protected override IEnumerable <Toil> MakeNewToils() { // Error checking and 'helpful' messages for what is wrong. if (holder == null) // A later check will catch this (failon) but that fails silently. { Log.Error(errorBase + "TargetThingA is null. A Pawn is required to perform a reload."); yield return(null); } if (weapon == null) // Required. { Log.Error(errorBase + "TargetThingB is null. A weapon (ThingWithComps) is required to perform a reload."); yield return(null); } if (compReloader == null) // Required. { Log.Error(errorBase + pawn + " tried to do reload job on " + weapon.LabelCap + " which doesn't have a required CompAmmoUser."); yield return(null); } if (holder != pawn) // Helps restrict what this job does, not really necessary and may work fine (though possibly undesirable behavior) without this check. { Log.Error(errorBase + "TargetThingA (" + holder.Name + ") is not the same Pawn (" + pawn.Name + ") that was given the job."); yield return(null); } // get the state of the job (inventory vs other) at the start. reloadingInventory = weaponInInventory; reloadingEquipment = weaponEquipped; // A couple more more 'helpful' error check/message. if (!reloadingInventory && !reloadingEquipment) // prevent some bad states/behavior on FailOn and job text. { Log.Error(errorBase + "Unable to find the weapon to be reloaded (" + weapon.LabelCap + ") in the inventory nor equipment of " + pawn.Name); yield return(null); } if (reloadingInventory && reloadingEquipment) // prevent incorrect information on job text. If somehow this was true may cause a FailOn to trip. { Log.Error(errorBase + "Something went spectacularly wrong as the weapon to be reloaded was found in both the Pawn's equipment AND inventory at the same time."); yield return(null); } // current state of equipment, want to interrupt the reload if a pawn's equipment changes. initEquipment = pawn.equipment?.Primary; // choose ammo to be loaded and set failstate for no ammo in inventory if (compReloader.UseAmmo) { this.FailOn(() => !compReloader.TryFindAmmoInInventory(out initAmmo)); } // setup fail states, if something goes wrong with the pawn performing the reload, the weapon, or something else that we want to fail on. this.FailOnDespawnedOrNull(indReloader); this.FailOnMentalState(indReloader); this.FailOnDestroyedOrNull(indWeapon); this.FailOn(HasNoGunOrAmmo); // Throw mote if (compReloader.ShouldThrowMote && holder.Map != null) //holder.Map is temporarily null after game load, skip mote if a pawn was reloading when game was saved { MoteMaker.ThrowText(pawn.Position.ToVector3Shifted(), holder.Map, string.Format("CE_ReloadingMote".Translate(), weapon.def.LabelCap)); } //Toil of do-nothing Toil waitToil = new Toil() { actor = pawn }; // actor was always null in testing... waitToil.initAction = () => waitToil.actor.pather.StopDead(); waitToil.defaultCompleteMode = ToilCompleteMode.Delay; waitToil.defaultDuration = Mathf.CeilToInt(compReloader.Props.reloadTime.SecondsToTicks() / pawn.GetStatValue(CE_StatDefOf.ReloadSpeed)); yield return(waitToil.WithProgressBarToilDelay(indReloader)); //Actual reloader Toil reloadToil = new Toil(); reloadToil.AddFinishAction(() => compReloader.LoadAmmo(initAmmo)); yield return(reloadToil); // If reloading one shot at a time and if possible to reload, jump back to do-nothing toil System.Func <bool> jumpCondition = () => compReloader.Props.reloadOneAtATime && compReloader.CurMagCount < compReloader.Props.magazineSize && (!compReloader.UseAmmo || compReloader.TryFindAmmoInInventory(out initAmmo)); Toil jumpToil = Toils_Jump.JumpIf(waitToil, jumpCondition); yield return(jumpToil); //Continue previous job if possible Toil continueToil = new Toil { defaultCompleteMode = ToilCompleteMode.Instant }; yield return(continueToil); }
protected new void Impact(Thing hitThing) { bool flag = hitThing == null; if (flag) { Pawn pawn; bool flag2 = (pawn = base.Position.GetThingList(base.Map).FirstOrDefault((Thing x) => x == this.assignedTarget) as Pawn) != null; if (flag2) { hitThing = pawn; } } bool hasValue = this.impactDamage.HasValue; if (hasValue) { for (int i = 0; i < this.timesToDamage; i++) { bool flag3 = this.damageLaunched; if (flag3) { this.flyingThing.TakeDamage(this.impactDamage.Value); } else { hitThing.TakeDamage(this.impactDamage.Value); } } bool flag4 = this.explosion; if (flag4) { GenExplosion.DoExplosion(base.Position, base.Map, 0.9f, DamageDefOf.Stun, this, -1, 0, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false); } } try { SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f); this.FireExplosion(pwrVal, verVal, base.Position, base.Map, 1.2f + (float)(verVal * .8f)); if (!pawn.IsColonist) { this.FireExplosion(3, 3, base.Position, base.Map, 1.2f + (float)(3 * .8f)); } MoteMaker.ThrowSmoke(pawn.Position.ToVector3(), base.Map, 0.8f + (float)(verVal * .8f)); for (int i = 0; i < (2 + verVal); i++) { expCell1 = GetNewPos(expCell1, this.origin.x <= this.DestinationCell.x, this.origin.z <= this.DestinationCell.z, false, 0, 0, xProb, 1 - xProb); MoteMaker.ThrowSmoke(expCell1.ToVector3(), base.Map, 1.6f); expCell2 = GetNewPos(expCell2, this.origin.x <= this.DestinationCell.x, this.origin.z <= this.DestinationCell.z, false, 0, 0, 1 - xProb, xProb); MoteMaker.ThrowSmoke(expCell2.ToVector3(), base.Map, 1.6f); } for (int i = 0; i < (4 + (3 * verVal)); i++) { CellRect cellRect = CellRect.CenteredOn(expCell1, 1 + verVal); cellRect.ClipInsideMap(base.Map); IntVec3 randomCell = cellRect.RandomCell; this.FireExplosion(pwrVal, verVal, randomCell, base.Map, .4f); cellRect = CellRect.CenteredOn(expCell2, 1 + verVal); randomCell = cellRect.RandomCell; this.FireExplosion(pwrVal, verVal, randomCell, base.Map, .4f); } GenSpawn.Spawn(this.flyingThing, base.Position, base.Map); ModOptions.Constants.SetPawnInFlight(false); Pawn p = this.flyingThing as Pawn; TM_Action.SearchAndTaunt(p, 3f, 5, .7f); HealthUtility.AdjustSeverity(p, TorannMagicDefOf.TM_HediffShield, .25f); RemoveInvul(p); if (p.IsColonist) { p.drafter.Drafted = true; CameraJumper.TryJumpAndSelect(p); } this.Destroy(DestroyMode.Vanish); } catch { GenSpawn.Spawn(this.flyingThing, base.Position, base.Map); ModOptions.Constants.SetPawnInFlight(false); Pawn p = this.flyingThing as Pawn; RemoveInvul(p); if (p.IsColonist) { p.drafter.Drafted = true; } this.Destroy(DestroyMode.Vanish); } }
/// <summary> /// Performs the actual melee attack part. Awards XP, calculates and applies whether an attack connected and the outcome. /// </summary> /// <returns>True if the attack connected, false otherwise</returns> protected override bool TryCastShot() { Pawn casterPawn = CasterPawn; if (casterPawn.stances.FullBodyBusy) { return(false); } Thing targetThing = currentTarget.Thing; if (!CanHitTarget(targetThing)) { Log.Warning(string.Concat(new object[] { casterPawn, " meleed ", targetThing, " from out of melee position." })); } casterPawn.rotationTracker.Face(targetThing.DrawPos); // Award XP as per vanilla bool targetImmobile = IsTargetImmobile(currentTarget); if (!targetImmobile && casterPawn.skills != null) { casterPawn.skills.Learn(SkillDefOf.Melee, HitXP * verbProps.AdjustedFullCycleTime(this, casterPawn), false); } // Hit calculations bool result; string moteText = ""; SoundDef soundDef; Pawn defender = targetThing as Pawn; //var hitRoll = Rand.Value; if (Rand.Chance(GetHitChance(targetThing))) { // Check for dodge if (!targetImmobile && !surpriseAttack && Rand.Chance(defender.GetStatValue(StatDefOf.MeleeDodgeChance))) { // Attack is evaded result = false; soundDef = SoundMiss(); CreateCombatLog((ManeuverDef maneuver) => maneuver.combatLogRulesDodge, false); moteText = "TextMote_Dodge".Translate(); defender.skills?.Learn(SkillDefOf.Melee, DodgeXP * verbProps.AdjustedFullCycleTime(this, casterPawn), false); } else { // Attack connects, calculate resolution //var resultRoll = Rand.Value; var counterParryBonus = 1 + (EquipmentSource?.GetStatValue(CE_StatDefOf.MeleeCounterParryBonus) ?? 0); var parryChance = GetComparativeChanceAgainst(defender, casterPawn, CE_StatDefOf.MeleeParryChance, BaseParryChance, counterParryBonus); if (!surpriseAttack && defender != null && CanDoParry(defender) && Rand.Chance(parryChance)) { // Attack is parried Apparel shield = defender.apparel.WornApparel.FirstOrDefault(x => x is Apparel_Shield); bool isShieldBlock = shield != null && Rand.Chance(ShieldBlockChance); Thing parryThing = isShieldBlock ? shield : defender.equipment?.Primary ?? defender; if (Rand.Chance(GetComparativeChanceAgainst(defender, casterPawn, CE_StatDefOf.MeleeCritChance, BaseCritChance))) { // Do a riposte DoParry(defender, parryThing, true); moteText = "CE_TextMote_Riposted".Translate(); CreateCombatLog((ManeuverDef maneuver) => maneuver.combatLogRulesDeflect, false); //placeholder defender.skills?.Learn(SkillDefOf.Melee, (CritXP + ParryXP) * verbProps.AdjustedFullCycleTime(this, casterPawn), false); } else { // Do a parry DoParry(defender, parryThing); moteText = "CE_TextMote_Parried".Translate(); CreateCombatLog((ManeuverDef maneuver) => maneuver.combatLogRulesMiss, false); //placeholder defender.skills?.Learn(SkillDefOf.Melee, ParryXP * verbProps.AdjustedFullCycleTime(this, casterPawn), false); } result = false; soundDef = SoundMiss(); // TODO Set hit sound to something more appropriate } else { BattleLogEntry_MeleeCombat log = CreateCombatLog((ManeuverDef maneuver) => maneuver.combatLogRulesHit, false); // Attack connects if (surpriseAttack || Rand.Chance(GetComparativeChanceAgainst(casterPawn, defender, CE_StatDefOf.MeleeCritChance, BaseCritChance))) { // Do a critical hit isCrit = true; ApplyMeleeDamageToTarget(currentTarget).AssociateWithLog(log); moteText = casterPawn.def.race.Animal ? "CE_TextMote_Knockdown".Translate() : "CE_TextMote_CriticalHit".Translate(); casterPawn.skills?.Learn(SkillDefOf.Melee, CritXP * verbProps.AdjustedFullCycleTime(this, casterPawn), false); } else { // Do a regular hit as per vanilla ApplyMeleeDamageToTarget(currentTarget).AssociateWithLog(log); } result = true; soundDef = targetThing.def.category == ThingCategory.Building ? SoundHitBuilding() : SoundHitPawn(); } } } else { // Attack missed result = false; soundDef = SoundMiss(); CreateCombatLog((ManeuverDef maneuver) => maneuver.combatLogRulesMiss, false); } if (!moteText.NullOrEmpty()) { MoteMaker.ThrowText(targetThing.PositionHeld.ToVector3Shifted(), targetThing.MapHeld, moteText); } soundDef.PlayOneShot(new TargetInfo(targetThing.PositionHeld, targetThing.MapHeld)); casterPawn.Drawer.Notify_MeleeAttackOn(targetThing); if (defender != null && !defender.Dead) { defender.stances.StaggerFor(95); if (casterPawn.MentalStateDef != MentalStateDefOf.SocialFighting || defender.MentalStateDef != MentalStateDefOf.SocialFighting) { defender.mindState.meleeThreat = casterPawn; defender.mindState.lastMeleeThreatHarmTick = Find.TickManager.TicksGame; } } casterPawn.rotationTracker.FaceCell(targetThing.Position); if (casterPawn.caller != null) { casterPawn.caller.Notify_DidMeleeAttack(); } return(result); }
private bool CheckForFreeInterceptBetween(Vector3 lastExactPos, Vector3 newExactPos) { IntVec3 intVec = lastExactPos.ToIntVec3(); IntVec3 intVec2 = newExactPos.ToIntVec3(); if (intVec2 == intVec) { return(false); } if (!intVec.InBounds() || !intVec2.InBounds()) { return(false); } if (intVec2.AdjacentToCardinal(intVec)) { bool flag = this.CheckForFreeIntercept(intVec2); if (DebugViewSettings.drawInterceptChecks) { if (flag) { MoteMaker.ThrowText(intVec2.ToVector3Shifted(), "x", -1f); } else { MoteMaker.ThrowText(intVec2.ToVector3Shifted(), "o", -1f); } } return(flag); } if (this.origin.ToIntVec3().DistanceToSquared(intVec2) > 16f) { Vector3 vector = lastExactPos; Vector3 v = newExactPos - lastExactPos; Vector3 b = v.normalized * 0.2f; int num = (int)(v.MagnitudeHorizontal() / 0.2f); ProjectileCP.checkedCells.Clear(); int num2 = 0; while (true) { vector += b; IntVec3 intVec3 = vector.ToIntVec3(); if (!ProjectileCP.checkedCells.Contains(intVec3)) { if (this.CheckForFreeIntercept(intVec3)) { break; } ProjectileCP.checkedCells.Add(intVec3); } if (DebugViewSettings.drawInterceptChecks) { MoteMaker.ThrowText(vector, "o", -1f); } num2++; if (num2 > num) { return(false); } if (intVec3 == intVec2) { return(false); } } if (DebugViewSettings.drawInterceptChecks) { MoteMaker.ThrowText(vector, "x", -1f); } return(true); } return(false); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); Toil gotoThing = new Toil(); gotoThing.initAction = delegate { this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.Touch); }; gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival; gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(gotoThing); Toil enchanting = new Toil();//actions performed to enchant an item enchanting.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); enchanting.FailOnDestroyedOrNull(TargetIndex.A); enchanting.initAction = delegate { actor = enchanting.actor; thing = TargetThingA; thingLoc = thing.Position; if (!(thing.def.IsMeleeWeapon || thing.def.IsRangedWeapon || thing.def.IsApparel)) { actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); Log.Message("Failed to initialize enchanting - invalid item type."); } }; enchanting.tickAction = delegate { if (thing.Position != thingLoc || thing.Destroyed) { actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); Log.Message("Failed to complete enchanting - item being enchanted not at enchanting location or destroyed"); } if (Find.TickManager.TicksGame % 5 == 0) { TM_MoteMaker.ThrowEnchantingMote(TargetLocA.ToVector3Shifted(), actor.Map, .6f); } }; enchanting.WithProgressBar(TargetIndex.A, delegate { if (thing == null) { return(1f); } return(1f - (float)enchanting.actor.jobs.curDriver.ticksLeftThisToil / 240); }, false, 0f); enchanting.defaultCompleteMode = ToilCompleteMode.Delay; enchanting.defaultDuration = 240; enchanting.AddFinishAction(delegate { CompEnchantedItem enchantment = thing.TryGetComp <CompEnchantedItem>(); CompEnchant enchantingItem = actor.TryGetComp <CompEnchant>(); CompAbilityUserMagic pawnComp = actor.TryGetComp <CompAbilityUserMagic>(); if (enchantment != null && enchantingItem != null && enchanting.actor.jobs.curDriver.ticksLeftThisToil < 1) { EnchantItem(enchantingItem.enchantingContainer[0], enchantment); enchantingItem.enchantingContainer[0].Destroy(); pawnComp.Mana.CurLevel -= .5f; MoteMaker.ThrowText(TargetLocA.ToVector3Shifted(), actor.Map, "TM_Enchanted".Translate(), -1); SoundStarter.PlayOneShotOnCamera(TorannMagicDefOf.ItemEnchanted, null); //DestroyEnchantingStone(enchantingItem.innerContainer[0]); } else { Log.Message("Detected null enchanting comp."); } }); yield return(enchanting); }
private bool CheckForFreeIntercept(IntVec3 c) { float num = (c.ToVector3Shifted() - this.origin).MagnitudeHorizontalSquared(); if (num < 16f) { return(false); } List <Thing> list = Find.ThingGrid.ThingsListAt(c); for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (thing != this.ThingToNeverIntercept) { if (thing != this.launcher) { if (thing.def.Fillage == FillCategory.Full && this.InterceptWalls) { this.Impact(thing); return(true); } if (this.FreeIntercept) { float num2 = 0f; Pawn pawn = thing as Pawn; if (pawn != null) { num2 = 0.4f; if (pawn.GetPosture() != PawnPosture.Standing) { num2 *= 0.1f; } if (this.launcher != null && pawn.Faction != null && this.launcher.Faction != null && !pawn.Faction.HostileTo(this.launcher.Faction)) { num2 *= 0.4f; } num2 *= Mathf.Clamp(pawn.BodySize, 0.1f, 2f); } else if (thing.def.fillPercent > 0.2f) { num2 = thing.def.fillPercent * 0.07f; } if (num2 > 1E-05f) { if (num < 49f) { num2 *= 0.5f; } else if (num < 100f) { num2 *= 0.75f; } if (DebugViewSettings.drawShooting) { MoteMaker.ThrowText(this.ExactPosition, num2.ToStringPercent(), -1f); } if (Rand.Value < num2) { this.Impact(thing); return(true); } } } } } } return(false); }
public override void Notify_PawnDied() { IntVec3 spawnLoc = !base.Pawn.Dead ? base.parent.pawn.Position : base.parent.pawn.PositionHeld; Map spawnMap = !base.Pawn.Dead ? base.parent.pawn.Map : base.parent.pawn.MapHeld; this.Pawn.def.race.deathActionWorkerClass = typeof(DeathActionWorker_Simple); bool fullterm = this.parent.CurStageIndex > this.parent.def.stages.Count - 3; if (!fullterm) { Log.Message(string.Format("died before reaching fullterm, no spawning")); return; } else { if (spawnMap == null || spawnLoc == null) { Log.Message(string.Format("spawnMap or spawnLoc is null, no spawning")); return; } else { if (countToSpawn == 0) { countToSpawn++; } for (int i = 0; i < countToSpawn; i++) { Pawn pawn = XenomorphSpawnRequest(); // Log.Message(string.Format("Xenomorph to hatch: {0}", pawn.LabelShortCap)); pawn.ageTracker.CurKindLifeStage.bodyGraphicData.color = HostBloodColour; pawn.Notify_ColorChanged(); pawn.ageTracker.AgeBiologicalTicks = 0; pawn.ageTracker.AgeChronologicalTicks = 0; Comp_Xenomorph _Xenomorph = pawn.TryGetComp <Comp_Xenomorph>(); if (_Xenomorph != null) { _Xenomorph.host = base.parent.pawn.kindDef; } GenSpawn.Spawn(pawn, spawnLoc, spawnMap, 0); } Vector3 vector = spawnLoc.ToVector3Shifted(); for (int i = 0; i < 101; i++) { if (Rand.MTBEventOccurs(DustMoteSpawnMTB, 2f, 3.TicksToSeconds())) { MoteMaker.ThrowDustPuffThick(new Vector3(vector.x, 0f, vector.z) { y = AltitudeLayer.MoteOverhead.AltitudeFor() }, spawnMap, 1.5f, new Color(HostBloodColour.r, HostBloodColour.g, HostBloodColour.b, HostBloodColour.a)); } if (i == 100) { } if (i % 10 == 0) { FilthMaker.MakeFilth(spawnLoc + GenAdj.AdjacentCellsAndInside.RandomElement(), this.Pawn.MapHeld, this.Pawn.RaceProps.BloodDef, this.Pawn.LabelIndefinite(), 1); } } ThingDef motedef = DefDatabase <ThingDef> .GetNamedSilentFail("Mote_BlastExtinguisher"); MoteMaker.ThrowExplosionCell(spawnLoc, MyMap, motedef, HostBloodColour); // GenAdj.AdjacentCellsAndInside[i]; for (int i2 = 0; i2 < GenAdj.AdjacentCellsAndInside.Length; i2++) { FilthMaker.MakeFilth(spawnLoc + GenAdj.AdjacentCellsAndInside[i2], this.Pawn.MapHeld, this.Pawn.RaceProps.BloodDef, this.Pawn.LabelIndefinite(), 1); } string text = TranslatorFormattedStringExtensions.Translate("Xeno_Chestburster_Emerge", base.parent.pawn.LabelShort, this.parent.Part.LabelShort); MoteMaker.ThrowText(spawnLoc.ToVector3(), spawnMap, text, 5f); if (!PlayerKnowledgeDatabase.IsComplete(XenomorphConceptDefOf.RRY_Concept_Chestbursters) && MyMap != null) { LessonAutoActivator.TeachOpportunity(XenomorphConceptDefOf.RRY_Concept_Chestbursters, OpportunityType.Important); } } } }
protected override IEnumerable <Toil> MakeNewToils() { Toil toil = new Toil(); toil.initAction = delegate { Pawn pawn = toil.actor; if (pawn.thinker == null) { return; } //Find apparel JobGiver_OptimizeApparel optimizer = pawn.thinker.TryGetMainTreeThinkNode <JobGiver_OptimizeApparel>(); if (optimizer == null) { return; } pawn.mindState?.Notify_OutfitChanged(); // Lie so that it re-equips things ThinkResult result = optimizer.TryIssueJobPackage(pawn, new JobIssueParams()); //TryGiveJob is protected :( //Find loadout, Combat Extended if (result == ThinkResult.NoJob) { if (CEloadoutGiverType != null) { if (CEloadoutGetter == null) { CEloadoutGetter = AccessTools.Method(typeof(Pawn_Thinker), nameof(Pawn_Thinker.TryGetMainTreeThinkNode)).MakeGenericMethod(new Type[] { CEloadoutGiverType }); } if (CEloadoutGetter != null) { object CELoadoutGiver = CEloadoutGetter.Invoke(pawn.thinker, new object[] { }); if (CELoadoutGiver != null) { result = (ThinkResult)TryIssueJobPackageInfo.Invoke(CELoadoutGiver, new object[] { pawn, new JobIssueParams() }); } } } } //Find weapons, Weapons of Choice if (result == ThinkResult.NoJob) { if (WOCGiverType != null) { if (WOCGetter == null) { WOCGetter = AccessTools.Method(typeof(Pawn_Thinker), nameof(Pawn_Thinker.TryGetMainTreeThinkNode)).MakeGenericMethod(new Type[] { WOCGiverType }); } if (WOCGetter != null) { object WOCLoadoutGiver = WOCGetter.Invoke(pawn.thinker, new object[] { }); if (WOCLoadoutGiver != null) { result = (ThinkResult)TryIssueJobPackageInfo.Invoke(WOCLoadoutGiver, new object[] { pawn, new JobIssueParams() }); } } } } //Okay, nothing to do, go to target if (result == ThinkResult.NoJob) { IntVec3 intVec = RCellFinder.BestOrderedGotoDestNear(TargetA.Cell, pawn); Job job = new Job(JobDefOf.Goto, intVec); if (pawn.Map.exitMapGrid.IsExitCell(UI.MouseCell())) { job.exitMapOnArrival = true; // I guess } if (!pawn.Drafted) { //Drafting clears the job queue. We want to keep the queue. //It'll also return jobs to the pool, and clear each job too. //So extract each job and clear the queue manually, then re-queue them all. List <QueuedJob> queue = new List <QueuedJob>(); while (pawn.jobs.jobQueue.Count > 0) { queue.Add(pawn.jobs.jobQueue.Dequeue()); } pawn.drafter.Drafted = true; pawn.jobs.StartJob(job, JobCondition.Succeeded); foreach (QueuedJob qj in queue) { pawn.jobs.jobQueue.EnqueueLast(qj.job, qj.tag); } } else { pawn.jobs.StartJob(job, JobCondition.Succeeded); } MoteMaker.MakeStaticMote(intVec, pawn.Map, ThingDefOf.Mote_FeedbackGoto, 1f); } //Queue up the Gear job, then do another Gear+Go job else { Job optJob = result.Job; Log.Message($"{pawn} JobDriver_GearUpAndGo job {optJob}"); if (optJob.def == JobDefOf.Wear) { pawn.Reserve(optJob.targetA, optJob); } pawn.jobs.jobQueue.EnqueueFirst(new Job(GearUpAndGoJobDefOf.GearUpAndGo, TargetA)); pawn.jobs.jobQueue.EnqueueFirst(optJob); } }; yield return(toil); }