public ConsumingEffect(IGameObjectVisualizationContentStorage visualizationContentStorage, Vector2 targetObjectPosition, ConsumeEffectType effectType) { _startEffectPosition = targetObjectPosition; _targetEffectPosition = targetObjectPosition - (Vector2.UnitY * EFFECT_FLIGHT_DISTANCE); var spriteSourceRect = GetSpriteSourceRect(effectType); _effectSprite = new Sprite(visualizationContentStorage.GetConsumingEffectTexture()) { Position = targetObjectPosition, SourceRectangle = spriteSourceRect }; _counter = EFFECT_DISPLAY_DURATION_SECONDS; }
public HitEffect( GameObjectBase attacker, GameObjectBase target, IGameObjectVisualizationContentStorage contentStorage, Vector2 effectPosition, Vector2 direction, ActDescription usedActDescription) { var hitType = GetHitType(usedActDescription); var hitDirection = GetHitDirection(direction); var hitTexture = contentStorage.GetHitEffectTexture(hitType, hitDirection); _hitSprite = new Sprite(hitTexture) { Position = effectPosition, Origin = new Vector2(0.5f, 0.5f), Color = new Color(255, 255, 255, 0.0f), SourceRectangle = new Rectangle(0, 0, FRAME_WIDTH, FRAME_HEIGHT) }; var hitBackingTexture = contentStorage.GetHitEffectTexture(hitType | HitEffectTypes.Backing, HitEffectDirections.Left); _hitBackingSprite = new Sprite(hitBackingTexture) { Position = effectPosition, Origin = new Vector2(0.5f, 0.5f), Color = new Color(255, 255, 255, 0.0f), SourceRectangle = new Rectangle(0, 0, FRAME_WIDTH, FRAME_HEIGHT) }; if (direction.X > 0) { _hitSprite.FlipX = true; _hitBackingSprite.FlipX = true; } _animationCounter = EFFECT_DISPLAY_DURATION_SECONDS; _postAnimationCounter = EFFECT_DELAY_DURATION_SECONDS; _boundGameObjects = new[] { attacker, target }; }
public ActorViewModel( IActor actor, GameObjectParams gameObjectParams) { Actor = actor; _game = gameObjectParams.Game ?? throw new ArgumentException($"{nameof(gameObjectParams.Game)} is not defined.", nameof(gameObjectParams)); _sectorViewModelContext = gameObjectParams.SectorViewModelContext ?? throw new ArgumentException( $"{nameof(gameObjectParams.SectorViewModelContext)} is not defined.", nameof(gameObjectParams)); _personSoundStorage = gameObjectParams.PersonSoundStorage ?? throw new ArgumentException( $"{nameof(gameObjectParams.PersonSoundStorage)} is not defined.", nameof(gameObjectParams)); _gameObjectVisualizationContentStorage = gameObjectParams.GameObjectVisualizationContentStorage ?? throw new ArgumentException( $"{nameof(gameObjectParams.GameObjectVisualizationContentStorage)} is not defined.", nameof(gameObjectParams)); _spriteBatch = gameObjectParams.SpriteBatch ?? throw new ArgumentException($"{nameof(gameObjectParams.SpriteBatch)} is not defined.", nameof(gameObjectParams)); if (gameObjectParams.PersonVisualizationContentStorage is null) { throw new ArgumentException( $"{nameof(gameObjectParams.PersonVisualizationContentStorage)} is not defined.", nameof(gameObjectParams)); } var equipmentModule = Actor.Person.GetModuleSafe <IEquipmentModule>(); var shadowTexture = _game.Content.Load <Texture2D>("Sprites/game-objects/simple-object-shadow"); _rootSprite = new SpriteContainer(); _shadowSprite = new Sprite(shadowTexture) { Position = new Vector2(0, 0), Origin = new Vector2(0.5f, 0.5f), Color = new Color(Color.White, 0.5f) }; _rootSprite.AddChild(_shadowSprite); var isHumanGraphics = Actor.Person is HumanPerson; if (isHumanGraphics) { if (equipmentModule is not null) { var graphicsRoot = new HumanoidGraphics(equipmentModule, gameObjectParams.PersonVisualizationContentStorage); _rootSprite.AddChild(graphicsRoot); _graphicsRoot = graphicsRoot; } else { // There is no cases when human person hasn't equipment module. // It can be empty module to show "naked" person in the future. throw new InvalidOperationException("Person has no IEquipmentModule."); } } else { var monsterPerson = Actor.Person as MonsterPerson; SpriteContainer?graphics = null; switch (monsterPerson.Scheme.Sid) { case "predator": graphics = new AnimalGraphics(gameObjectParams.PersonVisualizationContentStorage); break; case "warthog": graphics = new MonoGraphics("warthog", gameObjectParams.PersonVisualizationContentStorage); break; case "predator-meat": graphics = new AnimalGraphics(gameObjectParams.PersonVisualizationContentStorage); break; case "skeleton": graphics = new MonoGraphics("skeleton", gameObjectParams.PersonVisualizationContentStorage); break; case "skeleton-equipment": graphics = new MonoGraphics("skeleton-equipment", gameObjectParams.PersonVisualizationContentStorage); break; case "gallbladder": graphics = new MonoGraphics("gallbladder", gameObjectParams.PersonVisualizationContentStorage); break; } _rootSprite.AddChild(graphics); _graphicsRoot = (IActorGraphics)graphics; } var hexSize = MapMetrics.UnitSize / 2; var playerActorWorldCoords = HexHelper.ConvertToWorld(((HexNode)Actor.Node).OffsetCoords); var newPosition = new Vector2( (float)(playerActorWorldCoords[0] * hexSize * Math.Sqrt(3)), playerActorWorldCoords[1] * hexSize * 2 / 2 ); _rootSprite.Position = newPosition; Actor.Moved += Actor_Moved; Actor.UsedProp += Actor_UsedProp; Actor.PropTransferPerformed += Actor_PropTransferPerformed; Actor.BeginTransitionToOtherSector += Actor_BeginTransitionToOtherSector; if (Actor.Person.HasModule <IEquipmentModule>()) { Actor.Person.GetModule <IEquipmentModule>().EquipmentChanged += PersonEquipmentModule_EquipmentChanged; } if (Actor.Person.HasModule <ISurvivalModule>()) { Actor.Person.GetModule <ISurvivalModule>().Dead += PersonSurvivalModule_Dead; } _actorStateEngineList = new List <IActorStateEngine> { new ActorIdleEngine(_graphicsRoot.RootSprite) }; }