public Entity CreateBulletEntity(int cmdSeq, EntityKey entityKey, int serverTime, Vector3 dir, int weaponId, EBulletCaliber caliber, BulletConfig bulletConfig, Vector3 viewPosition, Vector3 emitPosition) { int bulletEntityId = _entityIdGenerator.GetNextEntityId(); Vector3 velocity = dir * bulletConfig.EmitVelocity; var bulletEntity = _bulletContext.CreateEntity(); float maxDistance = bulletConfig.MaxDistance; bulletEntity.AddEntityKey(new EntityKey(bulletEntityId, (int)EEntityType.Bullet)); bulletEntity.AddBulletData(velocity, 0, bulletConfig.Gravity, 0, serverTime, maxDistance, bulletConfig.PenetrableLayerCount, bulletConfig.BaseDamage, bulletConfig.PenetrableThickness, bulletConfig, bulletConfig.VelocityDecay, caliber, weaponId, bulletConfig.DistanceDecayFactor); bulletEntity.AddPosition(); bulletEntity.position.Value = viewPosition; bulletEntity.AddOwnerId(entityKey); bulletEntity.bulletData.CmdSeq = cmdSeq; bulletEntity.bulletData.StartPoint = viewPosition; bulletEntity.bulletData.EmitPoint = emitPosition; bulletEntity.bulletData.StartDir = dir; bulletEntity.isNew = true; bulletEntity.AddEmitPosition(emitPosition); bulletEntity.isFlagSyncNonSelf = true; bulletEntity.AddLifeTime(DateTime.Now, SharedConfig.BulletLifeTime); // in case user logout return(bulletEntity); }
protected override void ExecuteUserCmd(PlayerEntity playerEntity, IUserCmd cmd) { var controller = playerEntity.WeaponController(); var dataList = controller.BulletList; if (dataList != null && dataList.Count > 0) { BulletConfig bulletConfig = controller.HeldWeaponAgent.BulletCfg; if (null == bulletConfig) { return; } int weaponConfigId = controller.HeldWeaponAgent.ConfigId; var caliber = (EBulletCaliber)UserWeaponConfigManagement.FindConfigById(weaponConfigId).NewWeaponCfg.Caliber; foreach (var bulletData in dataList) { int bulletEntityId = _entityIdGenerator.GetNextEntityId(); Vector3 velocity = bulletData.Dir * bulletConfig.EmitVelocity; var bulletEntity = _bulletContext.CreateEntity(); float maxDistance = bulletConfig.MaxDistance; bulletEntity.AddEntityKey(new EntityKey(bulletEntityId, (int)EEntityType.Bullet)); bulletEntity.AddBulletData( velocity, 0, bulletConfig.Gravity, 0, cmd.RenderTime, maxDistance, bulletConfig.PenetrableLayerCount, bulletConfig.BaseDamage, bulletConfig.PenetrableThickness, bulletConfig, bulletConfig.VelocityDecay, caliber, weaponConfigId); bulletEntity.AddPosition(bulletData.ViewPosition); bulletEntity.AddOwnerId(playerEntity.entityKey.Value); bulletEntity.bulletData.CmdSeq = cmd.Seq; bulletEntity.bulletData.StartPoint = bulletData.ViewPosition; bulletEntity.bulletData.EmitPoint = bulletData.EmitPosition; bulletEntity.bulletData.StartDir = bulletData.Dir; bulletEntity.isNew = true; bulletEntity.AddEmitPosition(bulletData.EmitPosition); bulletEntity.isFlagSyncNonSelf = true; bulletEntity.AddLifeTime(DateTime.Now, SharedConfig.BulletLifeTime); // in case user logout bulletData.ReleaseReference(); } dataList.Clear(); } }
protected override void Execute(List <UnitEntity> entities) { foreach (var entity in entities) { entity.AddShootingCooldown(0.25f); // TODO - this is temporaty value var bullet = _bullets.CreateEntity(); bullet.AddPosition(entity.position.value); bullet.AddTarget(entity.target.value); bullet.AddDealDamage(0.3f); bullet.AddTimeToHit(0.3f); bullet.AddAsset("Dot"); } }