コード例 #1
0
        private void DamageTarget()
        {
            if (Target == null)
            {
                return;
            }

            if (Target.HasComponent <OwnerComponent>() && Parent.HasComponent <OwnerComponent>() && Target.GetComponent <OwnerComponent>() != Parent.GetComponent <OwnerComponent>())
            {
                if (Type == AttackType.Far)
                {
                    var type = Parent.GetComponent <HealthComponent>().ArmyType;
                    ((IGameEntityFactory)Parent.Scene.EntityFactory).CreateProjectile(Parent, Target, new Vector2(type == 2 ? 0.4f : 0.25f), AttackDamage);
                }
                else if (Type == AttackType.Melee)
                {
                    var damage = AttackDamage;

                    var targetMultiplierType = Target.GetComponent <HealthComponent>().ArmyType;
                    if (DamageMultipliers.ContainsKey(targetMultiplierType))
                    {
                        damage *= DamageMultipliers[targetMultiplierType];
                    }

                    Target.GetComponent <HealthComponent>().Damage(damage, Parent);
                }
            }

            damaged = true;
        }
コード例 #2
0
            public int GetDamageMultiplier(string damageType)
            {
                if (DamageMultipliers.TryGetValue(damageType, out int multiplier))
                {
                    return(multiplier);
                }

                return(1);
            }
コード例 #3
0
            public UnitGroup(string line, bool immuneSystem)
            {
                string[] words = line.Split(' ');

                UnitCount  = int.Parse(words[0]);
                HP         = int.Parse(words[4]);
                Initiative = int.Parse(words[words.Length - 1]);
                Damage     = int.Parse(words[words.Length - 6]);
                DamageType = words[words.Length - 5];

                ImmuneSystem = immuneSystem;

                int openIndex  = line.IndexOf('(');
                int closeIndex = line.IndexOf(')');

                if (openIndex != -1)
                {
                    openIndex += 1;

                    string   resistances     = line.Substring(openIndex, closeIndex - openIndex);
                    string[] resistanceWords = resistances.Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

                    bool immuneState = true;

                    for (int i = 0; i < resistanceWords.Length; i++)
                    {
                        switch (resistanceWords[i])
                        {
                        case "immune":
                            //Set state to Immunities
                            immuneState = true;
                            break;

                        case "weak":
                            //Set state to Weaknesses
                            immuneState = false;
                            break;

                        case "to":
                            //Skip meaningless word
                            break;

                        case "bludgeoning":
                        case "radiation":
                        case "slashing":
                        case "cold":
                        case "fire":
                            DamageMultipliers.Add(resistanceWords[i], immuneState ? 0 : 2);
                            break;

                        default: throw new Exception($"Unexpected Keyword: {resistanceWords[i]}");
                        }
                    }
                }
            }
コード例 #4
0
        private bool HasInRange(IEntity other)
        {
            if (other.HasComponent <HealthComponent>())
            {
                var targetMultiplierType = other.GetComponent <HealthComponent>().ArmyType;
                if (DamageMultipliers.ContainsKey(targetMultiplierType))
                {
                    if (DamageMultipliers[targetMultiplierType] == 0)
                    {
                        return(false);
                    }
                }
            }

            return((Parent.Position - other.Position).Length < Range + (Parent.Size.X / 2));
        }
コード例 #5
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;
            }
        }