INACTIVE PlusEMU RP Versio

Status
Not open for further replies.
May 1, 2015
470
154
I put the taxi command on a new thread so it doesn't interfere with anything else, but if i see that it's casuing issues (which i doubt) I'll change it to task.delay.
Thanks for the feedback :)
 
Statistics are now being saved every minute to keep track of everything -
Jail system has been re-coded and now runs on a timer instead of a check-up when processing the jail room.
 
May 1, 2015
470
154
I decided to re-code gangs because i'd rather cache everything inside the emulator using LINQ
Here is the gang manager for anyone interested:
Code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;

using Plus.HabboHotel.GameClients;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Users;
using Plus.Communication.Packets.Incoming;
using System.Collections.Concurrent;

using Plus.Database.Interfaces;
using log4net;

namespace Plus.HabboHotel.Users
{
    public class GangManager
    {
        private static readonly ILog Log = LogManager.GetLogger("Plus.HabboHotel.Users.GangManager");

        private readonly Object _gangloadingsync;
        private ConcurrentDictionary<int, Gang> _gangs;

        public GangManager()
        {
            this._gangloadingsync = new Object();

            // this.Init();
        }

        public bool TryGetGang(int Id, out Gang Gang)
        {
            Gang = null;

            if (this._gangs.ContainsKey(Id))
                return this._gangs.TryGetValue(Id, out Gang);

            lock (this._gangloadingsync)
            {
                if (this._gangs.ContainsKey(Id))
                    return this._gangs.TryGetValue(Id, out Gang);

                DataRow Row = null;
                using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    Adapter.SetQuery("SELECT * FROM `rp_gangs` WHERE `id` = @id LIMIT 1");
                    Adapter.AddParameter("id", Id);
                    Row = Adapter.getRow();

                    if (Row != null)
                    {
                        Gang = new Gang(
                            Convert.ToInt32(Row["id"]), Convert.ToString(Row["gang_name"]), Convert.ToInt32(Row["owner_id"]));
                        this._gangs.TryAdd(Gang.Id, Gang);
                        return true;
                    }
                }
            }
            return false;
        }

        public void Init()
        {
            _gangs = new ConcurrentDictionary<int, Gang>();
            // ClearInfo();

            using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                Adapter.SetQuery("SELECT * FROM rp_gangs");

                DataTable Table = Adapter.getTable();

                Log.Info("Gang Manager -> LOADED (Loaded " + Table.Rows.Count + "Gangs");
            }
        }

        public bool TryCreateGang(Habbo Player, string GangName, out Gang Gang)
        {
            Gang = new Gang(0, GangName, Player.Id);
            if (string.IsNullOrWhiteSpace(GangName))
                return false;

            using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                Adapter.SetQuery("INSERT INTO `rp_gangs` (`gang_name` `owner_id`) VALUES (@name, @ownerid)");
                Adapter.AddParameter("name", Gang.GangName);
                Adapter.AddParameter("ownerid", Gang.CreatorId);
                Gang.Id = Convert.ToInt32(Adapter.InsertQuery());

                Gang.AddMember(Player.Id);
                // Gang.AddOwner(Player.Id);

                if (!this._gangs.TryAdd(Gang.Id, Gang))
                    return false;
            }
            return true;
        }


        public void DeleteGang(int Id)
        {
            Gang Gang = null;

            if (this._gangs.ContainsKey(Id))
                this._gangs.TryRemove(Id, out Gang);

            if (Gang != null)
            {
                Gang.Dispose();
            }
        }
    }
}
 
Last edited:
May 1, 2015
470
154
I just finished re-coding some stuff on the jail timer once again, if you log off while arrested or in the process of being arrested it will be logged and on log-in you will be redirected back to jail for the remaining time of your sentence.
I also did some work on gangs they are functioning properly and loaded on emu start up. I just need to do a little more improvements until they're functioning the way i'd like them to.
Now that i have the basics done I am going to work on some jobs commands (Hospital Workers, basic police commands & whatever else i think of)
I will not be doing a weapon system, just hitting etc will be on this emulator.
The hospital will have a bot if there is no one on duty which will automatically heal you.
perhaps i'll release something later on that has to do with weapons but expect a release in the next few days.
 
Last edited:

NathanCarn3y

Leaving a legacy
Sep 14, 2016
625
195
I just finished re-coding some stuff on the jail timer once again, if you log off while arrested or in the process of being arrested it will be logged and on log-in you will be redirected back to jail for the remaining time of your sentence.
I also did some work on gangs they are functioning properly and loaded on emu start up. I just need to do a little more improvements until they're functioning the way i'd like them to.
Now that i have the basics done I am going to work on some jobs commands (Hospital Workers, basic police commands & whatever else i think of)
I will not be doing a weapon system, just hitting etc will be on this emulator.
The hospital will have a bot if there is no one on duty which will automatically heal you.
perhaps i'll release something later on that has to do with weapons but expect a release in the next few days.
Will you provide a database. Because when this is release I will put it on and that's my rp for a live one for people to see.
 

Zodiak

recovering crack addict
Nov 18, 2011
453
417
Don't mean to intrude, looked at some of the snippets and just thought I'd help out abit.

UserManager
Code:
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Threading;

using log4net;

using Plus.Core;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Groups;
using Plus.HabboHotel.GameClients;
using Plus.HabboHotel.Achievements;
using Plus.HabboHotel.Users.Badges;
using Plus.HabboHotel.Users.Inventory;
using Plus.HabboHotel.Users.Messenger;
using Plus.HabboHotel.Users.Relationships;
using Plus.HabboHotel.Users.UserDataManagement;

using Plus.HabboHotel.Users.Process;
using Plus.Communication.Packets.Outgoing.Inventory.Purse;


using Plus.HabboHotel.Users.Navigator.SavedSearches;
using Plus.HabboHotel.Users.Effects;
using Plus.HabboHotel.Users.Messenger.FriendBar;
using Plus.HabboHotel.Users.Clothing;
using Plus.Communication.Packets.Outgoing.Navigator;
using Plus.Communication.Packets.Outgoing.Rooms.Engine;
using Plus.Communication.Packets.Outgoing.Rooms.Session;
using Plus.Communication.Packets.Outgoing.Handshake;
using Plus.Database.Interfaces;
using Plus.HabboHotel.Rooms.Chat.Commands;
using Plus.HabboHotel.Users.Permissions;
using Plus.HabboHotel.Subscriptions;
using Plus.HabboHotel.Users.Calendar;

namespace Plus.HabboHotel.Users
{
    public class Roleplay
    {
        private static readonly ILog Log = LogManager.GetLogger("Plus.HabboHotel.Users.Roleplay");

        private int _userId;

        public int UserId
        {
            get { return this._userId; }
            set { this._userId = value; }
        }

        private string _motto;

        public string Motto
        {
            get { return this._motto; }
            set { this._motto = value; }
        }

        private GameClient _user;

        public GameClient user
        {
            get { return this._user; }
            set { this._user = value; }
        }

        private int _health;

        public int Health
        {
            get { return this._health; }
            set { this._health = value; }
        }

        private int _goingToId;

        public int GoingToId
        {
            get { return this._goingToId; }
            set { this._goingToId = value; }
        }

        private bool _wanted;

        public bool Wanted
        {
            get { return this._wanted; }
            set{ this._wanted = value; }
        }

        private int _jailTime;

        public int JailTime
        {
            get { return this._jailTime; }
            set { this._jailTime = value; }
        }

        public bool InJail
        {
            get { return this._jailTime >= 1; }
        }

        public GameClient GetClient
        {
            get { return PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(this.UserId); }
        }

        private void LoadUserData()
        {
            if (this.UserId > 0)
            {
                int health = 100;
                bool injail = false;
                int jailtime = 0;

                using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    Adapter.SetQuery("SELECT * FROM rp_data WHERE userid @id");
                    Adapter.AddParameter("id", this.UserId);

                    DataRow Row = Adapter.getRow();
                    if(Row == null)
                    {
                        Adapter.SetQuery("INSERT INTO rp_data (userid) VALUES @id");
                        Adapter.AddParameter("id", this.UserId);
                        Adapter.RunQuery();

                        Row = Adapter.getRow(); //Inserts and attempts to get new data.
                    }

                    if (Row != null)
                    {
                        this._health = Convert.ToInt32(Row["health"]);

                        //This column isn't needed injail = PlusEnvironment.EnumToBool(Row["in_jail"].ToString());

                        this._jailTime = Convert.ToInt32(Row["jail_time"]);
                    }
                }

                this._motto = "Citizen";
            }
        }

        public Roleplay(int UserId)
        {
            this._userId = UserId;
            this.LoadUserData();
        }

        public void Chat(string msg)
        {
            GameClient User = PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(this.UserId);
            User.GetHabbo().CurrentRoom.GetRoomUserManager().GetRoomUserByHabbo(User.GetHabbo().Username).OnChat(0, msg, false);
        }
  
        public void CallTaxi(int ID)
        {
            if(this.GetClient == null || this.GetClient.GetHabbo() == null)
                return; //Client or Habbo is null.

            this._goingToId = ID;
            RoomData Room = PlusEnvironment.GetGame().GetRoomManager().GenerateRoomData(ID);
            if (Room == null)
                return;

            this.Chat("*Whistles for a taxi to " + Room.Name + "*");

            new Thread(() =>
            {
                Thread.Sleep(10000);
                this.GetClient.GetHabbo().Credits -= 15;
                this.GetClient.SendMessage(new CreditBalanceComposer(this.GetClient.GetHabbo().Credits));
                this.GetClient.GetHabbo().PrepareRoom(ID, "");
            }).Start();
        }
    }
}

TaxiCommand
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class TaxiCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_taxi"; }
        }

        public string Parameters
        {
            get { return "%roomid%"; }
        }

        public string Description
        {
            get { return "Call a taxi to another room"; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if(Session == null || Session.GetHabbo() == null || Session.GetHabbo().Roleplay == null)
                return; //Null Habbo.
            if(Room == null)
                return; //Null Room.

            if (Session.GetHabbo().Roleplay.GoingToId > 0)
            {
                Session.GetHabbo().Roleplay.Chat("*Cancels their taxi*");
                return;
            }

            if (Session.GetHabbo().Roleplay.InJail)
            {
                Session.SendWhisper("You're currently in prison.");
                return;
            }

            if(Params.Length <= 1)
            { //No Params[1] / RoomID specified.
                Session.SendWhisper("No Room Id specified.");
                return;
            }

            int targetId;

            if(!int.TryParse(Params[1], out targetId)
            { //Params[1] / RoomID isn't a number.
                Session.SendWhisper("Room ID must be a number.");
                return;
            }

            if (targetId == Session.GetHabbo().CurrentRoomId)
            {
                Session.SendWhisper("You're already in that room.");
                return;
            }

            if (Session.GetHabbo().Credits < 15)
            {
                Session.SendWhisper("You cannot afford the taxi! ($15)");
                return;
            }

            Session.GetHabbo().Roleplay.CallTaxi(targetId);
        }
    }
}

StartWork
Code:
public void StartWork(GameClient Session, int JobId, int JobRank)
{
    if (Session == null || Session.GetHabbo() == null)
        return;

    string RankName = null;
    int Pay = 0;
    string MaleUni = null;
    string FemaleUni = null;
    string JobMotto = null;
    string JobLook = null;
    string JobName = null;
    int JobRoomId = 0;
    bool CanExitHeadquarters = false;

    Room Room = Session.GetHabbo().CurrentRoom;
    if (Room == null)
        return;

    RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
    if (User == null)
        return;

    if (Session.GetHabbo().Roleplay.IsWorking)
    {
        Session.SendWhisper("You are already working!");
        return;
    }

    if (JobId == 0 && JobRank == 0)
    {
        Session.GetHabbo().Roleplay.IsWorking = true;
        Session.GetHabbo().Roleplay.OnTheClock = DateTime.Now;
        Session.GetHabbo().Roleplay.Payment = 15;
        Session.GetHabbo().Roleplay.CanExitHeadQuarters = true;
        string OldMotto = Session.GetHabbo().Motto;
        Session.GetHabbo().Motto = "[WORKING] Welfare";
        Room.SendMessage(new UserChangeComposer(User, true));

        Session.GetHabbo().Roleplay.Chat("*Starts collecting welfare*");
        Session.GetHabbo().Roleplay.StartWorkTimer(15);
    }
    else
    {
        using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
        {
            Adapter.SetQuery("SELECT a.*,b.* FROM `rp_jobs` AS `A` JOIN `rp_ranks` AS `b` ON (`a`.`id` = `b`.`job_id`) WHERE `b`.`job_id` = @jobid AND `b`.`rank_id` = @rankid");
            Adapter.AddParameter("jobid", JobId);
            Adapter.AddParameter("rankid", JobRank);
            Adapter.RunQuery();

            DataTable Table = Adapter.getTable();

            if (Table != null)
            {
                foreach (DataRow Row in Table.Rows)
                {
                    JobId = Convert.ToInt32(Row["job_id"]);
                    RankName = Convert.ToString(Row["job_name"]);
                    Pay = Convert.ToInt32(Row["pay"]);
                    MaleUni = Convert.ToString(Row["male_uni"]);
                    FemaleUni = Convert.ToString(Row["female_uni"]);
                    JobMotto = Convert.ToString(Row["motto"]);
                    JobRoomId = Convert.ToInt32(Row["roomid"]);
                    JobName = Convert.ToString(Row["rank_name"]);
                    CanExitHeadquarters = PlusEnvironment.EnumToBool(Row["exithq"].ToString());

                    if (Session.GetHabbo().CurrentRoomId != JobRoomId)
                    {
                        Session.SendWhisper("You must be in your job headquarters to start working!");
                        return;
                    }

                    Session.GetHabbo().Roleplay.LookBeforeWork = Session.GetHabbo().Look;
                    this.UpdateClothing(Session, (Session.GetHabbo().Gender.ToLower() == "m" ? MaleUni : FemaleUni));

                    Session.GetHabbo().Look = JobLook;
                    Session.GetHabbo().Roleplay.OldMotto = Session.GetHabbo().Motto;
                    Session.GetHabbo().Motto = "[Working] " + JobName + "";
                    Session.GetHabbo().Roleplay.Payment = Pay;
                    Session.GetHabbo().Roleplay.IsWorking = true;
                    Session.GetHabbo().Roleplay.CanExitHeadQuarters = CanExitHeadquarters ? true : false;
          

                    Session.GetHabbo().Roleplay.Chat("*Starts working as a " + JobName + "*");
                    Session.SendWhisper("Your current pay is $" + Pay + " and you will receive it in 10 minutes.");

                    Session.GetHabbo().Roleplay.StartWorkTimer(Session.GetHabbo().Roleplay.Payment);

                    Room.SendMessage(new UserChangeComposer(User, false));
                    Session.GetHabbo().CurrentRoom.SendMessage(new UserChangeComposer(User, false));
                }
            }
        }
    }
}

CreateGang
Code:
public void CreateGang(GameClient Session, string GangName)
{
    /*
    * TODO: Remove 'string GangName' and change it to 'int GangId' and store GangId instead.
    */
    if(Session == null || Session.GetHabbo() == null)
        return;

    using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
    {
        Adapter.SetQuery("SELECT * FROM `rp_gangs` WHERE `name` = @name LIMIT 1");
        Adapter.AddParameter("name", GangName);
        Adapter.RunQuery();

        DataRow Row = Adapter.getRow();
        if (Row != null)
        {
            Adapter.SetQuery("INSERT INTO `rp_gangs` (`owner_id`, `gang_name`, `kills`) VALUES ('" + Session.GetHabbo().Id + "', @name, 0)");
            Adapter.AddParameter("name", GangName);
            Adapter.RunQuery();

            Session.SendWhisper("You have successfully created the gang " + GangName + "!");
        }
        else
        {
            Session.SendWhisper("That gang exists already!");
            return;
        }
    }
}
 
Last edited:
May 1, 2015
470
154
We all know you have. You've been telling all your retro friends that you're making a emulator when its Jordan.
OT: Any updates lad
Unfortunately not, I will try my best to start up work on this again soon.
 
This project has been passed over to @Velaski
I will help some-what if i have the time.
 
Status
Not open for further replies.

Users who are viewing this thread

Top