private bool PlaceEmpty(csItem item, int amount) { if (emptySlots > 0) { Debug.Log("빈공간잇음"); for (int i = 0; i < MySlots.Count; i++) { csSlotStorage tmp = MySlots[i]; if (tmp.IsEmpty) { Debug.Log("빈공간 인덱스 : " + i); tmp.AddItem(item); for (int j = 0; j < amount - 1 && tmp.IsAvailable; j++) { tmp.AddItem(item); } emptySlots--; Debug.Log("빈공간 : " + emptySlots); SqlQurey(i, tmp.Items.Peek().itemCode, tmp.Items.Count); return(true); } } } return(false); }
void Start() { items = new Stack <csItem>(); mRoot = NGUITools.FindInParents <UIRoot>(transform.parent); manager = GameObject.Find("Backpack").GetComponent <csInventory>(); Front_Leg = GameObject.Find("FrontLeg").GetComponent <csSlotStorage>(); Back_Leg = GameObject.Find("BackLeg").GetComponent <csSlotStorage>(); selectedItem = GameObject.Find("SelectedItem").GetComponent <csSeletedItem>(); shop = GameObject.Find("Shop"); Factory = GameObject.Find("Factory"); }
public bool AddItem(csItem item, int amount) { if (item.itemMaxAmount == 1) { PlaceEmpty(item, 1); return(true); } else { for (int i = 0; i < MySlots.Count; i++) { csSlotStorage tmp = MySlots[i]; if (!tmp.IsEmpty) { if (tmp.CurrentItem.itemID == item.itemID && tmp.IsAvailable) { for (int j = 0; j < amount && tmp.IsAvailable; j++) { tmp.AddItem(item); } SqlQurey(i, tmp.Items.Peek().itemCode, tmp.Items.Count); return(true); } } } Debug.Log(emptySlots); // 슬롯에 맞는 아이템이 없는경우 if (emptySlots > 0) { Debug.Log("슬롯에 맞는게 없다"); PlaceEmpty(item, amount); return(true); } } return(false); }
void OnDrop(GameObject dropped) { Debug.Log("빈빈" + manager.emptySlots); bool isInvenToInven = true; bool isEquip = false; string FromItemCode = null; int FromIndex = -1; int FromItemCount = -1; int ToIndex = -1; csSlotStorage tmpslot = dropped.GetComponent <csSlotStorage>(); if (tmpslot == null || tmpslot.Items.Count == 0) { return; } if (tmpslot.slotType == csItem.ItemType.Sell) { return; } // 파는곳에 두면 if (slotType == csItem.ItemType.Sell) { csSlotStorage slot = dropped.GetComponent <csSlotStorage>(); if (slot == null || slot.Items.Count == 0) { return; } Stack <csItem> tmp = new Stack <csItem>(this.Items); this.AddAllItem(slot.Items); if (tmp.Count == 0) { slot.ClearSlot(); manager.emptySlots++; } else { slot.AddAllItem(tmp); } int price = 0; string FromCode = ""; int FromCount = 0; if (slot.Items.Count != 0) { FromCode = slot.Items.Peek().itemCode; FromCount = slot.Items.Count; } else { FromCode = ""; } Debug.Log(price + "팔꺼야"); price = Items.Peek().sell_Price *Items.Count; sellPrice.text = price.ToString(); SqlQurey(1, 4, slot.index, FromCode, FromCount, true); } // 아니면 else { //인벤에 놨을때 if (slotType == csItem.ItemType.None) { Debug.Log("인벤에 놨다"); csSlotStorage slot = dropped.GetComponent <csSlotStorage>(); if (slot == null || slot.Items.Count == 0) { return; } csItem item = slot.items.Peek(); bool isReturn = false; if (items.Count != 0) { Debug.Log("놓은곳이 빈곳이 아니다 리턴하자"); isReturn = true; if (items.Peek().itemType == item.itemType && items.Peek().legCount == item.legCount) { Debug.Log("리턴할라했는데 종류와 다리수가 같은거 였다 리턴 ㄴㄴ"); isReturn = false; } else { Debug.Log("종류가다르거나 다리수가 틀리다"); } } // 인벤에서 인벤은 리턴안함 if (slot.slotType == csItem.ItemType.None) { isReturn = false; } if (isReturn) { Debug.Log("리턴"); return; } // 내거 백업 Stack <csItem> tmp = new Stack <csItem>(this.Items); this.AddAllItem(slot.Items); // 놓은곳이 빈공간이면 if (tmp.Count == 0) { Debug.Log("빈 인벤에 놨다"); //장비에서 인벤에 놨으면 if (slot.slotType != csItem.ItemType.None) { isInvenToInven = false; manager.emptySlots--; Debug.Log("장비창에서 인벤에 놨다"); if (slot.slotType == csItem.ItemType.Head) { FromIndex = 0; Debug.Log("머리에서 가져왔음"); } else if (slot.slotType == csItem.ItemType.Tail) { FromIndex = 1; Debug.Log("꼬리에서 가져왔음"); } else if (slot.slotType == csItem.ItemType.Front_Leg) { Debug.Log("앞다리에서 가져왔음"); if (slot.items.Peek().legCount == 2) { Debug.Log("가져온 아이템이 2족이였다 뒷다리 x표시 지우자"); Back_Leg.sprite.spriteName = ""; } FromIndex = 2; } else if (slot.slotType == csItem.ItemType.Back_Leg) { Debug.Log("뒷다리에서 가져왔음"); if (slot.items.Peek().legCount == 2) { Debug.Log("가져온 아이템이 2족이였다 앞다리 x표시 지우자"); Front_Leg.sprite.spriteName = ""; } FromIndex = 3; } ToIndex = index; Debug.Log("제거만하는 조립"); manager.Assembly(item, 1); } // 인벤에서 인벤 else { Debug.Log("인벤에서 인벤으로 옮겼다"); FromIndex = slot.index; ToIndex = index; } slot.ClearSlot(); } else { Debug.Log("놓은 곳이 빈공간이 아니다"); slot.AddAllItem(tmp); if (slot.slotType != csItem.ItemType.None) { Debug.Log("장비에서 가져왔다"); Debug.Log("장비에서 인벤으로 가져왔을떄 조립"); manager.Assembly(slot.items.Peek(), 0); } else { Debug.Log("인벤에서 가져옴"); FromIndex = slot.index; ToIndex = index; } } if (slot.items.Count > 0) { FromItemCode = slot.items.Peek().itemCode; } FromItemCount = slot.items.Count; } //장비창에 놨을때 else { Debug.Log("장비창에 놨다"); csSlotStorage slot = dropped.GetComponent <csSlotStorage>(); if (slot == null || slot.Items.Count == 0) { return; } csItem item = slot.items.Peek(); //다리 옮길때 if (item.itemType == csItem.ItemType.Front_Leg || item.itemType == csItem.ItemType.Back_Leg) { Debug.Log("앞다리거나 뒷다리를 가져왔다"); bool isReturn = true; // 2족다리 옮길때 if (item.legCount == 2) { Debug.Log("2족다리를 가져왔다"); // 앞다리에 놨을때 if (slotType == csItem.ItemType.Front_Leg) { Debug.Log("앞다리장비창에 놨다"); //뒷다리 비어있으면 가능 if (Back_Leg.items.Count == 0) { Debug.Log("뒷다리가 비어있다 가져온 2족다리를 놓을수 있다 뒷다리에 x표시"); isReturn = false; Back_Leg.sprite.spriteName = "X"; } else { Debug.Log("뒷다리에 뭔가 장착되어있다"); } } // 뒷다리에 놨을때 if (slotType == csItem.ItemType.Back_Leg) { Debug.Log("뒷다리장비창에 놨다"); // 앞다리 비어있으면 가능 if (Front_Leg.items.Count == 0) { Debug.Log("앞다리가 비어있다"); if (Items.Count == 0) { Debug.Log("뒷다리칸이 비어있어서 놓을수 있다 "); isReturn = false; Front_Leg.sprite.spriteName = "X"; } else { Debug.Log("뒷다리칸에 무언가 장착되어있다"); if (CurrentItem.legCount == item.legCount) { Debug.Log("같은 2족이 뒷다리칸에 장착되어있어 교체가능하다"); isReturn = false; Front_Leg.sprite.spriteName = "X"; } else { Debug.Log("뒷다리에 장착되어 있는 것이 2족이 아니다"); } } } } } // 4족다리 옮길때 else if (item.legCount == 4) { Debug.Log("4족다리를 가져왔다"); // 앞다리에 놨을때 if (slotType == csItem.ItemType.Front_Leg) { Debug.Log("앞다리장비창에 놨다"); if (Back_Leg.items.Count != 0) { Debug.Log("뒷다리에 뭔가가 장착되어있다"); if (Back_Leg.items.Peek().legCount == 4) { Debug.Log("뒷다리에 4족이 껴져있었다"); if (item.itemType == slotType) { Debug.Log("가져온아이템이 앞다리가 맞다"); isReturn = false; } else { Debug.Log("가져온아이템이 앞다리가 아니다"); } } else { Debug.Log("뒷다리에 4족다리가 아닌것이 장착되어 있다"); } } else { Debug.Log("뒷다리가 비어있다"); if (item.itemType == slotType) { if (Items.Count == 0) { Debug.Log("뒷다리와 앞다리가 비어있어서 놓을수 있다"); isReturn = false; } else { Debug.Log("앞다리에 뭔가가 장착되어있다"); if (item.legCount == CurrentItem.legCount) { Debug.Log("가져온아이템이 앞다리가 맞고 다리수도 같다"); isReturn = false; } } } else { Debug.Log("뒷다리가 비어있지만 가져온아이템이 뒷다리가 아니다"); } } } // 뒷다리에 놨을때 else if (slotType == csItem.ItemType.Back_Leg) { Debug.Log("뒷다리장비창에 놨다"); if (Front_Leg.items.Count != 0) { Debug.Log("앞다리에 뭔가가 장착되어있다"); if (Front_Leg.items.Peek().legCount == 4) { Debug.Log("앞다리에 4족다리가 껴져있었다"); if (item.itemType == slotType) { Debug.Log("가져온 아이템이 뒷다리가 맞다"); isReturn = false; } else { Debug.Log("가져온 아이템이 뒷다리가 아니다"); } } else { Debug.Log("뒷다리에 4족다리가 아닌것이 장착되어있다"); } } else { Debug.Log("앞다리가 비어 있다"); if (item.itemType == slotType) { if (Items.Count == 0) { Debug.Log("뒷다리 장비칸이 비어있다"); isReturn = false; } else { Debug.Log("뒷다리에 무언가 껴져있다"); if (item.legCount == CurrentItem.legCount) { Debug.Log("가져온아이템이 뒷다리가 맞고 다리수도 같다"); isReturn = false; } } } else { Debug.Log("앞다리가 비어있지만 가져온 아이템이 뒷다리가 아니다"); } } } } if (isReturn) { Debug.Log("리턴"); return; } } // 나머지 옮길때 else { Debug.Log("다리가 아닌 아이템을 옮기고 있다"); if (item.itemType != slotType) { Debug.Log("가져온아이템과 놓은곳이 틀리다 리턴"); return; } else { Debug.Log("가져온아이템고 놓은곳이 맞다"); } } //장비창 Stack <csItem> tmp = new Stack <csItem>(this.Items); this.AddAllItem(slot.Items); //인벤에서 장비에 놨으면 if (tmp.Count == 0) { slot.ClearSlot(); manager.emptySlots++; } else { slot.AddAllItem(tmp); } manager.Assembly(item, 0); Debug.Log("생성도하는 조립"); if (slot.items.Count > 0) { FromItemCode = slot.items.Peek().itemCode; } FromItemCount = slot.items.Count; FromIndex = (int)slotType - 1; // 장비창인덱스 ToIndex = slot.index; // 인벤인덱스 isInvenToInven = false; isEquip = true; } Debug.Log("옮기기 성공"); //인벤에서 인벤 if (isInvenToInven) { SqlQurey(0, FromIndex, ToIndex, FromItemCode, FromItemCount, isEquip); } else { SqlQurey(1, FromIndex, ToIndex, FromItemCode, FromItemCount, isEquip); } } }
void Start() { items = new Stack<csItem>(); mRoot = NGUITools.FindInParents<UIRoot>(transform.parent); manager = GameObject.Find("Backpack").GetComponent<csInventory>(); Front_Leg = GameObject.Find("FrontLeg").GetComponent<csSlotStorage>(); Back_Leg = GameObject.Find("BackLeg").GetComponent<csSlotStorage>(); selectedItem = GameObject.Find("SelectedItem").GetComponent<csSeletedItem>(); shop = GameObject.Find("Shop"); Factory = GameObject.Find("Factory"); }