public void Create(string[] args) { var name = args[1]; var ageOrCapacity = int.Parse(args[2]); if (args.Length == 4) { var kind = args[3]; IPet pet = petFactory.CreatePet(name, ageOrCapacity, kind); this.pets.Add(pet); } else { IClinic clinic = clinicFactory.CreateClinic(name, ageOrCapacity); this.clinics.Add(clinic); } }
public void Run() { while (true) { string input = Console.ReadLine(); if (input == "End") { break; } string[] commandArgs = input.Split(); string individ = commandArgs[0]; if (individ == "Citizen") { IBirthable citizen = CitizenFactory.CreateCitizen(commandArgs.Skip(1).ToArray()); population.Add(citizen); } else if (individ == "Pet") { IBirthable pet = PetFactory.CreatePet(commandArgs.Skip(1).ToArray()); population.Add(pet); } } string yearToShow = Console.ReadLine(); foreach (var birthable in population) { if (birthable.Birthdate.EndsWith(yearToShow)) { Console.WriteLine(birthable.Birthdate); } } }
public static void HandlePurchase(SqlDatabaseClient MySqlClient, Session Session, CatalogItem Item, string ItemFlags) { lock (mPurchaseSyncRoot) { string Color = "ffffff"; int TotalCreditCost = Item.CostCredits; int TotalApCost = Item.CostActivityPoints; if (Session.CharacterInfo.CreditsBalance < TotalCreditCost || Session.CharacterInfo.ActivityPointsBalance < TotalApCost) { return; } string[] PetData = null; if (Item.PresetFlags.Length > 0) { ItemFlags = Item.PresetFlags; } else { switch (Item.Definition.Behavior) { case ItemBehavior.Pet: PetData = ItemFlags.Split('\n'); if (PetData.Length != 3) { return; } string Name = PetData[0]; Color = PetData[2]; int Race = 0; int.TryParse(PetData[1], out Race); bool RaceOk = false; List <PetRaceData> Races = PetDataManager.GetRaceDataForType(Item.Definition.BehaviorData); foreach (PetRaceData RaceData in Races) { if (RaceData.Data1 == Race) { RaceOk = true; break; } } /// if (PetName.VerifyPetName(Name) != PetNameError.NameOk || Color.ToLower() != "ffffff" || !RaceOk) if (PetName.VerifyPetName(Name) != PetNameError.NameOk || !RaceOk) // WHY COLOR??? { return; } break; case ItemBehavior.PrizeTrophy: if (ItemFlags.Length > 255) { ItemFlags = ItemFlags.Substring(0, 255); } ItemFlags = Session.CharacterInfo.Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + Convert.ToChar(9) + UserInputFilter.FilterString(ItemFlags.Trim(), true); break; default: ItemFlags = string.Empty; break; } } if (TotalCreditCost > 0) { Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, -TotalCreditCost); Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance)); } if (TotalApCost > 0) { Session.CharacterInfo.UpdateActivityPointsBalance(MySqlClient, -TotalApCost); Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance, -TotalApCost)); } Dictionary <int, List <uint> > NewItems = new Dictionary <int, List <uint> >(); for (int i = 0; i < Item.Amount; i++) { switch (Item.Definition.Type) { default: List <Item> GeneratedGenericItems = new List <Item>(); double ExpireTimestamp = 0; if (Item.Definition.Behavior == ItemBehavior.Rental) { ExpireTimestamp = UnixTimestamp.GetCurrent() + 3600; } GeneratedGenericItems.Add(ItemFactory.CreateItem(MySqlClient, Item.DefinitionId, Session.CharacterId, ItemFlags, ItemFlags, ExpireTimestamp)); switch (Item.Definition.Behavior) { case ItemBehavior.Teleporter: Item LinkedItem = ItemFactory.CreateItem(MySqlClient, Item.DefinitionId, Session.CharacterId, GeneratedGenericItems[0].Id.ToString(), string.Empty, ExpireTimestamp); GeneratedGenericItems[0].Flags = LinkedItem.Id.ToString(); GeneratedGenericItems[0].SynchronizeDatabase(MySqlClient, true); GeneratedGenericItems.Add(LinkedItem); break; } foreach (Item GeneratedItem in GeneratedGenericItems) { Session.InventoryCache.Add(GeneratedItem); int TabId = GeneratedItem.Definition.Type == ItemType.FloorItem ? 1 : 2; if (!NewItems.ContainsKey(TabId)) { NewItems.Add(TabId, new List <uint>()); } NewItems[TabId].Add(GeneratedItem.Id); } break; case ItemType.AvatarEffect: AvatarEffect Effect = null; if (Session.AvatarEffectCache.HasEffect((int)Item.Definition.SpriteId)) { Effect = Session.AvatarEffectCache.GetEffect((int)Item.Definition.SpriteId); if (Effect != null) { Effect.AddToQuantity(); } } else { Effect = AvatarEffectFactory.CreateEffect(MySqlClient, Session.CharacterId, (int)Item.Definition.SpriteId, 3600); Session.AvatarEffectCache.Add(Effect); } if (Effect != null) { Session.SendData(UserEffectAddedComposer.Compose(Effect)); } break; case ItemType.Pet: Pet Pet = PetFactory.CreatePet(MySqlClient, Session.CharacterId, Item.Definition.BehaviorData, PetData[0], int.Parse(PetData[1]), Color.ToLower()); Session.PetInventoryCache.Add(Pet); Session.SendData(InventoryPetAddedComposer.Compose(Pet)); if (!NewItems.ContainsKey(3)) { NewItems.Add(3, new List <uint>()); } NewItems[3].Add(Pet.Id); break; } } Session.SendData(CatalogPurchaseResultComposer.Compose(Item)); Session.SendData(InventoryRefreshComposer.Compose()); foreach (KeyValuePair <int, List <uint> > NewItemData in NewItems) { foreach (uint NewItem in NewItemData.Value) { Session.NewItemsCache.MarkNewItem(MySqlClient, NewItemData.Key, NewItem); } } if (NewItems.Count > 0) { Session.SendData(InventoryNewItemsComposer.Compose(new Dictionary <int, List <uint> >(NewItems))); } } }
public void Run() { int numberOfCommands = int.Parse(Console.ReadLine()); string[] inputArgs; for (int curr = 0; curr < numberOfCommands; curr++) { inputArgs = Console.ReadLine().Split(); string command = inputArgs[0]; switch (command) { case "Create": string type = inputArgs[1]; string[] createArgs = inputArgs.Skip(2).ToArray(); if (type == "Pet") { Pet pet = PetFactory.CreatePet(createArgs); pets.Add(pet); } else if (type == "Clinic") { try { Clinic clinic = ClinicFactory.CreateClinic(createArgs); clinics.Add(clinic); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } } break; case "Add": string addPetName = inputArgs[1]; string addClinicName = inputArgs[2]; Pet addPet = pets.First(p => p.Name == addPetName); Clinic addClinic = clinics.First(c => c.Name == addClinicName); Console.WriteLine(addClinic.Add(addPet)); break; case "Release": string releaseClinicName = inputArgs[1]; Clinic releaseClinic = clinics.First(c => c.Name == releaseClinicName); Console.WriteLine(releaseClinic.Release()); break; case "HasEmptyRooms": string hasEmptyRoomsClinicName = inputArgs[1]; Clinic hasEmptyRoomsClinic = clinics.First(c => c.Name == hasEmptyRoomsClinicName); Console.WriteLine(hasEmptyRoomsClinic.HasEmptyRooms()); break; case "Print": string printClinicName = inputArgs[1]; Clinic printClinic = clinics.First(c => c.Name == printClinicName); if (inputArgs.Length == 2) { printClinic.Print(); } else if (inputArgs.Length > 2) { int room = int.Parse(inputArgs[2]); printClinic.Print(room - 1); } break; } } }
public void CreatePet(string[] parameters) { Pet pet = petFactory.CreatePet(parameters); pets.Add(pet); }