2017-09-21 18:33:05 +08:00
|
|
|
|
using SharpDX;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CodeWalker.GameFiles
|
|
|
|
|
{
|
|
|
|
|
[TypeConverter(typeof(ExpandableObjectConverter))]
|
|
|
|
|
public class Archetype
|
|
|
|
|
{
|
2017-09-28 12:28:09 +08:00
|
|
|
|
public virtual MetaName Type => MetaName.CBaseArchetypeDef;
|
|
|
|
|
|
|
|
|
|
public CBaseArchetypeDef _BaseArchetypeDef;
|
|
|
|
|
public CBaseArchetypeDef BaseArchetypeDef { get { return _BaseArchetypeDef; } set { _BaseArchetypeDef = value; } }
|
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
public MetaHash Hash { get; set; }
|
|
|
|
|
public YtypFile Ytyp { get; set; }
|
|
|
|
|
public MetaHash DrawableDict { get; set; }
|
|
|
|
|
public MetaHash TextureDict { get; set; }
|
|
|
|
|
public MetaHash ClipDict { get; set; }
|
|
|
|
|
public Vector3 BBMin { get; set; }
|
|
|
|
|
public Vector3 BBMax { get; set; }
|
|
|
|
|
public Vector3 BSCenter { get; set; }
|
|
|
|
|
public float BSRadius { get; set; }
|
|
|
|
|
public float LodDist { get; set; }
|
|
|
|
|
public MetaWrapper[] Extensions { get; set; }
|
2017-09-28 12:28:09 +08:00
|
|
|
|
|
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-09-28 12:28:09 +08:00
|
|
|
|
return _BaseArchetypeDef.name.ToString();
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public string AssetName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-09-28 12:28:09 +08:00
|
|
|
|
return _BaseArchetypeDef.assetName.ToString();
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 12:28:09 +08:00
|
|
|
|
|
|
|
|
|
protected void InitVars(ref CBaseArchetypeDef arch)
|
2017-09-21 18:33:05 +08:00
|
|
|
|
{
|
2017-09-28 12:28:09 +08:00
|
|
|
|
BaseArchetypeDef = arch;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
Hash = arch.assetName;
|
|
|
|
|
if (Hash.Hash == 0) Hash = arch.name;
|
|
|
|
|
DrawableDict = arch.drawableDictionary;
|
|
|
|
|
TextureDict = arch.textureDictionary;
|
|
|
|
|
ClipDict = arch.clipDictionary;
|
|
|
|
|
BBMin = arch.bbMin;
|
|
|
|
|
BBMax = arch.bbMax;
|
|
|
|
|
BSCenter = arch.bsCentre;
|
|
|
|
|
BSRadius = arch.bsRadius;
|
2017-09-28 00:24:21 +08:00
|
|
|
|
LodDist = arch.lodDist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Init(YtypFile ytyp, ref CBaseArchetypeDef arch)
|
|
|
|
|
{
|
|
|
|
|
Ytyp = ytyp;
|
|
|
|
|
InitVars(ref arch);
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
2017-09-28 12:28:09 +08:00
|
|
|
|
|
|
|
|
|
public virtual bool IsActive(float hour)
|
2017-09-21 18:33:05 +08:00
|
|
|
|
{
|
2017-09-28 12:28:09 +08:00
|
|
|
|
return true;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
2017-09-28 12:28:09 +08:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return _BaseArchetypeDef.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TypeConverter(typeof(ExpandableObjectConverter))]
|
|
|
|
|
public class TimeArchetype : Archetype
|
|
|
|
|
{
|
|
|
|
|
public override MetaName Type => MetaName.CTimeArchetypeDef;
|
|
|
|
|
|
|
|
|
|
public CTimeArchetypeDefData _TimeArchetypeDef;
|
|
|
|
|
public CTimeArchetypeDefData TimeArchetypeDef { get { return _TimeArchetypeDef; } set { _TimeArchetypeDef = value; } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public uint TimeFlags { get; set; }
|
|
|
|
|
public bool[] ActiveHours { get; set; }
|
|
|
|
|
public string[] ActiveHoursText { get; set; }
|
|
|
|
|
public bool ExtraFlag { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Init(YtypFile ytyp, ref CTimeArchetypeDef arch)
|
2017-09-21 18:33:05 +08:00
|
|
|
|
{
|
|
|
|
|
Ytyp = ytyp;
|
2017-09-28 00:24:21 +08:00
|
|
|
|
InitVars(ref arch._BaseArchetypeDef);
|
2017-09-28 12:28:09 +08:00
|
|
|
|
TimeArchetypeDef = arch.TimeArchetypeDef;
|
|
|
|
|
|
|
|
|
|
TimeFlags = _TimeArchetypeDef.timeFlags;
|
|
|
|
|
ActiveHours = new bool[24];
|
|
|
|
|
ActiveHoursText = new string[24];
|
|
|
|
|
for (int i = 0; i < 24; i++)
|
|
|
|
|
{
|
|
|
|
|
bool v = ((TimeFlags >> i) & 1) == 1;
|
|
|
|
|
ActiveHours[i] = v;
|
|
|
|
|
|
|
|
|
|
int nxth = (i < 23) ? (i + 1) : 0;
|
|
|
|
|
string hrs = string.Format("{0:00}:00 - {1:00}:00", i, nxth);
|
|
|
|
|
ActiveHoursText[i] = (hrs + (v ? " - On" : " - Off"));
|
|
|
|
|
}
|
|
|
|
|
ExtraFlag = ((TimeFlags >> 24) & 1) == 1;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 12:28:09 +08:00
|
|
|
|
public override bool IsActive(float hour)
|
2017-09-21 18:33:05 +08:00
|
|
|
|
{
|
2017-09-28 12:28:09 +08:00
|
|
|
|
if (ActiveHours == null) return true;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
int h = ((int)hour) % 24;
|
|
|
|
|
if ((h < 0) || (h > 23)) return true;
|
2017-09-28 12:28:09 +08:00
|
|
|
|
return ActiveHours[h];
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 12:28:09 +08:00
|
|
|
|
public class MloArchetype : Archetype
|
2017-09-21 18:33:05 +08:00
|
|
|
|
{
|
2017-09-28 12:28:09 +08:00
|
|
|
|
public override MetaName Type => MetaName.CMloArchetypeDef;
|
|
|
|
|
|
|
|
|
|
public CMloArchetypeDefData _MloArchetypeDef;
|
|
|
|
|
public CMloArchetypeDefData MloArchetypeDef { get { return _MloArchetypeDef; } set { _MloArchetypeDef = value; } }
|
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
public CEntityDef[] entities { get; set; }
|
|
|
|
|
public CMloRoomDef[] rooms { get; set; }
|
|
|
|
|
public CMloPortalDef[] portals { get; set; }
|
|
|
|
|
public CMloEntitySet[] entitySets { get; set; }
|
|
|
|
|
public CMloTimeCycleModifier[] timeCycleModifiers { get; set; }
|
2017-09-28 12:28:09 +08:00
|
|
|
|
|
|
|
|
|
public void Init(YtypFile ytyp, ref CMloArchetypeDef arch)
|
|
|
|
|
{
|
|
|
|
|
Ytyp = ytyp;
|
|
|
|
|
InitVars(ref arch._BaseArchetypeDef);
|
|
|
|
|
MloArchetypeDef = arch.MloArchetypeDef;
|
|
|
|
|
}
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 12:28:09 +08:00
|
|
|
|
|
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
[TypeConverter(typeof(ExpandableObjectConverter))]
|
2017-09-28 00:24:21 +08:00
|
|
|
|
public class MloInstanceData
|
2017-09-21 18:33:05 +08:00
|
|
|
|
{
|
2017-09-28 00:24:21 +08:00
|
|
|
|
public YmapEntityDef Owner { get; set; }
|
|
|
|
|
public CMloInstanceDef _Instance;
|
|
|
|
|
public CMloInstanceDef Instance { get { return _Instance; } set { _Instance = value; } }
|
|
|
|
|
public uint[] Unk_1407157833 { get; set; }
|
|
|
|
|
|
|
|
|
|
public YmapEntityDef[] Entities { get; set; }
|
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
|
2017-09-28 12:28:09 +08:00
|
|
|
|
public void CreateYmapEntities(YmapEntityDef owner, MloArchetype mloa)
|
2017-09-21 18:33:05 +08:00
|
|
|
|
{
|
2017-09-28 00:24:21 +08:00
|
|
|
|
Owner = owner;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
if (owner == null) return;
|
2017-09-28 12:28:09 +08:00
|
|
|
|
if (mloa.entities == null) return;
|
|
|
|
|
var ec = mloa.entities.Length;
|
2017-09-28 00:24:21 +08:00
|
|
|
|
Entities = new YmapEntityDef[ec];
|
|
|
|
|
for (int i = 0; i < ec; i++)
|
2017-09-21 18:33:05 +08:00
|
|
|
|
{
|
2017-09-28 12:28:09 +08:00
|
|
|
|
YmapEntityDef e = new YmapEntityDef(null, i, ref mloa.entities[i]);
|
2017-09-28 00:24:21 +08:00
|
|
|
|
e.MloRefPosition = e.Position;
|
|
|
|
|
e.MloRefOrientation = e.Orientation;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
e.MloParent = owner;
|
2017-09-28 00:24:21 +08:00
|
|
|
|
e.Position = owner.Position + owner.Orientation.Multiply(e.MloRefPosition);
|
|
|
|
|
e.Orientation = Quaternion.Multiply(owner.Orientation, e.MloRefOrientation);
|
2017-09-21 18:33:05 +08:00
|
|
|
|
e.UpdateWidgetPosition();
|
|
|
|
|
e.UpdateWidgetOrientation();
|
2017-09-28 00:24:21 +08:00
|
|
|
|
Entities[i] = e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-21 18:33:05 +08:00
|
|
|
|
|
|
|
|
|
|
2017-09-28 00:24:21 +08:00
|
|
|
|
public void UpdateEntities()
|
|
|
|
|
{
|
|
|
|
|
if (Entities == null) return;
|
|
|
|
|
if (Owner == null) return;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Entities.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
YmapEntityDef e = Entities[i];
|
|
|
|
|
e.Position = Owner.Position + Owner.Orientation.Multiply(e.MloRefPosition);
|
|
|
|
|
e.Orientation = Quaternion.Multiply(Owner.Orientation, e.MloRefOrientation);
|
|
|
|
|
e.UpdateWidgetPosition();
|
|
|
|
|
e.UpdateWidgetOrientation();
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
2017-09-28 00:24:21 +08:00
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
2017-09-28 00:24:21 +08:00
|
|
|
|
|
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 00:24:21 +08:00
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|