public void Pickup(PickupInteraction item) { /* * if (item == in_hands || item == suitcase || item == on_back || item == active_item || HasI)*/ if (item == null) { return; } if (HasItem(item)) { return; } switch (item.GetItemSize()) { case ItemSize.Bulky: PickupCarryOnly(item); return; case ItemSize.Small: case ItemSize.Large: PickupHolsterable(item); return; default: Debug.Log("This should be impossible"); break; } }
public bool HasItem(PickupInteraction item) { if (item == null) { return(false); } return(items.Contains(item)); }
public void AddItem(PickupInteraction item) { if (item == null || items.Contains(item)) { return; } items.Add(item); }
public void ExecutePlace() { if (in_hands != null) { DropItem(in_hands, true); in_hands = null; return; } }
private void AttachToRightHand(PickupInteraction item) { HumanoidAttachment attach_manager = GetComponent <HumanoidAttachment>(); if (attach_manager != null && item != null) { item.AttachTo(attach_manager.attach_right_hand); } }
private void AttachToBack(PickupInteraction item) { HumanoidAttachment attach_manager = GetComponent <HumanoidAttachment>(); if (attach_manager != null && item != null) { item.AttachTo(attach_manager.attach_back); } }
private void DoThrowExecute(PickupInteraction item, HumanoidInventoryController inventory) { if (CanThrow(item)) { inventory.DropItem(item, true); // TODO: The item should know by itself whether it is attached or not // Rigidbody is ensured by CanThrow Rigidbody body = item.GetComponent <Rigidbody>(); body.AddForce(DoThrowGetAngle() * THROW_DISTRACTION_FORCE, ForceMode.Impulse); } }
private void PickupCarryOnly(PickupInteraction item) { if (in_hands == null) { // Pick it up AddToHand(item); } else { PickupSwap(item, in_hands); } }
public void DropItem(PickupInteraction item, bool is_attached) { if (item != null) { // Not in the inventory anymore RemoveItem(item); // Make the item visible item.SetHolstered(false); item.SetVisible(true); // Drop it! item.Detach(); } }
private HolsterResult DoHolsterMainHand() { if (in_hands == null || in_hands.IsHolstered()) { return(HolsterResult.Invalid); } switch (in_hands.GetItemSize()) { case ItemSize.Small: Debug.Log("Stash to inventory: " + in_hands.gameObject.name); // Item is holstered and hidden in_hands.SetHolstered(true); in_hands.SetVisible(false); // Item is selected active_item = in_hands; AttachToRightHand(in_hands); // Hand is empty now, but do not detach in_hands = null; return(HolsterResult.Success); case ItemSize.Large: if (on_back == null) { Debug.Log("Holster to back: " + in_hands.gameObject.name); // Item is holstered, but visible in_hands.SetHolstered(true); in_hands.SetVisible(true); // Item is on back on_back = in_hands; AttachToBack(in_hands); // Hand is empty now, but do not detach in_hands = null; return(HolsterResult.Success); } else { // Do not holster, but also do not do anything else return(HolsterResult.Blocked); } case ItemSize.Bulky: case ItemSize.Case: // Do not holster, but also do not do anything else return(HolsterResult.Blocked); default: Debug.Log("Unsupported"); break; } return(HolsterResult.Invalid); }
private bool CanThrow(PickupInteraction item) { // Cannot throw? if (item == null || item.IsHolstered() || !item.IsVisible() || item.GetComponent <Rigidbody>() == null) // Throwing makes sense for physical objects only { Debug.Log("Throw aiming not possible"); return(false); } // TODO: Make a throwable property and check that, too return(true); }
private void PutOnBack(PickupInteraction item) { // Save to inventory Debug.Log("Picked up to back:" + item.gameObject.name); // Item is neither selected nor in the hand, // but the attachment needs to be done anyway AttachToBack(item); on_back = item; if (item == in_hands) { in_hands = null; } // Make the item holstered, but visible item.SetHolstered(true); item.SetVisible(true); }
private void PutInHand(PickupInteraction item) { // Save to inventory Debug.Log("Picked up to hand:" + item.gameObject.name); // Item is selected and in the hand now in_hands = item; active_item = item; if (item == on_back) { on_back = null; } AttachToRightHand(item); // Make the item visible item.SetHolstered(false); item.SetVisible(true); }
private void PutInInventory(PickupInteraction item) { // Save to inventory Debug.Log("Picked up to inventory:" + item.gameObject.name); // Item is neither selected nor in the hand, // but the attachment needs to be done anyway AttachToRightHand(item); if (item == on_back) { on_back = null; } if (item == in_hands) { in_hands = null; } // Make the item invisible item.SetHolstered(true); item.SetVisible(false); }
private bool DoThrowAiming(PickupInteraction item) { if (CanThrow(item)) { // Rigidbody is ensured by CanThrow Rigidbody body = item.GetComponent <Rigidbody>(); float mass_item = Mathf.Max(THROW_REFERENCE_MASS, body.mass); Vector3 start = body.position; // Do the trajectory! float v0 = THROW_DISTRACTION_FORCE / mass_item; float time_step = 0.1f; // Simulate every 100ms of flight DrawAimingTrajectory(start, DoThrowGetAngle() * v0, time_step); return(true); } else { return(false); } }
private void AddToBack(PickupInteraction item) { AddItem(item); PutOnBack(item); }
private void AddToHand(PickupInteraction item) { AddItem(item); PutInHand(item); }
public void RemoveItem(PickupInteraction item) { items.Remove(item); }
private void PickupHolsterable(PickupInteraction item) { DoButtonCooldown(); // Picking up a large item, while carrying a suitcase? if (suitcase != null && item.GetItemSize() == ItemSize.Large) { // Store to back if the slot is free? if (on_back == null) { AddToBack(item); return; } // TODO: No idea whether suit and bulky item will be dropped... // Cancel for now return; } // Already holding something? if (in_hands != null) { if (in_hands.GetItemSize() == ItemSize.Large || in_hands.GetItemSize() == ItemSize.Bulky) { switch (item.GetItemSize()) { case ItemSize.Large: if (on_back == null) { AddToBack(item); } else { PickupSwap(item, on_back); } break; case ItemSize.Bulky: PickupSwap(item, in_hands); break; case ItemSize.Small: AddToInventory(item); break; default: Debug.Log("This code should not be reached"); break; } return; } else if (in_hands.GetItemSize() == ItemSize.Small) { DoHolsterMainHand(); } } // Hand is free, pick it up if (in_hands == null) { AddToHand(item); return; } }
private void PickupSwap(PickupInteraction item_new, PickupInteraction item_old) { Debug.Log("Swap not supported yet"); }
private void AddToInventory(PickupInteraction item) { AddItem(item); PutInInventory(item); }