Example #1
0
        public override void InitializeRecursive(Screen screen)
        {
            if (TrackerSettings.IsPostExplorationUpdate)
            {
                Advancement = screen.AdvancementTracker.Advancement(AdvancementName);
            }
            else
            {
                Advancement = screen.AchievementTracker.Achievement(AdvancementName);
            }
            if (Advancement == null)
            {
                return;
            }

            Name = Advancement.ID;
            int textScale = scale < 3 ? 1 : 2;

            FlexWidth  *= Math.Min(scale + textScale - 1, 4);
            FlexHeight *= scale;

            if (TrackerSettings.IsPostExplorationUpdate)
            {
                Padding = new Margin(0, 0, 4 * scale, 0);
            }
            else
            {
                Padding = new Margin(0, 0, 6, 0);
            }

            frame = GetControlByName("frame", true) as UIPicture;
            if (frame != null)
            {
                frame.FlexWidth  *= scale;
                frame.FlexHeight *= scale;
            }

            icon = GetControlByName("icon", true) as UIPicture;
            if (icon != null)
            {
                icon.FlexWidth  *= scale;
                icon.FlexHeight *= scale;
                icon.SetTexture(Advancement.Icon);
                icon.SetLayer(Layer.Fore);
            }

            label = GetControlByName("label", true) as UITextBlock;
            if (label != null)
            {
                label.Margin = new Margin(0, 0, (int)frame.FlexHeight.InternalValue, 0);
                label.SetFont("minecraft", 12 * textScale);
                label.SetText(Advancement.Name);

                if (TrackerSettings.IsPreExplorationUpdate && screen is MainScreen)
                {
                    label.DrawBackground = true;
                }
            }
            base.InitializeRecursive(screen);
        }
 static public void InitializeResearchPanel(
     DBClass typeBypass,
     GameObject source,
     Dictionary <DBClass, GameObject> unlockToGO,
     Advancement screen,
     string addFilter)
 {
     try
     {
         Type t = typeBypass.GetType();
         if (t == typeof(Resource))
         {
             var r = Globals.GetTypeFromDBAsDBClass <Resource>();
             ResearchPanelConstruction(source, unlockToGO, r, screen, addFilter, 1f, 1f);
         }
         else if (t == typeof(ItemTech))
         {
             var r = Globals.GetTypeFromDBAsDBClass <ItemTech>();
             ResearchPanelConstruction(source, unlockToGO, r, screen, addFilter, 2f, 1.1f);
         }
         else if (t == typeof(BuildingTech))
         {
             var r = Globals.GetTypeFromDBAsDBClass <BuildingTech>();
             ResearchPanelConstruction(source, unlockToGO, r, screen, addFilter, 1f, .8f);
         }
     }
     catch (Exception e)
     {
         Debug.LogError("[ERROR]\n" + e);
     }
 }
 public AdvancementValue this[Advancement advancement]
 {
     set
     {
         Advancements.Add(advancement, value);
     }
 }
        public async Task InsertAdvancementVanillaTest()
        {
            var adReceivable = new AdvancedReceivable
            {
                AdvancedAmount           = 100L,
                PaymentScheme            = "VCC",
                SettlementObligationDate = DateTime.Now
            };
            var adReceivables = new List <AdvancedReceivable>
            {
                adReceivable
            };
            var adItem = new Advancement
            {
                AssetHolderDocumentType         = DocumentType.CNPJ,
                AssetHolder                     = "74190072000185",
                OperationValue                  = 100L,
                OperationExpectedSettlementDate = DateTime.Now,
                Reference           = "RF_01",
                AdvancedReceivables = adReceivables
            };
            var adItems = new List <Advancement>
            {
                adItem
            };
            var adInput = new AdvancementRequest
            {
                Advancements = adItems
            };
            var result = await _advacementService.InsertAdvancements(adInput);

            Print(result);
        }
Example #5
0
        private void AddAdvancement(string key, Advancement advancement)
        {
            //create new check box for this advancement
            var box = new CheckBox();

            box.Text            = "     " + advancement.Name;
            box.Width           = 175;
            box.Margin          = new Padding(0, 0, 1, 1);
            box.ImageAlign      = ContentAlignment.MiddleLeft;
            box.Appearance      = Appearance.Button;
            box.AutoSize        = false;
            box.Tag             = advancement.Type;
            box.CheckedChanged += OnCheckedChanged;

            //find appropriate image
            if (pngs.TryGetValue(advancement.Icon, out string icon))
            {
                box.Image = SpriteSheet.BitmapFromFile(icon, 16, 16);
            }
            else if (pngs.TryGetValue(advancement.Icon + SpriteSheet.RESOLUTION_PREFIX + "16", out icon))
            {
                box.Image = SpriteSheet.BitmapFromFile(icon, 16, 16);
            }
            else if (gifs.TryGetValue(advancement.Icon, out icon))
            {
                box.Image = Image.FromFile(icon);
            }

            advancementBoxes[key] = box;
            advancements.Controls.Add(box);
        }
Example #6
0
        //Validates that the player can afford the requested advancements
        public bool CheckPlayerCanAffordAdvancements(int[] advancements)
        {
            //Gather discount information
            int artDiscount      = ActiveCiv.GetTotalArtCredit();
            int civicDiscount    = ActiveCiv.GetTotalCivicCredit();
            int craftDiscount    = ActiveCiv.GetTotalCraftCredit();
            int religionDiscount = ActiveCiv.GetTotalReligionCredit();
            int scienceDiscount  = ActiveCiv.GetTotalScienceCredit();
            int specificDiscount = 0;

            int totalPrice = 0;

            //For each advancement the player wishes to buy...
            foreach (int advancementId in advancements)
            {
                Advancement candidateAdvance = GameContext.Advancements.Find(advancementId);

                //Get any discounts for specifically this advance
                specificDiscount = ActiveCiv.GetDiscountForAdvancement(candidateAdvance);

                totalPrice += candidateAdvance.GetDiscountedPrice(
                    artDiscount,
                    civicDiscount,
                    craftDiscount,
                    religionDiscount,
                    scienceDiscount,
                    specificDiscount
                    );
            }

            //Return whether the total price is less than or equal to the spending limit
            return(totalPrice <= ActiveCiv.SpendLimit);
        }
        public async Task CanGetDetails()
        {
            int testAdvancementId = 2;

            //Get a test controller
            GameContext gameContext = GetTestContext("test_details");

            foreach (Ability ability in Iteration1Seeder.GetSeedAbilities())
            {
                gameContext.Abilities.Add(ability);
            }
            gameContext.SaveChanges();

            AdvancementsController testController = new AdvancementsController(gameContext);

            //Run the controller's Details()
            IActionResult result = await testController.Details(testAdvancementId);

            //Assert that...
            //...we got a view back
            ViewResult viewResult = Assert.IsType <ViewResult>(result);
            //...the view is an advancement
            Advancement model = Assert.IsAssignableFrom <Advancement>(viewResult.ViewData.Model);

            //...the abilities for the advancement are present
            Assert.Equal(gameContext.Abilities.Where(a => a.AdvancementId == testAdvancementId).Count(), model.Abilities.Count());
        }
Example #8
0
        public void AddAdvancement(Advancement advancement)
        {
            string path = Path + "/advancements/" + advancement.Id.ParentPath;

            Directory.CreateDirectory(path);
            File.WriteAllText(path + "/" + advancement.Id.Last + ".json", advancement.ToJson());
        }
Example #9
0
        public void CanGetDiscountForAdvancement(int[] grantors, int expectedDiscount)
        {
            int         advancementId   = 1;
            Advancement testAdvancement = new Advancement {
                Id = advancementId
            };

            Collection <OwnedAdvancement> owned = new Collection <OwnedAdvancement>();

            foreach (int grantor in grantors)
            {
                owned.Add(
                    new OwnedAdvancement {
                    Advancement = new Advancement {
                        Id = grantor,
                        CreditAdvancementId    = advancementId,
                        CreditAdvancementValue = 10
                    }
                }
                    );
            }

            ActiveCiv testCiv = new ActiveCiv {
                OwnedAdvancements = owned
            };

            int actualDiscount = testCiv.GetDiscountForAdvancement(testAdvancement);

            Assert.Equal(expectedDiscount, actualDiscount);
        }
Example #10
0
        private void AdventureBtn_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.Hide();
            Advancement adv = new Advancement(debugMode);

            adv.ShowDialog();
            this.Close();
        }
Example #11
0
    public void WriteAdvancement(Advancement advancement)
    {
        var hasParent = !string.IsNullOrEmpty(advancement.Parent);

        this.WriteBoolean(hasParent);

        if (hasParent)
        {
            this.WriteString(advancement.Parent);
        }

        var hasDisplay = advancement.Display != null;

        this.WriteBoolean(hasDisplay);

        if (hasDisplay)
        {
            this.WriteChat(advancement.Display.Title);
            this.WriteChat(advancement.Display.Description);

            this.WriteItemStack(Registry.GetSingleItem(advancement.Display.Icon.Type));

            this.WriteVarInt(advancement.Display.AdvancementFrameType);

            this.WriteInt((int)advancement.Display.Flags);

            if (advancement.Display.Flags.HasFlag(AdvancementFlags.HasBackgroundTexture))
            {
                this.WriteString(advancement.Display.BackgroundTexture);
            }

            this.WriteFloat(advancement.Display.XCoord);
            this.WriteFloat(advancement.Display.YCoord);
        }

        this.WriteVarInt(advancement.Criteria.Count);

        foreach (var criteria in advancement.Criteria)
        {
            this.WriteString(criteria.Identifier);
        }

        var reqired = advancement.Criteria.Where(x => x.Required);

        //For some reason this takes a array of an array??
        if (reqired.Any())
        {
            //Always gonna be 1 for now
            this.WriteVarInt(1);

            this.WriteVarInt(reqired.Count());

            foreach (var criteria in reqired)
            {
                this.WriteString(criteria.Identifier);
            }
        }
    }
Example #12
0
        public static string ToConciseString(this Advancement advancement)
        {
            switch (advancement)
            {
            case Advancement.Advances:
                return("ADVN");

            case Advancement.Wildcard:
                return("WILD");

            case Advancement.Eliminated:
                return("ELIM");
            }

            throw new ArgumentOutOfRangeException();
        }
Example #13
0
        public override void InitializeRecursive(Screen screen)
        {
            if (TrackerSettings.IsPostExplorationUpdate)
            {
                advancement = screen.AdvancementTracker.Advancement(AdvancementName);
            }
            else
            {
                advancement = screen.AchievementTracker.Achievement(AdvancementName);
            }
            if (advancement == null)
            {
                return;
            }

            goalName = advancement.CriteriaGoal;

            var adv = GetFirstOfType(typeof(UIAdvancement), true) as UIAdvancement;

            if (adv != null)
            {
                adv.AdvancementName = AdvancementName;
            }

            var flow = GetFirstOfType(typeof(UIFlowPanel), true) as UIFlowPanel;

            if (flow != null)
            {
                foreach (var criterion in advancement.Criteria)
                {
                    var crit = new UICriterion();
                    crit.AdvancementName = AdvancementName;
                    crit.CriterionName   = criterion.Key;
                    flow.AddControl(crit);
                }
            }

            label = GetControlByName("progress", true) as UITextBlock;
            bar   = GetControlByName("bar", true) as UIProgressBar;
            bar?.SetMax(advancement.Criteria.Count);

            base.InitializeRecursive(screen);
        }
Example #14
0
        /*
         * Generates a collection of owned advancements with the specified credit values and credit category
         */
        private ICollection <OwnedAdvancement> PrepareMockOwnedAdvancements(int[] credits, Advancement.Category category)
        {
            ICollection <OwnedAdvancement> ownedAdvancements = new Collection <OwnedAdvancement>();

            foreach (int credit in credits)
            {
                //TODO: swap these to mocked versions
                Advancement advancement = new Advancement();
                switch (category)
                {
                case Advancement.Category.Art:
                    advancement.CreditArt = credit;
                    break;

                case Advancement.Category.Civic:
                    advancement.CreditCivic = credit;
                    break;

                case Advancement.Category.Craft:
                    advancement.CreditCraft = credit;
                    break;

                case Advancement.Category.Religion:
                    advancement.CreditReligion = credit;
                    break;

                case Advancement.Category.Science:
                    advancement.CreditScience = credit;
                    break;
                }

                ownedAdvancements.Add(
                    new OwnedAdvancement
                {
                    Advancement = advancement
                }
                    );
            }

            return(ownedAdvancements);
        }
        public void CanGetDiscountedPrice(int baseCost, bool[] categories, int[] discounts, int expectedPrice)
        {
            Advancement advancement = new Advancement
            {
                BaseCost   = baseCost,
                IsArt      = categories[0],
                IsCivic    = categories[1],
                IsCraft    = categories[2],
                IsReligion = categories[3],
                IsScience  = categories[4],
            };

            int actualPrice = advancement.GetDiscountedPrice(
                discounts[0],
                discounts[1],
                discounts[2],
                discounts[3],
                discounts[4],
                discounts[5]
                );

            Assert.Equal(expectedPrice, actualPrice);
        }
 public BuyBuildingAction(Advancement building)
 {
     this.Id   = building.Id;
     this.Cost = building.Cost;
 }
 public DemolishBuildingAction(Advancement building)
 {
     this.Id = building.Id;
 }
 public AdvancementsArgument Done(Advancement a)
 {
     Advancements.Add(a, true);
     return(this);
 }
 public AdvancementsArgument NotDone(Advancement a)
 {
     Advancements.Add(a, false);
     return(this);
 }
 public AdvancementsArgument DoneSpecific(Advancement a, Dictionary <string, bool> Criteria)
 {
     Advancements.Add(a, Criteria);
     return(this);
 }
        static void ResearchPanelConstruction(GameObject source,
                                              Dictionary <DBClass, GameObject> unlockToGO,
                                              List <DBClass> sources,
                                              Advancement screen,
                                              string addFilter,
                                              float radiusMultiplier,
                                              float horizontalSpreadMultiplier)
        {
            int   circleRadius        = 160;
            float spreadAngleDistance = 360 / 20f;

            var r = sources;


            if (addFilter == "food items")
            {
                r = r.FindAll(o => FilterCooking(o));
            }
            else if (addFilter == "nonfood items")
            {
                r = r.FindAll(o => FilterNonCooking(o));
            }

            List <List <DBClass> > structure = new List <List <DBClass> >();
            HashSet <DBClass>      listed    = new HashSet <DBClass>();

            Dictionary <DBClass, Vector3> resourcePositions = new Dictionary <DBClass, Vector3>();

            float layoutRadius   = circleRadius * radiusMultiplier;
            float spreadDistance = spreadAngleDistance / horizontalSpreadMultiplier;
            int   k = 0;

            while (listed.Count < r.Count)
            {
                k++;
                if (k > 10)
                {
                    break;
                }
                List <DBClass> layer = new List <DBClass>();
                structure.Add(layer);
                if (!SortingSources(r, listed, layer))
                {
                    break;
                }
            }

            for (var l = 0; l < structure.Count; l++)
            {
                if (l == 0)
                {
                    float count = structure[l].Count;
                    for (int i = 0; i < count; i++)
                    {
                        Quaternion q = Quaternion.Euler(0, 0, 360 * i / count);

                        Vector3 dir = q * (new Vector3(0, 1, 0) * layoutRadius);

                        DBClass    res = structure[l][i];
                        GameObject s   = GameObjectUtils.Instantiate(source, source.transform.parent);
                        GameObject go  = screen.PopulateNode(s, res);
                        go.transform.localPosition = dir;
                        resourcePositions[res]     = dir;
                        unlockToGO[res]            = go;

                        VectorLine vl = screen.DrawLink(go, go.transform.parent.gameObject);

                        screen.RegisterLine(res, null, vl);

                        DBClass resRef = Globals.GetInstanceFromDB(go.name);
                        go.GetComponent <Button>().onClick.AddListener(delegate()
                        {
                            if (resRef is Resource)
                            {
                                screen.Click(resRef as Resource);
                            }
                            else if (resRef is ItemTech)
                            {
                                screen.Click(resRef as ItemTech);
                            }
                            else if (resRef is BuildingTech)
                            {
                                screen.Click(resRef as BuildingTech);
                            }
                        });

                        Image icon = GameObjectUtils.FindByNameGetComponent <Image>(go, "Bg");
                        icon.alphaHitTestMinimumThreshold = 0.5f;

                        var st = GameObjectUtils.GetOrAddComponent <RolloverSimpleTooltip>(icon.gameObject);
                        if (resRef is Resource)
                        {
                            var stRes = resRef as Resource;
                            st.title       = stRes.descriptionInfo.name;
                            st.imageName   = stRes.descriptionInfo.iconName;
                            st.description = stRes.descriptionInfo.description;
                        }
                        else if (resRef is ItemTech)
                        {
                            var stIT = resRef as ItemTech;
                            st.title       = stIT.descriptionInfo.name;
                            st.imageName   = stIT.descriptionInfo.iconName;
                            st.description = stIT.descriptionInfo.description;
                        }
                        else if (resRef is BuildingTech)
                        {
                            var stBT = resRef as BuildingTech;
                            st.title       = stBT.descriptionInfo.name;
                            st.imageName   = stBT.descriptionInfo.iconName;
                            st.description = stBT.descriptionInfo.description;
                        }
                    }
                }
                else
                {
                    List <DBClass> layer = structure[l];
                    while (layer.Count > 0)
                    {
                        DBClass res = layer[0];
                        if (GetParents(res) == null)
                        {
                            break;
                        }

                        List <DBClass> group = layer.FindAll(o => GetParents(o) != null &&
                                                             (o == res ||
                                                              (
                                                                  GetParents(o).All(GetParents(res).Contains) &&
                                                                  GetParents(res).All(GetParents(o).Contains)
                                                              )
                                                             )
                                                             );
                        layer = layer.FindAll(o => !group.Contains(o));

                        Vector3 cumulativeOffset = Vector3.zero;
                        int     count            = 0;
                        foreach (var v in GetParents(res))
                        {
                            cumulativeOffset += resourcePositions[v];
                            count++;
                        }

                        Vector3 groupDir = (cumulativeOffset / count).normalized;

                        for (int i = 0; i < group.Count; i++)
                        {
                            res = group[i];

                            float      steps = i - (group.Count - 1) * 0.5f;
                            Quaternion q     = Quaternion.Euler(0, 0, steps * spreadDistance);
                            Vector3    dir   = q * groupDir;

                            //First radius is multiplied based on the extra settings to ensure this distance is set on screen basis
                            //Second and further are spread by default distance
                            dir = dir.normalized * layoutRadius +
                                  dir.normalized * circleRadius * l;

                            GameObject s  = GameObjectUtils.Instantiate(source, source.transform.parent);
                            GameObject go = screen.PopulateNode(s, res);
                            go.transform.localPosition = dir;
                            resourcePositions[res]     = dir;
                            unlockToGO[res]            = go;

                            foreach (var v in GetParents(res))
                            {
                                VectorLine vl = screen.DrawLink(unlockToGO[res], unlockToGO[v]);
                                screen.RegisterLine(v, res, vl);
                            }

                            DBClass resRef = Globals.GetInstanceFromDB(go.name);
                            go.GetComponent <Button>().onClick.AddListener(delegate()
                            {
                                if (resRef is Resource)
                                {
                                    screen.Click(resRef as Resource);
                                }
                                else if (resRef is ItemTech)
                                {
                                    screen.Click(resRef as ItemTech);
                                }
                                else if (resRef is BuildingTech)
                                {
                                    screen.Click(resRef as BuildingTech);
                                }
                            });

                            Image icon = GameObjectUtils.FindByNameGetComponent <Image>(go, "Bg");
                            icon.alphaHitTestMinimumThreshold = 0.5f;

                            var st = GameObjectUtils.GetOrAddComponent <RolloverSimpleTooltip>(icon.gameObject);
                            if (resRef is Resource)
                            {
                                var stRes = resRef as Resource;
                                st.title       = stRes.descriptionInfo.name;
                                st.imageName   = stRes.descriptionInfo.iconName;
                                st.description = stRes.descriptionInfo.description;
                            }
                            else if (resRef is ItemTech)
                            {
                                var stIT = resRef as ItemTech;
                                st.title       = stIT.descriptionInfo.name;
                                st.imageName   = stIT.descriptionInfo.iconName;
                                st.description = stIT.descriptionInfo.description;
                            }
                            else if (resRef is BuildingTech)
                            {
                                var stBT = resRef as BuildingTech;
                                st.title       = stBT.descriptionInfo.name;
                                st.imageName   = stBT.descriptionInfo.iconName;
                                st.description = stBT.descriptionInfo.description;
                            }
                        }
                    }
                }
            }

            GameObject.Destroy(source);
        }
Example #22
0
 public UnlockUpgradeAction(Advancement upgrade)
 {
     this.Id   = upgrade.Id;
     this.Cost = upgrade.Cost;
 }
 public AdvanceToEraAction(Advancement advancement)
 {
     this.Id   = advancement.Id;
     this.Cost = advancement.Cost;
 }