示例#1
0
 protected virtual void Start()
 {
     mortality        = GetComponent <Mortality>();
     orientableEntity = GetComponent <OrientableEntity>();
     mortality.Revive();
     mortality.OnDeath      += OnDeath;
     mortality.OnHealthDown += OnHealthDown;
 }
    protected override void Start()
    {
        base.Start();
        mortality = GetComponent <Mortality>();
        mortality.initialHealth = 150;
        mortality.Revive();
        // GameObject.Find("UI Life Text").GetComponent<Text>().text = "150/150";

        mortality.OnHealthDown += OnLoseLife;

        GameManager.instance.uiManager.SetLife(mortality.health, mortality.health);
        GameManager.instance.uiManager.SetXp(currentXp, currentXp);
        GameManager.instance.uiManager.SetMoney(currentMoney, currentMoney);
    }
示例#3
0
    void OnTriggerStay2D(Collider2D other)
    {
        Mortality mortality = other.GetComponent <Mortality>();

        if (mortality == null)
        {
            return;
        }

        // Mortality tod check
        if (tag.Equals(TagName.TrapEnemy))
        {
            if (other.tag.Equals(TagName.Friendly))
            {
                if (state == State.OPEN)
                {
                    if (Time.time > nextAttackTime)
                    {
                        mortality.DecrementHealth(baseAttackDamage);
                        nextAttackTime = Time.time + timeBetweenAttack;
                    }
                }
            }
        }

        if (tag.Equals(TagName.TrapNeutral))
        {
            if (state == State.OPEN)
            {
                if (Time.time > nextAttackTime)
                {
                    mortality.DecrementHealth(baseAttackDamage);
                    nextAttackTime = Time.time + timeBetweenAttack;
                }
            }
        }

        //// Explosion
        //if (explosion != null)
        //{
        //    for (int i = 0; i < 3; i++)
        //    {
        //        Vector3 p = new Vector3(Random.Range(-0.2f, 0.2f), Random.Range(-0.2f, 0.2f), 0);
        //        Instantiate(explosion, new Vector2(transform.position.x + p.x, transform.position.y + p.y), Quaternion.identity);
        //    }
        //}
    }
 // Use this for initialization
 void Start()
 {
     mortality = GetComponent <Mortality>();
 }
示例#5
0
    void OnTriggerEnter2D(Collider2D other)
    {
        bool destroy = false;

        // Block Mask
        if (TagName.BlockMask.Contains(other.tag))
        {
            destroy = true;
        }

        // Mortality
        Mortality mortality = other.GetComponent <Mortality>();

        if (mortality != null)
        {
            if (other.gameObject != sender)
            {
                // Si projectile AMI
                if (tag.Equals(TagName.FriendlyProjectiles))
                {
                    PhysicalEntities physics = other.GetComponent <PhysicalEntities>();
                    //Ne recherche que les collisions avec les ennemys
                    if (other.tag.Equals(TagName.Enemy))
                    {
                        destroy = true;
                        mortality.DecrementHealth(damage);
                        if (physics != null && physics.bumpSensible)
                        {
                            Vector2 direction = other.transform.position - transform.position; //direction entre this and target
                            direction.Normalize();
                            physics.ApplyForce(direction * bumpForce);
                        }
                    }
                    if (TagName.BlockMask.Contains(other.tag))
                    {
                        destroy = true;
                        mortality.DecrementHealth(damage);
                    }
                }

                // Si projectile ENEMY
                if (tag.Equals(TagName.EnemyProjectiles))
                {
                    //Ne recherche que les collisions avec les friendly
                    if (other.tag.Equals(TagName.Friendly))
                    {
                        PhysicalEntities physics = other.GetComponent <PhysicalEntities>();
                        destroy = true;
                        mortality.DecrementHealth(damage);
                        if (physics != null && physics.bumpSensible)
                        {
                            Vector2 direction = other.transform.position - transform.position; //direction entre this and target
                            direction.Normalize();
                            physics.ApplyForce(direction * bumpForce);
                        }
                    }
                }
            }
        }

        // Destroy
        if (destroy)
        {
            gameObject.SetActive(false);
            // Explosion
            if (explosion != null)
            {
                for (int i = 0; i < 3; i++)
                {
                    Vector3 p = new Vector3(Random.Range(-0.2f, 0.2f), Random.Range(-0.2f, 0.2f), 0);

                    GameObject g = ObjectPool.instance.GetPooledObject(explosion);
                    g.GetComponent <Explosion>().Init();
                    g.transform.position = new Vector2(transform.position.x + p.x, transform.position.y + p.y);

                    //Instantiate(explosion, new Vector2(transform.position.x + p.x, transform.position.y + p.y), Quaternion.identity);
                }
            }
        }
    }
示例#6
0
 // Use this for initialization
 void Start()
 {
     mortality          = GetComponent <Mortality>();
     mortality.OnDeath += OnDeath;
 }
示例#7
0
        public HttpResponseMessage MortalityAddOrEdit([FromBody] MortalityDTO uDto)
        {
            string key;
            var    ur        = new AppUserRepository();
            var    companyId = 0;
            var    UserId    = ur.ValidateUser(uDto.Key, out key, ref companyId);

            AppUserRoleRepository aur = new AppUserRoleRepository();


            if (UserId > 0 && aur.IsInRole(UserId, "Chowtime"))
            {
                var thisuser    = ur.GetById(UserId);
                var pr          = new PondRepository();
                int thisfarm    = pr.GetById(int.Parse(uDto.PondId)).FarmId;
                int UsersFarmId = thisuser.UserFarms.Where(x => x.FarmId == thisfarm).SingleOrDefault().UserFarmId;
                uDto.UsersFarmId = UsersFarmId.ToString();
                uDto.FarmID      = thisfarm;

                var db = new AppEntities();

                var NEMortalityId = 0;
                if (int.TryParse(uDto.MortalityId, out NEMortalityId))
                {
                    if (NEMortalityId == -1)
                    {
                        //  creating new Feeding record
                        var mort = new Mortality();
                        mort.MortalityDate   = DateTime.Parse(uDto.MortalityDate);
                        mort.MortalityPounds = int.Parse(uDto.MortalityPounds);
                        mort.PondId          = int.Parse(uDto.PondId);
                        mort.UsersFarmId     = UsersFarmId;
                        db.Mortalities.Add(mort);
                        db.SaveChanges();

                        uDto.MortalityId = mort.MortalityId.ToString();
                        uDto.Key         = key;
                        var response = Request.CreateResponse(HttpStatusCode.Created, uDto);
                        response.Headers.Location = new Uri(Url.Link("Default", new
                        {
                            id = mort.MortalityId
                        }));
                        return(response);
                    }
                    else
                    {
                        //  editing existing Feeding record
                        var mort = db.Mortalities.Find(NEMortalityId);
                        mort.MortalityDate   = DateTime.Parse(uDto.MortalityDate);
                        mort.MortalityPounds = int.Parse(uDto.MortalityPounds);
                        mort.PondId          = int.Parse(uDto.PondId);
                        mort.UsersFarmId     = UsersFarmId;
                        db.SaveChanges();


                        uDto.Key = key;
                        return(Request.CreateResponse(HttpStatusCode.Accepted, uDto));
                    }
                }
                //  no idea what this is
                var msg = "invalid data structure submitted";
                return(Request.CreateResponse(HttpStatusCode.BadRequest, msg));
            }
            var message = "validation failed";

            return(Request.CreateResponse(HttpStatusCode.NotFound, message));
        }