Super Knight : Enter the Dungeon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MapBlockShop : MonoBehaviour
{
[Space(10)]
public int productCnt = 3;
public int productTierMin = 0;
public int productTierMax = 999;
List<DropItem> shopItems = new List<DropItem>();
public void OnInitialized(MapBlock map, System.Action<GameObject, DropItem> OnGain)
{
productCnt = map.manager.floorData.productCnt;
productTierMin = map.manager.floorData.productTierMin;
productTierMax = map.manager.floorData.productTierMax;
shopItems.Clear();
for (int i = 0; i < productCnt; i++)
{
ItemData rewardData = map.manager.DuplicateItemCheck(map.manager.items_All, productTierMin, productTierMax, null, false);
if (rewardData == null)
break;
DropItem item = map.manager.ObjectCreateLocalPos(map.prefabRewardDropItem.gameObject, transform, Vector3.one, map.rewardPos).GetComponent<DropItem>();
item.item = ItemData.Copy(rewardData, 1);
item.OnGain = OnGain;
item.OnInitialized(true);
map.dropItems.Add(item);
shopItems.Add(item);
}
Vector3 posStart = map.rewardPos;
float interval = 2f;
int x = shopItems.Count < 3 ? shopItems.Count : 3;
if (0 < x)
posStart.x = posStart.x - (interval * (x - 1) / 2f);
int z = shopItems.Count < 3 ? 0 : Mathf.CeilToInt(shopItems.Count / 3f);
if (0 < z)
posStart.z = posStart.z - (interval * (z - 1) / 2f);
Vector3 pos = Vector3.zero;
for (int i = 0; i < shopItems.Count; i++)
{
pos.x = posStart.x + (interval * (i % 3));
pos.z = posStart.z + (interval * (i / 3));
shopItems[i].transform.localPosition = pos;
}
}
}