public WrappedInteraction(IInteraction interaction, IWorldItem active, IWorldItem passive)
 {
     Interaction = interaction;
     Active      = active;
     Passive     = passive;
     IsSync      = interaction is IInteractionSync;
 }
 public ChestOpenCommand(Player player, IWorldItem item, CollisionSides side)
 {
     myPlayer = player;
     //mySword = playerSword;
     myItem = item;
     mySide = side;
 }
Exemple #3
0
 public void SetTargetFood(IWorldItem value)
 {
     _targetFood              = value;
     _targetFood.OnDestroyed += (itemDestroyed) => {
         _targetFood = null;
     };
 }
Exemple #4
0
 public override bool IsAvailable(IWorldItem active)
 {
     if (active is TActive obj)
     {
         return(IsAvailable(obj));
     }
     return(false);
 }
Exemple #5
0
        public sealed override bool IsAvailable(IWorldItem active, IWorldItem passive)
        {
            if (TryCast(active, passive, out var activeObj, out var passiveObj))
            {
                return(IsAvailable(activeObj, passiveObj));
            }

            return(false);
        }
        public Task <IObjective> InteractAsync(IWorldItem active, IWorldItem passive)
        {
            if (TryCast(active, passive, out var activeObj, out var passiveObj))
            {
                return(InteractAsync(activeObj, passiveObj));
            }

            Debug.LogError($"Unable to cast {active} and {passive} to {typeof(TActive)} and {typeof(TPassive)}");
            return(Task.FromResult <IObjective>(null));;
        }
Exemple #7
0
        public IObjective Interact(IWorldItem active, IWorldItem passive)
        {
            if (TryCast(active, passive, out var activeObj, out var passiveObj))
            {
                return(Interact(activeObj, passiveObj));
            }

            Debug.LogError($"Unable to cast {active} and {passive} to {typeof(TActive)} and {typeof(TPassive)}");
            return(null);
        }
Exemple #8
0
        private void OnCollision(IWorldItem snakeItem, IWorldItem food)
        {
            if (food.WorldItemType != WorldItemType.Food)
            {
                return;
            }
            var snake = snakeItem as ISnake;

            snake.AddLength();
            food.Destroy();
        }
Exemple #9
0
        protected static bool TryCast(IWorldItem active, IWorldItem passive, out TActive activeObj, out TPassive passiveObj)
        {
            if (active is TActive activeObject && passive is TPassive passiveObject)
            {
                activeObj  = activeObject;
                passiveObj = passiveObject;
                return(true);
            }

            activeObj  = default;
            passiveObj = default;
            return(false);
        }
Exemple #10
0
        public WorldItem CreateWorldItem(IWorldItem worldItemToCreate)
        {
            var worldItem = (WorldItem)worldItemToCreate;

            worldItem.Id = GuidGenerator.GenerateTimeBasedGuid();

            using (var context = GetContext())
            {
                WithItemLock(worldItem.ItemId, () =>
                {
                    context.WorldItems.Add(worldItem);
                    context.SaveChanges();
                });
            }

            return(worldItem);
        }
        public IReadOnlyList <WrappedInteraction> GetInteractions(IWorldItem active, IReadOnlyList <IWorldItem> targets)
        {
            var result = new List <WrappedInteraction>();

            var filtered = FindPairs(active.GetType(), targets);

            foreach (var(interaction, passive) in filtered)
            {
                var isAvailable = interaction.IsAvailable(active, passive);
                if (isAvailable)
                {
                    result.Add(new WrappedInteraction(interaction, active, passive));
                }
            }

            return(result);
        }
Exemple #12
0
        public void AddItem(IWorldItem item, bool randomPosition = true)
        {
            _collisionHandler.AddItem(item);
            _items.Add(item);

            if (randomPosition)
            {
                item.SetPosition(GetRandomFreePosition());
            }

            item.SetParent(transform);
            item.OnDestroyed += (IWorldItem itemDestroyed) => {
                if (_items.Contains(itemDestroyed))
                {
                    _items.Remove(itemDestroyed);
                }
            };
        }
Exemple #13
0
        protected override void OnCollision(IWorldItem item1, IWorldItem item2)
        {
            var snake1 = (item1 as ISnake);
            var snake2 = (item2 as ISnake);

            if (snake2 == null)
            {
                return;
            }
            if (item1.Position.ConvertToInt() == item2.Position.ConvertToInt())
            {
                snake1?.Destroy();
                snake2?.Destroy();
            }
            else
            {
                snake2.DestroyTailFromPosition(item1.Position);
            }
        }
Exemple #14
0
        public override bool CanWalkOnBy(IWorldItem itemCollision, ISnake item, Vector3 position)
        {
            if (itemCollision == null)
            {
                return(true);
            }
            var res = true;

            switch (itemCollision.WorldItemType)
            {
            case WorldItemType.Barrier:
                res = false;
                break;

            case WorldItemType.Snake:
                if (itemCollision.transform.GetInstanceID() == item.transform.GetInstanceID())
                {
                    res = false;
                }
                break;
            }
            return(res);
        }
Exemple #15
0
 void ILinkState.PickUp(IWorldItem contentOfChest)
 {
     player.currentState = new LinkShowingItem(contentOfChest, player);
 }
Exemple #16
0
 public void PickupItem(IWorldItem contentOfChest)
 {
     currentState.PickUp(contentOfChest);
 }
 void ILinkState.PickUp(IWorldItem contentOfChest)
 {
 }
Exemple #18
0
 public void Touch(IWorldItem partner)
 {
     switch (partner.Type)
     {
         case WorldItemType.Player:
         case WorldItemType.PlayerBullet:
             if (!touchedThisFrame.Contains(partner))
             {
                 touchedThisFrame.Add(partner);
                 partner.TouchedThisFrame.Add(this);
                 partner.LivePoints -= this.touchDamage;
                 this.livePoints -= partner.TouchDamage;
             }
             break;
         default:
             break;
     }
 }
Exemple #19
0
 public sealed override bool IsAvailable(IWorldItem active) => false; // cant interact with yourself
Exemple #20
0
 public abstract bool IsAvailable(IWorldItem active, IWorldItem passive);
Exemple #21
0
 public LinkShowingItem(IWorldItem itemToShow, Player player)
 {
     this.player           = player;
     content               = itemToShow;
     this.my_texture_index = 0;
 }
Exemple #22
0
 public void putItemInChest(IWorldItem contentOfChest)
 {
     content = contentOfChest;
 }
Exemple #23
0
 public void PickUp(IWorldItem contentOfChest)
 {
 }
Exemple #24
0
 private void OnDestroyedItem(IWorldItem item)
 {
     _currentAmountFood--;
 }
Exemple #25
0
 public KeyDisappearCommand(Player player, IWorldItem item, Room room)
 {
     myPlayer = player;
     myItem   = item;
     myRoom   = room;
 }
Exemple #26
0
 public CollisionData(IWorldItem item, WorldItemType itemType)
 {
     Item     = item;
     ItemType = itemType;
 }