Example #1
0
        public static Asda2GuildWave CreateGuildWave(int guildId, int difficulty, Character chr)
        {
            Asda2GuildWave guildWave = new Asda2GuildWave(guildId, difficulty, chr.Guild);

            guildWave.AddRegisteringPlayer(chr);
            guildWaves.TryAdd(guildId, guildWave);
            Asda2GuildWaveHandler.GuildWaveEnterStatusToGuild(chr.Guild, GuildWaveEnterStatus.Register);
            return(guildWave);
        }
Example #2
0
        public void UpdateGuildWave(int dt)
        {
            if (terminating)
            {
                return;
            }

            timeToRegistrationPreparationFinish -= dt;

            if (timeToRegistrationPreparationFinish <= 0)
            {
                if (!_registered)
                {
                    if (PlayersRegisteredCount < 1)
                    {
                        Asda2GuildWaveHandler.GuildWaveEnterStatusToGuild(_guild, GuildWaveEnterStatus.Fail);
                        _fail = true;
                        lock (_playersRegisteredLock)
                        {
                            playersRegistered.Clear();
                            _map.Stop();
                        }
                    }
                    else
                    {
                        Asda2GuildWaveHandler.GuildWaveEnterStatusToGuild(_guild, GuildWaveEnterStatus.Ok);
                        _registered = true;
                        timeToRegistrationPreparationFinish = Asda2GuildWaveMgr.defaultRegistrationPreparationTime;
                    }
                }
                else
                {
                    if (!_inProgress)
                    {
                        timeToFight   = waveTimers[currentWaveNumber];
                        timeToPrepare = 0;
                        preparation   = false;

                        ClearPlayersRegisteredList();

                        /*if (PlayersRegisteredCount < Asda2GuildWaveMgr.NeedPlayerToStartGW)
                         * {
                         *  Asda2GuildWaveHandler.GuildWaveEnterStatusToGuild(_guild, GuildWaveEnterStatus.Fail);
                         *  lock (_playersRegisteredLock)
                         *  {
                         *      foreach (Character chr in playersRegistered.ToList())
                         *      {
                         *          ExitGuildWave(chr);
                         *      }
                         *      _map.Stop();
                         *      _fail = true;
                         *      terminating = true;
                         *      return;
                         *  }
                         * }*/


                        Asda2GuildWaveHandler.GuildWaveEnterStatusToGuild(_guild, GuildWaveEnterStatus.AlreadyStarted);
                        Asda2GuildWaveHandler.GuildWaveUpdate(this, GuildWaveUpdateStatus.Start, currentWaveNumber, timeToFight);

                        PrepareNpcEntriesList();
                        SpawnNpcsForCurrentWave(0);
                        timeToSpawnNpcs = defaultTimeToSpawnNpcs;

                        _inProgress = true;
                    }
                }
            }

            if (!_inProgress)
            {
                return;
            }

            lock (_playersRegisteredLock)
            {
                for (int i = 0; i < playersRegistered.Count; ++i)
                {
                    Character chr = playersRegistered[i];

                    if (World.GetCharacter(chr.Name, false) == null)
                    {
                        playersRegistered.RemoveAt(i--);
                    }
                }

                if (playersRegistered.Count <= 0)
                {
                    Guild.WaveLimit = (Guild.WaveLimit + 1);
                    currentWaveNpcs.Clear();

                    _map.CallOnAllNPCs((NPC npc) =>
                    {
                        npc.Kill();
                    });

                    _map.Stop();

                    _finished   = true;
                    terminating = true;
                    return;
                }
            }

            if (!preparation)
            {
                timeToFight -= dt;

                if (timeToFight <= 0)
                {
                    currentWaveNpcs.Clear();

                    ClearPlayersRegisteredList();

                    lock (_playersRegisteredLock)
                    {
                        foreach (Character chr in playersRegistered)
                        {
                            GuildWaveResultAndItems(chr);
                        }
                    }

                    _map.CallOnAllNPCs((NPC npc) =>
                    {
                        npc.Kill();
                    });
                    Guild.WaveLimit = (Guild.WaveLimit + 1);
                    _map.CallDelayed(60 * 1000, () =>
                    {
                        lock (_playersRegisteredLock)
                        {
                            while (playersRegistered.Count > 0)
                            {
                                RemoveEnteredPlayer(playersRegistered[0]);
                            }
                            Asda2GuildWaveHandler.GuildWaveEnterStatusToGuild(Guild, GuildWaveEnterStatus.Ended);
                            _map.Stop();
                            _finished = true;
                        }
                    });


                    terminating = true;
                    return;
                }
                else
                {
                    timeToSpawnNpcs -= dt;

                    if (timeToSpawnNpcs <= 0 && npcTemplate.Count > 0)
                    {
                        SpawnNpcsForCurrentWave(1);
                    }

                    int deadNpcsCount = 0;

                    foreach (NPC npc in currentWaveNpcs)
                    {
                        if (npc.Health <= 0)
                        {
                            deadNpcsCount++;
                        }
                    }

                    if (deadNpcsCount == (npcsCount1 + npcsCount2))
                    {
                        if (currentWaveNumber < 20)
                        {
                            timeToPrepare = defaultTimeToPrepare;
                        }
                        else
                        {
                            timeToPrepare = defaultTimeToPrepareAfter20;
                        }

                        preparation = true;

                        Asda2GuildWaveHandler.GuildWaveUpdate(this, GuildWaveUpdateStatus.Finish, currentWaveNumber + 1, timeToPrepare);

                        currentWaveNpcs.Clear();

                        if (currentWaveNumber == 29)
                        {
                            Guild.WaveLimit = (Guild.WaveLimit + 1);

                            //currentWaveNpcs.Clear();

                            ClearPlayersRegisteredList();

                            lock (_playersRegisteredLock)
                            {
                                foreach (Character chr in playersRegistered)
                                {
                                    GuildWaveResultAndItems(chr);
                                }
                            }

                            //Asda2GuildWaveHandler.GuildWaveEnterStatusToGuild(_guild, GuildWaveEnterStatus.Ended);

                            _map.CallDelayed(60 * 1000, () =>
                            {
                                lock (_playersRegisteredLock)
                                {
                                    while (playersRegistered.Count > 0)
                                    {
                                        RemoveEnteredPlayer(playersRegistered[0]);
                                    }

                                    _finished = true;
                                }

                                _map.CallDelayed(60 * 1000, () =>
                                {
                                    _map.Stop();
                                });
                            });
                            Asda2GuildWaveHandler.GuildWaveEnterStatusToGuild(_guild, GuildWaveEnterStatus.Ended);
                            terminating = true;

                            return;
                        }
                    }
                }
            }
            else
            {
                timeToPrepare -= dt;

                if (timeToPrepare <= 0)
                {
                    _map.ClearLootOnGuildWaveNow(GuildId);

                    ++currentWaveNumber;

                    timeToFight   = waveTimers[currentWaveNumber];
                    timeToPrepare = 0;
                    preparation   = false;

                    Asda2GuildWaveHandler.GuildWaveUpdate(this, GuildWaveUpdateStatus.Start, currentWaveNumber, timeToFight);

                    PrepareNpcEntriesList();
                    SpawnNpcsForCurrentWave(0);
                    timeToSpawnNpcs = defaultTimeToSpawnNpcs;
                }
            }
        }