public void Drop(base_item item) { // ignore if (!item) return; // player, try remove if (gameObject.layer == game_variables.Instance.LayerPlayer && !menu_inventory.Instance.Modify(item, false)) // fail - ignore return; // drop item.SetParent(null); // clear reference if (item == _equipped) _equipped = null; }
// null - drop | else - equip public bool SetEquipped(base_item item) { // if (item == null) // { // if (!_equipped) // return; // if (gameObject.layer == game_variables.Instance.LayerPlayer) // { // feedback_toaster.Instance.RegisterMessage(gameObject.name + " : drop " + _equipped?.gameObject.name, game_variables.Instance.ColorItem); // menu_inventory.Instance.SetEquipped(_equipped, false); // } // _equipped?.SetParent(null); // _equipped?.SetActive(true); // _equipped = null; // } // else // { // if (_equipped != null) // { // if (menu_inventory.Instance.IsEmptyOrContains(item)) // _equipped.SetActive(false); // else // { // _equipped.SetParent(null); // _equipped.SetActive(true); // } // } // // else if (menu_inventory.Instance.IsEmptyOrContains(item)) // // { // // // // // } // if (gameObject.layer == game_variables.Instance.LayerPlayer) // { // feedback_toaster.Instance.RegisterMessage(gameObject.name + " : equip " + item.gameObject.name, game_variables.Instance.ColorItem); // menu_inventory.Instance.SetEquipped(item, true); // } // _equipped = item; // _equipped.SetActive(true); // _equipped.SetParent(_motor._anchor); // } // --- // // player // if (gameObject.layer == game_variables.Instance.LayerPlayer) // { // if (item) // { // // add // feedback_toaster.Instance.RegisterMessage(gameObject.name + " : equip " + item.gameObject.name, game_variables.Instance.ColorItem); // menu_inventory.Instance.InventoryModify(item, true); // } // else // { // // remove // feedback_toaster.Instance.RegisterMessage(gameObject.name + " : drop " + _equipped?.gameObject.name, game_variables.Instance.ColorItem); // menu_inventory.Instance.InventoryModify(_equipped, false); // } // } // --- // // * testing // // pickup // if (item) // { // // player // if (gameObject.layer == game_variables.Instance.LayerPlayer) // { // // try add/replace // if (!menu_inventory.Instance.Modify(item, true)) // // fail - ignore // return; // // // if (_equipped) // { // // added // if (menu_inventory.Instance.Contains(_equipped)) // // holster // _equipped.SetActive(false); // // replaced // else // // drop // _equipped.SetParent(null); // } // } // // store/overwrite reference // _equipped = item; // _equipped.SetParent(_motor._anchor); // } // // drop // else // { // // ignore // if (!_equipped) // return; // // player, try remove // if (gameObject.layer == game_variables.Instance.LayerPlayer && !menu_inventory.Instance.Modify(_equipped, false)) // // fail - ignore // return; // // clear reference // _equipped.SetParent(null); // _equipped = item; // } // --- if (!item) return false; // player, try add if (gameObject.layer == game_variables.Instance.LayerPlayer && !menu_inventory.Instance.Modify(item, true)) // fail - ignore return false; // store/overwrite reference Holster(); _equipped = item; _equipped.SetParent(_motor._anchor); return true; }
public virtual void HealthDrain(int value = 0, Transform source = null) { if (_healthInst == 0 || _timerIframes > 0f) return; _healthInst -= value == 0 ? _health : value; _healthInst = Mathf.Clamp(_healthInst, 0, _health); if (source) { if (!_hostiles.Contains(source)) _hostiles.Add(source); if (gameObject.layer == game_variables.Instance.LayerPlayer) feedback_damage.Instance.RegisterMarker(source); if (gameObject.layer == game_variables.Instance.LayerMob) _controller.RegisterEvent(source.position, source.gameObject.layer, Time.time); } print("Hurt " + gameObject.name + ":" + source); // * testing if (gameObject.layer == game_variables.Instance.LayerPlayer) { // ? duration if (game_variables.Instance.Vibration == 0 || game_variables.Instance.Vibration == 1) Handheld.Vibrate(); feedback_toaster.Instance.RegisterMessage(gameObject.name + " : health -" + (value == 0 ? _health : value), game_variables.Instance.ColorDamage); } else if (gameObject.layer == game_variables.Instance.LayerMob) feedback_popup.Instance.RegisterMessage(transform, "health -" + (value == 0 ? _health : value), game_variables.Instance.ColorDamage); // // * testing drop on hurt // if (_equipped) // SetEquipped(null); // Instantiate(_gib, transform.position, transform.rotation).SetActive(true); // * testing if (_healthInst == 0) { Clear(); _motor.NavigateCancel(); // * testing drop item // menu_inventory.Instance.SetEquipped(null); SetEquipped(null); if (_resurrect) { HealthRestore(); if (gameObject.layer == game_variables.Instance.LayerPlayer) SetIframes(); } else if (gameObject.layer == game_variables.Instance.LayerPlayer) { // game_master.Instance.Save(); manager_ui.Instance.SetMain(true); input_touch.Instance.Initialize(); } else if (gameObject.layer == game_variables.Instance.LayerMob) { _hostiles.Clear(); _hostiles.Add(controller_player.Instance.Motor.transform); // * testing disable colliders ? disallow target gameObject.SetActive(false); foreach (GameObject drop in _drops) { base_item temp = (Instantiate(drop, transform.position, transform.rotation)).GetComponent<base_item>(); temp?.gameObject.SetActive(true); temp?.SetParent(null); // temp?.AddForce(new Vector2(Random.Range(-1f, 1f) * _force, Random.Range(-1f, 1f) * _force)); } } } }