[Help] Hospital Bot For HabboRP'S [Help]

Jerry

not rly active lol
Jul 8, 2013
1,956
522
using System;

using Reality.Game.Rooms;
using Reality.Specialized;

using System.Collections.Generic;
using System.Collections.ObjectModel;
using Reality.Game.Pathfinding;
using Reality.Game.Misc;
using Reality.Util;
using Reality.Game.Sessions;
using Reality.Storage;
using Reality.Communication.Outgoing;

namespace Reality.Game.Bots.Behavior
{
public class HospitalBot : IBotBehavior
{
private Bot mSelfBot;
private RoomActor mSelfActor;
private bool mNeedsRotation;

private int mNextSpeechAttempt;
private int mNextMovementAttempt;
private int remindSpeech;

private int mServingItemId;
private uint mServingActorId;
private bool mMovingToServePos;
private Vector2 mActorServePos;

public bool InRoom
{
get
{
return (mSelfActor != null);
}
}

public override void Initialize(Bot BotReference)
{
mSelfBot = BotReference;
}

public override void OnSelfEnterRoom(RoomInstance Instance)
{
mSelfActor = Instance.GetActorByReferenceId(mSelfBot.Id, RoomActorType.AiBot);

if (mSelfActor == null)
{
return;
}

mNeedsRotation = false;
mNextSpeechAttempt = RandomGenerator.GetNext(20, 255);
mNextMovementAttempt = RandomGenerator.GetNext(20, 255);
mServingItemId = 0;
mServingActorId = 0;
mMovingToServePos = false;
mActorServePos = null;

if (mSelfBot.Rotation >= 0)
{
mSelfActor.BodyRotation = mSelfBot.Rotation;
mSelfActor.HeadRotation = mSelfBot.Rotation;
}
}

public override void OnSelfLeaveRoom(RoomInstance Instance)
{
if (mSelfActor == null)
{
return;
}

mSelfActor = null;
}

public override void OnUserChat(RoomInstance Instance, RoomActor Actor, string MessageText, bool Shout)
{
try
{
Session Session = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(Actor.Name));

if (MessageText.ToLower().Contains("heal"))
{
if (Session.CharacterInfo.Dead != 1)
{
if (Session.CharacterInfo.Health < 100)
{
Session.CharacterInfo.beingHealedSeconds = 60;
Session.CharacterInfo.beingHealed = true;

mSelfActor.Chat("*Treats " + Session.CharacterInfo.Username + " for major wounds*", true, true);
Session.CharacterInfo.poisoned = false;
}
else if(Session.CharacterInfo.Health >= 100)
{
Session.SendData(RoomChatComposer.Compose(Actor.Id, "Your health is already full!", 0, ChatType.Whisper));
return;
}
}

else
{
using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
{
RealityEMU.Game.Roleplay.RPMisc.releaseFromHosp(Session, Instance);
}

mSelfActor.Chat("*Discharges " + Session.CharacterInfo.Username + "' from the hospital*", true, true);
Instance.BroadcastMessage(UserInfoUpdateComposer.Compose(Actor.Id, Session.CharacterInfo.Figure, Session.CharacterInfo.Gender, Session.CharacterInfo.Motto, Session.CharacterInfo.Score));
}
}

}
catch (Exception e) { Console.WriteLine(e.ToString()); }

}

public override void OnUserEnter(RoomInstance Instance, RoomActor Actor)
{
mSelfActor.Chat("Welcome to the hospital " + Actor.Name + ". If you need a heal just ask!");

if (mSelfActor == null || Actor.Type == RoomActorType.AiBot)
{
return;
}

if (mSelfBot.Effect > 0)
{
mSelfActor.ApplyEffect(mSelfBot.Effect);
}
}

public override void OnUserLeave(RoomInstance Instance, RoomActor Actor)
{
if (mSelfActor == null || Actor.Type == RoomActorType.AiBot)
{
return;
}
}

public override void PerformUpdate(RoomInstance Instance)
{
if (mNextSpeechAttempt <= 0)
{
string Message = BotManager.GetRandomSpeechForBotDefinition(mSelfBot.DefinitionId);

if (Message != null && Message.Length > 0)
{
mSelfActor.Chat(Message);
}

mNextSpeechAttempt = RandomGenerator.GetNext(0, 255);
}
else
{
mNextSpeechAttempt--;
}
if (mSelfActor != null)
{
//!mSelfActor.IsMoving && mNextMovementAttempt <= 0
if (mNextMovementAttempt <= 0)
{
switch (mSelfBot.WalkMode)
{
default:
case BotWalkMode.STAND:

break;

case BotWalkMode.FREEROAM:

Vector2 position = new Vector2(RandomGenerator.GetNext(0, Instance.Model.Heightmap.SizeX - 1),
RandomGenerator.GetNext(0, Instance.Model.Heightmap.SizeY - 1));
mSelfActor.MoveTo(position);

break;

case BotWalkMode.SPECIFIED_RANGE:

ReadOnlyCollection<Vector2> Possibilites = mSelfBot.PredefinedPositions;
mSelfActor.MoveTo(Possibilites[RandomGenerator.GetNext(0, (Possibilites.Count - 1))]);
break;
}

mNextMovementAttempt = 5;
mNeedsRotation = true;
// mSelfActor.Chat("lol");
}
else
{
mNextMovementAttempt--;

if (mNextMovementAttempt > 5)
{
mNextMovementAttempt = 5;
}
//mSelfActor.Chat(mNextMovementAttempt + "-");
if (!mSelfActor.IsMoving)
{
if (mMovingToServePos)
{
mMovingToServePos = false;
mSelfActor.CarryItem(mServingItemId);
mSelfActor.MoveTo(mActorServePos);
}
else if (mServingItemId > 0)
{
mSelfActor.CarryItem(0);

RoomActor TargetActor = Instance.GetActor(mServingActorId);

if (TargetActor != null)
{
TargetActor.CarryItem(mServingItemId);

int NewRot = Rotation.Calculate(mActorServePos, TargetActor.Position.GetVector2());

mSelfActor.HeadRotation = NewRot;
mSelfActor.BodyRotation = NewRot;
mNeedsRotation = true;

mSelfActor.UpdateNeeded = true;
}

mServingItemId = 0;
}
else if (mNeedsRotation && mSelfBot.Rotation >= 0)
{
mSelfActor.BodyRotation = mSelfBot.Rotation;
mSelfActor.HeadRotation = mSelfBot.Rotation;
mNeedsRotation = false;
}
}
}

if (remindSpeech <= 0)
{
mSelfActor.Chat("If you need a heal just ask!");
remindSpeech = 100;
}
else
{
remindSpeech--;
}
}
}
}
}
 

Users who are viewing this thread

Top