Exemple #1
0
        public void Apply(IActionEffect effect)
        {
            if (effect == null)
            {
                throw new ArgumentNullException();
            }

            _effects.Add(effect);
        }
Exemple #2
0
        public override IEnumerable <IActionEffect> Execute()
        {
            Vector2Int previousPosition = ActorData.LogicalPosition;
            Vector2Int newPosition      = previousPosition + Direction;

            if (_gridInfoProvider.IsWalkable(newPosition))
            {
                if (ActorData.ActorType == ActorType.Player && _gameContext.EnvironmentTilemap.HasTile(newPosition.ToVector3Int()))
                {
                    TileBase stairsDownTile = Resources.Load <TileBase>("Tiles/Environment/Stairs_down");
                    if (_gameContext.EnvironmentTilemap.GetTile(newPosition.ToVector3Int()) == stairsDownTile)
                    {
                        _textEffectPresenter.ShowTextEffect(ActorData.LogicalPosition, "Back down? Never!", Color.yellow);
                    }
                }
                if (_gameContext.BasherSteps == 0 && ActorData.ActorType == ActorType.Basher && Vector2IntUtilities.WalkDistance(ActorData.LogicalPosition,
                                                                                                                                 _gameContext.PlayerActor.ActorData.LogicalPosition) <= 5)
                {
                    _gameContext.BasherSteps = 1;
                    _uiConfig.BasherMessage.gameObject.SetActive(true);
                    _uiConfig.BasherMessage.SetMessage("Ha! So you didn't disappoint me! Finally I see you again, my rattish friend! As you might " +
                                                       "have guessed, that was me that sent you the key. I'll be happy to take you away from this scary place. But first " +
                                                       "we have to deal with one thing. You saved my life by attributing to yourself my deeds against the revolutionists. " +
                                                       "But this also made me feel like a lousy coward. My honour has been terribly undermined and I need to clean it. " +
                                                       "I challenge you to a duel! No magic, no eating, just me, you and steel. Prepare!");

                    IEnumerable <ActorData> friendsAndBuddies = _entityDetector.DetectActors(ActorData.LogicalPosition, 15)
                                                                .Where(a => a.ActorType == ActorType.Friend || a.ActorType == ActorType.Buddy);
                    foreach (var friendOrBuddy in friendsAndBuddies)
                    {
                        _deathHandler.HandleDeath(friendOrBuddy);
                    }
                }

                IActionEffect effect = ActionEffectFactory.CreateMoveEffect(ActorData, previousPosition);
                ActorData.LogicalPosition = newPosition;
                if (ActorData.CaughtActor != null)
                {
                    ActorData.CaughtActor.LogicalPosition = newPosition;
                }

                yield return(effect);
            }
            else
            {
                IActionEffect effect = ActionEffectFactory.CreateBumpEffect(ActorData, newPosition);
                yield return(effect);
            }
        }
Exemple #3
0
        public override IEnumerable <IActionEffect> Execute()
        {
            GameEntity entityToRelease = Contexts.sharedInstance.game.GetEntityWithId(Entity.entityHolder.EntityHeld);

            Position?newPosition = _firstPlaceInAreaFinder.FindForItem(Entity.position.Position);

            entityToRelease.ReplacePosition(newPosition.Value);
            entityToRelease.AddEnergy(1f, 0f);
            entityToRelease.isCarryable = true;

            Entity.ReplaceEntityHolder(Guid.Empty);
            IActionEffect effect = ActionEffectFactory
                                   .CreateLambdaEffect(viewController => viewController.DropHeldEntity(entityToRelease), Entity.view.Controller);

            yield return(effect);
        }
Exemple #4
0
        public override IEnumerable <IActionEffect> Execute()
        {
            Position previousPosition = Entity.position.Position;
            Position newPosition      = previousPosition + Direction;

            if (_grid.IsWalkable(newPosition))
            {
                IActionEffect effect = ActionEffectFactory.CreateMoveEffect(Entity, previousPosition);
                Entity.ReplacePosition(newPosition);
                yield return(effect);
            }
            else
            {
                IActionEffect effect = ActionEffectFactory.CreateBumpEffect(Entity, newPosition);
                yield return(effect);
            }
        }
Exemple #5
0
        public override IEnumerable <IActionEffect> Execute()
        {
            int maxDamage = 10;

            if (Entity.isPlayerControlled)
            {
                maxDamage = (int)(maxDamage);
            }
            int damage = _rng.Next(1, maxDamage + 1);

            AttackedEntity.ReplaceReceiveDamage(damage, Entity.id.Id);
            _reactiveFeature.Execute();

            IActionEffect bumpEffect = _actionEffectFactory.CreateBumpEffect(Entity, AttackedEntity.position.Position);

            yield return(bumpEffect);
        }
Exemple #6
0
        public override IEnumerable <IActionEffect> Execute()
        {
            if (Entity.entityHolder.EntityHeld != Guid.Empty || ItemToPickUp.hasHeld)
            {
                throw new InvalidOperationException(
                          "Actor should not try to pick up if he's holding an entity or someone else is holding an entity");
            }

            Entity.entityHolder.EntityHeld = ItemToPickUp.id.Id;
            ItemToPickUp.ReplaceHeld(Entity.id.Id);

            _uiFacade.AddLogEntry($"<color=#aaa>You pick up {ItemToPickUp.view.Controller.Name}.</color>");

            IActionEffect effect = ActionEffectFactory
                                   .CreateLambdaEffect(viewController => viewController.HoldOnFront(ItemToPickUp), Entity.view.Controller);

            yield return(effect);
        }
Exemple #7
0
        public override IEnumerable <IActionEffect> Execute()
        {
            int maxDamage = 10;
            int damage    = _rng.Next(1, maxDamage + 1);

            AttackedEntity.ReplaceReceiveDamage(damage, Entity.id.Id);
            if (!AttackedEntity.hasStimuli)
            {
                AttackedEntity.AddStimuli(new List <Stimulus>());
            }
            AttackedEntity.stimuli.Stimuli.Add(new Stimulus {
                Type = StimulusType.IAmAttacked, ObjectEntityId = Entity.id.Id
            });
            _reactiveFeature.Execute();

            IActionEffect bumpEffect = _actionEffectFactory.CreateBumpEffect(Entity, AttackedEntity.position.Position);

            yield return(bumpEffect);
        }
Exemple #8
0
        public override IEnumerable <IActionEffect> Execute()
        {
            Entity.ReplaceEntityHolder(EntityToKidnap.id.Id);
            EntityToKidnap.AddHeld(Entity.id.Id);
            EntityToKidnap.RemoveEnergy();
            EntityToKidnap.isEnergyReady = false;
            EntityToKidnap.isCarryable   = false;

            if (!Entity.hasEntityHolder || Entity.entityHolder.EntityHeld == Guid.Empty)
            {
                IActionEffect effect = ActionEffectFactory
                                       .CreateLambdaEffect(viewController => viewController.HoldOnBack(EntityToKidnap), Entity.view.Controller);
                yield return(effect);
            }
            else
            {
                throw new InvalidOperationException("Kidnap action shouldn't be executed if the active actor is holding something.");
            }
        }
        public override IEnumerable <IActionEffect> Execute()
        {
            yield return(new ControlStaysEffect());

            List <Guid> inventoryList = Entity.inventory.EntitiesInInventory;

            Guid       itemToTakeId = inventoryList[_indexInInventory];
            GameEntity itemToTake   = Contexts.sharedInstance.game.GetEntityWithId(itemToTakeId);

            inventoryList[_indexInInventory] = Guid.Empty;
            Entity.ReplaceInventory(inventoryList);
            Entity.ReplaceEntityHolder(itemToTakeId);
            itemToTake.ReplacePosition(Entity.position.Position);

            IActionEffect effect = ActionEffectFactory
                                   .CreateLambdaEffect(viewController => viewController.HoldOnFront(itemToTake), Entity.view.Controller);

            yield return(effect);
        }
Exemple #10
0
        public override IEnumerable <IActionEffect> Execute()
        {
            if (Entity.entityHolder.EntityHeld == _itemToDrop.id.Id)
            {
                IActionEffect dropEffect = ActionEffectFactory
                                           .CreateLambdaEffect(actorBehaviour => actorBehaviour.DropHeldEntity(_itemToDrop), Entity.view.Controller);

                Entity.ReplaceEntityHolder(Guid.Empty);

                string itemName = _itemToDrop.view.Controller.Name;

                Position?newPosition = _firstPlaceInAreaFinder.FindForItem(Entity.position.Position);
                _itemToDrop.RemoveHeld();
                _itemToDrop.ReplacePosition(newPosition ?? Entity.position.Position);
                _itemToDrop.view.Controller.RefreshWorldPosition();
                _uiFacade.AddLogEntry($"<color=#aaa>You drop {itemName} on the ground.</color>");

                yield return(dropEffect);
            }
        }
 protected TeamBase(IActionEffect effect)
 {
     Effect = effect;
 }
Exemple #12
0
 public void AddActionEffect(IActionEffect action)
 {
     actionEffects.Add(action);
 }
Exemple #13
0
        public override IEnumerable <IActionEffect> Execute()
        {
            float chanceToDealAccurateBlow = ActorData.Accuracy;
            bool  accurate = _rng.Check(chanceToDealAccurateBlow);

            if (_isDaringBlow)
            {
                ActorData.Swords -= 2;
            }

            bool hit = (_isDaringBlow || _attackedActor.Swords <= 0) && accurate;

            if (hit)
            {
                int damage = Math.Max(_rng.Next(ActorData.WeaponWeld.WeaponDefinition.MaxDamage + 1), _rng.Next(ActorData.WeaponWeld.WeaponDefinition.MaxDamage + 1));
                _attackedActor.Health -= damage;
                if (_attackedActor.Health <= 0)
                {
                    _deathHandler.HandleDeath(_attackedActor);
                    ActorData.Xp += _attackedActor.XpGiven;
                }

                if (_attackedActor.ActorType == ActorType.Basher && ActorData.ActorType == ActorType.Player && _attackedActor.HealthProgress < 0.5f)
                {
                    _uiConfig.BasherMessage.gameObject.SetActive(true);
                    _uiConfig.BasherMessage.GetComponent <RectTransform>().sizeDelta = new Vector3(560, 180);
                    _uiConfig.BasherMessage.SetMessage("Ouch! Enough for me! That was a satisfactory duel. My reputation is clean now. Thank you! Now, we have to go. To south, along the road!");
                    _gameContext.BasherSteps  = 2;
                    _attackedActor.Team       = Team.Beasts;
                    ActorData.HasFinishedDuel = true;
                    ActorData.HasWonDuel      = true;
                }
                if (_attackedActor.ActorType == ActorType.Player && ActorData.ActorType == ActorType.Basher && _attackedActor.HealthProgress < 0.5f)
                {
                    _uiConfig.BasherMessage.gameObject.SetActive(true);
                    _uiConfig.BasherMessage.GetComponent <RectTransform>().sizeDelta = new Vector3(560, 180);
                    _uiConfig.BasherMessage.SetMessage("Ha! I think you've had enough. That was a good duel! My reputation is clean now. Thank you! Now, we have to go. To south, along the road!");
                    _gameContext.BasherSteps       = 2;
                    ActorData.Team                 = Team.Beasts;
                    _attackedActor.HasFinishedDuel = true;
                    _attackedActor.HasWonDuel      = false;
                }

                yield return(new LambdaEffect(() =>
                {
                    Animator blood = Resources.Load <Animator>("Prefabs/Blood");
                    Animator bloodObject = GameObject.Instantiate(blood, AttackedActor.Entity.transform.position, Quaternion.identity);
                    bloodObject.Play("Blood");
                    GameObject.Destroy(bloodObject.gameObject, .4f);
                }));
            }

            if (_attackedActor.Swords > 0 && accurate)
            {
                --_attackedActor.Swords;
            }

            if (ActorData.WeaponWeld.WeaponDefinition.IsBodyPart)
            {
                IActionEffect bumpEffect = ActionEffectFactory.CreateBumpEffect(ActorData, AttackedActor.LogicalPosition);
                yield return(bumpEffect);
            }
            else
            {
                IActionEffect strikeEffect = ActionEffectFactory.CreateStrikeEffect(ActorData, AttackedActor, !hit, _isDaringBlow);
                yield return(strikeEffect);
            }


            AttackedActor.BlockedUntil = DateTime.UtcNow + TimeSpan.FromMilliseconds(300);
            ActorData.BlockedUntil     = DateTime.UtcNow + TimeSpan.FromMilliseconds(300);
        }