Ejemplo n.º 1
0
        private void GenerateActorsAndItemsOutside()
        {
            var bound = new BoundsInt(new Vector3Int(-2, -53, 0), new Vector3Int(19, 18, 1));

            for (int i = 0; i < 10; i++)
            {
                Vector2Int randomPosition = _rng.NextPosition(bound);
                if (_gridInfoProvider.IsWalkable(randomPosition))
                {
                    var actor = _rng.Choice(new[]
                    {
                        ActorType.Rogue,
                        ActorType.BruisedRat,
                        ActorType.BruisedRat,
                        ActorType.Rat,
                        ActorType.Rat,
                        ActorType.RatChiefBetter,
                        ActorType.RatChief,
                        ActorType.Dog,
                        ActorType.RatVeteran,
                    });
                    _entitySpawner.SpawnActor(actor, randomPosition);
                }
            }
            ItemDefinition recoverTailDefinition = Resources.Load <ItemDefinition>("PotionOfRecoverTail");

            _entitySpawner.SpawnItem(recoverTailDefinition, new Vector2Int(-3, -83));
            _entitySpawner.SpawnActor(ActorType.LastMonster, new Vector2Int(-2, -83));
            _entitySpawner.SpawnActor(ActorType.Basher, new Vector2Int(11, -64));
            _entitySpawner.SpawnActor(ActorType.RatChief, new Vector2Int(3, -87));
        }
Ejemplo n.º 2
0
        public override IEnumerable <IActionEffect> Execute()
        {
            if (_fromInventory)
            {
                _uiConfig.ItemHolder.RemoveItem(_uiConfig.ItemHolder.SelectedItemIndex);
            }
            else
            {
                ItemData itemAtFeet = _entityDetector.DetectItems(ActorData.LogicalPosition).First(i => i.ItemType == _item.ItemType);
                _entityRemover.RemoveItem(itemAtFeet);
            }

            bool isAllowed = !
                             (_gameContext.BasherSteps == 1 &&
                              new[]
            {
                ItemType.PotionOfBuddy, ItemType.PotionOfFriend, ItemType.PotionOfHealing,
                ItemType.PotionOfLight, ItemType.Food
            }
                              .Contains(_item.ItemType)
                             );

            if (_item.ItemType == ItemType.PotionOfRecoverTail)
            {
                _textEffectPresenter.ShowTextEffect(ActorData.LogicalPosition, "Squeak! At last!", Color.yellow);
            }
            else
            {
                _textEffectPresenter.ShowTextEffect(ActorData.LogicalPosition, isAllowed ? "Ha!" : "Oh, it doesn't work!", Color.yellow);
            }

            if (_item.ItemType == ItemType.Weapon)
            {
                ItemDefinition previousWeapon = ActorData.WeaponWeld;
                if (_fromInventory)
                {
                    _uiConfig.ItemHolder.AddItem(previousWeapon);
                }
                else
                {
                    if (previousWeapon.Name == "Key")
                    {
                        _entitySpawner.SpawnItem(previousWeapon, ActorData.LogicalPosition);
                    }
                    else
                    {
                        _entitySpawner.SpawnWeapon(previousWeapon.WeaponDefinition, ActorData.LogicalPosition, previousWeapon);
                    }
                }
                Image currentWeaponSprite = _uiConfig.CurrentWeaponHolder.gameObject.transform.Find("Image")
                                            .gameObject.GetComponent <Image>();
                _uiConfig.TooltipCurrentWeaponPresenter.GetComponent <CurrentWeaponTooltip>().LabelWearingUpper.gameObject.SetActive(true);
                _uiConfig.TooltipCurrentWeaponPresenter.Present(_item, true);
                _uiConfig.TooltipPresenter.gameObject.SetActive(false);
                currentWeaponSprite.sprite = _item.Sprite;
                currentWeaponSprite.color  = Color.white;

                ActorData.WeaponWeld = _item;
                Action effectAction = () => ((ActorBehaviour)ActorData.Entity).WeaponAnimator.Awake();
                var    effect       = new LambdaEffect(effectAction);
                yield return(effect);
            }
            else if (_item.ItemType == ItemType.PotionOfRecoverTail)
            {
                Sprite withTailSprite = Resources.Load <Sprite>("Sprites/Characters/player_with_tail");
                ActorData.Entity.SpriteRenderer.sprite = withTailSprite;
                ActorData.HasTail = true;
            }
            else if (isAllowed)
            {
                if (_item.ItemType == ItemType.Food)
                {
                    ActorData.Health += (int)(ActorData.MaxHealth * 0.3f);
                    if (ActorData.Health > ActorData.MaxHealth)
                    {
                        ActorData.Health = ActorData.MaxHealth;
                    }
                }
                else if (_item.ItemType == ItemType.PotionOfHealing)
                {
                    ActorData.Health += (int)(ActorData.MaxHealth * 0.7f);
                    if (ActorData.Health > ActorData.MaxHealth)
                    {
                        ActorData.Health = ActorData.MaxHealth;
                    }
                }
                else if (_item.ItemType == ItemType.PotionOfBuddy)
                {
                    _entitySpawner.SpawnActor(ActorType.Buddy, ActorData.LogicalPosition);
                }
                else if (_item.ItemType == ItemType.PotionOfFriend)
                {
                    _entitySpawner.SpawnActor(ActorType.Friend, ActorData.LogicalPosition);
                }
                else if (_item.ItemType == ItemType.PotionOfLight)
                {
                    IEnumerable <ActorData> actorsAround = _entityDetector.DetectActors(ActorData.LogicalPosition, 4).Where(a => a != ActorData);
                    foreach (var actorData in actorsAround)
                    {
                        actorData.Energy -= (2 + _rng.NextFloat() * 2f);
                        actorData.Swords -= 1;
                        if (actorData.Swords < 0)
                        {
                            actorData.Swords = 0;
                        }
                        string text = "";
                        if (actorData.ActorType != ActorType.Dog)
                        {
                            text = _rng.Choice(new[] { "My eyes!", "I can't see!", "Oh!", "Squeak!" });
                        }
                        else
                        {
                            text = "Squeak!";
                        }
                        _textEffectPresenter.ShowTextEffect(actorData.LogicalPosition, text);
                    }
                }
            }
        }