public void PickUp(IPickupAble pickupAble) { if (pickupAble.Weight + this.CurerentWeight <= this.ObjMaxCap) { Backpack.Add(pickupAble); } }
private void Detach_performed(InputAction.CallbackContext obj) { if (CurrentPickup != null) { var comp = (CurrentPickup as Component); if (comp == null) { CurrentPickup = null; return; } CurrentPickup.Drop(); } }
private void Activate_performed(InputAction.CallbackContext obj) { var objects = Physics.OverlapSphere(Hands.position, 0.3f); var collected = new List <IPickupAble>(); for (int i = 0; i < objects.Length; i++) { var isBasket = objects[i].GetComponentInParent <CartBasket>(); if (isBasket) { continue; } var cart = objects[i].GetComponentInParent <CartMovement>(); if (cart) { if (Vector3.Angle(transform.forward, cart.transform.forward) < 90) { if (CarriedItem == null) { _targetPickup = cart; } } } var jay = objects[i].GetComponentInParent <JayAI>(); if (jay && !(_targetPickup is CartMovement)) { _targetPickup = jay; } } if (_targetPickup != null) { var comp = (_targetPickup as Component); if (comp == null) { CurrentPickup = null; return; } var pickTransform = comp.transform; var dist = transform.position - pickTransform.position; if (dist.magnitude < MaxPickupDistance) { _targetPickup.Pickup(); } } }
private void WaitForCommand() { Console.WriteLine("Enter Command"); ConsoleKeyInfo keyInfo = Console.ReadKey(); int x = _player.X; int y = _player.Y; switch (keyInfo.Key) { case ConsoleKey.LeftArrow: x--; break; case ConsoleKey.RightArrow: x++; break; case ConsoleKey.DownArrow: y++; break; case ConsoleKey.UpArrow: y--; break; case ConsoleKey.I: case ConsoleKey.B: _player.BackPack.DisplayBackPack(); return; case ConsoleKey.L: GameEvents.DisplayEventLog(pauseAfterPrint: true); return; // default: return exits the function if input is not an arrow key default: return; } Room targetRoom = _rooms[x, y]; // exits function if the target room is a Wall (prevents movement etc.) if (targetRoom.IsWall) { return; } if (targetRoom.RoomMonster != null) { // Initialize Battle round _battle.Start(_player, targetRoom.RoomMonster); if (targetRoom.RoomMonster.Health <= 0) { // Checks if the monster implements the IPickupAble interface if (targetRoom.RoomMonster is IPickupAble) { IPickupAble monster = (IPickupAble)targetRoom.RoomMonster; // If the monster can be picked up, adds to backpack _player.BackPack.Add(monster); } // removes the monster targetRoom.RoomMonster = null; } } if (targetRoom.RoomItem != null) { _player.BackPack.Add(targetRoom.RoomItem); targetRoom.RoomItem = null; } // Moves the player _player.X = x; _player.Y = y; }
public void Add(IPickupAble item) { item.PickUp(Owner); Content.Add(item); Game.GameEvents.AddEvent("You picked up a " + item.Name); }
public void SetTrackedPickupable(IPickupAble pickupable) { _targetPickup = pickupable; }
public void SetCurrentPickup(IPickupAble pick) { CurrentPickup = pick; }