Ejemplo n.º 1
0
        public override void Handle(Session Session)
        {
            GameState state = FFRKProxy.Instance.GameState;
            // Win or lose, finishing a battle means it's safe to record that encounter and its drops
            // since it won't be possible for the user to have the same drop set if they continue.
            if (state.ActiveBattle != null)
            {
                EventBattleInitiated original_battle = state.ActiveBattle;
                state.ActiveBattle = null;

                lock (FFRKProxy.Instance.Cache.SyncRoot)
                {
                    DataCache.Battles.Key key = new DataCache.Battles.Key { BattleId = original_battle.Battle.BattleId };
                    DataCache.Battles.Data data = null;
                    if (FFRKProxy.Instance.Cache.Battles.TryGetValue(key, out data))
                    {
                        data.Samples++;
                        data.HistoSamples++;
                    }
                }

                DbOpRecordBattleEncounter op = new DbOpRecordBattleEncounter(original_battle);
                FFRKProxy.Instance.Database.BeginExecuteRequest(op);
                FFRKProxy.Instance.RaiseBattleComplete(original_battle);
            }
        }
Ejemplo n.º 2
0
        public void Execute(MySqlConnection connection, MySqlTransaction transaction)
        {
            string stmt = "SELECT * FROM battles ORDER BY dungeon ASC, id ASC";

            using (MySqlCommand command = new MySqlCommand(stmt, connection, transaction))
            {
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    uint   current_dungeon           = 0;
                    ushort current_stam_to_reach     = 0;
                    DataCache.Battles.Data last_data = null;
                    while (reader.Read())
                    {
                        DataCache.Battles.Key  key  = new DataCache.Battles.Key();
                        DataCache.Battles.Data data = new DataCache.Battles.Data();

                        key.BattleId      = (uint)reader["id"];
                        data.DungeonId    = (uint)reader["dungeon"];
                        data.Name         = (string)reader["name"];
                        data.Stamina      = (ushort)reader["stamina"];
                        data.Samples      = (uint)reader["samples"];
                        data.HistoSamples = (uint)reader["histo_samples"];
                        data.Repeatable   = true;

                        if (current_dungeon != data.DungeonId)
                        {
                            // We just went to a new dungeon.  Stamina to reach is 0.
                            current_stam_to_reach = 0;

                            // The previous battle is not repeatable.
                            if (last_data != null)
                            {
                                last_data.Repeatable = false;
                            }
                        }
                        else
                        {
                            current_stam_to_reach += data.Stamina;
                        }

                        data.StaminaToReach = current_stam_to_reach;
                        mBattles.Update(key, data);

                        current_dungeon = data.DungeonId;
                        last_data       = data;
                    }
                    last_data.Repeatable = false;
                }
            }
        }
Ejemplo n.º 3
0
        public void Execute(MySqlConnection connection, MySqlTransaction transaction)
        {
            string stmt = "SELECT * FROM battles ORDER BY dungeon ASC, id ASC";
            using (MySqlCommand command = new MySqlCommand(stmt, connection, transaction))
            {
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    uint current_dungeon = 0;
                    ushort current_stam_to_reach = 0;
                    DataCache.Battles.Data last_data = null;
                    while (reader.Read())
                    {
                        DataCache.Battles.Key key = new DataCache.Battles.Key();
                        DataCache.Battles.Data data = new DataCache.Battles.Data();

                        key.BattleId = (uint)reader["id"];
                        data.DungeonId = (uint)reader["dungeon"];
                        data.Name = (string)reader["name"];
                        data.Stamina = (ushort)reader["stamina"];
                        data.Samples = (uint)reader["samples"];
                        data.HistoSamples = (uint)reader["histo_samples"];
                        data.Repeatable = true;

                        if (current_dungeon != data.DungeonId)
                        {
                            // We just went to a new dungeon.  Stamina to reach is 0.
                            current_stam_to_reach = 0;

                            // The previous battle is not repeatable.
                            if (last_data != null)
                                last_data.Repeatable = false;
                        }
                        else
                            current_stam_to_reach += data.Stamina;

                        data.StaminaToReach = current_stam_to_reach;
                        mBattles.Update(key, data);

                        current_dungeon = data.DungeonId;
                        last_data = data;
                    }
                    last_data.Repeatable = false;
                }
            }
        }
Ejemplo n.º 4
0
        public override void Handle(Session Session)
        {
            string ResponseJson = Session.GetResponseBodyAsString();

            EventListBattles result = JsonConvert.DeserializeObject <EventListBattles>(ResponseJson);

            FFRKProxy.Instance.GameState.ActiveDungeon = result;

            lock (FFRKProxy.Instance.Cache.SyncRoot)
            {
                result.Battles.Sort((x, y) => x.Id.CompareTo(y.Id));
                ushort stam_to_reach = 0;
                for (int i = 0; i < result.Battles.Count; ++i)
                {
                    DataBattle            battle = result.Battles[i];
                    DataCache.Battles.Key key    = new DataCache.Battles.Key {
                        BattleId = battle.Id
                    };
                    DataCache.Battles.Data data = null;
                    if (!FFRKProxy.Instance.Cache.Battles.TryGetValue(key, out data))
                    {
                        data = new DataCache.Battles.Data
                        {
                            DungeonId      = battle.DungeonId,
                            HistoSamples   = 1,
                            Name           = battle.Name,
                            Repeatable     = (i < result.Battles.Count - 1),
                            Samples        = 1,
                            Stamina        = battle.Stamina,
                            StaminaToReach = stam_to_reach
                        };

                        FFRKProxy.Instance.Cache.Battles.Update(key, data);
                    }

                    stam_to_reach += battle.Stamina;
                }
            }
            FFRKProxy.Instance.Database.BeginExecuteRequest(new DbOpRecordBattleList(result));
            FFRKProxy.Instance.RaiseListBattles(result);
        }
Ejemplo n.º 5
0
        public override void Handle(Session Session)
        {
            string ResponseJson = Session.GetResponseBodyAsString();

            EventListBattles result = JsonConvert.DeserializeObject<EventListBattles>(ResponseJson);
            FFRKProxy.Instance.GameState.ActiveDungeon = result;

            lock (FFRKProxy.Instance.Cache.SyncRoot)
            {
                result.Battles.Sort((x,y) => x.Id.CompareTo(y.Id));
                ushort stam_to_reach = 0;
                for (int i=0; i < result.Battles.Count; ++i)
                {
                    DataBattle battle = result.Battles[i];
                    DataCache.Battles.Key key = new DataCache.Battles.Key { BattleId = battle.Id };
                    DataCache.Battles.Data data = null;
                    if (!FFRKProxy.Instance.Cache.Battles.TryGetValue(key, out data))
                    {
                        data = new DataCache.Battles.Data
                        {
                            DungeonId = battle.DungeonId,
                            HistoSamples = 1,
                            Name = battle.Name,
                            Repeatable = (i < result.Battles.Count-1),
                            Samples = 1,
                            Stamina = battle.Stamina,
                            StaminaToReach = stam_to_reach
                        };

                        FFRKProxy.Instance.Cache.Battles.Update(key, data);
                    }

                    stam_to_reach += battle.Stamina;
                }
            }
            FFRKProxy.Instance.Database.BeginExecuteRequest(new DbOpRecordBattleList(result));
            FFRKProxy.Instance.RaiseListBattles(result);
        }
Ejemplo n.º 6
0
 public BattleListItem(DataCache.Battles.Key key, DataCache.Battles.Data data)
 {
     mKey = key;
     mData = data;
 }