public void Craft_Microwave(MicrowaveController microwave, Item hand, CraftType craftType, CraftTable craftTable) { if (microwave.isOpen && microwave.itemInside) { microwave.Close(); } else if (!microwave.isOpen && microwave.itemInside) { StartCoroutine(microwave.Work()); ItemCraftData recept = FindRecept(hand, microwave.itemInside, craftType, craftTable); if (recept == null) { Debug.Log("no recept"); return; } Item craftResult = recept.recept.craftResult; Debug.Log(craftResult.itemName); microwave.itemInside = craftResult; AddExpReward(recept); } }
public void Craft_Hands(GameObject itemInHand, GameObject toolGO) { Item tool = toolGO.GetComponent <ItemCell>().item; Item item = itemInHand.GetComponent <ItemCell>().item; //// если активная рука пустая и айтес имеет функционал для открытия окна //if (item.itemOptionData.actionWindowTag != string.Empty && controller.IsEmpty(toolGO.GetComponent<Button>())) //{ // string tagWithPrefix = item.itemOptionData.actionWindowTag + "Hand"; // ActionWindowController actionWindow = Global.Component.GetActionWindowController(); // actionWindow.OpenActionWindow(tagWithPrefix); // actionWindow.InitActioWindow(tagWithPrefix, null, item, null); //} ItemCraftData recept = FindRecept(tool, item, CraftType.Cooking, CraftTable.Hands); if (recept == null) { Debug.Log("no recept"); return; } Item craftResult = Instantiate(recept.recept.craftResult); // для передачи таков между айтемами (оригинальным и результатом) if (item.itemTimeflowModify.ticsTransition == true) { craftResult.itemTimeflowModify.tics = item.itemTimeflowModify.tics; } craftResult.itemEffect.currentCell = itemInHand.GetComponent <Button>(); itemInHand.GetComponent <ItemCell>().item = craftResult; itemInHand.GetComponent <Image>().sprite = craftResult.itemSprite; }
void AddExpReward(ItemCraftData itemCraftData) { CraftType craftType = itemCraftData.craftType; float exp = itemCraftData.expReward; if (craftType == CraftType.Cooking) { skillsInit.cooking.AddExp(exp); } }
public bool Craft_Table(RaycastHit2D[] hits, Item tool, CraftType craftType, CraftTable craftTable) { GameObject GameObjOnTable = GetGameObjOnTable(hits); if (GameObjOnTable == null) { Debug.Log("TableIsEmpty"); return(false); } Item itemOnTabe = GameObjOnTable.GetComponent <ItemCell>().item; ItemCraftData recept = FindRecept(tool, itemOnTabe, craftType, craftTable); if (recept == null) { Debug.Log("no recept"); return(false); } if (!IsSuitableMinLvl(recept)) { Debug.Log("recept lvl bigger then skill lvl"); return(false); } Item craftResult = recept.recept.craftResult; // для вызова actionWindow if (itemOnTabe.itemOptionData.actionWindowTag != string.Empty) { Item _itemOnTabe = Instantiate(itemOnTabe); Item _craftResult = Instantiate(craftResult); ActionWindowController actionWindow = Global.Component.GetActionWindowController(); actionWindow.OpenActionWindow(itemOnTabe.itemOptionData.actionWindowTag); actionWindow.InitActioWindow(itemOnTabe.itemOptionData.actionWindowTag, GameObjOnTable, _itemOnTabe, _craftResult); //UpdateGameObjItem(GameObjOnTable, craftResult); return(recept.removeTool); } UpdateGameObjItem(GameObjOnTable, craftResult); AddExpReward(recept); return(recept.removeTool); }
bool IsSuitableMinLvl(ItemCraftData itemCraftData) { CraftType craftType = itemCraftData.craftType; int minCraftLvl = itemCraftData.craftMinLVL; if (craftType == CraftType.Cooking && skillsInit.cooking.GetSkillLvl() >= minCraftLvl) { return(true); } return(false); }
ItemCraftData FindRecept(Item tool, Item originItem, CraftType craftType, CraftTable craftTable) { List <ItemCraftData> sameTool = new List <ItemCraftData>(); foreach (var cd in itemCraftData) { if (cd.recept.craftTool.Find(c => c.IsSameItems(tool))) { sameTool.Add(cd); } } List <ItemCraftData> sameType = sameTool .Where(r => r.craftType == craftType) .Where(r => r.craftTable == craftTable).ToList(); ItemCraftData recept = sameType .Where(r => r.recept.ingredients[0].itemName.Equals(originItem.itemName)) .FirstOrDefault(); return(recept); }
void Update() { if (IsInActionRadius() == true) { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y); RaycastHit2D[] hits = Physics2D.RaycastAll(mousePos2D, Vector2.zero); if (hits.Length == 0) { isdetected = false; } foreach (var hit in hits) { if (hit.collider.tag == "substitudeItem") { BaseConection baseConection = hit.collider.GetComponent <BaseConection>(); NPC_Info npcInfo = hit.collider.GetComponent <NPC_Info>(); PCController pcController = baseConection.FindPcInRadius(); string interactionStr = Global.Tooltip.LM_INTERACT + " / " + Global.Tooltip.RM_TURN_OFF; if (pcController != null) { bool isConnected = pcController.peripherals.Contains(hit.collider.gameObject); interactionStr = ((isConnected == true) ? Global.Tooltip.LM_DISCONNECT : Global.Tooltip.LM_CONNECT) + " / " + Global.Tooltip.RM_TURN_OFF; } isdetected = true; //tooltipPosition = Camera.main.WorldToScreenPoint(hit.transform.position); ShowToolTip(npcInfo == null ? "obj" : npcInfo.npcName, interactionStr); TooltipLocate(hit.collider.transform.position); return; } else if (hit.collider.tag == "table") { TableController tableController = hit.collider.GetComponent <TableController>(); isdetected = true; //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position); if (IsCurrentHandEmpty() && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == false) { ShowToolTip((tableController.tableName == string.Empty) ? "table" : tableController.tableName, PrintRed(Global.Tooltip.NO_ACTIONS)); } else if (IsCurrentHandEmpty() && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == true) { Item itemOnTable = FindRaycast(hits, Global.DROPED_ITEM_PREFIX, false)?.collider .GetComponent <ItemCell>().item; ShowToolTip((tableController.tableName == string.Empty) ? "table" + " (" + itemOnTable.itemName + ")" : tableController.tableName + " (" + itemOnTable.itemName + ")", Global.Tooltip.LM_PICK_UP); } else if (IsCurrentHandEmpty() == false && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == true) { Item tool = controller.GetItemInHand(controller.currentHand); RaycastHit2D?itemOnTableHit = FindRaycast(hits, Global.DROPED_ITEM_PREFIX, false); Item temOnTable = itemOnTableHit.GetValueOrDefault().collider.GetComponent <ItemCell>().item; ItemCraftData craftData = CraftController.FindRecept_Static(tool, temOnTable, CraftType.Cooking, /* TODO */ CraftTable.Table); ShowToolTip((tableController.tableName == string.Empty) ? "table" + " (" + temOnTable.itemName + ")" : tableController.tableName + " (" + temOnTable.itemName + ")", Global.Tooltip.LM_PUT + ((tableController.isCraftTable) ? ((craftData != null) ? " / " + Global.Tooltip.RM_CRAFT + " " + craftData.recept.craftResult.itemName : string.Empty) : string.Empty)); } else { ShowToolTip((tableController.tableName == string.Empty) ? "table" : tableController.tableName, Global.Tooltip.LM_PUT); } TooltipLocate(hit.collider.transform.position); return; } else if (hit.collider.name.Contains(Global.DROPED_ITEM_PREFIX)) { bool onTable = false; foreach (var hitTable in hits) { if (hitTable.collider.tag == "table") { onTable = true; } } if (onTable == false) { Item item = hit.collider.GetComponent <ItemCell>().item; Item itemInHand = controller.currentHand.GetComponent <ItemCell>().item; isdetected = true; string useInteraction = (item.itemSubstitution.IsSubstituted() == true && item.itemSubstitution.IsItemToUseExist(itemInHand)) ? " / " + Global.Tooltip.RM_TURN_ON : string.Empty; ShowToolTip(item.itemName, (controller.IsEmpty(controller.currentHand) == true) ? Global.Tooltip.LM_PICK_UP + useInteraction : ((useInteraction == string.Empty) ? PrintRed(Global.Tooltip.NO_ACTIONS) : useInteraction.Substring(" / ".Length))); TooltipLocate(hit.collider.transform.position); return; } } else if (hit.collider.tag == "case") { CaseController caseController = hit.collider.GetComponent <CaseController>(); isdetected = true; ShowToolTip((caseController.caseName == string.Empty) ? "case" : caseController.caseName, (caseController.isOpen == false) ? Global.Tooltip.LM_OPEN : Global.Tooltip.LM_CLOSE); TooltipLocate(hit.collider.transform.position); return; } else if (hit.collider.tag == "tv") { TVController tvController = hit.collider.GetComponent <TVController>(); isdetected = true; //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position); ShowToolTip("tv", (tvController.IsTvOpen() == false) ? Global.Tooltip.LM_TURN_ON : Global.Tooltip.LM_TURN_OFF + " / " + Global.Tooltip.RM_NEXT_CHANNEL); TooltipLocate(hit.collider.transform.position); return; } else if (hit.collider.tag == "envObj") { VendingController vending = hit.collider.GetComponent <VendingController>(); isdetected = true; //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position + // Global.Tooltip.EnvObjOffset()); ShowToolTip((vending.headerTitle == string.Empty) ? "vending" : vending.headerTitle.ToLower(), Global.Tooltip.LM_USE); TooltipLocate(hit.collider.transform.position); return; } else if (hit.collider.tag == "pc") { Item itemInHand = controller.currentHand.GetComponent <ItemCell>().item; PCController pcController = hit.collider.GetComponent <PCController>(); Item disk = pcController.disk; isdetected = true; //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position); if (disk != null && controller.IsEmpty(controller.currentHand)) { ShowToolTip("pc", Global.Tooltip.LM_INTERACT + " / " + Global.Tooltip.RM_PULL_THE_DISK); } else { ShowToolTip("pc", (controller.IsEmpty(controller.currentHand) == false && itemInHand.itemName.Contains("disk")) ? Global.Tooltip.LM_INTERACT + " / " + Global.Tooltip.RM_INSERT : Global.Tooltip.LM_INTERACT); } TooltipLocate(hit.collider.transform.position); } else if (hit.collider.tag == "playerAction") { if (controller.IsEmpty(controller.currentHand) == false && controller.GetItemInHand(controller.currentHand).itemBuff.buff != null) { playerTooltip.gameObject.SetActive(true); } else { playerTooltip.gameObject.SetActive(false); } return; } else if (hit.collider.gameObject.name.Contains(Global.ITEM_SWITCH_PREFIX)) { isdetected = true; ISwitchItem switchItem = hit.collider.GetComponent <ISwitchItem>(); Item itemInHand = controller.GetItemInHand(controller.currentHand); ShowToolTip(switchItem.GetISwitchName(), (itemInHand.IsSameItems(switchItem.GetNeedItem()) ? Global.Tooltip.RM_INSERT : PrintRed(Global.Tooltip.NO_ACTIONS))); TooltipLocate(hit.collider.transform.position); } else { isdetected = false; } //playerTooltip.gameObject.SetActive(hit.collider.tag == "player"); } playerTooltip.gameObject.SetActive(false); if (isTooltipOpen == true && isdetected == false) { HideToolTip(); } } else { if (isTooltipOpen == true) { HideToolTip(); } } }