public override void TickRare() { base.TickRare(); // デバッグオプションがONなら時間設定や電力状態を無視 if (compPowerTrader.PowerOn || MizuDef.GlobalSettings.forDebug.enableAlwaysActivateSprinklerGrowing) { // 電源ON、故障無し、稼働時間範囲内の時 if (InputWaterNet != null) { // 水やり範囲 var cells = GenRadial.RadialCellsAround(Position, def.specialDisplayRadius, true); // 設備の置かれた部屋 var room = Position.GetRoom(Map); // 設備と同じ部屋に属するセル(肥沃度あり) // 暫定で植木鉢は無効とする var sameRoomCells = cells.Where( c => c.GetRoom(Map) == room && Map.terrainGrid.TerrainAt(c).fertility >= 0.01f); var wateringComp = Map.GetComponent <MapComponent_Watering>(); // 10の水やり効果で1L→1の水やり効果で0.1L // 水が足りているかチェック var useWaterVolume = UseWaterVolumePerOne * sameRoomCells.Count(); // デバッグオプションがONなら消費貯水量を0.1Lにする if (MizuDef.GlobalSettings.forDebug.enableAlwaysActivateSprinklerGrowing) { useWaterVolume = 0.1f; } if (InputWaterNet.StoredWaterVolumeForFaucet >= useWaterVolume) { // 水を減らしてからセルに水やり効果 InputWaterNet.DrawWaterVolumeForFaucet(useWaterVolume); foreach (var c in sameRoomCells) { wateringComp.Add(Map.cellIndices.CellToIndex(c), 1); Map.mapDrawer.SectionAt(c).dirtyFlags = MapMeshFlag.Terrain; // 水やりエフェクト(仮) var mote = (MoteThrown)ThingMaker.MakeThing(MizuDef.Mote_SprinklerWater); // mote.Scale = 1f; // mote.rotationRate = (float)(Rand.Chance(0.5f) ? -30 : 30); mote.exactPosition = c.ToVector3Shifted(); GenSpawn.Spawn(mote, c, Map); // 消火効果(仮) // 複製しないとダメージを受けて消えた時点で元のリストから除外されてエラーになる var fireList = new List <Fire>(Map.thingGrid.ThingsListAt(c).OfType <Fire>()); foreach (var fire in fireList) { fire.TakeDamage(new DamageInfo(DamageDefOf.Extinguish, ExtinguishPower)); } } } } } ResetPowerOutput(); }
public static Toil FindStoreCellForCart(TargetIndex CartInd) { const int NearbyCell = 8; const int RegionCellOffset = 16; IntVec3 invalid = new IntVec3(0, 0, 0); #if DEBUG StringBuilder stringBuilder = new StringBuilder(); #endif Toil toil = new Toil(); toil.initAction = () => { IntVec3 storeCell = IntVec3.Invalid; Pawn actor = toil.GetActor(); Vehicle_Cart cart = toil.actor.jobs.curJob.GetTarget(CartInd).Thing as Vehicle_Cart; if (cart == null) { Log.Error(actor.LabelCap + " Report: Cart is invalid."); toil.actor.jobs.curDriver.EndJobWith(JobCondition.Errored); } //Find Valid Storage foreach (IntVec3 cell in GenRadial.RadialCellsAround(cart.Position, NearbyCell, false)) { if (cell.IsValidStorageFor(cart) && ReservationUtility.CanReserveAndReach(actor, cell, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(actor))) { storeCell = cell; #if DEBUG stringBuilder.AppendLine("Found cell: " + storeCell); #endif } } if (storeCell == IntVec3.Invalid) { //Regionwise Flood-fill cellFinder int regionInd = 0; List <Region> regions = new List <Region>(); regions.Add(cart.Position.GetRegion()); #if DEBUG stringBuilder.AppendLine(actor.LabelCap + " Report"); #endif bool flag1 = false; while (regionInd < regions.Count) { #if DEBUG stringBuilder.AppendLine("Region id: " + regions[regionInd].id); #endif if (regions[regionInd].extentsClose.Center.InHorDistOf(cart.Position, NearbyCell + RegionCellOffset)) { IntVec3 foundCell = IntVec3.Invalid; IntVec3 distCell = (regionInd > 0)? regions[regionInd - 1].extentsClose.Center : cart.Position; float distFoundCell = float.MaxValue; foreach (IntVec3 cell in regions[regionInd].Cells) { //Find best cell for placing cart if (cell.GetEdifice() == null && cell.GetZone() == null && cell.Standable() && !GenAdj.CellsAdjacentCardinal(cell, Rot4.North, IntVec2.One).Any(cardinal => cardinal.GetEdifice() is Building_Door) && ReservationUtility.CanReserveAndReach(actor, cell, PathEndMode.ClosestTouch, DangerUtility.NormalMaxDanger(actor))) { if (distCell.DistanceToSquared(cell) < distFoundCell) { foundCell = cell; distFoundCell = distCell.DistanceToSquared(cell); flag1 = true; } } } if (flag1 == true) { storeCell = foundCell; #if DEBUG stringBuilder.AppendLine("Found cell: " + storeCell); #endif break; } foreach (RegionLink link in regions[regionInd].links) { if (regions.Contains(link.RegionA) == false) { regions.Add(link.RegionA); } if (regions.Contains(link.RegionB) == false) { regions.Add(link.RegionB); } } } regionInd++; } } //Log.Message(stringBuilder.ToString()); /* * //Home Area * if (storeCell == IntVec3.Invalid) * foreach (IntVec3 cell in Find.AreaHome.ActiveCells.Where(cell => (cell.GetZone() == null || cell.IsValidStorageFor(cart)) && cell.Standable() && cell.GetEdifice() == null)) * if (cell.DistanceToSquared(cart.Position) < NearbyCell) * storeCell = cell; */ ReservationUtility.Reserve(actor, storeCell); toil.actor.jobs.curJob.targetB = (storeCell != invalid && storeCell != IntVec3.Invalid) ? storeCell : cart.Position; }; return(toil); }
protected override void Impact(Thing hitThing) { base.Impact(hitThing); if (!this.initialized) { this.caster = this.launcher as Pawn; CompAbilityUserMight comp = caster.GetComp <CompAbilityUserMight>(); //pwrVal = caster.GetComp<CompAbilityUserMight>().MightData.MightPowerSkill_GraveBlade.FirstOrDefault((MightPowerSkill x) => x.label == "TM_GraveBlade_pwr").level; //verVal = caster.GetComp<CompAbilityUserMight>().MightData.MightPowerSkill_GraveBlade.FirstOrDefault((MightPowerSkill x) => x.label == "TM_GraveBlade_ver").level; verVal = TM_Calc.GetMightSkillLevel(caster, comp.MightData.MightPowerSkill_GraveBlade, "TM_GraveBlade", "_ver", true); pwrVal = TM_Calc.GetMightSkillLevel(caster, comp.MightData.MightPowerSkill_GraveBlade, "TM_GraveBlade", "_pwr", true); //ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef(); this.arcaneDmg = comp.mightPwr; //if (settingsRef.AIHardMode && !caster.IsColonist) //{ // pwrVal = 3; // verVal = 3; //} this.radius = this.def.projectile.explosionRadius; this.duration = 10 + (int)(this.radius * 20); this.innerCellList = GenRadial.RadialCellsAround(base.Position, this.radius, true).ToList(); this.ringCellList = GenRadial.RadialCellsAround(base.Position, this.radius + 1, false).Except(innerCellList).ToList(); this.effectIndex2 = ringCellList.Count / 2; this.initialized = true; } if (this.Map != null) { if (Find.TickManager.TicksGame % this.effectDelay == 0) { Vector3 drawIndex1 = this.ringCellList[effectIndex1].ToVector3Shifted(); drawIndex1.x += Rand.Range(-.35f, .35f); drawIndex1.z += Rand.Range(-.35f, .35f); Vector3 drawIndex2 = this.ringCellList[effectIndex2].ToVector3Shifted(); drawIndex2.x += Rand.Range(-.35f, .35f); drawIndex2.z += Rand.Range(-.35f, .35f); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SpiritFlame"), drawIndex1, this.Map, Rand.Range(.4f, .8f), .1f, 0, .6f, 0, Rand.Range(.4f, 1f), Rand.Range(-20, 20), Rand.Range(-20, 20)); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SpiritFlame"), drawIndex2, this.Map, Rand.Range(.4f, .8f), .1f, 0, .6f, 0, Rand.Range(.4f, 1f), Rand.Range(-20, 20), Rand.Range(-20, 20)); this.effectIndex1++; this.effectIndex2++; if (this.effectIndex1 >= ringCellList.Count) { this.effectIndex1 = 0; } if (this.effectIndex2 >= ringCellList.Count) { this.effectIndex2 = 0; } } if (Find.TickManager.TicksGame % this.strikeDelay == 0 && !this.caster.DestroyedOrNull()) { IntVec3 centerCell = innerCellList.RandomElement(); IEnumerable <IntVec3> targetCells = GenRadial.RadialCellsAround(centerCell, 2f, true); foreach (var target in targetCells) { IntVec3 curCell = target; Pawn victim = curCell.GetFirstPawn(this.Map); if (victim != null && !victim.Destroyed && !victim.Dead && victim != this.caster) { TM_Action.DamageEntities(victim, null, (Rand.Range(10, 16) + (2 * pwrVal)) * this.arcaneDmg, TMDamageDefOf.DamageDefOf.TM_Spirit, this.launcher); if (!this.caster.DestroyedOrNull() && !this.caster.Dead && Rand.Chance(verVal)) { TM_Action.DoAction_HealPawn(this.caster, this.caster, 1, (Rand.Range(6, 10) + (2 * verVal)) * this.arcaneDmg); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SpiritRetaliation"), this.caster.DrawPos, this.caster.Map, Rand.Range(1f, 1.2f), Rand.Range(.1f, .15f), 0, Rand.Range(.1f, .2f), -600, 0, 0, Rand.Range(0, 360)); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SpiritRetaliation"), this.caster.DrawPos, this.caster.Map, Rand.Range(1f, 1.2f), Rand.Range(.1f, .15f), 0, Rand.Range(.1f, .2f), 600, 0, 0, Rand.Range(0, 360)); } if (Rand.Chance(verVal)) { if (!victim.IsWildMan() && victim.RaceProps.Humanlike && victim.mindState != null && !victim.InMentalState) { try { Job job = new Job(JobDefOf.FleeAndCower); //victim.mindState.mentalStateHandler.TryStartMentalState(TorannMagicDefOf.TM_PanicFlee); } catch (NullReferenceException) { } } } } } TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_GraveBlade"), centerCell.ToVector3Shifted(), this.Map, Rand.Range(1f, 1.6f), .15f, .1f, .2f, 0, Rand.Range(4f, 6f), 0, 0); } } }
protected override void Impact(Thing hitThing) { base.Impact(hitThing); ThingDef def = this.def; if (!this.initialized) { this.casterPawn = this.launcher as Pawn; CompAbilityUserMagic comp = casterPawn.GetComp <CompAbilityUserMagic>(); MagicPowerSkill pwr = comp.MagicData.MagicPowerSkill_ChronostaticField.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_ChronostaticField_pwr"); MagicPowerSkill ver = comp.MagicData.MagicPowerSkill_ChronostaticField.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_ChronostaticField_ver"); ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef(); pwrVal = pwr.level; verVal = ver.level; if (this.casterPawn.story.traits.HasTrait(TorannMagicDefOf.Faceless)) { MightPowerSkill mpwr = casterPawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr"); MightPowerSkill mver = casterPawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver"); pwrVal = mpwr.level; verVal = mver.level; } this.arcaneDmg = comp.arcaneDmg; if (settingsRef.AIHardMode && !casterPawn.IsColonist) { pwrVal = 3; verVal = 3; } this.strikeDelay = this.strikeDelay - verVal; this.radius = this.def.projectile.explosionRadius; this.duration = Mathf.RoundToInt(this.radius * this.strikeDelay); this.initialized = true; //this.targets = GenRadial.RadialCellsAround(base.Position, this.radius, true); //cellList = targets.ToList<IntVec3>(); } cellList = new List <IntVec3>(); cellList.Clear(); cellList = GenRadial.RadialCellsAround(base.Position, this.radius, true).ToList(); //this.radius instead of 2 for (int i = 0; i < cellList.Count; i++) { if (cellList[i].IsValid && cellList[i].InBounds(this.Map)) { List <Thing> thingList = cellList[i].GetThingList(this.Map); if (thingList != null && thingList.Count > 0) { for (int j = 0; j < thingList.Count; j++) { Pawn pawn = thingList[j] as Pawn; if (pawn != null) { RemoveFireAt(thingList[j].Position); if (Rand.Chance(TM_Calc.GetSpellSuccessChance(this.casterPawn, pawn, false) * (.6f + (.1f * verVal)))) { IntVec3 targetCell = pawn.Position; targetCell.z++; LaunchFlyingObect(targetCell, pawn, 1, Mathf.RoundToInt(Rand.Range(1400, 1800) * (1f + (.2f * pwrVal)) * this.arcaneDmg)); } else { MoteMaker.ThrowText(pawn.DrawPos, pawn.Map, "TM_ResistedSpell".Translate(), -1); } } } } } } this.age = this.duration; this.Destroy(DestroyMode.Vanish); }
public static HashSet <IntVec3> DoSettlementGeneration(Map map, string path, LocationDef locationDef, Faction faction, bool disableFog) { Log.Message("DoSettlementGeneration: GetOrGenerateMapPatch.locationData: " + GetOrGenerateMapPatch.locationData?.locationDef); Log.Message("DoSettlementGeneration: path: " + path); Log.Message("DoSettlementGeneration: locationDef: " + locationDef); GetOrGenerateMapPatch.locationData = null; GetOrGenerateMapPatch.caravanArrival = false; var mapComp = map.GetComponent <MapComponentGeneration>(); try { if (locationDef != null && locationDef.destroyEverythingOnTheMapBeforeGeneration) { var thingsToDespawn = map.listerThings.AllThings; if (thingsToDespawn != null && thingsToDespawn.Count > 0) { for (int i = thingsToDespawn.Count - 1; i >= 0; i--) { try { if (thingsToDespawn[i].Spawned) { thingsToDespawn[i].DeSpawn(DestroyMode.WillReplace); } } catch (Exception ex) { Log.Error("4 Cant despawn: " + thingsToDespawn[i] + " - " + thingsToDespawn[i].Position + "error: " + ex); } } } } if (locationDef != null && locationDef.factionDefForNPCsAndTurrets != null) { faction = Find.FactionManager.FirstFactionOfDef(locationDef.factionDefForNPCsAndTurrets); } else if (faction == Faction.OfPlayer || faction == null) { faction = Faction.OfAncients; } List <Thing> thingsToDestroy = new List <Thing>(); HashSet <IntVec3> tilesToProcess = new HashSet <IntVec3>(); int radiusToClear = 0; // //foreach (var building in map.listerThings.AllThings // .Where(x => x is Building && x.Faction == faction && !(x is Mineable))) //{ // foreach (var pos in GenRadial.RadialCellsAround(building.Position, radiusToClear, true)) // { // if (GenGrid.InBounds(pos, map)) // { // tilesToProcess.Add(pos); // } // } // thingsToDestroy.Add(building); //} List <Corpse> corpses = new List <Corpse>(); List <Pawn> pawnCorpses = new List <Pawn>(); List <Pawn> pawns = new List <Pawn>(); List <Building> buildings = new List <Building>(); List <Thing> things = new List <Thing>(); List <Filth> filths = new List <Filth>(); List <Plant> plants = new List <Plant>(); Dictionary <IntVec3, TerrainDef> terrains = new Dictionary <IntVec3, TerrainDef>(); Dictionary <IntVec3, RoofDef> roofs = new Dictionary <IntVec3, RoofDef>(); HashSet <IntVec3> tilesToSpawnPawnsOnThem = new HashSet <IntVec3>(); Scribe.loader.InitLoading(path); Scribe_Collections.Look <Pawn>(ref pawnCorpses, "PawnCorpses", LookMode.Deep, new object[0]); Scribe_Collections.Look <Corpse>(ref corpses, "Corpses", LookMode.Deep, new object[0]); Scribe_Collections.Look <Pawn>(ref pawns, "Pawns", LookMode.Deep, new object[0]); Scribe_Collections.Look <Building>(ref buildings, "Buildings", LookMode.Deep, new object[0]); Scribe_Collections.Look <Filth>(ref filths, "Filths", LookMode.Deep, new object[0]); Scribe_Collections.Look <Thing>(ref things, "Things", LookMode.Deep, new object[0]); Scribe_Collections.Look <Plant>(ref plants, "Plants", LookMode.Deep, new object[0]); Scribe_Collections.Look <IntVec3, TerrainDef>(ref terrains, "Terrains", LookMode.Value, LookMode.Def, ref terrainKeys, ref terrainValues); Scribe_Collections.Look <IntVec3, RoofDef>(ref roofs, "Roofs", LookMode.Value, LookMode.Def, ref roofsKeys, ref roofsValues); Scribe_Collections.Look <IntVec3>(ref tilesToSpawnPawnsOnThem, "tilesToSpawnPawnsOnThem", LookMode.Value); Scribe.loader.FinalizeLoading(); if (corpses is null) { corpses = new List <Corpse>(); } else { corpses.RemoveAll(x => x is null); } if (pawnCorpses is null) { pawnCorpses = new List <Pawn>(); } else { pawnCorpses.RemoveAll(x => x is null); } if (pawns is null) { pawns = new List <Pawn>(); } else { pawns.RemoveAll(x => x is null); } if (buildings is null) { buildings = new List <Building>(); } else { buildings.RemoveAll(x => x is null); } if (things is null) { things = new List <Thing>(); } else { things.RemoveAll(x => x is null); } if (filths is null) { filths = new List <Filth>(); } else { filths.RemoveAll(x => x is null); } if (plants is null) { plants = new List <Plant>(); } else { plants.RemoveAll(x => x is null); } var cells = new List <IntVec3>(tilesToSpawnPawnsOnThem); cells.AddRange(buildings.Select(x => x.Position).ToList()); var centerCell = GetCellCenterFor(cells); var offset = map.Center - centerCell; if (corpses != null && corpses.Count > 0) { foreach (var corpse in corpses) { try { var position = GetOffsetPosition(locationDef, corpse.Position, offset); if (GenGrid.InBounds(position, map)) { GenSpawn.Spawn(corpse, position, map, WipeMode.Vanish); } } catch (Exception ex) { Log.Error("1 Error in map generating, cant spawn " + corpse + " - " + ex); } } } if (pawns != null && pawns.Count > 0) { foreach (var pawn in pawns) { try { var position = GetOffsetPosition(locationDef, pawn.Position, offset); if (GenGrid.InBounds(position, map)) { pawn.pather = new Pawn_PathFollower(pawn); GenSpawn.Spawn(pawn, position, map, WipeMode.Vanish); if (pawn.Faction != faction) { pawn.SetFaction(faction); } } } catch (Exception ex) { Log.Error("2 Error in map generating, cant spawn " + pawn + " - " + ex); } } } if (tilesToSpawnPawnsOnThem != null && tilesToSpawnPawnsOnThem.Count > 0) { foreach (var tile in tilesToSpawnPawnsOnThem) { var position = GetOffsetPosition(locationDef, tile, offset); try { if (GenGrid.InBounds(position, map)) { var things2 = map.thingGrid.ThingsListAt(position); foreach (var thing in things2) { if (thing is Building || (thing is Plant plant && plant.def != ThingDefOf.Plant_Grass) || IsChunk(thing)) { thingsToDestroy.Add(thing); } } } } catch (Exception ex) { Log.Error("3 Error in map generating, cant spawn " + position + " - " + ex); } } } if (buildings != null && buildings.Count > 0) { foreach (var building in buildings) { var position = GetOffsetPosition(locationDef, building.Position, offset); foreach (var pos in GenRadial.RadialCellsAround(position, radiusToClear, true)) { if (GenGrid.InBounds(pos, map)) { tilesToProcess.Add(pos); } } } if (tilesToProcess != null && tilesToProcess.Count > 0) { foreach (var pos in tilesToProcess) { if (pos.InBounds(map)) { var things2 = map.thingGrid.ThingsListAt(pos); foreach (var thing in things2) { if (thing is Building || (thing is Plant plant && plant.def != ThingDefOf.Plant_Grass) || IsChunk(thing)) { thingsToDestroy.Add(thing); } } var terrain = pos.GetTerrain(map); if (terrain != null) { if (terrain.IsWater) { map.terrainGrid.SetTerrain(pos, TerrainDefOf.Soil); } if (map.terrainGrid.CanRemoveTopLayerAt(pos)) { map.terrainGrid.RemoveTopLayer(pos, false); } } var roof = pos.GetRoof(map); if (roof != null && (!map.roofGrid.RoofAt(pos).isNatural || map.roofGrid.RoofAt(pos) == RoofDefOf.RoofRockThin)) { map.roofGrid.SetRoof(pos, null); } } } } if (thingsToDestroy != null && thingsToDestroy.Count > 0) { for (int i = thingsToDestroy.Count - 1; i >= 0; i--) { try { if (thingsToDestroy[i].Spawned) { thingsToDestroy[i].DeSpawn(DestroyMode.WillReplace); } } catch (Exception ex) { Log.Error("4 Cant despawn: " + thingsToDestroy[i] + " - " + thingsToDestroy[i].Position + "error: " + ex); } } } foreach (var building in buildings) { var position = GetOffsetPosition(locationDef, building.Position, offset); try { if (GenGrid.InBounds(position, map)) { GenSpawn.Spawn(building, position, map, building.Rotation, WipeMode.Vanish); if (building.def.CanHaveFaction && building.Faction != faction) { building.SetFaction(faction); } } } catch (Exception ex) { Log.Error("5 Error in map generating, cant spawn " + building + " - " + position + " - " + ex); } } } if (filths != null && filths.Count > 0) { foreach (var filth in filths) { try { var position = GetOffsetPosition(locationDef, filth.Position, offset); if (position.InBounds(map)) { GenSpawn.Spawn(filth, position, map, WipeMode.Vanish); } } catch (Exception ex) { Log.Error("6.5 Error in map generating, cant spawn " + filth + " - " + ex); } } } if (plants != null && plants.Count > 0) { foreach (var plant in plants) { try { var position = GetOffsetPosition(locationDef, plant.Position, offset); if (position.InBounds(map) && map.fertilityGrid.FertilityAt(position) >= plant.def.plant.fertilityMin) { GenSpawn.Spawn(plant, position, map, WipeMode.Vanish); } } catch (Exception ex) { Log.Error("6 Error in map generating, cant spawn " + plant + " - " + ex); } } } var containers = map.listerThings.AllThings.Where(x => x is Building_Storage).ToList(); if (things != null && things.Count > 0) { foreach (var thing in things) { try { var position = GetOffsetPosition(locationDef, thing.Position, offset); if (position.InBounds(map)) { GenSpawn.Spawn(thing, position, map, WipeMode.Vanish); if (locationDef != null && locationDef.moveThingsToShelves) { TryDistributeTo(thing, map, containers, faction != Faction.OfPlayer); } } } catch (Exception ex) { Log.Error("7 Error in map generating, cant spawn " + thing + " - " + ex); } } } if (locationDef != null && locationDef.moveThingsToShelves) { foreach (var item in map.listerThings.AllThings) { if (item.IsForbidden(Faction.OfPlayer)) { TryDistributeTo(item, map, containers, faction != Faction.OfPlayer); } } } if (terrains != null && terrains.Count > 0) { foreach (var terrain in terrains) { try { var position = GetOffsetPosition(locationDef, terrain.Key, offset); if (GenGrid.InBounds(position, map)) { map.terrainGrid.SetTerrain(position, terrain.Value); } } catch (Exception ex) { Log.Error("8 Error in map generating, cant spawn " + terrain.Key + " - " + ex); } } } if (roofs != null && roofs.Count > 0) { foreach (var roof in roofs) { try { var position = GetOffsetPosition(locationDef, roof.Key, offset); if (GenGrid.InBounds(position, map)) { map.roofGrid.SetRoof(position, roof.Value); } } catch (Exception ex) { Log.Error("9 Error in map generating, cant spawn " + roof.Key + " - " + ex); } } } if (locationDef != null && (locationDef.percentOfDamagedWalls.HasValue || locationDef.percentOfDestroyedWalls.HasValue) || locationDef.percentOfDamagedFurnitures.HasValue) { var walls = map.listerThings.AllThings.Where(x => x.def.IsEdifice() && x.def.defName.ToLower().Contains("wall")).ToList(); if (locationDef.percentOfDestroyedWalls.HasValue) { var percent = locationDef.percentOfDestroyedWalls.Value.RandomInRange * 100f; var countToTake = (int)((percent * walls.Count()) / 100f); var wallsToDestroy = walls.InRandomOrder().Take(countToTake).ToList(); for (int num = wallsToDestroy.Count - 1; num >= 0; num--) { walls.Remove(wallsToDestroy[num]); wallsToDestroy[num].DeSpawn(); } } if (locationDef.percentOfDamagedWalls.HasValue) { var percent = locationDef.percentOfDamagedWalls.Value.RandomInRange * 100f; var countToTake = (int)((percent * walls.Count()) / 100f); var wallsToDamage = walls.InRandomOrder().Take(countToTake).ToList(); for (int num = wallsToDamage.Count - 1; num >= 0; num--) { var damagePercent = Rand.Range(0.3f, 0.6f); var hitpointsToTake = (int)(wallsToDamage[num].MaxHitPoints * damagePercent); wallsToDamage[num].HitPoints = hitpointsToTake; } } if (locationDef.percentOfDamagedFurnitures.HasValue) { var furnitures = map.listerThings.AllThings.Where(x => !walls.Contains(x) && x.def.IsBuildingArtificial).ToList(); var percent = locationDef.percentOfDamagedFurnitures.Value.RandomInRange * 100f; var countToTake = (int)((percent * furnitures.Count()) / 100f); var furnituresToDamage = furnitures.InRandomOrder().Take(countToTake).ToList(); for (int num = furnituresToDamage.Count - 1; num >= 0; num--) { var damagePercent = Rand.Range(0.3f, 0.6f); var hitpointsToTake = (int)(furnituresToDamage[num].MaxHitPoints * damagePercent); furnituresToDamage[num].HitPoints = hitpointsToTake; } } } if (faction.def.HasModExtension <SettlementOptionModExtension>()) { var options = faction.def.GetModExtension <SettlementOptionModExtension>(); if (options.removeVanillaGeneratedPawns) { for (int i = map.mapPawns.PawnsInFaction(faction).Count - 1; i >= 0; i--) { map.mapPawns.PawnsInFaction(faction)[i].DeSpawn(DestroyMode.Vanish); } } if (options.pawnsToGenerate != null && options.pawnsToGenerate.Count > 0 && tilesToSpawnPawnsOnThem != null && tilesToSpawnPawnsOnThem.Count > 0) { foreach (var pawn in options.pawnsToGenerate) { foreach (var i in Enumerable.Range(1, (int)pawn.selectionWeight)) { var settler = PawnGenerator.GeneratePawn(new PawnGenerationRequest(pawn.kind, faction)); try { var pos = tilesToSpawnPawnsOnThem.Where(x => map.thingGrid.ThingsListAt(x) .Where(y => y is Building).Count() == 0).RandomElement(); GenSpawn.Spawn(settler, pos, map); } catch (Exception ex) { Log.Error("10 Error in map generating, cant spawn " + settler + " - " + ex); } } } } } foreach (var pawn in map.mapPawns.PawnsInFaction(faction)) { var lord = pawn.GetLord(); if (lord != null) { map.lordManager.RemoveLord(lord); } var lordJob = new LordJob_DefendBase(); if (tilesToSpawnPawnsOnThem != null && tilesToSpawnPawnsOnThem.Count > 0) { lordJob = new LordJob_DefendBase(faction, tilesToSpawnPawnsOnThem.RandomElement()); } else { lordJob = new LordJob_DefendBase(faction, pawn.Position); } LordMaker.MakeNewLord(faction, lordJob, map, null).AddPawn(pawn); } if (disableFog != true) { try { FloodFillerFog.DebugRefogMap(map); } catch { foreach (var cell in map.AllCells) { if (!tilesToProcess.Contains(cell) && !(cell.GetFirstBuilding(map) is Mineable)) { var item = cell.GetFirstItem(map); if (item != null) { var room = item.GetRoom(); if (room != null) { if (room.PsychologicallyOutdoors) { FloodFillerFog.FloodUnfog(cell, map); } } } } } } mapComp.reFog = true; } mapComp.doGeneration = false; mapComp.path = null; GetOrGenerateMapPatch.caravanArrival = false; return(tilesToSpawnPawnsOnThem.Select(x => GetOffsetPosition(locationDef, x, offset)).ToHashSet()); } catch (Exception ex) { Log.Error("Error in DoSettlementGeneration: " + ex); } mapComp.doGeneration = false; mapComp.path = null; return(null); }
public void GetAffectedPawns(IntVec3 center, Map map) { Pawn victim = null; IntVec3 curCell; IEnumerable <IntVec3> targets = GenRadial.RadialCellsAround(center, this.def.projectile.explosionRadius, true); for (int i = 0; i < targets.Count(); i++) { curCell = targets.ToArray <IntVec3>()[i]; if (curCell.InBounds(map) && curCell.IsValid) { victim = curCell.GetFirstPawn(map); } if (victim != null && victim.Faction == this.caster.Faction && !victim.Dead) { if (verVal >= 1) { HealthUtility.AdjustSeverity(victim, HediffDef.Named("TM_HediffTimedInvulnerable"), 1f); } if (verVal >= 2) { Pawn pawn = victim; bool flag = pawn != null && !pawn.Dead; if (flag) { int num = 3; using (IEnumerator <BodyPartRecord> enumerator = pawn.health.hediffSet.GetInjuredParts().GetEnumerator()) { while (enumerator.MoveNext()) { BodyPartRecord rec = enumerator.Current; bool flag2 = num > 0; if (flag2) { int num2 = 1; IEnumerable <Hediff_Injury> arg_BB_0 = pawn.health.hediffSet.GetHediffs <Hediff_Injury>(); Func <Hediff_Injury, bool> arg_BB_1; arg_BB_1 = ((Hediff_Injury injury) => injury.Part == rec); foreach (Hediff_Injury current in arg_BB_0.Where(arg_BB_1)) { bool flag4 = num2 > 0; if (flag4) { bool flag5 = current.CanHealNaturally() && !current.IsOld(); if (flag5) { //current.Heal((float)((int)current.Severity + 1)); if (!this.caster.IsColonistPlayerControlled) { current.Heal(20.0f); // power affects how much to heal } else { current.Heal((5.0f * this.caster.TryGetComp <CompAbilityUserMagic>().arcaneDmg)); // power affects how much to heal } TM_MoteMaker.ThrowRegenMote(pawn.Position.ToVector3Shifted(), pawn.Map, .6f); TM_MoteMaker.ThrowRegenMote(pawn.Position.ToVector3Shifted(), pawn.Map, .4f); num--; num2--; } } } } } } } } if (verVal >= 3) { HealthUtility.AdjustSeverity(victim, HediffDef.Named("BestowMightHD"), 1f); } } targets.GetEnumerator().MoveNext(); } }
protected override void Impact(Thing hitThing) { base.Impact(hitThing); ThingDef def = this.def; Pawn victim = null; if (!this.initialized) { this.pawn = this.launcher as Pawn; CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>(); MagicPowerSkill pwr = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Repulsion.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Repulsion_pwr"); MagicPowerSkill ver = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Repulsion.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Repulsion_ver"); ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef(); pwrVal = pwr.level; verVal = ver.level; if (pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless)) { MightPowerSkill mpwr = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr"); MightPowerSkill mver = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver"); pwrVal = mpwr.level; verVal = mver.level; } this.arcaneDmg = comp.arcaneDmg; if (settingsRef.AIHardMode && !pawn.IsColonist) { pwrVal = 3; verVal = 3; } this.strikeDelay = this.strikeDelay - verVal; this.radius = this.def.projectile.explosionRadius; this.duration = Mathf.RoundToInt(this.radius * this.strikeDelay); this.initialized = true; this.targets = GenRadial.RadialCellsAround(base.Position, strikeNum, false); this.casterSensitivity = this.pawn.GetStatValue(StatDefOf.PsychicSensitivity, false); cellList = targets.ToList <IntVec3>(); } if (Find.TickManager.TicksGame % this.strikeDelay == 0) { int force = Mathf.RoundToInt((10 + (2 * pwrVal) - strikeNum) * casterSensitivity); IntVec3 curCell; for (int i = 0; i < cellList.Count; i++) { curCell = cellList[i]; Vector3 angle = GetVector(base.Position, curCell); TM_MoteMaker.ThrowArcaneWaveMote(curCell.ToVector3(), this.Map, .3f * (curCell - base.Position).LengthHorizontal, .1f, .05f, .3f, 0, 3, (Quaternion.AngleAxis(90, Vector3.up) * angle).ToAngleFlat(), (Quaternion.AngleAxis(90, Vector3.up) * angle).ToAngleFlat()); if (curCell.IsValid && curCell.InBounds(this.Map)) { victim = curCell.GetFirstPawn(this.Map); if (victim != null && !victim.Dead) { Vector3 launchVector = GetVector(base.Position, victim.Position); IntVec3 projectedPosition = victim.Position + (force * launchVector).ToIntVec3(); if (projectedPosition.IsValid && projectedPosition.InBounds(this.Map)) { if (Rand.Chance(TM_Calc.GetSpellSuccessChance(pawn, victim, true))) { damageEntities(victim, force * (.2f * verVal), DamageDefOf.Blunt); LaunchFlyingObect(projectedPosition, victim, force); } } } } } strikeNum++; IEnumerable <IntVec3> newTargets = GenRadial.RadialCellsAround(base.Position, strikeNum, false); try { cellList = newTargets.Except(targets).ToList <IntVec3>(); } catch { cellList = newTargets.ToList <IntVec3>(); } targets = newTargets; } }
internal virtual List <IntVec3> GetAffectedCellsAtPosition(IntVec3 position, float radius) { return(GenRadial.RadialCellsAround(position, radius, true).ToList()); }
private void DropBomb() { for (int i = 0; i < (bombType == BombingType.precise ? this.precisionBombingNumBombs : 1); ++i) { if (innerContainer.Any(x => ((ActiveDropPod)x)?.Contents.innerContainer.Any(y => SRTSMod.mod.settings.allowedBombs.Contains(y.def.defName)) ?? false)) { ActiveDropPod srts = (ActiveDropPod)innerContainer.First(); Thing thing = srts?.Contents.innerContainer.FirstOrDefault(y => SRTSMod.mod.settings.allowedBombs.Contains(y.def.defName)); if (thing is null) { return; } Thing thing2 = srts?.Contents.innerContainer.Take(thing, 1); IntVec3 bombPos = bombCells[0]; if (bombType == BombingType.carpet) { bombCells.RemoveAt(0); } int timerTickExplode = 20 + Rand.Range(0, 5); //Change later to allow release timer if (SRTSHelper.CEModLoaded) { goto Block_CEPatched; } FallingBomb bombThing = new FallingBomb(thing2, thing2.TryGetComp <CompExplosive>(), this.Map, this.def.skyfaller.shadow); bombThing.HitPoints = int.MaxValue; bombThing.ticksRemaining = timerTickExplode; IntVec3 c = (from x in GenRadial.RadialCellsAround(bombPos, GetCurrentTargetingRadius(), true) where x.InBounds(this.Map) select x).RandomElementByWeight((IntVec3 x) => 1f - Mathf.Min(x.DistanceTo(this.Position) / GetCurrentTargetingRadius(), 1f) + 0.05f); bombThing.angle = this.angle + (SPTrig.LeftRightOfLine(this.DrawPosCell, this.Position, c) * -10); bombThing.speed = (float)SPExtra.Distance(this.DrawPosCell, c) / bombThing.ticksRemaining; Thing t = GenSpawn.Spawn(bombThing, c, this.Map); GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(t, thing2.TryGetComp <CompExplosive>().Props.explosiveDamageType, null); continue; Block_CEPatched :; // Replaced referencing the projectile trough the detonateProjectile property of the item's def with referencing trough AmmoSetDef. The reason is taht not all mortar shells had detonateProjectile. Don't ask how I came up with this. ProjectileCE_Explosive bombCE = (ProjectileCE_Explosive)ThingMaker.MakeThing((thing2.def as AmmoDef).AmmoSetDefs.Find(set => set.ammoTypes.Any()).ammoTypes.Find(link => link.ammo == (thing2.def as AmmoDef)).projectile, null); //ProjectileCE_Explosive bombCE = (ProjectileCE_Explosive)ThingMaker.MakeThing((AccessTools.Field(thing2.def.GetType(), "detonateProjectile").GetValue(thing2.def) as ThingDef), null); /*ThingComp CEComp = (thing2 as ThingWithComps)?.AllComps.Find(x => x.GetType().Name == "CompExplosiveCE"); * FallingBombCE CEbombThing = new FallingBombCE(thing2, CEComp.props, CEComp, this.Map, this.def.skyfaller.shadow); * CEbombThing.HitPoints = int.MaxValue; * CEbombThing.ticksRemaining = timerTickExplode;*/ IntVec3 c2 = (from x in GenRadial.RadialCellsAround(bombPos, GetCurrentTargetingRadius(), true) where x.InBounds(this.Map) select x).RandomElementByWeight((IntVec3 x) => 1f - Mathf.Min(x.DistanceTo(this.Position) / GetCurrentTargetingRadius(), 1f) + 0.05f); /*CEbombThing.angle = this.angle + (SPTrig.LeftRightOfLine(this.DrawPosCell, this.Position, c2) * -10); * CEbombThing.speed = (float)SPExtra.Distance(this.DrawPosCell, c2) / CEbombThing.ticksRemaining; * Thing CEt = GenSpawn.Spawn(CEbombThing, c2, this.Map);*/ //Basically Im stea- "borrrowing" code from Verb_LaunchProjectileCE. GenSpawn.Spawn(bombCE, this.DrawPosCell, this.Map); bombCE.canTargetSelf = false; bombCE.minCollisionDistance = 1; bombCE.intendedTarget = null; bombCE.AccuracyFactor = 1f; bombCE.Launch(this, this.DrawPosCell.ToIntVec2.ToVector2(), 0f, this.angle + UnityEngine.Random.Range(-60f, 60f), 5f, (float)SPExtra.Distance(this.DrawPosCell, c2), this); //GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(CEt, DamageDefOf., null); /*Is GenExplosion CE compatible?*/ } } if (bombType == BombingType.precise && bombCells.Any()) { bombCells.Clear(); } }
public void SearchForTargets(IntVec3 center, float radius) { Pawn curPawnTarg = null; Building curBldgTarg = null; IntVec3 curCell; IEnumerable <IntVec3> targets = GenRadial.RadialCellsAround(center, radius, true); for (int i = 0; i < targets.Count(); i++) { curCell = targets.ToArray <IntVec3>()[i]; if (curCell.InBounds(base.Map) && curCell.IsValid) { curPawnTarg = curCell.GetFirstPawn(base.Map); curBldgTarg = curCell.GetFirstBuilding(base.Map); } if (curPawnTarg != null && curPawnTarg != launcher) { bool newTarg = false; if (this.age > this.lastStrike + (this.maxStrikeDelay - (int)Rand.Range(0 + (pwrVal * 20), 40 + (pwrVal * 15)))) { if (Rand.Chance(.1f)) { newTarg = true; } if (newTarg) { CellRect cellRect = CellRect.CenteredOn(curCell, 2); cellRect.ClipInsideMap(base.Map); DrawStrike(center, curPawnTarg.Position.ToVector3()); for (int k = 0; k < Rand.Range(1, 8); k++) { IntVec3 randomCell = cellRect.RandomCell; GenExplosion.DoExplosion(randomCell, base.Map, Rand.Range(.4f, .8f), TMDamageDefOf.DamageDefOf.TM_Lightning, this.launcher, Mathf.RoundToInt(Rand.Range(5 + pwrVal, 9 + 3 * pwrVal) * this.arcaneDmg), SoundDefOf.Thunder_OnMap, null, null, null, 0f, 1, false, null, 0f, 1, 0.1f, true); } GenExplosion.DoExplosion(curPawnTarg.Position, base.Map, 1f, TMDamageDefOf.DamageDefOf.TM_Lightning, this.launcher, Mathf.RoundToInt(Rand.Range(5 + pwrVal, 9 + 3 * pwrVal) * this.arcaneDmg), SoundDefOf.Thunder_OffMap, null, null, null, 0f, 1, false, null, 0f, 1, 0.1f, true); this.lastStrike = this.age; } } } if (curBldgTarg != null) { bool newTarg = false; if (this.age > this.lastStrikeBldg + (this.maxStrikeDelayBldg - (int)Rand.Range(0 + (pwrVal * 10), (pwrVal * 15)))) { if (Rand.Chance(.1f)) { newTarg = true; } if (newTarg) { CellRect cellRect = CellRect.CenteredOn(curCell, 1); cellRect.ClipInsideMap(base.Map); DrawStrike(center, curBldgTarg.Position.ToVector3()); for (int k = 0; k < Rand.Range(1, 8); k++) { IntVec3 randomCell = cellRect.RandomCell; GenExplosion.DoExplosion(randomCell, base.Map, Rand.Range(.2f, .6f), TMDamageDefOf.DamageDefOf.TM_Lightning, this.launcher, Mathf.RoundToInt(Rand.Range(3 + 3 * pwrVal, 7 + 5 * pwrVal) * this.arcaneDmg), SoundDefOf.Thunder_OffMap, null, null, null, 0f, 1, false, null, 0f, 1, 0.1f, true); } GenExplosion.DoExplosion(curBldgTarg.Position, base.Map, 1f, TMDamageDefOf.DamageDefOf.TM_Lightning, this.launcher, Mathf.RoundToInt(Rand.Range(5 + 5 * pwrVal, 10 + 10 * pwrVal) * this.arcaneDmg), SoundDefOf.Thunder_OffMap, null, null, null, 0f, 1, false, null, 0f, 1, 0.1f, true); this.lastStrikeBldg = this.age; } } } targets.GetEnumerator().MoveNext(); } DrawStrikeFading(); age++; }
public void ShieldTick(bool flag_direct, bool flag_indirect, bool flag_fireSupression, bool flag_InterceptDropPod, bool shieldRepairMode) { if (!this.enabled) { return; } ++this.tick; if (this.online && this.shieldCurrentStrength > 0) { if (this.shieldStructuralIntegrityMode) { this.SetupCurrentSquares(); using (List <IntVec3> .Enumerator enumerator = this.squares.GetEnumerator()) { while (enumerator.MoveNext()) { IntVec3 current = enumerator.Current; this.ProtectSquare(current, flag_direct, flag_indirect, true); this.supressFire(flag_fireSupression, current); this.repairSytem(current, shieldRepairMode); if (this.shieldCurrentStrength <= 0) { break; } } } } else { using (IEnumerator <IntVec3> enumerator = GenRadial.RadialCellsAround(new IntVec3(0, 0, 0), (float)this.shieldShieldRadius, false).GetEnumerator()) { while (((IEnumerator)enumerator).MoveNext()) { IntVec3 current = enumerator.Current; if (Vectors.VectorSize(current) >= (double)this.shieldShieldRadius - 1.5) { this.ProtectSquare(IntVec3.op_Addition(current, this.position), flag_direct, flag_indirect, false); } if (this.shieldCurrentStrength <= 0) { break; } } } this.supressFire(flag_fireSupression); this.interceptPods(flag_InterceptDropPod); } } if (this.online && (this.tick % (long)this.shieldRechargeTickDelay == 0L || DebugSettings.unlimitedPower != null) && this.shieldCurrentStrength < this.shieldMaxShieldStrength) { ++this.shieldCurrentStrength; } else { if (this.online) { return; } if (this.warmupTicksCurrent < this.shieldRecoverWarmup) { ++this.warmupTicksCurrent; if (DebugSettings.unlimitedPower == null) { return; } this.warmupTicksCurrent += 5; } else { this.StartupField(this.shieldInitialShieldStrength); } } }
// Token: 0x0600061C RID: 1564 RVA: 0x00058160 File Offset: 0x00056360 public override void CompTick() { base.CompTick(); bool spawned = this.Pawn.Spawned; if (spawned) { bool flag = Find.TickManager.TicksGame % 10 == 0; if (flag) { bool flag2 = this.Pawn.Downed && !this.Pawn.Dead; if (flag2) { GenExplosion.DoExplosion(this.Pawn.Position, this.Pawn.Map, Rand.Range(this.explosionRadius * 0.5f, this.explosionRadius * 1.5f), DamageDefOf.Burn, this.Pawn, Rand.Range(6, 10), 0f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false); this.Pawn.Kill(null, null); } } bool flag3 = Find.TickManager.TicksGame % this.nextLeap == 0 && !this.Pawn.Downed && !this.Pawn.Dead; if (flag3) { LocalTargetInfo a = null; bool flag4 = this.Pawn.CurJob != null && this.Pawn.CurJob.targetA != null; if (flag4) { a = this.Pawn.jobs.curJob.targetA.Thing; } bool flag5 = a != null && a.Thing != null; if (flag5) { Thing thing = a.Thing; bool flag6 = thing is Pawn && thing.Spawned; if (flag6) { float lengthHorizontal = (thing.Position - this.Pawn.Position).LengthHorizontal; bool flag7 = lengthHorizontal <= this.Props.leapRangeMax && lengthHorizontal > this.Props.leapRangeMin; if (flag7) { bool flag8 = Rand.Chance(this.Props.GetLeapChance); if (flag8) { bool flag9 = this.CanHitTargetFrom(this.Pawn.Position, thing); if (flag9) { this.LeapAttack(thing); } } else { bool textMotes = this.Props.textMotes; if (textMotes) { bool flag10 = Rand.Chance(0.5f); if (flag10) { MoteMaker.ThrowText(this.Pawn.DrawPos, this.Pawn.Map, "grrr", -1f); } else { MoteMaker.ThrowText(this.Pawn.DrawPos, this.Pawn.Map, "hsss", -1f); } } } } else { bool bouncingLeaper = this.Props.bouncingLeaper; if (bouncingLeaper) { Faction faction = null; bool flag11 = thing != null && thing.Faction != null; if (flag11) { faction = thing.Faction; } IEnumerable <IntVec3> enumerable = GenRadial.RadialCellsAround(this.Pawn.Position, this.Props.leapRangeMax, false); for (int i = 0; i < enumerable.Count <IntVec3>(); i++) { Pawn pawn = null; IntVec3 c = enumerable.ToArray <IntVec3>()[i]; bool flag12 = c.InBounds(this.Pawn.Map) && c.IsValid; if (flag12) { pawn = c.GetFirstPawn(this.Pawn.Map); bool flag13 = pawn != null && pawn != thing && !pawn.Downed && !pawn.Dead && pawn.RaceProps != null; if (flag13) { bool flag14 = pawn.Faction != null && pawn.Faction == faction; if (flag14) { bool flag15 = Rand.Chance(1f - this.Props.leapChance); if (flag15) { i = enumerable.Count <IntVec3>(); } else { pawn = null; } } else { pawn = null; } } else { pawn = null; } } bool flag16 = pawn != null; if (flag16) { bool flag17 = this.CanHitTargetFrom(this.Pawn.Position, thing); if (flag17) { bool flag18 = !pawn.Downed && !pawn.Dead; if (flag18) { this.LeapAttack(pawn); } this.LeapAttack(pawn); break; } } enumerable.GetEnumerator().MoveNext(); } } } } } } } }
protected override void Impact(Thing hitThing) { applyHediffToPawnsInArea(this.Map, GenRadial.RadialCellsAround(this.Position, this.def.projectile.explosionRadius, true).ToHashSet(), HediffDefOf.ToxicBuildup, null); base.Impact(hitThing); }
public void TempTick() { if (compFlickable != null) { if (!compFlickable.SwitchIsOn) { if (this.active) { SetActive(false); RecalculateAffectedCells(); if (proxyHeatManager.compTemperatures.Contains(this)) { proxyHeatManager.RemoveComp(this); } } return; } } if (Props.dependsOnFuel && Props.dependsOnPower) { if (powerComp != null && powerComp.PowerOn && fuelComp != null && fuelComp.HasFuel) { if (!this.active) { this.SetActive(true); } } else if (this.active) { this.SetActive(false); } } else if (powerComp != null) { if (!powerComp.PowerOn && this.active) { this.SetActive(false); } else if (powerComp.PowerOn && !this.active) { this.SetActive(true); } } else if (fuelComp != null) { if (!fuelComp.HasFuel && this.active) { this.SetActive(false); } else if (fuelComp.HasFuel && !this.active) { this.SetActive(true); } } else if (gasComp != null) { if (!(bool)methodInfoGasOn.Invoke(gasComp, null) && this.active) { this.SetActive(false); } else if ((bool)methodInfoGasOn.Invoke(gasComp, null) && !this.active) { this.SetActive(true); } } if (dirty) { MarkDirty(); } if (active) { if (map != null && Props.smeltSnowRadius > 0) { var cellToSmeltSnow = new HashSet <IntVec3>(); foreach (var cell in this.parent.OccupiedRect()) { foreach (var cell2 in GenRadial.RadialCellsAround(cell, Props.smeltSnowRadius, true)) { if (cell2.GetSnowDepth(map) > 0 && HarmonyPatches.proxyHeatManagers.TryGetValue(map, out ProxyHeatManager proxyHeatManager)) { var finalTemperature = proxyHeatManager.GetTemperatureOutcomeFor(cell2, cell2.GetTemperature(map)); if (finalTemperature >= Props.smeltSnowAtTemperature) { cellToSmeltSnow.Add(cell2); } } } } foreach (var cell in cellToSmeltSnow) { map.snowGrid.AddDepth(cell, -Props.smeltSnowPower); } } } }
public override void Tick() { if (this.triggered) { if (this.age >= this.lastStrike + this.strikeDelay) { IntVec3 curCell; IEnumerable <IntVec3> targets = GenRadial.RadialCellsAround(base.Position, this.radius, true); for (int i = 0; i < targets.Count(); i++) { curCell = targets.ToArray <IntVec3>()[i]; if (curCell.InBounds(base.Map) && curCell.IsValid) { Pawn victim = curCell.GetFirstPawn(base.Map); if (victim != null && !victim.Dead && victim.RaceProps.IsFlesh && !victim.Downed) { damageEntities(victim, Mathf.RoundToInt(Rand.Range(2, 4)), TMDamageDefOf.DamageDefOf.TM_Poison); } } } this.lastStrike = this.age; } this.age++; if (this.age > this.duration) { Destroy(); } } else { if (this.Armed) { IntVec3 curCell; IEnumerable <IntVec3> targets = GenRadial.RadialCellsAround(base.Position, 2, true); for (int i = 0; i < targets.Count(); i++) { curCell = targets.ToArray <IntVec3>()[i]; List <Thing> thingList = curCell.GetThingList(base.Map); for (int j = 0; j < thingList.Count; j++) { Pawn pawn = thingList[j] as Pawn; if (pawn != null && !this.touchingPawns.Contains(pawn)) { if (!pawn.RaceProps.Animal && pawn.Faction != this.Faction && pawn.HostileTo(this.Faction)) { this.touchingPawns.Add(pawn); this.CheckSpring(pawn); } } } } } for (int j = 0; j < this.touchingPawns.Count; j++) { Pawn pawn2 = this.touchingPawns[j]; if (!pawn2.Spawned || pawn2.Position != base.Position) { this.touchingPawns.Remove(pawn2); } } } base.Tick(); }
public override void Generate(Map map) { if (map.Biome != Util_CaveBiome.CaveBiomeDef) { // Nothing to do. return; } // Get river origin side. int riverEntrySideAsInt = Rand.RangeInclusive(2, 3); int riverExitSideAsInt = (riverEntrySideAsInt + 2) % 4; Rot4 riverEntrySide = new Rot4(riverEntrySideAsInt); Rot4 riverExitSide = new Rot4(riverExitSideAsInt); // Get river origin and end coordinates. Vector2 riverStart = Vector2.zero; Vector2 riverEnd = Vector2.zero; switch (riverEntrySideAsInt) { default: case 2: // South. if ((riverEntrySideAsInt == 0) || (riverEntrySideAsInt == 1)) { Log.Warning("CaveBiome: river entry side (" + riverEntrySideAsInt + ") should not occur."); } riverStart = new Vector2(Rand.RangeInclusive((int)((float)(map.Size.x) * 0.25f), (int)((float)(map.Size.x) * 0.75f)), -OutOfBoundsOffset); riverEnd = new Vector2(Rand.RangeInclusive((int)((float)(map.Size.x) * 0.25f), (int)((float)(map.Size.x) * 0.75f)), map.Size.z + OutOfBoundsOffset); break; case 3: // West. riverStart = new Vector2(-OutOfBoundsOffset, Rand.RangeInclusive((int)((float)(map.Size.z) * 0.25f), (int)((float)(map.Size.z) * 0.75f))); riverEnd = new Vector2(map.Size.x + OutOfBoundsOffset, Rand.RangeInclusive((int)((float)(map.Size.z) * 0.25f), (int)((float)(map.Size.z) * 0.75f))); break; } // Get straight river points. Vector2 riverVector = riverEnd - riverStart; int numberOfParts = (int)Math.Ceiling((double)(riverVector.magnitude / RiverPartsGranularity)); Vector2 riverVectorNormalized = riverVector / (float)numberOfParts; List <Vector2> riverCoordinates = new List <Vector2>(); Vector2 vector = riverStart; for (int partIndex = 0; partIndex < numberOfParts; partIndex++) { riverCoordinates.Add(vector); vector += riverVectorNormalized; } // Generate Perlin map and apply perturbations. Perlin perlinMap = new Perlin(0.05, 2.0, 0.5, 4, Rand.Range(0, 2147483647), QualityMode.High); List <Vector2> riverCoordinatesCopy = riverCoordinates.ListFullCopy <Vector2>(); riverCoordinates.Clear(); List <float> riverWidth = new List <float>(); for (int coordinatesIndex = 0; coordinatesIndex < riverCoordinatesCopy.Count; coordinatesIndex++) { float perturbation = RiverLateralFactor * (float)perlinMap.GetValue((double)coordinatesIndex, 0.0, 0.0); Vector2 pointCoordinates = Vector2.zero; if (riverEntrySide == Rot4.South) { pointCoordinates = riverCoordinatesCopy[coordinatesIndex] + perturbation * Vector2.right; } else { pointCoordinates = riverCoordinatesCopy[coordinatesIndex] + perturbation * Vector2.down; } riverCoordinates.Add(pointCoordinates); float width = Mathf.Min(Mathf.Abs(RiverWidthFactor * (float)perlinMap.GetValue(0.0, 0.0, (double)coordinatesIndex)), 8f); riverWidth.Add(width); } // Generate river from coordinates. for (int coordinatesIndex = 0; coordinatesIndex < riverCoordinates.Count - 1; coordinatesIndex++) { float width = Mathf.Max(2.5f, riverWidth[coordinatesIndex]); Vector2 riverPart = riverCoordinates[coordinatesIndex + 1] - riverCoordinates[coordinatesIndex]; Vector2 riverPartNormalized = riverPart / RiverPartsGranularity; for (int pointIndex = 0; pointIndex < RiverPartsGranularity; pointIndex++) { IntVec3 point = new IntVec3(riverCoordinates[coordinatesIndex]) + new IntVec3(pointIndex * riverPartNormalized); // Generate mud. foreach (IntVec3 cell in GenRadial.RadialCellsAround(point, width + 1.9f, true)) { if (cell.InBounds(map) == false) { continue; } Thing building = cell.GetEdifice(map); if (building != null) { continue; } TerrainDef terrain = map.terrainGrid.TerrainAt(cell); // Do not change stony terrains. if ((terrain.defName.Contains("Rough") == false) && (terrain != TerrainDefOf.WaterShallow) && (terrain != TerrainDefOf.WaterDeep)) { map.terrainGrid.SetTerrain(cell, TerrainDef.Named("Mud")); } } // Generate shallow water and remove building/roof. foreach (IntVec3 cell in GenRadial.RadialCellsAround(point, width, true)) { if (cell.InBounds(map) == false) { continue; } Thing building = cell.GetEdifice(map); if (building != null) { building.Destroy(); } if (map.roofGrid.Roofed(cell)) { map.roofGrid.SetRoof(cell, null); } TerrainDef terrain = map.terrainGrid.TerrainAt(cell); if (terrain != TerrainDefOf.WaterDeep) { map.terrainGrid.SetTerrain(cell, TerrainDefOf.WaterShallow); } } // Generate deep water. if (width > 4) { foreach (IntVec3 cell in GenRadial.RadialCellsAround(point, width - 3.9f, true)) { if (cell.InBounds(map) == false) { continue; } map.terrainGrid.SetTerrain(cell, TerrainDefOf.WaterDeep); } } } } IntVec3 offset = IntVec3.Zero; if (riverEntrySide == Rot4.South) { offset = new IntVec3(8, 0, 0); } else { offset = new IntVec3(0, 0, 8); } MapGenerator.PlayerStartSpot = new IntVec3(riverCoordinates[riverCoordinates.Count / 2]) + offset; }
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) { hitThing.TakeDamage(this.impactDamage.Value); } try { SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f); if (this.flyingThing != null) { GenSpawn.Spawn(this.flyingThing, base.Position, base.Map); if (this.flyingThing is Pawn) { Pawn p = this.flyingThing as Pawn; if (p.IsColonist && this.drafted) { p.drafter.Drafted = true; } if (this.earlyImpact) { damageEntities(p, this.impactForce, DamageDefOf.Blunt); damageEntities(p, this.impactForce, DamageDefOf.Stun); } } else if (flyingThing.def.thingCategories != null && (flyingThing.def.thingCategories.Contains(ThingCategoryDefOf.Chunks) || flyingThing.def.thingCategories.Contains(ThingCategoryDef.Named("StoneChunks")))) { float radius = 4f; Vector3 center = this.ExactPosition; if (this.earlyImpact) { bool wallFlag90neg = false; IntVec3 wallCheck = (center + (Quaternion.AngleAxis(-90, Vector3.up) * this.direction)).ToIntVec3(); MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map); wallFlag90neg = wallCheck.Walkable(base.Map); wallCheck = (center + (Quaternion.AngleAxis(90, Vector3.up) * this.direction)).ToIntVec3(); MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map); bool wallFlag90 = wallCheck.Walkable(base.Map); if ((!wallFlag90 && !wallFlag90neg) || (wallFlag90 && wallFlag90neg)) { //fragment energy bounces in reverse direction of travel center = center + ((Quaternion.AngleAxis(180, Vector3.up) * this.direction) * 3); } else if (wallFlag90) { center = center + ((Quaternion.AngleAxis(90, Vector3.up) * this.direction) * 3); } else if (wallFlag90neg) { center = center + ((Quaternion.AngleAxis(-90, Vector3.up) * this.direction) * 3); } } List <IntVec3> damageRing = GenRadial.RadialCellsAround(base.Position, radius, true).ToList(); List <IntVec3> outsideRing = GenRadial.RadialCellsAround(base.Position, radius, false).Except(GenRadial.RadialCellsAround(base.Position, radius - 1, true)).ToList(); for (int i = 0; i < damageRing.Count; i++) { List <Thing> allThings = damageRing[i].GetThingList(base.Map); for (int j = 0; j < allThings.Count; j++) { if (allThings[j] is Pawn) { damageEntities(allThings[j], Rand.Range(14, 22), DamageDefOf.Blunt); } else if (allThings[j] is Building) { damageEntities(allThings[j], Rand.Range(56, 88), DamageDefOf.Blunt); } else { if (Rand.Chance(.1f)) { GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_RubbleRock), damageRing[i], base.Map, ThingPlaceMode.Near); } } } } for (int i = 0; i < outsideRing.Count; i++) { IntVec3 intVec = outsideRing[i]; if (intVec.IsValid && intVec.InBounds(base.Map)) { Vector3 moteDirection = TM_Calc.GetVector(this.ExactPosition.ToIntVec3(), intVec); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Rubble"), this.ExactPosition, base.Map, Rand.Range(.3f, .6f), .2f, .02f, .05f, Rand.Range(-100, 100), Rand.Range(8f, 13f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0); TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_Smoke, this.ExactPosition, base.Map, Rand.Range(.9f, 1.2f), .3f, .02f, Rand.Range(.25f, .4f), Rand.Range(-100, 100), Rand.Range(5f, 8f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0); GenExplosion.DoExplosion(intVec, base.Map, .4f, DamageDefOf.Blunt, pawn, 0, 0, SoundDefOf.Pawn_Melee_Punch_HitBuilding, null, null, null, ThingDefOf.Filth_RubbleRock, .25f, 1, false, null, 0f, 1, 0, false); //MoteMaker.ThrowSmoke(intVec.ToVector3Shifted(), base.Map, Rand.Range(.6f, 1f)); } } //damageEntities(this.flyingThing, 305, DamageDefOf.Blunt); this.flyingThing.Destroy(DestroyMode.Vanish); } else if ((flyingThing.def.thingCategories != null && (flyingThing.def.thingCategories.Contains(ThingCategoryDefOf.Corpses))) || this.flyingThing is Corpse) { Corpse flyingCorpse = this.flyingThing as Corpse; float radius = 3f; Vector3 center = this.ExactPosition; if (this.earlyImpact) { bool wallFlag90neg = false; IntVec3 wallCheck = (center + (Quaternion.AngleAxis(-90, Vector3.up) * this.direction)).ToIntVec3(); MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map); wallFlag90neg = wallCheck.Walkable(base.Map); wallCheck = (center + (Quaternion.AngleAxis(90, Vector3.up) * this.direction)).ToIntVec3(); MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map); bool wallFlag90 = wallCheck.Walkable(base.Map); if ((!wallFlag90 && !wallFlag90neg) || (wallFlag90 && wallFlag90neg)) { //fragment energy bounces in reverse direction of travel center = center + ((Quaternion.AngleAxis(180, Vector3.up) * this.direction) * 3); } else if (wallFlag90) { center = center + ((Quaternion.AngleAxis(90, Vector3.up) * this.direction) * 3); } else if (wallFlag90neg) { center = center + ((Quaternion.AngleAxis(-90, Vector3.up) * this.direction) * 3); } } List <IntVec3> damageRing = GenRadial.RadialCellsAround(base.Position, radius, true).ToList(); List <IntVec3> outsideRing = GenRadial.RadialCellsAround(base.Position, radius, false).Except(GenRadial.RadialCellsAround(base.Position, radius - 1, true)).ToList(); Filth filth = (Filth)ThingMaker.MakeThing(flyingCorpse.InnerPawn.def.race.BloodDef); for (int i = 0; i < damageRing.Count; i++) { List <Thing> allThings = damageRing[i].GetThingList(base.Map); for (int j = 0; j < allThings.Count; j++) { if (allThings[j] is Pawn) { damageEntities(allThings[j], Rand.Range(18, 28), DamageDefOf.Blunt); } else if (allThings[j] is Building) { damageEntities(allThings[j], Rand.Range(56, 88), DamageDefOf.Blunt); } else { if (Rand.Chance(.05f)) { if (filth != null) { filth = (Filth)ThingMaker.MakeThing(flyingCorpse.InnerPawn.def.race.BloodDef); GenPlace.TryPlaceThing(filth, damageRing[i], base.Map, ThingPlaceMode.Near); } else { GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_Blood), damageRing[i], base.Map, ThingPlaceMode.Near); } } if (Rand.Chance(.05f)) { GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_CorpseBile), damageRing[i], base.Map, ThingPlaceMode.Near); } } } } for (int i = 0; i < outsideRing.Count; i++) { IntVec3 intVec = outsideRing[i]; if (intVec.IsValid && intVec.InBounds(base.Map)) { Vector3 moteDirection = TM_Calc.GetVector(this.ExactPosition.ToIntVec3(), intVec); TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_BloodSquirt, this.ExactPosition, base.Map, Rand.Range(.3f, .6f), .2f, .02f, .05f, Rand.Range(-100, 100), Rand.Range(4f, 13f), (Quaternion.AngleAxis(Rand.Range(60, 120), Vector3.up) * moteDirection).ToAngleFlat(), 0); TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_BloodMist, this.ExactPosition, base.Map, Rand.Range(.9f, 1.2f), .3f, .02f, Rand.Range(.25f, .4f), Rand.Range(-100, 100), Rand.Range(5f, 8f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0); GenExplosion.DoExplosion(intVec, base.Map, .4f, DamageDefOf.Blunt, pawn, 0, 0, SoundDefOf.Pawn_Melee_Punch_HitBuilding, null, null, null, filth.def, .08f, 1, false, null, 0f, 1, 0, false); //MoteMaker.ThrowSmoke(intVec.ToVector3Shifted(), base.Map, Rand.Range(.6f, 1f)); } } //damageEntities(this.flyingThing, 305, DamageDefOf.Blunt); //this.flyingThing.Destroy(DestroyMode.Vanish); } } else { float radius = 2f; Vector3 center = this.ExactPosition; if (this.earlyImpact) { bool wallFlag90neg = false; IntVec3 wallCheck = (center + (Quaternion.AngleAxis(-90, Vector3.up) * this.direction)).ToIntVec3(); MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map); wallFlag90neg = wallCheck.Walkable(base.Map); wallCheck = (center + (Quaternion.AngleAxis(90, Vector3.up) * this.direction)).ToIntVec3(); MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map); bool wallFlag90 = wallCheck.Walkable(base.Map); if ((!wallFlag90 && !wallFlag90neg) || (wallFlag90 && wallFlag90neg)) { //fragment energy bounces in reverse direction of travel center = center + ((Quaternion.AngleAxis(180, Vector3.up) * this.direction) * 3); } else if (wallFlag90) { center = center + ((Quaternion.AngleAxis(90, Vector3.up) * this.direction) * 3); } else if (wallFlag90neg) { center = center + ((Quaternion.AngleAxis(-90, Vector3.up) * this.direction) * 3); } } List <IntVec3> damageRing = GenRadial.RadialCellsAround(base.Position, radius, true).ToList(); List <IntVec3> outsideRing = GenRadial.RadialCellsAround(base.Position, radius, false).Except(GenRadial.RadialCellsAround(base.Position, radius - 1, true)).ToList(); for (int i = 0; i < damageRing.Count; i++) { List <Thing> allThings = damageRing[i].GetThingList(base.Map); for (int j = 0; j < allThings.Count; j++) { if (allThings[j] is Pawn) { damageEntities(allThings[j], Rand.Range(10, 16), DamageDefOf.Blunt); } else if (allThings[j] is Building) { damageEntities(allThings[j], Rand.Range(32, 88), DamageDefOf.Blunt); } else { if (Rand.Chance(.1f)) { GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_RubbleRock), damageRing[i], base.Map, ThingPlaceMode.Near); } } } } for (int i = 0; i < outsideRing.Count; i++) { IntVec3 intVec = outsideRing[i]; if (intVec.IsValid && intVec.InBounds(base.Map)) { Vector3 moteDirection = TM_Calc.GetVector(this.ExactPosition.ToIntVec3(), intVec); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Rubble"), this.ExactPosition, base.Map, Rand.Range(.3f, .6f), .2f, .02f, .05f, Rand.Range(-100, 100), Rand.Range(8f, 13f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0); TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_Smoke, this.ExactPosition, base.Map, Rand.Range(.9f, 1.2f), .3f, .02f, Rand.Range(.25f, .4f), Rand.Range(-100, 100), Rand.Range(5f, 8f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0); GenExplosion.DoExplosion(intVec, base.Map, .4f, DamageDefOf.Blunt, pawn, 0, 0, SoundDefOf.Pawn_Melee_Punch_HitBuilding, null, null, null, null, .4f, 1, false, null, 0f, 1, 0, false); //MoteMaker.ThrowSmoke(intVec.ToVector3Shifted(), base.Map, Rand.Range(.6f, 1f)); } } } this.Destroy(DestroyMode.Vanish); } catch { if (this.flyingThing != null) { if (!this.flyingThing.Spawned) { GenSpawn.Spawn(this.flyingThing, base.Position, base.Map); Log.Message("catch"); } } this.Destroy(DestroyMode.Vanish); } }
private static float FriendlyFireConeTargetScoreOffset(IAttackTarget target, IAttackTargetSearcher searcher, Verb verb) { Pawn pawn = searcher.Thing as Pawn; if (pawn == null) { return(0f); } if ((int)pawn.RaceProps.intelligence < 1) { return(0f); } if (pawn.RaceProps.IsMechanoid) { return(0f); } Verb_Shoot verb_Shoot = verb as Verb_Shoot; if (verb_Shoot == null) { return(0f); } ThingDef defaultProjectile = verb_Shoot.verbProps.defaultProjectile; if (defaultProjectile == null) { return(0f); } if (defaultProjectile.projectile.flyOverhead) { return(0f); } Map map = pawn.Map; ShotReport report = ShotReport.HitReportFor(pawn, verb, (Thing)target); float radius = Mathf.Max(VerbUtility.CalculateAdjustedForcedMiss(verb.verbProps.forcedMissRadius, report.ShootLine.Dest - report.ShootLine.Source), 1.5f); IEnumerable <IntVec3> enumerable = (from dest in GenRadial.RadialCellsAround(report.ShootLine.Dest, radius, useCenter: true) where dest.InBounds(map) select new ShootLine(report.ShootLine.Source, dest)).SelectMany((ShootLine line) => line.Points().Concat(line.Dest).TakeWhile((IntVec3 pos) => pos.CanBeSeenOverFast(map))).Distinct(); float num = 0f; foreach (IntVec3 item in enumerable) { float num2 = VerbUtility.InterceptChanceFactorFromDistance(report.ShootLine.Source.ToVector3Shifted(), item); if (!(num2 <= 0f)) { List <Thing> thingList = item.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing is IAttackTarget && thing != target) { float num3 = (thing == searcher) ? 40f : ((!(thing is Pawn)) ? 10f : (thing.def.race.Animal ? 7f : 18f)); num3 *= num2; num3 = ((!searcher.Thing.HostileTo(thing)) ? (num3 * -1f) : (num3 * 0.6f)); num += num3; } } } } return(num); }
protected override void Impact(Thing hitThing) { if (!this.initialized) { base.Impact(hitThing); this.initialized = true; this.BF = new List <BloodFire>(); this.BF.Clear(); ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef(); Pawn pawn = this.launcher as Pawn; CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>(); MagicPowerSkill bpwr = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_BloodGift.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_BloodGift_pwr"); MagicPowerSkill pwr = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_IgniteBlood.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_IgniteBlood_pwr"); MagicPowerSkill ver = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_IgniteBlood.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_IgniteBlood_ver"); pwrVal = pwr.level; verVal = ver.level; if (pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless)) { MightPowerSkill mpwr = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr"); MightPowerSkill mver = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver"); pwrVal = mpwr.level; verVal = mver.level; } this.arcaneDmg = comp.arcaneDmg; this.arcaneDmg *= 1 + (.1f * bpwr.level); this.spreadRate -= 2 * verVal; if (settingsRef.AIHardMode && !pawn.IsColonist) { pwrVal = 3; verVal = 3; } this.bloodTypes = new HashSet <ThingDef>(); if (settingsRef.unrestrictedBloodTypes) { this.pawnBloodDef = pawn.RaceProps.BloodDef; this.bloodTypes = TM_Calc.AllRaceBloodTypes.ToHashSet(); } else { this.pawnBloodDef = ThingDefOf.Filth_Blood; this.bloodTypes.Add(this.pawnBloodDef); } List <IntVec3> cellList = GenRadial.RadialCellsAround(base.Position, this.def.projectile.explosionRadius, true).ToList(); Filth filth = (Filth)ThingMaker.MakeThing(this.pawnBloodDef); GenSpawn.Spawn(filth, base.Position, pawn.Map); //FilthMaker.MakeFilth(base.Position, this.Map, ThingDefOf.Filth_Blood, 1); for (int i = 0; i < 30; i++) { IntVec3 randomCell = cellList.RandomElement(); if (randomCell.IsValid && randomCell.InBounds(pawn.Map) && !randomCell.Fogged(pawn.Map) && randomCell.Walkable(pawn.Map)) { //FilthMaker.MakeFilth(randomCell, this.Map, ThingDefOf.Filth_Blood, 1); //Log.Message("creating blood at " + randomCell); Filth filth2 = (Filth)ThingMaker.MakeThing(this.pawnBloodDef); GenSpawn.Spawn(filth2, randomCell, pawn.Map); } } this.BF.Add(new BloodFire(base.Position, 0)); } if (this.age > 0 && Find.TickManager.TicksGame % this.spreadRate == 0) { BurnBloodAtCell(); FindNearbyBloodCells(); } if (this.BF.Count <= 0) { this.age = this.duration; } if (this.age >= this.duration) { this.Destroy(DestroyMode.Vanish); } }
protected virtual 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) { hitThing.TakeDamage(this.impactDamage.Value); } try { IntVec3 centerCell = base.Position; IntVec3 curCell; WizardryDefOf.SoftExplosion.PlayOneShot(new TargetInfo(base.Position, pawn.Map, false)); for (int k = 0; k < 1; k++) { IEnumerable <IntVec3> oldExplosionCells = GenRadial.RadialCellsAround(centerCell, k, true); IEnumerable <IntVec3> newExplosionCells = GenRadial.RadialCellsAround(centerCell, k + 1, true); IEnumerable <IntVec3> explosionCells = newExplosionCells.Except(oldExplosionCells); for (int i = 0; i < explosionCells.Count(); i++) { curCell = explosionCells.ToArray <IntVec3>()[i]; if (curCell.InBounds(base.Map) && curCell.IsValid) { Vector3 heading = (curCell - centerCell).ToVector3(); float distance = heading.magnitude; Vector3 direction = heading / distance; EffectMaker.MakeEffect(WizardryDefOf.Mote_ExpandingFlame, curCell.ToVector3(), base.Map, .8f, (Quaternion.AngleAxis(90, Vector3.up) * direction).ToAngleFlat(), 4f, Rand.Range(100, 200)); EffectMaker.MakeEffect(WizardryDefOf.Mote_RecedingFlame, curCell.ToVector3(), base.Map, .7f, (Quaternion.AngleAxis(90, Vector3.up) * direction).ToAngleFlat(), 1f, 0); List <Thing> hitList = curCell.GetThingList(base.Map); Thing burnThing = null; for (int j = 0; j < hitList.Count; j++) { burnThing = hitList[j]; DamageEntities(burnThing, Rand.Range(6, 16), DamageDefOf.Flame); } //GenExplosion.DoExplosion(this.currentPos.ToIntVec3(), this.Map, .4f, DamageDefOf.Flame, this.launcher, 10, SoundDefOf.ArtilleryShellLoaded, def, this.equipmentDef, null, 0f, 1, false, null, 0f, 1, 0f, false); if (Rand.Chance(.5f)) { FireUtility.TryStartFireIn(curCell, base.Map, Rand.Range(.1f, .25f)); } } } } //SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f); //GenSpawn.Spawn(this.flyingThing, base.Position, base.Map); //Pawn p = this.flyingThing as Pawn; //if (this.earlyImpact) //{ // DamageEntities(p, this.impactForce, DamageDefOf.Blunt); // DamageEntities(p, 2 * this.impactForce, DamageDefOf.Stun); //} this.Destroy(DestroyMode.Vanish); } catch { //GenSpawn.Spawn(this.flyingThing, base.Position, base.Map); //Pawn p = this.flyingThing as Pawn; this.Destroy(DestroyMode.Vanish); } }
private static float FriendlyFireConeTargetScoreOffset(IAttackTarget target, IAttackTargetSearcher searcher, Verb verb) { if (!(searcher.Thing is Pawn pawn)) { return(0f); } if (pawn.RaceProps.intelligence < Intelligence.ToolUser) { return(0f); } if (pawn.RaceProps.IsMechanoid) { return(0f); } if (!(verb is Verb_Shoot verb_Shoot)) { return(0f); } ThingDef defaultProjectile = verb_Shoot.verbProps.defaultProjectile; if (defaultProjectile == null) { return(0f); } if (defaultProjectile.projectile.flyOverhead) { return(0f); } Map map = pawn.Map; ShotReport report = ShotReport.HitReportFor(pawn, verb, (Thing)target); float a = VerbUtility.CalculateAdjustedForcedMiss(verb.verbProps.ForcedMissRadius, report.ShootLine.Dest - report.ShootLine.Source); float radius = Mathf.Max(a, 1.5f); IntVec3 dest2 = report.ShootLine.Dest; IEnumerable <IntVec3> source = from dest in GenRadial.RadialCellsAround(dest2, radius, true) where dest.InBounds(map) select dest; IEnumerable <ShootLine> source2 = from dest in source select new ShootLine(report.ShootLine.Source, dest); IEnumerable <IntVec3> source3 = source2.SelectMany((ShootLine line) => line.Points().Concat(line.Dest).TakeWhile((IntVec3 pos) => pos.CanBeSeenOverFast(map))); IEnumerable <IntVec3> enumerable = source3.Distinct <IntVec3>(); float num = 0f; foreach (IntVec3 c in enumerable) { float num2 = VerbUtility.InterceptChanceFactorFromDistance(report.ShootLine.Source.ToVector3Shifted(), c); if (num2 > 0f) { List <Thing> thingList = c.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing is IAttackTarget && thing != target) { float num3; if (thing == searcher) { num3 = 40f; } else if (thing is Pawn) { num3 = ((!thing.def.race.Animal) ? 18f : 7f); } else { num3 = 10f; } num3 *= num2; if (searcher.Thing.HostileTo(thing)) { num3 *= 0.6f; } else { num3 *= -1f; } num += num3; } } } } return(num); }
protected static List <IntVec3> GetBeerSearchAreaCells(IntVec3 pyrePosition) { return(GenRadial.RadialCellsAround(pyrePosition, beerSearchAreaRadius, true).ToList <IntVec3>()); }
private void PodImpact() { // max side length of drawSize or actual size determine result crater radius var impactRadius = Mathf.Max(Mathf.Max(def.Size.x, def.Size.z), Mathf.Max(Graphic.drawSize.x, Graphic.drawSize.y)) * 1.5f; for (int i = 0; i < 6; i++) { Vector3 loc = Position.ToVector3Shifted() + Gen.RandomHorizontalVector(1f); MoteThrower.ThrowDustPuff(loc, 1.2f); } // Create a crashed drop pod DropPodCrashed dropPod = (DropPodCrashed)ThingMaker.MakeThing(ThingDef.Named("DropPodCrashed"), null); dropPod.info = contents; dropPod.SetFactionDirect(factionDirect); // Spawn the crater var crater = (Crater)ThingMaker.MakeThing(ThingDef.Named("Crater")); // adjust result crater size to the impact zone radius crater.impactRadius = impactRadius; // spawn the crater, rotated to the random angle, to provide visible variety GenSpawn.Spawn(crater, Position, Rot4.North); // Spawn the crashed drop pod GenSpawn.Spawn(dropPod, Position, Rotation); // For all cells around the crater centre point based on half its diameter (radius) foreach (IntVec3 current in GenRadial.RadialCellsAround(crater.Position, impactRadius, true)) { // List all things found in these cells List <Thing> list = Find.ThingGrid.ThingsListAt(current); // Reverse iterate through the things so we can destroy without breaking the pointer for (int i = list.Count - 1; i >= 0; i--) { // If its a plant, filth, or an item if (list[i].def.category == ThingCategory.Plant || list[i].def.category == ThingCategory.Filth || list[i].def.category == ThingCategory.Item) { // Destroy it list[i].Destroy(); } } } RoofDef roof = Position.GetRoof(); if (roof != null) { if (!roof.soundPunchThrough.NullOrUndefined()) { roof.soundPunchThrough.PlayOneShot(Position); } if (roof.filthLeaving != null) { for (int j = 0; j < 3; j++) { FilthMaker.MakeFilth(Position, roof.filthLeaving, 1); } } } // Do a bit of camera shake for added effect CameraShaker.DoShake(0.020f); // Fire an explosion with motes GenExplosion.DoExplosion(Position, 0.5f, DamageDefOf.Bomb, this, null, null, null, null, 0f, false, null, 0f); CellRect cellRect = CellRect.CenteredOn(Position, 2); cellRect.ClipInsideMap(); for (int i = 0; i < 5; i++) { IntVec3 randomCell = cellRect.RandomCell; MoteThrower.ThrowFireGlow(DrawPos.ToIntVec3(), 1.5f); } this.Destroy(DestroyMode.Vanish); }
protected IEnumerable <IntVec3> GetEffectArea(IntVec3 centre) { return(GenRadial.RadialCellsAround(centre, (float)this.def.effectRadius, true)); }
public void DrawEffects(IEnumerable <IntVec3> effectRadial) { if (effectRadial != null && effectRadial.Count() > 0) { IntVec3 curCell = effectRadial.RandomElement(); bool flag2 = Find.TickManager.TicksGame % 3 == 0; float fadeIn = .2f; float fadeOut = .25f; float solidTime = .05f; if (this.direction.ToAngleFlat() >= -135 && this.direction.ToAngleFlat() < -45) { TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_SpiritWolf_North, curCell.ToVector3(), base.Map, .8f, solidTime, fadeIn, fadeOut, 0, Rand.Range(5, 8), this.angle + Rand.Range(-20, 20), 0); if (flag2) { IEnumerable <IntVec3> effectRadialSmall = GenRadial.RadialCellsAround(this.ExactPosition.ToIntVec3(), 1, true); curCell = effectRadialSmall.RandomElement(); TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_SpiritWolf_North, curCell.ToVector3(), base.Map, .8f, solidTime, fadeIn, fadeOut, 0, Rand.Range(10, 15), this.angle + Rand.Range(-20, 20), 0); } } else if (this.direction.ToAngleFlat() >= 45 && this.direction.ToAngleFlat() < 135) { TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_SpiritWolf_South, curCell.ToVector3(), base.Map, .8f, solidTime, fadeIn, fadeOut, 0, Rand.Range(5, 8), this.angle + Rand.Range(-20, 20), 0); if (flag2) { IEnumerable <IntVec3> effectRadialSmall = GenRadial.RadialCellsAround(this.ExactPosition.ToIntVec3(), 1, true); curCell = effectRadialSmall.RandomElement(); TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_SpiritWolf_South, curCell.ToVector3(), base.Map, .8f, solidTime, fadeIn, fadeOut, 0, Rand.Range(10, 15), this.angle + Rand.Range(-20, 20), 0); } } else if (this.direction.ToAngleFlat() >= -45 && this.direction.ToAngleFlat() < 45) { TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_SpiritWolf_East, curCell.ToVector3(), base.Map, .8f, solidTime, fadeIn, fadeOut, 0, Rand.Range(5, 8), this.angle + Rand.Range(-20, 20), 0); if (flag2) { IEnumerable <IntVec3> effectRadialSmall = GenRadial.RadialCellsAround(this.ExactPosition.ToIntVec3(), 1, true); curCell = effectRadialSmall.RandomElement(); TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_SpiritWolf_East, curCell.ToVector3(), base.Map, .8f, solidTime, fadeIn, fadeOut, 0, Rand.Range(10, 15), this.angle + Rand.Range(-20, 20), 0); } } else { TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_SpiritWolf_West, curCell.ToVector3(), base.Map, .8f, solidTime, fadeIn, fadeOut, 0, Rand.Range(5, 8), this.angle + Rand.Range(-20, 20), 0); if (flag2) { IEnumerable <IntVec3> effectRadialSmall = GenRadial.RadialCellsAround(this.ExactPosition.ToIntVec3(), 1, true); curCell = effectRadialSmall.RandomElement(); TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_SpiritWolf_West, curCell.ToVector3(), base.Map, .8f, solidTime, fadeIn, fadeOut, 0, Rand.Range(10, 15), this.angle + Rand.Range(-20, 20), 0); } } if (lastRadial != null && lastRadial.Count() > 0) { curCell = lastRadial.RandomElement(); if (curCell.InBounds(base.Map) && curCell.IsValid) { ThingDef moteSmoke = ThingDef.Named("Mote_Smoke"); if (Rand.Chance(.5f)) { TM_MoteMaker.ThrowGenericMote(moteSmoke, curCell.ToVector3(), base.Map, Rand.Range(1.2f, 1.5f), moteSmoke.mote.solidTime, moteSmoke.mote.fadeInTime, moteSmoke.mote.fadeOutTime, Rand.Range(-2, 2), Rand.Range(.3f, .4f), this.direction.ToAngleFlat(), Rand.Range(0, 360)); } else { TM_MoteMaker.ThrowGenericMote(moteSmoke, curCell.ToVector3(), base.Map, Rand.Range(1.2f, 1.5f), moteSmoke.mote.solidTime, moteSmoke.mote.fadeInTime, moteSmoke.mote.fadeOutTime, Rand.Range(-2, 2), Rand.Range(.3f, .4f), 180 + this.direction.ToAngleFlat(), Rand.Range(0, 360)); } } } } }
public void ShieldTick(bool flag_direct, bool flag_indirect, bool flag_fireSupression, bool flag_InterceptDropPod, bool shieldRepairMode) { if (!this.enabled) { return; } ++this.tick; if (this.online && this.shieldCurrentStrength > 0) { if (this.shieldStructuralIntegrityMode) { this.SetupCurrentSquares(); foreach (IntVec3 square in this.squares) { this.ProtectSquare(square, flag_direct, flag_indirect, true); this.supressFire(flag_fireSupression, square); this.repairSytem(square, shieldRepairMode); if (this.shieldCurrentStrength <= 0) { break; } } } else { foreach (IntVec3 a in GenRadial.RadialCellsAround(new IntVec3(0, 0, 0), (float)this.shieldShieldRadius, false)) { if (Vectors.VectorSize(a) >= (double)this.shieldShieldRadius - 1.5) { this.ProtectSquare(a + this.position, flag_direct, flag_indirect, false); } if (this.shieldCurrentStrength <= 0) { break; } } this.supressFire(flag_fireSupression); this.interceptPods(flag_InterceptDropPod); } } if (this.online && (this.tick % (long)this.shieldRechargeTickDelay == 0L || DebugSettings.unlimitedPower) && this.shieldCurrentStrength < this.shieldMaxShieldStrength) { ++this.shieldCurrentStrength; } else { if (this.online) { return; } if (this.warmupTicksCurrent < this.shieldRecoverWarmup) { ++this.warmupTicksCurrent; if (!DebugSettings.unlimitedPower) { return; } this.warmupTicksCurrent += 5; } else { this.StartupField(this.shieldInitialShieldStrength); } } }
protected override void Impact(Thing hitThing) { Map map = base.Map; base.Impact(hitThing); ThingDef def = this.def; if (!this.initialized) { this.bloodCircleOuterCells = new List <IntVec3>(); this.bloodCircleOuterCells.Clear(); this.victimHitTick = new List <int>(); this.victimHitTick.Clear(); this.victims = new List <Pawn>(); this.victims.Clear(); this.wolfDmg = new List <float>(); this.wolfDmg.Clear(); caster = this.launcher as Pawn; CompAbilityUserMagic comp = caster.GetComp <CompAbilityUserMagic>(); MagicPowerSkill bpwr = comp.MagicData.MagicPowerSkill_BloodGift.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_BloodGift_pwr"); pwrVal = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_BloodMoon.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_BloodMoon_pwr").level; verVal = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_BloodMoon.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_BloodMoon_ver").level; effVal = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_BloodMoon.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_BloodMoon_eff").level; this.arcaneDmg = comp.arcaneDmg; this.arcaneDmg *= (1f + (.1f * bpwr.level)); this.attackFrequency *= (1 - (.05f * effVal)); this.duration = Mathf.RoundToInt(this.duration + (this.duration * .1f * verVal)); this.angle = Rand.Range(-2f, 2f); this.radius = this.def.projectile.explosionRadius; IntVec3 curCell = base.Position; this.CheckSpawnSustainer(); if (curCell.InBounds(map) && curCell.IsValid) { List <IntVec3> cellList = GenRadial.RadialCellsAround(base.Position, this.radius, true).ToList(); for (int i = 0; i < cellList.Count; i++) { curCell = cellList[i]; if (curCell.InBounds(map) && curCell.IsValid) { this.bloodCircleCells.Add(curCell); } } cellList.Clear(); cellList = GenRadial.RadialCellsAround(base.Position, this.radius + 1, true).ToList(); List <IntVec3> outerRing = new List <IntVec3>(); for (int i = 0; i < cellList.Count; i++) { curCell = cellList[i]; if (curCell.InBounds(map) && curCell.IsValid) { outerRing.Add(curCell); } } this.bloodCircleOuterCells = outerRing.Except(this.bloodCircleCells).ToList(); } TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodCircle"), base.Position.ToVector3Shifted(), caster.Map, this.radius + 2, (this.duration / 60) * .9f, (this.duration / 60) * .06f, (this.duration / 60) * .08f, Rand.Range(-50, -50), 0, 0, Rand.Range(0, 360)); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodCircle"), base.Position.ToVector3Shifted(), caster.Map, this.radius + 2, (this.duration / 60) * .9f, (this.duration / 60) * .06f, (this.duration / 60) * .08f, Rand.Range(50, 50), 0, 0, Rand.Range(0, 360)); TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodCircle"), base.Position.ToVector3Shifted(), caster.Map, this.radius + 2, (this.duration / 60) * .9f, (this.duration / 60) * .06f, (this.duration / 60) * .08f, Rand.Range(-50, 50), 0, 0, Rand.Range(0, 360)); caster.Map.weatherManager.eventHandler.AddEvent(new TM_WeatherEvent_BloodMoon(caster.Map, this.duration, 2f - (this.pwrVal * .1f))); this.initialized = true; } if (this.initialized && this.Map != null && this.age > 15) { if (this.victims.Count > 0) { for (int i = 0; i < this.victims.Count; i++) { if (this.victimHitTick[i] < this.age) { TM_Action.DamageEntities(victims[i], null, Mathf.RoundToInt((Rand.Range(5, 8) * this.wolfDmg[i]) * this.arcaneDmg), DamageDefOf.Bite, this.launcher); TM_MoteMaker.ThrowBloodSquirt(victims[i].DrawPos, victims[i].Map, Rand.Range(.6f, 1f)); this.victims.Remove(this.victims[i]); this.victimHitTick.Remove(this.victimHitTick[i]); this.wolfDmg.Remove(this.wolfDmg[i]); } } } if (Find.TickManager.TicksGame % this.bloodFrequency == 0) { Filth filth = (Filth)ThingMaker.MakeThing(ThingDefOf.Filth_Blood); GenSpawn.Spawn(filth, this.bloodCircleOuterCells.RandomElement(), this.Map); } if (this.nextAttack < this.age && !this.caster.DestroyedOrNull() && !this.caster.Dead) { Pawn victim = TM_Calc.FindNearbyEnemy(base.Position, this.Map, this.caster.Faction, this.radius, 0); if (victim != null) { IntVec3 rndPos = victim.Position; while (rndPos == victim.Position) { rndPos = this.bloodCircleCells.RandomElement(); } Vector3 wolf = rndPos.ToVector3Shifted(); Vector3 direction = TM_Calc.GetVector(wolf, victim.DrawPos); float angle = direction.ToAngleFlat(); float fadeIn = .1f; float fadeOut = .25f; float solidTime = .10f; float drawSize = Rand.Range(.7f, 1.2f) + (this.pwrVal * .1f); float velocity = (victim.DrawPos - wolf).MagnitudeHorizontal(); if (angle >= -135 && angle < -45) //north { TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodWolfNorth"), wolf, this.Map, drawSize, solidTime, fadeIn, fadeOut, 0, 2 * velocity, (Quaternion.AngleAxis(90, Vector3.up) * direction).ToAngleFlat(), 0); } else if (angle >= 45 && angle < 135) //south { TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodWolfSouth"), wolf, this.Map, drawSize, solidTime, fadeIn, fadeOut, 0, 2 * velocity, (Quaternion.AngleAxis(90, Vector3.up) * direction).ToAngleFlat(), 0); } else if (angle >= -45 && angle < 45) //east { TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodWolfEast"), wolf, this.Map, drawSize, solidTime, fadeIn, fadeOut, 0, 2 * velocity, (Quaternion.AngleAxis(90, Vector3.up) * direction).ToAngleFlat(), 0); } else //west { TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodWolfWest"), wolf, this.Map, drawSize, solidTime, fadeIn, fadeOut, 0, 2 * velocity, (Quaternion.AngleAxis(90, Vector3.up) * direction).ToAngleFlat(), 0); } int hitDelay = this.age + this.delayTicks; Effecter BloodShieldEffect = TorannMagicDefOf.TM_BloodShieldEffecter.Spawn(); BloodShieldEffect.Trigger(new TargetInfo(wolf.ToIntVec3(), this.Map, false), new TargetInfo(wolf.ToIntVec3(), this.Map, false)); BloodShieldEffect.Cleanup(); this.victims.Add(victim); this.victimHitTick.Add(hitDelay); this.wolfDmg.Add(drawSize); if (Rand.Chance(.1f)) { if (Rand.Chance(.65f)) { SoundInfo info = SoundInfo.InMap(new TargetInfo(wolf.ToIntVec3(), this.Map, false), MaintenanceType.None); SoundDef.Named("TM_DemonCallHigh").PlayOneShot(info); } else { SoundInfo info = SoundInfo.InMap(new TargetInfo(wolf.ToIntVec3(), this.Map, false), MaintenanceType.None); info.pitchFactor = .8f; info.volumeFactor = .8f; SoundDef.Named("TM_DemonPain").PlayOneShot(info); } } } this.nextAttack = this.age + Mathf.RoundToInt(Rand.Range(.4f * (float)this.attackFrequency, .8f * (float)this.attackFrequency)); } } }
public void SpawnCycle() { float wealthMultiplier = .7f; float wealth = this.Map.PlayerWealthForStoryteller; if (wealth > 20000) { wealthMultiplier = .8f; } if (wealth > 50000) { wealthMultiplier = 1f; } if (wealth > 100000) { wealthMultiplier = 1.25f; } if (wealth > 250000) { wealthMultiplier = 1.5f; } if (wealth > 500000) { wealthMultiplier = 2.5f; } ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef(); float geChance = 0.007f * wealthMultiplier; if (settingsRef.riftChallenge > 1) { geChance *= settingsRef.riftChallenge; } else { geChance = 0; } float eChance = 0.035f * settingsRef.riftChallenge * wealthMultiplier; float leChance = 0.12f * settingsRef.riftChallenge * wealthMultiplier; 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(geChance)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1f); MoteMaker.ThrowMicroSparks(curCell.ToVector3(), this.Map); SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f); rogueElemental.def = TorannMagicDefOf.TM_GreaterEarth_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_GreaterEarth_Elemental"); } else if (Rand.Chance(eChance)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1f); MoteMaker.ThrowMicroSparks(curCell.ToVector3(), this.Map); SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f); rogueElemental.def = TorannMagicDefOf.TM_Earth_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_Earth_Elemental"); } else if (Rand.Chance(leChance)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1f); MoteMaker.ThrowMicroSparks(curCell.ToVector3(), this.Map); SoundDefOf.Ambient_AltitudeWind.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(geChance)) { 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(eChance)) { 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(leChance)) { 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(geChance)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1); SoundDefOf.Ambient_AltitudeWind.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(eChance)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1); SoundDefOf.Ambient_AltitudeWind.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(leChance)) { MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1); SoundDefOf.Ambient_AltitudeWind.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(geChance)) { rogueElemental.def = TorannMagicDefOf.TM_GreaterWind_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_GreaterWind_Elemental"); MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1 + 1 * 2); SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.white); } else if (Rand.Chance(eChance)) { rogueElemental.def = TorannMagicDefOf.TM_Wind_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_Wind_Elemental"); MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1 + 1 * 2); SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.white); } else if (Rand.Chance(leChance)) { rogueElemental.def = TorannMagicDefOf.TM_LesserWind_ElementalR; rogueElemental.kindDef = PawnKindDef.Named("TM_LesserWind_Elemental"); MoteMaker.ThrowSmoke(curCell.ToVector3(), this.Map, 1 + 1 * 2); SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f); MoteMaker.ThrowTornadoDustPuff(curCell.ToVector3(), this.Map, 1, Color.white); } else { rogueElemental = null; } } if (rogueElemental != null) { SingleSpawnLoop(rogueElemental, curCell, this.Map); } } } }
private void Initialize() { caster = this.launcher as Pawn; CompAbilityUserMagic comp = caster.GetComp <CompAbilityUserMagic>(); pwrVal = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_EarthernHammer.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_EarthernHammer_pwr").level; verVal = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_EarthernHammer.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_EarthernHammer_ver").level; ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef(); if (caster.story.traits.HasTrait(TorannMagicDefOf.Faceless)) { pwrVal = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr").level; verVal = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver").level; } this.arcaneDmg = comp.arcaneDmg; if (settingsRef.AIHardMode && !caster.IsColonist) { pwrVal = 3; verVal = 3; } this.gravityPoints = this.baseGravityPoints + (pwrVal * 2); this.launchCells = new List <IntVec3>(); this.launchCells.Clear(); this.launchCells = GenRadial.RadialCellsAround(caster.Position, this.radius, false).ToList(); for (int i = 0; i < launchCells.Count(); i++) { if (launchCells[i].IsValid && launchCells[i].InBounds(caster.Map)) { List <Thing> cellList = launchCells[i].GetThingList(caster.Map); bool invalidCell = false; for (int j = 0; j < cellList.Count(); j++) { try { if (cellList[j].def.designationCategory != null) { if (cellList[j].def.designationCategory == DesignationCategoryDefOf.Structure || cellList[j].def.altitudeLayer == AltitudeLayer.Building || cellList[j].def.altitudeLayer == AltitudeLayer.Item || cellList[j].def.altitudeLayer == AltitudeLayer.ItemImportant) { invalidCell = true; } } if (cellList[j].def.thingCategories != null) { if (cellList[j].def.thingCategories.Contains(ThingCategoryDefOf.StoneChunks) || cellList[j].def.thingCategories.Contains(ThingCategoryDefOf.StoneBlocks)) { this.launchableThings.Add(cellList[j]); } } } catch (NullReferenceException ex) { //Log.Message("threw exception " + ex); } } if (invalidCell) { launchCells.Remove(launchCells[i]); } } } }
public override void Tick() { base.Tick(); var baseComp = this.GetComp <CompPowerZTransmitter>(); if (baseComp.PowerNet != null) { if (baseComp.PowerNet.powerComps.Where(x => x is CompPowerZTransmitter).Count() > 1 && this.lowerPowerComp == null && this.upperPowerComp == null) { //Log.Message("1 Removing " + baseComp + " - " + baseComp.GetHashCode(), true); baseComp.PowerNet.powerComps.Remove(baseComp); } else if (baseComp != null && baseComp.PowerNet.powerComps.Contains(baseComp)) { if (!baseComp.PowerNet.powerComps.Contains(baseComp)) { //Log.Message("1 Adding " + baseComp + " - " + baseComp.GetHashCode(), true); baseComp.PowerNet.powerComps.Add(baseComp); } var powerComps = new List <CompPowerZTransmitter>(); if (connectedPowerNets.powerNets == null) { //Log.Message("2 Adding " + baseComp + " - " + baseComp.GetHashCode(), true); powerComps.Add(baseComp); connectedPowerNets.powerNets = new Dictionary <int, List <CompPowerZTransmitter> > { { 0, powerComps } }; } else if (connectedPowerNets.powerNets.Count == 0) { //Log.Message("3 Adding " + baseComp + " - " + baseComp.GetHashCode(), true); powerComps.Add(baseComp); connectedPowerNets.powerNets.Add(0, powerComps); } else if (connectedPowerNets.powerNets.Values.Where(x => x.Where(y => y.PowerNet == baseComp.PowerNet && y.PowerNet.powerComps.Exists(c => c is CompPowerZTransmitter)).Count() > 0).Count() == 0) { //Log.Message("4 Adding " + baseComp + " - " + baseComp.GetHashCode(), true); powerComps.Add(baseComp); int maxKey = connectedPowerNets.powerNets.Max(x => x.Key); connectedPowerNets.powerNets.Add(maxKey + 1, powerComps); } else { powerComps = connectedPowerNets.powerNets.Values.Where(x => x .Where(y => y.PowerNet == baseComp.PowerNet).Count() == 1).ToList().First(); } //Log.Message(this + ZTracker.GetMapInfo(this.Map) + " works", true); var upperMap = ZTracker.GetUpperLevel(this.Map.Tile, this.Map); var lowerMap = ZTracker.GetLowerLevel(this.Map.Tile, this.Map); //if (Find.TickManager.TicksGame % 60 == 0) //{ // Log.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.upperTransmitter: " + this.upperTransmitter); // Log.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.upperTransmitter.Spawned: " + this.upperTransmitter?.Spawned); // Log.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.upperPowerComp: " + this.upperPowerComp); // Log.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.lowerTransmitter: " + this.lowerTransmitter); // Log.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.lowerTransmitter.Spawned: " + this.lowerTransmitter?.Spawned); // Log.Message(this + " in " + ZTracker.GetMapInfo(this.Map) + " - this.lowerPowerComp: " + this.lowerPowerComp); //} if (this.upperPowerComp != null && (upperTransmitter == null || !upperTransmitter.Spawned)) { this.upperPowerComp = null; upperTransmitter = null; } if (this.lowerPowerComp != null && (lowerTransmitter == null || !lowerTransmitter.Spawned)) { this.lowerPowerComp = null; lowerTransmitter = null; } if (upperMap != null && this.upperPowerComp == null && Find.TickManager.TicksGame % 200 == 0) { foreach (var pos in GenRadial.RadialCellsAround(this.Position, 3f, true)) { foreach (var t in pos.GetThingList(upperMap)) { //Log.Message("Power candidate: " + t); if (t.TryGetComp <CompPowerTransmitter>() != null) { upperTransmitter = t; var upperComp = upperTransmitter.TryGetComp <CompPowerTransmitter>(); upperPowerComp = (CompPowerZTransmitter)upperComp.PowerNet.powerComps .Where(x => x is CompPowerZTransmitter).FirstOrDefault(); if (upperPowerComp == null) { upperPowerComp = new CompPowerZTransmitter { parent = this, powerOutputInt = 0, //PowerOn = true, transNet = upperComp.transNet }; upperPowerComp.Initialize(new CompProperties_PowerZTransmitter()); //Log.Message("5 Adding " + upperPowerComp + " - " + upperPowerComp.GetHashCode(), true); upperComp.PowerNet.powerComps.Add(upperPowerComp); } if (upperPowerComp != null && !powerComps.Contains(upperPowerComp)) { //Log.Message("6 Adding " + upperPowerComp + " - " + upperPowerComp.GetHashCode(), true); powerComps.Add(upperPowerComp); } break; } } } } if (lowerMap != null && this.lowerPowerComp == null && Find.TickManager.TicksGame % 200 == 0) { foreach (var pos in GenRadial.RadialCellsAround(this.Position, 3f, true)) { foreach (var t in pos.GetThingList(lowerMap)) { if (t.TryGetComp <CompPowerTransmitter>() != null) { lowerTransmitter = t; var lowerComp = lowerTransmitter.TryGetComp <CompPowerTransmitter>(); lowerPowerComp = (CompPowerZTransmitter)lowerComp.PowerNet .powerComps.Where(x => x is CompPowerZTransmitter).FirstOrDefault(); if (lowerPowerComp == null) { lowerPowerComp = new CompPowerZTransmitter { parent = this, powerOutputInt = 0, transNet = lowerComp.transNet, //PowerOn = true }; lowerPowerComp.Initialize(new CompProperties_PowerZTransmitter()); //Log.Message("7 Adding " + lowerPowerComp + " - " + lowerPowerComp.GetHashCode(), true); lowerComp.PowerNet.powerComps.Add(lowerPowerComp); } if (lowerPowerComp != null && !powerComps.Contains(lowerPowerComp)) { //Log.Message(this + " Lower add " + lowerPowerComp); //Log.Message("8 Adding " + lowerPowerComp + " - " + lowerPowerComp.GetHashCode(), true); powerComps.Add(lowerPowerComp); } break; } } } } } } if (this.ticksToExplode > 0) { if (this.wickSustainer == null) { this.StartWickSustainer(); } else { this.wickSustainer.Maintain(); } this.ticksToExplode--; if (this.ticksToExplode == 0) { IntVec3 randomCell = this.OccupiedRect().RandomCell; float radius = Rand.Range(0.5f, 1f) * 3f; GenExplosion.DoExplosion(randomCell, base.Map, radius, DamageDefOf.Flame, null, -1, -1f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false, null, null); } } //Log.Message(pawn + " - -----------------", true); }