Example #1
0
 private void OnTriggerEnter(Collider collision)
 {
     if (collision.tag == "Player")
     {
         hp = collision.gameObject.GetComponent <HpSystem>();
         hp.AdjustHealth(DmgCount);
     }
 }
Example #2
0
 public BodyPart(EBodyType bodyType, HpSystem hpSystem, string name, float size, CapacityInfo capacityInfo)
 {
     this.BodyType     = bodyType;
     this.HpSystem     = hpSystem;
     this.Name         = name;
     this.NameCustom   = name;
     this.Size         = size;
     this.CapacityInfo = capacityInfo;
 }
Example #3
0
 protected override void Start()
 {
     base.Start();
     animator     = GetComponentInChildren <Animator>();
     hpSystem     = new HpSystem((int)(MaxHp * (1 + Difficulty / 10f) * (GameManager.isMultiplayer ? 1.5 : 1)));
     bubbleOffset = new Vector3(0, 0.6f, 0);
     bubbleScale  = 2;
     spells[0]    = gameObject.AddComponent <BossFireball>() as Spell;
     spells[1]    = gameObject.AddComponent <EnemyTornado>() as Spell;
 }
Example #4
0
 protected override void Start()
 {
     base.Start();
     animator     = GetComponentInChildren <Animator>();
     hpSystem     = new HpSystem((int)(MaxHp * GameObject.Find("GameManager").GetComponent <GameManager>().level *(1 + Difficulty / 10f) * (GameManager.isMultiplayer ? 1.5f : 1f)));
     bubbleOffset = new Vector3(0, 1, 0);
     bubbleScale  = 4;
     CmdUpdateColor();
     AttackDamage = Random.Range(2, 6);
 }
Example #5
0
 private void OnTriggerEnter(Collider other)
 {
     Debug.Log("Ping");
     if (other.tag == "Player")
     {
         hp = other.gameObject.GetComponent <HpSystem>();
         hp.AdjustHealth(HealingCount);
         Destroy(gameObject);
     }
 }
Example #6
0
    // Update is called once per frame

    private void OnTriggerEnter(Collider other)
    {
        if (atk.isAttacking == true && other.tag == "Enemy")
        {
            hp = other.gameObject.GetComponent <HpSystem>();
            hp.AdjustHealth(-weapon.AttackDamage);
            curDur--;
            if (curDur == 0)
            {
                wp.weaponName = "";
                wp.isPicked   = false;
                Destroy(gameObject);
            }
        }
    }
Example #7
0
 protected override void HandleDying()
 {
     if (mode == 1)
     {
         hpSystem               = new HpSystem(MaxHp * (1 + Difficulty / 10));
         hpBar.fillAmount       = hpSystem.CurrentLifePercentage();
         ScreenHpBar.fillAmount = hpSystem.CurrentLifePercentage();
         mode = 2;
     }
     else
     {
         base.HandleDying();
         animator.SetBool("WalkForward", false);
         animator.SetTrigger("Die");
         SceneManager.LoadScene("VictoryScene");
     }
 }
Example #8
0
    protected override void Start()
    {
        base.Start();
        rb               = GetComponent <Rigidbody>();
        popUpText        = Resources.Load <GameObject>("CoinPopUp");
        distanceToGround = GetComponent <Collider>().bounds.extents.y;
        animator         = GetComponentInChildren <Animator>();

        hpSystem = new HpSystem(100);

        if (!isLocalPlayer)
        {
            clientHpBar.SetActive(true);
            hpBar = clientHpBar.transform.Find("hp_background").Find("hp_filled").GetComponentInChildren <Image>();
            GameManager.AddPlayer(this);
        }
        DontDestroyOnLoad(this);
    }
Example #9
0
 public HpSystemDamageEvent TakeDamage(Damage damage) => HpSystem.TakeDamage(damage);
 public string HpSystemToRichString(HpSystem hpSystem)
 {
     return(RichStrings.WithColor($"[{hpSystem.HpCurrent}/{hpSystem.HpBase}]", DamageStates.DamageStateToColor(hpSystem.GetDamageState())));
 }
Example #11
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;
            }
        }
 protected override void Start()
 {
     base.Start();
     spell    = GetComponent <Spell>();
     hpSystem = new HpSystem(MaxHp);
 }