public void Register(base_item item) { if (_items.Contains(item)) { return; } _items.Add(item); }
// public bool IsEmptyOrContains(base_item item) // { // // if (_equipment.Count < 5) // if (_equipment.Count < controller_player.Instance.Data.Inventory) // return true; // for (int i = 0; i < _equipment.Count; i++) // if (_equipment[i].Item == item) // return true; // return false; // } public bool Contains(base_item item) { for (int i = 0; i < _equipment.Count; i++) { if (_equipment[i].Item == item) { return(true); } } return(false); }
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; }
// ? override Start protected virtual void Initialize() { if (gameObject.layer == game_variables.Instance.LayerMob) _controller = GetComponent<controller_mob>(); // _equipped = null; // _autoPickup = false; // _health = 1; // _ammoWeapons = new int[3]; // ? new load save // * testing gem ?coin ?pearl _collectibles = new int [5]; // gold // pouch CollectibleModify(1, 1); // ammo flintlock CollectibleModify(2, 8); // ammo shotgun CollectibleModify(3, 4); // ammo saber CollectibleModify(4, 6); _invisible = false; }
public void Holster() { _equipped?.SetActive(false); _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)); } } } }
// // null - remove drop | else - add equip // public void SetEquipped(base_item item) // { // // drop // if (item == null) // { // // unequipped // if (!controller_player.Instance.Data.Equipped) // // ignore // return; // // // player // // if (gameObject.layer == game_variables.Instance.LayerPlayer) // // { // // // remove // // feedback_toaster.Instance.RegisterMessage(gameObject.name + " : drop " + controller_player.Instance.Data.Equipped?.gameObject.name, game_variables.Instance.ColorItem); // // InventoryModify(controller_player.Instance.Data.Equipped, false); // // } // // clear reference // // controller_player.Instance.Data.Equipped.SetParent(null); // // controller_player.Instance.Data.Equipped.SetActive(true); // // controller_player.Instance.Data.SetEquipped(null); // } // // pickup // else // { // // equipped // if (controller_player.Instance.Data.Equipped) // { // // // space or match // // if (IsEmptyOrContains(item)) // // // holster ? // // controller_player.Instance.Data.Equipped.SetActive(false); // // ignore // // return; // // // player // // if (gameObject.layer == game_variables.Instance.LayerPlayer) // // { // // // remove // // feedback_toaster.Instance.RegisterMessage(gameObject.name + " : drop " + controller_player.Instance.Data.Equipped?.gameObject.name, game_variables.Instance.ColorItem); // // InventoryModify(controller_player.Instance.Data.Equipped, false); // // } // // clear reference // // controller_player.Instance.Data.Equipped.SetParent(null); // // controller_player.Instance.Data.Equipped.SetActive(true); // controller_player.Instance.Data.SetEquipped(null); // } // // else if (menu_inventory.Instance.IsEmptyOrContains(item)) // // { // // // // // } // // // player // // 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); // // // controller_player.Instance.Data.SetEquipped(item); // // InventoryModify(item, true); // // } // // store reference // controller_player.Instance.Data.SetEquipped(item); // // controller_player.Instance.Data.Equipped.SetActive(true); // // controller_player.Instance.Data.Equipped.SetParent(controller_player.Instance.Motor._anchor); // } // } // true - add | false - remove public bool Modify(base_item item, bool equip) { Pouch remove = new Pouch(); for (int i = 0; i < _equipment.Count; i++) { if (_equipment[i].Item == item) { if (equip) { // match - duplicate feedback_toaster.Instance.RegisterMessage("Equip : " + item.gameObject.name, game_variables.Instance.ColorItem); return(true); } else { // match - remove remove = _equipment[i]; } break; } } if (_equipment.Contains(remove)) { _equipment.Remove(remove); // drop item feedback_toaster.Instance.RegisterMessage("Drop : " + remove.Item.gameObject.name, game_variables.Instance.ColorItem); remove.Slot.GetComponent <SelfDestruct>().Trigger(); return(true); } if (equip) { // if (_equipment.Count < 5) if (IsEmpty) { // no match, space - add Pouch pouch = new Pouch(); pouch.Slot = Instantiate(_pouch, transform.position, transform.rotation).transform; pouch.Slot.SetParent(transform); pouch.Slot.gameObject.SetActive(true); pouch.Slot.GetComponent <button_pouch>().ID = _equipment.Count; pouch.Item = item; pouch.Status = pouch.Slot.GetChild(0).GetComponent <Text>(); _equipment.Add(pouch); feedback_toaster.Instance.RegisterMessage("Equip : " + item.gameObject.name, game_variables.Instance.ColorItem); return(true); } else { // full - warning feedback_toaster.Instance.RegisterMessage("Inventory Full - Cannot Equip Item", game_variables.Instance.ColorDefault); } // { // for (int i = 0; i < _equipment.Count; i++) // { // if (_equipment[i].Item == controller_player.Instance.Data.Equipped) // { // // full, equipped - replace // feedback_toaster.Instance.RegisterMessage("Drop : " + _equipment[i].Item.gameObject.name, game_variables.Instance.ColorItem); // Pouch pouch = new Pouch(); // pouch.Slot = _equipment[i].Slot; // pouch.Item = item; // pouch.Status = _equipment[i].Status; // // _equipment[i].Item.SetActive(true); // _equipment[i] = pouch; // feedback_toaster.Instance.RegisterMessage("Equip : " + item.gameObject.name, game_variables.Instance.ColorItem); // return true; // } // } // } } return(false); }