Exemple #1
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;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void sendCastAbilityOnEntityId(UInt16 viewId, UInt32 animationId, UInt16 value)
        {
            ClientView theView = Store.currentClient.viewMan.getViewById(viewId);

            Random randomObject = new Random();
            ushort randomHealth = (ushort)randomObject.Next(3, 1800);
            // RSI Health FX "send 02 03 02 00 02 80 80 80 90 ed 00 30 22 0a 00 28 06 00 00;"
            PacketContent pak = new PacketContent();

            if (viewId == 0)
            {
                viewId = 2;
            }
            pak.addUint16(viewId, 1);

            UInt32 theGoID = 12;

            if (theView != null)
            {
                theGoID = theView.GoID;
            }

            switch (theGoID)
            {
            case 12:
                pak.addByte(0x02);
                pak.addByte(0x80);
                pak.addByte(0x80);
                pak.addByte(0x80);
                if (viewId == 2)
                {
                    pak.addByte(0x80);
                    pak.addByte(0xb0);
                }
                else
                {
                    pak.addByte(0x0c);
                }
                pak.addUint32(animationId, 1);
                pak.addUintShort(Store.currentClient.playerData.assignSpawnIdCounter());
                break;

            case 599:

                // Its more a demo - we "one hit" the mob currently so we must update this
                lock (WorldSocket.npcs.SyncRoot)
                {
                    for (int i = 0; i < WorldSocket.npcs.Count; i++)
                    {
                        Mob thismob = (Mob)WorldSocket.npcs[i];
                        if (theView != null && thismob.getEntityId() == theView.entityId)
                        {
                            thismob.HitEnemyWithDamage(value, animationId);

                            if (thismob.getHealthC() <= 0)
                            {
                                thismob.setIsDead(true);
                                this.SendNpcDies(theView.ViewID, Store.currentClient, thismob);

                                // We got some Exp for it - currently we just make a simple trick to calculate some exp
                                // Just take currentLevel * modifier
                                Random rand = new Random();

                                UInt32 expModifier = (UInt32)rand.Next(100, 500);
                                UInt32 expGained   = thismob.getLevel() * expModifier;
                                // Update EXP
                                new PlayerHandler().IncrementPlayerExp(expGained);
                                thismob.setIsLootable(true);
                            }
                            WorldSocket.npcs[i] = thismob;
                        }
                    }
                }
                break;

            default:
                pak.addByte(0x02);
                pak.addByte(0x80);
                pak.addByte(0x80);
                pak.addByte(0x80);
                if (viewId == 2)
                {
                    pak.addByte(0x80);
                    pak.addByte(0xb0);
                }
                else
                {
                    pak.addByte(0x0c);
                }
                pak.addUint32(animationId, 1);
                pak.addUintShort(Store.currentClient.playerData.assignSpawnIdCounter());
                break;
            }

            string hex = StringUtils.bytesToString(pak.returnFinalPacket());

            Store.currentClient.messageQueue.addObjectMessage(pak.returnFinalPacket(), false);
            Store.currentClient.FlushQueue();
        }