예제 #1
0
        public void TakeDamage(List <Damage> damages)
        {
            this.HpPrev = HpCurrent;
            List <Damage> damagesAfterModifier = DamageMultiplier.GetDamageAfterMultiplier(damages, damageMultipliers);
            float         totalDamage          = Damage.GetTotalDamage(damagesAfterModifier);

            this.Health -= totalDamage / HpBase;
            OnEvent(new HpSystemEvent(this, damagesAfterModifier));
        }
예제 #2
0
        /// <inheritdoc />
        public ItemAttributes GetBonus(D3Calculator calculator)
        {
            var attr = new DamageMultiplier(multiplier).GetBonus(calculator);

            attr.armorBonusItem = malusMultiplier * calculator.GetHeroArmor();

            attr += new ResistancesMultiplier(malusMultiplier).GetBonus(calculator);

            return(attr);
        }
예제 #3
0
        /// <inheritdoc />
        public ItemAttributes GetBonus(D3Calculator calculator)
        {
            var attr = new DamageMultiplier(0.10).GetBonus(calculator);

            attr.armorBonusItem = 0.20 * calculator.GetHeroArmor();

            attr += new ResistancesMultiplier(0.20).GetBonus(calculator);

            return attr;
        }
예제 #4
0
    static ContactPoint2D[] contacts = new ContactPoint2D[10];  //A reusable array of references to contact point objects

    //This is called whenever this rigidbodys collider intersect another
    void OnCollisionEnter2D(Collision2D collision)
    {
        //Get all contact points, convert impulse to damage, and apply damage
        int   numContacts = collision.GetContacts(contacts);
        float dmg         = 0f;

        for (int i = 0; i < numContacts; i++)
        {
            DamageMultiplier dm = contacts[i].collider.GetComponent <DamageMultiplier>();
            if (dm)
            {
                dmg += Mathf.Max(0, (contacts[i].normalImpulse - damageThreshold) * damagePerImpulse) * dm.multiplier;
            }
            else
            {
                dmg += Mathf.Max(0, (contacts[i].normalImpulse - damageThreshold) * damagePerImpulse);
            }
        }

        Damage(dmg);
    }
예제 #5
0
    public void swingPlayer(string id, int limb)
    {
        if (!base.GetComponent <Life>().dead&& ServerSettings.pvp)
        {
            NetworkUser userFromID = NetworkUserList.getUserFromID(id);
            if (userFromID != null && userFromID.model != null && userFromID.model != base.gameObject && !userFromID.model.GetComponent <Life>().dead&& (base.GetComponent <Player>().owner.friend == string.Empty || base.GetComponent <Player>().owner.friend != userFromID.friend) && (userFromID.model.transform.position - base.transform.position).magnitude < 3f)
            {
                float damage = (float)MeleeStats.getDamage(base.GetComponent <Clothes>().item) * DamageMultiplier.getMultiplierPlayer(limb);
                damage = damage * (1f + base.GetComponent <Skills>().warrior() * 0.4f);
                damage = damage * (1f - userFromID.model.GetComponent <Skills>().warrior() * 0.4f);
                if ((limb == 0 || limb == 1) && userFromID.model.GetComponent <Clothes>().pants != -1)
                {
                    damage = damage * ArmorStats.getArmor(userFromID.model.GetComponent <Clothes>().pants);
                }
                if ((limb == 2 || limb == 3 || limb == 5) && userFromID.model.GetComponent <Clothes>().shirt != -1)
                {
                    damage = damage * ArmorStats.getArmor(userFromID.model.GetComponent <Clothes>().shirt);
                }
                if (limb == 5 && userFromID.model.GetComponent <Clothes>().vest != -1)
                {
                    damage = damage * ArmorStats.getArmor(userFromID.model.GetComponent <Clothes>().vest);
                }
                if (limb == 4 && userFromID.model.GetComponent <Clothes>().hat != -1)
                {
                    damage = damage * ArmorStats.getArmor(userFromID.model.GetComponent <Clothes>().hat);
                }
                string empty = string.Empty;
                if (limb == 0)
                {
                    empty = "shin";
                }
                else if (limb == 1)
                {
                    empty = "thigh";
                }
                else if (limb == 2)
                {
                    empty = "arm";
                }
                else if (limb == 3)
                {
                    empty = "shoulder";
                }
                else if (limb == 4)
                {
                    empty = "head";
                }
                else if (limb == 5)
                {
                    empty = "chest";
                }

                int    itemId  = base.GetComponent <Clothes>().item;
                string steamID = base.GetComponent <Player>().owner.id;
                userFromID.model.GetComponent <Life>().damage((int)damage, string.Concat(new string[] { "You were chopped in the ", empty, " with the ", ItemName.getName(itemId), " by ", base.GetComponent <Player>().owner.name, "!" }), itemId, steamID);
                if (userFromID.model.GetComponent <Life>().dead&& Time.realtimeSinceStartup - userFromID.model.GetComponent <Player>().owner.spawned > (float)Reputation.SPAWN_DELAY)
                {
                    if (userFromID.model.GetComponent <Player>().owner.reputation >= 0)
                    {
                        NetworkHandler.offsetReputation(base.networkView.owner, -1);
                    }
                    else
                    {
                        NetworkHandler.offsetReputation(base.networkView.owner, 1);
                    }
                    if (!base.networkView.isMine)
                    {
                        base.sendKilledPlayer(userFromID, base.networkView.owner);
                        //base.networkView.RPC("killedPlayer", base.networkView.owner, new object[0]);
                    }
                    else
                    {
                        base.GetComponent <Player>().killedPlayer();
                    }
                }
            }
        }
    }
예제 #6
0
 public void swingAnimal(NetworkViewID id, int limb)
 {
     if (!base.GetComponent <Life>().dead)
     {
         GameObject gameObject = NetworkView.Find(id).gameObject;
         if (gameObject != null && !gameObject.GetComponent <AI>().dead)
         {
             gameObject.GetComponent <AI>().damage((int)((float)MeleeStats.getDamage(base.GetComponent <Clothes>().item) * (1f + base.GetComponent <Skills>().warrior() * 0.4f) * DamageMultiplier.getMultiplierZombie(limb)));
             if (gameObject.GetComponent <AI>().dead)
             {
                 base.GetComponent <Skills>().learn(UnityEngine.Random.Range(gameObject.GetComponent <AI>().xp - 1, gameObject.GetComponent <AI>().xp + 2));
                 if (gameObject.name == "zombie")
                 {
                     if (!base.networkView.isMine)
                     {
                         base.networkView.RPC("killedZombie", base.networkView.owner, new object[0]);
                     }
                     else
                     {
                         base.GetComponent <Player>().killedZombie();
                     }
                 }
                 else if (!base.networkView.isMine)
                 {
                     base.networkView.RPC("killedAnimal", base.networkView.owner, new object[0]);
                 }
                 else
                 {
                     base.GetComponent <Player>().killedAnimal();
                 }
             }
         }
     }
 }
예제 #7
0
        protected override void WriteDataXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            ele.TryPathTo("DamageMultiplier", true, out subEle);
            subEle.Value = DamageMultiplier.ToString("G15");

            ele.TryPathTo("Flags", true, out subEle);
            subEle.Value = Flags.ToString();

            ele.TryPathTo("Type", true, out subEle);
            subEle.Value = Type.ToString();

            ele.TryPathTo("HealthPercent", true, out subEle);
            subEle.Value = HealthPercent.ToString();

            ele.TryPathTo("ActorValue", true, out subEle);
            subEle.Value = ActorValue.ToString();

            ele.TryPathTo("ToHitChance", true, out subEle);
            subEle.Value = ToHitChance.ToString();

            ele.TryPathTo("Explodable/ExplosionChance", true, out subEle);
            subEle.Value = ExplosionChance.ToString();

            ele.TryPathTo("Explodable/DebrisCount", true, out subEle);
            subEle.Value = ExplosionDebrisCount.ToString();

            ele.TryPathTo("Explodable/Debris", true, out subEle);
            ExplosionDebris.WriteXML(subEle, master);

            ele.TryPathTo("Explodable/Explosion", true, out subEle);
            Explosion.WriteXML(subEle, master);

            ele.TryPathTo("TrackingMaxAngle", true, out subEle);
            subEle.Value = TrackingMaxAngle.ToString("G15");

            ele.TryPathTo("Explodable/DebrisScale", true, out subEle);
            subEle.Value = ExplosionDebrisScale.ToString("G15");

            ele.TryPathTo("Severable/DebrisCount", true, out subEle);
            subEle.Value = SeverableDebrisCount.ToString();

            ele.TryPathTo("Severable/Debris", true, out subEle);
            SeverableDebris.WriteXML(subEle, master);

            ele.TryPathTo("Severable/Explosion", true, out subEle);
            SeverableExplosion.WriteXML(subEle, master);

            ele.TryPathTo("Severable/DebrisScale", true, out subEle);
            subEle.Value = SeverableDebrisScale.ToString("G15");

            ele.TryPathTo("GoreEffects/Translate/X", true, out subEle);
            subEle.Value = GoreEffectsTranslateX.ToString("G15");

            ele.TryPathTo("GoreEffects/Translate/Y", true, out subEle);
            subEle.Value = GoreEffectsTranslateY.ToString("G15");

            ele.TryPathTo("GoreEffects/Translate/Z", true, out subEle);
            subEle.Value = GoreEffectsTranslateZ.ToString("G15");

            ele.TryPathTo("GoreEffects/Rotation/X", true, out subEle);
            subEle.Value = GoreEffectsRotationX.ToString("G15");

            ele.TryPathTo("GoreEffects/Rotation/Y", true, out subEle);
            subEle.Value = GoreEffectsRotationY.ToString("G15");

            ele.TryPathTo("GoreEffects/Rotation/Z", true, out subEle);
            subEle.Value = GoreEffectsRotationZ.ToString("G15");

            ele.TryPathTo("Severable/ImpactDataSet", true, out subEle);
            SeverableImpactDataSet.WriteXML(subEle, master);

            ele.TryPathTo("Explodable/ImpactDataSet", true, out subEle);
            ExplosionImpactDataSet.WriteXML(subEle, master);

            ele.TryPathTo("Severable/DecalCount", true, out subEle);
            subEle.Value = SeverableDecalCount.ToString();

            ele.TryPathTo("Explodable/DecalCount", true, out subEle);
            subEle.Value = ExplosionDecalCount.ToString();

            WriteUnusedXML(ele, master);

            ele.TryPathTo("LimbReplacementScale", true, out subEle);
            subEle.Value = LimbReplacementScale.ToString("G15");
        }
예제 #8
0
 public HPSystem(int HpBase, DamageMultiplier damageMultiplier) : this(HpBase, new List <DamageMultiplier>() { damageMultiplier })
 {
 }
예제 #9
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;
            }
        }
예제 #10
0
 public void punchAnimal(NetworkViewID id, int limb)
 {
     if (!base.GetComponent <Life>().dead)
     {
         GameObject gameObject = NetworkView.Find(id).gameObject;
         if (gameObject != null && !gameObject.GetComponent <AI>().dead)
         {
             gameObject.GetComponent <AI>().damage((int)(14f * (1f + base.GetComponent <Skills>().warrior() * 0.4f) * DamageMultiplier.getMultiplierZombie(limb)));
             if (gameObject.GetComponent <AI>().dead)
             {
                 base.GetComponent <Skills>().learn(UnityEngine.Random.Range(2, 4));
             }
         }
     }
 }