public Relation(int id, int idFirst, int idSecond, TypeRelation type)
 {
     this.Id       = id;
     this.IdFirst  = idFirst;
     this.IdSecond = idSecond;
     this.Type     = type;
 }
Beispiel #2
0
        public RelationSavingEngine(
            IServiceProvider serviceProvider,
            InformationRessource informationRessource,
            PropertyInfo propertyRelation,
            RelationshipJsonApiAttribute relationshipJApiAttribute,
            object idRessourceParent)
        {
            this._serviceProvider      = serviceProvider;
            this._informationRessource = informationRessource;
            this._relationProperty     = propertyRelation;
            this._idRessourceParent    = idRessourceParent;

            (PropertyInfo foreignKeyProperty, ForeignKeyJsonApiAttribute foreignKeyAttribute) =
                AttributeRelationsHandling.FindForeignKeyPropertyAndAttribute(this._informationRessource.TypeRessource, this._relationProperty.Name);

            if (foreignKeyProperty == null && foreignKeyAttribute == null)
            {
                throw new JsonApiArchitectureException($"ForeignKeyJsonApi manquant pour {this._relationProperty.Name} dans {this._informationRessource.TypeRessource.Name}, ajouter[ForeignKeyJsonApi (RelationName = nameof({this._relationProperty.Name}))]");
            }

            this._foreignKeyProperty = foreignKeyProperty;
            this._typeRelation       = relationshipJApiAttribute is HasManyJsonApiAttribute ? TypeRelation.Many : TypeRelation.One;

            this.SaveRelations();
        }
Beispiel #3
0
        internal List <TypeRelation> GetRelations(Type serviceType, Type[] genericParms, bool isDetect = false)
        {
            var relations = this.typeRelations.Where(_ =>
            {
                if (_.BuildFlag == false)
                {
                    return(false);
                }
                if (_.ServiceType == serviceType)
                {
                    return(true);
                }
                if (serviceType.IsConstructedGenericType)
                {
                    var outType = serviceType.GetGenericTypeDefinition();
                    if (_.ServiceType == outType)
                    {
                        return(true);
                    }
                }
                return(false);
            }).Select(p =>
            {
                if (p.ImplementType.IsGenericType &&
                    p.ImplementType.ContainsGenericParameters)
                {
                    Type newType        = null;
                    Type newServiceType = null;
                    if (genericParms == null)
                    {
                        newType        = p.ImplementType.MakeGenericType(serviceType.GetGenericArguments());
                        newServiceType = serviceType;
                    }
                    else
                    {
                        newType        = p.ImplementType.MakeGenericType(genericParms);
                        newServiceType = serviceType.MakeGenericType(genericParms);
                    }
                    var relation = new TypeRelation(newServiceType, newType, p.Lifetime);
                    if (isDetect == false)
                    {
                        this.TryAddServiceType(newServiceType);
                        this.typeRelations.Add(relation);
                    }
                    return(relation);
                }
                else
                {
                    return(p);
                }
            }).ToList();

            relations.Reverse();
            return(relations);
        }
Beispiel #4
0
 /// <summary>
 /// 查找最精确的输入类型和类型转换方法。
 /// </summary>
 /// <param name="method">类型转换方法。</param>
 /// <param name="inputRelation">实际输入类型到方法输入类型间的关系。</param>
 /// <param name="outputRelation">实际输出类型到方法输出类型间的关系。</param>
 private void GetBestConversion(UserConversionMethod method, TypeRelation inputRelation, TypeRelation outputRelation)
 {
     Contract.Requires(method != null);
     // 更新最优输入和输出类型。
     UpdateBestType(method.InputType, inputRelation, true, ref bestInputType, ref bestInputRelation);
     UpdateBestType(method.OutputType, outputRelation, false, ref bestOutputType, ref bestOutputRelation);
     if (method.InputType == bestInputType && method.OutputType == bestOutputType)
     {
         bestMethod.Value = method;
     }
 }
Beispiel #5
0
        public float calculateTypeMultiplier(int moveId,
                                             Pokemon a, Pokemon d, ref TypeRelation relation)
        {
            relation = TypeRelation.Null;

            float    multiplier = 1;
            MoveData moveData   = Fi.data.getMoveData(moveId);

            //If the move is the same type as the pokemon
            if ((PokemonType)moveData.typeId == a.type1 ||
                (PokemonType)moveData.typeId == a.type2)
            {
                multiplier *= 1.5f;
            }

            float typeMultiplier = Fi.data.getTypeRelationMultiplier(a.type1, d.type1);

            if (typeMultiplier == 2)
            {
                relation = TypeRelation.Good;
            }
            else if (typeMultiplier == 0.5)
            {
                relation = TypeRelation.Bad;
            }
            else
            {
                relation = TypeRelation.Neutral;
            }

            if (d.type2 != PokemonType.Null)
            {
                typeMultiplier *= Fi.data.getTypeRelationMultiplier(a.type1, d.type2);
                relation        = TypeRelation.Neutral;
            }

            if (a.type2 != PokemonType.Null)
            {
                typeMultiplier *= Fi.data.getTypeRelationMultiplier(a.type2, d.type1);
                relation        = TypeRelation.Neutral;

                if (d.type2 != PokemonType.Null)
                {
                    typeMultiplier *= Fi.data.getTypeRelationMultiplier(a.type2, d.type2);
                }
            }

            return(multiplier);
        }
Beispiel #6
0
        /// <summary>
        /// 根据serviceType创建新的依赖关系
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="isDedect"></param>
        /// <returns></returns>
        internal TypeRelation MakeGeneric(Type serviceType, bool isDedect = false)
        {
            var outType  = serviceType.GetGenericTypeDefinition();
            var relation = this.typeRelations.First(p => p.ServiceType == outType);
            var result   = new TypeRelation(serviceType,
                                            relation.ImplementType.MakeGenericType(serviceType.GenericTypeArguments),
                                            relation.Lifetime);

            if (isDedect == false)
            {
                this.typeRelations.Insert(0, result);
                this.TryAddServiceType(serviceType);
            }
            return(result);
        }
Beispiel #7
0
 /// <summary>
 /// Gets multiplier for specific type from relations.
 /// </summary>
 /// <param name="types">Type relations.</param>
 /// <param name="type">Type to find.</param>
 /// <returns>Multiplier of the type relationship.</returns>
 public static double GetMultiplier(TypeRelation types, string type)
 {
     if (types.Strong.ContainsKey(type))
     {
         return(types.Strong[type]);
     }
     else if (types.Weak.ContainsKey(type))
     {
         return(types.Weak[type]);
     }
     else
     {
         return(1.0);
     }
 }
Beispiel #8
0
 public XLink(int sourceTypeId, int sourceObjectId, int targetTypeId, int targetObjectId, TypeRelation relation)
 {
     if (sourceTypeId <= 0)
         throw new ArgumentOutOfRangeException("sourceTypeId", "Value must be greater than zero.");
     if (sourceObjectId <= 0)
         throw new ArgumentOutOfRangeException("sourceObjectId", "Value must be greater than zero.");
     if (targetTypeId <= 0)
         throw new ArgumentOutOfRangeException("targetTypeId", "Value must be greater than zero.");
     if (targetObjectId <= 0)
         throw new ArgumentOutOfRangeException("targetObjectId", "Value must be greater than zero.");
     Relation = relation;
     TargetObjectId = targetObjectId;
     TargetTypeId = targetTypeId;
     SourceObjectId = sourceObjectId;
     SourceTypeId = sourceTypeId;
 }
Beispiel #9
0
        /// <summary>
        /// Calculates all of the relevant Stats of a Pokémon. This
        /// includes the Forms, Moves, League IVs, Type interactions, and weather boosts.
        /// </summary>
        /// <param name="pokemon">Reference to a Pokémon.</param>
        public void GetPokemonStats(ref Pokemon pokemon)
        {
            if (pokemon != null)
            {
                TypeRelation typeRelations = GetTypeDefenseRelations(pokemon.Type);
                pokemon.Weakness   = typeRelations.Weak.Keys.ToList();
                pokemon.Resistance = typeRelations.Strong.Keys.ToList();
                pokemon.Weather    = GetWeather(pokemon.Type);
                pokemon.FastMove   = POGODBConnector.GetPokemonMoves(ReformatName(pokemon.Name), Global.FAST_MOVE_CATEGORY);
                pokemon.ChargeMove = POGODBConnector.GetPokemonMoves(ReformatName(pokemon.Name), Global.CHARGE_MOVE_CATEGORY, pokemon.Shadow);

                pokemon.CPMax = CPCalculator.CalcCPPerLevel(
                    pokemon.Attack, pokemon.Defense, pokemon.Stamina,
                    Global.MAX_IV, Global.MAX_IV, Global.MAX_IV, Global.MAX_XL_LEVEL);
            }
        }
Beispiel #10
0
            /// <summary>
            /// 更新最优的输入/输出类型。
            /// </summary>
            /// <param name="methodType">类型转换方法的输入/输出类型。</param>
            /// <param name="relation">实际输入类型与方法输入/输出类型间的关系。</param>
            /// <param name="relationJudge">方法输入/输出类型和最优类型间的关系判定。</param>
            /// <param name="bestType">当前的最优类型。</param>
            /// <param name="bestRelation">当前最优类型与实际输入/输出类型间的关系。</param>
            private void UpdateBestType(Type methodType, TypeRelation relation, bool relationJudge,
                                        ref Type bestType, ref TypeRelation bestRelation)
            {
                // 当前选择更差。
                if (relation > bestRelation)
                {
                    return;
                }
                // 当前选择更优,或者当前选择与最佳选择相同,但最佳选择没有类型填充。
                if (relation < bestRelation || bestType == null)
                {
                    bestType     = methodType;
                    bestRelation = relation;
                    bestMethod.Reset();
                    return;
                }
                ConversionType ctype = ConversionFactory.GetStandardConversion(methodType, bestType);

                if (ctype == ConversionType.None)
                {
                    // 找不到类型转换关系,令最佳选择前进至下一级别,并清除类型填充。
                    bestType = null;
                    bestRelation--;
                    bestMethod.Reset();
                    return;
                }
                if (ctype.IsImplicit() == relationJudge)
                {
                    // 当前选择被最优选择包含。
                    if (bestRelation == TypeRelation.Second)
                    {
                        bestType = methodType;
                        bestMethod.Reset();
                    }
                }
                else if (bestRelation == TypeRelation.Thirt)
                {
                    // 当前选择包含最优选择。
                    bestType = methodType;
                    bestMethod.Reset();
                }
            }
Beispiel #11
0
        void SingleAttack(Character attacker, Character opponent)
        {
            TypeRelation relation = Types.GetRelation(attacker.Type, opponent.Type);

            opponent.EnemyAwareness &= Types.GetPossibleTypes(attacker.Type, relation);
            float multiplier = relation == TypeRelation.Neutral ? 1 : (relation == TypeRelation.Advantage ? 2 : 0.5f);

            Character.Status hp = opponent.HitPoints;
            hp.Remaining      -= (int)Math.Round(multiplier * attacker.Strength);
            opponent.HitPoints = hp;

            if (!opponent.Alive)
            {
                opponent.Parent.Active = false;

                if (opponent is Hero && !((Hero)opponent).AlliedUnitInRoom(opponent.Tile.Room))
                {
                    opponent.Tile.Room.UpdateGraphics(Room.Visibility.Darkened);
                    attacker.GetComponent <SpriteRenderer>().Active = false;
                }
            }
        }
Beispiel #12
0
        public RelationsPropertyEngine(
            IServiceProvider serviceProvider,
            IQueryService queryService,
            InformationRessource informationRessource,
            PropertyInfo propertyRelation,
            RelationshipJsonApiAttribute relationshipJApiAttribute,
            string _relationPath,
            int depth)
        {
            this._serviceProvider      = serviceProvider;
            this._queryService         = queryService;
            this._informationRessource = informationRessource;
            this._relationProperty     = propertyRelation;
            this._relationAttribute    = relationshipJApiAttribute;
            this._depth        = depth;
            this._relationPath = _relationPath;

            (PropertyInfo foreignKeyProperty, ForeignKeyJsonApiAttribute foreignKeyAttribute) =
                AttributeRelationsHandling.FindForeignKeyPropertyAndAttribute(this._informationRessource.TypeRessource, this._relationProperty.Name);

            if (foreignKeyProperty == null && foreignKeyAttribute == null)
            {
                throw new JsonApiArchitectureException($"ForeignKeyJsonApi manquant pour {this._relationProperty.Name} dans {this._informationRessource.TypeRessource.Name}, ajouter[ForeignKeyJsonApi (RelationName = nameof({this._relationProperty.Name}))]");
            }

            this._identifiantRelationProperty = AttributeHandling.GetIdProperty(typeof(T));

            if (this._identifiantRelationProperty == null)
            {
                throw new JsonApiArchitectureException($"Ajouter [IdJsonApi] sur {typeof(T).Name}");
            }

            this._foreignKeyProperty  = foreignKeyProperty;
            this._foreignKeyAttribute = foreignKeyAttribute;
            this._typeRelation        = this._relationAttribute is HasManyJsonApiAttribute ? TypeRelation.Many : TypeRelation.One;

            this.GetRelations();
        }
Beispiel #13
0
        public static CombatType GetPossibleTypes(CombatType attacker, TypeRelation result)
        {
            if (result == TypeRelation.Neutral)
            {
                return(attacker);
            }

            switch (attacker)
            {
            case CombatType.Lizard:
                return(result == TypeRelation.Advantage ?
                       CombatType.Spock | CombatType.Paper :
                       CombatType.Scissors | CombatType.Rock);

            case CombatType.Paper:
                return(result == TypeRelation.Advantage ?
                       CombatType.Rock | CombatType.Spock :
                       CombatType.Scissors | CombatType.Lizard);

            case CombatType.Rock:
                return(result == TypeRelation.Advantage ?
                       CombatType.Scissors | CombatType.Lizard :
                       CombatType.Paper | CombatType.Spock);

            case CombatType.Scissors:
                return(result == TypeRelation.Advantage ?
                       CombatType.Paper | CombatType.Lizard :
                       CombatType.Rock | CombatType.Spock);

            case CombatType.Spock:
                return(result == TypeRelation.Advantage ?
                       CombatType.Scissors | CombatType.Rock :
                       CombatType.Paper | CombatType.Lizard);

            default:
                throw new InvalidOperationException("This will never happen.");
            }
        }
Beispiel #14
0
        protected sbyte ScoreHero(Hero hero)
        {
            sbyte score = 0;

            foreach (CombatType type in Enum.GetValues(typeof(CombatType)))
            {
                if (hero.EnemyAwareness.HasFlag(type))
                {
                    TypeRelation result = Types.GetRelation(Monster.Type, type);

                    if (result == TypeRelation.Advantage)
                    {
                        score++;
                    }
                    if (result == TypeRelation.Disadvantage)
                    {
                        score--;
                    }
                }
            }

            return(score);
        }
Beispiel #15
0
        public async Task Type([Summary("(Optional) Get information about this type.")] string type1           = null,
                               [Summary("(Optional) Get information about this secondary type.")] string type2 = null)
        {
            if (type1 == null)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine($"{Global.NONA_EMOJIS["bug_emote"]} Bug");
                sb.AppendLine($"{Global.NONA_EMOJIS["dark_emote"]} Dark");
                sb.AppendLine($"{Global.NONA_EMOJIS["dragon_emote"]} Dragon");
                sb.AppendLine($"{Global.NONA_EMOJIS["electric_emote"]} Electric");
                sb.AppendLine($"{Global.NONA_EMOJIS["fairy_emote"]} Fairy");
                sb.AppendLine($"{Global.NONA_EMOJIS["fighting_emote"]} Fighting");
                sb.AppendLine($"{Global.NONA_EMOJIS["fire_emote"]} Fire");
                sb.AppendLine($"{Global.NONA_EMOJIS["flying_emote"]} Flying");
                sb.AppendLine($"{Global.NONA_EMOJIS["ghost_emote"]} Ghost");
                sb.AppendLine($"{Global.NONA_EMOJIS["grass_emote"]} Grass");
                sb.AppendLine($"{Global.NONA_EMOJIS["ground_emote"]} Ground");
                sb.AppendLine($"{Global.NONA_EMOJIS["ice_emote"]} Ice");
                sb.AppendLine($"{Global.NONA_EMOJIS["normal_emote"]} Normal");
                sb.AppendLine($"{Global.NONA_EMOJIS["poison_emote"]} Poison");
                sb.AppendLine($"{Global.NONA_EMOJIS["psychic_emote"]} Psychic");
                sb.AppendLine($"{Global.NONA_EMOJIS["rock_emote"]} Rock");
                sb.AppendLine($"{Global.NONA_EMOJIS["steel_emote"]} Steel");
                sb.AppendLine($"{Global.NONA_EMOJIS["water_emote"]} Water");

                EmbedBuilder embed = new EmbedBuilder();
                embed.AddField($"Pokémon Types:", sb.ToString());
                embed.WithColor(Global.EMBED_COLOR_DEX_RESPONSE);
                embed.WithFooter("Pokémon have 1 or 2 types. Moves always have 1 type.");
                await ReplyAsync(embed : embed.Build());
            }
            else
            {
                List <string> types = new List <string> {
                    type1
                };
                if (type2 != null && !type1.Equals(type2, StringComparison.OrdinalIgnoreCase))
                {
                    types.Add(type2);
                }

                if (!CheckValidType(type1) || (types.Count == 2 && !CheckValidType(type2)))
                {
                    await ResponseMessage.SendErrorMessage(Context.Channel, "type", $"{(!CheckValidType(type1) ? type1 : type2)} is not a valid type.");
                }
                else
                {
                    string title = $"{type1}";
                    if (types.Count == 2)
                    {
                        title += $", {type2}";
                    }

                    string description = Global.NONA_EMOJIS[$"{type1}_emote"];
                    if (types.Count == 2)
                    {
                        description += Global.NONA_EMOJIS[$"{type2}_emote"];
                    }

                    TypeRelation? type1AttackRelations = (types.Count == 2) ? null : (TypeRelation?)Connections.Instance().GetTypeAttackRelations(type1);
                    TypeRelation  defenseRelations     = Connections.Instance().GetTypeDefenseRelations(types);
                    List <string> weather = Connections.Instance().GetWeather(types);

                    EmbedBuilder embed    = new EmbedBuilder();
                    string       fileName = GENERIC_IMAGE;
                    embed.WithTitle($"Type {title.ToUpper()}");
                    embed.WithDescription(description);
                    embed.WithThumbnailUrl($"attachment://{fileName}");
                    embed.AddField("Weather Boosts:", FormatWeatherList(weather), false);
                    if (type1AttackRelations.HasValue)
                    {
                        embed.AddField($"Super Effective against:", FormatTypeList(type1AttackRelations.Value.Strong), false);
                        embed.AddField($"Not Very Effective against:", FormatTypeList(type1AttackRelations.Value.Weak), false);
                    }
                    embed.AddField($"Weaknesses:", FormatTypeList(defenseRelations.Weak), false);
                    embed.AddField($"Resistances:", FormatTypeList(defenseRelations.Strong), false);
                    embed.WithColor(Global.EMBED_COLOR_DEX_RESPONSE);

                    Connections.CopyFile(fileName);
                    await Context.Channel.SendFileAsync(fileName, embed : embed.Build());

                    Connections.DeleteFile(fileName);
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Computes the union type of {@code this} and {@code other}, meaning {@code union extends this} and
        /// {@code union extends other}.
        /// The union function may return null if no union type could be created due conflicting
        /// primitive types.
        /// </summary>
        /// <param name="other">other type</param>
        /// <param name="memory">types already used</param>
        /// <returns>union type </returns>

        public XType Union(XType other, HashSet <XType> memory)
        {
            TypeRelation rel = this.CompareTo(other);

            if (rel == TypeRelation.EXTENDS || rel == TypeRelation.EQUAL)
            {
                return(this);
            }
            else if (rel == TypeRelation.SUPER)
            {
                return(other);
            }
            XType ret = new XType();

            memory.Add(this);
outer:
            foreach (XCapability c0 in this.Capabilities)
            {
                if (c0.ComplexType == null || !memory.Contains(c0.ComplexType))
                {
                    foreach (XCapability c1 in other.Capabilities)
                    {
                        // the same member?
                        if (c0.Name.CompareTo(c1.Name) != TypeRelation.NONE)
                        {
                            XCapability c2 = new XCapability();
                            c2.Name = c0.Name;
                            // both complex types?
                            if ((c0.ComplexType != null) && (c1.ComplexType != null))
                            {
                                c2.ComplexType = c0.ComplexType.Union(c1.ComplexType, memory);
                                if (c2.ComplexType == null)
                                {
                                    return(null); // can't union the types
                                }
                            }
                            else
                            {
                                if (c0.ValueType == c1.ValueType)
                                {
                                    c2.ValueType = c0.ValueType;
                                }
                                else
                                {
                                    return(null); // can't union the types
                                }
                            }
                            switch (Utils.CompareCardinality(c0.Cardinality, c1.Cardinality))
                            {
                            case TypeRelation.EXTENDS:
                            case TypeRelation.EQUAL:
                                c2.Cardinality = c0.Cardinality;
                                break;

                            case TypeRelation.SUPER:
                                c2.Cardinality = c1.Cardinality;
                                break;

                            default:
                                break;
                            }
                            ret.Capabilities.Add(c2);
                            goto outer;
                        }
                    }
                    // not found in c1
                    ret.Capabilities.Add(c0);
                }
            }
outer2:
            foreach (XCapability c1 in other.Capabilities)
            {
                foreach (XCapability c0 in this.Capabilities)
                {
                    if (c0.ComplexType == null || !memory.Contains(c0.ComplexType))
                    {
                        if (c0.Name.CompareTo(c1.Name) != TypeRelation.NONE)
                        {
                            goto outer2;
                        }
                    }
                }
                ret.Capabilities.Add(c1);
            }
            memory.Remove(this);
            return(ret);
        }
Beispiel #17
0
 private void DeleteTypeRelation(TypeRelation type)
 {
     Options.TypesRelation.Remove(type);
 }
Beispiel #18
0
 /// <summary>
 /// 根据依赖关系生成对象
 /// </summary>
 /// <param name="serviceProvider"></param>
 /// <param name="typeRelation"></param>
 /// <returns></returns>
 internal static object GetServiceByRelation(this IServiceProvider serviceProvider, TypeRelation typeRelation)
 {
     if (serviceProvider is ServiceProvider sp)
     {
         return(sp.GetServiceByRelation(typeRelation));
     }
     else
     {
         return(null);
     }
 }
Beispiel #19
0
 /// <summary>
 /// 查找最精确的输入类型和类型转换方法。
 /// </summary>
 /// <param name="method">类型转换方法。</param>
 /// <param name="inputRelation">实际输入类型到方法输入类型间的关系。</param>
 /// <param name="outputRelation">实际输出类型到方法输出类型间的关系。</param>
 private void GetBestConversion(UserConversionMethod method, TypeRelation inputRelation, TypeRelation outputRelation)
 {
     Contract.Requires(method != null);
     // 更新最优输入和输出类型。
     UpdateBestType(method.InputType, inputRelation, true, ref bestInputType, ref bestInputRelation);
     UpdateBestType(method.OutputType, outputRelation, false, ref bestOutputType, ref bestOutputRelation);
     if (method.InputType == bestInputType && method.OutputType == bestOutputType)
     {
         bestMethod.Value = method;
     }
 }
Beispiel #20
0
 /// <summary>
 /// 更新最优的输入/输出类型。
 /// </summary>
 /// <param name="methodType">类型转换方法的输入/输出类型。</param>
 /// <param name="relation">实际输入类型与方法输入/输出类型间的关系。</param>
 /// <param name="relationJudge">方法输入/输出类型和最优类型间的关系判定。</param>
 /// <param name="bestType">当前的最优类型。</param>
 /// <param name="bestRelation">当前最优类型与实际输入/输出类型间的关系。</param>
 private void UpdateBestType(Type methodType, TypeRelation relation, bool relationJudge,
     ref Type bestType, ref TypeRelation bestRelation)
 {
     // 当前选择更差。
     if (relation > bestRelation)
     {
         return;
     }
     // 当前选择更优,或者当前选择与最佳选择相同,但最佳选择没有类型填充。
     if (relation < bestRelation || bestType == null)
     {
         bestType = methodType;
         bestRelation = relation;
         bestMethod.Reset();
         return;
     }
     ConversionType ctype = ConversionFactory.GetStandardConversion(methodType, bestType);
     if (ctype == ConversionType.None)
     {
         // 找不到类型转换关系,令最佳选择前进至下一级别,并清除类型填充。
         bestType = null;
         bestRelation--;
         bestMethod.Reset();
         return;
     }
     if (ctype.IsImplicit() == relationJudge)
     {
         // 当前选择被最优选择包含。
         if (bestRelation == TypeRelation.Second)
         {
             bestType = methodType;
             bestMethod.Reset();
         }
     }
     else if (bestRelation == TypeRelation.Thirt)
     {
         // 当前选择包含最优选择。
         bestType = methodType;
         bestMethod.Reset();
     }
 }
Beispiel #21
0
        /// <summary>
        /// Récupere la liste des couples propriétés / attributes (HasOneJsonApiAttribute et/ou HasManyJsonApiAttribute) pour un type
        /// </summary>
        /// <param name="type">Type sur lequel chercher</param>
        /// <param name="typeRelation">Type de relation recherché, par défaut TypeRelation.None = Tous les relations</param>
        public static IEnumerable <Tuple <PropertyInfo, RelationshipJsonApiAttribute> > GetRelationshipProperties(Type type, TypeRelation typeRelation = TypeRelation.None)
        {
            Type typeAttribute;

            if (typeRelation == TypeRelation.One)
            {
                typeAttribute = typeof(HasOneJsonApiAttribute);
            }
            else if (typeRelation == TypeRelation.Many)
            {
                typeAttribute = typeof(HasManyJsonApiAttribute);
            }
            else if (typeRelation == TypeRelation.ManyToMany)
            {
                typeAttribute = typeof(HasManyToManyJsonApiAttribute);
            }
            else
            {
                typeAttribute = typeof(RelationshipJsonApiAttribute);
            }

            foreach (PropertyInfo prop in type.GetProperties())
            {
                var attr = (RelationshipJsonApiAttribute)prop.GetCustomAttribute(typeAttribute);

                if (attr != null)
                {
                    yield return(new Tuple <PropertyInfo, RelationshipJsonApiAttribute>(prop, attr));
                }
            }
        }
Beispiel #22
0
        /// <summary>
        /// Runs the counter simulation against a boss using raiders.
        /// </summary>
        /// <param name="boss">Boss to fight against.</param>
        /// <param name="raiders">Raiders used to attack the boss.</param>
        /// <returns>Counter calculation results.</returns>
        public static CounterCalcResults RunSim(Pokemon boss, List <Pokemon> raiders)
        {
            CounterCalcResults results = new CounterCalcResults();

            for (int mode = 0; mode < 2; mode++)
            {
                List <Counter> counters  = new List <Counter>();
                TypeRelation   bossTypes = Connections.Instance().GetTypeDefenseRelations(boss.Type);
                foreach (Pokemon raider in raiders)
                {
                    if (raider.Released &&
                        (mode == REGULAR_COUNTER_INDEX && !raider.Name.Contains("Mega ") ||
                         (mode == SPECIAL_COUNTER_INDEX && (raider.Shadow || raider.Name.Contains("Mega "))))
                        )
                    {
                        List <Counter> allCounters = new List <Counter>();
                        TypeRelation   raiderTypes = Connections.Instance().GetTypeDefenseRelations(raider.Type);
                        foreach (Move raiderFast in raider.FastMove)
                        {
                            foreach (Move raiderCharge in raider.ChargeMove)
                            {
                                if ((!raiderCharge.Name.Equals(Global.SHADOW_MOVES.ElementAt(Global.PURIFIED_INDEX).Name, StringComparison.OrdinalIgnoreCase) &&
                                     !raiderCharge.Name.Equals(Global.SHADOW_MOVES.ElementAt(Global.SHADOW_INDEX).Name, StringComparison.OrdinalIgnoreCase)) ||
                                    (raiderCharge.Name.Equals(Global.SHADOW_MOVES.ElementAt(Global.PURIFIED_INDEX).Name, StringComparison.OrdinalIgnoreCase) && mode == REGULAR_COUNTER_INDEX) ||
                                    (raiderCharge.Name.Equals(Global.SHADOW_MOVES.ElementAt(Global.SHADOW_INDEX).Name, StringComparison.OrdinalIgnoreCase) && mode == SPECIAL_COUNTER_INDEX))
                                {
                                    SimPokemon raiderSim = new SimPokemon
                                    {
                                        Number       = raider.Number,
                                        Name         = raider.Name,
                                        Fast         = raiderFast,
                                        Charge       = raiderCharge,
                                        FastEffect   = TypeCalculator.GetMultiplier(bossTypes, raiderFast.Type),
                                        ChargeEffect = TypeCalculator.GetMultiplier(bossTypes, raiderCharge.Type),
                                        FastStab     = raider.Type.Contains(raiderFast.Type) ? STAB_MULTIPLIER : 1.0,
                                        ChargeStab   = raider.Type.Contains(raiderCharge.Type) ? STAB_MULTIPLIER : 1.0,
                                        StadowAtkMul = mode == SPECIAL_COUNTER_INDEX && raider.Shadow ? SHADOW_ATK_MUL : 1.0,
                                        StadowDefMul = mode == SPECIAL_COUNTER_INDEX && raider.Shadow ? SHADOW_DEF_MUL : 1.0,
                                        AtkStat      = (int)((raider.Attack + Global.MAX_IV) * Global.DISCRETE_CPM[Global.MAX_REG_LEVEL - 1]),
                                        DefStat      = (int)((raider.Defense + Global.MAX_IV) * Global.DISCRETE_CPM[Global.MAX_REG_LEVEL - 1]),
                                        StamStat     = (int)((raider.Stamina + Global.MAX_IV) * Global.DISCRETE_CPM[Global.MAX_REG_LEVEL - 1])
                                    };

                                    SimPokemon bossSim = new SimPokemon
                                    {
                                        Number       = boss.Number,
                                        Name         = boss.Name,
                                        StadowAtkMul = 1.0,
                                        StadowDefMul = 1.0,
                                        AtkStat      = (int)((boss.Attack + Global.MAX_IV) * Global.DISCRETE_CPM[Global.MAX_REG_LEVEL - 1]),
                                        DefStat      = (int)((boss.Defense + Global.MAX_IV) * Global.DISCRETE_CPM[Global.MAX_REG_LEVEL - 1]),
                                        StamStat     = (int)((boss.Stamina + Global.MAX_IV) * Global.DISCRETE_CPM[Global.MAX_REG_LEVEL - 1])
                                    };

                                    double x        = 0.0;
                                    double y        = 0.0;
                                    double moveSets = 1;

                                    List <Move> bossFastMoves   = boss.FastMove.Where(m => !m.IsLegacy).ToList();
                                    List <Move> bossChargeMoves = boss.ChargeMove.Where(m => !m.IsLegacy).ToList();

                                    if (boss.Defense == 0 || bossFastMoves.Count + bossChargeMoves.Count == 0)
                                    {
                                        if (boss.Defense == 0)
                                        {
                                            bossSim.DefStat = DEFAULT_DEF;
                                        }
                                        x = (0.5 * raiderSim.Fast.PvEEnergy) + (0.5 * raiderSim.Charge.PvEEnergy);
                                        y = DEFAULT_DPS / (double)raiderSim.DefStat;
                                    }
                                    else
                                    {
                                        moveSets = boss.FastMove.Count * boss.ChargeMove.Count;
                                        foreach (Move bossFast in bossFastMoves)
                                        {
                                            bossSim.Fast       = bossFast;
                                            bossSim.FastEffect = TypeCalculator.GetMultiplier(raiderTypes, bossFast.Type);
                                            bossSim.FastStab   = boss.Type.Contains(bossFast.Type) ? STAB_MULTIPLIER : 1.0;
                                            foreach (Move bossCharge in bossChargeMoves)
                                            {
                                                if (!bossCharge.Name.Equals(Global.SHADOW_MOVES.ElementAt(Global.PURIFIED_INDEX).Name, StringComparison.OrdinalIgnoreCase) &&
                                                    !bossCharge.Name.Equals(Global.SHADOW_MOVES.ElementAt(Global.SHADOW_INDEX).Name, StringComparison.OrdinalIgnoreCase))
                                                {
                                                    bossSim.Charge       = bossCharge;
                                                    bossSim.ChargeEffect = TypeCalculator.GetMultiplier(raiderTypes, bossCharge.Type);
                                                    bossSim.ChargeStab   = boss.Type.Contains(bossCharge.Type) ? STAB_MULTIPLIER : 1.0;

                                                    DPSInput inputs = CalcDPSInput(bossSim, raiderSim);
                                                    x += inputs.X;
                                                    y += inputs.Y;
                                                }
                                            }
                                        }
                                    }

                                    allCounters.Add(CalcDps(bossSim, raiderSim, x / moveSets, y / moveSets));
                                }
                            }
                        }
                        if (allCounters.Count != 0)
                        {
                            counters.Add(allCounters.OrderByDescending(x => x.Rating).First());
                        }
                    }
                }

                if (mode == REGULAR_COUNTER_INDEX)
                {
                    results.Regular = counters.OrderByDescending(x => x.Rating).ThenBy(x => x.Name).Take(RESULTS).ToList();
                }
                else
                {
                    results.Special = counters.OrderByDescending(x => x.Rating).ThenBy(x => x.Name).Take(RESULTS).ToList();
                }
            }
            return(results);
        }
Beispiel #23
0
            /// <summary>
            /// 查找合适的用户自定义类型转换方法。
            /// </summary>
            /// <returns>合适的用户自定义类型转换方法,如果不存在则为 <c>null</c>。</returns>
            public MethodInfo FindConversion()
            {
                UserConversions convs = GetUserConversions(inputType);

                if (convs != null)
                {
                    Contract.Assume(convs.ConvertToIndex >= 0);
                    for (int i = convs.ConvertToIndex; i < convs.Methods.Length; i++)
                    {
                        UserConversionMethod method = convs.Methods[i];
                        ConversionType       ctype  = ConversionFactory.GetStandardConversion(outputType, method.OutputType);
                        if (ctype == ConversionType.None)
                        {
                            continue;
                        }
                        TypeRelation inputRelation = (method.InputType == inputType) ?
                                                     TypeRelation.Best : TypeRelation.Second;
                        TypeRelation outputRelation = TypeRelation.Best;
                        if (ctype >= ConversionType.ExplicitNumeric)
                        {
                            outputRelation = TypeRelation.Second;
                        }
                        else if (ctype > ConversionType.Identity)
                        {
                            outputRelation = TypeRelation.Thirt;
                        }
                        GetBestConversion(method, inputRelation, outputRelation);
                    }
                }
                convs = GetUserConversions(outputType);
                if (convs != null)
                {
                    for (int i = 0; i < convs.ConvertToIndex; i++)
                    {
                        UserConversionMethod method = convs.Methods[i];
                        ConversionType       ctype  = ConversionFactory.GetStandardConversion(method.InputType, inputType);
                        if (ctype == ConversionType.None)
                        {
                            continue;
                        }
                        TypeRelation outputRelation = (method.OutputType == outputType) ?
                                                      TypeRelation.Best : TypeRelation.Second;
                        TypeRelation inputRelation = TypeRelation.Best;
                        if (ctype >= ConversionType.ExplicitNumeric)
                        {
                            inputRelation = TypeRelation.Second;
                        }
                        else if (ctype > ConversionType.Identity)
                        {
                            inputRelation = TypeRelation.Thirt;
                        }
                        GetBestConversion(method, inputRelation, outputRelation);
                    }
                }
                if (bestMethod.IsUnique)
                {
                    return(bestMethod.Value.Method);
                }
                if (bestMethod.IsAmbig)
                {
                    throw CommonExceptions.AmbiguousUserDefinedConverter(inputType, outputType);
                }
                return(null);
            }