예제 #1
0
        public void MoverThreadProcess()
        {
            Output.WriteLine("[WORLD SERVER]MoverThread started");

            // Moove the Mobs a little bit around
            int npcCount = WorldSocket.npcs.Count;

            lock (WorldSocket.npcs.SyncRoot)
            {
                for (int i = 0; i < npcCount; i++)
                {
                    Mob thismob = (Mob)WorldSocket.npcs[i];
                    // Check if Client has a view for this mob

                    if (thismob.getIsSpawned() == true)
                    {
                        thismob.DoMobUpdate(thismob);
                    }
                }
            }


            // ToDo: This is the Mover Update Thread to update objects like NPCs every interval
            Thread.Sleep(1000);
        }
예제 #2
0
        public void loadMobs(string path)
        {
            // This is just an example of loading CSV
            //return dataTable;
            Output.Write("Loading Hostile Mobs ..");
            ArrayList goDB      = loadCSV(path, ';');
            int       linecount = 1;

            foreach (string[] data in goDB)
            {
                //Output.WriteLine("Show Colums for Line : " + linecount.ToString() + " GOID:  " + data[1].ToString() + " Name " + data[0].ToString());
                if (linecount > 1)
                {
                    UInt64 currentEntityId = WorldSocket.entityIdCounter;
                    WorldSocket.entityIdCounter++;
                    uint rotation = 0;
                    if (data[10].Length > 0)
                    {
                        rotation = uint.Parse(data[10]);
                    }


                    if (data[4].Length > 0 && data[5].Length > 0)
                    {
                        bool error  = false;
                        Mob  theMob = new Mob();
                        theMob.setEntityId(currentEntityId);
                        theMob.setDistrict(Convert.ToUInt16(data[0]));
                        theMob.setDistrictName(data[1]);
                        theMob.setName(data[2]);
                        theMob.setLevel(ushort.Parse(data[3]));
                        theMob.setHealthM(UInt16.Parse(data[4]));
                        theMob.setHealthC(UInt16.Parse(data[4])); // As max Health should be the current onload
                        if (UInt16.Parse(data[4]) == 0)
                        {
                            error = true;
                        }
                        theMob.setMobId((ushort)linecount);
                        theMob.setRsiHex(data[6]);
                        if (!isNumberEven(data[6].Length))
                        {
                            error = true;
                        }
                        theMob.setXPos(double.Parse(data[7]));
                        theMob.setYPos(double.Parse(data[8]));
                        theMob.setZPos(double.Parse(data[9]));
                        theMob.xBase = double.Parse(data[7]);
                        theMob.yBase = double.Parse(data[8]);
                        theMob.zBase = double.Parse(data[9]);
                        theMob.setRotation(rotation);
                        theMob.setIsDead(bool.Parse(data[11]));
                        theMob.setIsLootable(bool.Parse(data[12]));
                        // Init the Mob Update
                        if (!error)
                        {
                            theMob.DoMobUpdate(theMob);
                            WorldSocket.npcs.Add(theMob);
                            WorldSocket.gameServerEntities.Add(theMob);
                        }
                    }
                }
                linecount++;
            }
        }
예제 #3
0
        private static void CheckPlayerMobViews()
        {
            // Spawn/Update for mobs
            int npcCount = WorldSocket.npcs.Count;

            for (int i = 0; i < npcCount; i++)
            {
                Mob thismob = (Mob)WorldSocket.npcs[i];

                lock (WorldSocket.Clients.SyncRoot)
                {
                    foreach (string clientKey in WorldSocket.Clients.Keys)
                    {
                        // Loop through all clients
                        WorldClient thisclient = WorldSocket.Clients[clientKey] as WorldClient;

                        if (thisclient.Alive == true)
                        {
                            // Check if

                            if (thisclient.playerData.getOnWorld() == true && thisclient.playerData.waitForRPCShutDown == false)
                            {
                                Maths  math    = new Maths();
                                double playerX = 0;
                                double playerY = 0;
                                double playerZ = 0;
                                NumericalUtils.LtVector3dToDoubles(thisclient.playerInstance.Position.getValue(), ref playerX, ref playerY, ref playerZ);
                                Maths mathUtils     = new Maths();
                                bool  mobIsInCircle = mathUtils.IsInCircle((float)playerX, (float)playerZ, (float)thismob.getXPos(), (float)thismob.getZPos(), 5000);

                                // Spawn Mob if its in Visibility Range
                                ClientView mobView = thisclient.viewMan.getViewForEntityAndGo(thismob.getEntityId(), NumericalUtils.ByteArrayToUint16(thismob.getGoId(), 1));
                                if (mobView.viewCreated == false && thismob.getDistrict() == thisclient.playerData.getDistrictId() && thisclient.playerData.getOnWorld() && mobIsInCircle)
                                {
                                    #if DEBUG
                                    ServerPackets pak = new ServerPackets();
                                    pak.sendSystemChatMessage(thisclient, "Mob with Name " + thismob.getName() + " with new View ID " + mobView.ViewID + " spawned", "BROADCAST");
                                    #endif

                                    ServerPackets mobPak = new ServerPackets();
                                    mobPak.SpawnMobView(thisclient, thismob, mobView);
                                    mobView.spawnId      = thisclient.playerData.spawnViewUpdateCounter;
                                    mobView.viewCreated  = true;
                                    thismob.isUpdateable = true;
                                    thismob.DoMobUpdate(thismob);
                                }

                                // Delete Mob's View from Client if we are outside
                                if (mobView.viewCreated == true && !mobIsInCircle && thismob.getDistrict() == thisclient.playerData.getDistrictId())
                                {
                                    // ToDo: delete mob
                                    ServerPackets packets = new ServerPackets();
                                    packets.sendDeleteViewPacket(thisclient, mobView.ViewID);
                                    #if DEBUG
                                    packets.sendSystemChatMessage(thisclient, "MobView (" + thismob.getName() + " LVL: " + thismob.getLevel() + " ) with View ID " + mobView.ViewID + " is out of range and is deleted!", "MODAL");
                                    #endif
                                    thisclient.viewMan.removeViewByViewId(mobView.ViewID);
                                    thismob.isUpdateable = false;
                                }
                            }
                        }
                    }
                }
            }
        }