Skip to content

Commit

Permalink
load and parse of Skillgrp.dat
Browse files Browse the repository at this point in the history
  • Loading branch information
shnok committed Oct 16, 2024
1 parent b2db45b commit 720070f
Show file tree
Hide file tree
Showing 17 changed files with 47,166 additions and 26,592 deletions.
Binary file modified l2-unity-fmod/.cache/{4127ed50-b246-44fa-b836-f66fb20fe7bb}.pdc
Binary file not shown.
Binary file modified l2-unity-fmod/.cache/{4d8dba7a-2f4e-48a8-8a7f-0018e8aa04f3}.pdc
Binary file not shown.
53,064 changes: 26,532 additions & 26,532 deletions l2-unity/Assets/Resources/Scenes/Tests/TestParticles.unity

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions l2-unity/Assets/Scripts/Datatable/Grp/Model/SkillSoundgrp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using UnityEngine;

public class SkillSoundgrp
{
public int SkillId { get; set; }
public SkillSound[] SpellEffectSounds { get; set; }
public SkillSound[] ShotEffectSounds { get; set; }
public string[] CastingVoices { get; set; }
public string[] CastingEndVoices { get; set; }
public float CastVolume { get; set; }
public float CastRadius { get; set; }

public SkillSoundgrp()
{
SpellEffectSounds = new SkillSound[3];
ShotEffectSounds = new SkillSound[3];
CastingVoices = new string[14];
CastingEndVoices = new string[14];
}
}

public class SkillSound
{
public string SoundEvent { get; set; }
public float SoundVolune { get; set; }
public float SoundRadius { get; set; }
public float SoundDelay { get; set; }
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

222 changes: 222 additions & 0 deletions l2-unity/Assets/Scripts/Datatable/Grp/SkillSoundgrpTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using UnityEngine;

public class SkillSoundgrpTable
{
private static SkillSoundgrpTable _instance;
private Dictionary<int, SkillSoundgrp> _data;

public static SkillSoundgrpTable Instance
{
get
{
if (_instance == null)
{
_instance = new SkillSoundgrpTable();
}

return _instance;
}
}

public void Initialize()
{
ReadActions();
}

private void ReadActions()
{
_data = new Dictionary<int, SkillSoundgrp>();

string dataPath = Path.Combine(Application.streamingAssetsPath, "Data/Meta/SkillSoundgrp_Classic.txt");
if (!File.Exists(dataPath))
{
Debug.LogWarning("File not found: " + dataPath);
return;
}

using (StreamReader reader = new StreamReader(dataPath))
{
string line;
while ((line = reader.ReadLine()) != null)
{
SkillSoundgrp grp = new SkillSoundgrp();

string[] keyvals = line.Split('\t');

for (int i = 0; i < keyvals.Length; i++)
{
if (!keyvals[i].Contains("="))
{
continue;
}

string[] keyval = keyvals[i].Split("=");
string key = keyval[0];
string value = keyval[1].Replace("[", "").Replace("]", "");

switch (key)
{
case "skill_id":
grp.SkillId = int.Parse(value, CultureInfo.InvariantCulture);
break;
case "spelleffect_sound_1":
case "spelleffect_sound_2":
case "spelleffect_sound_3":
if (value != "None")
{
int index = int.Parse(key.Replace("spelleffect_sound_", ""), CultureInfo.InvariantCulture);
grp.SpellEffectSounds[--index] = new SkillSound();
grp.SpellEffectSounds[index].SoundEvent = value;
}
break;
case "spelleffect_sound_vol_1":
case "spelleffect_sound_vol_2":
case "spelleffect_sound_vol_3":
int volIndex = int.Parse(key.Replace("spelleffect_sound_vol_", ""));
if (grp.SpellEffectSounds[--volIndex] != null)
{
float vol = float.Parse(value, CultureInfo.InvariantCulture);
grp.SpellEffectSounds[volIndex].SoundVolune = vol;
}
break;
case "spelleffect_sound_rad_1":
case "spelleffect_sound_rad_2":
case "spelleffect_sound_rad_3":
int radIndex = int.Parse(key.Replace("spelleffect_sound_rad_", ""));
if (grp.SpellEffectSounds[--radIndex] != null)
{
float rad = float.Parse(value, CultureInfo.InvariantCulture);
grp.SpellEffectSounds[radIndex].SoundRadius = rad;
}
break;
case "spelleffect_sound_delay_1":
case "spelleffect_sound_delay_2":
case "spelleffect_sound_delay_3":
int delayIndex = int.Parse(key.Replace("spelleffect_sound_delay_", ""));
if (grp.SpellEffectSounds[--delayIndex] != null)
{
float delay = float.Parse(value, CultureInfo.InvariantCulture);
grp.SpellEffectSounds[delayIndex].SoundDelay = delay;
}
break;
case "shoteffect_sound_1":
case "shoteffect_sound_2":
case "shoteffect_sound_3":
if (value != "None")
{
int index = int.Parse(key.Replace("shoteffect_sound_", ""), CultureInfo.InvariantCulture);
grp.ShotEffectSounds[--index] = new SkillSound();
grp.ShotEffectSounds[index].SoundEvent = value;
}
break;
case "shoteffect_sound_vol_1":
case "shoteffect_sound_vol_2":
case "shoteffect_sound_vol_3":
int volIndex2 = int.Parse(key.Replace("shoteffect_sound_vol_", ""));
if (grp.ShotEffectSounds[--volIndex2] != null)
{
float vol = float.Parse(value, CultureInfo.InvariantCulture);
grp.ShotEffectSounds[volIndex2].SoundVolune = vol;
}
break;
case "shoteffect_sound_rad_1":
case "shoteffect_sound_rad_2":
case "shoteffect_sound_rad_3":
int radIndex2 = int.Parse(key.Replace("shoteffect_sound_rad_", ""));
if (grp.ShotEffectSounds[--radIndex2] != null)
{
float rad = float.Parse(value, CultureInfo.InvariantCulture);
grp.ShotEffectSounds[radIndex2].SoundRadius = rad;
}
break;
case "shoteffect_sound_delay_1":
case "shoteffect_sound_delay_2":
case "shoteffect_sound_delay_3":
int delayIndex2 = int.Parse(key.Replace("shoteffect_sound_delay_", ""));
if (grp.ShotEffectSounds[--delayIndex2] != null)
{
float delay = float.Parse(value, CultureInfo.InvariantCulture);
grp.ShotEffectSounds[delayIndex2].SoundDelay = delay;
}
break;
case "mfighter_cast":
case "ffighter_cast":
case "mmagic_cast":
case "fmagic_cast":
case "melf_cast":
case "felf_cast":
case "mdarkelf_cast":
case "fdarkelf_cast":
case "mdwarf_cast":
case "fdwarf_cast":
case "morc_cast":
case "forc_cast":
case "mshaman_cast":
case "fshaman_cast":
// case "mkamael_cast":
// case "fkamael_cast":
// case "mertheia_cast":
// case "fertheia_cast":
if (value != "None")
{
CharacterModelType modelType = CharacterModelTypeParser.ParseRace(key.Replace("_cast", ""));
grp.CastingVoices[(int)modelType] = value;
}
break;
case "mfighter_magic":
case "ffighter_magic":
case "mmagic_magic":
case "fmagic_magic":
case "melf_magic":
case "felf_magic":
case "mdarkelf_magic":
case "fdarkelf_magic":
case "mdwarf_magic":
case "fdwarf_magic":
case "morc_magic":
case "forc_magic":
case "mshaman_magic":
case "fshaman_magic":
// case "mkamael_magic":
// case "fkamael_magic":
// case "mertheia_magic":
// case "fertheia_magic":
if (value != "None")
{
CharacterModelType modelType = CharacterModelTypeParser.ParseRace(key.Replace("_magic", ""));
grp.CastingEndVoices[(int)modelType] = value;
}
break;
case "cast_volune":
grp.CastVolume = float.Parse(value, CultureInfo.InvariantCulture);
break;
case "cast_rad":
grp.CastRadius = float.Parse(value, CultureInfo.InvariantCulture);
break;
}
}

_data.TryAdd(grp.SkillId, grp);
}
Debug.Log($"Successfully imported {_data.Count} SkillSoundGrp(s)");
}
}

public SkillSoundgrp GetSkillSoundGrp(int key)
{
SkillSoundgrp skillSoundgrp;
_data.TryGetValue(key, out skillSoundgrp);

if (skillSoundgrp == null)
{
Debug.LogWarning($"SkillsoundGrp is null for skillId: {key}.");
}

return skillSoundgrp;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion l2-unity/Assets/Scripts/Datatable/SkillTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public void CacheSkills()
skillgrpArray[i] = skillgrp[i + 1];
}

Skill skill = new Skill(kvp.Key, skillNameArray, skillgrpArray);
SkillSoundgrp skillSoundgrp = SkillSoundgrpTable.Instance.GetSkillSoundGrp(kvp.Key);

Skill skill = new Skill(kvp.Key, skillNameArray, skillgrpArray, skillSoundgrp);
Skills.Add(kvp.Key, skill);

Debug.LogWarning($"ID:{skill.SkillNameDatas[0].Id} Name:{skill.SkillNameDatas[0].Name} Effect:{skill.EffectId}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

public enum CharacterModelType : byte
{
FElf = 0,
Expand Down Expand Up @@ -50,4 +52,9 @@ public static CharacterModelType ParseRace(CharacterRace race, byte sex, bool is
return CharacterModelType.FDwarf;
}
}

public static CharacterModelType ParseRace(string value)
{
return (CharacterModelType)Enum.Parse(typeof(CharacterModelType), value, ignoreCase: true);
}
}
1 change: 1 addition & 0 deletions l2-unity/Assets/Scripts/Game/Manager/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private void Start()

private void LoadTables()
{
SkillSoundgrpTable.Instance.Initialize();
SkillTable.Instance.Initialize();
ItemTable.Instance.Initialize();
ItemNameTable.Instance.Initialize();
Expand Down
4 changes: 3 additions & 1 deletion l2-unity/Assets/Scripts/Game/Skill/Skill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ public class Skill
public SkillNameData[] SkillNameDatas { get; private set; }
public Skillgrp[] Skillgrps { get; private set; }
public L2SkillEffect SkillEffect { get; set; }
public SkillSoundgrp SkillSoundgrp { get; private set; }

public Skill(int skillId, SkillNameData[] skillNameDatas, Skillgrp[] skillgrps)
public Skill(int skillId, SkillNameData[] skillNameDatas, Skillgrp[] skillgrps, SkillSoundgrp skillSoundgrp)
{
SkillId = skillId;
SkillNameDatas = skillNameDatas;
Skillgrps = skillgrps;
SkillSoundgrp = skillSoundgrp;
}
}
1 change: 1 addition & 0 deletions l2-unity/Assets/Scripts/Tools/TestRoom/GameManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void Awake()

private void LoadTables()
{
SkillSoundgrpTable.Instance.Initialize();
SkillTable.Instance.Initialize();
ItemTable.Instance.Initialize();
ItemNameTable.Instance.Initialize();
Expand Down
Loading

0 comments on commit 720070f

Please sign in to comment.