예제 #1
0
        public void CreatePotion(Flask flask, Solvent solvent, Ingredient[] ingredients, Apothecary apothecary)
        {
            var potion = new Potion(flask, solvent, ingredients);

            this.PotionsForSale.Add(potion);

            this.RemovePotionMaterials(flask, solvent, ingredients);

            this.OnPotionCreated(potion, apothecary);
        }
예제 #2
0
        private void CreatePotion(object sender, IntEventArgs e)
        {
            if (World.Instance.Random.Next(0, 100) > 30)
            {
                return;
            }

            foreach (var potionPrototype in World.Instance.Shop.PotionPrototypes)
            {
                Flask flask = null;

                foreach (var shopFlask in World.Instance.Shop.Flasks)
                {
                    if (shopFlask.Name == potionPrototype.FlaskName)
                    {
                        flask = shopFlask;

                        break;
                    }
                }

                if (flask == null)
                {
                    continue;
                }

                Solvent solvent = null;

                var ingredients = new List <Ingredient>();

                foreach (var herbName in potionPrototype.HerbNames)
                {
                    foreach (var shopHerb in World.Instance.Shop.Herbs)
                    {
                        if (shopHerb.Name == herbName)
                        {
                            ingredients.Add(shopHerb);

                            break;
                        }
                    }
                }

                if (ingredients.Count != potionPrototype.IngredientCount)
                {
                    continue;
                }

                this.potionsCrafted++;

                World.Instance.Shop.CreatePotion(flask, solvent, ingredients.ToArray(), this);

                break;
            }
        }
예제 #3
0
        public void SellFlask(Flask flask)
        {
            if (!this.Shop.PurchaseFlask(flask))
            {
                return;
            }

            this.Flasks.Remove(flask);

            this.OnFlaskSold(flask);
        }
예제 #4
0
        private void RemovePotionMaterials(Flask flask, Solvent solvent, Ingredient[] ingredients)
        {
            this.DiscardFlask(flask);

            // DiscardSolvent(solvent);

            foreach (var ingredient in ingredients)
            {
                this.DiscardIngredient(ingredient);
            }
        }
예제 #5
0
        public bool PurchaseFlask(Flask flask)
        {
            if (this.Gold < flask.Value)
            {
                return(false);
            }

            this.Gold -= flask.Value;

            this.Flasks.Add(flask);

            this.OnFlaskBought(flask);

            return(true);
        }
예제 #6
0
        public void ResearchPotion(Flask flask, Solvent solvent, Ingredient[] ingredients)
        {
            foreach (var ingredient in ingredients)
            {
                Debug.Log(ingredient.Name);
            }
            var potion = new Potion(flask, solvent, ingredients);

            if (!this.AddPotionPrototype(potion))
            {
                return;
            }

            this.RemovePotionMaterials(flask, solvent, ingredients);

            this.OnPotionResearched(potion);
        }
예제 #7
0
        public Potion(Flask flask, Solvent solvent, Ingredient[] ingredients)
        {
            var herbNames = new List <string>();

            // var otherTypeNames = new List<string>();

            foreach (var ingredient in ingredients)
            {
                if (ingredient is Herb)
                {
                    herbNames.Add(ingredient.Name);
                }/* else if (ingredient is OtherType) {
                  * otherTypes.Add(ingredient.Name);
                  * }*/
            }

            var effectsToCheck = new Queue <Effect>();

            foreach (var ingredient in ingredients)
            {
                foreach (var effect in ingredient.Effects)
                {
                    effectsToCheck.Enqueue(effect);
                }
            }

            var effects = new List <Effect>();

            while (effectsToCheck.Count > 0)
            {
                var currentEffect = effectsToCheck.Dequeue();

                foreach (var effect in effectsToCheck)
                {
                    var combinedEffect = currentEffect.Combine(effect);

                    if (combinedEffect != null)
                    {
                        effects.Add(combinedEffect);
                    }
                }
            }

            var name = flask.Quality.ToString() + " Potion of ";

            for (var i = 0; i < effects.Count; i++)
            {
                name += effects[i].Name;

                if (i < effects.Count - 1)
                {
                    name += ", ";
                }
            }

            this.name        = name;
            this.flaskName   = flask.Name;
            this.solventName = solvent == null ? string.Empty : solvent.Name;
            this.herbNames   = herbNames.ToArray();
            // this.otherTypeNames = otherTypeNames.ToArray();
            this.effects = effects.ToArray();
            this.value   = flask.Value * effects.Count;
        }
예제 #8
0
 private void OnFlaskSold(Flask flask) => FlaskSold?.Invoke(this, new FlaskEventArgs(flask));
예제 #9
0
 private void OnFlaskDisplayed(Flask flask) => FlaskDisplayed?.Invoke(this, new FlaskEventArgs(flask));
예제 #10
0
        public void DisplayFlask(Flask flask)
        {
            this.Flasks.Add(flask);

            this.OnFlaskDisplayed(flask);
        }
예제 #11
0
 public FlaskEventArgs(Flask flask)
 {
     this.Flask = flask;
 }
예제 #12
0
 private void OnFlaskBought(Flask flask) => FlaskBought?.Invoke(this, new FlaskEventArgs(flask));
예제 #13
0
        public void DiscardFlask(Flask flask)
        {
            this.Flasks.Remove(flask);

            this.OnFlaskDiscarded(flask);
        }