public static void InitScripting(MonsterTemplate template, Area map, Monster obj) { if (obj.Scripts == null || !obj.Scripts.Any()) { obj.Scripts = ScriptManager.Load <MonsterScript>(template.ScriptName, obj, map); } }
public static Monster Create(MonsterTemplate template, Area map) { var monsterCreateScript = ScriptManager.Load <MonsterCreateScript>(ServerContext.Config.MonsterCreationScript, template, map) .FirstOrDefault(); return(monsterCreateScript.Value?.Create(template, map)); }
public static Monster Create(MonsterTemplate template, Area map) { if (template.CastSpeed == 0) { template.CastSpeed = 2000; } if (template.AttackSpeed == 0) { template.AttackSpeed = 1000; } if (template.MovementSpeed == 0) { template.MovementSpeed = 2000; } if (template.Level <= 0) { template.Level = 1; } var obj = new Monster { Template = template, CastTimer = new GameServerTimer(TimeSpan.FromMilliseconds(1 + template.CastSpeed)), BashTimer = new GameServerTimer(TimeSpan.FromMilliseconds(1 + template.AttackSpeed)), WalkTimer = new GameServerTimer(TimeSpan.FromMilliseconds(1 + template.MovementSpeed)), CastEnabled = template.MaximumMP > 0, TaggedAislings = new HashSet <int>() }; if (obj.Template.Grow) { obj.Template.Level++; } var mod = (obj.Template.Level + 1) * 0.01; var rate = mod * 250 * obj.Template.Level; var exp = obj.Template.Level * rate / 1; var hp = mod + 50 + obj.Template.Level * (obj.Template.Level + 40); var mp = hp / 3; var dmg = hp / 1 * mod * 1; obj.Template.MaximumHP = (int)hp; obj.Template.MaximumMP = (int)mp; var stat = RandomEnumValue <PrimaryStat>(); obj._Str = 3; obj._Int = 3; obj._Wis = 3; obj._Con = 3; obj._Dex = 3; switch (stat) { case PrimaryStat.STR: obj._Str += (byte)(obj.Template.Level * 0.5 * 2); break; case PrimaryStat.INT: obj._Int += (byte)(obj.Template.Level * 0.5 * 2); break; case PrimaryStat.WIS: obj._Wis += (byte)(obj.Template.Level * 0.5 * 2); break; case PrimaryStat.CON: obj._Con += (byte)(obj.Template.Level * 0.5 * 2); break; case PrimaryStat.DEX: obj._Dex += (byte)(obj.Template.Level * 0.5 * 2); break; } obj.MajorAttribute = stat; obj.BonusAc = (int)(70 - obj.Template.Level * 0.5 / 1.0); if (obj.BonusAc < -70) { obj.BonusAc = -70; } obj.DefenseElement = ElementManager.Element.None; obj.OffenseElement = ElementManager.Element.None; if (obj.Template.ElementType == ElementQualifer.Random) { obj.DefenseElement = RandomEnumValue <ElementManager.Element>(); obj.OffenseElement = RandomEnumValue <ElementManager.Element>(); } else if (obj.Template.ElementType == ElementQualifer.Defined) { obj.DefenseElement = template?.DefenseElement == ElementManager.Element.None ? RandomEnumValue <ElementManager.Element>() : template.DefenseElement; obj.OffenseElement = template?.OffenseElement == ElementManager.Element.None ? RandomEnumValue <ElementManager.Element>() : template.OffenseElement; } obj.BonusMr = (byte)(10 * (template.Level / 20)); if (obj.BonusMr > ServerContextBase.GlobalConfig.BaseMR) { obj.BonusMr = ServerContextBase.GlobalConfig.BaseMR; } if ((template.PathQualifer & PathQualifer.Wander) == PathQualifer.Wander) { obj.WalkEnabled = true; } else if ((template.PathQualifer & PathQualifer.Fixed) == PathQualifer.Fixed) { obj.WalkEnabled = false; } else if ((template.PathQualifer & PathQualifer.Patrol) == PathQualifer.Patrol) { obj.WalkEnabled = true; } if (template.MoodType.HasFlag(MoodQualifer.Aggressive)) { obj.Aggressive = true; } else if (template.MoodType.HasFlag(MoodQualifer.Unpredicable)) { lock (Generator.Random) { //this monster has a 50% chance of being aggressive. obj.Aggressive = Generator.Random.Next(1, 101) > 50; } } else { obj.Aggressive = false; } if (template.SpawnType == SpawnQualifer.Random) { var x = Generator.Random.Next(1, map.Cols); var y = Generator.Random.Next(1, map.Rows); obj.XPos = x; obj.YPos = y; if (map.IsWall(x, y)) { return(null); } } else if (template.SpawnType == SpawnQualifer.Defined) { obj.XPos = template.DefinedX; obj.YPos = template.DefinedY; } lock (Generator.Random) { obj.Serial = GenerateNumber(); } obj.CurrentMapId = map.ID; obj.CurrentHp = template.MaximumHP; obj.CurrentMp = template.MaximumMP; obj._MaximumHp = template.MaximumHP; obj._MaximumMp = template.MaximumMP; obj.AbandonedDate = DateTime.UtcNow; lock (Generator.Random) { obj.Image = template.ImageVarience > 0 ? (ushort)Generator.Random.Next(template.Image, template.Image + template.ImageVarience) : template.Image; } obj.Scripts = ScriptManager.Load <MonsterScript>(template.ScriptName, obj, map); if (obj.Template.LootType.HasFlag(LootQualifer.Table)) { obj.LootManager = new LootDropper(); obj.LootTable = new LootTable(template.Name); obj.UpgradeTable = new LootTable("Probabilities"); foreach (var drop in obj.Template.Drops) { if (drop.Equals("random", StringComparison.OrdinalIgnoreCase)) { lock (Generator.Random) { var available = ServerContextBase.GlobalItemTemplateCache.Select(i => i.Value) .Where(i => Math.Abs(i.LevelRequired - obj.Template.Level) <= 10).ToList(); if (available.Count > 0) { obj.LootTable.Add(available[GenerateNumber() % available.Count]); } } } else { if (ServerContextBase.GlobalItemTemplateCache.ContainsKey(drop)) { obj.LootTable.Add(ServerContextBase.GlobalItemTemplateCache[drop]); } } } obj.UpgradeTable.Add(new Common()); obj.UpgradeTable.Add(new Uncommon()); obj.UpgradeTable.Add(new Rare()); obj.UpgradeTable.Add(new Epic()); obj.UpgradeTable.Add(new Legendary()); obj.UpgradeTable.Add(new Mythical()); obj.UpgradeTable.Add(new Godly()); obj.UpgradeTable.Add(new Forsaken()); } return(obj); }
public static Monster Create(MonsterTemplate template, Area map) { if (template.CastSpeed == 0) { template.CastSpeed = 2000; } if (template.AttackSpeed == 0) { template.AttackSpeed = 1000; } if (template.MovementSpeed == 0) { template.MovementSpeed = 2000; } if (template.Level == 0) { template.Level = 1; } var obj = new Monster(); obj.Template = template; obj.Map = map; obj.CastTimer = new GameServerTimer(TimeSpan.FromMilliseconds(template.CastSpeed)); obj.BashTimer = new GameServerTimer(TimeSpan.FromMilliseconds(template.AttackSpeed)); obj.WalkTimer = new GameServerTimer(TimeSpan.FromMilliseconds(template.MovementSpeed)); obj.CastEnabled = template.MaximumMP > 0; if (obj.Template.Grow) { obj.Template.Level++; } if (obj.Template.Level > 99) { obj.Template.Level = 1; } //=E4 / 0.1 * E6 obj.Template.MaximumHP = (int)(obj.Template.Level / 0.1 * 32); obj.Template.MaximumMP = (int)(obj.Template.Level / 0.1 * 16); //calculate what ac to give depending on level. obj.BonusAc = (sbyte)(70 - 101 / 70 * template.Level); if (obj.BonusAc > Config.BaseAC) { obj.BonusAc = Config.BaseAC; } if (obj.Template.ElementType == ElementQualifer.Random) { obj.DefenseElement = RandomEnumValue <ElementManager.Element>(); obj.OffenseElement = RandomEnumValue <ElementManager.Element>(); } else if (obj.Template.ElementType == ElementQualifer.Defined) { obj.DefenseElement = template?.DefenseElement == ElementManager.Element.None ? RandomEnumValue <ElementManager.Element>() : template.DefenseElement; obj.OffenseElement = template?.OffenseElement == ElementManager.Element.None ? RandomEnumValue <ElementManager.Element>() : template.OffenseElement; } obj.BonusMr = (byte)(10 * (template.Level / 10 * 100 / 100)); if (obj.BonusMr > Config.BaseMR) { obj.BonusMr = Config.BaseMR; } if ((template.PathQualifer & PathQualifer.Wander) == PathQualifer.Wander) { obj.WalkEnabled = true; } if (template.MoodTyle == MoodQualifer.Aggressive) { obj.Aggressive = true; } else if (template.MoodTyle == MoodQualifer.Unpredicable) { lock (Generator.Random) { //this monster has a 50% chance of being aggressive. obj.Aggressive = Generator.Random.Next(1, 101) > 50; } } if ((template.SpawnType & SpawnQualifer.Random) == SpawnQualifer.Random) { var x = Generator.Random.Next(1, map.Cols); var y = Generator.Random.Next(1, map.Rows); while (map.IsWall(obj, x, y) || map.Tile[x, y] != TileContent.None) { x = Generator.Random.Next(1, map.Cols); y = Generator.Random.Next(1, map.Rows); } obj.X = x; obj.Y = y; } else if ((template.SpawnType & SpawnQualifer.Defined) == SpawnQualifer.Defined) { obj.X = template.DefinedX; obj.Y = template.DefinedY; var invalid = false; //if not available. find a nearbly location nearby and try spawn it there. while (map.IsWall(obj, obj.X, obj.Y) || map.Tile[obj.X, obj.Y] != TileContent.None) { for (var i = 0; i < 4; i++) { var tiles = map.GetNearByTiles(obj, (short)obj.X, (short)obj.Y, 20); if (tiles.Length > 0) { var pos = tiles[i]; if (pos != null) { obj.X = pos.X; obj.Y = pos.Y; break; } } else { invalid = true; } } if (invalid) { break; } } } lock (Generator.Random) { obj.Serial = Generator.GenerateNumber(); } obj.CurrentMapId = map.ID; obj.CurrentHp = template.MaximumHP; obj.CurrentMp = template.MaximumMP; obj._MaximumHp = template.MaximumHP; obj._MaximumMp = template.MaximumMP; obj.CreationDate = DateTime.UtcNow; lock (Generator.Random) { obj.Image = template.ImageVarience > 0 ? (ushort)Generator.Random.Next(template.Image, template.Image + template.ImageVarience) : template.Image; } obj.Script = ScriptManager.Load <MonsterScript>(template.ScriptName, obj, map); //TODO apply formulas. return(obj); }
public static Monster Create(MonsterTemplate template, Area map) { if (template.CastSpeed == 0) { template.CastSpeed = 2000; } if (template.AttackSpeed == 0) { template.AttackSpeed = 1000; } if (template.MovementSpeed == 0) { template.MovementSpeed = 2000; } if (template.Level == 0) { template.Level = 1; } var obj = new Monster(); obj.Template = template; obj.Map = map; obj.CastTimer = new GameServerTimer(TimeSpan.FromMilliseconds(template.CastSpeed)); obj.BashTimer = new GameServerTimer(TimeSpan.FromMilliseconds(template.AttackSpeed)); obj.WalkTimer = new GameServerTimer(TimeSpan.FromMilliseconds(template.MovementSpeed)); obj.CastEnabled = template.MaximumMP > 0; obj.TaggedAislings = new ConcurrentDictionary <int, Sprite>(); if (obj.Template.Grow) { obj.Template.Level++; } if (obj.Template.Level > 99) { obj.Template.Level = 1; } //=E4 / 0.1 * E6 obj.Template.MaximumHP = (int)(obj.Template.Level / 0.1 * 3); obj.Template.MaximumMP = (int)(obj.Template.Level / 0.1 * 2); //calculate what ac to give depending on level. obj.BonusAc = (sbyte)(70 - 101 / 70 * template.Level); if (obj.BonusAc > Config.BaseAC) { obj.BonusAc = Config.BaseAC; } obj.DefenseElement = ElementManager.Element.None; obj.OffenseElement = ElementManager.Element.None; if (obj.Template.ElementType == ElementQualifer.Random && obj.Template.Level > 3) { obj.DefenseElement = RandomEnumValue <ElementManager.Element>(); obj.OffenseElement = RandomEnumValue <ElementManager.Element>(); } else if (obj.Template.ElementType == ElementQualifer.Defined) { obj.DefenseElement = template?.DefenseElement == ElementManager.Element.None ? RandomEnumValue <ElementManager.Element>() : template.DefenseElement; obj.OffenseElement = template?.OffenseElement == ElementManager.Element.None ? RandomEnumValue <ElementManager.Element>() : template.OffenseElement; } obj.BonusMr = (byte)(10 * (template.Level / 10 * 100 / 100)); if (obj.BonusMr > Config.BaseMR) { obj.BonusMr = Config.BaseMR; } if ((template.PathQualifer & PathQualifer.Wander) == PathQualifer.Wander) { obj.WalkEnabled = true; } else if ((template.PathQualifer & PathQualifer.Fixed) == PathQualifer.Fixed) { obj.WalkEnabled = false; } else if ((template.PathQualifer & PathQualifer.Patrol) == PathQualifer.Patrol) { obj.WalkEnabled = true; } if (template.MoodTyle == MoodQualifer.Aggressive) { obj.Aggressive = true; } else if (template.MoodTyle == MoodQualifer.Unpredicable) { lock (Generator.Random) { //this monster has a 50% chance of being aggressive. obj.Aggressive = Generator.Random.Next(1, 101) > 50; } } if ((template.SpawnType & SpawnQualifer.Random) == SpawnQualifer.Random) { var x = Generator.Random.Next(1, map.Cols); var y = Generator.Random.Next(1, map.Rows); var tries = 0; var success = false; //let monters spawn on anything passable. while ((map.IsWall(obj, x, y) || map[x, y] != TileContent.Aisling && map.IsWall(obj, x, y) || map[x, y] != TileContent.Monster && map.IsWall(obj, x, y) || map[x, y] != TileContent.Mundane && map.IsWall(obj, x, y) || map[x, y] != TileContent.Wall) && tries <= 256) { lock (Generator.Random) { x = Generator.Random.Next(1, map.Cols); y = Generator.Random.Next(1, map.Rows); } tries++; } success = (tries < 256); if (!success) { lock (Generator.Random) { x = Generator.Random.Next(1, map.Cols); y = Generator.Random.Next(1, map.Rows); } } obj.X = x; obj.Y = y; } else if ((template.SpawnType & SpawnQualifer.Defined) == SpawnQualifer.Defined) { obj.X = template.DefinedX; obj.Y = template.DefinedY; } lock (Generator.Random) { obj.Serial = Generator.GenerateNumber(); } obj.CurrentMapId = map.ID; obj.CurrentHp = template.MaximumHP; obj.CurrentMp = template.MaximumMP; obj._MaximumHp = template.MaximumHP; obj._MaximumMp = template.MaximumMP; obj.AbandonedDate = DateTime.UtcNow; lock (Generator.Random) { obj.Image = template.ImageVarience > 0 ? (ushort)Generator.Random.Next(template.Image, template.Image + template.ImageVarience) : template.Image; } obj.Script = ScriptManager.Load <MonsterScript>(template.ScriptName, obj, map); if (obj.Template.LootType.HasFlag(LootQualifer.Table)) { obj.LootManager = new LootDropper(); obj.LootTable = new LootTable(template.Name); obj.UpgradeTable = new LootTable("Probabilities"); foreach (var drop in obj.Template.Drops) { obj.LootTable.Add(GlobalItemTemplateCache[drop]); } obj.UpgradeTable.Add(new Common()); obj.UpgradeTable.Add(new Uncommon()); obj.UpgradeTable.Add(new Rare()); obj.UpgradeTable.Add(new Epic()); obj.UpgradeTable.Add(new Legendary()); obj.UpgradeTable.Add(new Mythical()); obj.UpgradeTable.Add(new Godly()); obj.UpgradeTable.Add(new Forsaken()); } return(obj); }