Merging UserID with ID

Velaski

winner
Aug 4, 2015
562
165
Ok, title may be a bit confusing I will explain.
I have my code here:
Code:
class Character
    {
        public int Id { get; set; }
        public int HP { get; set; }
        public int Kills { get; set; }
        public int Deaths { get; set; }

        public Character(int Id, int HP, int Kills, int Deaths)
        {
            this.Id = Id;
            this.HP = HP;
            this.Kills = Kills;
            this.Deaths = Deaths;
        }
    }
And I want that "ID" to match the current userid, and I'm coding the manager. This is my current code:
Code:
using log4net;
using Plus.Database.Interfaces;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Plus.HabboHotel.Minigames
{
    class CharacterManager
    {
        private static readonly ILog log = LogManager.GetLogger("Plus.HabboHotel.Minigames.CharacterManager");
        private readonly Dictionary<int, Character> _character = new Dictionary<int, Character>();

        public CharacterManager()
        {

        }
        public void Init()
        {
            if (this._character.Count > 0)
                this._character.Clear();

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `userminigame_stats`;");
                DataTable GetCharacter = dbClient.getTable();

                if (GetCharacter != null)
                {
                    foreach (DataRow Row in GetCharacter.Rows)
                    {
                        if (!this._character.ContainsKey(Convert.ToInt32(Row["id"])))
                            this._character.Add(Convert.ToInt32(Row["id"]), new Character(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["hp"]), Convert.ToInt32(Row["kills"]), Convert.ToInt32(Row["deaths"])));
                    }
                }
            }

            log.Info("Loaded " + this._character.Count + " Minigame Character Codes.");
        }



    }
}

I also want it to start as default:
ID = Default userid
HP = 100
Kills = 0
Deaths = 0

Can anybody help real quick?

@JayCustom @Sledmore @Altercationz @Meap
 

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,194
3,901
I'm not 100% sure I follow?

I think I know what you want, but that'd be on inserting the data? You can have defaults in the database or just insert in full via your code.

PHP:
        public void InsertCharacter(Character Character)
        {
            //Check if it already exists
            if (!this._character.ContainsKey(Character.Id))
                return;

            //Run our query, possibly run a check before this to check the database.
            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("INSERT INTO `userminigame_stats` (`id`,`hp`,`kills`,`deaths`) VALUES ('" + Character.Id + "', '" + Character.HP + "', '" + Character.Kills + "', '" + Character.Deaths + "')");
                //I've done SetQuery so you can prepare the statement, it's most likely not needed as the data is already validated, I was just too lazy to do the rest.
                dbClient.RunQuery();
            }
        }

That would go in your manager. I hope this is right? Let me know.
 

Users who are viewing this thread

Top