public BoxesGenerationService( IMechanicEngine mechanicEngine, IBodyBuilder bodyBuilder, int containersCount) : base(mechanicEngine, bodyBuilder) { _containersCount = containersCount; }
public BaseGenerationService( IMechanicEngine mechanicEngine, IBodyBuilder bodyBuilder) { _mechanicEngine = mechanicEngine; _bodyBuilder = bodyBuilder; }
public NPCGenerationService( IMechanicEngine mechanicEngine, IBodyBuilder bodyBuilder, int npcCount) : base(mechanicEngine, bodyBuilder) { _npcCount = npcCount; }
public PlayerBody LoadPlayerBody(Guid characterId, IMechanicEngine mechanicEngine) { //TODO: load config from DB, get some data from depended services and as a result - load player object var character = _characterRepository.Find(characterId).FirstOrDefault(); var player = _unityContainer.Resolve <PlayerBody>( new ParameterOverride("name", character.Name)); player.AddWeapon(_unityContainer.Resolve <WeaponSimpleBullet>("Revolver")); player.AddWeapon(_unityContainer.Resolve <WeaponSimpleBullet>("Gun")); player.AddWeapon(_unityContainer.Resolve <WeaponMultipleShotgunBullet>("Shotgun")); player.AddWeapon(_unityContainer.Resolve <WeaponDynamite>("Dynamite")); player.SocialGroups.Add("Bandit"); //Fill playerBody with character data player.Id = character.Id; //Create session var newSession = new GameSession(character.Id); _sessionRepository.AddSession(newSession); player.SessionId = newSession.Id; return(player); }
public BoxBody BuildBox(IMechanicEngine mechanicEngine, Point point) { var bodyType = _randomizer.Next(1000); Body bodyInsideBox = null; if (bodyType % 2 != 0) { bodyInsideBox = _unityContainer.Resolve <WeaponSimpleBullet>("Revolver"); } else { bodyInsideBox = BuildLifeContainer(mechanicEngine); } var box = new BoxBody(new ShapeRectangle(30, 30, point), new List <Body>() { bodyInsideBox }, mechanicEngine, 20, 20); return(box); }
public GameCommandMove(long id, Vector direction, IMechanicEngine mechanicEngine, ActiveBody activeBody, TimeSpan duration) : base(mechanicEngine, activeBody) { Direction = direction; Duration = duration; Id = id; }
public WeaponBase(int damage, int shootingDistance, IMechanicEngine mechanicEngine, string name, Shape shape) : base(Guid.NewGuid(), shape) { _damage = damage; _shootingDistance = shootingDistance; _mechanicEngine = mechanicEngine; Name = name; }
public ActiveBody BuildNPCAI(IMechanicEngine mechanicEngine) { var npcai = _unityContainer.Resolve <NPCAI>(); npcai.AddWeapon(_unityContainer.Resolve <WeaponSimpleBullet>("Revolver")); npcai.SocialGroups.Add("Police"); //TODO: load config from DB, get some data from depended services and as a result - build NPC return(npcai); }
public GameCommandMakeDamage(long id, IMechanicEngine mechanicEngine, ActiveBody activeBody, int damage) : base(mechanicEngine, activeBody) { Id = id; Damage = damage; }
public static void Run(ILogger logger) { _logger = logger; var meb = new UnityMechanicEngineBuilder(); SlowpokeHub.MechanicEngine = meb.Build(UpdatePlayerState, _engineConfiguration); SlowpokeHub.MechanicEngine.StartEngine(); }
public SlowpokeGame() { var meb = new MechanicEngineBuilder(); _mechanicEngine = meb.Build(); _mechanicEngine.AddNPCBody(); _mechanicEngine.StartEngine(); }
public BoxBody( Shape shape, IEnumerable <Body> childBodies, IMechanicEngine mechanicEngine, int life, int lifeMax) : base(shape, new Vector(1, 1), mechanicEngine, life, lifeMax, 0) { _childBodies = childBodies; }
public NPCAI(Shape shape, IMechanicEngine mechanicEngine, int life, int lifeMax, int viewZone, int speed) : base( shape, new Vector(1, 1), mechanicEngine, life, lifeMax, viewZone, speed) { }
public WeaponMultipleShotgunBullet( int damage, int bulletSize, int shootingDistance, int bulletSpeed, TimeSpan shootFrequency, IMechanicEngine mechanicEngine, string name, Shape shape ) : base(damage, bulletSize, shootingDistance, bulletSpeed, shootFrequency, mechanicEngine, name, shape) { }
public CharacterBody( Shape shape, Vector direction, IMechanicEngine mechanicEngine, int life, int lifeMax, int viewZone, int speed) : base(shape, direction, mechanicEngine, life, lifeMax, speed) { ViewZone = viewZone; _score = 0; _weapons = new List <WeaponBase>(); SocialGroups = new List <string>(); }
public PlayerBody( Shape shape, Vector direction, IMechanicEngine mechanicEngine, IGameSessionRepository sessionRepository, int life, int lifeMax, string name, int viewZone, int speed ) : base(shape, direction, mechanicEngine, life, lifeMax, viewZone, speed) { _sessionRepository = sessionRepository; Name = name; }
public WeaponSimpleBullet( int damage, int bulletSize, int shootingDistance, int bulletSpeed, TimeSpan shootFrequency, IMechanicEngine mechanicEngine, string name, Shape shape ) : base(damage, shootingDistance, mechanicEngine, name, shape) { _bulletSpeed = bulletSpeed; _bulletSize = bulletSize; _shootFrequency = shootFrequency; }
private void ApplyDamageToActiveBody(IMechanicEngine mechanicEngine, CharacterBody bulletOwnerBody, ActiveBody collidedActiveBody, int damage) { collidedActiveBody.Harm(damage); //Kill collided active body if needed if (collidedActiveBody.Life <= 0) { mechanicEngine.ReleaseBody(collidedActiveBody.Id); //Increase score of bullet owner if (bulletOwnerBody != null) { bulletOwnerBody.UpdateScore(collidedActiveBody.LifeMax); } } }
public ActiveBody( Shape shape, Vector direction, IMechanicEngine mechanicEngine, int life, int lifeMax, int speed) : base(Guid.NewGuid(), shape) { _mechanicEngine = mechanicEngine; Shape = shape; Direction = direction; Life = life; LifeMax = lifeMax; State = BodyState.Alive; Speed = speed; }
public DynamitBody( Shape shape, Vector direction, IMechanicEngine mechanicEngine, int damage, int speed, int dynamiteDetonationTime, int bangRadius, Guid ownerId ) : base(shape, direction, mechanicEngine, 0, 0, speed) { _damage = damage; _dynamiteDetonationTime = dynamiteDetonationTime; _bangRadius = bangRadius; OwnerId = ownerId; }
public WeaponDynamite( int dynamiteDetonationTime, int bangRadius, int damage, int bulletSize, int shootingDistance, int bulletSpeed, TimeSpan shootFrequency, IMechanicEngine mechanicEngine, string name, Shape shape ) : base(damage, bulletSize, shootingDistance, bulletSpeed, shootFrequency, mechanicEngine, name, shape) { _dynamiteDetonationTime = dynamiteDetonationTime; _bangRadius = bangRadius; }
public Bullet( int shootingDistance, int speed, int damage, Shape shape, Vector direction, Guid ownerId, IMechanicEngine mechanicEngine, long commandId, string bulletTypeName) : base(shape, direction, mechanicEngine, 1, 1, speed) { ShootingDistance = shootingDistance; Damage = damage; OwnerId = ownerId; CreatedByCommandId = commandId; BulletTypeName = bulletTypeName; //calculate position Shape.Position = Direction.MovePoint(Shape.Position, Shape.MaxDimension); StartPosition = Shape.Position; }
Action <GameCommand, PhysicsProcessingResult> > BuildBulletCollisionHandler(IMechanicEngine mechanicEngine) { return(new Tuple <Func <GameCommand, PhysicsProcessingResult, bool>, Action <GameCommand, PhysicsProcessingResult> >( (gameCommand, result) => { return result is PhysicsProcessingResultCollision && gameCommand.ActiveBody is Bullet //Execute only when collided with not IUsableBody && ((PhysicsProcessingResultCollision)result).Bodies.Where(v => !(v is IUsableBody)).Count() > 0; }, (gameCommand, result) => { var resultCollision = (PhysicsProcessingResultCollision)result; var bullet = (Bullet)gameCommand.ActiveBody; mechanicEngine.ReleaseBody(gameCommand.ActiveBody.Id); foreach (var body in resultCollision.Bodies) { var bulletOwnerBody = mechanicEngine.FindBody(bullet.OwnerId) as CharacterBody; if ( (body is CharacterBody && ((CharacterBody)body).SocialGroups.Intersect(bulletOwnerBody.SocialGroups).Count() > 0) || (body is BoxBody && !(bulletOwnerBody is PlayerBody))) { continue; } if (body is ActiveBody && bulletOwnerBody != null) { //Set damage to collided active body var collidedActiveBody = ((ActiveBody)body); ApplyDamageToActiveBody(mechanicEngine, bulletOwnerBody, collidedActiveBody, bullet.Damage); } } })); }
public GameCommandChangeDirection(long id, Vector direction, IMechanicEngine mechanicEngine, ActiveBody activeBody) : base(mechanicEngine, activeBody) { Id = id; Direction = direction; }
public LifeContainer BuildLifeContainer(IMechanicEngine mechanicEngine) { var lifeContainer = _unityContainer.Resolve <LifeContainer>(); return(lifeContainer); }
Action <GameCommand, PhysicsProcessingResult> > BuildUsableContainerCollisionHandler(IMechanicEngine mechanicEngine) { return(new Tuple <Func <GameCommand, PhysicsProcessingResult, bool>, Action <GameCommand, PhysicsProcessingResult> >( (gameCommand, result) => { return result is PhysicsProcessingResultCollision && gameCommand.ActiveBody is PlayerBody && ((PhysicsProcessingResultCollision)result).Bodies[0] is IUsableBody; }, (gameCommand, result) => { var resultCollision = (PhysicsProcessingResultCollision)result; var player = (PlayerBody)gameCommand.ActiveBody; //Set usable container player.UsableBodyInScope = (IUsableBody)resultCollision.Bodies[0]; })); }
public GameCommand(IMechanicEngine mechanicEngine, ActiveBody activeBody) { _mechanigEngine = mechanicEngine; ActiveBody = activeBody; }
Action <GameCommand, PhysicsProcessingResult> > BuildMakeDamageCollisionHandler(IMechanicEngine mechanicEngine) { return(new Tuple <Func <GameCommand, PhysicsProcessingResult, bool>, Action <GameCommand, PhysicsProcessingResult> >( (gameCommand, result) => { return result is PhysicsProcessingResultCollision && gameCommand is GameCommandMakeDamage; }, (gameCommand, result) => { var resultCollision = (PhysicsProcessingResultCollision)result; var command = (GameCommandMakeDamage)gameCommand; foreach (ActiveBody collidedActiveBody in resultCollision.Bodies.Where(v => v is ActiveBody)) { var bulletOwnerBody = mechanicEngine.FindBody(command.ActiveBody.OwnerId) as CharacterBody; ApplyDamageToActiveBody(mechanicEngine, bulletOwnerBody, collidedActiveBody, command.Damage); } if (command.ActiveBody is DynamitBody) { mechanicEngine.ReleaseBody(command.ActiveBody.Id); } })); }