Пример #1
0
        public static void Create(MundaneTemplate template)
        {
            if (template == null)
            {
                return;
            }

            var existing = template.GetObject <Mundane>(p => p.Template != null && p.Template.Name == template.Name);

            //this npc was already created?
            if (existing != null)
            {
                //check if it's dead.
                if (existing.CurrentHp == 0)
                {
                    existing.OnDeath();
                }
                else
                {
                    //it's alive. no need to re-add.
                    return;
                }
            }


            var npc = new Mundane();

            npc.Template = template;

            npc.CurrentMapId = npc.Template.AreaID;
            lock (Generator.Random)
            {
                npc.Serial = Generator.GenerateNumber();
            }
            npc.X                  = template.X;
            npc.Y                  = template.Y;
            npc._MaximumHp         = (int)(npc.Template.Level / 0.1 * 32);
            npc._MaximumMp         = (int)(npc.Template.Level / 0.1 * 16);
            npc.Template.MaximumHp = npc.MaximumHp;
            npc.Template.MaximumMp = npc.MaximumMp;

            npc.CurrentHp = npc.Template.MaximumHp;
            npc.CurrentMp = npc.Template.MaximumMp;
            npc.Direction = npc.Template.Direction;

            npc.Map    = ServerContext.GlobalMapCache[npc.CurrentMapId];
            npc.Script = ScriptManager.Load <MundaneScript>(template.ScriptKey, ServerContext.Game, npc);

            npc.Template.AttackTimer   = new GameServerTimer(TimeSpan.FromMilliseconds(450));
            npc.Template.EnableTurning = false;
            npc.Template.WalkTimer     = new GameServerTimer(TimeSpan.FromSeconds(750));
            npc.Template.ChatTimer     = new GameServerTimer(TimeSpan.FromSeconds(Generator.Random.Next(10, 35)));
            npc.Template.TurnTimer     = new GameServerTimer(TimeSpan.FromSeconds(6));

            npc.AddObject(npc);
        }
Пример #2
0
        public static void Create(MundaneTemplate template)
        {
            if (template == null)
            {
                return;
            }

            var map      = ServerContext.GlobalMapCache[template.AreaID];
            var existing = template.GetObject <Mundane>(map,
                                                        p => p != null && p.Template != null && p.Template.Name == template.Name);

            if (existing != null)
            {
                if (existing.CurrentHp == 0)
                {
                    existing.OnDeath();
                }
                else
                {
                    return;
                }
            }

            var npc = new Mundane
            {
                Template = template
            };

            if (npc.Template.TurnRate == 0)
            {
                npc.Template.TurnRate = 5;
            }

            if (npc.Template.CastRate == 0)
            {
                npc.Template.CastRate = 2;
            }

            if (npc.Template.WalkRate == 0)
            {
                npc.Template.WalkRate = 2;
            }

            npc.CurrentMapId = npc.Template.AreaID;
            lock (Generator.Random)
            {
                npc.Serial = Generator.GenerateNumber();
            }

            npc.XPos               = template.X;
            npc.YPos               = template.Y;
            npc._MaximumHp         = (int)(template.Level / 0.1 * 15);
            npc._MaximumMp         = (int)(template.Level / 0.1 * 5);
            npc.Template.MaximumHp = npc.MaximumHp;
            npc.Template.MaximumMp = npc.MaximumMp;

            npc.CurrentHp    = npc.Template.MaximumHp;
            npc.CurrentMp    = npc.Template.MaximumMp;
            npc.Direction    = npc.Template.Direction;
            npc.CurrentMapId = npc.Template.AreaID;

            npc.BonusAc = (int)(70 - npc.Template.Level * 0.5 / 1.0);

            if (npc.BonusAc < -70)
            {
                npc.BonusAc = -70;
            }

            if (npc.Template.ChatRate == 0)
            {
                npc.Template.ChatRate = 10;
            }

            if (npc.Template.TurnRate == 0)
            {
                npc.Template.TurnRate = 8;
            }

            npc.DefenseElement = Generator.RandomEnumValue <ElementManager.Element>();
            npc.OffenseElement = Generator.RandomEnumValue <ElementManager.Element>();

            npc.Scripts = ScriptManager.Load <MundaneScript>(template.ScriptKey, ServerContext.Game, npc);

            npc.Template.AttackTimer   = new GameServerTimer(TimeSpan.FromMilliseconds(450));
            npc.Template.EnableTurning = false;
            npc.Template.WalkTimer     = new GameServerTimer(TimeSpan.FromSeconds(npc.Template.WalkRate));
            npc.Template.ChatTimer     = new GameServerTimer(TimeSpan.FromSeconds(npc.Template.ChatRate));
            npc.Template.TurnTimer     = new GameServerTimer(TimeSpan.FromSeconds(npc.Template.TurnRate));
            npc.Template.SpellTimer    = new GameServerTimer(TimeSpan.FromSeconds(npc.Template.CastRate));
            npc.InitMundane();

            npc.AddObject(npc);
        }
Пример #3
0
        public static void Create(MundaneTemplate template)
        {
            if (template == null)
            {
                return;
            }

            var existing = template.GetObject <Mundane>(p => p != null && p.Template != null && p.Template.Name == template.Name);

            //this npc was already created?
            if (existing != null)
            {
                if (existing.CurrentHp == 0)
                {
                    existing.OnDeath();
                }
                else
                {
                    return;
                }
            }


            var npc = new Mundane();

            npc.Template = template;

            if (npc.Template.TurnRate == 0)
            {
                npc.Template.TurnRate = 5;
            }

            if (npc.Template.CastRate == 0)
            {
                npc.Template.CastRate = 2;
            }

            if (npc.Template.WalkRate == 0)
            {
                npc.Template.WalkRate = 2;
            }


            npc.CurrentMapId = npc.Template.AreaID;
            lock (Generator.Random)
            {
                npc.Serial = Generator.GenerateNumber();
            }

            npc.X                  = template.X;
            npc.Y                  = template.Y;
            npc._MaximumHp         = (int)(template.Level / 0.1 * 15);
            npc._MaximumMp         = (int)(template.Level / 0.1 * 5);
            npc.Template.MaximumHp = npc.MaximumHp;
            npc.Template.MaximumMp = npc.MaximumMp;

            npc.CurrentHp    = npc.Template.MaximumHp;
            npc.CurrentMp    = npc.Template.MaximumMp;
            npc.Direction    = npc.Template.Direction;
            npc.CurrentMapId = npc.Template.AreaID;

            npc.BonusAc = (int)((5 + npc.Template.Level - 40 / 100 * npc.Template.Level));

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

            npc.DefenseElement = Generator.RandomEnumValue <ElementManager.Element>();
            npc.OffenseElement = Generator.RandomEnumValue <ElementManager.Element>();

            npc.Script = ScriptManager.Load <MundaneScript>(template.ScriptKey, ServerContext.Game, npc);

            npc.Template.AttackTimer   = new GameServerTimer(TimeSpan.FromMilliseconds(450));
            npc.Template.EnableTurning = false;
            npc.Template.WalkTimer     = new GameServerTimer(TimeSpan.FromSeconds(npc.Template.WalkRate));
            npc.Template.ChatTimer     = new GameServerTimer(TimeSpan.FromSeconds(Generator.Random.Next(25, 40)));
            npc.Template.TurnTimer     = new GameServerTimer(TimeSpan.FromSeconds(npc.Template.TurnRate));
            npc.Template.SpellTimer    = new GameServerTimer(TimeSpan.FromSeconds(npc.Template.CastRate));
            npc.InitMundane();
            npc.AddObject(npc);
        }