Beispiel #1
0
        public void Tick()
        {
            if (NewItems == null)
            {
                NewItems    = new ConcurrentDictionary <Serial, LKCamelot.script.item.Item>();
                NewAuctions = new ConcurrentDictionary <Serial, script.item.AuctionItem>();
                foreach (var items in BinaryIO.LoadItems())
                {
                    NewItems.TryAdd(items.m_Serial, items);
                }
                foreach (var play in BinaryIO.LoadAuctions())
                {
                    NewAuctions.TryAdd(play.item.m_Serial, play);
                }
                foreach (var play in BinaryIO.LoadPlayers())
                {
                    handler.add.TryAdd(play.Name, play);
                }
                Console.WriteLine("Loaded " + NewAuctions.Count + " Auctions.");
                Console.WriteLine("Loaded " + NewItems.Count + " Items.");
                Console.WriteLine("Loaded " + handler.add.Count + " Players.");
            }

            if (m_MObjects == null)
            {
                m_MObjects = new ConcurrentDictionary <Serial, Serial>();
                foreach (var mobile in handler.add.Values)
                {
                    m_MObjects.TryAdd(mobile.Serial, mobile.Serial);
                }
                foreach (var item in NewItems)
                {
                    m_MObjects.TryAdd(item.Key, item.Key);
                }
                foreach (var item in NewAuctions)
                {
                    m_MObjects.TryAdd(item.Key, item.Key);
                }
            }

            if (NewNpcs == null)
            {
                NewNpcs = new Dictionary <Serial, LKCamelot.script.npc.BaseNPC>()
                {
                    { 1, new script.npc.Arnold() },
                    { 2, new script.npc.Employee() },
                    { 3, new script.npc.Loen() },
                    { 4, new script.npc.Aron() },
                    { 7, new script.npc.Boy() },
                    { 5, new script.npc.Alias() },
                }
            }
            ;

            if (World.NewMonsters == null)
            {
                Spawnere.Spawn();
            }

            if (spawner == null)
            {
                spawner = Task.Factory.StartNew(() =>
                                                { spawnrun(); }
                                                );
            }


            QueDele        tq;
            List <QueDele> TickQued = new List <QueDele>();

            try
            {
                TickQued = TickQue.ToList();
            }
            catch { };

            foreach (var tick in TickQued)
            {
                if (tick == null)
                {
                    TickQue.RemoveAt(0);
                    continue;
                }

                if (tick.Serial < LKCamelot.Server.tickcount.ElapsedMilliseconds)
                {
                    SendToAll(tick);
                    TickQue.Remove(tick);
                    //  var ttt = tick.Packet.Skip(1).Take(4);
                    Serial temp;
                    if (m_MObjects.ContainsKey(tick.tempser))
                    {
                        m_MObjects.TryRemove(tick.tempser, out temp);
                    }
                }
            }

            if (LKCamelot.Server.tickcount.ElapsedMilliseconds - 3600000 > lastitemsave)
            {
                lastitemsave = LKCamelot.Server.tickcount.ElapsedMilliseconds;
                SaveAll();
                string chat = "[Alias]: Bring your friends to the Last Kingdom!";
                SendToAll(new QueDele("all", new UpdateChatBox(0x08, 0x02, 0, (short)chat.Count(), chat).Compile()));
                chat = "[Alias]: Visit the trader at: lk.kingdomofk.net/trader!";
                SendToAll(new QueDele("all", new UpdateChatBox(0x08, 0x02, 0, (short)chat.Count(), chat).Compile()));
            }


            foreach (var playe in w_server.OnlineConnections)
            {
                if (playe.Client == null || playe.Client.player == null)
                {
                    continue;
                }

                KeyValuePair <string, Player> play =
                    new KeyValuePair <string, Player>(playe.Client.player.Name, playe.Client.player);
                if (play.Value == null || play.Value.loggedIn == false)
                {
                    continue;
                }

                if ((play.Value.client.keepalive + 15000) < Server.tickcount.ElapsedMilliseconds)
                {
                    w_server.Disconnect(play.Value.client.connection);
                }

                if (play.Value.client.connection == null || play.Value.client.connection.Socket == null)
                {
                    w_server.Disconnect(play.Value.client.connection);
                }


                if (play.Value.Color == 0)
                {
                    if (play.Value.pklastpk.Count > 0)
                    {
                        play.Value.Color = 1;
                    }
                    else if (Server.tickcount.ElapsedMilliseconds > play.Value.pkPinkDelay &&
                             Server.tickcount.ElapsedMilliseconds - play.Value.pkpinkktime < play.Value.pkPinkDelay)
                    {
                        play.Value.Color = 2;
                    }
                }
                if (play.Value.Color == 2)
                {
                    if (Server.tickcount.ElapsedMilliseconds - play.Value.pkpinkktime > play.Value.pkPinkDelay)
                    {
                        play.Value.Color = 0;
                    }
                    if (play.Value.pklastpk.Count > 0)
                    {
                        play.Value.Color = 1;
                    }
                }

                if (play.Value.Color == 1)
                {
                    try
                    {
                        long[] pkslist = new long[play.Value.pklastpk.Count];
                        play.Value.pklastpk.CopyTo(pkslist);
                        if (Server.tickcount.ElapsedMilliseconds - play.Value.pklastred > play.Value.pkRedDelay)
                        {
                            play.Value.pklastred = Server.tickcount.ElapsedMilliseconds;
                            play.Value.pklastpk.RemoveAt(0);
                        }
                        if (play.Value.pklastpk.Count == 0)
                        {
                            play.Value.Color = 0;
                        }

                        /*     foreach (var pk in pkslist)
                         *   {
                         *       if (Server.tickcount.ElapsedMilliseconds - pk > play.Value.pkRedDelay)
                         *           play.Value.pklastpk.Remove(pk);
                         *   }*/
                    }
                    catch { }
                }

                if (play.Value.AutoMana && play.Value.MPCur < (play.Value.MP * play.Value.AutoManaP))
                {
                    var pot = NewItems.Where(xe => xe.Value.Parent != null && (xe.Value.Parent == play.Value || xe.Value.ParSer == play.Value.Serial) &&
                                             (xe.Value.Name == "Magic Drug" || xe.Value.Name == "Full Magic Drug")).FirstOrDefault();
                    if (pot.Value != null)
                    {
                        pot.Value.Use(play.Value);
                    }
                }
                if (play.Value.AutoHP && play.Value.HPCur < (play.Value.HP * play.Value.AutoHPP))
                {
                    var pot = NewItems.Where(xe => xe.Value.Parent != null && (xe.Value.Parent == play.Value || xe.Value.ParSer == play.Value.Serial) &&
                                             (xe.Value.Name == "Life Drug" || xe.Value.Name == "Full Life Drug")).FirstOrDefault();
                    if (pot.Value != null)
                    {
                        pot.Value.Use(play.Value);
                    }
                }

                if (play.Value.AutoHit && LKCamelot.Server.tickcount.ElapsedMilliseconds - play.Value.AttackSpeed > play.Value.autohittick &&
                    LKCamelot.Server.tickcount.ElapsedMilliseconds - play.Value.AttackSpeed > play.Value.client.LastAttack)
                {
                    play.Value.autohittick       = LKCamelot.Server.tickcount.ElapsedMilliseconds;
                    play.Value.client.LastAttack = LKCamelot.Server.tickcount.ElapsedMilliseconds;
                    World.SendToAll(new QueDele(play.Value.Map, new SwingAnimationChar(play.Value.Serial, play.Value.Face).Compile()));
                    play.Value.client.combatHandler.HandleMelee(play.Value, play.Value.Face);
                }

                if (LKCamelot.Server.tickcount.ElapsedMilliseconds - play.Value.RegenTick > play.Value.LastRegen)
                {
                    float regamt = 0.1f;
                    if (play.Value.Map == "Rest")
                    {
                        regamt = 0.25f;
                    }
                    play.Value.LastRegen = LKCamelot.Server.tickcount.ElapsedMilliseconds;
                    var playhp = play.Value;
                    playhp.HPCur += (int)((float)playhp.HP * regamt);
                    playhp.MPCur += (int)((float)playhp.MP * regamt);
                }

                /*      var Items = World.NewItems.Where(xe => xe.Value.m_Map != null
                 *     && xe.Value.m_Map == play.Value.Map)
                 *     .Select(xe => xe);
                 */



                /*       var LocalPlayers = handler.add.Where(xe => xe.Value != null && xe.Value.Map != null
                 *         && xe.Value.loggedIn && xe.Value.Map == play.Value.Map).Select(xe => xe);
                 *
                 *
                 *
                 *     foreach (var playee in LocalPlayers)
                 *     {
                 *         if (playee.Key == play.Key)
                 *             continue;
                 *
                 *         if (!play.Value.InstancedObjects.Contains(playee.Value.Serial))
                 *         {
                 *             play.Value.InstancedObjects.Add(playee.Value.Serial);
                 *             play.Value.client.SendPacket(new CreateChar(playee.Value, playee.Value.Serial).Compile());
                 *             play.Value.client.SendPacket(new SetObjectEffectsPlayer(playee.Value).Compile());
                 *         }
                 *     }*/

                //   System.Threading.Tasks.Parallel.ForEach(Monsters, mob => ProcMobs(play, mob));
            }
        }