Ejemplo n.º 1
0
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            try
            {
                Player playerLeft = Players.All[Context.ConnectionId];
                Console.WriteLine($"--> Player disconnected: {Context.ConnectionId}, Name: '{playerLeft.Name}', Table: '{playerLeft.TableName}'");
                if (!String.IsNullOrEmpty(playerLeft.TableName))
                {
                    TableController table = new TableController(GameTables.All[playerLeft.TableName], StateUpdated);
                    table.LeaveTable(playerLeft);
                    await Groups.RemoveFromGroupAsync(Context.ConnectionId, table.TableName);

                    if (table.TableEmpty)
                    {
                        GameTables.RemoveTable(table.TableName);
                    }
                }
                Players.RemovePlayerById(playerLeft.ConnID);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
            await base.OnDisconnectedAsync(exception);
        }
Ejemplo n.º 2
0
        public static void WriteCombatRatingTables()
        {
            Tools.StartRealm();
            GameTables.LoadGtDBCs();

            if (!GameTables.Loaded)
            {
                Console.WriteLine("GameTables are not loaded, aborting....");
                return;
            }

            Console.Write("Writing combat rating tables to " + DumpFile);

            var names = Enum.GetNames(typeof(CombatRating));

            using (var writer = new StreamWriter(DumpFile))
            {
                for (int i = 0; i < names.Length; i++)
                {
                    writer.WriteLine(names[i]);
                    WriteTable((CombatRating)i + 1, writer);
                }

                WriteTableByClass(GameTables.BaseMeleeCritChance, writer, "BaseMeleeCritChance");
                WriteTableByClass(GameTables.BaseSpellCritChance, writer, "BaseSpellCritChance");
                WriteTableByClassLevel(GameTables.GetUnModifiedClassMeleeCritChanceValue, writer, "ClassMeleeCritChance");
                WriteTableByClassLevel(GameTables.GetUnmodifiedClassSpellCritChanceValue, writer, "ClassSpellCritChance");
                WriteTableByClassLevel(GameTables.OCTRegenHP, writer, "OCTRegenHealth");
                WriteTableByClassLevel(GameTables.OCTRegenMP, writer, "OCTRegenMana");
                WriteTableByClassLevel(GameTables.RegenHPPerSpirit, writer, "RegenHealthPerSpirit");
                WriteTableByClassLevel(GameTables.RegenMPPerSpirit, writer, "RegenManaPerSpirit");
            }

            Console.Write("\nSuccess!");
        }
Ejemplo n.º 3
0
        // TODO: Check if we get the correct CR table
        internal static void UpdateCritChance(this Unit unit)
        {
            var chr = unit as Character;

            if (chr != null)
            {
                // Crit chance from crit rating
                var critChance = chr.GetCombatRating(CombatRating.MeleeCritChance) /
                                 GameTables.GetCRTable(CombatRating.MeleeCritChance)[chr.Level - 1];

                var rangedCritChance = chr.GetCombatRating(CombatRating.RangedCritChance) /
                                       GameTables.GetCRTable(CombatRating.RangedCritChance)[chr.Level - 1];

                // Crit chance from agility
                rangedCritChance += ((Character)unit).Archetype.Class.CalculateRangedCritChance(unit.Level, unit.Agility);
                rangedCritChance += unit.IntMods[(int)StatModifierInt.RangedCritChance];

                critChance += ((Character)unit).Archetype.Class.CalculateMeleeCritChance(unit.Level, unit.Agility);
                critChance += unit.GetCritMod(DamageSchool.Physical);

                chr.CritChanceMeleePct   = critChance;
                chr.CritChanceRangedPct  = rangedCritChance;
                chr.CritChanceOffHandPct = critChance;
            }
        }
Ejemplo n.º 4
0
        public ClientGameTable(Func <T, int> func)
        {
            gameTable = ClientDB.GameTables.SingleOrDefault(gt => gt.Name == typeof(T).Name.Substring(2));

            if (gameTable != null)
            {
                var tempData = DB.Data.Select(func).OrderBy(kp => kp.Key).ToDictionary(pair => pair.Key, pair => pair.Value);

                if (tempData.Count != gameTable.NumColumns * gameTable.NumRows)
                {
                    Log.Error($"Wrong data for {gameTable.Name}.");

                    return;
                }

                data = new Dictionary <int, Dictionary <int, T> >(gameTable.NumColumns);

                for (var i = 0; i < gameTable.NumColumns; i++)
                {
                    data[i] = tempData.Values.Take(gameTable.NumRows).ToDictionary(func);

                    tempData = tempData.Skip(gameTable.NumRows).ToDictionary(pair => pair.Key, pair => pair.Value);
                }
            }
            else
            {
                Log.Error($"No GameTables data for {typeof(T).Name}.");
            }
        }
Ejemplo n.º 5
0
        public StatusWindow()
        {
            InitializeComponent();

            try
            {
                var enumTables = GameTables.Load().EnumTables;
                if (enumTables != null)
                {
                    _turnStrings = enumTables["TurnPhase"];
                }
            }
            catch
            {
                _turnStrings = null;
            }

            Channel <TurnProgressChangedMessage> .Public.Subscribe(
                onNext : o => ProcessTurnPhaseChange(o.TurnPhase),
                threadOption : ChannelThreadOption.UIThread);

            //ClientEvents.TurnPhaseChanged.Subscribe(OnTurnPhaseChanged, ThreadOption.UIThread);
            ClientEvents.TurnStarted.Subscribe(OnTurnStarted, ThreadOption.UIThread);
            ClientEvents.AllTurnEnded.Subscribe(OnAllTurnEnded, ThreadOption.UIThread);
            ClientEvents.GameStarted.Subscribe(OnGameStarted, ThreadOption.UIThread);
            ClientEvents.GameEnded.Subscribe(OnGameEnded, ThreadOption.UIThread);
            ClientEvents.ClientDisconnected.Subscribe(OnClientDisconnected, ThreadOption.UIThread);
            ClientEvents.ViewActivating.Subscribe(OnViewActivating, ThreadOption.UIThread);
        }
Ejemplo n.º 6
0
 internal static void UpdateExpertise(this Unit unit)
 {
     if (unit is Character)
     {
         var chr       = unit as Character;
         var expertise = (uint)chr.IntMods[(int)StatModifierInt.Expertise];
         expertise    += (uint)(chr.GetCombatRating(CombatRating.Expertise) / GameTables.GetCRTable(CombatRating.Expertise)[chr.Level - 1]);
         chr.Expertise = expertise;
     }
 }
Ejemplo n.º 7
0
        public static void InitializeWorld()
        {
            if (s_MapTemplates[(uint)MapId.Kalimdor] == null)
            {
                LoadMapData();
                LoadZoneInfos();
                GameTables.LoadGtDBCs();
                LoadChatChannelsDBC();

                TerrainMgr.InitTerrain();
                _taskQueue.IsRunning = true;                            // start global task queue
            }
        }
Ejemplo n.º 8
0
        internal static void UpdateExpertise(this Unit unit)
        {
            if (!(unit is Character))
            {
                return;
            }
            Character character = unit as Character;
            uint      num       = (uint)character.IntMods[23] +
                                  (uint)((double)character.GetCombatRating(CombatRating.Expertise) /
                                         (double)GameTables.GetCRTable(CombatRating.Expertise)[character.Level - 1]);

            character.Expertise = num;
        }
Ejemplo n.º 9
0
        internal static void UpdateSpellCritChance(this Character chr)
        {
            chr.UpdateCritChance();
            for (var school = DamageSchool.Physical + 1; school < DamageSchool.Count; school++)
            {
                var chance = chr.GetCombatRating(CombatRating.SpellCritChance) /
                             GameTables.GetCRTable(CombatRating.SpellCritChance)[chr.Level - 1];
                chance += chr.Archetype.Class.CalculateMagicCritChance(chr.Level, chr.Intellect);
                chance += chr.GetCritMod(school);

                chr.SetCritChance(school, chance);
            }
        }
Ejemplo n.º 10
0
        internal static void UpdateRangedHitChance(this Unit unit)
        {
            float hitChance;

            hitChance = unit.IntMods[(int)StatModifierInt.HitChance];
            if (unit is Character)
            {
                var chr = unit as Character;

                hitChance += chr.GetCombatRating(CombatRating.RangedHitChance) /
                             GameTables.GetCRTable(CombatRating.RangedHitChance)[chr.Level - 1];
                chr.HitChance = hitChance;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Increases the defense skill according to your defense rating
        /// Updates Dodge and Parry chances
        /// </summary>
        /// <param name="unit"></param>
        internal static void UpdateDefense(this Unit unit)
        {
            var chr = unit as Character;

            if (chr != null)
            {
                var defense = chr.GetCombatRating(CombatRating.DefenseSkill) /
                              GameTables.GetCRTable(CombatRating.DefenseSkill)[chr.Level - 1];

                //chr.Defense = chr.Skills[SkillId.Defense].ActualValue + defense;
                chr.Defense = (uint)defense;
                UpdateDodgeChance(unit);
                UpdateParryChance(unit);
            }
        }
Ejemplo n.º 12
0
        internal static void UpdateDodgeChance(this Unit unit)
        {
            var chr = unit as Character;

            if (chr != null)
            {
                float dodgeChance = 0;
                if (chr.Agility == 0)
                {
                    return;                     // too early
                }
                dodgeChance += (chr.GetCombatRating(CombatRating.Dodge) / GameTables.GetCRTable(CombatRating.Dodge)[chr.Level - 1]);
                dodgeChance += ((Character)unit).Archetype.Class.CalculateDodge(unit.Level, unit.Agility,
                                                                                unit.BaseStats[(int)StatType.Agility],
                                                                                (int)chr.Skills.GetValue(SkillId.Defense),
                                                                                chr.GetCombatRating(CombatRating.Dodge),
                                                                                chr.GetCombatRating(CombatRating.DefenseSkill)
                                                                                );
                dodgeChance    += unit.IntMods[(int)StatModifierInt.DodgeChance];
                chr.DodgeChance = dodgeChance;
            }
        }
Ejemplo n.º 13
0
        internal static void UpdateBlockChance(this Unit unit)
        {
            var chr = unit as Character;

            if (chr == null)
            {
                return;
            }

            var inv = chr.Inventory;

            if (inv == null)
            {
                // called too early
                return;
            }

            var shield      = inv[InventorySlot.OffHand];
            var blockValue  = 0;
            var blockChance = 0f;

            if (shield != null && shield.Template.InventorySlotType == InventorySlotType.Shield)
            {
                blockChance = chr.IntMods[(int)StatModifierInt.BlockChance];

                blockValue = 5 + (int)shield.Template.BlockValue + (int)blockChance;

                // + block from block rating
                blockChance += chr.GetCombatRating(CombatRating.Block) / GameTables.GetCRTable(CombatRating.Block)[chr.Level - 1];
            }

            blockValue += chr.Strength / 2 - 10;
            blockValue  = GetMultiMod(chr.FloatMods[(int)StatModifierFloat.BlockValue], blockValue);

            chr.BlockValue  = (uint)blockValue;
            chr.BlockChance = blockChance;
        }
Ejemplo n.º 14
0
        private static void WriteTable(CombatRating rating, StreamWriter writer)
        {
            var table = GameTables.GetCRTable(rating);

            WriteTable(table, writer);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Calculates the amount of power regeneration for the class at a specific level, Intellect and Spirit.
        /// Changed in 3.1, overrides for casters are redundant.
        /// </summary>
        public static int CalculateManaRegen(Unit unit)
        {
            // default mana generation
            // see: http://www.wowwiki.com/Mana_regeneration
            var regen = (int)((0.001f + unit.Spirit * (float)Math.Sqrt(unit.Intellect) * GameTables.GetBaseRegenForLevel(unit.Level)) * 0.6f + 0.9f);              // rounded up

            return(regen * RegenRateFactor);
        }
Ejemplo n.º 16
0
        public async Task JoinTable(int tableType, string privateTableId)
        {
            try
            {
                if (Context.Items.ContainsKey("Lang"))
                {
                    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture((string)Context.Items["Lang"]);
                }

                Player playerJoined = Players.All[Context.ConnectionId];

                TableController table = null;
                if (string.IsNullOrEmpty(privateTableId))
                {
                    bool tableJoined  = false;
                    int  joinAttempts = 0;
                    while (!tableJoined && joinAttempts < 10)
                    {
                        joinAttempts++;
                        try
                        {
                            table = new TableController(GameTables.GetFreeTable(tableType, playerJoined.WatchOnly), StateUpdated);
                            table.JoinTable(playerJoined); // Add player to table
                            tableJoined = true;
                        }
                        catch
                        {
                            tableJoined = false;
                        }
                    }
                    if (!tableJoined)
                    {
                        throw new Exception("Could not find a free table to join.");
                    }
                }
                else
                {
                    privateTableId = $"{tableType}-{privateTableId}";

                    if (GameTables.All.ContainsKey(privateTableId)) // Private table by name already exists
                    {
                        table = new TableController(GameTables.All[privateTableId], StateUpdated);
                        table.JoinTable(playerJoined); // Add player to table
                    }
                    else // Let us add a new private table
                    {
                        table = new TableController(GameTables.AddTable(tableType, privateTableId), StateUpdated);
                        table.JoinTable(playerJoined); // Add player to table
                    }
                }

                // add new player to table group
                await Groups.AddToGroupAsync(Context.ConnectionId, table.TableName);

                // If table is full send ready to start event
                if (table.TableFull && table.Game.Stage == GameStage.WaitingForPlayers)
                {
                    table.StartNextGame(new Random().Next(table.T.MaxPlayers)); // Deal cards and initialize bidding
                }
            }
            catch (System.Exception e)
            {
                await Clients.Caller.OnError((e is Card56Exception)?((Card56Exception)e).ErrorData.ErrorCode : 0,
                                             Cards56HubMethod.JoinTable,
                                             e.Message,
                                             (e is Card56Exception)?((Card56Exception)e).ErrorData : null);
            }
        }