Postado Qui 3 Mar 2011 - 19:34
Coloque este código na base do seu servidor, ou seja: o seu source.
Código:
Eu acho que é para substituir ou colar, mas faça um de cada vez, se não funcionar um, faça o outro.
Código:
E execute a SQL com este código:
Créditos: Ragezone
Código:
- Código:
case "compra":
using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
if (_isOwner == true)
{
int count = dbClient.getInt("SELECT max(id) FROM roombots");
if (args[1] == "gatto")
{
if (dbClient.findsResult("select id from roombots where roomid = '" + _roomID + "'"))
{
sendData("BK" + "Puoi tenere un solo animale per stanza");
}
else
{
int count2 = count + 1;
string nome = args[2];
dbClient.runQuery("update users set credits = credits -50 where id = '" + userID +"'");
refreshValueables(true, false);
string miao = "Miao!";
string zz = "ZZzzz!";
dbClient.runQuery("insert into roombots (id,roomid,name,mission,figure,x,y,z,freeroam) values ('" + count2 + "','" + _roomID + "','" + nome + "','ciao',1,10,9,0,0)");
dbClient.runQuery("insert into roombots_texts (id,type,text) values ('" + count2 + "','say','" + miao + "')");
dbClient.runQuery("insert into roombots_texts (id,type,text) values ('" + count2 + "','say','" + zz + "')");
dbClient.runQuery("insert into roombots_texts_triggers (id,words,replies) values ('" + count2 + "','" + nome + "','" + miao + "')");
sendData("BK" + "Hai Acquistato un gatto rientrando in stanza lo vedrai");
}
}
if (args[1] == "coccodrillo")
{
if (dbClient.findsResult("select id from roombots where roomid = '" + _roomID + "'"))
{
sendData("BK" + "Puoi tenere un solo animale per stanza");
}
else
{
int count2 = count + 1;
string nome = args[2];
dbClient.runQuery("update users set credits = credits -50 where id = '" + userID +"'");
refreshValueables(true, false);
string shout = "Shouting is not neccessary";
string miao = "Croc!";
string zz = "ZZzzz!";
dbClient.runQuery("insert into roombots (id,roomid,name,mission,figure,x,y,z,freeroam,message_noshouting) values ('" + count2 + "','" + _roomID + "','" + nome + "','ciao',2,10,9,0,0,'" + shout + "')");
dbClient.runQuery("insert into roombots_texts (id,type,text) values ('" + count2 + "','say','" + miao + "')");
dbClient.runQuery("insert into roombots_texts (id,type,text) values ('" + count2 + "','say','" + zz + "')");
dbClient.runQuery("insert into roombots_texts_triggers (id,words,replies) values ('" + count2 + "','" + nome + "','" + miao + "')");
sendData("BK" + "Hai Acquistato un coccodrillo rientrando in stanza lo vedrai");
}
}
}
else
sendData("BK" + "La stanza non è tua quindi non puoi aggiungere ne rimuovere animali");
break;
case "elimina":
using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
if(_isOwner==true)
{
int id = dbClient.getInt("select id from roombots where roomid = '" + _roomID + "'");
dbClient.runQuery("delete from roombots_texts where id = '" + id + "'");
dbClient.runQuery("delete from roombots where roomid = '" + _roomID + "'");
dbClient.runQuery("delete from roombots_coords where id = '" + id + "'");
dbClient.runQuery("delete from roombots_texts_triggers where id = '" + id + "'");
sendData("BK" + "Al prossimo rientro in stanza non troverai più il tuo animale");
}
else
sendData("BK" + "La stanza non è tua quindi non puoi aggiungere ne rimuovere animali");
break;
Eu acho que é para substituir ou colar, mas faça um de cada vez, se não funcionar um, faça o outro.
Código:
- Código:
using System;
using System.Data;
using System.Text;
using System.Threading;
using System.Collections;
using Holo.Virtual.Users;
using Holo.Virtual.Rooms.Pathfinding;
using Ion.Storage;
namespace Holo.Virtual.Rooms.Bots
{
///
/// Represents a computer controlled virtual user with an artifical intelligence (AI). The bot walks around in virtual rooms on specified coordinates, interacts with other virtual users and serves drinks and food.
///
internal class virtualBot
{
#region Declares
///
/// The ID of the bot in the virtual room.
///
internal int roomUID;
///
/// The virtual room the bot roams in.
///
internal virtualRoom Room;
///
/// The name of the bot.
///
internal string Name;
///
/// The mission/motto that the bot has.
///
internal string Mission;
///
/// The bot's figure string.
///
internal string Figure;
///
/// The X position of the bot in the virtual room.
///
internal int X;
///
/// The Y position of the bot in the virtual room.
///
internal int Y;
///
/// The height of the bot in the virtual room.
///
internal double H;
///
/// The rotation of the bot's head in the virtual room.
///
internal byte Z1;
///
/// The rotation of the bot's body in the virtual room.
///
internal byte Z2;
///
/// Used for pathfinding. The X coordinate of the bot's target square in the virtual room.
///
internal int goalX;
///
/// Used for pathfinding. The Y coordinate of the bot's target square in the virtual room.
///
internal int goalY;
///
/// Indicates if the bot uses 'freeroam', which allows it to walk everywhere where it can go to. Astar pathfinding is used.
///
internal bool freeRoam;
///
/// The message that the bot will use (on random) to shouting people near the bot.
///
internal string noShoutingMessage;
private delegate void statusVoid(string Key, string Value, int Length);
///
/// Handles the random determining of actions.
///
private Thread aiHandler;
///
/// Contains the texts that the bot can 'say' on random.
///
private string[] Sayings;
///
/// Contains the texts that the bot can 'shout' on random.
///
private string[] Shouts;
///
/// Contains the coordinate's where the bot can walk to. Ignored if freeroam is enabled.
///
private Coord[] Coords;
///
/// Contains the chat triggers where the bot reacts on.
///
private chatTrigger[] chatTriggers;
///
/// The virtualRoomUser object the bot is currently serving an item to.
///
private virtualRoomUser Customer;
///
/// The chatTrigger object that was invoked by the current customer.
///
private chatTrigger customerTrigger;
#endregion
#region Constructors/destructors
///
/// Contains the bot's animation statuses.
///
private Hashtable Statuses;
///
/// Initializes a new virtualBot object, loading the walk squares, chat texts etc.
///
/// The database ID of the bot.
/// The ID that identifies this bot in room.
/// The virtualRoom object where the bot is in.
internal virtualBot(int botID, int roomUID, virtualRoom Room)
{
this.roomUID = roomUID;
this.Room = Room;
DataRow dRow;
using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
{
dRow = dbClient.getRow("SELECT name,mission,figure,x,y,z,freeroam,message_noshouting FROM roombots WHERE id = '" + botID + "'");
}
this.Name = Convert.ToString(dRow[0]);
this.Mission = Convert.ToString(dRow[1]);
this.Figure = Convert.ToString(dRow[2]);
this.X = Convert.ToInt32(dRow[3]);
this.Y = Convert.ToInt32(dRow[4]);
this.Z1 = Convert.ToByte(dRow[5]);
this.Z2 = Z1;
this.goalX = -1;
this.freeRoam = (Convert.ToString(dRow[6]) == "1");
this.noShoutingMessage = Convert.ToString(dRow[7]);
DataColumn dCol;
using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
{
dCol = dbClient.getColumn("SELECT text FROM roombots_texts WHERE id = '" + botID + "' AND type = 'say'");
}
this.Sayings = (string[])dataHandling.dColToArray(dCol);
using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
{
dCol = dbClient.getColumn("SELECT text FROM roombots_texts WHERE id = '" + botID + "' AND type = 'shout'");
}
this.Shouts = (string[])dataHandling.dColToArray(dCol);
DataTable dTable;
using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
{
dTable = dbClient.getTable("SELECT words, replies, serve_replies, serve_item FROM roombots_texts_triggers WHERE id = '" + botID + "'");
}
this.chatTriggers = new chatTrigger[dTable.Rows.Count];
int i = 0;
foreach (DataRow dbRow in dTable.Rows)
{
this.chatTriggers[i] = new chatTrigger((Convert.ToString(dbRow["words"]).ToLower()).Split('}'), (Convert.ToString(dbRow["replies"])).Split('}'), (Convert.ToString(dbRow["serve_replies"])).Split('}'), Convert.ToString(dbRow["serve_item"]));
i++;
}
using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
{
dTable = dbClient.getTable("SELECT x,y FROM roombots_coords WHERE id = '" + botID + "'");
}
Coords = new Coord[dTable.Rows.Count];
i = 0;
foreach (DataRow dbRow in dTable.Rows)
{
Coords[i] = new Coord(Convert.ToInt32(dbRow["x"]), Convert.ToInt32(dbRow["y"]));
i++;
}
Statuses = new Hashtable();
aiHandler = new Thread(new ThreadStart(AI));
aiHandler.Priority = ThreadPriority.BelowNormal;
aiHandler.Start();
}
///
/// Safely shuts this virtualBot down and tidies up all resources.
///
internal void Kill()
{
try { aiHandler.Abort(); }
catch { }
aiHandler = null;
Room = null;
Statuses = null;
Coords = null;
Sayings = null;
Shouts = null;
chatTriggers = null;
Customer = null;
customerTrigger = null;
}
#endregion
#region Bot properties
///
/// The details string of the bot, containing room identifier ID, name, motto, figure etc.
///
internal string detailsString
{
get
{
string petTransformAdd = "";
string petTransformFigure = "";
petTransformAdd = "7ui1" + Convert.ToChar(4);
petTransformFigure = Figure + " 000 " + "98A1C5";
string s = "i:" + roomUID + Convert.ToChar(13) + "a:-1" + Convert.ToChar(13) + "n:" + petTransformAdd + Name + Convert.ToChar(13) + "f:" + petTransformFigure + Convert.ToChar(13) + "l:" + X + " " + Y + " " + H + Convert.ToChar(13);
if (Mission != "") { s += "c:" + Mission + Convert.ToChar(13); }
else { s += "c:" + " Baboh rulez!" + Convert.ToChar(13); }
return s + ":p" + Convert.ToChar(13);
}
}
///
/// The status string of the bot, containing positions, movements, statuses (animations) etc.
///
internal string statusString
{
get
{
string s = roomUID + " " + X + "," + Y + "," + H.ToString().Replace(",", ".") + "," + Z1 + "," + Z2 + "/";
foreach (string Key in Statuses.Keys)
{
s += Key;
string Value = (string)Statuses[Key];
if (Value != "")
s += " " + Value;
s += "/";
}
return s;
}
}
#endregion
#region Actions
///
/// Invoked by a virtualRoomUser. There is checked if this bot reacts on a certain chat message, if so, then replies/orders etc are processed.
///
/// The virtualRoomUser object that interacts with this bot by saying a message.
/// The message that the virtualRoomUser said to this bot.
internal void Interact(virtualRoomUser roomUser, string Message)
{
Message = Message.ToLower();
string[] messageWords = Message.Split(' ');
if (chatTriggers != null)
{
foreach (chatTrigger Trigger in chatTriggers)
{
for (int i = 0; i < messageWords.Length; i++)
{
if (Trigger.containsWord(messageWords[i]))
{
if (Trigger.serveItem != "") // Serve an item, walk up to the customer and hand over the beverage
{
if (Customer != null) // The bot is currently serving a different room user, ignore this trigger
return;
Coord Closest = getClosestWalkCoordTo(roomUser.X, roomUser.Y);
if (Closest.X == -1) // Can't serve this user (no square close enough)
return;
Room.sendSaying(this, Trigger.Reply);
removeStatus("dance");
addStatus("carryd", Trigger.serveItem); // Make the bot starting to carry the order to deliver it
goalX = Closest.X;
goalY = Closest.Y;
this.Customer = roomUser;
this.customerTrigger = Trigger;
}
else
{
this.Z1 = Rotation.Calculate(X, Y, roomUser.X, roomUser.Y);
this.Z2 = this.Z1;
Room.sendSaying(this, Trigger.Reply);
}
return; // One trigger per time
}
}
}
}
}
///
/// If the bot currently is processing an order, then it'll hand over the order and prepare for a new one.
///
internal void checkOrders()
{
if (Customer != null)
{
{
goalX = -1;
Rotate(Customer.X, Customer.Y);
removeStatus("carryd");
Room.sendSaying(this, customerTrigger.serveReply);
if (Customer.statusManager.containsStatus("sit") == false)
{
Customer.Z1 = Rotation.Calculate(Customer.X, Customer.Y, X, Y);
Customer.Z2 = Customer.Z1;
}
Customer.statusManager.carryItem(customerTrigger.serveItem);
}
{
Customer = null;
customerTrigger = null;
}
}
}
///
/// Rotates the bot to a certain X and Y coordinate and refreshes it in the room. If the bot is sitting, then rotating will be ignored.
///
/// The X coordinate to face.
/// The Y coordinate to face.
internal void Rotate(int toX, int toY)
{
Rotate(Rotation.Calculate(X, Y, toX, toY));
}
///
/// Sets a new rotation for the bot and refreshes it in the room. If the bot is sitting, then rotating will be ignored.
///
/// The new rotation to use.
internal void Rotate(byte R)
{
if (R != Z1 && Statuses.ContainsKey("sit") == false)
{
Z1 = R;
Z2 = R;
Refresh();
}
}
///
/// Returns a Coord object with the X and Y of the walkcoord that is as closest to the given position.
///
/// The X position.
/// The Y position.
internal Coord getClosestWalkCoordTo(int X, int Y)
{
int minDistance = 6;
Coord Closest = new Coord(-1, 0);
foreach (Coord Coord in Coords)
{
int curDistance = Math.Abs(X - Coord.X) + Math.Abs(Y - Coord.Y);
if (curDistance < minDistance)
{
minDistance = curDistance;
Closest = Coord;
}
}
return Closest;
}
#endregion
#region Status management
///
/// Adds a status key and a value to the bot's statuses. If the status is already inside, then the previous one will be removed.
///
/// The key of the status.
/// The value of the status.
internal void addStatus(string Key, string Value)
{
if (Statuses.ContainsKey(Key))
Statuses.Remove(Key);
Statuses.Add(Key, Value);
}
///
/// Removes a certain status from the bot's statuses.
///
/// The key of the status to remove.
internal void removeStatus(string Key)
{
try
{
if (Statuses.ContainsKey(Key))
Statuses.Remove(Key);
}
catch { }
}
///
/// Returns a bool that indicates if the bot has a certain status at the moment.
///
/// The key of the status to check.
internal bool containsStatus(string Key)
{
return Statuses.ContainsKey(Key);
}
///
/// Refreshes the status of the bot in the virtual room.
///
internal void Refresh()
{
Room.Refresh(this);
}
///
/// Adds a status to the bot, keeps it for a specified amount of time [in ms] and removes the status. Refreshes at add and remove.
///
/// The key of the status, eg, 'sit'.
/// The value of the status, eg, '1.0'.
/// The amount of milliseconsd to keep the status before removing it again.
internal void handleStatus(string Key, string Value, int Length)
{
if (Statuses.ContainsKey(Key))
Statuses.Remove(Key);
new statusVoid(HANDLESTATUS).BeginInvoke(Key, Value, Length, null, null);
}
private void HANDLESTATUS(string Key, string Value, int Length)
{
try
{
Statuses.Add(Key, Value);
Refresh();
Thread.Sleep(Length);
Statuses.Remove(Key);
Refresh();
}
catch { }
}
#endregion
#region Misc
///
/// Ran on a thread. Handles the bot's artifical intelligence, by interacting with users and using random values etc.
///
private void AI()
{
int lastMessageID = -1;
Random RND = new Random();
//try
{
while (true)
{
if (Customer != null) // Currently serving a different user
continue;
int ACTION = RND.Next(0, 4);
switch (ACTION)
{
case 1: // Move
{
removeStatus("jmp");
removeStatus("sit");
removeStatus("ded");
Coord Next = new Coord();
int[] Borders = Room.getMapBorders();
{
Next = new Coord(RND.Next(0, Borders[0]), RND.Next(0, Borders[1]));
goalX = Next.X;
goalY = Next.Y;
}
break;
}
case 2: // Status
{
int action = RND.Next(1, 4);
switch (action)
{
case 1:
removeStatus("jmp");
removeStatus("ded");
addStatus("sit", string.Concat(1));
Refresh();
break;
case 2:
removeStatus("sit");
removeStatus("ded");
addStatus("jmp", string.Concat(1));
Refresh();
break;
case 3:
removeStatus("sit");
removeStatus("jmp");
addStatus("ded", string.Concat(1));
Refresh();
break;
}
break;
}
case 3: // Say
{
foreach (chatTrigger Trigger in chatTriggers)
Room.sendSaying(this, Trigger.Reply);
break;
}
}
Thread.Sleep(3000);
Out.WriteTrace("Bot AI loop");
}
}
//catch { aiHandler.Abort(); }
}
#endregion
#region Private objects
///
/// Represents a trigger that can be invoked by a chat message. Results in a reply and/or an order confirmation.
///
private class chatTrigger
{
///
/// A System.String array with words that invoke this trigger.
///
private string[] Words;
///
/// A System.String array with replies that are used when this trigger is invoked.
///
private string[] Replies;
///
/// A System.String array with replies that are used when the bot hands over the food/drink item for this trigger.
///
private string[] serveReplies;
///
/// The item (food/drink) that will be served when one of this trigger's words match a given word.
///
internal string serveItem;
internal chatTrigger(string[] Words, string[] Replies, string[] serveReplies, string serveItem)
{
this.Words = Words;
this.Replies = Replies;
this.serveReplies = serveReplies;
this.serveItem = serveItem;
}
///
/// Returns a boolean that indicates if this trigger replies on a certain word.
///
/// The word to check.
internal bool containsWord(string Word)
{
if (Word.Substring(Word.Length - 1, 1) == "?")
Word = Word.Substring(0, Word.Length - 1);
for (int i = 0; i < Words.Length; i++)
if (Words[i] == Word)
return true;
return false;
}
///
/// Returns a random reply from the replies array.
///
internal string Reply
{
get
{
return Replies[new Random(DateTime.Now.Millisecond).Next(0, Replies.Length)];
}
}
///
/// Returns a random 'hand over item, here you are' reply from the replies array.
///
internal string serveReply
{
get
{
return serveReplies[new Random(DateTime.Now.Millisecond).Next(0, serveReplies.Length)];
}
}
}
#endregion
}
}
E execute a SQL com este código:
- Código:
/*
-- ----------------------------
-- Table structure for roombots
-- ----------------------------
DROP TABLE IF EXISTS `roombots`;
CREATE TABLE `roombots` (
`id` int(10) NOT NULL auto_increment,
`roomid` int(10) NOT NULL,
`name` varchar(50) collate latin1_general_ci NOT NULL,
`mission` varchar(100) collate latin1_general_ci default NULL,
`figure` text collate latin1_general_ci NOT NULL,
`x` int(5) NOT NULL,
`y` int(5) NOT NULL,
`z` int(1) NOT NULL,
`freeroam` enum('1','0') collate latin1_general_ci NOT NULL default '0',
`message_noshouting` varchar(200) collate latin1_general_ci NOT NULL default 'Shouting is not neccessary.',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
-- ----------------------------
-- Table structure for roombots_coords
-- ----------------------------
DROP TABLE IF EXISTS `roombots_coords`;
CREATE TABLE `roombots_coords` (
`id` int(10) NOT NULL,
`x` int(5) NOT NULL,
`y` int(5) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
-- ----------------------------
-- Table structure for roombots_texts
-- ----------------------------
DROP TABLE IF EXISTS `roombots_texts`;
CREATE TABLE `roombots_texts` (
`id` int(10) NOT NULL,
`type` enum('shout','say') collate latin1_general_ci NOT NULL,
`text` varchar(255) collate latin1_general_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
-- ----------------------------
-- Table structure for roombots_texts_triggers
-- ----------------------------
DROP TABLE IF EXISTS `roombots_texts_triggers`;
CREATE TABLE `roombots_texts_triggers` (
`id` int(10) NOT NULL,
`words` text collate latin1_general_ci NOT NULL,
`replies` text collate latin1_general_ci NOT NULL,
`serve_replies` text collate latin1_general_ci NOT NULL,
`serve_item` varchar(20) collate latin1_general_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
Créditos: Ragezone