Ejemplo n.º 1
0
 public bool SetDamage(int damage, IDestroyable victim)
 {
     victim.TakeDamage(damage);
     if (victim.GetHealth() <= 0)
     {
         return(true);
     }
     return(false);
 }
        public virtual void HitAsteroid(IDestroyable asteroid)
        {
            if (hit)
            {
                return;
            }
            else
            {
                hit = true;
            }

            if (bullet.Owner.IsCurrentPlayerOrBot())
            {
                bullet.Owner.AddScoreAndShow(ScoreDefines.CANNON_HIT);
                if (bullet.Owner.IsCurrentPlayer())
                {
                    bullet.SceneMgr.FloatingTextMgr.AddFloatingText(ScoreDefines.CANNON_HIT, bullet.Center, FloatingTextManager.TIME_LENGTH_1,
                                                                    FloatingTextType.SCORE);
                }

                if (asteroid is UnstableAsteroid)
                {
                    Rect   opponentLoc = PlayerBaseLocation.GetBaseLocation(bullet.Owner.GetPosition() == PlayerPosition.RIGHT ? PlayerPosition.LEFT : PlayerPosition.RIGHT);
                    double xMin        = opponentLoc.X;
                    double xMax        = opponentLoc.X + opponentLoc.Width;

                    if (asteroid.Position.Y > SharedDef.VIEW_PORT_SIZE.Height * 0.4 &&
                        asteroid.Position.X >= xMin && asteroid.Position.X <= xMax)
                    {
                        if (bullet.Owner.IsCurrentPlayer())
                        {
                            bullet.SceneMgr.FloatingTextMgr.AddFloatingText(Strings.ft_score_cannon_unstable_above_enemy, bullet.Center,
                                                                            FloatingTextManager.TIME_LENGTH_4, FloatingTextType.BONUS_SCORE, FloatingTextManager.SIZE_BIG, false, true);
                        }
                        bullet.Owner.AddScoreAndShow(ScoreDefines.CANNON_DESTROYED_UNSTABLE_ASTEROID_ABOVE_ENEMY);
                    }
                }
            }

            asteroid.TakeDamage(bullet.Damage, bullet);

            NetOutgoingMessage msg = bullet.SceneMgr.CreateNetMessage();

            msg.Write((int)PacketType.BULLET_HIT);
            msg.Write(bullet.Id);
            msg.Write(asteroid.Id);
            msg.Write(bullet.Damage);
            bullet.SceneMgr.SendMessage(msg);

            EmmitorGroup g = ParticleEmmitorFactory.CreateBulletImplosionEmmitor(bullet.SceneMgr, bullet.Center, bullet.Color);

            g.Attach(bullet.SceneMgr, false);
        }
Ejemplo n.º 3
0
 //disappears when hitting something
 private void OnCollisionEnter2D(Collision2D _collision)
 {
     //Debug.Log(myOwner.gameObject);
     //Debug.Log(_collision.gameObject);
     if (_collision.gameObject != myOwner.gameObject)
     {
         MonoBehaviour[] list = _collision.gameObject.GetComponents <MonoBehaviour>();
         foreach (MonoBehaviour mb in list)
         {
             if (mb is IDestroyable)
             {
                 IDestroyable breakable = (IDestroyable)mb;
                 breakable.TakeDamage(1);
                 //base.Destroy();
                 myOwner.gun.LoadBullet();
             }
         }
     }
     else
     {
         myOwner.gun.LoadBullet();
     }
 }
Ejemplo n.º 4
0
        private void ReceivedBulletHitMsg(NetIncomingMessage msg)
        {
            long bulletId = msg.ReadInt64();
            long aId      = msg.ReadInt64();
            int  damage   = msg.ReadInt32();

            IProjectile  bullet = null;
            IDestroyable target = null;

            foreach (ISceneObject obj in objects)
            {
                if (obj.Id == bulletId)
                {
                    if (obj is IProjectile)
                    {
                        bullet = obj as IProjectile;
                    }

                    ExplodingSingularityBulletControl c = obj.GetControlOfType <ExplodingSingularityBulletControl>();
                    if (c != null)
                    {
                        c.StartDetonation();
                    }

                    break;
                }
            }

            foreach (ISceneObject obj in objects)
            {
                if (obj.Id != aId)
                {
                    continue;
                }

                if (obj is IDestroyable)
                {
                    target = (obj as IDestroyable);
                }
                else
                {
                    Logger.Error("Object id " + bulletId + " (" + obj.GetType().Name + ") is supposed to be a instance of IDestroyable but it is not");
                }

                break;
            }

            if (bullet == null)
            {
                return;
            }

            if (target != null)
            {
                target.TakeDamage(damage, bullet);
            }
            else
            {
                idsToRemove.Add(aId);
            }

            if (!(bullet is SingularityExplodingBullet))
            {
                bullet.DoRemoveMe();
            }
        }