2025-09-14 05:09:31 +00:00
|
|
|
using GUPS.AntiCheat.Protected;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
2025-09-15 00:52:36 +00:00
|
|
|
public enum eMiniGameObtacleType { White, Red, HpHeal, AlbumOpen, ChatCoin, GachaCoin, ItemBomb, ItemUmbrella, ItemDildo }
|
2025-09-14 05:09:31 +00:00
|
|
|
|
|
|
|
|
public class MiniGameObtacle : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public RectTransform m_RectTransform;
|
|
|
|
|
public Rigidbody2D m_Rigidbody2D;
|
|
|
|
|
public Image i_img;
|
2025-09-18 20:42:29 +00:00
|
|
|
public RectTransform tf_objend;
|
2025-09-14 05:09:31 +00:00
|
|
|
|
|
|
|
|
eMiniGameObtacleType m_Type;
|
|
|
|
|
ProtectedInt32 m_Dmg;
|
|
|
|
|
|
2025-09-18 20:42:29 +00:00
|
|
|
public void Set(Dictionary<eMiniGameObtacleType, int> dic_weight, RectTransform rtend)
|
2025-09-14 05:09:31 +00:00
|
|
|
{
|
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
|
SetRandomTypeByWeight(dic_weight);
|
2025-09-18 20:42:29 +00:00
|
|
|
tf_objend = rtend;
|
2025-09-14 05:09:31 +00:00
|
|
|
m_Rigidbody2D.gravityScale = Random.Range(table_GlobalValue.Ins.Get_Float("MiniGameSpeedMin"),
|
|
|
|
|
table_GlobalValue.Ins.Get_Float("MiniGameSpeedMax"));
|
|
|
|
|
|
|
|
|
|
var x = (Screen.width >> 1) - 50;
|
|
|
|
|
m_RectTransform.anchoredPosition = new Vector2(Random.Range(-x, x), 0f);
|
|
|
|
|
|
2025-09-19 00:59:12 +00:00
|
|
|
Set_Item();
|
|
|
|
|
i_img.transform.eulerAngles = Vector3.zero;
|
|
|
|
|
|
|
|
|
|
void SetRandomTypeByWeight(Dictionary<eMiniGameObtacleType, int> dic_weight)
|
|
|
|
|
{
|
|
|
|
|
// 총합
|
|
|
|
|
int totalWeight = dic_weight.Values.Sum();
|
|
|
|
|
if (totalWeight <= 0)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("가중치 총합이 0 이하입니다. 기본값으로 White 선택.");
|
|
|
|
|
m_Type = eMiniGameObtacleType.White;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 랜덤 뽑기
|
|
|
|
|
int rand = Random.Range(0, totalWeight);
|
|
|
|
|
int cumulative = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var pair in dic_weight)
|
|
|
|
|
{
|
|
|
|
|
cumulative += pair.Value;
|
|
|
|
|
if (rand < cumulative)
|
|
|
|
|
{
|
|
|
|
|
m_Type = pair.Key;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Set_Item()
|
|
|
|
|
{
|
2025-09-14 05:09:31 +00:00
|
|
|
switch (m_Type)
|
|
|
|
|
{
|
|
|
|
|
case eMiniGameObtacleType.White:
|
2025-09-18 20:21:29 +00:00
|
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("icon 1_mini game");
|
2025-09-14 18:55:59 +00:00
|
|
|
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_White_DMG");
|
2025-09-14 05:09:31 +00:00
|
|
|
break;
|
|
|
|
|
case eMiniGameObtacleType.Red:
|
2025-09-18 20:21:29 +00:00
|
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("icon 2_mini game");
|
2025-09-14 18:55:59 +00:00
|
|
|
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_Red_DMG");
|
2025-09-14 05:09:31 +00:00
|
|
|
break;
|
|
|
|
|
case eMiniGameObtacleType.AlbumOpen:
|
|
|
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.AlbumOpen);
|
2025-09-14 18:55:59 +00:00
|
|
|
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_Heart_Amount");
|
2025-09-14 05:09:31 +00:00
|
|
|
break;
|
|
|
|
|
case eMiniGameObtacleType.ChatCoin:
|
|
|
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.Chat);
|
2025-09-14 18:55:59 +00:00
|
|
|
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_ChatCoin_Amount");
|
2025-09-14 05:09:31 +00:00
|
|
|
break;
|
|
|
|
|
case eMiniGameObtacleType.GachaCoin:
|
|
|
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.Gacha);
|
2025-09-14 18:55:59 +00:00
|
|
|
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_GachaCoin_Amount");
|
2025-09-14 05:09:31 +00:00
|
|
|
break;
|
|
|
|
|
case eMiniGameObtacleType.HpHeal:
|
2025-09-18 20:21:29 +00:00
|
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("icon 5_mini game");
|
2025-09-14 18:55:59 +00:00
|
|
|
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_Heal");
|
2025-09-14 05:09:31 +00:00
|
|
|
break;
|
2025-09-15 00:52:36 +00:00
|
|
|
case eMiniGameObtacleType.ItemBomb:
|
|
|
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("item_bomb");
|
|
|
|
|
m_Dmg = 1;
|
|
|
|
|
break;
|
|
|
|
|
case eMiniGameObtacleType.ItemUmbrella:
|
|
|
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("item_umbrella");
|
|
|
|
|
m_Dmg = 1;
|
|
|
|
|
break;
|
|
|
|
|
case eMiniGameObtacleType.ItemDildo:
|
|
|
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("item_dildo");
|
|
|
|
|
m_Dmg = 1;
|
|
|
|
|
break;
|
2025-09-14 05:09:31 +00:00
|
|
|
}
|
2025-09-19 00:59:12 +00:00
|
|
|
m_Dmg.Obfuscate();
|
2025-09-18 20:21:29 +00:00
|
|
|
i_img.SetNativeSize();
|
|
|
|
|
if (m_Type == eMiniGameObtacleType.AlbumOpen || m_Type == eMiniGameObtacleType.ChatCoin ||
|
|
|
|
|
m_Type == eMiniGameObtacleType.GachaCoin)
|
|
|
|
|
i_img.transform.localScale = Vector3.one * 0.5f;
|
2025-09-18 20:42:29 +00:00
|
|
|
else
|
|
|
|
|
i_img.transform.localScale = Vector3.one;
|
2025-09-19 00:59:12 +00:00
|
|
|
}
|
|
|
|
|
public void Change_Item(Dictionary<eMiniGameObtacleType, int> dic_weight)
|
2025-09-14 05:09:31 +00:00
|
|
|
{
|
2025-09-19 00:59:12 +00:00
|
|
|
switch (m_Type)
|
2025-09-14 05:09:31 +00:00
|
|
|
{
|
2025-09-19 00:59:12 +00:00
|
|
|
case eMiniGameObtacleType.White:
|
|
|
|
|
case eMiniGameObtacleType.Red:
|
|
|
|
|
case eMiniGameObtacleType.HpHeal:
|
|
|
|
|
case eMiniGameObtacleType.ItemBomb:
|
|
|
|
|
case eMiniGameObtacleType.ItemUmbrella:
|
|
|
|
|
case eMiniGameObtacleType.ItemDildo:
|
|
|
|
|
{
|
|
|
|
|
// 후보 아이템 리스트
|
|
|
|
|
var candidates = new List<eMiniGameObtacleType>
|
|
|
|
|
{
|
|
|
|
|
eMiniGameObtacleType.AlbumOpen,
|
|
|
|
|
eMiniGameObtacleType.ChatCoin,
|
|
|
|
|
eMiniGameObtacleType.GachaCoin
|
|
|
|
|
};
|
2025-09-14 05:09:31 +00:00
|
|
|
|
2025-09-19 00:59:12 +00:00
|
|
|
// 총 가중치 합
|
|
|
|
|
int totalWeight = 0;
|
|
|
|
|
foreach (var c in candidates)
|
|
|
|
|
{
|
|
|
|
|
if (dic_weight.TryGetValue(c, out int w))
|
|
|
|
|
totalWeight += w;
|
|
|
|
|
}
|
2025-09-14 05:09:31 +00:00
|
|
|
|
2025-09-19 00:59:12 +00:00
|
|
|
if (totalWeight <= 0) return; // 가중치가 전혀 없으면 리턴
|
|
|
|
|
|
|
|
|
|
// 랜덤 값
|
|
|
|
|
int rand = Random.Range(0, totalWeight);
|
|
|
|
|
|
|
|
|
|
// 가중치 누적하면서 선택
|
|
|
|
|
foreach (var c in candidates)
|
|
|
|
|
{
|
|
|
|
|
if (!dic_weight.TryGetValue(c, out int w)) continue;
|
|
|
|
|
if (rand < w)
|
|
|
|
|
{
|
|
|
|
|
m_Type = c; // 선택된 아이템으로 교체
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
rand -= w;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2025-09-14 05:09:31 +00:00
|
|
|
}
|
2025-09-19 00:59:12 +00:00
|
|
|
|
|
|
|
|
Set_Item();
|
2025-09-14 05:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
2025-09-18 20:42:29 +00:00
|
|
|
if (m_RectTransform.position.y < tf_objend.position.y)
|
2025-09-14 05:09:31 +00:00
|
|
|
{
|
2025-09-14 07:05:38 +00:00
|
|
|
Off(false);
|
2025-09-14 05:09:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-16 00:55:24 +00:00
|
|
|
public void Off_OnlyObtacle()
|
|
|
|
|
{
|
|
|
|
|
if (m_Type == eMiniGameObtacleType.White || m_Type == eMiniGameObtacleType.Red)
|
|
|
|
|
Off(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Off(bool showeffect, bool playsound = true)
|
2025-09-14 05:09:31 +00:00
|
|
|
{
|
|
|
|
|
gameObject.SetActive(false);
|
2025-09-14 07:05:38 +00:00
|
|
|
if (showeffect)
|
|
|
|
|
{
|
|
|
|
|
LobbyUI.Ins.m_Game_Mini.Show_HitEffect(m_RectTransform.position);
|
2025-09-16 00:55:24 +00:00
|
|
|
if (playsound)
|
|
|
|
|
SoundInfo.Ins.Play_OneShot(eSound.s002_Bubble, 1f);
|
2025-09-14 07:05:38 +00:00
|
|
|
}
|
2025-09-14 05:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
|
|
|
{
|
|
|
|
|
if (collision.tag.Equals("Player"))
|
|
|
|
|
{
|
2025-09-14 07:05:38 +00:00
|
|
|
Off(true);
|
2025-09-14 18:34:04 +00:00
|
|
|
LobbyUI.Ins.m_Game_Mini.Hit(m_Type, m_Dmg);
|
2025-09-14 05:09:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|