Esempio n. 1
0
        private static ToolCE GetUsedTool(this IEnumerable <ToolCE> tools, DamageInfo dinfo)
        {
            if (tools.Count() == 1)
            {
                if (dinfo.WeaponBodyPartGroup != null && tools.First().linkedBodyPartsGroup != dinfo.WeaponBodyPartGroup)
                {
                    Log.ErrorOnce("CE :: For " + dinfo.Weapon + ", WeaponBodyPartGroup was specified for DamageInfo " + dinfo.ToString() + ", but none of the tools " + String.Join(",", tools.Select(t => t.ToString()).ToArray()) + " have this linkedBodyPartsGroup.", dinfo.GetHashCode() + 3473534);
                }
            }
            else if (!tools.Any())
            {
                Log.Warning("No ToolCE could be found for " + dinfo.ToString() + ", but GetUsedTool was called.");
            }
            else
            {
                if (dinfo.WeaponBodyPartGroup != null)
                {
                    var linkedTools = tools.Where(t => t.linkedBodyPartsGroup == dinfo.WeaponBodyPartGroup);

                    if (linkedTools.Count() > 1)
                    {
                        Log.ErrorOnce("CE :: " + dinfo.Weapon + " has multiple ToolCE with linkedBodyPartsGroup=" + dinfo.WeaponBodyPartGroup + ", and they can not be fully distinguished because of it. [While evaluating DamageInfo " + dinfo.ToString() + "]", dinfo.Weapon.GetHashCode() + dinfo.WeaponBodyPartGroup.GetHashCode() + 84827378);
                        return(linkedTools.DistinguishBodyPartGroups(dinfo));
                    }

                    if (linkedTools.Any())
                    {
                        return(linkedTools.First());
                    }
                }
                else
                {
                    var nonLinkedTools = tools.Where(t => t.linkedBodyPartsGroup == null);

                    if (nonLinkedTools.Count() > 1)
                    {
                        Log.ErrorOnce("CE :: " + dinfo.Weapon + " has multiple ToolCE without linkedBodyPartsGroup, and they can not be fully distinguished because of it. [While evaluating DamageInfo " + dinfo.ToString() + "]", dinfo.Weapon.GetHashCode() + 5481278);
                        return(nonLinkedTools.DistinguishBodyPartGroups(dinfo));
                    }

                    if (nonLinkedTools.Any())
                    {
                        return(nonLinkedTools.First());
                    }
                }
            }
            return(tools.FirstOrDefault());
        }