예제 #1
0
        public override void Handle(GameService session)
        {
            Angle += (float)(Math.PI * 0.05 * (0.5 - Program.rnd.NextDouble()));
            BulletEntity bullet = new BulletEntity(session.Room, Angle, session.Room.Players[session.Id]);

            bullet.Teleport(session.Room.Players[session.Id].Entity.X, session.Room.Players[session.Id].Entity.Y);
            new EntityPacket(bullet).Send();

            base.Handle(session);
        }
예제 #2
0
    //删除单位
    public void DestroyBulletEntity(int id)
    {
        BulletEntity unity = m_BulletEntitys[id];

        if (unity != null)
        {
            unity.Destroy();
            m_BulletEntitys.Remove(id);
        }
    }
 public static BulletCollisionEventPayload Create(BulletEntity bulletEntity, Transform collisionTransform, Vector2 collisionPoint, Vector2 collisionNormal)
 {
     return(new BulletCollisionEventPayload
     {
         BulletEntity = bulletEntity,
         CollisionTransform = collisionTransform,
         CollisionPoint = collisionPoint,
         CollisionNormal = collisionNormal
     });
 }
예제 #4
0
    private void OnPlayHitHandler()
    {
        if (Target == null)
        {
            return;
        }
        if (actionInfo != null && AnimationType.IsAttackAction(actionInfo.ActionName))
        {
            if (!actionInfo.IsLangAttack)
            {
                if (actionInfo.IsHitMove && actionInfo.HitMoveDistance > 0f && actionInfo.HitMoveTime > 0f)
                {
                    target.DoHitMove(creature.GetPosition(), actionInfo.HitMoveDistance, actionInfo.HitMoveTime);
                }
                else if (actionInfo.IsHitFly && actionInfo.HitFlyDistance > 0f && actionInfo.HitFlyTime > 0f)
                {
                    target.DoHitFly(creature.GetPosition(), actionInfo.HitFlyDistance, actionInfo.HitFlyTime);
                }
                else
                {
                    target.DoHit();
                }
            }
            else
            {
                for (int i = 0; i < actionInfo.ActionEffectInfos.Count; ++i)
                {
                    EffectInfo effectInfo = actionInfo.ActionEffectInfos[i];
                    if (effectInfo.EffectType == EffectTypes.Bullet)
                    {
                        BulletEntity bulletEntity = new BulletEntity();

                        Transform bron = creature.Model.GetChild(effectInfo.BindName);
                        if (bron != null)
                        {
                            bulletEntity.ID              = Entity.UniqueID;
                            bulletEntity.OwnerId         = creature.ID;
                            bulletEntity.TargetId        = Target.ID;
                            bulletEntity.HitFly          = actionInfo.IsHitFly;
                            bulletEntity.HitFlyDistance  = actionInfo.HitFlyDistance;
                            bulletEntity.HitFlyTime      = actionInfo.HitFlyTime;
                            bulletEntity.HitMove         = actionInfo.IsHitMove;
                            bulletEntity.HitMoveDistance = actionInfo.HitMoveDistance;
                            bulletEntity.HitMoveTime     = actionInfo.HitMoveTime;
                            Vector3 pos  = Target.Model.GetChild(BoneTypes.CenterPoint).position;
                            Vector3 pos1 = Target.Container.transform.TransformDirection(Vector3.back * 5f);
                            pos1.y = pos.y;
                            bulletEntity.Play(bron.position, pos + pos1, effectInfo.FlySpeed, effectInfo.EffectName, effectInfo.EffectName, effectInfo.SoundName, effectInfo.SoundPlayDelayTime);
                        }
                    }
                }
            }
        }
    }
예제 #5
0
    public override void beHit(BulletEntity bullet, double damageRate = 1)
    {
        bool isDead = this._dead;

        base.beHit(bullet, damageRate);

        //被这个子弹干掉了。 算击杀。
        if (this._dead && !isDead)
        {
            bullet.ownerPlayer.killPlayer(this);
        }
    }
        private void OnBulletThrowEvent(BulletThrowEventPayload payload)
        {
            BulletEntity bulletEntity = GameManager.Instance.GameFactory.BulletFactory.Create();

            bulletEntity.SetOwner(payload.Sender);
            bulletEntity.SetEventBus(m_eventBus);
            bulletEntity.transform.position = payload.FromPosition;
            bulletEntity.SetDirection(payload.ToDirection);
            bulletEntity.SetForce(payload.Force);

            GameManager.Instance.GameFactory.BulletFactory.DestroyEntity(bulletEntity, 10);
            GameManager.Instance.GameFactory.BulletFactory.DestroyEntity(bulletEntity, x => Vector2.Distance(payload.FromPosition, x.transform.position) > 10);
        }
예제 #7
0
파일: Prototype.cs 프로젝트: Publol/Engine
        public static T CreateCopyOf <T>(string prototypeID)
            where T : class
        {
            if (typeof(T).Equals(typeof(GameObject)))
            {
                if (_gameObjectPrototypes.ContainsKey(prototypeID))
                {
                    BaseEntity entity = _gameObjectPrototypes[prototypeID].Entity;
                    GameObject obj    = null;
                    if (entity.GetType().Equals(typeof(BulletEntity)))
                    {
                        BulletEntity bulletEntity = entity as BulletEntity;
                        obj = Factory.Build <GameObject>((GraphicModule)_gameObjectPrototypes[prototypeID].Graphic.Clone(),
                                                         (BulletEntity)bulletEntity.Clone());
                    }
                    if (entity.GetType().Equals(typeof(EnemyEntity)))
                    {
                        EnemyEntity bulletEntity = entity as EnemyEntity;
                        obj = Factory.Build <GameObject>((GraphicModule)_gameObjectPrototypes[prototypeID].Graphic.Clone(),
                                                         (EnemyEntity)bulletEntity.Clone());
                    }
                    if (entity.GetType().Equals(typeof(PlayerEntity)))
                    {
                        PlayerEntity bulletEntity = entity as PlayerEntity;
                        obj = Factory.Build <GameObject>((GraphicModule)_gameObjectPrototypes[prototypeID].Graphic.Clone(),
                                                         (PlayerEntity)bulletEntity.Clone());
                    }
                    return(obj as T);
                }
            }

            if (typeof(T).Equals(typeof(GraphicModule)))
            {
                if (_graphicModulePrototypes.ContainsKey(prototypeID))
                {
                    GraphicModule graphic = _graphicModulePrototypes[prototypeID];
                    GameObject    obj     = null;
                    if (graphic.GetType().Equals(typeof(TexturedGraphicModule)))
                    {
                        return((TexturedGraphicModule)_graphicModulePrototypes[prototypeID].Clone() as T);
                    }
                    if (graphic.GetType().Equals(typeof(GraphicModule)))
                    {
                        return((GraphicModule)_graphicModulePrototypes[prototypeID].Clone() as T);
                    }
                }
            }


            return(null);
        }
예제 #8
0
 public BulletEntity Shoot(Vector3 pos, Vector3 vel, float lifetime = 10.0f, int owner_id=0)
 {
     var e = new BulletEntity
     {
         position = pos,
         velosity = vel,
         rotation = Quaternion.LookRotation(vel),
         lifetime = lifetime,
         owner_id = owner_id,
     };
     m_entities_to_add[m_add_index++] = e;
     m_add_index %= m_entities_to_add.Length;
     return e;
 }
예제 #9
0
    //protected override void intervalHandler() {
    //    if(null != this.target) {
    //        Dictionary<string, object> bulletData = (Dictionary<string, object>)skillData["bullet"];
    //        BulletEntity bullet = this._player.map.createFightEntity(ConfigConstant.ENTITY_BULLET) as BulletEntity;
    //        bullet.targets = new List<PersonEntity>() { this.target};
    //        bullet.owner = this._player;
    //        bullet.initConfig(bulletData);
    //        bullet.atk = this.damage;
    //        this.hitCount = Math.Min(this.hitCount + 1, this._maxHitCount);
    //    }
    //}

    protected override void useSkill()
    {
        if (null != this.target)
        {
            Dictionary <string, object> bulletData = (Dictionary <string, object>)skillData["bullet"];
            BulletEntity bullet = this._person.map.createFightEntity(ConfigConstant.ENTITY_BULLET) as BulletEntity;
            bullet.lockTarget = this.target;
            bullet.owner      = this._person;
            bullet.initConfig(bulletData);
            bullet.atk    = this.damage;
            this.hitCount = Math.Min(this.hitCount + 1, this._maxHitCount);
            this._cdTime.reset();
        }
    }
 public void Shoot(Vector3[] pos, Vector3[] vel, float lifetime = 10.0f, int owner_id = 0)
 {
     for (int i = 0; i < pos.Length; ++i)
     {
         var e = new BulletEntity
         {
             position = pos[i],
             velosity = vel[i],
             rotation = Quaternion.LookRotation(vel[i]),
             lifetime = lifetime,
         };
         m_entities_to_add[m_add_index++] = e;
         m_add_index %= m_entities_to_add.Length;
     }
 }
    public BulletEntity Shoot(Vector3 pos, Vector3 vel, float lifetime = 10.0f, int owner_id = 0)
    {
        var e = new BulletEntity
        {
            position = pos,
            velosity = vel,
            rotation = Quaternion.LookRotation(vel),
            lifetime = lifetime,
            owner_id = owner_id,
        };

        m_entities_to_add[m_add_index++] = e;
        m_add_index %= m_entities_to_add.Length;
        return(e);
    }
예제 #12
0
    ///判断和子弹的碰撞
    public void checkBullet()
    {
        if (this._checkBulletType == 0)
        {
            return;
        }
        //TODO:这里检测了两次碰撞。 只用一次其实就够了。 filter传true。
        //Biggo修改
        List <FightEntity> bullets = this._map.getFightEntitysByRange(this._shape, new List <int> {
            ConfigConstant.ENTITY_BULLET
        }, (FightEntity entity1, FightEntity entity2) => {
            return(((BulletEntity)entity2).checkBarrier);
        }, -1);

        bullets = new List <FightEntity>(bullets);//这个要副本的!因为在bomb的时候 会改变这个通用的数组的长度。
        for (int i = 0, len = bullets.Count; i < len; i++)
        {
            BulletEntity bullet   = (BulletEntity)bullets[i];
            Vector2D     deltaV2d = bullet.findDelta.clone();
            double       dist     = bullet.findDist;
            double       radius   = bullet.shape.radius + this._shape.radius;
            //障碍物到命中点的向量
            Vector2D hitDelta          = bullet.getHitPos(this);
            double   angleHitDelta     = hitDelta.angle;
            double   angleBulletBounce = bullet.velocity.angle + Math.PI;
            //子弹回弹方向如果与命中向量夹角大于90,则说明子弹本身就是向外的,不用处理
            double angleDelta = Math2.deltaAngle(angleHitDelta, angleBulletBounce);
            if (Math.Abs(angleDelta) < Math.PI / 2)
            {
                if (this._checkBulletType == 1)
                {
                    //新子弹的速度方向改变
                    bullet.velocity.angle = bullet.angle = angleHitDelta - angleDelta * 0.5f;
                }
                else if (this._checkBulletType == 2)
                {
                    //引爆消亡逻辑
                    bullet.bomb();
                }

                deltaV2d.length = bullet.backForce * this._bounceSelfRate * 0.6f;
                addForce(deltaV2d);
                this.dispatchEventWith(EventConstant.HIT);
            }
        }
    }
예제 #13
0
        public override void Click(Entity entity, ItemStack item)
        {
            if (!(entity is HumanoidEntity))
            {
                // TODO: non-humanoid support
                return;
            }
            HumanoidEntity character = (HumanoidEntity)entity;
            double         fireRate  = FireRate * item.GetAttributeF("firerate_mod", 1f);

            if (item.Datum != 0 && !character.WaitingForClickRelease && (character.TheRegion.GlobalTickTime - character.LastGunShot >= fireRate))
            {
                double spread = Spread * item.GetAttributeF("spread_mod", 1f);
                double speed  = Speed * item.GetAttributeF("speed_mod", 1f);
                int    shots  = (int)((double)Shots * item.GetAttributeF("shots_mod", 1f));
                for (int i = 0; i < shots; i++)
                {
                    BulletEntity be = new BulletEntity(character.TheRegion);
                    be.SetPosition(character.GetEyePosition()); // TODO: ItemPosition?
                    be.NoCollide.Add(character.EID);
                    Location ang = character.Direction;
                    ang.Yaw   += Utilities.UtilRandom.NextDouble() * spread * 2 - spread;
                    ang.Pitch += Utilities.UtilRandom.NextDouble() * spread * 2 - spread;
                    be.SetVelocity(Utilities.ForwardVector_Deg(ang.Yaw, ang.Pitch) * speed);
                    be.Size         = RoundSize;
                    be.Damage       = ImpactDamage;
                    be.SplashSize   = SplashSize;
                    be.SplashDamage = SplashMaxDamage;
                    character.TheRegion.SpawnEntity(be);
                }
                if (ShotPerClick)
                {
                    character.WaitingForClickRelease = true;
                }
                character.LastGunShot = character.TheRegion.GlobalTickTime;
                item.Datum           -= 1;
                if (character is PlayerEntity)
                {
                    ((PlayerEntity)character).Network.SendPacket(new SetItemPacketOut(character.Items.Items.IndexOf(item), item));
                }
            }
            else if (item.Datum == 0 && !character.WaitingForClickRelease)
            {
                Reload(character, item);
            }
        }
예제 #14
0
 private void UpdateShooting()
 {
     if (m_shootingInputOn)
     {
         if ((Time.time - BULLET_COOLDOWN_TIME_SECONDS) > m_timeSinceLastBulletFired)
         {
             m_timeSinceLastBulletFired = Time.time;
             var bulletStartPosition = m_playerShipEntity.Position;
             var bullet = new BulletEntity();
             bullet.Position = m_playerShipEntity.Position;
             bullet.Velocity = new Vector2(0f, 2f);
             m_gameEntities.Add(bullet);
         }
         else
         {
             // RPB: Do not shoot because we are within the cooldown time.
         }
     }
 }
예제 #15
0
        public HostBotController(BotEntity botEntityPrefab, TileMapInfo tileMapInfo, BulletEntity bulletPrefab,
                                 CameraFollower cameraFollower, PlayerHpPresenter playerHpPresenter, RunButtonEvent runButtonEvent,
                                 ScriptText scriptText, ErrorMsg errorMsg, SoundManager soundManager, GameSignalingHost gameSignalingHost,
                                 MeleeAttackEntity meleeAttackEntity, ProcessScrollViewPresenter processScrollViewPresenter,
                                 EventSystemWatcher eventSystemWatcher)
        {
            this.errorMsg          = errorMsg;
            this.playerHpPresenter = playerHpPresenter;
            var botEntity = Object.Instantiate(botEntityPrefab);

            tileMapInfo.PlayerTankTransform = botEntity.transform;
            botEntity.gameObject.layer      = LayerMask.NameToLayer("PlayerBot");
            cameraFollower.SetPlayerPosition(botEntity.transform);
            var botEntityAnimation = botEntity.GetComponent <BotEntityAnimation>();

            botEntity.transform.position = tileMapInfo.GetPlayer1StartPosition();
            MeleeAttackApplication meleeAttackApplication = new MeleeAttackApplication(meleeAttackEntity, soundManager);
            var gun = new Gun(
                soundManager,
                new BulletEntityCreator(bulletPrefab, LayerMask.NameToLayer("PlayerBullet")),
                false
                );

            botApplication = new BotApplication.BotApplication(
                botEntity, botEntityAnimation, tileMapInfo, eventSystemWatcher, gun,
                meleeAttackApplication
                );
            var hookBotApplication = new HostBotCommandsHook(botApplication, gameSignalingHost);

            javaScriptEngine = new JavaScriptEngine.JavaScriptEngine(hookBotApplication);
            runButtonEvent.AddClickEvent(async() =>
            {
                var tokenSource = new CancellationTokenSource();
                var token       = tokenSource.Token;
                var panel       =
                    processScrollViewPresenter.AddProcessPanel(
                        () => { tokenSource.Cancel(); });
                var task = javaScriptEngine.ExecuteJS(scriptText.GetScriptText(), token, panel.ProcessId);
                await task;
                panel.Dispose();
            });
        }
예제 #16
0
        public CpuBotController(BotEntity botEntityPrefab, TileMapInfo tileMapInfo, BulletEntity bulletPrefab,
                                SoundManager soundManager, MeleeAttackEntity meleeAttackEntity, EventSystemWatcher eventSystemWatcher)
        {
            var botEntity = Object.Instantiate(botEntityPrefab);

            tileMapInfo.EnemyTankTransform = botEntity.transform;
            botEntity.gameObject.layer     = LayerMask.NameToLayer("EnemyBot");
            botEntity.transform.position   = tileMapInfo.GetPlayer2StartPosition();
            var botEntityAnimation = botEntity.GetComponent <BotEntityAnimation>();
            MeleeAttackApplication meleeAttackApplication = new MeleeAttackApplication(meleeAttackEntity, soundManager);
            var gun = new Gun(
                soundManager,
                new BulletEntityCreator(bulletPrefab, LayerMask.NameToLayer("EnemyBullet")),
                true
                );

            botApplication = new BotApplication.BotApplication(
                botEntity, botEntityAnimation, tileMapInfo, eventSystemWatcher, gun, meleeAttackApplication
                );
            cpuAi.Start(botApplication);
        }
예제 #17
0
    private void createBullet()
    {
        object[] bullets = (object[])this._step["bullets"];
        //return;
        Dictionary <string, object> global = this._step.ContainsKey("global") ? (Dictionary <string, object>) this._step["global"] : null;

        MediatorSystem.timeStart("skillCreateBullet");
        BulletShallow shallow = null;

        if (this._step.ContainsKey("shallow"))
        {
            shallow         = new BulletShallow(this._map).init();
            shallow.shallow = Convert.ToDouble(this._step["shallow"]);
        }


        for (int i = 0, len = bullets.Length; i < len; i++)
        {
            //MediatorSystem.timeStart("clone");
            Dictionary <string, object> bulletData = (Dictionary <string, object>)bullets[i];
            //当前的字典 合并到子弹里。
            if (null != global)
            {
                Dictionary <string, object> temp = (Dictionary <string, object>)Utils.clone(global);
                Utils.union1(temp, bulletData);
                bulletData = temp;
            }
            //MediatorSystem.getRunTime("clone");

            BulletEntity bullet = this._player.map.createFightEntity(ConfigConstant.ENTITY_BULLET) as BulletEntity;
            bullet.lockTarget = this._lockTarget;
            bullet.owner      = this._player;
            bullet.shallow    = shallow;
            bullet.initConfig(bulletData);
        }

        MediatorSystem.getRunTime("skillCreateBullet", bullets.Length);
    }
예제 #18
0
        public static void CollectBulletInfoC(BulletEntity entity, INetworkChannel networkChannel)
        {
            if (networkChannel == null)
            {
                return;
            }
            var cmd     = entity.bulletData.CmdSeq;
            var start   = entity.bulletData.StartPoint;
            var emit    = entity.bulletData.EmitPoint;
            var dir     = entity.bulletData.StartDir;
            var hit     = entity.bulletData.HitPoint;
            var hitType = entity.bulletData.HitType;
            var msg     = FireInfoMessage.Allocate();

            msg.Seq        = cmd;
            msg.StartPoint = Vector3Converter.UnityToProtobufVector3(start);
            msg.EmitPoint  = Vector3Converter.UnityToProtobufVector3(emit);
            msg.StartDir   = Vector3Converter.UnityToProtobufVector3(dir);
            msg.HitPoint   = Vector3Converter.UnityToProtobufVector3(hit);
            msg.HitType    = (int)hitType;
            networkChannel.SendReliable((int)EClient2ServerMessage.FireInfo, msg);
            msg.ReleaseReference();
        }
예제 #19
0
    public virtual void beHit(BulletEntity bullet, double damageRate = 1)
    {
        /***********************击退**********************************/
        Vector2D backV2d;

        if (bullet.velocity.length < 2) //子弹速度很低时,按相对位置击退
        {
            backV2d = Collision.realPosition(bullet.position, this._position, this._map.mapData).deltaPos;
        }
        else
        {
            backV2d = bullet.velocity.clone();
        }
        backV2d.length = bullet.backForce;
        this.addForce(backV2d);
        /**************************增加buff********************************/

        if (bullet.data.ContainsKey("buff"))
        {
            Dictionary <string, object> buffs = (Dictionary <string, object>)bullet.data["buff"];
            string id = buffs["id"].ToString();
            foreach (string key in buffs.Keys)
            {
                if (key == "id")
                {
                    continue;
                }
                Buff buff = new Buff(this.map).initBuff(id, key, this, bullet.owner, (Dictionary <string, object>)buffs[key]);
                if (key == ConfigConstant.BUFF_STUN)
                {
                    buff.totalTime += bullet.stun;
                }
            }
        }

        this.hurt(bullet, damageRate);
    }
예제 #20
0
    public override FightEntity createFightEntity(int type, int netId = -1)
    {
        FightEntity entity = null;

        switch (type)
        {
        case ConfigConstant.ENTITY_LOOP_BEAN:        //
            entity = new LoopBeanEntity(this);
            break;

        case ConfigConstant.ENTITY_PLAYER:
            entity = new PlayerEntity(this);
            break;

        case ConfigConstant.ENTITY_BULLET:
            entity = new BulletEntity(this);
            break;

        case ConfigConstant.ENTITY_PRICE_BEAN:
            entity = new PriceBeanEntity(this);
            break;

        case ConfigConstant.ENTITY_CALL:
            entity = new CallEntity(this);
            break;

        case ConfigConstant.ENTITY_BARRIER:
            entity = new BarrierEntity(this);
            break;

        case ConfigConstant.ENTITY_RADISH:
            entity = new RadishEntity(this);
            break;
        }
        return(entity);
    }
예제 #21
0
    private void checkPlayerHit2(PersonEntity person1, PersonEntity person2)
    {
        if (person1.type == ConfigConstant.ENTITY_CALL && person1.ownerPlayer.teamIndex == person2.ownerPlayer.teamIndex)
        {
            return;
        }
        if (person2.type == ConfigConstant.ENTITY_CALL && person1.ownerPlayer.teamIndex == person2.ownerPlayer.teamIndex)
        {
            return;
        }

        CollisionInfo info = Collision.checkCollision(person1.collisionShape, person2.collisionShape, this.mapData);

        if (info.isHit)
        {
            //相对速度冲量(投影到斥力方向的分力)
            Vector2D velocityDeltaV2d = person1.velocity.clone().subtract(person2.velocity);
            Vector2D positionDeltaV2d = info.deltaPos.clone();
            double   len = velocityDeltaV2d.projectionOn(positionDeltaV2d);
            if (len > 0)
            {
                Vector2D pushForceV2d  = positionDeltaV2d.clone();
                bool     isPlayer      = person1.type == ConfigConstant.ENTITY_PLAYER && person2.type == ConfigConstant.ENTITY_PLAYER;
                bool     hurtCollision = isPlayer && person1.ownerPlayer.teamIndex != person2.ownerPlayer.teamIndex;
                double   forcePush     = hurtCollision ? ConfigConstant.PLAYER_FORCE_PUSH2 : ConfigConstant.PLAYER_FORCE_PUSH;
                forcePush *= len;
                int pushBack = isPlayer ? ConfigConstant.PUSH_FORCE_BACK : 0;
                pushForceV2d.length = forcePush * person1.scale / person2.scale + pushBack;
                person2.addForce(pushForceV2d);
                pushForceV2d.length = forcePush * person2.scale / person1.scale + pushBack;
                pushForceV2d.multiply(-1);
                person1.addForce(pushForceV2d);

                pushForceV2d.clear();
                //都是人  并且队伍不同。 碰撞伤害!
                if (hurtCollision)
                {
                    //子弹的配置。也确实 写死就好了。
                    Dictionary <string, object> bulletData = new Dictionary <string, object> {
                        { "resId", "bulletNull" },
                        { "speed", 1 },
                        { "lifeTime", 30 },
                        { "atk", (int)(forcePush * ConfigConstant.PUSH_DAMAGE_RATE) + ConfigConstant.PUSH_DAMAGE },
                        { "range", new object[] { ConfigConstant.SHIP_RADIUS } },
                        { "posTarget", 1 },
                        { "bangRes", "hitCollide" },
                        { "bangScale", Math.Sqrt(forcePush * 0.02) },
                        { "buff", new Dictionary <string, object>()
                          {
                              { "spRate", new Dictionary <string, object>()
                                {
                                    //'joystickMin': { 'value':60, 'operation':1, 'effect':'buff002' },   #遥感最小值
                                    { "value", 0.4f },
                                    { "operation", 2 },
                                    { "time", 500 },
                                } },
                              { "id", "spRate" }
                          } }
                    };
                    Vector2D     pos    = positionDeltaV2d.clone().multiply(0.5);
                    BulletEntity bullet = this.createFightEntity(ConfigConstant.ENTITY_BULLET) as BulletEntity;
                    bullet.lockTarget = person1;
                    bullet.owner      = person2;
                    bullet.position.copy(pos);
                    bullet.initConfig(bulletData);

                    bullet            = this.createFightEntity(ConfigConstant.ENTITY_BULLET) as BulletEntity;
                    bullet.lockTarget = person2;
                    bullet.owner      = person1;
                    bullet.position.copy(pos.reverse());
                    bullet.initConfig(bulletData);
                }
            }
            //近距离排斥力,越近越大
            double dist = (person1.collisionShape.radius + person2.collisionShape.radius) - positionDeltaV2d.length;
            positionDeltaV2d.length = dist * ConfigConstant.PLAYER_FORCE_REPULSIVE;
            person2.addForce(positionDeltaV2d);
            positionDeltaV2d.multiply(-1);
            person1.addForce(positionDeltaV2d);
            velocityDeltaV2d.clear();
        }
    }
예제 #22
0
        /// <summary>
        /// Fires a bullet for the entity if based on the behavior.
        /// </summary>
        /// <param name="entity">The source entity shooting.</param>
        /// <param name="gameTime">The elapsed game time.</param>
        /// <param name="bulletManager">A bullet manager to shoot bullets with.</param>
        public void FireWhenReady(IShootingEntity entity, GameTime gameTime)
        {
            if (gameTime.TotalGameTime > this.LastShot + this.FireRate)
            {
                this.LastShot = gameTime.TotalGameTime;

                var lBullet = new BulletEntity
                {
                    Damage = this.BulletDamage,
                    Renderer = new BasicRenderer(this.BulletTexture),
                    MovementBehavior = new GravityMovementBehavior
                    {
                        Acceleration = Vector2.UnitX * this.TargetAtraction,
                        Velocity = Vector2.Normalize(this.BulletDirection) * this.BulletSpeed,
                        Position = entity.Position + (entity.Size / 2f),
                        TargetEntity = this.TargetEntity,
                    },
                    IsFriendly = entity.IsFriendly,
                };

                this.FireBullet(lBullet);
            }
        }
예제 #23
0
        /// <summary>
        /// Fires a bullet for the entity if based on the behavior.
        /// </summary>
        /// <param name="entity">The source entity shooting.</param>
        /// <param name="gameTime">The elapsed game time.</param>
        /// <param name="bulletManager">A bullet manager to shoot bullets with.</param>
        public void FireWhenReady(IShootingEntity entity, GameTime gameTime)
        {
            if (gameTime.TotalGameTime > this.LastShot + this.FireRate)
            {
                this.LastShot = gameTime.TotalGameTime;

                var lDirectionOffset = MathHelper.ToRadians(this.Spread);
                var lDirection = Math.Atan2(this.BulletDirection.Y, this.BulletDirection.X);
                var lTopDirection = lDirection - lDirectionOffset;
                var lBottomDirection = lDirection + lDirectionOffset;

                var lTopVector = this.BulletSpeed * new Vector2(
                    (float)Math.Cos(lTopDirection),
                    (float)Math.Sin(lTopDirection));

                var lBottomVector = this.BulletSpeed * new Vector2(
                    (float)Math.Cos(lBottomDirection),
                    (float)Math.Sin(lBottomDirection));

                var lBulletTop = new BulletEntity
                {
                    Damage = this.BulletDamage,
                    MovementBehavior = new StraightMovementBehavior
                    {
                        Acceleration = Vector2.Zero,
                        Velocity = lTopVector,
                        Position = entity.Position + (entity.Size / 2f),
                    },
                    Renderer = new BasicRenderer(this.BulletTexture),
                    IsFriendly = entity.IsFriendly,
                };

                var lBulletBottom = new BulletEntity
                {
                    Damage = this.BulletDamage,
                    Renderer = new BasicRenderer(this.BulletTexture),
                    MovementBehavior = new StraightMovementBehavior
                    {
                        Acceleration = Vector2.Zero,
                        Velocity = lBottomVector,
                        Position = entity.Position + (entity.Size / 2f),
                    },
                    IsFriendly = entity.IsFriendly,
                };

                this.FireBullet(lBulletTop);
                this.FireBullet(lBulletBottom);
            }
        }
예제 #24
0
 public BulletEntityTag(BulletEntity ent)
 {
     Internal = ent;
 }
        public RemoteHostBotController(BotEntity botEntityPrefab, TileMapInfo tileMapInfo, BulletEntity bulletPrefab,
                                       SoundManager soundManager, GameSignalingClient gameSignalingClient,
                                       MeleeAttackEntity meleeAttackEntity, EventSystemWatcher eventSystemWatcher)
        {
            var botEntity = Object.Instantiate(botEntityPrefab);

            tileMapInfo.EnemyTankTransform = botEntity.transform;
            botEntity.gameObject.layer     = LayerMask.NameToLayer("EnemyBot");
            botEntity.transform.position   = tileMapInfo.GetPlayer1StartPosition();
            var botEntityAnimation = botEntity.GetComponent <BotEntityAnimation>();
            MeleeAttackApplication meleeAttackApplication = new MeleeAttackApplication(meleeAttackEntity, soundManager);
            var gun = new Gun(
                soundManager,
                new BulletEntityCreator(bulletPrefab, LayerMask.NameToLayer("EnemyBullet")),
                true
                );

            botApplication = new BotApplication.BotApplication(
                botEntity, botEntityAnimation, tileMapInfo, eventSystemWatcher, gun,
                meleeAttackApplication, true
                );

            gameSignalingClient.ReceivedClientReceiveSignalData += data =>
            {
                if (data.commandApplyTarget == MatchType.Host)
                {
                    new BotCommandsTransformerService().FromCommandData(data.commandData, botApplication);
                }
            };
        }
예제 #26
0
 public void Shoot(Vector3[] pos, Vector3[] vel, float lifetime = 10.0f, int owner_id = 0)
 {
     for (int i = 0; i < pos.Length; ++i )
     {
         var e = new BulletEntity
         {
             position = pos[i],
             velosity = vel[i],
             rotation = Quaternion.LookRotation(vel[i]),
             lifetime = lifetime,
         };
         m_entities_to_add[m_add_index++] = e;
         m_add_index %= m_entities_to_add.Length;
     }
 }
예제 #27
0
 public override void beHit(BulletEntity bullet, double damageRate = 1)
 {
     base.beHit(bullet, damageRate);
     bullet.dispatchEventWith(EventConstant.HIT, this);
 }
예제 #28
0
    //创建新单位
    public void CreateBulletEntity(GameScene gs, Protomsg.BulletDatas data)
    {
        BulletEntity hero = new BulletEntity(data, gs);

        m_BulletEntitys[data.ID] = hero;
    }
예제 #29
0
    //承受伤害,各个部件分摊伤害
    public override void hurt(BulletEntity bullet, double damageRate = 1)
    {
        //如果穿着了装备,先判定命中位置
        int damage = (int)(bullet.getDamage(this) * damageRate);
        //伤害加深。
        List <Buff> buffs = this.getBuffs(ConfigConstant.BUFF_HURT_SHALLOW);

        //TODO:如果都是乘以我就不用排序了!
        for (int i = 0, len = buffs.Count; i < len; i++)
        {
            damage = Mathf.CeilToInt(Convert.ToSingle(LogicOperation.operation(Convert.ToSingle(damage), buffs[i].value, buffs[i].operation)));
        }

        //对玩家造成了伤害,子弹的主人奖励积分
        bullet.ownerPlayer.changeScore(Mathf.CeilToInt(Convert.ToSingle(ConfigConstant.SCORE_DAMAGE * damage)));
        //护盾
        damage = this.hurtShield(damage);
        //忽略体积
        if (Utils.equal(bullet.data, "ignoreBear", 1))
        {
            damage = Mathf.CeilToInt(Convert.ToSingle(damage * (1 - this.getProperty(ConfigConstant.PROPERTY_DEF_RATE))));
        }
        else
        {
            damage = Mathf.CeilToInt(Convert.ToSingle(damage * (1 - this.getProperty(ConfigConstant.PROPERTY_DEF_RATE)) * this.getProperty(ConfigConstant.PROPERTY_BEAR_RATE)));
            //如果穿着了装备,先判定命中位置
            if (this.partGroup.hasPart)
            {
                Vector2D deltaP = bullet.getHitPos(this);
                //转化相对角度
                deltaP.angle -= this.angle;
                //依次判定相对命中点 距离4个装备参考点是否算命中
                //			double distance;
                int        bangRadius = (int)(bullet.radiusMax + ConfigConstant.SHIP_RADIUS * 0.5f);
                List <int> hitParts   = new List <int>();
                if (deltaP.dist(partHeadOffset) <= bangRadius)
                {
                    //前部件被命中
                    hitParts.Add(0);
                }
                if (deltaP.dist(partWingOffsetL) <= bangRadius || deltaP.dist(partWingOffsetR) <= bangRadius)
                {
                    //中部件被命中
                    hitParts.Add(1);
                }
                if (deltaP.dist(partTailOffset) <= bangRadius)
                {
                    //后部件被命中
                    hitParts.Add(2);
                }
                //根据被命中的部件个数,每个部件分摊伤害
                int hitCount = hitParts.Count;
                if (hitCount > 0)
                {
                    int tempDamage;
                    int damagePerPart = damage / hitCount;
                    int i;
                    for (i = 0; i < hitCount; i++)
                    {
                        PartAction part = this.partGroup.getPart(hitParts[i], true);
                        if (part != null)
                        {
                            //装备部件分担伤害
                            tempDamage = Mathf.CeilToInt(Convert.ToSingle(damagePerPart * part.hpRate));
                            part.beHit(tempDamage);
                            damage -= tempDamage;
                        }
                    }
                }
            }
        }

        this.changeHp(-damage);
    }
예제 #30
0
        public PlayerBotController(BotEntity botEntityPrefab, TileMapInfo tileMapInfo, BulletEntity bulletPrefab,
                                   CameraFollower cameraFollower, PlayerHpPresenter playerHpPresenter, RunButtonEvent runButtonEvent,
                                   ScriptText scriptText, ErrorMsg errorMsg, SoundManager soundManager, MeleeAttackEntity meleeAttackEntity,
                                   ProcessScrollViewPresenter processScrollViewPresenter, EventSystemWatcher eventSystemWatcher)
        {
            this.errorMsg          = errorMsg;
            this.playerHpPresenter = playerHpPresenter;
            var botEntity = Object.Instantiate(botEntityPrefab);

            tileMapInfo.PlayerTankTransform = botEntity.transform;
            botEntity.gameObject.layer      = LayerMask.NameToLayer("PlayerBot");
            cameraFollower.SetPlayerPosition(botEntity.transform);
            var botEntityAnimation = botEntity.GetComponent <BotEntityAnimation>();

            botEntity.transform.position = tileMapInfo.GetPlayer1StartPosition();
            MeleeAttackApplication meleeAttackApplication = new MeleeAttackApplication(meleeAttackEntity, soundManager);
            var gun = new Gun(
                soundManager,
                new BulletEntityCreator(bulletPrefab, LayerMask.NameToLayer("PlayerBullet")),
                false
                );

            botApplication = new BotApplication.BotApplication(
                botEntity, botEntityAnimation, tileMapInfo, eventSystemWatcher, gun, meleeAttackApplication
                );

            javaScriptEngine = new JavaScriptEngine.JavaScriptEngine(botApplication);
            runButtonEvent.AddClickEvent(() => OnRunButtonClick(processScrollViewPresenter, scriptText));
        }
예제 #31
0
 public BulletEntityAgent(BulletEntity bulletEntity)
 {
     this.bulletEntity = bulletEntity;
 }
예제 #32
0
    void Update()
    {
        if (!this.isPlay)
        {
            return;
        }
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            this.isPlay = false;
            this.cc     = 4;
        }
        else if (Input.GetKeyUp(KeyCode.F1))
        {
            this.isPlay = true;
            this.cc     = 5;
        }
        else if (Input.GetKeyUp(KeyCode.A))
        {
            isTest = !isTest;
        }
        else if (Input.GetKeyUp(KeyCode.S))
        {
            //NetSocket.test = true;
            NetAdapter.delayCount = Convert.ToInt32(TestValue.value) / ConfigConstant.MAP_ACT_TIME_S;
        }
        else if (Input.GetKeyUp(KeyCode.W))
        {
            FightMain.instance.selection.localPlayer.changeScore(-100000);
        }
        else if (Input.GetKeyUp(KeyCode.D))
        {
            FightMain.instance.selection.localPlayer.changeScore(100000);
        }
        else if (Input.GetKeyUp(KeyCode.C))
        {
            this.testUseCard();
        }
        else if (Input.GetKeyUp(KeyCode.Z))
        {
            this._selection.refereeController.radishController.addTeamPoint(0, 1);
        }
        else if (Input.GetKeyUp(KeyCode.X))
        {
            this._selection.refereeController.radishController.addTeamPoint(1, 1);
        }
        else if (Input.GetKeyUp(KeyCode.B))
        {
            Dictionary <string, object> bulletData = new Dictionary <string, object> {
                { "resId", "bulletNull" },
                { "speed", 1 },
                { "lifeTime", 30 },
                { "atk", 100000 },
                { "range", new object[] { ConfigConstant.SHIP_RADIUS } },
                { "posTarget", 1 },
                { "bangRes", "hitCollide" },
            };
            BulletEntity bullet = this._selection.createFightEntity(ConfigConstant.ENTITY_BULLET) as BulletEntity;
            bullet.lockTarget = this._selection.localPlayer;
            bullet.owner      = this._selection.localPlayer;
            bullet.initConfig(bulletData);
        }
        else if (Input.GetKeyUp(KeyCode.P))
        {
            this._selection.startTime += 33f / 1000;
        }


        MediatorSystem.timeStart("FightMain");
        //try {
        if (FightMain.isLocal && null != this.server)
        {
            this.server.update();
        }

        if (null != this._selection)
        {
            this._selection.update();
        }
        //} catch(Exception e) {
        //    LogMessage.instance.text.text += e.Message + "\n" + e.StackTrace;
        //    NetAdapter.sendQuitFight();
        //}


        //if(Input.GetKeyUp(KeyCode.Keypad1)) {
        //    this.selection = this.clients[0];
        //}else if(Input.GetKeyUp(KeyCode.Keypad2)) {
        //    this.selection = this.clients[1];
        //}else if(Input.GetKeyUp(KeyCode.Keypad3)) {
        //    this.selection = this.clients[2];
        //}
        MediatorSystem.getRunTime("FightMain");
    }
예제 #33
0
 public BulletApplication(BulletEntity bulletEntity, Vector3 addPos)
 {
     this.bulletEntity = bulletEntity;
     this.addPos       = addPos;
     this.bulletEntity.RockHitedEvent += (sender, args) => { DeleteFlag = true; };
 }
예제 #34
0
 public static void CollectBulletInfoS(BulletEntity entity, INetworkChannel networkChannel)
 {
 }