public override IEnumerable <IActionEffect> Execute() { if (ActorData.WeaponWeld.Name == "DogBite" && ItemToPickUp.ItemDefinition.Name == "Key") // uuch... { ActorData.WeaponWeld = ItemToPickUp.ItemDefinition; Action effectAction = () => ((ActorBehaviour)ActorData.Entity).WeaponAnimator.Awake(); var effect = new LambdaEffect(effectAction); _entityRemover.RemoveItem(ItemToPickUp); var currentWeaponImage = _uiConfig.CurrentWeaponHolder.gameObject.transform.Find("Image").GetComponent <Image>(); currentWeaponImage.sprite = ItemToPickUp.ItemDefinition.Sprite; currentWeaponImage.color = Color.white; yield return(effect); yield break; } _uiConfig.ItemHolder.AddItem(ItemToPickUp.ItemDefinition); _entityRemover.RemoveItem(ItemToPickUp); yield break; }
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); } } } }