Exemplo n.º 1
0
    public void EvolutionCheck(ActivePet pet)
    {
        EvolutionTree tree = evolutionGarden.GetTree(pet.treeName);

        if (tree == null)
        {
            Debug.LogError("Didn't find tree: " + pet.treeName + " of " + pet.species);
        }
        else
        {
            if (tree.IsTimeToEvolve(pet))
            {
                Species evolveTo = tree.GetEvolution(pet);
                //Debug.Log("Evolving to " + evolveTo.name);
                if (evolveTo)
                {
                    Debug.Log("Evolving to " + evolveTo.name);
                    // Animate
                    if (onEvolutionEvent != null)
                    {
                        onEvolutionEvent(FindSheet(pet.species).idle[0], FindSheet(evolveTo.speciesName).idle[0]);
                    }

                    pet.EvolveTo(PetFactory.Evolve(pet, evolveTo));

                    if (onActivePetsChange != null)
                    {
                        onActivePetsChange(this.activePets);
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
 public ClinicManager()
 {
     petFactory    = new PetFactory();
     clinicFactory = new ClinicFactory();
     pets          = new HashSet <Pet>();
     clinics       = new HashSet <Clinic>();
 }
Exemplo n.º 3
0
    private void LoadPets()
    {
        Debug.Log(user.active);
        for (int i = 0; i < maxActive && i < user.active.Length; i++)
        {
            foreach (PetSnapshot snapshot in user.pets)
            {
                if (snapshot._id == user.active[i])
                {
                    bool inGraveyard = false;

                    foreach (string grave in user.graveyard)
                    {
                        if (snapshot._id == grave)
                        {
                            inGraveyard = true;
                        }
                    }

                    if (inGraveyard == false)
                    {
                        activePets.Add(PetFactory.CreateFromSnapshot(snapshot));
                    }
                }
            }
        }

        if (onActivePetsChange != null)
        {
            onActivePetsChange(activePets);
        }

        ForceSelection();
    }
Exemplo n.º 4
0
 public ClinicController()
 {
     this.clinics       = new List <IClinic>();
     this.pets          = new List <IPet>();
     this.clinicFactory = new ClinicFactory();
     this.petFactory    = new PetFactory();
 }
Exemplo n.º 5
0
        public void CreateCat_Should_Return_Instance_Of_Type_IPet()
        {
            // Arrange & Act
            var cat = new PetFactory().CreateCat("name", AnimalGenderType.female, 1);

            // Assert
            Assert.IsInstanceOfType(cat, typeof(IPet));
        }
Exemplo n.º 6
0
        public void CreateHamster_Should_Return_Instance_Of_Type_IPet()
        {
            // Arrange & Act
            var hamster = new PetFactory().CreateHamster("name", AnimalGenderType.female, 1);

            // Assert
            Assert.IsInstanceOfType(hamster, typeof(IPet));
        }
Exemplo n.º 7
0
        public void CreateDog_Should_Return_Instance_Of_Type_IPet()
        {
            // Arrange & Act
            var dog = new PetFactory().CreateDog("name", AnimalGenderType.female, "breed", 1);

            // Assert
            Assert.IsInstanceOfType(dog, typeof(IPet));
        }
Exemplo n.º 8
0
 public Engine(IReader reader, IWriter writer)
 {
     this.reader    = reader;
     this.writer    = writer;
     citizenFactory = new CitizenFactory();
     robotFactory   = new RobotFactory();
     petFactory     = new PetFactory();
     list           = new List <string>();
 }
Exemplo n.º 9
0
        public PetWalkingService(PetFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            this.factory = factory;
        }
Exemplo n.º 10
0
 public StateGT048(botWindow botwindow)   //, GotoTrade gototrade)
 {
     this.botwindow     = botwindow;
     this.serverFactory = new ServerFactory(botwindow);
     this.server        = serverFactory.create(); // создали конкретный экземпляр класса server по паттерну "простая Фабрика" (Америка, Европа или Синг)
     this.petFactory    = new PetFactory(botwindow);
     this.pet           = petFactory.createPet();
     this.tekStateInt   = 48;
 }
        public IClientFactory WithPet(Action <IPetFactory> pet)
        {
            var petFactory = new PetFactory();

            pet(petFactory);

            this.pets.Add(petFactory.Build());

            return(this);
        }
Exemplo n.º 12
0
 public StateGT405(botWindow botwindow)
 {
     this.botwindow     = botwindow;
     this.serverFactory = new ServerFactory(botwindow);
     this.server        = serverFactory.create(); // создали конкретный экземпляр класса server по паттерну "простая Фабрика" (Америка, Европа или Синг)
     this.town          = server.getTown();
     this.petFactory    = new PetFactory(botwindow);
     this.pet           = petFactory.createPet();
     this.tekStateInt   = 405;
 }
Exemplo n.º 13
0
        public static void Main(string[] args)
        {
            var petFactory = new PetFactory();

            var pet = petFactory.GetPet(PetType.Dog);

            pet.Speak();

            pet = petFactory.GetPet(PetType.Duck);

            pet.Speak();
        }
        public IClientFactory WithPets(IList <Action <IPetFactory> > pets)
        {
            this.pets = new List <Pet>();

            var petFactory = new PetFactory();

            foreach (var pet in pets)
            {
                pet(petFactory);

                this.pets.Add(petFactory.Build());
            }

            return(this);
        }
Exemplo n.º 15
0
        /// <summary>The constructor <c>PetService</c> will receive setting parameters provided that
        /// those have been configured accordingly on the Setup.cs file of the solution
        /// </summary>
        public PetService(IPetDatabaseSettings settings, List <PetConfigurationSettings> petSettings)
        {
            string detectedHost = Environment.GetEnvironmentVariable("MONGODB_HOST");

            if (detectedHost == null)
            {
                detectedHost = settings.ConnectionString;
            }
            var client   = new MongoClient(detectedHost);
            var database = client.GetDatabase(settings.DatabaseName);

            _petFactory = new PetFactory(petSettings);
            _pets       = database.GetCollection <Pet>(settings.PetCollectionName);
            _owners     = database.GetCollection <User>(settings.UserCollectionName);
        }
Exemplo n.º 16
0
        public void ReloadCache(SqlDatabaseClient MySqlClient)
        {
            lock (mSyncRoot)
            {
                mInner.Clear();

                MySqlClient.SetParameter("userid", mCharacterId);
                DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM pets WHERE user_id = @userid AND room_id = 0");

                foreach (DataRow Row in Table.Rows)
                {
                    Pet Pet = PetFactory.GetPetFromDatabaseRow(Row);
                    mInner.Add(Pet.Id, Pet);
                }
            }
        }
Exemplo n.º 17
0
    public bool PickupEgg(EvolutionTree tree)
    {
        if (activePets.Count >= maxActive)
        {
            return(false);
        }

        ActivePet pet = PetFactory.CreateEgg(tree);

        if (pet != null)
        {
            StartCoroutine(CreateEgg(pet));
        }

        return(true);
    }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            bool quit = false;

            do
            {
                Console.WriteLine("What size of pet do you prefer (small, medium, large)?");
                string petSize = Console.ReadLine();

                var myPet = PetFactory.GetPet(petSize);
                if (myPet != null)
                {
                    myPet.Companion();
                }
                else
                {
                    quit = true;
                }
            }while (quit == false);

            Console.WriteLine("Finished making pets");
        }
Exemplo n.º 19
0
        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);
                }
            }
        }
Exemplo n.º 20
0
        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)));
                }
            }
        }
Exemplo n.º 21
0
        private static void Main(string[] args)
        {
            IPet pet = PetFactory.GetPet("Bird");

            pet.Move();
        }
Exemplo n.º 22
0
        public PetTest()
        {
            List <PetConfigurationSettings> _allSettings = GlobalPetConfigurationSettings.generateDefaultSettings().Metrics;

            _petFactory = new PetFactory(_allSettings);
        }
Exemplo n.º 23
0
 public IActionResult RenderPet(int petId, string animation = "stand0", int frame = 0, int petEquip = -1)
 => File(PetFactory.RenderPet(petId, animation, frame, petEquip).ImageToByte(Request), "image/png");
Exemplo n.º 24
0
        public IActionResult GetName(int petId)
        {
            Pet eq = PetFactory.GetPet(petId);

            return(Json(eq.Description));
        }
Exemplo n.º 25
0
        public IActionResult GetPetActions(int petId)
        {
            Pet eq = PetFactory.GetPet(petId);

            return(Json(eq.frameBooks.Where(c => c.Value.FirstOrDefault()?.frames?.Count() > 0).ToDictionary(c => c.Key, c => c.Value.FirstOrDefault()?.frames?.Count() ?? 0)));
        }
Exemplo n.º 26
0
 public IActionResult GetPet(int petId) => Json(PetFactory.GetPet(petId));
Exemplo n.º 27
0
 public IActionResult GetAllPets() => Json(PetFactory.GetPets());
Exemplo n.º 28
0
        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;
                }
            }
        }
Exemplo n.º 29
0
        public RoomInstance(uint InstanceId, RoomInfo Info, RoomModel Model)
        {
            mActorSyncRoot = new object();
            mItemSyncRoot  = new object();

            mInstanceId               = InstanceId;
            mInfo                     = Info;
            mActors                   = new Dictionary <uint, RoomActor>();
            mCachedModel              = Model;
            mRelativeHeightmap        = string.Empty;
            mActorIdGenerator         = 1;
            mActorIdGeneratorSyncLock = new object();
            mTileStates               = new TileState[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mUsersWithRights          = new List <uint>();
            mBannedUsers              = new Dictionary <uint, double>();
            mItems                    = new Dictionary <uint, Item>();
            mStaticObjects            = new List <StaticObject>();
            mItemLimitCache           = new Dictionary <ItemBehavior, int>();
            mUserGrid                 = new List <RoomActor> [mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mMusicController          = new RoomMusicController();
            mTemporaryStickieRights   = new Dictionary <uint, uint>();
            mTradeManager             = new TradeManager();
            mRollerItems              = new List <Item> [mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
            mWiredManager             = new WiredManager(this);

            foreach (Bot Bot in BotManager.GenerateBotInstancesForRoom(RoomId))
            {
                AddBotToRoom(Bot);
            }

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                // Items
                MySqlClient.SetParameter("id", RoomId);
                DataTable ItemTable = MySqlClient.ExecuteQueryTable("SELECT * FROM items WHERE room_id = @id");

                foreach (DataRow Row in ItemTable.Rows)
                {
                    Item Item = ItemFactory.CreateFromDatabaseRow(Row, mWiredManager);

                    if (Item.PendingExpiration && Item.ExpireTimeLeft <= 0)
                    {
                        Item.RemovePermanently(MySqlClient);
                        continue;
                    }

                    if (Item.InSoundManager)
                    {
                        continue;
                    }

                    mItems.Add(Item.Id, Item);
                    IncrecementFurniLimitCache(Item.Definition.Behavior);

                    ItemEventDispatcher.InvokeItemEventHandler(null, Item, this, ItemEventType.InstanceLoaded);
                }

                // Static objects
                MySqlClient.SetParameter("id", RoomId);
                DataTable StaticObjectTable = MySqlClient.ExecuteQueryTable("SELECT id,name,position,height,rotation,is_seat FROM static_objects WHERE room_id = @id");

                foreach (DataRow Row in StaticObjectTable.Rows)
                {
                    mStaticObjects.Add(new StaticObject((uint)Row["id"], (string)Row["name"], Vector2.FromString((string)Row["position"]),
                                                        (int)Row["height"], (int)Row["rotation"], (Row["is_seat"].ToString() == "1")));
                }

                // Rights
                MySqlClient.SetParameter("id", RoomId);
                DataTable RightsTable = MySqlClient.ExecuteQueryTable("SELECT user_id FROM room_rights WHERE room_id = @id");

                foreach (DataRow Row in RightsTable.Rows)
                {
                    mUsersWithRights.Add((uint)Row["user_id"]);
                }

                // Pets
                MySqlClient.SetParameter("id", RoomId);
                DataTable PetsTable = MySqlClient.ExecuteQueryTable("SELECT * FROM pets WHERE room_id = @id");

                foreach (DataRow Row in PetsTable.Rows)
                {
                    Pet PetData = PetFactory.GetPetFromDatabaseRow(Row);

                    AddBotToRoom(BotManager.CreateNewInstance(BotManager.GetHandlerDefinitionForPetType(PetData.Type),
                                                              RoomId, Vector3.FromString(Row["room_pos"].ToString()), PetData));
                }
            }

            RegenerateRelativeHeightmap();

            mUpdater = new Timer(new TimerCallback(PerformUpdate), null, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));
        }
Exemplo n.º 30
0
    static void Main()
    {
        IPet cat = PetFactory.Create("cat");

        cat.Show();
    }