Esempio n. 1
0
        public string JoinDuel(string connectionId, string duelId)
        {
            var player = PlayerService.Get(connectionId);

            if (player == null)
            {
                return(NoSuchPlayer);
            }
            var duel = DuelService.Get(duelId);

            if (duel == null)
            {
                return(NoSuchDuel);
            }
            lock (duel.LockObject)
            {
                if (duel.Status != DuelStatus.WaitingForPlayers)
                {
                    return(DuelHasAlreadyStartedError);
                }

                duel.AddPlayer(player);
                PrepareDuel(duel);

                return(null);
            }
        }
Esempio n. 2
0
 public Game()
 {
     Random        = new Random();
     PlayerService = new PlayerService();
     DuelService   = new DuelService(Random);
     BotService    = new BotService(Random);
 }
Esempio n. 3
0
        public void RetryDuel(string connectionId, string duelId)
        {
            Player player    = PlayerService.Get(connectionId);
            Duel   retryDuel = DuelService.GetRetryDuel(duelId);

            retryDuel.AddPlayer(player);
            if (retryDuel.HasEnoughPlayersToStart)
            {
                PrepareDuel(retryDuel);
            }
        }
Esempio n. 4
0
        public static void PlayerEnterWorld(Player player)
        {
            MapService.PlayerEnterWorld(player);
            PlayerService.PlayerEnterWorld(player);
            ControllerService.PlayerEnterWorld(player);
            FeedbackService.OnPlayerEnterWorld(player.Connection, player);

            PartyService.UpdateParty(player.Party);
            GuildService.OnPlayerEnterWorld(player);

            DuelService.PlayerLeaveWorld(player);
        }
Esempio n. 5
0
        public static void PlayerEndGame(Player player)
        {
            if (player == null)
            {
                return;
            }

            PlayerService.PlayerEndGame(player);
            MapService.PlayerLeaveWorld(player);
            ControllerService.PlayerEndGame(player);

            PartyService.UpdateParty(player.Party);

            DuelService.PlayerLeaveWorld(player);
        }
Esempio n. 6
0
        protected void TryCreateDuel(Player player, Player opponent)
        {
            player.StopWaitingPartner();
            player.PartnerWaitTimerElapsed -= OnWaitPartnerTimerElapsed;
            opponent.StopWaitingPartner();
            opponent.PartnerWaitTimerElapsed -= OnWaitPartnerTimerElapsed;

            var duel = new Duel(Random, new List <Player> {
                player, opponent
            });

            DuelService.Add(duel);

            PrepareDuel(duel);
        }
Esempio n. 7
0
 public MainController(
     UserService userService,
     DuelService duelService,
     ContentService contentService,
     ISocialService socialService,
     ConcurrencyService concurrencyService,
     ILogger <MainController> logger
     )
 {
     _userService        = userService;
     _duelService        = duelService;
     _contentService     = contentService;
     _socialService      = socialService;
     _concurrencyService = concurrencyService;
     _logger             = logger;
 }
Esempio n. 8
0
        public Duel CreateDuel(string connectionId)
        {
            var player = PlayerService.Get(connectionId);

            if (player == null)
            {
                return(null);
            }
            var duel = new Duel(Random, new List <Player> {
                player
            });

            DuelService.Add(duel);

            return(duel);
        }
Esempio n. 9
0
        private void TryWinDuel(Duel duel, Player player)
        {
            lock (duel.LockObject)
            {
                if (duel.IsGameOver)
                {
                    return;
                }

                DuelService.FinishAndRemove(duel);
                Player opponent = duel.GetOpponent(player.ConnectionId);

                GameOver(opponent, false);
                GameOver(player, true);
            }
        }
Esempio n. 10
0
        public void RemovePlayer(string connectionId)
        {
            var player = PlayerService.Get(connectionId);

            if (player == null)
            {
                return;
            }
            PlayerService.Remove(player);
            Duel duel;

            if ((duel = DuelService.GetDuelForPlayer(player.ConnectionId)) != null)
            {
                var duelPlayer = duel.Players.First(i => i.Player == player);
                duelPlayer.Disconnected = true;

                if (duel.Players.All(i => i.Disconnected))
                {
                    DuelService.FinishAndRemove(duel);
                }
            }
        }
Esempio n. 11
0
        public void ReadyToPlay(string connectionId)
        {
            var player = PlayerService.Get(connectionId);

            if (player == null)
            {
                return;
            }
            var duel = DuelService.GetDuelForPlayer(player.ConnectionId);

            if (duel == null)
            {
                return;
            }
            player.Status = PlayerStatus.ReadyToPlay;
            var opponents = duel.GetOpponents(player.ConnectionId).ToList();
            var allready  = opponents.Any() && opponents.All(t => t.Status == PlayerStatus.ReadyToPlay);

            if (allready)
            {
                StartDuel(duel);
            }
        }
Esempio n. 12
0
        public void RecordStep(string connectionId, Step step)
        {
            Player player = PlayerService.Get(connectionId);

            if (player == null)
            {
                return;
            }
            Duel duel = DuelService.GetDuelForPlayer(player.ConnectionId);

            if (duel == null || duel.IsGameOver)
            {
                return;
            }

            Player opponent = duel.GetOpponent(player.ConnectionId);

            GetContext().Clients.Client(opponent.ConnectionId).receiveStep(step);

            if (duel.IsGameOverStep(step))
            {
                TryWinDuel(duel, player);
            }
        }
Esempio n. 13
0
        private static void RunServer()
        {
            Data.Data.DataPath = "data/";

            Stopwatch sw = Stopwatch.StartNew();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Console.WriteLine("----===== Tera-Project C# GameServer Emulator =====----\n\n");
            Console.WriteLine("Starting Game Server!\n"
                              + "-------------------------------------------");

            TcpServer = new TcpServer("*", Config.GetServerPort(), Config.GetServerMaxCon());
            Connection.SendAllThread.Start();

            OpCodes.Init();
            Console.WriteLine("OpCodes - Revision 1725 initialized!\n"
                              + "-------------------------------------------\n");

            #region global_components

            //services
            FeedbackService    = new FeedbackService();
            AccountService     = new AccountService();
            PlayerService      = new PlayerService();
            MapService         = new MapService();
            ChatService        = new ChatService();
            VisibleService     = new VisibleService();
            ControllerService  = new ControllerService();
            CraftService       = new CraftService();
            ItemService        = new ItemService();
            AiService          = new AiService();
            GeoService         = new GeoService();
            StatsService       = new StatsService();
            ObserverService    = new ObserverService();
            AreaService        = new AreaService();
            InformerService    = new InformerService();
            TeleportService    = new TeleportService();
            PartyService       = new PartyService();
            SkillsLearnService = new SkillsLearnService();
            CraftLearnService  = new CraftLearnService();
            GuildService       = new GuildService();
            EmotionService     = new EmotionService();
            RelationService    = new RelationService();
            DuelService        = new DuelService();
            StorageService     = new StorageService();
            TradeService       = new TradeService();
            MountService       = new MountService();

            //engines
            ActionEngine = new ActionEngine.ActionEngine();
            AdminEngine  = new AdminEngine.AdminEngine();
            SkillEngine  = new SkillEngine.SkillEngine();
            QuestEngine  = new QuestEngine.QuestEngine();

            #endregion

            GlobalLogic.ServerStart("SERVER=" + Config.GetDatabaseHost() + ";DATABASE=" + Config.GetDatabaseName() + ";UID=" + Config.GetDatabaseUser() + ";PASSWORD="******";PORT=" + Config.GetDatabasePort() + ";charset=utf8");

            Console.WriteLine("-------------------------------------------\n"
                              + "Loading Tcp Service.\n"
                              + "-------------------------------------------");
            TcpServer.BeginListening();

            try
            {
                ServiceApplication = ScsServiceBuilder.CreateService(new ScsTcpEndPoint(23232));
                ServiceApplication.AddService <IInformerService, InformerService>((InformerService)InformerService);
                ServiceApplication.Start();
                Log.Info("InformerService started at *:23232.");

                var webservices = new ServiceManager();
                webservices.Run();
            }
            catch (Exception ex)
            {
                Log.ErrorException("InformerService can not be started.", ex);
            }

            sw.Stop();
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("           Server start in {0}", (sw.ElapsedMilliseconds / 1000.0).ToString("0.00s"));
            Console.WriteLine("-------------------------------------------");
        }
Esempio n. 14
0
        private async void ProcessArea(Creature creature, Skill skill, Targeting targeting, TargetingArea area,
                                       Projectile projectile = null)
        {
            try
            {
                bool isProjectileSkill = skill.Type == SkillType.Projectile || skill.Type == SkillType.Userslug;

                int skillId = creature.Attack.Args.SkillId;
                if (isProjectileSkill)
                {
                    skillId += 20;
                }

                if (targeting.Time > 0)
                {
                    await Task.Delay((int)(targeting.Time / skill.TimeRate));
                }
                int elapsed = targeting.Time;

                Player player = creature as Player;

                do
                {
                    try
                    {
                        if (creature.LifeStats.IsDead())
                        {
                            return;
                        }

                        if (area.DropItem != null)
                        {
                            creature.Instance.AddDrop(new Item
                            {
                                Owner = player,

                                ItemId   = (int)area.DropItem,
                                Count    = 1,
                                Position = Geom.ForwardPosition(creature.Position, 40),
                                Instance = player.Instance,
                            });
                        }

                        Point3D center =
                            projectile != null
                                ? projectile.Position.ToPoint3D()
                                : Geom.GetNormal(creature.Position.Heading)
                            .Multiple(area.OffsetDistance)
                            .Add(creature.Position);

                        int count = 0;

                        List <Creature> targets =
                            creature.Attack.Args.Targets.Count > 0
                                ? creature.Attack.Args.Targets
                                : VisibleService.FindTargets(creature,
                                                             center,
                                                             projectile != null
                                                                 ? projectile.AttackDistance
                                                                 : area.MaxRadius,
                                                             area.Type);

                        foreach (Creature target in targets)
                        {
                            if (target != creature && //Ignore checks for self-target
                                !isProjectileSkill &&
                                !creature.Attack.Args.IsItemSkill)
                            {
                                if (center.DistanceTo(target.Position) < area.MinRadius - 40)
                                {
                                    continue;
                                }

                                if (center.DistanceTo(target.Position) > area.MaxRadius)
                                {
                                    continue;
                                }

                                short diff = Geom.GetAngleDiff(creature.Attack.Args.StartPosition.Heading,
                                                               Geom.GetHeading(center, target.Position));

                                //diff from 0 to 180
                                //area.RangeAngel from 0 to 360
                                if (diff * 2 > (creature.Attack.Args.IsTargetAttack ? 90 : Math.Abs(area.RangeAngle) + 10))
                                {
                                    continue;
                                }
                            }

                            if (skill.TotalAtk > 0)
                            {
                                int damage = SeUtils.CalculateDamage(creature, target, skill.TotalAtk * area.Effect.Atk);

                                AttackResult result
                                    = new AttackResult
                                    {
                                    AttackType = AttackType.Normal,
                                    AttackUid  = creature.Attack.UID,
                                    Damage     = damage,
                                    Target     = target,
                                    };

                                result.AngleDif = Geom.GetAngleDiff(creature.Attack.Args.StartPosition.Heading, result.Target.Position.Heading);
                                SeUtils.UpdateAttackResult(creature, result);

                                if (result.AttackType == AttackType.Block)
                                {
                                    VisibleService.Send(target, new SpAttackShowBlock(target, skillId));
                                }

                                VisibleService.Send(target, new SpAttackResult(creature, skillId, result));

                                AiLogic.OnAttack(creature, target);
                                AiLogic.OnAttacked(target, creature, result.Damage);

                                if (target is Player && ((Player)target).Duel != null && player != null &&
                                    ((Player)target).Duel.Equals(player.Duel) &&
                                    target.LifeStats.GetHpDiffResult(damage) < 1)
                                {
                                    DuelService.FinishDuel(player);
                                }
                                else
                                {
                                    CreatureLogic.HpChanged(target, target.LifeStats.MinusHp(result.Damage));
                                }
                            }

                            if (area.Effect.HpDiff > 0)
                            {
                                AttackResult result = new AttackResult {
                                    HpDiff = area.Effect.HpDiff, Target = target
                                };

                                PassivityProcessor.OnHeal(player, result);
                                if (target is Player)
                                {
                                    PassivityProcessor.OnHealed((Player)target, result);
                                }

                                CreatureLogic.HpChanged(target, target.LifeStats.PlusHp(result.HpDiff),
                                                        creature);
                            }

                            if (area.Effect.MpDiff > 0)
                            {
                                CreatureLogic.MpChanged(target, target.LifeStats.PlusMp(area.Effect.MpDiff), creature);
                            }

                            if (area.Effect.AbnormalityOnCommon != null)
                            {
                                for (int i = 0; i < area.Effect.AbnormalityOnCommon.Count; i++)
                                {
                                    AbnormalityProcessor.AddAbnormality(target, area.Effect.AbnormalityOnCommon[i],
                                                                        creature);
                                }
                            }
                            if (player != null)
                            {
                                DuelService.ProcessDamage(player);

                                //MP regen on combo skill
                                if (skill.Id / 10000 == 1 && player.GameStats.CombatMpRegen > 0)
                                {
                                    CreatureLogic.MpChanged(player, player.LifeStats.PlusMp(
                                                                player.MaxMp * player.GameStats.CombatMpRegen / 200));
                                }
                            }

                            if (++count == area.MaxCount)
                            {
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteLine(LogState.Exception, "SkillEngine: ProcessAreaExc: " + ex);
                    }

                    if (targeting.Interval > 0)
                    {
                        await Task.Delay((int)(targeting.Interval / skill.TimeRate));

                        elapsed += targeting.Interval;
                    }
                } while (targeting.Interval > 0 && elapsed < targeting.Until);
            }
            catch (Exception ex)
            {
                Logger.WriteLine(LogState.Exception, "SkillEngine: ProcessArea: " + ex);
            }
        }
Esempio n. 15
0
        private static void RunServer()
        {
            //Start ServerStartTime
            Stopwatch serverStartStopwatch = Stopwatch.StartNew();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            //CheckServerMode
            CheckServerMode();

            //ConsoleOutput-Infos
            PrintServerLicence();
            PrintServerInfo();

            //Initialize TcpServer
            TcpServer = new TcpServer("*", Configuration.Network.GetServerPort(), Configuration.Network.GetServerMaxCon());
            Connection.SendAllThread.Start();

            //Initialize Server OpCodes
            OpCodes.Init();
            Console.WriteLine("----------------------------------------------------------------------------\n"
                              + "---===== OpCodes - Revision: " + OpCodes.Version + " EU initialized!");

            //Global Services
            #region global_components
            //Services
            FeedbackService    = new FeedbackService();
            AccountService     = new AccountService();
            PlayerService      = new PlayerService();
            MapService         = new MapService();
            ChatService        = new ChatService();
            VisibleService     = new VisibleService();
            ControllerService  = new ControllerService();
            CraftService       = new CraftService();
            ItemService        = new ItemService();
            AiService          = new AiService();
            GeoService         = new GeoService();
            StatsService       = new StatsService();
            ObserverService    = new ObserverService();
            AreaService        = new AreaService();
            TeleportService    = new TeleportService();
            PartyService       = new PartyService();
            SkillsLearnService = new SkillsLearnService();
            CraftLearnService  = new CraftLearnService();
            GuildService       = new GuildService();
            EmotionService     = new EmotionService();
            RelationService    = new RelationService();
            DuelService        = new DuelService();
            StorageService     = new StorageService();
            TradeService       = new TradeService();
            MountService       = new MountService();

            //Engines
            ActionEngine = new ActionEngine.ActionEngine();
            AdminEngine  = new AdminEngine.AdminEngine();
            SkillEngine  = new SkillEngine.SkillEngine();
            QuestEngine  = new QuestEngine.QuestEngine();
            #endregion

            //Set SqlDatabase Connection
            GlobalLogic.ServerStart("SERVER=" + DAOManager.MySql_Host + ";DATABASE=" + DAOManager.MySql_Database + ";UID=" + DAOManager.MySql_User + ";PASSWORD="******";PORT=" + DAOManager.MySql_Port + ";charset=utf8");
            Console.ForegroundColor = ConsoleColor.Gray;

            //Start Tcp-Server Listening
            Console.WriteLine("----------------------------------------------------------------------------\n"
                              + "---===== Loading GameServer Service.\n"
                              + "----------------------------------------------------------------------------");
            TcpServer.BeginListening();

            //Stop ServerStartTime
            serverStartStopwatch.Stop();
            Console.WriteLine("----------------------------------------------------------------------------");
            Console.WriteLine("---===== GameServer start in {0}", (serverStartStopwatch.ElapsedMilliseconds / 1000.0).ToString("0.00s"));
            Console.WriteLine("----------------------------------------------------------------------------");
        }
Esempio n. 16
0
        private static void RunServer()
        {
            Data.Data.DataPath = "data/";

            Stopwatch sw = Stopwatch.StartNew();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Console.WriteLine("----===== GameServer =====----\n\n"
                              + "Starting game server\n\n"
                              + "Loading data files.\n"
                              + "-------------------------------------------");

            TcpServer = new TcpServer("*", 11101, 1000);
            Connection.SendAllThread.Start();

            OpCodes.Init();

            #region global_components

            //services
            FeedbackService    = new FeedbackService();
            AccountService     = new AccountService();
            PlayerService      = new PlayerService();
            MapService         = new MapService();
            ChatService        = new ChatService();
            VisibleService     = new VisibleService();
            ControllerService  = new ControllerService();
            CraftService       = new CraftService();
            ItemService        = new ItemService();
            AiService          = new AiService();
            GeoService         = new GeoService();
            StatsService       = new StatsService();
            ObserverService    = new ObserverService();
            AreaService        = new AreaService();
            InformerService    = new InformerService();
            TeleportService    = new TeleportService();
            PartyService       = new PartyService();
            SkillsLearnService = new SkillsLearnService();
            CraftLearnService  = new CraftLearnService();
            GuildService       = new GuildService();
            EmotionService     = new EmotionService();
            RelationService    = new RelationService();
            DuelService        = new DuelService();
            StorageService     = new StorageService();
            TradeService       = new TradeService();
            MountService       = new MountService();

            //engines
            ActionEngine = new ActionEngine.ActionEngine();
            AdminEngine  = new AdminEngine.AdminEngine();
            SkillEngine  = new SkillEngine.SkillEngine();
            QuestEngine  = new QuestEngine.QuestEngine();

            #endregion

            GlobalLogic.ServerStart();

            TcpServer.BeginListening();

            try
            {
                ServiceApplication = ScsServiceBuilder.CreateService(new ScsTcpEndPoint(23232));
                ServiceApplication.AddService <IInformerService, InformerService>((InformerService)InformerService);
                ServiceApplication.Start();
                Log.Info("InformerService started at *:23232.");
            }
            catch (Exception ex)
            {
                Log.ErrorException("InformerService can not be started.", ex);
            }

            sw.Stop();
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("           Server start in {0}", (sw.ElapsedMilliseconds / 1000.0).ToString("0.00s"));
            Console.WriteLine("-------------------------------------------");
        }