public void CreateSpawn(DBSpawn spawn, UnitBase unit)
        {
            try
            {
                unit.Position   = spawn.Position;
                unit.Facing     = spawn.Facing;
                unit.Level      = spawn.Level;
                unit.DisplayID  = spawn.DisplayID;
                unit.Faction    = spawn.Faction;
                unit.Dead       = false;
                unit.StandState = UNITSTANDSTATE.STANDING;
                unit.Target     = 0;
                unit.Attacking  = false;
                unit.Roaming    = spawn.Roam;
                unit.Spawn_ID   = (int)spawn.ObjectId;

                unit.RespawnTime += (int)Math.Exp(unit.Level / 5);

                StatManager.CalculateNewStats(unit);

                LootManager.GenerateMobLoot(unit);

                unit.Health = unit.MaxHealth;
                unit.Power  = unit.MaxPower;

                //Console.WriteLine("Spawning: " + unit.Name + "(" + unit.Level + ") at " + unit.Position.X + " " + unit.Position.Y + " " + unit.Position.Z);
                Enter(unit);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while initializing spawn " + spawn.ObjectId);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Esempio n. 2
0
        static void OnSpawn(int msgID, BinReader data)
        {
            uint charID     = data.ReadUInt32();
            uint creatureID = data.ReadUInt32();
            uint spawnID    = data.ReadUInt32();

            WorldClient client = WorldServer.GetClientByCharacterID(charID);

            if (client == null)
            {
                return;
            }

            DBSpawn spawn = (DBSpawn)DBManager.GetDBObject(typeof(DBSpawn), spawnID);

            if (spawn == null)
            {
                Chat.System(client, "no spawn");
                return;
            }

            spawn.Creature = (DBCreature)DBManager.GetDBObject(typeof(DBCreature), creatureID);
            if (spawn.Creature == null)
            {
                Chat.System(client, "no creature");
                return;
            }

            if (spawn.Creature.Script == null)
            {
                Chat.System(client, "Creature script is null that's a nono");
                return;
            }

            spawn.Position   = client.Player.Position;
            spawn.Facing     = client.Player.Facing;
            spawn.WorldMapID = client.Player.WorldMapID;

            Type scriptType = Type.GetType(spawn.Creature.Script);

            if (scriptType == null)
            {
                Console.WriteLine("Unable to find " + spawn.Creature.Script + " for spawn " + spawn.ObjectId);
                return;
            }

//			Console.WriteLine("ScriptType: >"+scriptType+"<");
            UnitBase unit = (UnitBase)Activator.CreateInstance(scriptType, new object[1] {
                spawn.Creature
            });

            client.Player.MapTile.Map.CreateSpawn(spawn, unit);
            DBManager.SaveDBObject((DBSpawn)spawn);
//			Chat.System(client, spawn.ObjectId.ToString());
        }
Esempio n. 3
0
        public override void FireEvent()
        {
            // Here is the respawn code :)
            Console.WriteLine("Trying to respawn mobs: " + m_mobs.Name + " - ID: " + (uint)m_mobs.Spawn_ID + " - Time: " + m_mobs.RespawnTime);
            DBSpawn spawn = (DBSpawn)DBManager.GetDBObject(typeof(DBSpawn), (uint)m_mobs.Spawn_ID);

            if (spawn != null)
            {
                m_mobs.Position = spawn.Position;
                MapManager.GetMap(spawn.WorldMapID).CreateSpawn(spawn, m_mobs);
                m_mobs.InitializeUnit();
            }
        }
Esempio n. 4
0
        public void Send(DBSpawn spawn)
        {
            if (m_hasSpawn[(int)spawn.ObjectId])
            {
                return;
            }
            m_hasSpawn[(int)spawn.ObjectId] = true;

            if (spawn.Creature == null)
            {
                Console.WriteLine("Spawn " + spawn.ObjectId + " is missing creature object.");
            }
            else
            {
                Send(spawn.Creature);
            }

            SendDBObject(spawn);
        }
Esempio n. 5
0
        static void InitMaps(WORLDMSG msgID, BinReader data)
        {
            int numMaps = data.ReadInt32();

            for (int i = 0; i < numMaps; i++)
            {
                DBWorldMap map       = new DBWorldMap(data);
                int        numSpawns = data.ReadInt32();
                map.Spawns = new DBSpawn[numSpawns];
                for (int j = 0; j < numSpawns; j++)
                {
                    DBSpawn spawn = new DBSpawn();
                    spawn.Deserialize(data);
                    spawn.Creature = (DBCreature)DBManager.GetDBObject(typeof(DBCreature), spawn.CreatureID);
                    if (spawn.Creature == null)
                    {
                        Console.WriteLine("Spawn " + spawn.ObjectId + " is missing creature on worldserver.");
                    }
                    map.Spawns[j] = spawn;
                }
                m_maps[map.ObjectId] = new MapInstance(map);
            }
        }
Esempio n. 6
0
        static bool OnBanish(WorldClient client, string input)
        {
            if (client.Player.AccessLvl < ACCESSLEVEL.TEMPGM)
            {
                Chat.System(client, "You do not have access to this command");
                return(true);
            }

            LivingObject tmpObj = (LivingObject)client.Player.Selection;

            if ((tmpObj == null) || (tmpObj.ObjectType != OBJECTTYPE.UNIT))
            {
                Chat.System(client, "Selection is not a monster");
                return(false);
            }

            UnitBase mob = (UnitBase)client.Player.Selection;

            DBSpawn tmpSpawn = (DBSpawn)DBManager.GetDBObject(typeof(DBSpawn), (uint)mob.Spawn_ID);

            if (tmpSpawn == null)
            {
                Chat.System(client, "Spawn did not exist: " + mob.Spawn_ID);
            }
            else
            {
                Chat.System(client, "Removed Spawn: " + mob.Spawn_ID + " from the database.");
                DBManager.DeleteDBObject(tmpSpawn);
            }

            mob.SaveAndRemove();
            Chat.System(client, "Removed Monster: " + mob.Name + " with GUID: " + mob.GUID + " from the world.");

//			Console.WriteLine("This is GUID " + mob.GUID + " and spawn_id " + mob.Spawn_ID);
            return(true);
        }
Esempio n. 7
0
 public UnitBase(DBSpawn spawn) : this(spawn.Creature)
 {
     //m_mindamage = (float)spawn.Min_Damage;
     //m_maxdamage = (float)spawn.Max_Damage;
 }
Esempio n. 8
0
        static bool OnSpawn(LoginClient client, string input)
        {
            if (client.Account.AccessLvl < ACCESSLEVEL.TEMPGM)
            {
                Chat.System(client, "You do not have access to this command");
                return(true);
            }
            bool isVendor = false;

            char[] delim = new char[2];
            delim[0] = '\"';
            delim[1] = '^';
            string[] split  = input.Split(delim);
            string   script = "WorldScripts.Living.";
// Rewritten by Phaze so that only the first 2 parameters are necessary, and has defaults for the rest
            string name      = "";
            int    displayID = 0;
            int    level     = 1;
            int    health    = 1;
            int    mana      = 1;
            int    faction   = 14;
            uint   npc_flags = 0;
//			string facString="monster";
            string subName  = "";
            bool   bWalking = true;
            string cmd      = "";
            string input2   = "";

            if (split.Length == 3)
            {
                cmd    = split[0].TrimEnd(delim);
                cmd    = split[0].TrimEnd(' ');
                name   = split[1];
                input2 = "cmd name" + split[2];
            }
            else if (split.Length == 1)
            {
                split = input.Split(' ');
                if (split.Length == 1)
                {
                    return(false);
                }
                cmd    = split[0];
                name   = split[1];
                input2 = input;
            }
            else
            {
                return(false);
            }

            split = input2.Split(' ');

            if (split.Length > 2)
            {
                try
                {
                    if (split[2].StartsWith("0x"))
                    {
                        displayID = int.Parse(split[2].Substring(2), System.Globalization.NumberStyles.HexNumber);
                    }
                    else
                    {
                        displayID = int.Parse(split[2]);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }

                if (cmd.Length > 6)
                {
                    isVendor = true;
                }

                if (split.Length > 3)
                {
                    level = int.Parse(split[3]);
                    if (level == 0)
                    {
                        level = 1;
                    }
                    if (split.Length > 4)
                    {
//						facString=split[4];
// New code so that faction can be assigned by name or number - Phaze
                        FACTION NewFaction;
                        try
                        {
                            NewFaction = (FACTION)Enum.Parse(typeof(FACTION), split[4].ToUpper());
                        }
                        catch (System.ArgumentException)
                        {
                            Chat.System(client, "Invalid Faction");
                            Chat.System(client, "Available Factions are: ");
                            string Factions = "";
                            foreach (string eFaction in Enum.GetNames(typeof(FACTION)))
                            {
                                Factions += eFaction + ", ";
                            }
                            Chat.System(client, Factions);
                            return(true);
                        }
                        faction = (int)NewFaction;

                        if (split.Length > 5)
                        {
                            try
                            {
                                bWalking = bool.Parse(split[5]);
                            }
                            catch (Exception)
                            {
                                Chat.System(client, "Walking must be either TRUE or FALSE");
                                return(true);
                            }
                            if (split.Length > 6)
                            {
                                subName = split[6];
                                if (split.Length > 7)
                                {
                                    health = int.Parse(split[7]);
                                }
//									script += split[7];
                            }
                        }
                    }
                }
                if (health < 2)
                {
                    health = 25 + 50 * level;
                }
            }
            else
            {
                return(false);
            }
            if (isVendor)
            {
                switch (cmd.ToLower())
                {
                case "createtalker":
                    npc_flags = 1;
                    Chat.System(client, "Creating Talker: " + name);
                    break;

                case "createquester":
                    npc_flags = 2;
                    Chat.System(client, "Creating Quester: " + name);
                    break;

                case "createvendor":
                    npc_flags = 4;
                    subName   = "Merchant";
                    Chat.System(client, "Creating Vendor: " + name);
                    break;

                case "createtrainer":
                    npc_flags = 80;
                    subName   = "Trainer";
                    Chat.System(client, "Creating Trainer: " + name);
                    break;

                case "createtaxi":
                    npc_flags = 200;
                    subName   = "Taxi Vendor";
                    Chat.System(client, "Creating Taxi Vendor: " + name);
                    break;

                case "createtabard":
                    npc_flags = 512;                           //512 for tabard
                    subName   = "Tabard Vendor";
                    Chat.System(client, "Creating Tabard Vendor: " + name);
                    break;

                case "createbank":
                    npc_flags = 128;                           // This was for testing...  Phaze
                    subName   = "Banker";
                    Chat.System(client, "Creating Banker: " + name);
                    break;

                case "createtest":
                    npc_flags = 96;                           // This was for testing...  Phaze
                    subName   = "Test Vendor 96";
                    Chat.System(client, "Creating Test Vendor: " + name);
                    break;
                }
                if (faction == 14)
                {
                    faction = 0;
                }
                script  += "VendorBase";
                health   = 1000;
                bWalking = false;
            }
            else
            {
                script += "MonsterBase";
            }

            name = name.Replace("'", "");             // bleh!!
            if (name.Length > 20)
            {
                name = name.Substring(0, 20);
            }
            DataObject[] objs;
            try
            {
                objs = DataServer.Database.SelectObjects(typeof(DBCreature), "Name = '" + name + "'");
            }
            catch (Exception)
            {
                Chat.System(client, "Error looking up name in database.");
                return(true);
            }


            DBCreature creature;

            if (objs.Length == 0)
            {
                creature          = new DBCreature();
                creature.Name     = name;
                creature.Script   = script;
                creature.Title    = subName;
                creature.Roam     = bWalking;
                creature.NPCFlags = npc_flags;
                DataServer.Database.AddNewObject(creature);
            }
            else
            {
                creature = (DBCreature)objs[0];
            }

            DBSpawn spawn = new DBSpawn();

            spawn.Creature   = creature;
            spawn.CreatureID = creature.ObjectId;
            spawn.Level      = level;
            spawn.Health     = health;
            spawn.Power      = mana;
            spawn.DisplayID  = displayID;
            spawn.Faction    = faction;
            spawn.Roam       = bWalking;
            DataServer.Database.AddNewObject(spawn);

            client.WorldConnection.Send(creature);
            client.WorldConnection.Send(spawn);

            ScriptPacket pkg = new ScriptPacket(SCRMSG.SPAWN);

            pkg.Write(client.Character.ObjectId);
            pkg.Write(creature.ObjectId);
            pkg.Write(spawn.ObjectId);
            client.WorldConnection.Send(pkg);
            return(true);
        }
Esempio n. 9
0
        static bool OnTitle(WorldClient client, string input)
        {
            if (client.Player.AccessLvl < ACCESSLEVEL.TEMPGM)
            {
                Chat.System(client, "You do not have access to this command");
                return(true);
            }

            char[] delim = new char[2];
            delim[0] = '\"';
            delim[1] = '^';
            string[] split = input.Split(delim);

/*
 *                      DataObject[] obj = DataServer.Database.SelectObjects(typeof(DBVendor), "GUID='"+client.Character.Selected+"'");
 *                      if (obj==null || obj.Length==0)
 *                      {
 *                              Chat.System(client, "Vendor not found");
 *                              return true;
 *                      }
 *                      DBVendor vendor = (DBVendor)obj[0];
 *                      DBSpawn spawn = DataServer.Database.FindObjectByKey(typeof(DBSpawn), vendor.SpawnID);
 */
            UnitBase target = ((UnitBase)client.Player.Selection);

            if (target == null)
            {
                Chat.System(client, "Please select a mob or NPC first.");
                return(false);
            }

            DBSpawn spawn = (DBSpawn)DBManager.GetDBObject(typeof(DBSpawn), (uint)target.Spawn_ID);

            if (spawn == null)
            {
                Chat.System(client, "Please select a mob or NPC first.");
                return(false);
            }

            spawn.Creature = (DBCreature)DBManager.GetDBObject(typeof(DBCreature), spawn.CreatureID);
            if (spawn.Creature == null)
            {
                Chat.System(client, "Could not find creature");
                return(false);
            }

            if (split.Length != 1)
            {
                spawn.Creature.Title = split[1];
            }

            else
            {
                split = input.Split(' ');
                if (split.Length == 1)
                {
                    return(false);
                }
                spawn.Creature.Title = split[1];
            }
            DBManager.SaveDBObject(spawn.Creature);
            ServerPacket w = new ServerPacket(SMSG.CREATURE_QUERY_RESPONSE);

//			BinWriter w = new Binwriter(); //LoginClient.NewPacket(SMSG.CREATURE_QUERY_RESPONSE);
            w.Write(spawn.Creature.ObjectId);
            w.Write(spawn.Creature.Name);
            w.Write(spawn.Creature.Name1);
            w.Write(spawn.Creature.Name2);
            w.Write(spawn.Creature.Name3);
            w.Write(spawn.Creature.Title);
            w.Write(spawn.Creature.Flags);
            w.Write(spawn.Creature.CreatureType);
            w.Write(spawn.Creature.CreatureFamily);
            w.Write(0);             // unknown
            w.Finish();
            client.Player.MapTile.Map.Send(w, target.Position, 250f);
//			return true;


            target.SaveAndRemove();
            Type scriptType = Type.GetType(spawn.Creature.Script);

            //	Console.WriteLine(scriptType.BaseType);
            if (scriptType == null)
            {
                Console.WriteLine("Unable to find " + spawn.Creature.Script + " for spawn " + spawn.ObjectId);
            }

            UnitBase unit = (UnitBase)Activator.CreateInstance(scriptType, new object[1] {
                spawn.Creature
            });

            client.Player.MapTile.Map.CreateSpawn(spawn, unit);
            return(true);
        }