Esempio n. 1
0
//		void Log(string fmt, params object[] obs)
//		{
//			Const.Log("Spawn", fmt, obs);
//		}

        Obj SpawnObj(SpawnData data, uint entry)
        {
            if (data.obtype == ObjectType.UNIT)
            {
                Unit u = new Unit(gameServer);

                Position  pos = data.point;
                SpawnData p   = null;
                if (entry != Const.SpawnPointEntry)
                {
                    p = data;
                    gameServer.PPoint.GetDest(data.map, pos, Const.rand.Next(6), Const.rand.Next((int)p.spawnDist[0]), out pos);
                }
                if (!u.Create(entry, data.map, pos, data.ang, p))
                {
                    if (LogMessageEvent != null)
                    {
                        LogMessageEvent("SpawnObj ERROR: unknown creature {0} entry :" + entry);
                    }
                    return(null);
                }
                gameServer.AddObj(u);
                return(u);
            }
            return(null);
        }
Esempio n. 2
0
        public bool Create(uint entry, ushort map, Position pos, float ang, SpawnData spawn)
        {
            Entry       = entry;             // asi id monstra
            Map         = map;
            Pos         = pos;
            Orientation = ang;
            spawnPoint  = spawn;

            Hashtable r = gameServer.DB.creatures.Get("creature " + entry.ToString());

            if (r == null)
            {
                return(false);
            }

            Name      = r["name"] as string;
            displayID = (uint)(int)r["model"];
            if (r.Contains("level"))
            {
                if (r["level"] is int[])
                {
                    int[] lvls = r["level"] as int[];
                    if (lvls[0] < lvls[1])
                    {
                        level = (uint)(lvls[0] + Const.rand.Next(lvls[1] - lvls[0]));
                    }
                    else
                    {
                        level = (uint)(lvls[1] + Const.rand.Next(lvls[0] - lvls[1]));
                    }
                }
                else
                {
                    level = (uint)(int)r["level"];
                }
            }
            if (r.Contains("npcflags"))
            {
                npcflags = (uint)(int)r["npcflags"];
                SetUpdateValue(UpdateFields.UNIT_NPC_FLAGS, npcflags);
            }

            if (r.Contains("size"))
            {
                SetUpdateValueFloat(UpdateFields.OBJECT_FIELD_SCALE_X, (float)r["size"]);
            }

            if (r.Contains("maxhealth"))
            {
                health = mhealth = (uint)(int)r["maxhealth"];
            }

            if (r.Contains("maxmana"))
            {
                power[0] = mpower[0] = (uint)(int)r["maxmana"];
            }

            if (r.Contains("faction"))
            {
                SetUpdateValue(UpdateFields.UNIT_FIELD_FACTIONTEMPLATE, (uint)(int)r["faction"]);
            }

            Create();
            return(true);
        }
Esempio n. 3
0
        public void TrySpawnObj(ushort map, Position pos)
        {
            for (int i = 0; i < worldData.Count; i++)
            {
                SpawnData d = (SpawnData)worldData[i];
                if (d.map != map || d.point.Distance(pos) > Const.UPDATE_DISTANCE || d.spawnTick == -1 || d.spawnTick > Const.Tick)
                {
                    continue;
                }

                uint cnt = 0;
                for (int j = 0; j < d.spawnMaxCount.Length; j++)
                {
                    cnt += (uint)d.spawnMaxCount[j];
                }

                // need respawn?
                if (d.spawnUnits != null)
                {
                    if (d.spawnUnits.Count >= cnt)
                    {
                        continue;
                    }
                }
                else
                {
                    d.spawnUnits = new ArrayList();
                    d.spawnPoint = SpawnObj(d, Const.SpawnPointEntry);
                }

                uint[] count = new uint[d.spawnMaxCount.Length];
                foreach (Obj ob in d.spawnUnits)
                {
                    for (int j = 0; j < d.spawnEntry.Length; j++)
                    {
                        if (ob.Entry == d.spawnEntry[j])
                        {
                            count[j]++;
                        }
                    }
                }
                for (int j = 0; j < count.Length; j++)
                {
                    if (d.spawnMaxCount[j] == count[j])
                    {
                        continue;
                    }

                    if (LogMessageEvent != null)
                    {
                        LogMessageEvent("spawn {0} {1} entry " + d.spawnEntry[j] + " count " + Convert.ToString(d.spawnMaxCount[j] - count[j]));
                    }

                    while (count[j] < d.spawnMaxCount[j])
                    {
                        Obj ob = SpawnObj(d, (uint)d.spawnEntry[j]);
                        if (ob == null)
                        {
                            break;
                        }
                        count[j]++;
                        d.spawnUnits.Add(ob);
                    }
                }

                d.spawnTick = -1;
            }
        }
Esempio n. 4
0
        void SetWorldData(string sec, Hashtable table)
        {
            if (sec == null)
            {
                return;
            }

            DB.ConvertType(sec, table);
            if (!table.Contains(sec))
            {
                return;
            }

            Hashtable data = table[sec] as Hashtable;

            table.Remove(sec);
            if (!data.Contains("TYPE"))
            {
                return;
            }

            ObjectType type = (ObjectType)(int)data["TYPE"];

            switch (type)
            {
            case ObjectType.AREATRIGGER:
            case ObjectType.CORPSE:
            case ObjectType.GAMEOBJECT:

                break;

            case ObjectType.UNIT:                      // only add spawn object
            {
                if ((int)data["ENTRY"] != Const.SpawnPointEntry)
                {
                    break;
                }
                int[] spawn = data["SPAWN"] as int[];
                if (spawn == null)
                {
                    break;
                }

                SpawnData d   = new SpawnData();
                float[]   xyz = (float[])data["XYZ"];
                d.point = new Position(xyz[0], xyz[1], xyz[2]);
                d.ang   = xyz[3];
                if (data.Contains("MAP"))
                {
                    d.map = (ushort)(int)data["MAP"];
                }
                d.obtype = type;

                d.spawnEntry    = new int[spawn.Length / 2];
                d.spawnMaxCount = new int[spawn.Length / 2];
                for (int i = 0; i < spawn.Length - 1; i += 2)
                {
                    d.spawnEntry[i / 2]    = spawn[i];
                    d.spawnMaxCount[i / 2] = spawn[i + 1];
                }

                if (data.Contains("SPAWNTIME"))
                {
                    d.spawnTime = (int[])data["SPAWNTIME"];
                }
                if (data.Contains("SPAWNDIST"))
                {
                    d.spawnDist = (float[])data["SPAWNDIST"];
                }

                worldData.Add(d);
                break;
            }
            }
        }