internal CustomMonster(int id, int modlevel, CustomMonsterType cmtype) { ID = id; MODLevel = modlevel; CMType = cmtype; SpawnTime = DateTime.Now; //Customized = true; }
private static int SpawnCustomMonsterExactPosition(CustomMonsterType CMType, int X, int Y, int modlevel = 0) { int CID = -1; if (modlevel <= CMType.MODMaxLevel) { int spawnTileX; int spawnTileY; TShockAPI.TShock.Utils.GetRandomClearTileWithInRange(X, Y, 10, 10, out spawnTileX, out spawnTileY); int npcid = NPC.NewNPC(spawnTileX * 16, spawnTileY * 16, CMType.BaseType); Main.npc[npcid].SetDefaults(CMType.BaseType); CustomizeMonster(npcid, CMType, modlevel); CID = npcid; NetMessage.SendData(23, -1, -1, "", npcid, 0f, 0f, 0f, 0); } return CID; }
private static int SpawnCustomMonster(CustomMonsterType CMType, int X, int Y, int modlevel = 0) { int CID = -1; if (modlevel <= CMType.MODMaxLevel) { int npcid = NPC.NewNPC(X * 16, Y * 16, CMType.BaseType); Main.npc[npcid].SetDefaults(CMType.BaseType); CustomizeMonster(npcid, CMType, modlevel); CID = npcid; NetMessage.SendData(23, -1, -1, "", npcid, 0f, 0f, 0f, 0); } return CID; }
private static void ReplaceMonsters() { for (int i = 0; i < Main.maxNPCs; i++) { if (CustomMonsters.Find(monster => monster.ID == i) == null) { CustomMonsterType CMType = new CustomMonsterType(); List<CustomMonsterType> RCMTypes = CMTypes.FindAll(monstertype => monstertype.Replaces.Count > 0); foreach (CustomMonsterType cmt in RCMTypes) { foreach (NPC npc in cmt.Replaces) { if (npc.name.ToLower() == Main.npc[i].name.ToLower()) { CustomizeMonster(i, CMType, 0); } } } if (CMType.Name != "" && CMType.BaseType > 0) CustomizeMonster(i, CMType, 0); } else continue; } }
private static void LoadCustomMonstersFromText() { string[] CustomMonstersDataPaths = Directory.GetFiles(@CustomMonstersDataDirectory); foreach (string CMDataPath in CustomMonstersDataPaths) { List<string> MonsterData = new List<string>(); try { using (StreamReader sr = new StreamReader(CMDataPath)) { string line; while ((line = sr.ReadLine()) != null) { if (!line.StartsWith("##")) MonsterData.Add(line); } } } catch (Exception e) { string errormessage = string.Format("The file \"{0}\" could not be read:", CMDataPath); Console.WriteLine(errormessage); Console.WriteLine(e.Message); } CustomMonsterType CMType = new CustomMonsterType(); foreach (string CMFieldAndVal in MonsterData) { if (CMFieldAndVal.Split(':').Length > 1) { #region donator version switch block switch (CMFieldAndVal.Split(':')[0].ToLower()) { case "name": { CMType.Name = CMFieldAndVal.Split(':')[1]; break; } case "basetype": case "type": { int type; Int32.TryParse(CMFieldAndVal.Split(':')[1], out type); CMType.BaseType = type; break; } case "life": case "lifemax": { int life; Int32.TryParse(CMFieldAndVal.Split(':')[1], out life); CMType.Life = life; break; } case "blitzdata": case "blitz": { int type; int style; int time; if (CMFieldAndVal.Split(':').Length > 3) { if (Int32.TryParse(CMFieldAndVal.Split(':')[1], out type) && Int32.TryParse(CMFieldAndVal.Split(':')[2], out style) && Int32.TryParse(CMFieldAndVal.Split(':')[3], out time)) { CMType.BlitzData.Add(new BlitzData(type, style, time)); } } break; } case "cblitzdata": case "cblitz": { int style; int time; if (CMFieldAndVal.Split(':').Length > 3) { if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out style) && Int32.TryParse(CMFieldAndVal.Split(':')[3], out time)) { CMType.CBlitzData.Add(new CBlitzData(CMFieldAndVal.Split(':')[0], style, time)); } } break; } case "shooterdata": case "shooter": { int type; int style; int time; int damage; if (CMFieldAndVal.Split(':').Length > 4) { if (Int32.TryParse(CMFieldAndVal.Split(':')[1], out type) && Int32.TryParse(CMFieldAndVal.Split(':')[2], out style) && Int32.TryParse(CMFieldAndVal.Split(':')[3], out time) && Int32.TryParse(CMFieldAndVal.Split(':')[4], out damage)) { CMType.ShooterData.Add(new ShooterData(type, damage, style, time)); } } break; } case "buff": { int type; int time = 5; int rate = 10; if (CMFieldAndVal.Split(':').Length > 1) { if (CMFieldAndVal.Split(':').Length > 2) Int32.TryParse(CMFieldAndVal.Split(':')[2], out time); if (CMFieldAndVal.Split(':').Length > 3) Int32.TryParse(CMFieldAndVal.Split(':')[3], out rate); if (Int32.TryParse(CMFieldAndVal.Split(':')[1], out type)) { CMType.Buffs.Add(new BuffRateandDuration(type, time, rate)); } } break; } case "corruption": { int rate=10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Corruption.SpawnHere = true; CMType.Corruption.Rate = rate; break; } case "meteor": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Meteor.SpawnHere = true; CMType.Meteor.Rate = rate; break; } case "jungle": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Jungle.SpawnHere = true; CMType.Jungle.Rate = rate; break; } case "hallow": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Hallow.SpawnHere = true; CMType.Hallow.Rate = rate; break; } case "dungeon": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Dungeon.SpawnHere = true; CMType.Dungeon.Rate = rate; break; } case "forest": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Forest.SpawnHere = true; CMType.Forest.Rate = rate; break; } case "region": { if (CMFieldAndVal.Split(':').Length > 5) { Region spawnregion = TShock.Regions.GetRegionByName(CMFieldAndVal.Split(':')[1]); int spawnrate; if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out spawnrate)) { int spawnchance = 1; int maxspawns =5; bool staticspawnrate = false; Int32.TryParse(CMFieldAndVal.Split(':')[3], out maxspawns); Int32.TryParse(CMFieldAndVal.Split(':')[4], out spawnchance); bool.TryParse(CMFieldAndVal.Split(':')[5], out staticspawnrate); CMType.SpawnRegions.Add(new RegionAndRate(spawnregion, spawnrate, maxspawns, spawnchance, staticspawnrate)); } } else if (CMFieldAndVal.Split(':').Length > 4) { Region spawnregion = TShock.Regions.GetRegionByName(CMFieldAndVal.Split(':')[1]); int spawnrate; if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out spawnrate)) { int spawnchance = 1; int maxspawns = 5; Int32.TryParse(CMFieldAndVal.Split(':')[3], out maxspawns); Int32.TryParse(CMFieldAndVal.Split(':')[4], out spawnchance); CMType.SpawnRegions.Add(new RegionAndRate(spawnregion, spawnrate, maxspawns, spawnchance)); } } else if (CMFieldAndVal.Split(':').Length > 3) { Region spawnregion = TShock.Regions.GetRegionByName(CMFieldAndVal.Split(':')[1]); int spawnrate; if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out spawnrate)) { int maxspawns = 5; Int32.TryParse(CMFieldAndVal.Split(':')[3], out maxspawns); CMType.SpawnRegions.Add(new RegionAndRate(spawnregion, spawnrate, maxspawns)); } } else if (CMFieldAndVal.Split(':').Length > 2) { Region spawnregion = TShock.Regions.GetRegionByName(CMFieldAndVal.Split(':')[1]); int spawnrate; if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out spawnrate)) { CMType.SpawnRegions.Add(new RegionAndRate(spawnregion, spawnrate)); } } break; } case "replace": case "replaces": { if (TShock.Utils.GetNPCByIdOrName(CMFieldAndVal.Split(':')[1]).Count == 1) { NPC npc = TShock.Utils.GetNPCByIdOrName(CMFieldAndVal.Split(':')[1])[0]; CMType.Replaces.Add(npc); } break; } case "ai": case "customai": case "customaistyle": case "aistyle": { int ai; if(Int32.TryParse(CMFieldAndVal.Split(':')[1],out ai)) CMType.CustomAIStyle = ai; break; } case "multiplyondeath": { int MODML; if (Int32.TryParse(CMFieldAndVal.Split(':')[1], out MODML)) { CMType.MODMaxLevel = MODML; CMType.MultiplyOnDeath = false; } break; } case "transform": case "transformation": { if (CMFieldAndVal.Split(':').Length > 2) { int hp; if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out hp)) CMType.Transformation = new Transformation(CMFieldAndVal.Split(':')[1], hp); } break; } case "donttakedamage": { bool dtd; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out dtd)) CMType.dontTakeDamage = dtd; break; } case "lavaimmune": { bool lavaimmune; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out lavaimmune)) CMType.lavaImmune = lavaimmune; break; } case "boss": { bool boss; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out boss)) CMType.Boss = boss; break; } case "notilecollide": { bool noTileCollide; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out noTileCollide)) CMType.noTileCollide = noTileCollide; break; } case "nogravity": { bool noGravity; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out noGravity)) CMType.noGravity = noGravity; break; } case "value": { float value; if (float.TryParse(CMFieldAndVal.Split(':')[1], out value)) CMType.Value = value; break; } //case "spawnmessage": // { // CMType.SpawnMessage = CMFieldAndVal.Split(':')[1]; // break; // } case "onfire": { bool onfire; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out onfire)) CMType.OnFire = onfire; break; } case "poisoned": { bool poisoned; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out poisoned)) CMType.Poisoned = poisoned; break; } default: CMType.SpawnMessage = CMFieldAndVal; break; } } #endregion } lock (CMTypes) { if (CMType.Name != "" && CMType.BaseType > 0) CMTypes.Add(CMType); } } }
private static void CustomizeMonster(int npcid, CustomMonsterType CMType, int modlevel, int life = -1) { NPC Custom = Main.npc[npcid]; Custom.netDefaults(CMType.BaseType); Custom.name = CMType.Name; Custom.displayName = CMType.Name; Custom.lifeMax = CMType.Life ?? Custom.lifeMax; Custom.life = life <= 0 ? (CMType.Life ?? Custom.life): life; Custom.aiStyle = CMType.CustomAIStyle ?? Custom.aiStyle; Custom.dontTakeDamage = CMType.dontTakeDamage ?? Custom.dontTakeDamage; Custom.lavaImmune = CMType.lavaImmune ?? Custom.lavaImmune; Custom.boss = CMType.Boss ?? Custom.boss; Custom.noGravity = CMType.noGravity ?? Custom.noGravity; Custom.noTileCollide = CMType.noTileCollide ?? Custom.noTileCollide; Custom.value = CMType.Value ?? Custom.value; Custom.onFire = CMType.OnFire ?? Custom.onFire; Custom.poisoned = CMType.Poisoned ?? Custom.poisoned; if (modlevel == 0 && CMType.SpawnMessage != "") TShockAPI.TShock.Utils.Broadcast(CMType.SpawnMessage, Color.MediumPurple); CustomMonsters.Add(new CustomMonster(npcid, modlevel, CMType)); }
private static void ReplaceMonsters() { for (int i = 0; i < Main.maxNPCs; i++) { if (CustomMonsters.Find(monster => monster.ID == i) == null) { CustomMonsterType CMType = new CustomMonsterType(); List<CustomMonsterType> RCMTypes = CMTypes.FindAll(monstertype => monstertype.Replaces.Count > 0); foreach (CustomMonsterType cmt in RCMTypes) { foreach (NPC npc in cmt.Replaces) { try { var name = Main.npc[i].name; if (name != null && npc.name.ToLower() == name.ToLower()) { CustomizeMonster(i, cmt, 0); //Main.npc[i].active=true; //NetMessage.SendData(23, -1, -1, "", i, 0f, 0f, 0f, 0); } } catch (Exception e) { Log.ConsoleError(e.ToString()); } } } if (CMType.Name != "" && CMType.BaseType != 0) CustomizeMonster(i, CMType, 0); } else continue; } }
private static void CreateCustomMonster(List<string> MonsterData) { CustomMonsterType CMType = new CustomMonsterType(); foreach (string CMFieldAndVal in MonsterData) { if (CMFieldAndVal.Split(':').Length > 1) { #region donator version switch block switch (CMFieldAndVal.Split(':')[0].ToLower()) { case "name": { CMType.Name = CMFieldAndVal.Split(':')[1]; break; } case "basetype": case "type": { int type; Int32.TryParse(CMFieldAndVal.Split(':')[1], out type); CMType.BaseType = type; break; } case "life": case "lifemax": { int life; Int32.TryParse(CMFieldAndVal.Split(':')[1], out life); CMType.Life = life; break; } case "blitzdata": case "blitz": { int type; int style; int time; if (CMFieldAndVal.Split(':').Length > 3) { if (Int32.TryParse(CMFieldAndVal.Split(':')[1], out type) && Int32.TryParse(CMFieldAndVal.Split(':')[2], out style) && Int32.TryParse(CMFieldAndVal.Split(':')[3], out time)) { CMType.BlitzData.Add(new BlitzData(type, style, time)); } } break; } case "cblitzdata": case "cblitz": { int style; int time; if (CMFieldAndVal.Split(':').Length > 3) { if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out style) && Int32.TryParse(CMFieldAndVal.Split(':')[3], out time)) { CMType.CBlitzData.Add(new CBlitzData(CMFieldAndVal.Split(':')[1], style, time)); } } break; } case "shooterdata": case "shooter": { int type; int style; int time; int damage; if (CMFieldAndVal.Split(':').Length > 4) { if (Int32.TryParse(CMFieldAndVal.Split(':')[1], out type) && Int32.TryParse(CMFieldAndVal.Split(':')[2], out style) && Int32.TryParse(CMFieldAndVal.Split(':')[3], out time) && Int32.TryParse(CMFieldAndVal.Split(':')[4], out damage)) { CMType.ShooterData.Add(new ShooterData(type, damage, style, time)); } } break; } case "buff": { int type; int time = 5; int rate = 10; if (CMFieldAndVal.Split(':').Length > 1) { if (CMFieldAndVal.Split(':').Length > 2) Int32.TryParse(CMFieldAndVal.Split(':')[2], out time); if (CMFieldAndVal.Split(':').Length > 3) Int32.TryParse(CMFieldAndVal.Split(':')[3], out rate); if (Int32.TryParse(CMFieldAndVal.Split(':')[1], out type)) { CMType.Buffs.Add(new BuffRateandDuration(type, time, rate)); } } break; } case "biome": { string name; int maxSpawns = -1; int rate; int spawnChance = 100; bool staticSpawnRate = false; if (CMFieldAndVal.Split(':').Length > 2) { name = CMFieldAndVal.Split(':')[1]; Int32.TryParse(CMFieldAndVal.Split(':')[2], out rate); Int32.TryParse(CMFieldAndVal.Split(':')[3], out maxSpawns); Int32.TryParse(CMFieldAndVal.Split(':')[4], out spawnChance); bool.TryParse(CMFieldAndVal.Split(':')[5], out staticSpawnRate); CMType.BiomeData.Add(new BiomeData(name, maxSpawns, rate, spawnChance, staticSpawnRate)); } break; } /*case "corruption": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Corruption.SpawnHere = true; CMType.Corruption.Rate = rate; break; } case "meteor": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Meteor.SpawnHere = true; CMType.Meteor.Rate = rate; break; } case "jungle": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Jungle.SpawnHere = true; CMType.Jungle.Rate = rate; break; } case "hallow": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Hallow.SpawnHere = true; CMType.Hallow.Rate = rate; break; } case "dungeon": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Dungeon.SpawnHere = true; CMType.Dungeon.Rate = rate; break; } case "forest": { int rate = 10; Int32.TryParse(CMFieldAndVal.Split(':')[1], out rate); CMType.Forest.SpawnHere = true; CMType.Forest.Rate = rate; break; }*/ case "region": { if (CMFieldAndVal.Split(':').Length > 5) { string spawnregion = CMFieldAndVal.Split(':')[1]; int spawnrate; if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out spawnrate)) { int spawnchance = 1; int maxspawns = 5; bool staticspawnrate = false; Int32.TryParse(CMFieldAndVal.Split(':')[3], out maxspawns); Int32.TryParse(CMFieldAndVal.Split(':')[4], out spawnchance); bool.TryParse(CMFieldAndVal.Split(':')[5], out staticspawnrate); CMType.SpawnRegions.Add(new RegionAndRate(spawnregion, spawnrate, maxspawns, spawnchance, staticspawnrate)); } } else if (CMFieldAndVal.Split(':').Length > 4) { string spawnregion = CMFieldAndVal.Split(':')[1]; int spawnrate; if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out spawnrate)) { int spawnchance = 1; int maxspawns = 5; Int32.TryParse(CMFieldAndVal.Split(':')[3], out maxspawns); Int32.TryParse(CMFieldAndVal.Split(':')[4], out spawnchance); CMType.SpawnRegions.Add(new RegionAndRate(spawnregion, spawnrate, maxspawns, spawnchance)); } } else if (CMFieldAndVal.Split(':').Length > 3) { string spawnregion = CMFieldAndVal.Split(':')[1]; int spawnrate; if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out spawnrate)) { int maxspawns = 5; Int32.TryParse(CMFieldAndVal.Split(':')[3], out maxspawns); CMType.SpawnRegions.Add(new RegionAndRate(spawnregion, spawnrate, maxspawns)); } } else if (CMFieldAndVal.Split(':').Length > 2) { string spawnregion = CMFieldAndVal.Split(':')[1]; int spawnrate; if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out spawnrate)) { CMType.SpawnRegions.Add(new RegionAndRate(spawnregion, spawnrate)); } } break; } case "replace": case "replaces": { if (TShock.Utils.GetNPCByIdOrName(CMFieldAndVal.Split(':')[1]).Count == 1) { NPC npc = TShock.Utils.GetNPCByIdOrName(CMFieldAndVal.Split(':')[1])[0]; CMType.Replaces.Add(npc); } break; } case "ai": case "customai": case "customaistyle": case "aistyle": { int ai; if (Int32.TryParse(CMFieldAndVal.Split(':')[1], out ai)) CMType.CustomAIStyle = ai; break; } case "multiplyondeath": { int MODML; if (Int32.TryParse(CMFieldAndVal.Split(':')[1], out MODML)) { CMType.MODMaxLevel = MODML; CMType.MultiplyOnDeath = true; } break; } case "transform": case "transformation": { if (CMFieldAndVal.Split(':').Length > 2) { int hp; if (Int32.TryParse(CMFieldAndVal.Split(':')[2], out hp)) CMType.Transformation = new Transformation(CMFieldAndVal.Split(':')[1], hp); } break; } case "donttakedamage": { bool dtd; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out dtd)) CMType.dontTakeDamage = dtd; break; } case "lavaimmune": { bool lavaimmune; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out lavaimmune)) CMType.lavaImmune = lavaimmune; break; } case "boss": { bool boss; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out boss)) CMType.Boss = boss; break; } case "notilecollide": { bool noTileCollide; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out noTileCollide)) CMType.noTileCollide = noTileCollide; break; } case "nogravity": { bool noGravity; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out noGravity)) CMType.noGravity = noGravity; break; } case "value": { float value; if (float.TryParse(CMFieldAndVal.Split(':')[1], out value)) CMType.Value = value; break; } //case "spawnmessage": // { // CMType.SpawnMessage = CMFieldAndVal.Split(':')[1]; // break; // } case "onfire": { bool onfire; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out onfire)) CMType.OnFire = onfire; break; } case "poisoned": { bool poisoned; if (bool.TryParse(CMFieldAndVal.Split(':')[1], out poisoned)) CMType.Poisoned = poisoned; break; } default: CMType.SpawnMessage = CMFieldAndVal.Split(':')[1]; break; } } #endregion } lock (CMTypes) { if (CMType.Name != "" && CMType.BaseType != 0) { if (CMType.Transformation == null) CMType.Transformation = new Transformation(); CMTypes.Add(CMType); } } }
private static int SpawnCustomMonster(CustomMonsterType CMType, int X, int Y, int modlevel = 0) { int CID = -1; if (modlevel <= CMType.MODMaxLevel) { int npcid = NPC.NewNPC(X, Y, CMType.BaseType); //Console.WriteLine(String.Format("id is {0} X {1} Y {2} - compare {3} and {4}",npcid,X,Y,Main.npc[1].position.X,Main.npc[1].position.Y)); Main.npc[npcid].SetDefaults(CMType.BaseType); CustomizeMonster(npcid, CMType, modlevel); CID = npcid; NetMessage.SendData(23, -1, -1, "", npcid, 0f, 0f, 0f, 0); } return CID; }