public void OnPointerClick(PointerEventData eventData) { if (m_State != ItemState.DEFAULT) { return; } Debug.Log("click a plant"); //find local player PlayerComponent m_player = GameManagerForNetwork.Instance.LocalPlayer.GetComponent <PlayerComponent>(); PickedUpItems holdedItem = m_player.GetWhatsInHand(); if (holdedItem != null) { if (holdedItem.getItemName() == GameResources.PickedUpItemName.POOPOO && f_status == FruitStatus.noFruit) { photonView.RPC("Rpcfertilize", RpcTarget.AllBuffered); m_player.useItemInHand(); return; } } if (f_status == FruitStatus.withFruit) { //pick up fruit pickUpFruit(m_player); } else if (f_status == FruitStatus.noFruit) { pickUpPlant(m_player); } }
private void Awake() { image = GetComponent <Image>(); controller = transform.parent.parent.parent.GetComponent <PickedUpItems>(); button = GetComponent <Button>(); button.onClick.AddListener(OnClick); Selected = transform.Find("Selected").gameObject; }
public void RpcHandItemBack() { if (currentHolded != null) { currentHolded.gameObject.SetActive(false); currentHolded.m_State = PickedUpItems.ItemState.IN_BAG; currentHolded = null; } }
public void RpcDestroyHoldedItem() { if (currentHolded != null) { Debug.Log("Destroy current holded item"); Destroy(currentHolded.gameObject); currentHolded = null; } }
//Show item in hand(inactive original item's obj, active new item's obj) public void HoldItemInHand(PickedUpItems item) { if (item is Cloth) { if (currentCloth != null) { currentCloth.gameObject.SetActive(false); } item.m_State = PickedUpItems.ItemState.IN_HAND; currentCloth = (Cloth)item; currentCloth.gameObject.SetActive(true); } else { if (currentHolded != null) { currentHolded.gameObject.SetActive(false); } //if (item.m_State == PickedUpItems.ItemState.IN_BAG) //{ //hold in hand(change UI?) item.m_State = PickedUpItems.ItemState.IN_HAND; currentHolded = item; currentHolded.gameObject.SetActive(true); //Debug.Log("Hold Item: "+ item.getItemName()); //string HoldedItemID = item.getItemName().ToString(); //Debug.Log("Hold Item: Item exist."); //photonView.RPC("RpcChangeHoldItemSprite", RpcTarget.AllBuffered, HoldedItemID, m_ID); } //item.transform.SetParent(transform); if (item.getItemName() == PickedUpItemName.LIGHT_BULB || item.getItemName() == PickedUpItemName.LAMP || item.getItemName() == PickedUpItemName.LITTLE_SUN) { item.transform.SetParent(HoldedLightPosition); item.transform.localPosition = Vector3.zero; } else if (item is Cloth) { item.transform.SetParent(ClothPosition); item.transform.localPosition = Vector3.zero; //item.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); } else { item.transform.SetParent(HoldedPosition); item.transform.localPosition = Vector3.zero; //item.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); } //} }
public void OnPointerClick(PointerEventData eventData) { Debug.Log("click a placeable item"); //find local player PlayerComponent m_player = GameManagerForNetwork.Instance.LocalPlayer.GetComponent <PlayerComponent>(); PickedUpItems holdedItem = m_player.GetWhatsInHand(); //pick up a placeable if (true) { //photonView.RPC("RpcPickUpItem", RpcTarget.AllBuffered, m_player.m_ID); PickUpItem(m_player); } }
//this function run on client and for all players public bool PickedUp(PickedUpItems item) { GameResources.PickedUpItemName name = item.getItemName(); Debug.Log("Pick up " + name.ToString()); Debug.Log("Bag full: " + bagFull); //if (currentHolded != null && bagFull) //{ // Debug.Log("Oops, your bug is full! Can not pick up " + name.ToString()); // return false; //} //for self if (photonView.IsMine) { //play sound AudioManager.instance.PlaySound("pickUp"); //put in bag if (myBackpack.AddNewItem(item)) { bagFull = myBackpack.ItemSpaceLeft() <= 0; Debug.Log("Sucessfully put " + item.getItemName().ToString() + " in bag: now space left " + myBackpack.ItemSpaceLeft()); item.gameObject.SetActive(false); } else { Debug.Log("Oops, your bug is full! Can not pick up " + name.ToString()); return(false); } if (currentHolded == null) { HoldItemInHand(item); } } else { //not local player, only check hold in hand if (currentHolded == null) { HoldItemInHand(item); } } item.m_State = PickedUpItems.ItemState.IN_BAG; //item.gameObject.SetActive(false); return(true); }
// public bool AddNewItem(GameResources.PickedUpItemName newItem) // { // int weight = 1; // if (weight > this.CapacityLeft()) // { // return false; // } // int tmpCount; // if (backpack.TryGetValue(newItem, out tmpCount)) // { // backpack[newItem] = tmpCount + 1; // slotList[itemToSlotIndex[newItem]].updateItem(newItem, tmpCount + 1); // } // else // { // if (ItemSpaceLeft() == 0) // { // return false; // } // for (int i = 0; i < 12; i++) // { // if (!slotIndexToItem.ContainsKey(i)) // { // slotIndexToItem[i] = newItem; // itemToSlotIndex[newItem] = i; // slotList[i].updateItem(newItem, 1); // break; // } // } // backpack[newItem] = 1; // } // currentWeight += weight; // return true; // } public bool AddNewItem(PickedUpItems newItem) { GameResources.PickedUpItemName itemName = newItem.getItemName(); int weight = 1; if (weight > this.CapacityLeft()) { return(false); } int tmpCount; if (backpack.TryGetValue(itemName, out tmpCount)) { backpack[itemName] = tmpCount + 1; slotList[itemToSlotIndex[itemName]].updateItem(itemName, tmpCount + 1); } else { if (ItemSpaceLeft() == 0) { return(false); } for (int i = 0; i < 12; i++) { if (!slotIndexToItem.ContainsKey(i)) { slotIndexToItem[i] = itemName; itemToSlotIndex[itemName] = i; slotList[i].updateItem(itemName, 1); break; } } backpack[itemName] = 1; } instanceList.Add(newItem); currentWeight += weight; return(true); }
public bool PopItem(PickedUpItems newItem) { GameResources.PickedUpItemName itemName = newItem.getItemName(); int weight = 1; Debug.Log("POP " + itemName); int tmpCount; instanceList.Remove(newItem); if (backpack.TryGetValue(itemName, out tmpCount)) { int index = itemToSlotIndex[itemName]; if (tmpCount - 1 > 0) { backpack[itemName] = tmpCount - 1; slotList[index].updateItem(itemName, tmpCount - 1); } else { slotList[index].updateItem(GameResources.PickedUpItemName.DEFAULT, 0); backpack.Remove(itemName); slotIndexToItem.Remove(index); itemToSlotIndex.Remove(itemName); myPlayer = GameManagerForNetwork.Instance.LocalPlayer; if (myPlayer.currentHolded == newItem) { myPlayer.DestroyHoldedItem(); } } } else { return(false); } currentWeight -= weight; return(true); }
public bool PopItem(GameResources.PickedUpItemName ItemName) { PickedUpItems thisItem = null; foreach (PickedUpItems item in instanceList) { if (item.getItemName() == ItemName) { thisItem = item; } } if (thisItem == null) { Debug.LogError("Didn't find item in instance list"); return(false); } else { return(PopItem(thisItem)); } }
private void Start() { IPUP = 0; Transform Root = transform.Find("Root"); pickUpButton = Root.Find("PickUpItem").gameObject; topItemImage = Root.Find("TopItem").Find("Icon").GetComponent <Image>(); topItemText = Root.Find("TopItem").Find("Count").GetComponent <Text>(); bottomItemImage = Root.Find("BottomItem").Find("Icon").GetComponent <Image>(); bottomItemText = Root.Find("BottomItem").Find("Count").GetComponent <Text>(); shieldBut = Root.Find("Shield").Find("Icon").GetComponent <Image>(); backBut = Root.Find("Pause").Find("Icon").GetComponent <Image>(); GameOver = transform.Find("GameOver").gameObject; pause = transform.Find("Pause").gameObject; buttons.AddRange(transform.Find("Pause").GetComponentsInChildren <Game_LongButton>()); items = transform.Find("Items").GetComponent <PickedUpItems>(); puInfo = Root.Find("PickedUpInfo").GetComponent <PickedUpInfo>(); DisplayActual(); }
// compare method public List <string> CompareChanges(HubaBusSceneState other) { var result = new List <string>(); if (!AngerLevel.Equals(other.AngerLevel)) { result.Add(String.Format("AngerLevel:\t{0}\t>>>\t{1}", other.AngerLevel, AngerLevel)); } if (!askedForTicket.Equals(other.askedForTicket)) { result.Add(String.Format("askedForTicket:\t{0}\t>>>\t{1}", other.askedForTicket, askedForTicket)); } if (!getOnTheBus.Equals(other.getOnTheBus)) { result.Add(String.Format("getOnTheBus:\t{0}\t>>>\t{1}", other.getOnTheBus, getOnTheBus)); } if (!hasBusLeft.Equals(other.hasBusLeft)) { result.Add(String.Format("hasBusLeft:\t{0}\t>>>\t{1}", other.hasBusLeft, hasBusLeft)); } if (!CharPosition.Equals(other.CharPosition)) { result.Add(String.Format("CharPosition:\t{0}\t>>>\t{1}", other.CharPosition, CharPosition)); } if (!isBusWaiting.Equals(other.isBusWaiting)) { result.Add(String.Format("isBusWaiting:\t{0}\t>>>\t{1}", other.isBusWaiting, isBusWaiting)); } if (!isDelivered.Equals(other.isDelivered)) { result.Add(String.Format("isDelivered:\t{0}\t>>>\t{1}", other.isDelivered, isDelivered)); } if (!isDrunk.Equals(other.isDrunk)) { result.Add(String.Format("isDrunk:\t{0}\t>>>\t{1}", other.isDrunk, isDrunk)); } if (!isInTheBus.Equals(other.isInTheBus)) { result.Add(String.Format("isInTheBus:\t{0}\t>>>\t{1}", other.isInTheBus, isInTheBus)); } if (!isOpened.Equals(other.isOpened)) { result.Add(String.Format("isOpened:\t{0}\t>>>\t{1}", other.isOpened, isOpened)); } if (!isOutOfTheHouse.Equals(other.isOutOfTheHouse)) { result.Add(String.Format("isOutOfTheHouse:\t{0}\t>>>\t{1}", other.isOutOfTheHouse, isOutOfTheHouse)); } if (!isPaid.Equals(other.isPaid)) { result.Add(String.Format("isPaid:\t{0}\t>>>\t{1}", other.isPaid, isPaid)); } if (!PickedUpItems.Equals(other.PickedUpItems)) { result.Add(String.Format("PickedUpItems:\t{0}\t>>>\t{1}", other.PickedUpItems, PickedUpItems)); } if (!UsedItems.Equals(other.UsedItems)) { result.Add(String.Format("UsedItems:\t{0}\t>>>\t{1}", other.UsedItems, UsedItems)); } return(result); }
// compare method public List <string> CompareChanges(AnnanaTeaPartySceneState other) { var result = new List <string>(); if (!DrankTea.Equals(other.DrankTea)) { result.Add(String.Format("DrankTea:\t{0}\t>>>\t{1}", other.DrankTea, DrankTea)); } if (!InTheKitchen.Equals(other.InTheKitchen)) { result.Add(String.Format("InTheKitchen:\t{0}\t>>>\t{1}", other.InTheKitchen, InTheKitchen)); } if (!IsHappy.Equals(other.IsHappy)) { result.Add(String.Format("IsHappy:\t{0}\t>>>\t{1}", other.IsHappy, IsHappy)); } if (!IsInside.Equals(other.IsInside)) { result.Add(String.Format("IsInside:\t{0}\t>>>\t{1}", other.IsInside, IsInside)); } if (!IsLockOpen.Equals(other.IsLockOpen)) { result.Add(String.Format("IsLockOpen:\t{0}\t>>>\t{1}", other.IsLockOpen, IsLockOpen)); } if (!IsOutside.Equals(other.IsOutside)) { result.Add(String.Format("IsOutside:\t{0}\t>>>\t{1}", other.IsOutside, IsOutside)); } if (!IsReadingTheFine.Equals(other.IsReadingTheFine)) { result.Add(String.Format("IsReadingTheFine:\t{0}\t>>>\t{1}", other.IsReadingTheFine, IsReadingTheFine)); } if (!OwlFlownAway.Equals(other.OwlFlownAway)) { result.Add(String.Format("OwlFlownAway:\t{0}\t>>>\t{1}", other.OwlFlownAway, OwlFlownAway)); } if (!PickedUpItems.Equals(other.PickedUpItems)) { result.Add(String.Format("PickedUpItems:\t{0}\t>>>\t{1}", other.PickedUpItems, PickedUpItems)); } if (!TeaBagInTheCup.Equals(other.TeaBagInTheCup)) { result.Add(String.Format("TeaBagInTheCup:\t{0}\t>>>\t{1}", other.TeaBagInTheCup, TeaBagInTheCup)); } if (!TeapotOnTheStove.Equals(other.TeapotOnTheStove)) { result.Add(String.Format("TeapotOnTheStove:\t{0}\t>>>\t{1}", other.TeapotOnTheStove, TeapotOnTheStove)); } if (!TeapotOnTheTable.Equals(other.TeapotOnTheTable)) { result.Add(String.Format("TeapotOnTheTable:\t{0}\t>>>\t{1}", other.TeapotOnTheTable, TeapotOnTheTable)); } if (!ThrewCup.Equals(other.ThrewCup)) { result.Add(String.Format("ThrewCup:\t{0}\t>>>\t{1}", other.ThrewCup, ThrewCup)); } if (!TookTheFine.Equals(other.TookTheFine)) { result.Add(String.Format("TookTheFine:\t{0}\t>>>\t{1}", other.TookTheFine, TookTheFine)); } if (!UsedItems.Equals(other.UsedItems)) { result.Add(String.Format("UsedItems:\t{0}\t>>>\t{1}", other.UsedItems, UsedItems)); } if (!WaterInTheCup.Equals(other.WaterInTheCup)) { result.Add(String.Format("WaterInTheCup:\t{0}\t>>>\t{1}", other.WaterInTheCup, WaterInTheCup)); } return(result); }
// compare method public List <string> CompareChanges(HubaForestSceneState other) { var result = new List <string>(); if (!AngerLevel.Equals(other.AngerLevel)) { result.Add(String.Format("AngerLevel:\t{0}\t>>>\t{1}", other.AngerLevel, AngerLevel)); } if (!CurrentForestWay.Equals(other.CurrentForestWay)) { result.Add(String.Format("CurrentForestWay:\t{0}\t>>>\t{1}", other.CurrentForestWay, CurrentForestWay)); } if (!CharPosition.Equals(other.CharPosition)) { result.Add(String.Format("CharPosition:\t{0}\t>>>\t{1}", other.CharPosition, CharPosition)); } if (!IsHubaBlessed.Equals(other.IsHubaBlessed)) { result.Add(String.Format("IsHubaBlessed:\t{0}\t>>>\t{1}", other.IsHubaBlessed, IsHubaBlessed)); } if (!IsInForest.Equals(other.IsInForest)) { result.Add(String.Format("IsInForest:\t{0}\t>>>\t{1}", other.IsInForest, IsInForest)); } if (!IsOnSite.Equals(other.IsOnSite)) { result.Add(String.Format("IsOnSite:\t{0}\t>>>\t{1}", other.IsOnSite, IsOnSite)); } if (!IsReadingMap.Equals(other.IsReadingMap)) { result.Add(String.Format("IsReadingMap:\t{0}\t>>>\t{1}", other.IsReadingMap, IsReadingMap)); } if (!IsSceneStarted.Equals(other.IsSceneStarted)) { result.Add(String.Format("IsSceneStarted:\t{0}\t>>>\t{1}", other.IsSceneStarted, IsSceneStarted)); } if (!PickedUpItems.Equals(other.PickedUpItems)) { result.Add(String.Format("PickedUpItems:\t{0}\t>>>\t{1}", other.PickedUpItems, PickedUpItems)); } if (!RightForestWay.Equals(other.RightForestWay)) { result.Add(String.Format("RightForestWay:\t{0}\t>>>\t{1}", other.RightForestWay, RightForestWay)); } if (!UsedItems.Equals(other.UsedItems)) { result.Add(String.Format("UsedItems:\t{0}\t>>>\t{1}", other.UsedItems, UsedItems)); } return(result); }