public static void MakeWaterSplash(Vector3 loc, Map map, float size, float velocity)
 {
     if (loc.ShouldSpawnMotesAt(map) && !map.moteCounter.SaturatedLowPriority)
     {
         MoteSplash moteSplash = (MoteSplash)ThingMaker.MakeThing(ThingDefOf.Mote_WaterSplash, null);
         moteSplash.Initialize(loc, size, velocity);
         GenSpawn.Spawn(moteSplash, loc.ToIntVec3(), map);
     }
 }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            ThingDef def = this.def;

            if (!this.initialized)
            {
                caster = this.launcher as Pawn;
                CompAbilityUserMagic comp = caster.GetComp <CompAbilityUserMagic>();
                pwrVal = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Encase.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Encase_pwr").level;
                verVal = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Encase.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Encase_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;
                }
                if (settingsRef.AIHardMode && !caster.IsColonist)
                {
                    pwrVal = 3;
                    verVal = 3;
                }

                if (pwrVal == 3)
                {
                    spawnDef = ThingDef.Named("Granite"); //900
                }
                else if (pwrVal == 2)
                {
                    spawnDef = ThingDef.Named("Limestone"); //700
                }
                else if (pwrVal == 1)
                {
                    spawnDef = ThingDef.Named("Slate"); //500
                }
                else
                {
                    spawnDef = ThingDef.Named("Sandstone"); //400
                }
                List <IntVec3> outerCells = GenRadial.RadialCellsAround(base.Position, this.def.projectile.explosionRadius + 1f, true).ToList();
                List <IntVec3> innerCells = GenRadial.RadialCellsAround(base.Position, this.def.projectile.explosionRadius - 1f, true).ToList();
                this.wallPositions = new List <IntVec3>();
                this.wallPositions.Clear();
                this.terrainList = new List <TerrainDef>();
                this.terrainList.Clear();
                this.wallPositions = outerCells.Except(innerCells).ToList();
                for (int t = 0; t < wallPositions.Count(); t++)
                {
                    Encase temp = new Encase(wallPositions[t], wallPositions[t].GetTerrain(caster.Map));
                    wall.Add(temp);
                    this.terrainList.Add(wallPositions[t].GetTerrain(caster.Map));
                }
                float magnitude = (base.Position.ToVector3Shifted() - Find.Camera.transform.position).magnitude;
                Find.CameraDriver.shaker.DoShake(10 / magnitude);
                //for (int k = 0; k < wallPositions.Count(); k++)
                //{
                for (int k = 0; k < wall.Count(); k++)
                {
                    if (wall[k].position.IsValid && wall[k].position.InBounds(caster.Map) && !wall[k].position.Fogged(caster.Map) && !wall[k].position.InNoZoneEdgeArea(caster.Map))
                    //if (wallPositions[k].IsValid && wallPositions[k].InBounds(caster.Map) && !wallPositions[k].Fogged(caster.Map) && !wallPositions[k].InNoZoneEdgeArea(caster.Map))
                    {
                        if (wall[k].terrain.defName == "Marsh" || wall[k].terrain.defName == "WaterShallow" || wall[k].terrain.defName == "WaterMovingShallow" || wall[k].terrain.defName == "WaterOceanShallow" || wall[k].terrain.defName == "WaterMovingChestDeep")
                        {
                            MoteSplash moteSplash = (MoteSplash)ThingMaker.MakeThing(ThingDefOf.Mote_WaterSplash, null);
                            moteSplash.Initialize(wallPositions[k].ToVector3Shifted(), 8f, 1f);
                            GenSpawn.Spawn(moteSplash, wallPositions[k], map, WipeMode.Vanish);
                        }
                        List <Thing> cellList = new List <Thing>();
                        bool         hasWall  = false;
                        try
                        {
                            cellList = wall[k].position.GetThingList(caster.Map);
                            for (int i = 0; i < cellList.Count(); i++)
                            {
                                if (cellList[i].def.designationCategory == DesignationCategoryDefOf.Structure || cellList[i].def.altitudeLayer == AltitudeLayer.Building || cellList[i].def.altitudeLayer == AltitudeLayer.Item || cellList[i].def.altitudeLayer == AltitudeLayer.ItemImportant)
                                {
                                    if (!cellList[i].def.EverHaulable)
                                    {
                                        hasWall = true;
                                        //this.terrainList.Remove(this.terrainList[k]);
                                        //this.wallPositions.Remove(this.wallPositions[k]); //don't do anything if a building/wall already exists
                                        wall.Remove(wall[k]);
                                        break;
                                    }
                                }
                            }
                        }
                        catch //remove square if it threw an error trying to get item list at this location
                        {
                            hasWall = true;
                            //this.terrainList.Remove(this.terrainList[k]);
                            //this.wallPositions.Remove(this.wallPositions[k]);
                            wall.Remove(wall[k]);
                            continue;
                        }

                        if (!hasWall)
                        {
                            bool spawnWall = true;
                            for (int i = 0; i < cellList.Count(); i++)
                            {
                                if (!(cellList[i] is Pawn)) //
                                {
                                    if (cellList[i].def.defName.Contains("Mote"))
                                    {
                                        //Log.Message("avoided storing " + cellList[i].def.defName);
                                    }
                                    else if (cellList[i].def.defName == "Fire" || cellList[i].def.defName == "Spark")
                                    {
                                        cellList[i].Destroy(DestroyMode.Vanish);
                                    }
                                    else
                                    {
                                        this.despawnedThingList.Add(cellList[i]);
                                        cellList[i].DeSpawn();
                                    }
                                }
                            }
                            if (spawnWall)
                            {
                                AbilityUser.SpawnThings tempSpawn = new SpawnThings()
                                {
                                    def        = spawnDef,
                                    spawnCount = 1
                                };
                                try
                                {
                                    SingleSpawnLoop(tempSpawn, wall[k].position, caster.Map);
                                    for (int m = 0; m < 4; m++)
                                    {
                                        TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_ThickDust"), wall[k].position.ToVector3Shifted(), caster.Map, Rand.Range(.6f, .8f), Rand.Range(.2f, .3f), .05f, Rand.Range(.4f, .6f), Rand.Range(-20, 20), Rand.Range(1f, 2f), Rand.Range(0, 360), Rand.Range(0, 360));
                                    }
                                }
                                catch
                                {
                                    //dont spawn wall
                                    continue;
                                }
                            }
                        }
                    }
                }
                this.duration    = Mathf.RoundToInt(1800 + (240 * verVal) * comp.arcaneDmg);
                this.initialized = true;
                this.wallActive  = true;
            }
            else if (this.initialized && this.wallActive && !(this.age < this.duration))
            {
                for (int j = 0; j < wall.Count(); j++)
                {
                    Building structure = null;
                    structure = this.wall[j].position.GetFirstBuilding(this.Map);
                    if (structure != null)
                    {
                        structure.Destroy();
                        for (int m = 0; m < 4; m++)
                        {
                            TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_ThickDust"), wall[j].position.ToVector3Shifted(), this.Map, Rand.Range(.4f, .8f), Rand.Range(.2f, .3f), .05f, Rand.Range(.4f, .6f), Rand.Range(-20, 20), Rand.Range(1f, 2f), Rand.Range(0, 360), Rand.Range(0, 360));
                        }
                    }
                    structure = null;
                    this.Map.terrainGrid.SetTerrain(wall[j].position, wall[j].terrain);
                }

                for (int i = 0; i < this.despawnedThingList.Count(); i++)
                {
                    GenSpawn.Spawn(this.despawnedThingList[i], this.despawnedThingList[i].Position, this.Map);
                }
                this.wallActive = false;
            }
        }