Ejemplo n.º 1
0
        public static Bot CreateNewInstance(Bot Definition, uint RoomId, Vector3 Position, Pet PetData = null)
        {
            uint ResultId = 0;

            lock (mSyncRoot)
            {
                ResultId = mBotInstanceIdGenerator++;
            }

            Bot BotInstance = new Bot(ResultId, Definition.Id, Definition.BehaviorType, Definition.Name, Definition.Look,
                Definition.Motto, RoomId, Position, Definition.ServePosition, Definition.PredefinedPositions.ToList(),
                Definition.WalkMode, Definition.Kickable, Definition.Rotation, Definition.Responses, Definition.Effect,
                Definition.ResponseDistance, Definition.Health, Definition.CurrentPos, PetData);

            lock (mSyncRoot)
            {
                mBotInstances.Add(ResultId, BotInstance);
            }

            return BotInstance;
        }
Ejemplo n.º 2
0
 public uint GetBotActorId(Bot Bot)
 {
     uint ActorId = GenerateActorId();
     return ActorId;
 }
Ejemplo n.º 3
0
 public RoomActor GetBotActor(Bot Bot)
 {
     uint ActorId = GenerateActorId();
     return GetActor(ActorId);
 }
Ejemplo n.º 4
0
        public bool AddBotToRoom(Bot Bot)
        {
            uint ActorId = GenerateActorId();

            RoomActor BotActor = RoomActor.TryCreateActor(ActorId, RoomActorType.AiBot, Bot.Id, Bot,
                new Vector3(Bot.InitialPosition.X, Bot.InitialPosition.Y, Bot.InitialPosition.Z), 2, this);
            Bot.UpdatePosition(ActorId.ToString());
            Bot.Brain.Initialize(Bot);

            if (BotActor != null)
            {
                AddActorToRoom(BotActor);

                if (Bot.IsPet)
                {
                    mPetCount++;
                }

                return true;
            }

            return false;
        }
Ejemplo n.º 5
0
        public static void LoadBotDefinitions(SqlDatabaseClient MySqlClient)
        {
            mBotDefinitions.Clear();
            mDefinedResponses.Clear();
            mDefinedSpeech.Clear();
            mPetHandlerIndex.Clear();

            DataTable ResponseTable = MySqlClient.ExecuteQueryTable("SELECT bot_id,triggers,responses,response_serve_id FROM bot_responses");

            foreach (DataRow Row in ResponseTable.Rows)
            {
                BotResponse Response = new BotResponse(Row["triggers"].ToString().Split('|').ToList(),
                    Row["responses"].ToString().Split('|').ToList(), (int)Row["response_serve_id"]);

                if (!mDefinedResponses.ContainsKey((uint)Row["bot_id"]))
                {
                    mDefinedResponses.Add((uint)Row["bot_id"], new List<BotResponse>());
                }

                mDefinedResponses[(uint)Row["bot_id"]].Add(Response);
            }

            DataTable SpeechTable = MySqlClient.ExecuteQueryTable("SELECT bot_id,message FROM bots_speech");

            foreach (DataRow Row in SpeechTable.Rows)
            {
                if (!mDefinedSpeech.ContainsKey((uint)Row["bot_id"]))
                {
                    mDefinedSpeech.Add((uint)Row["bot_id"], new List<string>());
                }

                mDefinedSpeech[(uint)Row["bot_id"]].Add((string)Row["message"]);
            }

            MySqlClient.SetParameter("enabled", "1");
            DataTable BotTable = MySqlClient.ExecuteQueryTable("SELECT * FROM bots WHERE enabled = @enabled");

            foreach (DataRow Row in BotTable.Rows)
            {
                BotWalkMode WMode = BotWalkMode.STAND;

                switch ((string)Row["walk_mode"])
                {
                    case "freeroam":

                        WMode = BotWalkMode.FREEROAM;
                        break;

                    case "defined":

                        WMode = BotWalkMode.SPECIFIED_RANGE;
                        break;
                }

                List<Vector2> DefinedPositions = new List<Vector2>();
                string[] DefPosBits = Row["pos_defined_range"].ToString().Split(';');

                foreach (string DefPosBit in DefPosBits)
                {
                    DefinedPositions.Add(Vector2.FromString(DefPosBit));
                }

                Bot Bot = new Bot((uint)Row["id"], (uint)Row["id"], (string)Row["ai_type"], (string)Row["name"],
                    (string)Row["look"], (string)Row["motto"], (uint)Row["room_id"],
                    Vector3.FromString((string)Row["pos_start"]), Vector2.FromString((string)Row["pos_serve"]),
                    DefinedPositions, WMode, (Row["kickable"].ToString() == "1"), (int)Row["rotation"],
                    (mDefinedResponses.ContainsKey((uint)Row["id"]) ? mDefinedResponses[(uint)Row["id"]] : new List<BotResponse>()),
                    (int)Row["effect"], (int)Row["response_distance"], (int)Row["health"], (string)Row["pos_now"]);

                mBotDefinitions.Add((uint)Row["id"], Bot);

                int PetHandler = (int)Row["pet_type_handler_id"];

                if (PetHandler > 0)
                {
                    mPetHandlerIndex.Add(PetHandler, Bot);
                }
            }
        }