Project_WL/Assets/Script/Info/InGameInfo.cs

472 lines
16 KiB
C#

using CodeStage.AntiCheat.Detectors;
using CodeStage.AntiCheat.Storage;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.ResourceManagement.AsyncOperations;
public partial class InGameInfo : MyCoroutine
{
public static InGameInfo Ins;
public SceneInfo m_SceneInfo;
public Transform tf_Effects, tf_Objs;
public Material mat_Dissolve;
List<HUDDMGUI> list_HUDDMGUI = new List<HUDDMGUI>();
List<HUDUI> list_HUDUI = new List<HUDUI>();
HUDLvUp m_HUDLvUp;
Dictionary<string, List<GameObject>> dic_str_Effect = new Dictionary<string, List<GameObject>>();
Dictionary<eEffect, List<GameObject>> dic_Skill = new Dictionary<eEffect, List<GameObject>>();
Dictionary<eObj, GameObject> dic_Obj = new Dictionary<eObj, GameObject>();
eGameMode m_GameMode;
List<GameObject> list_dropitems = new List<GameObject>();
List<ProjectileData> list_projectileData = new List<ProjectileData>();
private void Awake()
{
Ins = this;
// PD #747 — 무기 궤적 트레일이 검끝 버스트를 스폰할 때 쓰는 경로(크레센트 억제용 콜백 포함).
WL.Combat.WeaponTrailDriver.ExternalSpawner = Show_EffectEx;
}
void Set_Init()
{
for (eEffect i = 0; i < eEffect.Max; i++)
dic_Skill.Add(i, new List<GameObject>());
for (int i = 0; i < 14; i++)
list_quickamount.Add(0);
for (eObj i = 0; i < eObj.Max; i++)
dic_Obj.Add(i, null);
AddrResourceMgr.Ins.LoadObject<GameObject>("Assets/Res_Addr/Obj/MobMark.prefab", handle =>
{
if (handle.IsDone && handle.Status == AsyncOperationStatus.Succeeded)
{
var mm = DSUtil.Get_Clone(handle.Result, tf_Objs);
AddrResourceMgr.Ins.Set_AddressableReleaseSelf(mm);
dic_Obj[eObj.MobMark] = mm;
mm.SetActive(false);
}
});
for (int i = 0; i < 200; i++) // 너무 많나?
list_projectileData.Add(new ProjectileData());
#if UNITY_EDITOR
if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "StatTest")
return;
#endif
AddrResourceMgr.Ins.LoadObject<GameObject>("Assets/Res_Addr/MainUI/NewGameUI.prefab", handle =>
{
if (handle.IsDone && handle.Status == AsyncOperationStatus.Succeeded)
{
DSUtil.Get_Clone(handle.Result);
InappInfo.Ins.Check_Retrieved();
}
});
}
IEnumerator Start()
{
DataCheckMgr.Ins.Set();
Set_Init();
while (!TableChecker.Ins.CheckAllLoad()) yield return new WaitForSeconds(0.1f);
var lst = table_effectlist.Ins.Get_DataList(1);
for (int i = 0; i < lst.Count; i++)
{
dic_str_Effect.Add(lst[i].s_EffectPrefab, new List<GameObject>());
for (int j = 0; j < lst[i].n_PreLoadCount; j++)
Load_Effect(lst[i].s_EffectPrefab, effect => { effect.transform.position = Vector3.one * 100000f; });
}
var skilllst = table_skilllist.Ins.Get_DataList();
for (int i = 0; i < skilllst.Count; i++)
{
if (skilllst[i].e_SkillType == eSkillType.Active && skilllst[i].e_Skill != eEffect.None)
{
for (int j = 0; j < 2; j++)
Load_Skill(skilllst[i].e_Skill, list_projectileData[0], true);
}
}
#if UNITY_EDITOR
if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "StatTest") yield break;
#endif
ObscuredCheatingDetector.StartDetection(OnCheaterDetected);
ObscuredPrefs.OnAlterationDetected += OnCheaterDetected;
SpeedHackDetector.StartDetection(OnCheaterDetected);
while (DSUtil.CheckNull(NewGameUI.Ins)) yield return null;
AddrResourceMgr.Ins.LoadObject<GameObject>("Assets/Res_Addr/Ingame/HUDDMGUI.prefab", handle =>
{
if (handle.IsDone && handle.Status == AsyncOperationStatus.Succeeded)
{
for (int i = 0; i < 150; i++)
list_HUDDMGUI.Add(DSUtil.Get_Clone<HUDDMGUI>(handle.Result, NewGameUI.Ins.tf_HUD));
list_HUDDMGUI.ForEach(f => f.Off(true));
}
});
AddrResourceMgr.Ins.LoadObject<GameObject>("Assets/Res_Addr/Ingame/HUDUI.prefab", handle =>
{
for (int i = 0; i < 100; i++)
list_HUDUI.Add(DSUtil.Get_Clone<HUDUI>(handle.Result, NewGameUI.Ins.tf_HUD));
list_HUDUI.ForEach(f => f.Off(true));
});
//var sinfo = ServerInfo.Ins;
//Init_StageInfo(eGameMode.Stage, sinfo.m_ServerData.Get_Common(eCommon.TotalStage));
//Set_Coroutine(() =>
//{
// if (sinfo.IsNewUser())
// {
// var pc = MyValue.MyPC;
// pc.Stop_PC();
// StoryUI.Ins.Set(() => { pc.FindNextTarget(); DataCheckMgr.Ins.Set(); });
// }
// else
// {
// sinfo.Check_OfflineReward();
// DataCheckMgr.Ins.Set();
// }
//}, Time.deltaTime);
//BossGemCoolTime = sinfo.m_ServerData.Get_Common(eCommon.BossGemCoolTime);
//DropEventCoolTime = 60f;
}
public void AllEffectOff()
{
foreach (var item in dic_str_Effect)
for (int i = 0; i < item.Value.Count; i++)
item.Value[i].SetActive(false);
foreach (var item in dic_Obj)
{
if (!DSUtil.CheckNull(item.Value))
item.Value.SetActive(false);
}
list_HUDDMGUI.ForEach(f => f.Off(true));
list_HUDUI.ForEach(f => f.Off(true));
}
void OnCheaterDetected()
{
Time.timeScale = 0f;
Popup.Ins.Set(ePopupType.One, -99, DSUtil.Quit, DSUtil.Quit);
}
public eGameMode Get_GameMode() { return m_GameMode; }
public bool IsGameMode(eGameMode _mode) { return m_GameMode == _mode; }
/// <summary>
/// -1 로비, 0 농장, 1 스테이지, 2 던전
/// </summary>
/// <param name="id"></param>
public void Load_Map(int id)
{
LoadingUI.Ins.Start_Loading();
AllEffectOff();
if (ProjectileInfo.isIns) ProjectileInfo.Ins.AllOff();
if (DropItemInfo.isIns) DropItemInfo.Ins.AllOff();
MyValue.MyChoiceMapData.n_MapID = id;
var Tdata = table_battlemapconfig.Ins.Get_Data(MyValue.MyChoiceMapData.n_MapID);
m_GameMode = Tdata.e_MapType;
ServerInfo.Ins.m_ServerData.Add_MissionCount(ePurpose.ARRIVAL_MAP_LIMIT, id);
m_SceneInfo.Load_AddScene(Tdata, () =>
{
StartCam();
NewGameUI.Ins.SetUI_byGameMode(m_GameMode);
});
}
public void StartCam() { StartCoroutine(Co_StartCam()); }
IEnumerator Co_StartCam()
{
while (!MyValue.bMyPC) yield return null;
MyValue.MyPC.StartCam(null);
}
#region HUD
public HUDUI Get_HUDUI()
{
HUDUI temp = null;
for (int i = 0; i < list_HUDUI.Count; i++)
{
if (list_HUDUI[i].Get_Check())
{
temp = list_HUDUI[i];
break;
}
}
if (DSUtil.CheckNull(temp) && list_HUDUI.Count > 0)
{
temp = DSUtil.Get_Clone<HUDUI>(list_HUDUI[0].gameObject, NewGameUI.Ins.tf_HUD);
list_HUDUI.Add(temp);
}
return temp;
}
public HUDDMGUI Get_HUDDMGUI()
{
HUDDMGUI temp = null;
for (int i = 0; i < list_HUDDMGUI.Count; i++)
{
if (!list_HUDDMGUI[i].gameObject.activeInHierarchy)
{
temp = list_HUDDMGUI[i];
break;
}
}
if (DSUtil.CheckNull(temp) && list_HUDDMGUI.Count > 0)
{
temp = DSUtil.Get_Clone<HUDDMGUI>(list_HUDDMGUI[0].gameObject, NewGameUI.Ins.tf_HUD);
list_HUDDMGUI.Add(temp);
}
return temp;
}
public HUDLvUp Get_HUDLvUp()
{
if (m_HUDLvUp == null) m_HUDLvUp = DSUtil.Get_Clone<HUDLvUp>("InGame/HUDLvUp", NewGameUI.Ins.tf_HUD);
return m_HUDLvUp;
}
#endregion
public void AllEffect_Off()
{
foreach (var item in dic_Skill)
{
for (int i = 0; i < item.Value.Count; i++)
item.Value[i].gameObject.SetActive(false);
}
}
public void Show_SkillTypeEffect(ProjectileData pd, Actor target, float lifeTime, Action<TurnOff_GO> cceffect = null)
{
var stcData = pd.m_skillTypeConfigTable;
if (!DSUtil.CheckNull(stcData) && !stcData.e_SkillEffect.Equals("None"))
{
if (!DSUtil.CheckNull(target))
{
Get_Effect(stcData.e_SkillEffect, temp =>
{
var effect = temp.GetComponent<TurnOff_GO>();
effect.Set(target, pd, lifeTime);
effect.Set_EffectwhenOff(stcData.s_SkillEffectWhenOff);
temp.transform.localScale = stcData.v3_Scale;
var chekers = temp.GetComponentsInChildren<ProjectileHitChecker>(true);
for (int i = 0; i < chekers.Length; i++)
chekers[i].Set(pd.m_ProjectileBase);
cceffect?.Invoke(effect);
});
}
}
}
public void Shoot_Effect(ProjectileData _ptd)
{
var isskill = _ptd.IsSkill();
eEffect effect;
if (isskill)
{
effect = _ptd.m_SkillListTableData.e_Skill;
switch (_ptd.m_SkillListTableData.e_SkillTarget)
{
case eSkillTarget.Self:
case eSkillTarget.SelfEnemy:
_ptd.target = _ptd.shooter;
break;
case eSkillTarget.Team:
_ptd.target = _ptd.shooter;
var myteam = ActorInfo.Ins.Get_AlliesActors(_ptd.shooter.IsEnemy(), _ptd.shooter.Get_position(),
table_GlobalValue.Ins.Get_Float("f_SkillTeamRange"));
for (int i = 0; i < myteam.Count; i++)
{
_ptd.Copy(list_projectileData[i]);
list_projectileData[i].target = myteam[i];
Shoot_Skill(effect, list_projectileData[i]);
}
return;
case eSkillTarget.Pet:
if (_ptd.shooter.IsRole(eRole.Pet))
_ptd.target = _ptd.shooter.Get_Owner();
else
_ptd.target = _ptd.shooter.Get_MyPet();
break;
}
}
else
effect = _ptd.m_Skill;
Shoot_Skill(effect, _ptd);
}
void Shoot_Skill(eEffect effect, ProjectileData _ptd, bool firstload = false)
{
for (int i = 0; i < dic_Skill[effect].Count; i++)
{
if (!dic_Skill[effect][i].activeInHierarchy)
{
dic_Skill[effect][i].GetComponent<ProjectileBase>().Set(_ptd);
return;
}
}
Load_Skill(effect, _ptd, firstload);
}
void Load_Skill(eEffect effect, ProjectileData _ptd, bool firstload = false)
{
AddrResourceMgr.Ins.LoadObject<GameObject>(Get_SkillPrefabPath(effect), handle =>
{
var temp = DSUtil.Get_Clone(handle.Result, tf_Effects);
dic_Skill[effect].Add(temp);
if (!firstload) temp.GetComponent<ProjectileBase>().Set(_ptd);
});
}
void Load_Effect(string prefab, Action<GameObject> act)
{
AddrResourceMgr.Ins.LoadObject<GameObject>(DSUtil.Format("Assets/Res_Addr/Effect/{0}.prefab", prefab), handle =>
{
if (handle.IsDone && handle.Status == AsyncOperationStatus.Succeeded)
{
var temp = DSUtil.Get_Clone(handle.Result, tf_Effects);
dic_str_Effect[prefab].Add(temp);
act?.Invoke(temp);
}
});
}
void Get_Effect(string prefab, Action<GameObject> act)
{
if (dic_str_Effect.ContainsKey(prefab))
{
for (int i = 0; i < dic_str_Effect[prefab].Count; i++)
if (!dic_str_Effect[prefab][i].activeInHierarchy)
{
act(dic_str_Effect[prefab][i]);
return;
}
}
else
dic_str_Effect.Add(prefab, new List<GameObject>());
Load_Effect(prefab, act);
}
public void Show_Effect(string prefab, Actor target)
{
Get_Effect(prefab, temp =>
{
var turnoff = temp.GetComponent<TurnOff_GO>();
turnoff.Set_PrefabInfo(target);
});
}
public void Show_Effect(string prefab, Vector3 pos, Vector3? _eulerAngles = null, string showEffectwhenOff = "")
{
Get_Effect(prefab, temp =>
{
temp.transform.position = pos;
if (_eulerAngles.HasValue)
temp.transform.eulerAngles = _eulerAngles.Value;
temp.SetActive(true);
temp.GetComponent<TurnOff_GO>().Set_EffectwhenOff(showEffectwhenOff);
});
}
/// <summary>
/// PD #747 — 스폰된 인스턴스를 콜백으로 넘겨 주는 오버로드.
/// 위 Show_Effect 와 동작은 같고, 호출부가 활성화 <b>직전에</b> 인스턴스를 후처리할 수 있다.
/// (무기 궤적 트레일이 원본 크레센트 이미터를 끄는 데 쓴다)
/// </summary>
public void Show_EffectEx(string prefab, Vector3 pos, Vector3 eulerAngles, Action<GameObject> actSpawned)
{
Get_Effect(prefab, temp =>
{
temp.transform.position = pos;
temp.transform.eulerAngles = eulerAngles;
actSpawned?.Invoke(temp); // 반드시 SetActive 전에 — 파티클이 재생되기 전에 걸러야 한다
temp.SetActive(true);
var off = temp.GetComponent<TurnOff_GO>();
if (off != null) off.Set_EffectwhenOff("");
});
}
public void Show_Effect(string prefab, Actor actor, eEffectLocation loca, float lifetime, Action<TurnOff_GO> actEffect = null)
{
Get_Effect(prefab, temp =>
{
var turnoff = temp.GetComponent<TurnOff_GO>();
turnoff.Set(actor, loca, lifetime);
actEffect?.Invoke(turnoff);
});
}
public GameObject Get_Obj(eObj obj) { return dic_Obj[obj]; }
string Get_SkillPrefabPath(eEffect effect)
{
if (effect.ToString().Contains("Select"))
return DSUtil.Format("Assets/Res_Addr/SelectSkill/{0}.prefab", effect);
else if (effect.ToString().Contains("Skill"))
return DSUtil.Format("Assets/Res_Addr/Skill/{0}.prefab", effect);
else
return DSUtil.Format("Assets/Res_Addr/Effect/{0}.prefab", effect);
}
public void Set_TimeScale(float _scale, float _delay) { Set_Coroutine(() => { Time.timeScale = _scale; }, _delay); }
#region ( , , , , , )
public void Clear_Chapter()
{
GameUI.Ins.IngameUI.m_StageResult.Set(true, false, Return_To_Lobby);
}
public void Boss_Meet()
{
}
public void Kill_Boss()
{
}
public void Defeat_byMonster()
{
// 죽으면 부활의 성소로 가므로 필요없음
//if (m_CurStageData.Chapter == 104)
// GameUI.Ins.IngameUI.m_MemoryWitchResult.Set();
//else
// GameUI.Ins.IngameUI.m_StageResult.Set(false, false, Return_To_Lobby);
}
public void PetBattleResult(bool _win)
{
Time.timeScale = 0.3f;
Set_Coroutine(() =>
{
Time.timeScale = 1f;
}, 0.5f);
}
public void Return_To_Lobby()
{
Time.timeScale = 1f; // 일시정지에서 돌아오면 0임
m_GameMode = eGameMode.Lobby;
Init_IngameData();
NewGameUI.Ins.SetUI_byGameMode(m_GameMode);
MyValue.MyChoiceMapData.n_PortalIndex = 0;
Load_Map(-1);
}
public void Return_To_ChapterLobby()
{
Return_To_Lobby();
}
#endregion
}