public List <FishItem> GetAllFishes()
        {
            List <FishItem> fishes = new List <FishItem>();
            SqlDataReader   reader = null;

            using (SqlConnection _conn = new SqlConnection(connectionString))
            {
                _conn.Open();
                SqlCommand cmd = new SqlCommand("GetAllFishes", _conn);
                cmd.CommandType = CommandType.StoredProcedure;
                reader          = cmd.ExecuteReader();

                while (reader.Read())
                {
                    int    id          = Convert.ToInt32(reader["FishID"]);
                    string name        = Convert.ToString(reader["Name"]);
                    int    isRaw       = Convert.ToInt32(reader["IsRaw"]);
                    int    healValue   = Convert.ToInt32(reader["HealValue"]);
                    int    value       = Convert.ToInt32(reader["Value"]);
                    string description = Convert.ToString(reader["Description"]);
                    bool   isRawBool   = false;

                    if (isRaw == 1)
                    {
                        isRawBool = true;
                    }

                    FishItem fish = new FishItem(id, name, isRawBool,
                                                 healValue, value, description);
                    fishes.Add(fish);
                }
            }
            return(fishes);
        }
Example #2
0
        public void CookFish(Character character, string fishItem)
        {
            bool cookedFish = false;

            //Loop trough all the fishes of a character to see if it matches with the string parameter of this method
            foreach (FishItem myFishItem in character.myFishItems)
            {
                if (myFishItem.Name == fishItem)
                {
                    if (myFishItem.Amount > 0)
                    {
                        //Withdraw this fish from the players inventory and set bool so we know we cooked the fish
                        myFishItem.AddToAmount(-1);
                        cookedFish = true;
                    }
                }
            }

            if (cookedFish)
            {
                bool     addedFish     = false;
                FishItem fishItemToAdd = new FishItem();

                //Add cooked fish to characters inventory
                string fishToAdd = fishItem.Replace("Raw ", "");

                //Checks if we already have this item so we can increase the amount by one
                foreach (FishItem myFishItems in character.myFishItems)
                {
                    //we allready have the item
                    if (myFishItems.Name == fishToAdd && addedFish == false)
                    {
                        myFishItems.AddToAmount(1);
                        character.CookingExperience += 44;
                        addedFish = true;
                    }
                }

                //we don't have this item yet
                if (addedFish == false)
                {
                    foreach (FishItem allfishItem in fishContainerRepository.GetAllFishes())
                    {
                        if (fishToAdd == allfishItem.Name)
                        {
                            fishItemToAdd        = allfishItem;
                            fishItemToAdd.Amount = 1;
                            fishItemToAdd.Name   = fishToAdd;
                            character.myFishItems.Add(fishItemToAdd);
                            character.CookingExperience += 44;
                        }
                    }
                }
            }
        }
        public void CookFish_CooksLobster_ReturnsCharacterWithLobster()
        {
            //arange
            FishItem fishItem = new FishItem(1, "Raw Lobster", true, 0, 0, "");

            fishItem.Amount = 1;
            character.myFishItems.Add(fishItem);

            //act
            cookingLogic.CookFish(character, "Raw Lobster");
            string fishInInventory = "";

            foreach (var myFishItem in character.myFishItems)
            {
                fishInInventory = myFishItem.Name;
            }

            //assert
            Assert.That(fishInInventory, Is.EqualTo("Lobster"));
        }
Example #4
0
        /* GameEvents_OnUpdateTick
         * Triggers 60 times per second.
         * Use one of the methods here https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Events#Game for other time durations
         */
        private void GameEvents_OnUpdateTick(object sender, EventArgs e)
        {
            if (Game1.player.CurrentTool is FishingRod rod)
            {
                if (rod.fishCaught && !this.PlayerReceivedFish)
                {
                    // Prevents the mod from giving the player 1 fish per tick ;)
                    this.PlayerReceivedFish = true;

                    this.whichFish = this.Helper.Reflection.GetField <int>(rod, "whichFish").GetValue();

                    // construct a temporary fish item to figure out what the caught fish's name is
                    FishItem tempFish = new FishItem(this.whichFish);

                    if (tempFish.Category == -4)   // is a fish

                    // get the list of fish in the Population with that name
                    {
                        List <FishModel> fishOfType;
                        this.population.TryGetValue(tempFish.Name, out fishOfType);

                        // get a random fish of that type from the population
                        int       numFishOfType     = fishOfType.Count;
                        int       selectedFishIndex = ModEntry.rand.Next(0, numFishOfType);
                        FishModel selectedFish      = fishOfType[selectedFishIndex];

                        this.Helper.Reflection.GetField <int>(rod, "fishSize").SetValue((int)Math.Round(selectedFish.length));

                        // store a new custom fish item
                        Item customFish = (Item) new FishItem(this.whichFish, selectedFish);
                        FishItem.itemToAdd = customFish as FishItem;
                        this.FishCaught    = customFish;

                        // make sure the fish in the ocean will be regenerated at the end of the day
                        this.AllFishCaughtToday.Add(new Tuple <string, int>(selectedFish.name, selectedFish.uniqueID));

                        // Prompt the player to throw back the fish
                        this.PromptThrowBackFish(selectedFish.name, selectedFish.uniqueID);
                    }
                }
            }


            if (Game1.activeClickableMenu is BobberBar && this.Bobber != null)
            {
                SBobberBar bobber = this.Bobber;

                if (!this.BeganFishingGame)
                {
                    this.OnFishingBegin();
                    this.PlayerReceivedFish = false;
                    this.BeganFishingGame   = true;
                }
            }
            else if (this.EndedFishingGame)
            {
                this.OnFishingEnd();
                this.EndedFishingGame = false;
            }
            else if (this.BeganFishingGame)
            {
                {}

                this.EndedFishingGame = true;
                this.BeganFishingGame = false;
            }
        }
Example #5
0
 private void OnTriggerEnter(Collider obj)
 {
     CurrentItemCollisioning = obj.GetComponent <FishItem> ();
 }
Example #6
0
 public void Catched()
 {
     CurrentItemCollisioning.RestartPosition();
     CurrentItemCollisioning = null;
 }
Example #7
0
 private void OnTriggerExit(Collider obj)
 {
     CurrentItemCollisioning = null;
 }
Example #8
0
	private void OnTriggerEnter(Collider obj)
	{
		CurrentItemCollisioning = obj.GetComponent<FishItem> ();
	}
Example #9
0
	public void Catched ()
	{
		CurrentItemCollisioning.RestartPosition ();
		CurrentItemCollisioning = null;
	}
Example #10
0
	private void OnTriggerExit(Collider obj)
	{
		CurrentItemCollisioning = null;
	}