Exemple #1
0
 public void Init(Entity owner, Vector2 spawnPosition, Vector2 direction, int teamId, bool suspressed, Entity possibleVictim = null)
 {
     this.owner      = owner;
     this.suspressed = suspressed && suspressedDamage > 0;
     Position        = spawnPosition - new Vector2(texture.Width / 2, texture.Height / 2);
     this.direction  = direction;
     this.teamId     = teamId;
     elapsedLifeTime = 0;
     if (possibleVictim != null && rayCastShot)
     {
         DamageAbleObject dmg = possibleVictim.GetComponent <DamageAbleObject>();
         if (dmg != null)
         {
             dmg.ChangeHealth(this, suspressed ? -suspressedDamage : -damage);
         }
     }
 }
Exemple #2
0
        private void Projectile_OnTriggerEnter(object sender, CollisionArgs e)
        {
            if (e.CollisionObject != Owner && e.CollisionObject.Blocking)
            {
                if (!rayCastShot)
                {
                    DamageAbleObject health = e.CollisionObject.GetComponent <DamageAbleObject>();
                    if (health != null)
                    {
                        health.ChangeHealth(this, suspressed ? -suspressedDamage :  -damage);
                    }

                    if (e.CollisionObject.Name != "Cover")
                    {
                        Destroy();
                    }
                    else
                    {
                        crossedCover = true;
                    }
                }
            }
        }
Exemple #3
0
        private void Think(float elapsedMs)
        {
            if (npcs != null)
            {
                if (SearchPlayer())
                {
                    if (inHand.AmmoInMag > 0)
                    {
                        if (Aim(npcsInView[0].Center, Center))
                        {
                            if (inHand.Reloading)
                            {
                                if (inHand.Slot == Weapon.WeaponSlot.Primary)
                                {
                                    SwitchWeapon(Weapon.WeaponSlot.Secondary);
                                }
                                else
                                {
                                    SwitchWeapon(Weapon.WeaponSlot.Primary);
                                }
                            }

                            if (inHand.AmmoInMag > 0 && !inHand.Reloading)
                            {
                                Weapon.FireState state = Attack(npcsInView[0]);
                                switch (state)
                                {
                                case Weapon.FireState.OutOfAmmo:     //Stop thinking?
                                    Destroy();
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!inHand.Reloading)
                        {
                            Reload();
                        }
                    }
                }
                else
                {
                    elapsedTimeSinceContact += elapsedMs;
                    if (elapsedTimeSinceContact > 1000f && !inHand.Reloading && inHand.AmmoInMag / inHand.MaxMagSize < 0.2f)
                    {
                        Reload();
                    }

                    if (elapsedTimeSinceContact < 2000f)
                    {
                        Aim(lastKnownPosition, Center);
                    }
                    else
                    {
                        Move();
                        Aim(Position + direction, Position, true);
                    }
                }

                if (Vector2.Distance(prevPosition, Position) > 5)
                {
                    elapsedTimeDoingNothing = 0;
                }

                elapsedTimeDoingNothing += elapsedMs;
                if (elapsedTimeDoingNothing > 10000)
                {
                    health.ChangeHealth(this, -health.MaxHealth);
                }
                prevPosition = Position;
            }
        }