void DropBag(Tile _tile, ItemList.ItemType itemType = ItemList.ItemType.None, int itemAmount = 0, bool destroyTile = true, bool setBackground = false) { if (itemType == ItemList.ItemType.None) { if (destroyTile) { SetOtherTiles(_tile); _tile.DelayedSetBlockSides(); _tile.DestroyThisTile(); } if (setBackground) { _tile.ChangeToBackground(); } return; } else { GameObject instBag = Instantiate(_tile.genChunkScript.tilePrefabs.droppedBagPrefab, new Vector3(_tile.gameObject.transform.position.x, _tile.gameObject.transform.position.y, _tile.gameObject.transform.position.z), Quaternion.identity); instBag.GetComponent <ItemDropped>().ItemAmount = itemAmount; instBag.GetComponent <ItemDropped>().itemType = itemType; if (destroyTile) { SetOtherTiles(_tile); _tile.DelayedSetBlockSides(); _tile.DestroyThisTile(); } if (setBackground) { _tile.ChangeToBackground(); } } }
public bool CheckIfItemIsBlock(ItemList.ItemType _item) { if (_item == ItemList.ItemType.Log) { return(true); } if (_item == ItemList.ItemType.Workbench) { return(true); } if (_item == ItemList.ItemType.WoodenPlanks) { return(true); } return(false); }
public GameObject ReturnItemTilePrefab(TilePrefabs _tilePref, ItemList.ItemType _item) { if (_item == ItemList.ItemType.Log) { return(_tilePref.trunkTile[0]); } if (_item == ItemList.ItemType.Workbench) { return(_tilePref.workbench); } if (_item == ItemList.ItemType.WoodenPlanks) { return(_tilePref.woodPlankTile); } return(null); }
public void Create(ItemList item) { itemNameText.text = item.ItemName; //ItemIconに画像をセットする。 this.gameObject.transform.GetChild(0).GetComponent <Image>().sprite = item.itemIcon; ItemName = item.ItemName; itemID = item.itemID; itemDesc = item.itemDesc; itemDefense = item.itemDefense; itemAttackSpeed = item.itemAttackSpeed; itemPower = item.itemPower; itemIcon = item.itemIcon; itemLifeInCrease = item.itemHPInCrease; itemLifeSteal = item.itemLifeSteal; etype = item.elementtype; ItemType = item.itemType; itemIcon = item.itemIcon; }
public void EnterCommand(string _cmd) { inputField.text = ""; if (_cmd.StartsWith("/")) { if (_cmd.ToLower().StartsWith("/help")) { consoleHistory.text = consoleHistory.text + "\n[" + System.DateTime.Now.ToLocalTime() + "] Commands: \n /give [itemID] [itemAmount]"; } if (_cmd.ToLower().StartsWith("/give")) { string[] cmd = _cmd.Split(" "[0]); if (cmd.Length == 3) { GameManagerGO = GameObject.FindGameObjectWithTag("GM"); HotbarGO = GameObject.FindGameObjectWithTag("Hotbar"); if (int.Parse(cmd[1]) >= GameManagerGO.GetComponent <ItemIconPrefabs>().itemIcons.Length || int.Parse(cmd[1]) == 0) { consoleHistory.text = consoleHistory.text + "\n[" + System.DateTime.Now.ToLocalTime() + "] No Such Item ID Found"; return; } Debug.Log(int.Parse(cmd[1])); ItemList.ItemType _item = GameManagerGO.GetComponent <ItemIconPrefabs>().TurnINTIntoItemType(int.Parse(cmd[1])); HotbarGO.GetComponent <Inventory>().AddItem(_item, int.Parse(cmd[2])); consoleHistory.text = consoleHistory.text + "\n[" + System.DateTime.Now.ToLocalTime() + "] Gave Player " + cmd[2] + " " + _item.ToString() + "'s"; } else { consoleHistory.text = consoleHistory.text + "\n[" + System.DateTime.Now.ToLocalTime() + "] Incorrect Usage, Use /give [itemID] [itemAmount]"; } } } else { consoleHistory.text = consoleHistory.text + "\n[" + System.DateTime.Now.ToLocalTime() + "] Command not found, type /help for a list of commmands"; } }
void SelectSlot(int _slotID) { if (inventory.slots.Count == 9) { slotSelected = _slotID; DisableSlotAllImages(); EnableSelectedSlotImage(_slotID); if (inventory.slots[_slotID - 1].item.noItem) { selectedItem = ItemList.ItemType.None; selectedItemScript = null; return; } else { selectedItem = inventory.slots[_slotID - 1].item.item; selectedItemScript = inventory.slots[_slotID - 1].item; } } else { StartCoroutine(wait2(_slotID)); } }
public int TurnItemTypeIntoINT(ItemList.ItemType _itemType) { int toInteger = (int)_itemType; return(toInteger); }
public ItemList.ItemType TurnINTIntoItemType(int _int) { ItemList.ItemType _item = (ItemList.ItemType)_int; return(_item); }
public void SceneLoaded(Scene scene, LoadSceneMode sceneMode) { GameObject ObjectGames_prefab = Instantiate(ObjectGames); GameObject Player = GameObject.FindGameObjectWithTag("Player"); GameObject GameManager = GameObject.FindGameObjectWithTag("GameController"); GameManagerScript GameManagerScript = GameManager.GetComponent <GameManagerScript>(); GameObject ItemController = GameObject.FindWithTag("ItemController"); ItemDatabase item_database = ItemController.GetComponent <ItemDatabase>(); PlayerStatus PlayerStatus = Player.GetComponent <PlayerStatus>(); GearManagerScript gear_manager_script = ItemController.GetComponent <GearManagerScript>(); GearsSetScript gears_set_script = ItemController.GetComponent <GearsSetScript>(); var continue_load_status = PlayerPrefsObject.GetObject <Status>("Status"); var continue_load_object_save = PlayerPrefsObject.GetObject <ObjectSave>("objectSave"); var continue_load_item_save = PlayerPrefsObject.GetObject <ItemSave>("ItemSave"); var continue_load_gear_save = PlayerPrefsObject.GetObject <GearSave>("GearSave"); var continue_load_gear_status_save = PlayerPrefsObject.GetObject <GearStatusSave>("GearStatusSave"); var continue_load_status_json = JsonUtility.ToJson(continue_load_status).ToString(); var continue_load_object_save_json = JsonUtility.ToJson(continue_load_object_save).ToString(); var continue_load_item_save_json = JsonUtility.ToJson(continue_load_item_save).ToString(); var continue_load_gear_save_json = JsonUtility.ToJson(continue_load_gear_save).ToString(); var continue_load_gear_status_save_json = JsonUtility.ToJson(continue_load_gear_status_save).ToString(); //jsonにしてデータ取り出しできるようにする var continue_load_status_json_taking_out = JsonUtility.FromJson <Status>(continue_load_status_json); var continue_load_object_save_json_taking_out = JsonUtility.FromJson <ObjectSave>(continue_load_object_save_json); var continue_load_item_save_json_taking_out = JsonUtility.FromJson <ItemSave>(continue_load_item_save_json); var continue_load_gear_save_json_taking_out = JsonUtility.FromJson <GearSave>(continue_load_gear_save_json); var continue_load_gear_status_save_json_taking_out = JsonUtility.FromJson <GearStatusSave>(continue_load_gear_status_save_json); //保存したデータをGameManagerに代入 GameManagerScript.SceneHistroy = continue_load_object_save_json_taking_out.SceneHistroy; GameManagerScript.SceneName = continue_load_object_save_json_taking_out.SceneName; GameManagerScript.wanna_destroy_enemy = continue_load_object_save_json_taking_out.WannnaDestroyEnemy; GameManagerScript.SceneNameBefore = continue_load_object_save_json_taking_out.SceneNameBefore; //保存したデータをItemDatabase(ItemController)に代入(削除したいアイテムのID名などの保管庫) item_database.wanna_destroy_item_id = continue_load_object_save_json_taking_out.WannaDestroyItem; //保存したデータをItemControllerに代入 for (int i = 0; i < continue_load_item_save_json_taking_out.ItemCount; i++) { string Name = continue_load_item_save_json_taking_out.Name[i]; float speed = continue_load_item_save_json_taking_out.speed[i]; Sprite sprite = continue_load_item_save_json_taking_out.sprite[i]; float HPIncrease = continue_load_item_save_json_taking_out.HPIncrease[i]; string ID = continue_load_item_save_json_taking_out.ID[i]; float Attack = continue_load_item_save_json_taking_out.Attack[i]; float Defense = continue_load_item_save_json_taking_out.Defense[i]; float LifeSteal = continue_load_item_save_json_taking_out.LifeSteal[i]; string Description = continue_load_item_save_json_taking_out.Description[i]; ItemList.ItemType itemType = continue_load_item_save_json_taking_out.iType[i]; ItemList.elementType elemenType = continue_load_item_save_json_taking_out.eType[i]; //float speed = continue_load_item_save_json_taking_out. //ここでまずはアイテムステータスを作っていくよ。 itemsLoad.Add(new ItemList(name: Name, id: ID, power: Attack, desc: Description, def: Defense, speed: speed, ls: LifeSteal, etype: elemenType, type: itemType, sprite: sprite, itemHPIncre: HPIncrease)); } //上で作成したListを入れていく— item_database.items = itemsLoad; //GearManagerScriptに代入。(装備管理スクリプト) gear_manager_script.weaponID = continue_load_gear_save_json_taking_out.weaponID; gear_manager_script.weaponName = continue_load_gear_save_json_taking_out.weaponName; gear_manager_script.weaponPower = continue_load_gear_save_json_taking_out.weaponPower; gear_manager_script.WeaponAttackSpeed = continue_load_gear_save_json_taking_out.WeaponAttackSpeed; gear_manager_script.GearID = continue_load_gear_save_json_taking_out.GearID; gear_manager_script.GearDefense = continue_load_gear_save_json_taking_out.GearDefense; gear_manager_script.GearName = continue_load_gear_save_json_taking_out.GearName; gear_manager_script.GearHead = continue_load_gear_save_json_taking_out.GearHead; gear_manager_script.GearBody = continue_load_gear_save_json_taking_out.GearBody; gear_manager_script.GearLeg = continue_load_gear_save_json_taking_out.GearLeg; gear_manager_script.GearArmRight = continue_load_gear_save_json_taking_out.GearArmRight; gear_manager_script.GearArmLeft = continue_load_gear_save_json_taking_out.GearArmLeft; for (int i = 0; i < continue_load_gear_status_save_json_taking_out.GearID.Count; i++) { gears_set_script.Head.Add(continue_load_gear_status_save_json_taking_out.GearHead[i]); gears_set_script.Body.Add(continue_load_gear_status_save_json_taking_out.GearBody[i]); gears_set_script.Leg.Add(continue_load_gear_status_save_json_taking_out.GearLeg[i]); gears_set_script.ArmsLeft.Add(continue_load_gear_status_save_json_taking_out.GearArmLeft[i]); gears_set_script.ArmsRight.Add(continue_load_gear_status_save_json_taking_out.GearArmRight[i]); gears_set_script.GearDefense.Add(continue_load_gear_status_save_json_taking_out.GearDefense[i]); gears_set_script.GearID.Add(continue_load_gear_status_save_json_taking_out.GearID[i]); gears_set_script.GearName.Add(continue_load_gear_status_save_json_taking_out.GearName[i]); } //保存したデータをPlayerStautsに代入 PlayerStatus.HP = continue_load_status_json_taking_out.HP; PlayerStatus.Defense = continue_load_status_json_taking_out.Defense; PlayerStatus.Attack = continue_load_status_json_taking_out.Attack; PlayerStatus.position = continue_load_status_json_taking_out.position; PlayerStatus.gameObject.transform.position = continue_load_status_json_taking_out.position; SceneManager.sceneLoaded -= SceneLoaded; }
public void ItemAdd(int HPIn, int MPIn, string item_name, string name, int id, string desc, int power, int def, int speed, int ls, ItemList.ElementType etype, ItemList.ItemType type, Sprite image) { if (currentPage < 1 && items.Count < max_count) { items.Add(new ItemList(HPIn, MPIn, item_name, name, id, desc, power, def, speed, ls, etype, type, image)); ItemPrefabCreate(); //itemPrefab.transform.GetChild(1).GetComponent<Text>().text = items[items.Count - 1].itemName; } }
public void ItemAdd(string name, string id, string desc, float power, float def, float speed, float ls, float itemHPInCrease, ItemList.elementType etype, ItemList.ItemType type, Sprite sprite) { items.Add(new ItemList(name, id, desc, power, def, speed, ls, itemHPInCrease, etype, type, sprite)); itemName.Add(name); }
void Update() { if (tempPlaceHolder != null) { Destroy(tempPlaceHolder); } selectedItem = hotbar.selectedItem; selectedItemScript = hotbar.selectedItemScript; if (selectedItemScript == null) { return; } if (gameManagerGO.GetComponent <CheckItems>().CheckIfItemIsBlock(selectedItem) == true) { Vector3 pz = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3 snappedV3 = new Vector3(Mathf.Round(pz.x / gridSize), Mathf.Round(pz.y / gridSize), pz.z) * gridSize; snappedV3.z = 20; if (Vector3.Distance(GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>().position, snappedV3) < maxBreakDistance) { tempPlaceHolder = Instantiate(gameManagerGO.GetComponent <CheckItems>().ReturnItemTilePrefab(gameManagerGO.GetComponent <TilePrefabs>(), selectedItem), snappedV3, Quaternion.identity); tempPlaceHolder.GetComponent <BoxCollider2D>().isTrigger = true; if (Input.GetKeyDown(KeyCode.Mouse1)) { Debug.Log("Mouse1"); RaycastHit2D hit4; Vector3 rayOrigin4 = tempPlaceHolder.gameObject.transform.position; hit4 = Physics2D.Raycast(rayOrigin4, Vector3.down, 1); if (hit4.collider == null || hit4.collider.tag == "Player") { Debug.Log("a"); return; } else { if (hit4.collider.transform.gameObject.GetComponent <Tile>().isupTileNull == true && hit4.collider.isTrigger == false) { Debug.Log("l"); lastTile = gameManagerGO.GetComponent <ChunkManager>().chunks[hit4.collider.transform.gameObject.GetComponent <Tile>().genChunkScript.chunkID].GetComponent <GenerateChunk>().SpawnTile2(hit4.collider.transform.gameObject.GetComponent <Tile>().x - 1, hit4.collider.transform.gameObject.GetComponent <Tile>().y, gameManagerGO.GetComponent <CheckItems>().ReturnItemTilePrefab(gameManagerGO.GetComponent <TilePrefabs>(), selectedItem)); lastTile.GetComponent <Tile>().manMade = true; Destroy(tempPlaceHolder); return; } else { Debug.Log("b"); return; } } } } else { return; } } else { if (tempPlaceHolder != null) { Destroy(tempPlaceHolder); } } }
public void AddItem(ItemList.ItemType _itemType, int amt) { ItemAmount = ItemAmount + amt; return; }
// Update is called once per frame public void AddItem(ItemList.ItemType _item, int numItem) { int _numItem = numItem; if (slots.Count == maxSlots) { if (slots[maxSlots - 1].item == null) { StartCoroutine(wait(_item, _numItem)); } else { //All slots are spawned foreach (Slot _slot in slots) { if (_numItem == 0) { return; } if (_slot.item.item == _item || _slot.item.noItem == true) { if (_slot.item.item == _item) { //Debug.Log("_numItem =" + _numItem + "For starting with slot" + _slot.slotID); //Debug.Log("-1"); //4 already 16 stacksize we wanted to add 14 //4+14-16 if (_slot.item.MaxStackSize > (_slot.item.StackSize + _numItem)) { //Debug.Log("0"); _slot.item.item = _item; _slot.item.StackSize = _slot.item.StackSize + _numItem; _slot.item.noItem = false; _numItem = 0; if (isHotbar) { hotbar.UpdateHotbar(); return; } return; } else { // Debug.Log("1"); _slot.item.item = _item; _slot.item.noItem = false; _numItem = (_slot.item.StackSize + _numItem) - _slot.item.MaxStackSize; _slot.item.StackSize = _slot.item.MaxStackSize; if (isHotbar) { hotbar.UpdateHotbar(); } } } if (_slot.item.noItem == true) { // Debug.Log("2"); //Debug.Log("Max Stack Size:" + _slot.item.MaxStackSize + "Num Items:" + _numItem); if (_slot.item.MaxStackSize > _numItem) { //Max stack size or 16 is greater then the number of items we want to add so therefore we don't need to go to the next slot //Debug.Log("3"); _slot.item.item = _item; _slot.item.StackSize = _numItem; _slot.item.noItem = false; _numItem = 0; if (isHotbar) { hotbar.UpdateHotbar(); return; } return; } else { //Debug.Log("4"); _slot.item.item = _item; _slot.item.noItem = false; _numItem = (_slot.item.StackSize + _numItem) - _slot.item.MaxStackSize; _slot.item.StackSize = _slot.item.MaxStackSize; //Debug.Log("Set _numItem To:" + _numItem + "For slot" + _slot.slotID); if (isHotbar) { hotbar.UpdateHotbar(); } } } } else { if (_slot.slotID == 9) { return; } } } if (isHotbar) { hotbar.UpdateHotbar(); } } } else { StartCoroutine(wait(_item, _numItem)); } }
IEnumerator wait(ItemList.ItemType _item, int numItem) { yield return(new WaitForSeconds(1)); AddItem(_item, numItem); }