コード例 #1
0
 public BodyPartHpEvent(BodyPart bodyPart, HpSystemEvent hpSystemEvent)
 {
     this.BodyPart      = bodyPart;
     this.HpSystemEvent = hpSystemEvent;
 }
コード例 #2
0
 public BodyNode AddBodyPart(BodyPart bodyPart) => AddBodyPart(bodyPart, ref _rootNode);
コード例 #3
0
        public static void ReadBodyPartsFromXml()
        {
            IsInitialized = true;

            AvailableBodyParts = new Dictionary <string, Dictionary <string, BodyPart> >();

            // STEP 1:
            // read names only
            List <string> bodyVariantsNames = BodyPartXmlReader.getChildren(new List <string>()
            {
                RootField, BaseStatsField
            });
            List <List <string> > bodyPartNamesPerVariant = new List <List <string> >();
            int countVariants = 0;

            foreach (var variantName in bodyVariantsNames)
            {
                List <string> bodyPartNames = BodyPartXmlReader.getChildren(new List <string>()
                {
                    RootField, BaseStatsField, variantName
                });

                bodyPartNamesPerVariant.Add(new List <string>());
                foreach (var bodyPartName in bodyPartNames)
                {
                    //Console.WriteLine("Adding bodyPartName " + bodyPartName);
                    bodyPartNamesPerVariant[countVariants].Add(bodyPartName);
                }

                countVariants++;
            }

            // STEP 2:
            // setup BodyPart Dictionary
            for (int i = 0; i < bodyVariantsNames.Count; i++)
            {
                var variantName = bodyVariantsNames[i];

                // check if variant exists
                if (!AvailableBodyParts.ContainsKey(variantName))
                {
                    AvailableBodyParts[variantName] = new Dictionary <string, BodyPart>();
                }

                //Console.WriteLine("variantName: " + variantName);

                foreach (var bodyPartName in bodyPartNamesPerVariant[i])
                {
                    bool isContainer = BodyPartXmlReader.getFloat(new List <string>()
                    {
                        RootField, BaseStatsField, variantName, bodyPartName, IsContainerField
                    }) == 1;
                    float hp = BodyPartXmlReader.getFloat(new List <string>()
                    {
                        RootField, BaseStatsField, variantName, bodyPartName, HpField
                    });
                    float size = BodyPartXmlReader.getFloat(new List <string>()
                    {
                        RootField, BaseStatsField, variantName, bodyPartName, SizeField
                    });

                    List <string> materialNames = BodyPartXmlReader.getStrings(
                        new List <string>()
                    {
                        RootField, BaseStatsField, variantName, bodyPartName, MaterialsField, ItemField, MaterialsNameField
                    });
                    List <string> materialWeights = BodyPartXmlReader.getStrings(
                        new List <string>()
                    {
                        RootField, BaseStatsField, variantName, bodyPartName, MaterialsField, ItemField, MaterialsSizeField
                    });

                    List <DamageMultiplier> multipliers = new List <DamageMultiplier>();
                    List <float>            weights     = new List <float>();
                    for (int j = 0; j < materialNames.Count; j++)
                    {
                        var   materialName   = materialNames[j];
                        float materialWeight = float.Parse(materialWeights[j]);
                        try
                        {
                            foreach (var mult in EntityMaterial.GetMaterial(materialName).DamageMultipliers)
                            {
                                multipliers.Add(mult);
                                weights.Add(materialWeight);
                            }
                        }
                        catch (Exception e) { /* do nothing */ }
                    }

                    multipliers = DamageMultiplier.Simplify(multipliers, weights);

                    HPSystem hpSystem = new HPSystem((int)hp, multipliers);

                    BodyPart bodyPart;
                    if (isContainer)
                    {
                        bodyPart = new BodyPartContainer(bodyPartName, size, hpSystem);
                    }
                    else
                    {
                        bodyPart = new BodyPart(bodyPartName, size, hpSystem);
                    }

                    // store bodypart
                    AvailableBodyParts[variantName][bodyPartName] = bodyPart;
                }
            }

            // STEP 3:
            // build bodies and add parts for containers
            List <string> variantNames = BodyPartXmlReader.getChildren(new List <string>()
            {
                RootField, InclusionField
            });

            foreach (var variantName in variantNames)
            {
                Body body = new Body(variantName);

                List <string> containerNames = BodyPartXmlReader.getChildren(new List <string>()
                {
                    RootField, InclusionField, variantName
                });

                foreach (var bodyPartName in containerNames)
                {
                    //Debug.Log("INCLUSION FOR " + variantName + " " + bodyPartName);

                    var bodyPart = AvailableBodyParts[variantName][bodyPartName];

                    BodyPartContainer container;
                    if (bodyPart.GetType() == typeof(BodyPartContainer))
                    {
                        container = (BodyPartContainer)bodyPart;
                    }
                    else
                    {
                        container = new BodyPartContainer(bodyPart);
                    }

                    List <string> partsList = BodyPartXmlReader.getChildren(
                        new List <string>()
                    {
                        RootField, InclusionField, variantName, bodyPartName
                    });

                    foreach (var partName in partsList)
                    {
                        //Debug.Log(variantName + " " + bodyPartName + " getting a new " + partName);

                        List <string> customNames = BodyPartXmlReader.getStrings(
                            new List <string>()
                        {
                            RootField, InclusionField, variantName, bodyPartName, partName, ItemField
                        });

                        if (customNames.Count == 0)
                        {
                            container.AddBodyPart(AvailableBodyParts[variantName][partName].Clone());
                        }

                        foreach (var customName in customNames)
                        {
                            BodyPart bp = AvailableBodyParts[variantName][partName].Clone();
                            bp.NameCustom = customName;
                            container.AddBodyPart(bp);
                        }
                    }

                    // write back
                    // TODO: check if this is necessary
                    AvailableBodyParts[variantName][bodyPartName] = container;

                    body.AddBodyPart(container);
                }

                AvailableBodies[variantName] = body;
            }
        }
コード例 #4
0
        public static void ReadBodyPartsFromXml()
        {
            IsInitialized = true;

            AvailableBodyParts = new Dictionary <string, Dictionary <string, BodyPart> >();

            // STEP 1:
            // read names only
            var bodyVariantsNames = _bodyPartXmlReader.GetChildren(new List <string>()
            {
                BodyPartsField
            });
            var bodyPartNamesPerVariant = new List <List <string> >();
            int countVariants           = 0;

            foreach (var variantName in bodyVariantsNames)
            {
                bodyPartNamesPerVariant.Add(new List <string>());

                var bodyPartNames = _bodyPartXmlReader.GetChildren(new List <string>()
                {
                    BodyPartsField, variantName
                });
                foreach (var bodyPartName in bodyPartNames)
                {
                    //Console.WriteLine("Adding bodyPartName " + bodyPartName);
                    bodyPartNamesPerVariant[countVariants].Add(bodyPartName);
                }

                countVariants++;
            }

            // STEP 2:
            // setup BodyPart Dictionary
            for (int i = 0; i < bodyVariantsNames.Count; i++)
            {
                var variantName     = bodyVariantsNames[i];
                var variantBodyType = BodyTypes.String2BodyType(variantName);

                // check if variant exists
                if (!AvailableBodyParts.ContainsKey(variantName))
                {
                    AvailableBodyParts[variantName] = new Dictionary <string, BodyPart>();
                }

                //Console.WriteLine("variantName: " + variantName);

                foreach (var bodyPartName in bodyPartNamesPerVariant[i])
                {
                    // get base statistics
                    float hp = _bodyPartXmlReader.GetFloat(new List <string>()
                    {
                        BodyPartsField, variantName, bodyPartName, HpField
                    });
                    float size = _bodyPartXmlReader.GetFloat(new List <string>()
                    {
                        BodyPartsField, variantName, bodyPartName, SizeField
                    });

                    // get materials
                    var materialNames = _bodyPartXmlReader.GetChildren(
                        new List <string>()
                    {
                        BodyPartsField, variantName, bodyPartName, MaterialsField
                    });

                    var multipliers = new List <Damage>();
                    var weights     = new List <float>();
                    foreach (var materialName in materialNames)
                    {
                        float materialWeight = _bodyPartXmlReader.GetFloat(
                            new List <string>()
                        {
                            BodyPartsField, variantName, bodyPartName, MaterialsField, materialName
                        });
                        var material = EntityMaterialFactory.GetMaterial(materialName);
                        try
                        {
                            foreach (var mult in material.DamageMultipliers)
                            {
                                multipliers.Add(mult);
                                weights.Add(materialWeight);
                            }
                        }
                        catch (Exception e) { /* do nothing */ }
                    }

                    // Debug.Log("Creating bodypart: " + bodyPartName);

                    // Debug.Log("before simplifying:");
                    // foreach (var mult in multipliers)
                    //     Debug.Log($"Multiplier [{mult.DamageType.ToString()}] " + mult.Amount);

                    multipliers = DamageMultipliers.Simplify(multipliers, weights);

                    // Debug.Log("after simplifying:");
                    // foreach (var mult in multipliers)
                    //     Debug.Log($"Multiplier [{mult.DamageType.ToString()}] " + mult.Amount);

                    // read capacities stats from XML
                    List <string> capacitiesNames;
                    try
                    {
                        capacitiesNames = _bodyPartXmlReader.GetChildren(
                            new List <string>()
                        {
                            CapacityStatsField, variantName, bodyPartName
                        });
                    }
                    catch (Exception e)
                    {
                        capacitiesNames = new List <string>();
                    }

                    // build capacities
                    var capacities = new Capacities.CapacityInfo();
                    foreach (var capacityName in capacitiesNames)
                    {
                        try
                        {
                            var value = _bodyPartXmlReader.GetFloat(
                                new List <string>()
                            {
                                CapacityStatsField, variantName, bodyPartName, capacityName
                            });

                            if (capacityName == CriticalField)
                            {
                                Debug.Log($"Got critical value = {value}");
                            }
                            else
                            {
                                var capacityType = CapacityTypes.CapacityStr2Type(capacityName);

                                capacities.SetCapacity(capacityType, value);
                                Debug.Log($"Got capacity {capacityName} = {value}");
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.Log($"Could not real XML for field {capacityName}");
                        }
                    }

                    // finally, build bodypart
                    var hpSystem = new HpSystem((int)hp, multipliers);
                    var bodyPart = new BodyPart(variantBodyType, hpSystem, bodyPartName, size, capacities);

                    Debug.Log("Created bodypart: " + bodyPart.NameCustom);

                    AvailableBodyParts[variantName][bodyPartName] = bodyPart;
                }
            }

            float defaulthHealingPeriod = _bodyPartXmlReader.GetFloat(
                new List <string>()
            {
                BodyStatsField, DefaultField, HealingPeriodField
            });
            float defaultHealingAmount = _bodyPartXmlReader.GetFloat(
                new List <string>()
            {
                BodyStatsField, DefaultField, HealingAmountField
            });

            // TODO: convert this to recursive function to be able to support deeper body structures
            // STEP 3:
            // build bodies and add parts for containers
            var bodyTypeNames = _bodyPartXmlReader.GetChildren(new List <string>()
            {
                InclusionField
            });

            foreach (var bodyTypeName in bodyTypeNames)
            {
                var eBodyType = BodyTypes.String2BodyType(bodyTypeName);
                var body      = new Body(eBodyType);

                var healingPeriod = _bodyPartXmlReader.TryGetFloat(
                    new List <string>()
                {
                    BodyStatsField, bodyTypeName, HealingPeriodField
                },
                    defaulthHealingPeriod);
                var healingAmount = _bodyPartXmlReader.TryGetFloat(
                    new List <string>()
                {
                    BodyStatsField, bodyTypeName, HealingAmountField
                },
                    defaultHealingAmount);

                body.HealingPeriod = healingPeriod;
                body.HealingAmount = healingAmount;

                var containerNames = _bodyPartXmlReader.GetChildren(new List <string>()
                {
                    InclusionField, bodyTypeName
                });

                foreach (var bodyPartName in containerNames)
                {
                    var bodyPart = AvailableBodyParts[bodyTypeName][bodyPartName];
                    var bodyNode = body.AddBodyPart(bodyPart);

                    var partsList = _bodyPartXmlReader.GetChildren(
                        new List <string>()
                    {
                        InclusionField, bodyTypeName, bodyPartName
                    });

                    foreach (var partName in partsList)
                    {
                        var customNames = _bodyPartXmlReader.GetStrings(
                            new List <string>()
                        {
                            InclusionField, bodyTypeName, bodyPartName, partName, XmlReader.ItemField
                        });

                        var bodyPartCustomName = AvailableBodyParts[bodyTypeName][partName].Clone();

                        if (customNames.Count == 0)
                        {
                            customNames.Add(bodyPartCustomName.Name);
                        }

                        foreach (var customName in customNames)
                        {
                            bodyPartCustomName.NameCustom = customName; // copy custom name
                            body.AddBodyPart(bodyPartCustomName, ref bodyNode);
                        }
                    }

                    // write back to body
                    body.SetNode(bodyNode);
                }

                AvailableBodies[bodyTypeName] = body;
            }
        }