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; }
public void SetTargetFood(IWorldItem value) { _targetFood = value; _targetFood.OnDestroyed += (itemDestroyed) => { _targetFood = null; }; }
public override bool IsAvailable(IWorldItem active) { if (active is TActive obj) { return(IsAvailable(obj)); } return(false); }
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));; }
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); }
private void OnCollision(IWorldItem snakeItem, IWorldItem food) { if (food.WorldItemType != WorldItemType.Food) { return; } var snake = snakeItem as ISnake; snake.AddLength(); food.Destroy(); }
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); }
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); }
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); } }; }
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); } }
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); }
void ILinkState.PickUp(IWorldItem contentOfChest) { player.currentState = new LinkShowingItem(contentOfChest, player); }
public void PickupItem(IWorldItem contentOfChest) { currentState.PickUp(contentOfChest); }
void ILinkState.PickUp(IWorldItem contentOfChest) { }
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; } }
public sealed override bool IsAvailable(IWorldItem active) => false; // cant interact with yourself
public abstract bool IsAvailable(IWorldItem active, IWorldItem passive);
public LinkShowingItem(IWorldItem itemToShow, Player player) { this.player = player; content = itemToShow; this.my_texture_index = 0; }
public void putItemInChest(IWorldItem contentOfChest) { content = contentOfChest; }
public void PickUp(IWorldItem contentOfChest) { }
private void OnDestroyedItem(IWorldItem item) { _currentAmountFood--; }
public KeyDisappearCommand(Player player, IWorldItem item, Room room) { myPlayer = player; myItem = item; myRoom = room; }
public CollisionData(IWorldItem item, WorldItemType itemType) { Item = item; ItemType = itemType; }