Exemplo n.º 1
0
        public bool Equals(CreatureTrait p)
        {
            if ((object)p == null)
            {
                return(false);
            }

            return(this.CreatureTraitId == p.CreatureTraitId);
        }
Exemplo n.º 2
0
            internal static int GetDefaultValue(CreatureTrait trait)
            {
                int result;

                if (!DefaultTraitValues.TryGetValue(trait.CreatureTraitId, out result))
                {
                    //todo
                    //Logger.LogError("no default value found for trait: " + trait.Trait.ToString());
                }
                return(result);
            }
Exemplo n.º 3
0
 internal static float GetAhSkillForTrait(CreatureTrait creatureTrait, bool epicCurve)
 {
     if (epicCurve)
     {
         return(EnumToAhSkillMapEpic[creatureTrait.CreatureTraitId]);
     }
     else
     {
         return(EnumToAhSkillMapFreedom[creatureTrait.CreatureTraitId]);
     }
 }
Exemplo n.º 4
0
            internal static string GetShortcutForTrait(CreatureTrait trait, int value)
            {
                string prefix = string.Empty;

                if (value > 0)
                {
                    prefix = "+";
                }
                if (value < 0)
                {
                    prefix = "-";
                }
                return(prefix + EnumToShortcutMap[trait.CreatureTraitId]);
            }
Exemplo n.º 5
0
        public override bool Equals(System.Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            CreatureTrait p = obj as CreatureTrait;

            if ((System.Object)p == null)
            {
                return(false);
            }

            return(this.CreatureTraitId == p.CreatureTraitId);
        }
Exemplo n.º 6
0
        public TraitViewManager(
            [NotNull] FormGrangerMain mainForm,
            [NotNull] GrangerContext context,
            [NotNull] ObjectListView listview)
        {
            if (mainForm == null)
            {
                throw new ArgumentNullException(nameof(mainForm));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (listview == null)
            {
                throw new ArgumentNullException(nameof(listview));
            }
            this.mainForm = mainForm;
            this.context  = context;
            this.olv      = listview;

            olv.FormatRow += OLV_FormatRow;

            allTraits = CreatureTrait.GetAllTraitEnums().Select(x => new CreatureTrait(x)).ToArray();
            BuildClearTraitView();

            listview.SetObjects(items);
            Decide();

            this.mainForm.GrangerSelectedSingleCreatureChanged += MainFormGrangerSelectedCreaturesChanged;
            this.mainForm.GrangerValuatorChanged             += MainForm_Granger_ValuatorChanged;
            this.mainForm.GrangerTraitViewDisplayModeChanged += MainForm_Granger_TraitViewDisplayModeChanged;
            this.context.OnHerdsModified       += Context_OnHerdsModified;
            this.context.OnCreaturesModified   += ContextOnCreaturesModified;
            this.context.OnTraitValuesModified += Context_OnTraitValuesModified;
        }
Exemplo n.º 7
0
 private static float GetSkillForTrait(CreatureTrait creatureTrait, bool epicCurve)
 {
     return(Helper.GetAhSkillForTrait(creatureTrait, epicCurve));
 }
Exemplo n.º 8
0
 public static int GetDefaultValue(CreatureTrait trait)
 {
     return(Helper.GetDefaultValue(trait));
 }
Exemplo n.º 9
0
 internal static string GetCompactNameForTrait(CreatureTrait creatureTrait)
 {
     return(EnumToCompactNameMap[creatureTrait.CreatureTraitId]);
 }
Exemplo n.º 10
0
        void SetupOlvCustomizations()
        {
            // GroupKeyGetter needs to be IComparable (non generic) to properly support ordering,
            // GroupKeyToTitleConverter converts that key into something more meaningful to display
            // AspectToStringConverter converts aspect into custom display string

            olvColumnPairedWith.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Creature creature = (Creature)x;
                Creature mate     = creature.GetMate();
                if (mate != null)
                {
                    string[] output = new string[2] {
                        creature.ToString(), mate.ToString()
                    };
                    return(string.Join(" + ", output.OrderBy(y => y)));
                }
                else
                {
                    return("Free");
                }
            });

            olvColumnValue.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Creature creature = (Creature)x;
                if (creature.Value >= 0)
                {
                    return("Positive");
                }
                else
                {
                    return("Negative");
                }
            });
            olvColumnValue.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                return(x.ToString());
            });

            olvColumnBreedValue.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Creature creature = (Creature)x;
                double?val        = creature.BreedValueAspect;
                if (val == null)
                {
                    return("Being Compared / Not comparing");
                }
                else
                {
                    return("Candidates");
                }
            });
            olvColumnBreedValue.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                if (x is double)
                {
                    double val = (double)x;
                    if (val == double.NegativeInfinity)
                    {
                        return("-inf");
                    }
                    else
                    {
                        return(val.ToString("F0"));
                    }
                }
                else if (x == null)
                {
                    return(string.Empty);
                }
                else
                {
                    return(x.ToString());
                }
            });

            olvColumnTraits.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Creature creature         = (Creature)x;
                var traits                = creature.Traits;
                CreatureTrait[] positives = CreatureTrait.GetGoodTraits(traits, this.mainForm.CurrentValuator);
                CreatureTrait[] negatives = CreatureTrait.GetBadTraits(traits, this.mainForm.CurrentValuator);
                return(string.Format("Good: {0}, Neutral: {1}, Bad: {2}",
                                     positives.Length,
                                     traits.Length - positives.Length - negatives.Length,
                                     negatives.Length));
            });

            olvColumnTraitsInspectedAt.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Creature creature = (Creature)x;
                var traitinfo     = creature.TraitsInspectedAtSkillAspect;
                if (traitinfo.Skill > CreatureTrait.GetFullTraitVisibilityCap(traitinfo.EpicCurve))
                {
                    return("Fully known");
                }
                else
                {
                    return("Known partially");
                }
            });

            olvColumnAge.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                CreatureAge age = ((Creature)x).Age;
                return((int)age.CreatureAgeId);
            });
            olvColumnAge.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
            {
                int result = (int)x;
                return(new CreatureAge(result.ToString()).ToString());
            });

            olvColumnNotInMoodFor.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Creature creature = (Creature)x;
                TimeSpan tms      = creature.NotInMoodForAspect;// notInMoodUntil - DateTime.Now;
                if (tms.TotalDays >= 0)
                {
                    return(0); // "Not in mood";
                }
                else
                {
                    return(1); // "In mood";
                }
            });
            olvColumnNotInMoodFor.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                if (x is TimeSpan)
                {
                    TimeSpan ts = (TimeSpan)x;
                    if (ts.TotalDays >= 0)
                    {
                        return(ts.ToStringCompact());
                    }
                    else
                    {
                        return(string.Empty);
                    }
                }
                else
                {
                    return(string.Empty);
                }
            });
            olvColumnNotInMoodFor.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
            {
                int result = (int)x;
                switch (result)
                {
                case 0:
                    return("Not in mood");

                case 1:
                    return("In mood");

                default:
                    return("");
                }
            });


            olvColumnGroomedAgo.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Creature creature = (Creature)x;
                TimeSpan tms      = creature.GroomedAgoAspect; // DateTime.Now - groomedon;
                if (tms.TotalHours <= 1)
                {
                    return("Less than 1 hour ago");
                }
                else
                {
                    return("More than 1 hour ago");
                }
            });
            olvColumnGroomedAgo.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                if (x is TimeSpan)
                {
                    TimeSpan ts = (TimeSpan)x;
                    if (ts < this.mainForm.Settings.ShowGroomingTime)
                    {
                        return(ts.ToStringCompact());
                    }
                    else
                    {
                        return(string.Empty);
                    }
                }
                else
                {
                    return(string.Empty);
                }
            });
            olvColumnGroomedAgo.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
            {
                return(x.ToString());
            });


            olvColumnPregnantFor.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Creature creature      = (Creature)x;
                DateTime pregnantUntil = creature.PregnantUntil;
                TimeSpan tms           = pregnantUntil - DateTime.Now;

                if (tms.Ticks <= 0)
                {
                    if (tms.TotalDays >= -1)
                    {
                        return(2);                     // "Gave birth within last 24h";
                    }
                    else if (tms.TotalDays >= -7)
                    {
                        return(3);                          // "Gave birth in last 7 days";
                    }
                    else
                    {
                        return(4); // "Not pregnant";
                    }
                }
                else if (tms.TotalDays <= 1)
                {
                    return(0); // "Will give birth within 24h";
                }
                else
                {
                    return(1); // "Will give birth in more than 24h";
                }
            });
            olvColumnPregnantFor.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                if (x is TimeSpan)
                {
                    TimeSpan ts = (TimeSpan)x;
                    if (ts.Ticks >= 0)
                    {
                        return(ts.ToStringCompact());
                    }
                    else
                    {
                        return(string.Empty);
                    }
                }
                else
                {
                    return(string.Empty);
                }
            });
            olvColumnPregnantFor.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
            {
                int group = (int)x;
                switch (group)
                {
                case 0:
                    return("Will give birth within 24h");

                case 1:
                    return("Will give birth in more than 24h");

                case 2:
                    return("Gave birth within last 24h");

                case 3:
                    return("Gave birth within last 7 days");

                case 4:
                    return("Not pregnant");

                default:
                    return("");
                }
            });


            olvColumnBirthDate.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Creature creature = (Creature)x;
                return(creature.BirthDate.Date);
            });
            olvColumnBirthDate.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                if (x is DateTime)
                {
                    DateTime dt = (DateTime)x;
                    if (dt < treshholdDtValueForBirthDate)
                    {
                        return(string.Empty);
                    }
                    else
                    {
                        return(dt.ToString(CultureInfo.CurrentCulture));
                    }
                }
                else
                {
                    return(string.Empty);
                }
            });
            olvColumnBirthDate.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
            {
                DateTime dt = (DateTime)x;
                if (dt < treshholdDtValueForBirthDate)
                {
                    return("No birth date available");
                }
                else
                {
                    return(dt.ToShortDateString());
                }
            });


            olvColumnExactAge.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Creature creature = (Creature)x;
                var val           = (int)creature.ExactAgeAspect.TotalDays;
                if (val > treshholdDaysValueForExactAge)
                {
                    return(int.MaxValue);
                }
                else
                {
                    return(val);
                }
            });
            olvColumnExactAge.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                if (x is TimeSpan)
                {
                    TimeSpan ts = (TimeSpan)x;
                    if (ts > treshholdTsValueForExactAge)
                    {
                        return(string.Empty);
                    }
                    else
                    {
                        return(ts.ToStringCompact());
                    }
                }
                else
                {
                    return(string.Empty);
                }
            });
            olvColumnExactAge.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
            {
                int gkey = (int)x;
                if (gkey > treshholdDaysValueForExactAge)
                {
                    return("No birth date available");
                }
                else
                {
                    return(string.Format("{0} real days", gkey));
                }
            });
        }