// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { lastDown = Time.time; } if (Input.GetMouseButtonUp(0) && Time.time - lastDown < clickDelay) { Shop shop = mover.GetShop(); IntPair shopCoords = shop.worldToShopCoordinates(Camera.main.ScreenToWorldPoint(Input.mousePosition)); if (shop.IsPositionInGrid(shopCoords)) { if (movingCoroutine != null) { StopCoroutine(movingCoroutine); } movingCoroutine = mover.MoveToPosition(shopCoords, MoveCallback); StartCoroutine(movingCoroutine); } } }
// Update is called once per frame void Update() { if (!isMoving && Time.time > nextMoveTime) { Shop shop = shopMover.GetShop(); int numFurniture = shop.GetFurnitureAmount(); if (numFurniture > 0) { int idx = Random.Range(0, numFurniture); Furniture furniture = shop.GetFurnitureAtIndex(idx); isMoving = true; StartCoroutine(shopMover.MoveToPosition(furniture.GetStandingPosition(), (s) => { isMoving = false; nextMoveTime = Time.time + 2 + Random.value * 3; })); } } }
private IEnumerator BeginAI() { while (true) { switch (Random.Range(0, 2)) { case 0: // Offer a trade. var info = MetaInformation.Instance(); if (info != null) { int numMappings = info.GetNumberOfRegisteredItems(); if (numMappings != 0) { ItemType offType = info.GetItemTypeMappings().ElementAt(Random.Range(0, numMappings)).Value; ItemType reqType = info.GetItemTypeMappings().ElementAt(Random.Range(0, numMappings)).Value; int numOfferedItem = Random.Range(1, 10); int numRequestItem = Random.Range(1, 10); TradingOffer offer = TradingOffer.MakeOffer( new ItemStack(offType, numOfferedItem), new ItemStack(reqType, numRequestItem)); bool didSucceed = false; yield return(TradingDialogUtility.OfferTrade(offer, (result) => { didSucceed = result == TradingResult.SUCCEED; })); if (didSucceed) { NotificationSystem.ShowNotificationIfPossible("Trade succeeded."); } else { NotificationSystem.ShowNotificationIfPossible("Trade failed."); } break; } else { goto case 1; } } else { Debug.Log("No MetaInformation instance found. AI will not make a random trade offer."); goto case 1; } case 1: // Move to a random piece of furniture in the shop. Shop shop = myShopMover.GetShop(); Furniture target = shop.GetFurnitureAtIndex(Random.Range(0, shop.GetFurnitureAmount())); yield return(myShopMover.MoveToPosition(target.GetStandingPosition(), (succ) => {})); break; } } }