Esempio n. 1
0
 public void initialize(HealthBox hb)
 {
     print("init button:");
     print(button);
     healthBox = hb;
     button.onClick.AddListener(delegate { healthBox.Advance(); });
     button.onClick.AddListener(delegate { advanceImage(); });
 }
    void Start()
    {
        ammoBox   = GetComponent <AmmoBox>();
        healthBox = GetComponent <HealthBox>();

        traitComponent = GetComponent <TraitComponent>();

        UpdateParams();
    }
        private void HealthBox_Click(object sender, EventArgs e)
        {
            if (!healthEditMode)
            {
                healthEditMode = true;

                HealthBox.Text = token.CurrentHP.ToString();
                HealthBox.SelectAll();
            }
        }
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        BotUtility botUtility = animator.GetComponentInParent <BotUtility>();
        HealthBox  target     = botUtility.FindClosestHealth();

        if (!botUtility.NavigateTo(target))
        {
            animator.SetTrigger("failed");
        }
    }
Esempio n. 5
0
    public void AddBox(HealthBox hb)
    {
        GameObject healthbox = Resources.Load <GameObject> ("Prefabs/UI/HealthBox");
        GameObject newBox    = Instantiate(healthbox);

        healthBoxList.Add(newBox);
        newBox.GetComponent <HealthBoxUI> ().initialize(hb);
        switch (hb.level)
        {
        case 7:
        {
            newBox.transform.SetParent(inc.transform);
            break;
        }

        case 0:
        {
            newBox.transform.SetParent(zero.transform);
            break;
        }

        case 1:
        {
            newBox.transform.SetParent(one.transform);
            break;
        }

        case 2:
        {
            newBox.transform.SetParent(two.transform);
            break;
        }

        case 4:
        {
            newBox.transform.SetParent(four.transform);
            break;
        }

        default:
        {
            break;
        }
        }
    }
        private void checkHpBoxEditMode()
        {
            if (!healthEditMode)
            {
                return;
            }

            HealthBox.DeselectAll();
            HPMinus.Select();
            healthEditMode = false;

            try
            {
                int newHp = Convert.ToInt32(HealthBox.Text);

                if (newHp >= 0 && newHp <= token.MaxHP)
                {
                    token.CurrentHP = Convert.ToInt32(HealthBox.Text);
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 7
0
    void OnTriggerEnter(Collider otherCollider)
    {
        if (otherCollider.GetComponent <AmmunationBox>() != null)
        {
            AmmunationBox ammunationBox = otherCollider.GetComponent <AmmunationBox>();
            ammunation += ammunationBox.ammunation;
            Destroy(ammunationBox.gameObject);
        }
        else if (otherCollider.GetComponent <HealthBox>() != null)
        {
            HealthBox healthBox = otherCollider.GetComponent <HealthBox>();
            health += healthBox.health;
            Destroy(healthBox.gameObject);
        }
        else
        {
            /* Do nothing */
        }

        if (!isHurt)
        {
            GameObject gameObject = null; //hazard

            if (otherCollider.GetComponent <Enemy>() != null)
            {
                Enemy enemy = otherCollider.GetComponent <Enemy>();
                if (!enemy.IsKilled)
                {
                    gameObject = enemy.gameObject;
                    health    -= enemy.damage;
                }
            }
            else if (otherCollider.GetComponent <Bullet>() != null)
            {
                Bullet bullet = otherCollider.GetComponent <Bullet>();
                if (!bullet.IsShotByPlayer)
                {
                    gameObject = bullet.gameObject;
                    health    -= bullet.bulletDamage;
                    bullet.gameObject.SetActive(false);
                }
            }
            else
            {
                /* Do nothing */
            }

            if (gameObject != null)
            {
                isHurt = true;

                Vector3 hurtDirection   = (transform.position - gameObject.transform.position).normalized;
                Vector3 recoilDirection = (hurtDirection + Vector3.up).normalized;
                GetComponent <ForceReceiver>().AddForce(recoilDirection, recoilForce);

                StartCoroutine(HurtRoutine());
            }

            if (health <= 0)
            {
                if (!isKilled)
                {
                    isKilled = true;
                    OnKill();
                }
            }
        }
    }
 void Awake()
 {
     ammoBox        = GetComponent <AmmoBox>();
     healthBox      = GetComponent <HealthBox>();
     traitComponent = GetComponent <Collectible>();
 }
Esempio n. 9
0
                static void Postfix(Battle __instance)
                {
                    ++tickCount;
                    if (tickCount % (TICKS_PER_SECOND * 10) == 0)
                    {
                        logger.LogDebug($"ComputeTick(): 10 second interval");

                        //var sceneTraverse = Traverse.Create(__instance.Scene);
                        //var updateableEntitiesProperty = sceneTraverse.Property("UpdateableEntities");
                        //var updateableEntities = updateableEntitiesProperty.GetValue() as IEnumerable;

                        //foreach (var updateableEntity in updateableEntities)
                        //{
                        //    if (updateableEntity.GetType().IsSubclassOf(typeof(Unit)) || updateableEntity.GetType() == typeof(Unit))
                        //    {
                        //        var unit = updateableEntity as Unit;
                        //        if (unit.Faction == unit.Battle.LocalPlayerFactionId)
                        //        {
                        //            float healAmount = unit.MaxHealth * 0.05f;
                        //            unit.DamageModel.Heal(healAmount, unit.EntityId);
                        //        }
                        //    }
                        //}

                        foreach (var unit in __instance.Scene.Units)
                        {
                            if (unit.Faction == __instance.LocalPlayerFactionId)
                            {
                                float healAmount = unit.MaxHealth * 0.05f;
                                unit.DamageModel.Heal(healAmount, unit.EntityId);
                            }
                        }

                        foreach (var structure in __instance.Scene.Structures)
                        {
                            if (structure.Faction == __instance.LocalPlayerFactionId)
                            {
                                float healAmount = structure.MaxHealth * 0.05f;
                                structure.DamageModel.Heal(healAmount, structure.EntityId);
                            }
                        }
                    }

                    if (tickCount % (TICKS_PER_SECOND * 60) == 0)
                    {
                        foreach (var unit in __instance.Scene.Units)
                        {
                            if (unit.Faction == __instance.LocalPlayerFactionId)
                            {
                                try
                                {
                                    logger.LogDebug($"Friendly unit: {unit} {unit.EntityId}, squad id: {unit.SquadId}, squad {unit.Squad}");
                                    if (unit is IExperienceReceiver unitReceiver)
                                    {
                                        var oldExp = unitReceiver.VeterancySystem.CurrentXP;
                                        unitReceiver.VeterancySystem.AddExperience(10000, RankChangedReason.Experience);
                                    }
                                    if (unit.Squad == null)
                                    {
                                        continue;
                                    }
                                    if (unit.Squad is IExperienceReceiver squadReceiver)
                                    {
                                        var oldExp = squadReceiver.VeterancySystem.CurrentXP;
                                        squadReceiver.VeterancySystem.AddExperience(10000, RankChangedReason.Experience);
                                    }
                                    if (unit.Squad.Health == unit.Squad.MaxHealth)
                                    {
                                        continue;
                                    }
                                    var healthBoxConfig = new HealthBoxConfig("");
                                    healthBoxConfig.HealingAmount = 1000;
                                    var healthBox         = new HealthBox(__instance, healthBoxConfig, 0, unit.Squad.Position, 0);
                                    var healthBoxTraverse = Traverse.Create(healthBox);
                                    var args = new object[] { unit.Squad };
                                    healthBoxTraverse.Method("Pickup", args).GetValue(args);
                                    logger.LogDebug($"Reinforced squad: {unit.Squad}");
                                }
                                catch (Exception e)
                                {
                                    logger.LogWarning($"ComputeTick(): 60 second interval encountered an error: {e.Message}");
                                }
                            }
                        }
                    }
                }