public static ItemScript CreateItem(Category type, int id) { /*GameObject tmp = Instantiate(InventoryManager.Instance.itemObject); tmp.AddComponent<ItemScript>(); ItemScript itemScript = tmp.GetComponent<ItemScript>(); Destroy(tmp);*/ ItemScript itemScript = new ItemScript(); switch (type) { case Category.Equipment: itemScript.Item = InventoryManager.Instance.ItemContainer.Equipments.Find(x => x.Id == id); break; case Category.Weapon: itemScript.Item = InventoryManager.Instance.ItemContainer.Weapons.Find(x => x.Id == id); break; case Category.Consumable: itemScript.Item = InventoryManager.Instance.ItemContainer.Consumables.Find(x => x.Id == id); break; default: break; } return itemScript; }
public override void Use (Slot slot, ItemScript item) { if (ItemName == "Energy Potion" && Stamina.Instance.currentStamina < Stamina.Instance.maxStamina){ Debug.Log(ItemName); Stamina.Instance.currentStamina += Stamina.Instance.energyPot; Stamina.Instance.bar.fillAmount += Stamina.Instance.energyPot / 100f; Stamina.Instance.ManaColor(); Stamina.Instance.ManaText(); if(Stamina.Instance.currentStamina >= Stamina.Instance.maxStamina) { Stamina.Instance.currentStamina = Stamina.Instance.maxStamina; } slot.RemoveItem(); } if (ItemName == "Health Potion" && PlayerScript.Instance.currentHealth < PlayerScript.Instance.maxHealth) { Debug.Log(ItemName); PlayerScript.Instance.GetHealth(); PlayerScript.Instance.HandleHealth(); slot.RemoveItem(); } if (ItemName == "Rage Potion" && Stamina.Instance.currentRage < Stamina.Instance.maxRage) { Debug.Log(ItemName); Stamina.Instance.RagePotion(); slot.RemoveItem(); } }
public void EquipItem(Slot slot, ItemScript item) { Slot to = Array.Find(equipmentSlots, x => x.canContain == item.Item.ItemType); if (to != null) { Slot.SwapItems(slot, to); SetClothing(to.name); } }
public void EquipItem(ItemScript item) { Slot to = Array.Find(equipmentSlots, x => x.canContain == item.Item.ItemType); if (to != null) { to.AddItem(item); SetClothing(to.name); } }
public void EquipItem(Slot slot, ItemScript item){ if (item.Item.ItemType == ItemType.MAINHAND || item.Item.ItemType == ItemType.TWOHAND && OffhandSlot.IsEmpty){ Slot.SwapItems(slot, WeaponSlot); } else{ Slot.SwapItems(slot, Array.Find(equipmentSlots, x => x.canContain == item.Item.ItemType)); } }
// Use this for initialization void Start() { mScript1 = Item1.GetComponent<ItemScript>(); mScript2 = Item2.GetComponent<ItemScript>(); mScript3 = Item3.GetComponent<ItemScript>(); mScript4 = Item4.GetComponent<ItemScript>(); mScript5 = Item5.GetComponent<ItemScript>(); mScript6 = Item6.GetComponent<ItemScript>(); mScript7 = Item7.GetComponent<ItemScript>(); }
//Equipts an item //The slot the item comes from, The item to equip public void EquipItem(Slot slot, ItemScript item) { //If we are equipping something in our hands, then we need to make sure, that we cant equip a twohand and an offhand at the same time if (item.Item.ItemType == ItemType.MAINHAND || item.Item.ItemType == ItemType.TWOHAND && OffHandSlot.IsEmpty) { Slot.SwapItems(slot, WeaponSlot); //Equips the item } else { //If it isn't a weapon Slot.SwapItems(slot, Array.Find(equipmentSlots, x => x.canContain == item.Item.ItemType)); //Equips the item } }
public void AddItem(ItemScript item) { if (isEmpty) { transform.parent.GetComponent<Inventory>().EmptySlots--; } items.Push (item); if (items.Count > 1) { stackText.text = items.Count.ToString(); } SpriteChange (item.spriteneutral, item.spriteHighlighted); }
public void SetItem(ItemScript newItem) { item = newItem; string path; Equipment equipment = (Equipment)item.Item; if (!this.GetComponentInParent<HumanoidBuilder>().Female || equipment.FemalePath == string.Empty) path = equipment.MalePath; else path = equipment.FemalePath; subSprites = Resources.LoadAll<Sprite>(path); spriteRenderer = GetComponent<SpriteRenderer>(); spriteRenderer.enabled = true; }
public void AddItem(ItemScript item) { items.Push(item); if (items.Count > 1) { stackTxt.text = items.Count.ToString(); } if (this.items.Count > 0) { ChangeSprite(CurrentItem.sprite); IconSprite.enabled = true; } }
public override void Use(Slot slot, ItemScript item) { slot.RemoveItem (); Debug.Log ("Used " + ItemName); player = GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.health = player = GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.health + Health; if(GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.health >= GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.maxHealth) { GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.health = GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.maxHealth; } player = GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.mana = player = GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.mana + Mana; if(GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.mana >= GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.maxMana) { GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.mana = GameObject.FindGameObjectWithTag("Player").GetComponent<Fighter>().PlayerClass.maxMana; } }
//creates a list of all positions which fire can spread to //then checks if any flammable objects occupy that position //then sets em on fire public void SpreadFire() { GameObject[] allItemsOnMap = TimeManagerScript.instance.allItemsOnGrid; List <Vector2Int> toFire = SpreadFireHelper(); toFire = toFire.Distinct().ToList(); for (int i = 0; i < allItemsOnMap.Length; i++) { ItemScript scr = allItemsOnMap[i].GetComponent <ItemScript>(); if (!scr.isOnFire && scr.isFlammable && scr.itemPos.x >= 0) //only set to fire if it's flammable and not yet on fire { for (int j = 0; j < toFire.Count; j++) { if (scr.CompareToItemPosition(toFire[j])) { scr.SetFire(true); break; } } } } }
private void Update() { if (Input.GetMouseButtonDown(0) && Input.mousePosition.x > GetComponent <Transform>().position.x) // drop item back { if (invenManger.selectedButton == null && ItemScript.selectedItem != null) //dropping back from ivenGrid { itemList.Add(ItemScript.selectedItem.GetComponent <ItemScript>().item); AddButton(ItemScript.selectedItem.GetComponent <ItemScript>().item);// shorten later itemEquipPool.ReturnObject(ItemScript.selectedItem); ItemScript.ResetSelectedItem(); } } if (Input.GetMouseButtonDown(1) && invenManger.selectedButton != null) //delesect selected item and button by right-click { invenManger.RefrechColor(false); // not refresh color to blue when mouse is non top of occupied slot after putting back itemEquip invenManger.selectedButton.GetComponent <CanvasGroup>().alpha = 1f; invenManger.selectedButton = null; itemEquipPool.ReturnObject(ItemScript.selectedItem); ItemScript.ResetSelectedItem(); } }
void ShootWater() { //Debug.Log("Shoot"); if (waterAmmoClip > 0) { Debug.Log("Shooting water!"); waterAmmoClip--; RaycastHit hit = new RaycastHit(); // getting camera transform for the raycast Transform camera = GameObject.FindGameObjectWithTag("HumanCamera").transform; // raycast if (Physics.Raycast(camera.position, camera.TransformDirection(Vector3.forward), out hit, waterRange)) { Debug.Log("Raycasted object: " + hit.collider.name); // if the player shot flamable object that is on fire if (hit.collider.gameObject.tag == "Flamable") { ItemScript itemScript = hit.collider.gameObject.GetComponent <ItemScript> (); Debug.Log("Raycasted flamable object: " + hit.collider.name); // used to show up UI elements, when the player points at fired object if (itemScript.onFire) { // adding steam effect itemScript.AddSteamEffect(); // passing the amount of water to itemscript itemScript.amountOfWater += waterAmount; Debug.Log("Amount Filled " + itemScript.amountOfWater); } } // end of hit.tag = "Flamable" } // end of Physics.Raycast } // end of waterAmmoClip > 0 } // end of ShootWater()
private void CreatePackageOfItems(List <ItemForCheck> itemsToMail) { ClearPackageOfItems(itemsToMail); for (int i = 0; i < buyItemWindow.transform.GetChild(1).GetChild(0).GetChild(0).childCount - 1; i++) { GameObject itemObject = buyItemWindow.transform.GetChild(1).GetChild(0).GetChild(0).GetChild(i).gameObject; ItemScript item = itemObject.GetComponent <InfoAboutItemToBuyScript>().item; itemsToMail.Add(new ItemForCheck( item.nameItem, item.vendorCode, item.firstTypeItem, item.secondTypeItem, item.firstCostItem.ToString(), item.secondCostItem.ToString(), itemObject.GetComponent <InfoAboutItemToBuyScript>().chousenSize, item.briefInfoOfItem, item.compositionOfItem, item.manufacturingFirm, itemObject.GetComponent <InfoAboutItemToBuyScript>().summIntText.text.ToString()) ); } }
void CheckForItems(float dist, Vector3 pos) { GameObject[] gos; gos = GameObject.FindGameObjectsWithTag("item"); foreach (GameObject go in gos) { xa.glx = go.transform.position; xa.glx.z = pos.z; if (Vector3.Distance(xa.glx, pos) < 10) //just check theyre not, like, on the other side of the map { float tempDist = dist; ItemScript itemScript = go.GetComponent <ItemScript>(); if (itemScript != null) { if (itemScript.itemActivationRadiusOverride != -1) { tempDist = itemScript.itemActivationRadiusOverride; } } if (Vector3.Distance(xa.glx, pos) < tempDist) { if (itemScript != null && itemScript.type != "bounceCoin") { UseFoundItem(go); } if (itemScript != null && itemScript.type == "bouncePad") { UseFoundItem(go); } } } } ShrineScript.CheckShrines(pos); }
public bool AddItem(ItemScript item) { if (item.maxSize == 1) { PlaceEmpty(item); return true; } else { foreach (Slot slot in allSlots) { Slot temp = slot.GetComponent<Slot>(); if (!temp.isEmpty) { if (temp.currentItem.type == item.type && temp.currentItem.itemName == item.itemName && temp.isAvailable) { if (temp.currentItem.classification == item.classification) { if (!InventoryManager.Instance.MovingSlot.isEmpty && InventoryManager.Instance.Clicked.GetComponent<Slot>() == temp.GetComponent<Slot>()) { continue; } else { temp.AddItem(item); return true; } } } } } if (emptySlots > 0) { return PlaceEmpty(item); } } return false; }
void OnCollisionEnter(Collision collision) { foreach (Collider col in Physics.OverlapSphere(this.transform.position, waterRadius)) { // if the nearby object has flamable tag if (col.gameObject.tag == "Flamable") { // getting ItemScript script from the object nearby ItemScript itemScript = col.GetComponent <ItemScript> (); // if the object is on fire if (itemScript.onFire) { // getting the closest face of the object that is near the water bomb Vector3 closestPoint = col.GetComponent <Collider> ().ClosestPointOnBounds(this.gameObject.transform.position); // distance between the closest face of the item on fire and the water bomb float distance = Vector3.Distance(closestPoint, this.gameObject.transform.position); // the closer the object the bigger the number which will lead to more water poured on the nearby objects on fire float waterRate = waterRadius - distance; // example 10 - 3, waterRate = 7 // leting the item script handle extinguishing itemScript.amountOfWater += (waterAmount * (waterRate / 10)); // adding steam particle effect steamEffect = Instantiate(Resources.Load("Prefabs/Steam"), itemScript.transform.position, Quaternion.identity) as GameObject; Debug.Log("I'm a water bomb and I exploded on " + col.gameObject.name + " object, distance from the object is " + distance + ", amountfilled = " + itemScript.amountOfWater); } // end of !(itemScript.onFire) } // end of (tag == "Flamable") } // end of foreach // had issues with object being destroyed at the start because it collided with the human if (timeAlive > 0.2f) { Destroy(this.gameObject); } }
public void onClick() { if (parent.GetComponent <ContextMenuScript>() != null) { item = parent.GetComponent <ContextMenuScript>().attachedItem.GetComponent <ItemScript>(); } if (parent.GetComponent <ContextMenuScript2>() != null) { item2 = parent.GetComponent <ContextMenuScript2>().attachedItem.GetComponent <lockObject>(); } string msg = "This object has no message"; if (item != null) { msg = item.message; } if (item2 != null) { msg = item2.message; } InspectMessageScript message = GameObject.Find("InspectMessage").GetComponent <InspectMessageScript>(); message.UpdateMessage(msg); if (parent.GetComponent <ContextMenuScript>() != null) { parent.GetComponent <ContextMenuScript>().Deactivate(); } if (parent.GetComponent <ContextMenuScript2>() != null) { parent.GetComponent <ContextMenuScript2>().Deactivate(); } }
/// <summary> /// 회복이 이루어지는 루틴입니다. /// </summary> /// <param name="player">플레이어 객체입니다.</param> /// <param name="item">사용한 아이템입니다.</param> /// <returns>Update()를 다시 호출하기 위해 함수를 종료할 때마다 null을 반환합니다.</returns> IEnumerator HealRoutine(PlayerController player, ItemScript item) { // 사용할 변수를 선언합니다. float time = 0f; float unitTime = 0.02f; AudioSource audioSource = AudioSources[item.SoundEffectIndexes[0]]; // 체력을 회복하는 루프입니다. for (int i = 0, len = item._itemValue; i < len; ++i) { // 루프 진입시마다 시작 시간을 초기화합니다. time = 0f; // 체력이 가득 찼다면 반복문을 탈출합니다. if (player.IsHealthFull()) { break; } // 체력을 회복하면서 체력 회복 효과음을 재생합니다. audioSource.Play(); audioSource.time = 0; player.Heal(); // 일정한 간격으로 체력을 회복합니다. while (time < unitTime) { time += Time.unscaledDeltaTime; yield return(null); } } // 정지한 움직임을 해제합니다. Unfreeze(); // 코루틴을 종료합니다. yield break; }
public void EquipItem(ItemScript item) { if (playerStats == null) { print("Error in PlayerInvetory EquipItem 81\n"); return; } if (item.GetItemName() == "Ring") { if (playerRing1 != null) { playerRing1 = item; playerStats.AddToStats(item); itemCount--; } else if (playerRing2 != null) { playerRing2 = item; playerStats.AddToStats(item); itemCount--; } } else if (item.GetItemName() == "Amulet") { if (playerAmulet1 != null) { playerAmulet1 = item; playerStats.AddToStats(item); itemCount--; } else if (playerAmulet2 != null) { playerAmulet2 = item; playerStats.AddToStats(item); itemCount--; } } }
void UpdateTheUI() { ItemScript zeItem = toKnowTheSlots.allTheSlots[m_slotAt].GetComponentInChildren <ItemScript>(); // Check whether is there any item script in the slot! if (zeItem != null) { theItemImage.enabled = true; theItemText.text = zeItem.m_itemInform.item_effect; theItemImage.sprite = zeItem.GetComponentInChildren <Image>().sprite; } else { theItemText.text = ""; //theItemImage.sprite = null; theItemImage.enabled = false; } thePosition.SetParent(toKnowTheSlots.allTheSlots[m_slotAt].GetComponent <RectTransform>(), false); // We will need to scroll the inventory! float zeValue = (float)(m_slotAt) / (float)toKnowTheSlots.allTheSlots.Count; theInventoryScrollbar.value = zeValue; }
void FixedUpdate () { if ( _inventory._slots.Count == 0) { return; } _item = _inventory._availableItems [_inventory._slots [_inventory._currentSlot]]; if (isLocalPlayer) { if(_fire1 && _item.Fire1()){ BulletScript bulletScript = _item.PrepareBullet(); if(hasAuthority){ UpdateHistory(_shotID,bulletScript); Rpc_Shoot(); }else{ Cmd_Fire1(_shotID); } _item.Shoot(true,_shotID,bulletScript); _shotID++; if(_shotID==255){ _shotID = 0; } } } }
public void OnPointerDown(PointerEventData eventData) { if (this.items != null) { if (selectedItemScript.items != null) { ItemScript cloneItemScript = new ItemScript(selectedItemScript.items); selectedItemScript.UpdateItemFunction(this.items); UpdateItemFunction(cloneItemScript); } else { selectedItemScript.UpdateItemFunction(this.items); UpdateItemFunction(null); } } else if (selectedItemScript.items != null) { UpdateItemFunction(selectedItemScript.items); selectedItemScript.UpdateItemFunction(null); } }
public bool Add(ItemScript item) { if (!item.isDefaultItem) { if (items.Count >= space) { Debug.Log("Not enough room."); return(false); } else { items.Add(item); } if (onIntemChangedCallback != null) { onIntemChangedCallback.Invoke(); } } return(true); }
void OnCollisionEnter2D(Collision2D collision) { /* 碰到对手 */ //Debug.Log ("OnCollisionEnter2D: " + collision.gameObject); mouseAudio.PlayOneShot(mousePong, 0.1f * collision.relativeVelocity.sqrMagnitude > 1f ? 1f : 0.1f * collision.relativeVelocity.sqrMagnitude); HealthScript hs = collision.gameObject.GetComponent <HealthScript>(); if (hs && hs.attack < attack) { // && hs.isEnemy != isEnemy) { // 攻击力不为0时,对对手和本方都会造成伤害 hs.Damage(attack - hs.attack); } // 碰到树桩受伤害 ItemScript iScript = collision.gameObject.GetComponent <ItemScript>(); if (iScript && iScript.isObstacle()) { Damage(iScript.damage); } }
/// <summary> /// Adds an item to inventory /// </summary> /// <param name="item"></param> /// <returns>true if we were able to add item to inventory</returns> public bool AddItem(ItemScript item) { //If we have unstackable item then just find the first avaible slot if (item.Item.MaxSize == 1) { PlaceEmpty(item); return(true); } else { foreach (GameObject slot in allSlots) { Slot tmp = slot.GetComponent <Slot>(); if (!tmp.isEmpty) { if (tmp.CurrentItem.Item.Id == item.Item.Id && tmp.IsAvailable) { if (!InventoryManager.Instance.MovingSlot.isEmpty && InventoryManager.Instance.Clicked.GetComponent <Slot>() == tmp.GetComponent <Slot>()) { continue; } else { tmp.AddItem(item); return(true); } } } } } if (EmptySlots() > 0) { PlaceEmpty(item); } return(false); }
void Victory() { int k = Random.Range(0, 4); Debug.LogWarning(k); for (int i = 0; i < k; i++) { GameObject temp = Instantiate(CashPrefab, this.transform.position + new Vector3(Random.Range(1, 3), Random.Range(1, 3), 0), Quaternion.identity); temp.GetComponent <CoinBehavior>().value = 100; } BossBar.SetActive(false); BossNameText.SetActive(false); ItemList = GameObject.Find("GameManager").GetComponent <ItemScript>(); int randomList = Random.Range(0, 3); if (randomList == 0) { droppedit = ItemList.Weapons[Random.Range(1, ItemList.Weapons.Count - 1)] as Weapon; } if (randomList == 1) { droppedit = ItemList.Passives[Random.Range(1, ItemList.Passives.Count - 1)] as Passive; } if (randomList == 2) { droppedit = ItemList.Usables[Random.Range(1, ItemList.Usables.Count - 1)] as UsableItem; } GameObject placehold; placehold = Instantiate(dropitem, transform.parent.position - new Vector3(0, 3, 0), Quaternion.identity, GameObject.FindGameObjectWithTag("Level").transform); placehold.GetComponent <DropBehavior>().thisitem = droppedit; placehold.GetComponent <SpriteRenderer>().sprite = droppedit.Shopsprite; Instantiate(Door, transform.parent.position, Quaternion.identity, GameObject.FindGameObjectWithTag("Level").transform); // //while boss is destroyed run this void in order to spawn item and do other stuff }
/// <summary> /// Adds an item to inventory /// </summary> /// <param name="item"></param> /// <returns>true if we were able to add item to inventory</returns> public bool AddItem(ItemScript item) { //If we have unstackable item then just find the first avaible slot if (item.Item.MaxSize == 1) { PlaceEmpty(item); return true; } else { foreach (GameObject slot in allSlots) { Slot tmp = slot.GetComponent<Slot>(); if (!tmp.isEmpty) { if (tmp.CurrentItem.Item.Id == item.Item.Id && tmp.IsAvailable) { if (!InventoryManager.Instance.MovingSlot.isEmpty && InventoryManager.Instance.Clicked.GetComponent<Slot>() == tmp.GetComponent<Slot>()) { continue; } else { tmp.AddItem(item); return true; } } } } } if (EmptySlots() > 0) { PlaceEmpty(item); } return false; }
public override void OnConstruct() { base.OnConstruct(); _mainGo = itemDrag.CreateViewGameObject(null); if (_mainGo == null) { return; } if (_peTrans == null) { _peTrans = gameObject.AddComponent <PeTrans>(); } if (_peTrans != null) { _peTrans.SetModel(_mainGo.transform); } _mainGo.transform.parent = transform; _mainGo.transform.position = transform.position; _mainGo.transform.rotation = transform.rotation; _mainGo.transform.localScale = transform.localScale; ItemScript itemScript = _mainGo.GetComponentInChildren <ItemScript>(); if (null != itemScript) { itemScript.SetItemObject(itemDrag.itemObj); itemScript.InitNetlayer(mNetlayer); itemScript.id = id; itemScript.OnConstruct(); } IsFirstConstruct = false; }
//Adds an item to the inventory public bool AddItem(ItemScript item) { if (item.Item.MaxSize == 1) { //If the item isn't stackable //Places the item at an empty slot return PlaceEmpty(item); } else { //If the item is stackable foreach (GameObject slot in allSlots) { //Runs through all slots in the inventory Slot tmp = slot.GetComponent<Slot>(); //Creates a reference to the slot if (!tmp.IsEmpty) { //If the item isn't empty //Checks if the om the slot is the same type as the item we want to pick up if (tmp.CurrentItem.Item.ItemName == item.Item.ItemName && tmp.IsAvailable) { if (!InventoryManager.Instance.MovingSlot.IsEmpty && InventoryManager.Instance.Clicked.GetComponent<Slot>() == tmp.GetComponent<Slot>()) { continue; } else { tmp.AddItem(item); //Adds the item to the inventory return true; } } } } if (emptySlots > 0) //Places the item on an empty slots { return PlaceEmpty(item); } } return false; }
// Update is called once per frame void Update() { if (Time.frameCount % 120 == 0) { frequncy += 2; } if (Time.frameCount % flamecheck == 0) { int rand = UnityEngine.Random.Range(0, 100); if (rand < frequncy) { int randnum = UnityEngine.Random.Range(0, Item.Length); int randX = UnityEngine.Random.Range(0, 30); Vector3 popPosition = new Vector3(transform.position.x - 1.5f + randX / 10.0f, transform.position.y, transform.position.z); GameObject item = Instantiate(Item[randnum], popPosition, transform.rotation) as GameObject; item.name = "target" + randnum; ItemScript itemScript = item.GetComponent <ItemScript>(); itemScript.itemNum = randnum; int randd = UnityEngine.Random.Range(0, 40); itemScript.SetSpeed(0.01f + randd / 3000.0f); } } }
private Color startColor; // this is the material the object has at the start // Puts on fire nearby items. Slowly changes the nearby objects' timeToFire (which will make it even easier to lighten up when candle approaches), the closer to the burning object the bigger change void FireNearbyItems() { foreach (Collider col in Physics.OverlapSphere(this.transform.position, fireSpreadRadius)) { // if the nearby object has flamable tag if (col.gameObject.tag == "Flamable") { // getting ItemScript script from the object nearby ItemScript itemScript = col.GetComponent <ItemScript> (); // if the object isn't yet on fire if (!(itemScript.onFire)) { // getting the closest face of the object that is near to the fire Vector3 closestPoint = col.GetComponent <Collider> ().ClosestPointOnBounds(this.gameObject.transform.position); // distance between the closest face and the object on fire float distance = Vector3.Distance(closestPoint, this.gameObject.transform.position); // the closer the object the bigger the number which will lead to more quickly putting the nearby object on fire float fireRate = fireSpreadRadius - distance; // example 10 - 3, fireRate = 7 // putting fire on the object, the further the object the longer it's going to take to light it up. // EXAMPLE 0.1 * (1 / 5) = 0.02, the object is 5 units away timePuttingFire += Time.deltaTime * (0.1f / fireRate); //Debug.Log ("I'm " + this.gameObject.name + " and I'm lighting up " + col.gameObject.name + " object, distance from the object is " + distance + ", fireRate = " + fireRate + " timePuttingFire: " + timePuttingFire); // if the amount of time putting on other object exeeds the needed to fire it up if (timePuttingFire >= itemScript.timeToFire) { // making the itemscript script's variable to true itemScript.onFire = true; // reseting the variable timePuttingFire = 0.0f; } } // end of !(itemScript.onFire) } // end of (tag == "Flamable") } // end of foreach }
public void addToInventory(ItemScript item) { bool found = false; foreach (ItemScript i in inventory) { if (i.itemName == item.itemName) { i.AddItem(); i.OnPickUp(); //Debug.Log("Player has item " + item.itemName +" Count: "+i.count); InventoryEvent?.Invoke(inventory); found = true; } } //Debug.Log("Adding " + item.itemName + " to inventory first time."); if (!found) { inventory.Add(item); item.AddItem(); item.OnPickUp(); InventoryEvent?.Invoke(inventory); } }
public void Construct(DragItemLogicCreation dragLogic) { var creation = GetComponent <CreationController>(); creation.visible = true; switch (creation.category) { case EVCCategory.cgAircraft: { ItemScript itemScript = GetComponent <ItemScript>(); if (null != itemScript) { itemScript.SetItemObject(dragLogic.itemDrag.itemObj); itemScript.InitNetlayer(dragLogic.mNetlayer); itemScript.id = dragLogic.id; } break; } case EVCCategory.cgBoat: case EVCCategory.cgVehicle: case EVCCategory.cgRobot: case EVCCategory.cgAITurret: { ItemScript itemScript = GetComponent <ItemScript>(); if (null != itemScript) { itemScript.SetItemObject(dragLogic.itemDrag.itemObj); itemScript.InitNetlayer(dragLogic.mNetlayer); itemScript.id = dragLogic.id; } break; } } }
void OnTriggerEnter2D(Collider2D otherCollider) { GameObject iObject = otherCollider.gameObject; ItemScript iScript = iObject.GetComponent <ItemScript>(); //Debug.Log ("hit a trigger: " + iScript.type); switch (iScript.type) { case ItemScript.ItemType.Score: Destroy(iObject); Restore(1); break; case ItemScript.ItemType.Trap: // hp = 0 Damage(hp); break; /* * case ItemScript.ItemType.Obstacle: * // 受到伤害HP -= 1 * Damage (1); * break; */ case ItemScript.ItemType.Fire: // 接触到火焰,增加攻击力 attack = 1; attackEnhanceTurnLeft = iScript.effectiveTurns; animator.SetBool("isFire", true); Destroy(iObject); break; default: break; } }
private void SpawnOrAddItem(ItemClass passedItem) { if (willAddToList)// add to list directly { sortManager.AddItemToList(passedItem); Debug.Log("Item added to list"); } else if (willAddToGrid)// add to grid directly { GameObject itemObj = itemEquipPool.GetObject(); itemObj.GetComponent <ItemScript>().SetItemObject(passedItem); // 그리드로 직접 저장이 실패한 경우 아이템을 다시 풀로 반환 if (invenManager.StoreItemDirectly(itemObj) == false) { itemEquipPool.ReturnObject(itemObj); } } else //spawn item on mouse { GameObject itemObject = itemEquipPool.GetObject(); itemObject.GetComponent <ItemScript>().SetItemObject(passedItem); ItemScript.SetSelectedItem(itemObject); } }
// place the itemScript in the empty slot private bool PlaceEmpty(ItemScript itemScript) { // checking if there are any empty slots if (emptySlot > 0) { // looping through all slots foreach (GameObject slot in allSlots) { Slot temp = slot.GetComponent <Slot>(); // check if slot is empty if (temp.isEmpty) { // adding the slot temp.AddItem(itemScript); // subtract empty Slot emptySlot--; return(true); } } } return(false); }
public void EquipItem(Slot slot, ItemScript item) { print ("Equipped"); item.isEquipped = true; if (item.isEquipped) { print ("Right-Clicked on Equipped Item!"); foreach (Slot spot in inventorySlots) { if (spot.isEmpty) { item.isEquipped = false; Slot.SwapItems (slot, spot); return; } } } else { Slot.SwapItems (slot, Array.Find(equipmentSlots, x => x.canContain == item.type)); item.isEquipped = true; } CalculateStats (); }
// Use this for initialization void Start() { buttonItems = new GameObject[shopItems.Length]; counter = 0; foreach (Item i in shopItems) { GameObject btn = (GameObject)Instantiate(button); buttonItems[counter] = btn; ItemScript scp = btn.GetComponent <ItemScript>(); scp.name.text = i.name; scp.cost.text = "Cost: " + i.cost.ToString("F1"); scp.count.text = i.count.ToString(); scp.gain.text = "BPS: " + i.gain.ToString("F1"); scp.icon.sprite = i.image; Item thisItem = i; scp.thisButton.onClick.AddListener(() => Purchase(thisItem)); btn.transform.SetParent(this.transform); counter++; } }
public void Upgrade(ItemScript item) { if (item.Attack > 0) { Attack = baseAttack + item.Attack; } if (item.Health > 0) { Health = Health + item.Health; } if (item.Movement > 0) { Movement = baseMovement + item.Movement; } if (item.Attack > 0) { DiggingPower = baseDigPower + item.DigPower; } if (Inventory == null) { Inventory = new List <ItemScript>(); } Inventory.Add(item); }
public override void Use(Slot slot, ItemScript item) { }
void DrawInventory() { Event e = Event.current; int i = 0; ItemScript item = slots[i]; for (int y = 0; y < slotsY; y++) { for (int x = 0; x < slotsX; x++) { Rect slotRect = new Rect(x*40, y * 40,30,30); GUI.Box(new Rect(slotRect), "", skin.GetStyle("Slots")); item = inventory[i]; if (item.itemName != null) { //this is the rectangule i whant to use GUI.DrawTexture(slotRect, item.itemIcon); // if with in this inventory rectangule, the mouse position layes. We can now se if the mouse is hovering over this slot if (slotRect.Contains(e.mousePosition)) { //if left mousebutton pressed pick up item => Move Item if (e.isMouse && e.button == 0 && e.type == EventType.mouseDrag && !draggingItem) { draggingItem = true; //we set the index number to the item.index we are dragging draggingIndex = i; //set the item to the item in that slot draggedItem = item; //set slot to empty item inventory[i] = new ItemScript(); } //swap items if (e.isMouse && e.type == EventType.mouseUp && draggingItem) { //Move the originat item of the new slot to the postition of the dragged items origan. inventory[draggingIndex] = inventory[i]; //set the dragged item to be the new item in the new slot inventory[i] = draggedItem; //we are no longer dragging items draggingItem = false; //set draggeditem to null, we are no longer dragging items. draggedItem = null; } //don't show tooltip if we are dragging if (!draggingItem) { toolTip = CreateToolTip(inventory[i]); showToolTip = true; } //Hover over slot and click right mousebutton to eat the item. if (e.isMouse && e.type == EventType.mouseDown && e.button == 1) { //if the item is consumable :-P if (item.itemType == ItemScript.ItemType.Consumable) { UseFood(slots[i],i,true); } } } if (toolTip == "") { showToolTip = false; } } else { //drop item ind a empty slot if (slotRect.Contains(e.mousePosition)) { if (e.isMouse && e.type == EventType.mouseUp && draggingItem) { //set the dragged item to be the new item in the new slot inventory[i] = draggedItem; //we are no longer dragging items draggingItem = false; //set draggeditem to null, we are no longer dragging items. draggedItem = null; } } } i++; } } }
//Places an item on an empty slot private bool PlaceEmpty(ItemScript item) { if (emptySlots > 0) { //If we have atleast 1 empty slot foreach (GameObject slot in allSlots) { //Runs through all slots Slot tmp = slot.GetComponent<Slot>(); //Creates a reference to the slot if (tmp.IsEmpty) { //If the slot is empty tmp.AddItem(item); //Adds the item return true; } } } return false; }
// Чтение всех записей из таблицы void ReadEntries() { if (ReturnCountItemOnServer() > 0) { items.Clear(); string query = string.Empty; // Отлавливаем ошибки try { query = "SELECT * FROM ItemList"; if (con.State.ToString() != "Open") { con.Open(); } using (con) { using (cmd = new MySqlCommand(query, con)) { rdr = cmd.ExecuteReader(); if (rdr.HasRows) { while (rdr.Read()) { ItemScript newItem = new ItemScript(); newItem.nameItem = rdr["nameItem"].ToString(); newItem.vendorCode = rdr["vendorCode"].ToString(); newItem.firstTypeItem = rdr["firstTypeItem"].ToString(); newItem.secondTypeItem = rdr["secondTypeItem"].ToString(); newItem.firstCostItem = float.Parse(rdr["firstCostItem"].ToString()); newItem.secondCostItem = float.Parse(rdr["secondCostItem"].ToString()); string size = rdr["sizeOfItem"].ToString(); //Debug.Log(size + " " + size.Length.ToString()); string[] sizeMass = size.Split(' '); newItem.sizeOfItem = new int[sizeMass.Length - 1]; //Debug.Log(sizeMass.Length); for (int i = 0; i < sizeMass.Length - 1; i++) { int.TryParse(sizeMass[i], out newItem.sizeOfItem[i]); } newItem.briefInfoOfItem = rdr["briefInfoOfItem"].ToString(); newItem.compositionOfItem = rdr["compositionOfItem"].ToString(); newItem.manufacturingFirm = rdr["manufacturingFirm"].ToString(); newItem.descriptionOfItem = rdr["descriptionOfItem"].ToString(); //newItem.imagesOfItem = rdr["imagesOfItem"].ToString(); bool image = bool.Parse(rdr["imagesOfItem"].ToString()); newItem.isThereItemOnStore = bool.Parse(rdr["isThereItemOnStore"].ToString()); newItem.name = newItem.vendorCode; items.Add(newItem); } } rdr.Dispose(); } } } catch (IOException ex) { Debug.Log(ex.ToString()); } finally { } isItemsLoaded = true; } }
/// <summary> /// Place an item to first avaible empty slot /// </summary> /// <param name="item"></param> /// <returns>true if we were able to place the item in inventory</returns> private bool PlaceEmpty(ItemScript item) { if (EmptySlots() > 0) { foreach (GameObject slot in allSlots) { Slot tmp = slot.GetComponent<Slot>(); if (tmp.isEmpty) { tmp.AddItem(item); return true; } } } return false; }
public void AddSettingsFrom(ItemScript itemScript) { PistolScript pistolScript = itemScript as PistolScript; if(pistolScript != null) { CurrentlyUnloadedAmmo += pistolScript.CurrentlyUnloadedAmmo + pistolScript.CurrentlyLoadedAmmo; if(CurrentlyUnloadedAmmo > MAXAMMO) { CurrentlyUnloadedAmmo = MAXAMMO; } } UIController.Instance.OnAmmoPickup(ItemType.pistol, CurrentlyUnloadedAmmo); }
//This function uses the item public abstract void Use(Slot slot, ItemScript item);
public static void SaveItems() { myGameState.itemData = ItemScript.AllGameItems(); }
public void AddSettingsFrom(ItemScript itemScript) { }
public static ItemScript CreateItem(int id) { /*GameObject tmp = Instantiate(InventoryManager.Instance.itemObject); tmp.AddComponent<ItemScript>(); ItemScript itemScript = tmp.GetComponent<ItemScript>(); Destroy(tmp);*/ ItemScript itemScript = new ItemScript(id); itemScript.Item = InventoryManager.Instance.ItemContainer.AllItems().Find(x => x.Id == id); return itemScript; }
private void UseFood(ItemScript item, int slot, bool deleteItem) { switch (item.itemID) { case 1: { //here we kan fx increase health on the Player print("Food eating: "+ item.itemName); break; } } if (deleteItem) { //replase item in slot with empty item inventory[slot] = new ItemScript(); } }
//Adds a single item to th inventory public void AddItem(ItemScript item) { if (IsEmpty) //if the slot is empty { transform.parent.GetComponent<Inventory>().EmptySlots--; //Reduce the number of empty slots } items.Push(item); //Adds the item to the stack if (items.Count > 1) //Checks if we have a stacked item { stackTxt.text = items.Count.ToString(); //If the item is stacked then we need to write the stack number on top of the icon } ChangeSprite(item.spriteNeutral, item.spriteHighlighted); //Changes the sprite so that it reflects the item the slot is occupied by }
// TODO : 우클릭 시에 원래자리로 돌아가도록 인벤그리드매니저에 추가. // TODO : 컬러 체인지 루틴은 빼기 private void Update() { if (Input.GetMouseButtonUp(0)) { // 씨앗 심기 등 원클릭 사용(?) 모드 일 때 if (UIController.Instance.IsSelectSequence) { if (highlightedSlot != null && ItemScript.selectedItem == null) // { var slotScript = highlightedSlot.GetComponent <SlotScript>(); // TODO : 이걸 나중에 slotscripts[,] 로 가져올 수 있도록 하는 방법을 생각해보자. if (slotScript.isOccupied) { UIController.Instance.SowSeedToGrower(slotScript.storedItemClass); Inventory.Instance.ExhaustItem(slotScript.storedItemClass); itemEquipPool.ReturnObject(slotScript.storedItemObject); // Remove item from slot slotScript.storedItemObject = null; slotScript.storedItemSize = IntVector2.Zero; slotScript.storedItemStartPos = IntVector2.Zero; slotScript.storedItemClass = null; slotScript.isOccupied = false; ClearCurtains(); } } } else { if (highlightedSlot != null && ItemScript.selectedItem != null && !isOverEdge) { switch (checkState) { case NOT_OCCUPIED: //store on empty slots StoreItem(ItemScript.selectedItem); ColorChangeLoop(SlotColorHighlights.Blue, ItemScript.selectedItemSize, totalOffset); ItemScript.ResetSelectedItem(); //RemoveSelectedButton(); // 리스트에 있던 애를 지워줌 break; case ONLY_ONE_OCCUPIED: //swap items ItemScript.SetSelectedItem(SwapItem(ItemScript.selectedItem)); SlotSectorScript.sectorScript.PosOffset(); ColorChangeLoop(SlotColorHighlights.Gray, otherItemSize, otherItemPos); //*1 RefreshColor(true); //RemoveSelectedButton(); break; //case DISABLE일 때에는 아무런 일도 일어나지 않는다. } }// retrieve items. 회수랄지 그리드에 이미 있는거 클릭했을 때. else if (highlightedSlot != null && ItemScript.selectedItem == null && highlightedSlot.GetComponent <SlotScript>().isOccupied == true) { ColorChangeLoop(SlotColorHighlights.Gray, highlightedSlot.GetComponent <SlotScript>().storedItemSize, highlightedSlot.GetComponent <SlotScript>().storedItemStartPos); ItemScript.SetSelectedItem(GetItem(highlightedSlot)); SlotSectorScript.sectorScript.PosOffset(); RefreshColor(true); } } } //right click to return item to list if item is from list if (Input.GetMouseButtonDown(1) && ItemScript.selectedItem != null) {/* * totalOffset = retItemOriginPos; * StoreItem(ItemScript.selectedItem); * * //RefreshColor(false); * ItemScript.ResetSelectedItem(); */ /* * invenManager.selectedButton.GetComponent<CanvasGroup>().alpha = 1f; * invenManager.selectedButton = null; * itemEquipPool.ReturnObject(ItemScript.selectedItem); */ } }
void RemoveItem(int id) { //find all slots for (int i = 0; i < inventory.Count; i++) { //if we find the item with that id if (inventory[i].itemID == id) { //when found replace item with empty item, then the slot won't disappear inventory[i] = new ItemScript(); //stop this makes sur that only one item disappears, not alle with that id break; } } }
string CreateToolTip( ItemScript item) { toolTip = item.itemName + "\n\n"+item.ItemDesc; return toolTip; }
void OnTriggerStay(Collider other) { if (other.gameObject.tag == "Hand") { if (OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) == 0 && (OVRInput.GetDown(OVRInput.Button.One))) { GetComponentInParent <Animator> ().SetBool("Pressed", !GetComponentInParent <Animator> ().GetBool("Pressed")); if (GetComponentInParent <Animator> ().GetBool("Pressed") == false) { GameObject[] Items = GameObject.FindGameObjectsWithTag("Item"); foreach (GameObject item in Items) { ItemScript itemScript = item.GetComponent <ItemScript>(); if (itemScript != null) { if (item.GetComponent <ItemScript>().InInventory) { item.transform.SetParent(transform.parent, true); item.transform.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; } } } } else if (GetComponentInParent <Animator> ().GetBool("Pressed") == true) { GameObject[] Items = GameObject.FindGameObjectsWithTag("Item"); foreach (GameObject item in Items) { ItemScript itemScript = item.GetComponent <ItemScript>(); if (itemScript != null) { if (item.GetComponent <ItemScript> ().InInventory) { item.transform.parent = null; item.transform.GetComponent <Rigidbody> ().constraints = RigidbodyConstraints.None; } } } } } if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) == 0 && (OVRInput.GetDown(OVRInput.Button.Three))) { GetComponentInParent <Animator> ().SetBool("Pressed", !GetComponentInParent <Animator> ().GetBool("Pressed")); if (GetComponentInParent <Animator> ().GetBool("Pressed") == false) { GameObject[] Items = GameObject.FindGameObjectsWithTag("Item"); foreach (GameObject item in Items) { ItemScript itemScript = item.GetComponent <ItemScript>(); if (itemScript != null) { if (item.GetComponent <ItemScript>().InInventory) { item.transform.SetParent(transform.parent, true); item.transform.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; } } } } else if (GetComponentInParent <Animator> ().GetBool("Pressed") == true) { GameObject[] Items = GameObject.FindGameObjectsWithTag("Item"); foreach (GameObject item in Items) { ItemScript itemScript = item.GetComponent <ItemScript>(); if (itemScript != null) { if (item.GetComponent <ItemScript>().InInventory) { item.transform.parent = null; item.transform.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; } } } } } } }
// Use this for initialization void Start() { invenpen = GameObject.Find ("InvenPan"); inventhin = GameObject.Find ("InventarHinweis").GetComponent<Text> (); player = GameObject.Find ("First Person Controller").GetComponent<playerController> (); qp = GameObject.Find ("QuestionPanel"); qptexts = qp.GetComponentsInChildren<Text> (); qpimages = qp.GetComponentsInChildren<Image> (); itemlog = GameObject.Find ("ItemLog").GetComponent<ItemScript> (); itemcoco = GameObject.Find ("ItemCoco").GetComponent<ItemScript> (); itemaxe = GameObject.Find ("ItemAxe").GetComponent<ItemScript> (); itemfire = GameObject.Find ("ItemFire").GetComponent<ItemScript> (); itemtent = GameObject.Find ("ItemTent").GetComponent<ItemScript> (); itemnet = GameObject.Find ("ItemNet").GetComponent<ItemScript> (); itemfish = GameObject.Find ("ItemFish").GetComponent<ItemScript> (); itemmeat = GameObject.Find ("ItemMeat").GetComponent<ItemScript> (); itemhealth = GameObject.Find ("ItemHealth").GetComponent<ItemScript> (); itemBottle = GameObject.Find ("ItemBottle").GetComponent<ItemScript> (); itemStone = GameObject.Find ("ItemStone").GetComponent<ItemScript> (); if(craftingcorrect == null) craftingcorrect = GameObject.Find("CraftingCorrect").audio; axe = GameObject.Find ("axe").GetComponent<WeaponScript> (); net = GameObject.Find ("net").GetComponent<WeaponScript> (); leftHand = ""; rightHand = ""; setInventarHinweis (""); }
public static string ItemToDictionaryKey(ItemScript item) { return(item.Name.ToLower()); }
/// <summary> /// Uses the item /// </summary> public override void Use(Slot slot, ItemScript item) { CharacterPanel.Instance.EquipItem(slot, item); }