internal static Pet CreatePet(uint UserId, string Name, int Type, string Race, string Color) { Pet pet = new Pet(404, UserId, 0, Name, (uint)Type, Race, Color, 0, 100, 100, 0, SilverwaveEnvironment.GetUnixTimestamp(), 0, 0, 0.0, false,0,0,-1); pet.DBState = DatabaseUpdateState.NeedsUpdate; using (IQueryAdapter dbClient = SilverwaveEnvironment.GetDatabaseManager().getQueryreactor()) { //,type,race,color,experience,energy,createstamp //,@" + pet.PetId + "race,@" + pet.PetId + "color,0,100,'" + pet.CreationStamp + "' dbClient.setQuery("INSERT INTO bots (user_id,name, ai_type) VALUES (" + pet.OwnerId + ",@" + pet.PetId + "name, 'pet')"); dbClient.addParameter(pet.PetId + "name", pet.Name); pet.PetId = (uint)dbClient.insertQuery(); dbClient.setQuery("INSERT INTO bots_petdata (id,type,race,color,experience,energy,createstamp) VALUES (" + pet.PetId + ", " + pet.Type + ",@" + pet.PetId + "race,@" + pet.PetId + "color,0,100,UNIX_TIMESTAMP())"); dbClient.addParameter(pet.PetId + "race", pet.Race); dbClient.addParameter(pet.PetId + "color", pet.Color); dbClient.runQuery(); } return pet; }
internal void AddPet(Pet Pet) { isUpdated = false; if (Pet == null || InventoryPets.ContainsKey(Pet.PetId)) return; Pet.PlacedInRoom = false; Pet.RoomId = 0; InventoryPets.Add(Pet.PetId, Pet); //using (DatabaseClient dbClient = SilverwaveEnvironment.GetDatabase().GetClient()) //{ // dbClient.addParameter("botid", Pet.PetId); // dbClient.runFastQuery("UPDATE user_pets SET room_id = 0, x = 0, y = 0, z = 0 WHERE id = @botid LIMIT 1"); //} ServerMessage AddMessage = new ServerMessage(603); Pet.SerializeInventory(AddMessage); GetClient().SendMessage(AddMessage); //UpdatePets(false); }
internal RoomUser DeployBot(RoomBot Bot, Pet PetData) { int num2; this.primaryPrivateUserID = (num2 = this.primaryPrivateUserID) + 1; RoomUser BotUser = new RoomUser(0, this.room.RoomId, num2, this.room, false); this.secondaryPrivateUserID = (num2 = this.secondaryPrivateUserID) + 1; int key = num2; BotUser.InternalRoomID = key; this.userlist.Add(key, BotUser); DynamicRoomModel Model = this.room.GetGameMap().Model; Point myPoint = new Point(Bot.X,Bot.Y); if ((Bot.X > 0 && Bot.Y > 0) && Bot.X < Model.MapSizeX && Bot.Y < Model.MapSizeY) { room.GetGameMap().AddUserToMap(BotUser, myPoint); BotUser.SetPos(Bot.X, Bot.Y, Bot.Z); BotUser.SetRot(Bot.Rot, false); } else { Bot.X = Model.DoorX; Bot.Y = Model.DoorY; BotUser.SetPos(Model.DoorX, Model.DoorY, Model.DoorZ); BotUser.SetRot(Model.DoorOrientation, false); } BotUser.BotData = Bot; BotUser.BotAI = Bot.GenerateBotAI(BotUser.VirtualId,(int)Bot.BotId); if (BotUser.IsPet) { BotUser.BotAI.Init(Bot.BotId, BotUser.VirtualId, room.RoomId, BotUser, room); BotUser.PetData = PetData; BotUser.PetData.VirtualId = BotUser.VirtualId; } else { BotUser.BotAI.Init(Bot.BotId, BotUser.VirtualId, room.RoomId, BotUser, room); } this.UpdateUserStatus(BotUser, false); BotUser.UpdateNeeded = true; ServerMessage EnterMessage = new ServerMessage(Outgoing.PlaceBot); EnterMessage.AppendInt32(1); BotUser.Serialize(EnterMessage, room.GetGameMap().gotPublicPool); room.SendMessage(EnterMessage); BotUser.BotAI.OnSelfEnterRoom(); if (BotUser.IsPet) { if (pets.ContainsKey(BotUser.PetData.PetId)) //Pet allready placed pets[BotUser.PetData.PetId] = BotUser; else pets.Add(BotUser.PetData.PetId, BotUser); petCount++; } if (BotUser.BotData.AiType == AIType.Generic) { if (bots.ContainsKey(BotUser.BotData.BotId)) bots[BotUser.BotData.BotId] = BotUser; else { bots.Add(BotUser.BotData.BotId, BotUser); } EnterMessage.Init(Outgoing.Dance); EnterMessage.AppendInt32(BotUser.VirtualId); EnterMessage.AppendInt32(BotUser.BotData.DanceId); room.SendMessage(EnterMessage); petCount++; } return BotUser; }