Exemple #1
0
        private void DetermineRandomDrop()
        {
            int idx = 0;

            if (Template.Drops.Count > 0)
            {
                lock (rnd)
                {
                    idx = rnd.Next(Template.Drops.Count);
                }
            }

            var rndSelector = Template.Drops[idx];

            if (GlobalItemTemplateCache.ContainsKey(rndSelector))
            {
                var item   = Item.Create(this, GlobalItemTemplateCache[rndSelector], true);
                var chance = 0.00;

                lock (rnd)
                {
                    chance = Math.Round(rnd.NextDouble(), 2);
                }

                if (chance <= item.Template.DropRate)
                {
                    item.Release(this, Position);
                }
            }
        }
Exemple #2
0
        private void GenerateDrops()
        {
            if (Template.LootType.HasFlag(LootQualifer.Table))
            {
                if (LootTable == null || LootManager == null)
                {
                    return;
                }

                lock (rnd)
                {
                    DetermineDrop().ForEach(i =>
                    {
                        if (i != null)
                        {
                            if (GlobalItemTemplateCache.ContainsKey(i))
                            {
                                var rolled_item = Item.Create(this, GlobalItemTemplateCache[i]);
                                if (rolled_item != GlobalLastItemRoll)
                                {
                                    GlobalLastItemRoll = rolled_item;
                                    var upgrade        = DetermineQuality();

                                    if (rolled_item == null)
                                    {
                                        return;
                                    }

                                    if (rolled_item.Template.Flags.HasFlag(ItemFlags.QuestRelated))
                                    {
                                        upgrade = null;
                                    }

                                    rolled_item.Upgrades = upgrade?.Upgrade ?? 0;

                                    if (rolled_item.Upgrades > 0)
                                    {
                                        Item.ApplyQuality(rolled_item);
                                    }
                                    rolled_item.Cursed = true;
                                    rolled_item.AuthenticatedAislings = GetTaggedAislings();
                                    rolled_item.Release(this, Position);
                                }
                            }
                        }
                    });
                }
                return;
            }
            else if (Template.LootType.HasFlag(LootQualifer.Random))
            {
                DetermineRandomDrop();
                return;
            }
        }
        private void GenerateDrops()
        {
            if (Template.Drops.Count > 0)
            {
                lock (rnd)
                {
                    var idx         = rnd.Next(Template.Drops.Count);
                    var rndSelector = Template.Drops[idx];

                    if (GlobalItemTemplateCache.ContainsKey(rndSelector))
                    {
                        var item = Item.Create(this, GlobalItemTemplateCache[rndSelector], true);
                        if (rnd.NextDouble() <= item.Template.DropRate)
                        {
                            item.Release(this, Position);
                        }
                    }
                }
            }
        }
Exemple #4
0
        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 ConcurrentDictionary <int, Sprite>()
            };

            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; //;Config.MONSTER_HP_TABLE[obj.Template.Level % Config.MONSTER_HP_TABLE.Length];
            obj.Template.MaximumMP = (int)mp; //;Config.MONSTER_HP_TABLE[obj.Template.Level % Config.MONSTER_HP_TABLE.Length] / 3;


            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;

            //=ROUND(5 + H1-40  / 100 * H1, 0)
            obj.BonusAc = (int)((5 + template.Level - 40 / 100 * template.Level));

            if (obj.BonusAc < 0 || obj.BonusAc >= 100)
            {
                obj.BonusAc = 100;
            }

            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 > 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.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.X = x;
                obj.Y = y;

                if (map.IsWall(x, y))
                {
                    return(null);
                }
            }
            else if (template.SpawnType == 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)
                {
                    if (drop.Equals("random", StringComparison.OrdinalIgnoreCase))
                    {
                        lock (Generator.Random)
                        {
                            var available = 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 (GlobalItemTemplateCache.ContainsKey(drop))
                        {
                            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);
        }
        private void GenerateDrops()
        {
            if (Template.LootType.HasFlag(LootQualifer.Table))
            {
                if (LootTable == null || LootManager == null)
                {
                    return;
                }


                DetermineDrop().ForEach(i =>
                {
                    if (i != null)
                    {
                        if (GlobalItemTemplateCache.ContainsKey(i))
                        {
                            var rolled_item = Item.Create(this, GlobalItemTemplateCache[i]);
                            if (rolled_item != GlobalLastItemRoll)
                            {
                                GlobalLastItemRoll = rolled_item;

                                var upgrade = DetermineQuality();

                                if (rolled_item.Template.Enchantable)
                                {
                                    var variance = DetermineVariance();

                                    if (!ServerContext.Config.UseLoruleVariants)
                                    {
                                        variance = Variance.None;
                                    }

                                    if (variance != Variance.None)
                                    {
                                        rolled_item.ItemVariance = variance;
                                    }
                                }

                                if (rolled_item == null)
                                {
                                    return;
                                }

                                if (rolled_item.Template.Flags.HasFlag(ItemFlags.QuestRelated))
                                {
                                    upgrade = null;
                                }

                                if (!ServerContext.Config.UseLoruleItemRarity)
                                {
                                    upgrade = null;
                                }

                                rolled_item.Upgrades = upgrade?.Upgrade ?? 0;

                                if (rolled_item.Upgrades > 0)
                                {
                                    ApplyQuality(rolled_item);

                                    if (rolled_item.Upgrades > 2)
                                    {
                                        var user = Target ?? null;

                                        if (user is Aisling aisling)
                                        {
                                            var party = aisling.GroupParty.Members;

                                            foreach (var player in party)
                                            {
                                                player.Client.SendMessage(0x03,
                                                                          string.Format("Special Drop: {0}", rolled_item.DisplayName));
                                            }

                                            Task.Delay(500).ContinueWith(ct => { rolled_item.Animate(160, 200); });
                                        }
                                    }
                                }

                                rolled_item.Cursed = true;
                                rolled_item.AuthenticatedAislings = GetTaggedAislings().Cast <Sprite>().ToArray();
                                rolled_item.Release(this, Position);
                            }
                        }
                    }
                });
            }
            else if (Template.LootType.HasFlag(LootQualifer.Random))
            {
                DetermineRandomDrop();
            }
        }