/// <summary> /// Tries to load a pet from the database and makes it visible in the room. If the X and Y parameters are not both zero, then the pet will be placed at the new position. /// </summary> /// <param name="nestID">The database ID of the nest item of the pet to load.</param> /// <param name="newX">The new X position of the pet. Supply 0 to set the last saved X position of the pet.</param> /// <param name="newY">The new Y position of the pet. Supply 0 to set the last saved Y position of the pet.</param> public void loadRoomPet(int nestID, byte newX, byte newY) { if (this.roomPets != null) { virtualPetInformation pInfo = ObjectTree.Game.Items.getPetInformation(nestID); if (pInfo != null) { roomPet pPet = new roomPet(pInfo); pPet.ID = this.getFreeRoomUnitIdentifier(); if (newX > 0 || newY > 0) // New placement from user hand { pPet.X = newX; pPet.Y = newY; } else { pPet.X = pPet.Information.lastX; pPet.Y = pPet.Information.lastY; } pPet.Z = this.gridHeight[pPet.X, pPet.Y]; this.gridUnit[pPet.X, pPet.Y] = true; this.roomPets.Add(pPet); if (newX > 0 || newY > 0) // New placement during instance lifetime { castRoomUnit(pPet.ToString()); } } } }
public void createPet(int nestID, string Name, char Type, byte Race, string htmlColor) { Database dbClient = new Database(false, true); dbClient.addParameterWithValue("id", nestID); dbClient.addParameterWithValue("name", Name); dbClient.addParameterWithValue("type", Type); dbClient.addParameterWithValue("race", Race); dbClient.addParameterWithValue("color", htmlColor); dbClient.addParameterWithValue("np", 0); dbClient.addParameterWithValue("nn", 0); dbClient.Open(); if (dbClient.Ready) { dbClient.runQuery( "INSERT INTO items_pets" + "(id,name,type,race,color,nature_positive,nature_negative,born) " + "VALUES " + "(@id,@name,@type,@race,@color,@np,@nn,NOW())" ); virtualPetInformation newPet = new virtualPetInformation(); newPet.ID = nestID; newPet.fFriendship = 1; newPet.dtLastKip = DateTime.Now.AddHours(-12); newPet.dtLastFed = newPet.dtLastKip; newPet.dtLastDrink = newPet.dtLastKip; newPet.dtLastPlayToy = DateTime.Now.AddDays(-1); newPet.dtLastPlayUser = newPet.dtLastPlayToy; newPet.Update(); // Update the fields } }
/// <summary> /// Constructs a roomPet object for a given virtualPetInformation object. /// </summary> /// <param name="pInfo">The virtualPetInformation that holds the values for this room pet.</param> public roomPet(virtualPetInformation pInfo) { this.Information = pInfo; }