private void SendServerInfo(MemoryMappedFileCommunicator communicator)
            {
                if (Info == null)
                {
                    Info = new ServerInformation
                    {
                        ServerConfig     = Config,
                        MonsterTemplates = new List <MonsterTemplate>(GlobalMonsterTemplateCache),
                        ItemTemplates    = new List <ItemTemplate>(GlobalItemTemplateCache.Select(i => i.Value)),
                        SkillTemplates   = new List <SkillTemplate>(GlobalSkillTemplateCache.Select(i => i.Value)),
                        SpellTemplates   = new List <SpellTemplate>(GlobalSpellTemplateCache.Select(i => i.Value)),
                        MundaneTemplates = new List <MundaneTemplate>(GlobalMundaneTemplateCache.Select(i => i.Value)),
                        WarpTemplates    = new List <WarpTemplate>(GlobalWarpTemplateCache),
                        Areas            = new List <Area>(GlobalMapCache.Select(i => i.Value)),
                        Buffs            = new List <Buff>(GlobalBuffCache.Select(i => i.Value)),
                        Debuffs          = new List <Debuff>(GlobalDeBuffCache.Select(i => i.Value)),
                    };
                }

                Info.GameServerOnline  = true;
                Info.LoginServerOnline = true;

                var players_online = Game?.Clients.Where(i => i != null && i.Aisling != null && i.Aisling.LoggedIn);

                if (players_online != null)
                {
                    Info.PlayersOnline    = new List <Aisling>(players_online.Select(i => i.Aisling));
                    Info.GameServerStatus = $"Up time {Math.Round(Uptime.TotalDays, 2)}:{Math.Round(Uptime.TotalHours, 2)} | Online Users ({ players_online.Count() }) | Total Characters ({ StorageManager.AislingBucket.Count })";
                    Info.GameServerOnline = true;
                }
                else
                {
                    Info.PlayersOnline    = new List <Aisling>();
                    Info.GameServerOnline = false;
                    Info.GameServerStatus = "Offline.";
                }

                lock (communicator)
                {
                    var jsonWrap = JsonConvert.SerializeObject(Info, StorageManager.Settings);
                    communicator.Write(jsonWrap);
                }
            }
示例#2
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);
        }