193 lines
7.4 KiB
C#
193 lines
7.4 KiB
C#
using LibW4M.Data.WeaponFactory;
|
|
using LibXom.Data;
|
|
using LibXom.Streams;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LibW4M.Data.Teams
|
|
{
|
|
public class TeamData : SaveDataEntry
|
|
{
|
|
|
|
public override string FriendlyName
|
|
{
|
|
get
|
|
{
|
|
return Name.Value;
|
|
}
|
|
}
|
|
|
|
private string secretWeaponUuid;
|
|
private string secretWeaponClusterUuid;
|
|
|
|
public WeaponData SecretWeapon
|
|
{
|
|
get
|
|
{
|
|
WeaponData? data = fileBelongs.WeaponFactoryCollective.findWeaponWithContainerUuid(secretWeaponUuid);
|
|
if (data is null) return new WeaponData(fileBelongs, fileBelongs.LookupContainerByUuid(secretWeaponUuid));
|
|
return data;
|
|
}
|
|
set
|
|
{
|
|
this.secretWeaponUuid = value.mainContainer.Uuid;
|
|
}
|
|
}
|
|
public WeaponData SecretWeaponCluster
|
|
{
|
|
get
|
|
{
|
|
WeaponData? data = fileBelongs.WeaponFactoryCollective.findWeaponWithContainerUuid(secretWeaponClusterUuid);
|
|
if(data is null) return new WeaponData(fileBelongs, fileBelongs.LookupContainerByUuid(secretWeaponClusterUuid));
|
|
return data;
|
|
}
|
|
set
|
|
{
|
|
this.secretWeaponClusterUuid = value.mainContainer.Uuid;
|
|
}
|
|
}
|
|
|
|
public XomString Name;
|
|
public XomString[] Worms;
|
|
public int TutorialsDone;
|
|
public int NewTeam;
|
|
public SkillLevel Skill;
|
|
public int Grave;
|
|
public int SWeapon;
|
|
public XomString Flag;
|
|
public XomString Speech;
|
|
public bool InGame;
|
|
public bool AllTutorialsDone;
|
|
public bool AllMissionsDone;
|
|
public XomString Player;
|
|
public XomString CustomWeapon;
|
|
public XomString Hat;
|
|
public XomString Gloves;
|
|
public XomString Glasses;
|
|
public XomString Tash;
|
|
public int[] StoryMissionsCompleted;
|
|
public int StoryChapter;
|
|
public TeamData(W4SaveFile fileBelongs, XomContainer mainContainer) : base(fileBelongs, mainContainer)
|
|
{
|
|
}
|
|
|
|
public override void DeleteEntries()
|
|
{
|
|
// delete weapon if its not in weapon collective, and this is the last reference to it.
|
|
|
|
if(fileBelongs.WeaponFactoryCollective.findWeaponWithContainerUuid(secretWeaponUuid) is null)
|
|
{
|
|
bool delete = true;
|
|
|
|
foreach (TeamData team in fileBelongs.TeamDataColective)
|
|
{
|
|
if (team.Equals(this)) continue;
|
|
if (team.secretWeaponUuid.Equals(this.secretWeaponUuid, StringComparison.InvariantCultureIgnoreCase)) delete = false;
|
|
}
|
|
|
|
if (delete)
|
|
{
|
|
this.SecretWeapon.DeleteEntries();
|
|
}
|
|
}
|
|
|
|
// delete cluster if its not in weapon collective, and this is the last reference to it.
|
|
if (fileBelongs.WeaponFactoryCollective.findWeaponWithContainerUuid(secretWeaponClusterUuid) is null)
|
|
{
|
|
bool delete = true;
|
|
|
|
foreach (TeamData team in fileBelongs.TeamDataColective)
|
|
{
|
|
if (team.Equals(this)) continue;
|
|
if (team.secretWeaponClusterUuid.Equals(this.secretWeaponClusterUuid, StringComparison.InvariantCultureIgnoreCase)) delete = false;
|
|
}
|
|
|
|
if (delete)
|
|
{
|
|
this.SecretWeaponCluster.DeleteEntries();
|
|
}
|
|
}
|
|
|
|
base.DeleteEntries();
|
|
}
|
|
|
|
public override void Load()
|
|
{
|
|
using (XomStreamReader reader = new XomStreamReader(new MemoryStream(this.mainContainer.GetData())))
|
|
{
|
|
reader.Skip(3);
|
|
|
|
this.Name = fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
|
|
this.Worms = fileBelongs.IntArrayToXomStringArray(reader.ReadCompressedIntArray());
|
|
this.TutorialsDone = reader.ReadInt32();
|
|
this.NewTeam = reader.ReadInt32();
|
|
this.Skill = (SkillLevel)reader.ReadInt32();
|
|
this.Grave = reader.ReadInt32();
|
|
this.SWeapon = reader.ReadInt32();
|
|
this.Flag = fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
|
|
this.Speech = fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
|
|
this.InGame = reader.ReadBool();
|
|
this.AllTutorialsDone = reader.ReadBool();
|
|
this.AllMissionsDone = reader.ReadBool();
|
|
this.Player = fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
|
|
|
|
this.secretWeaponUuid = fileBelongs.LookupContainerById(reader.ReadCompressedInt()).Uuid;
|
|
this.secretWeaponClusterUuid = fileBelongs.LookupContainerById(reader.ReadCompressedInt()).Uuid;
|
|
|
|
this.CustomWeapon = fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
|
|
|
|
this.Hat = fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
|
|
this.Gloves = fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
|
|
this.Glasses = fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
|
|
this.Tash = fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
|
|
|
|
this.StoryMissionsCompleted = reader.ReadInt32Array();
|
|
this.StoryChapter = reader.ReadInt32();
|
|
}
|
|
}
|
|
|
|
public override void Save()
|
|
{
|
|
using (MemoryStream ms = new MemoryStream())
|
|
{
|
|
using (XomStreamWriter writer = new XomStreamWriter(ms))
|
|
{
|
|
writer.Skip(3);
|
|
|
|
writer.WriteCompressedInt(this.Name.Id);
|
|
writer.WriteCompressedIntArray(this.fileBelongs.XomStringArrayToIntArray(this.Worms));
|
|
writer.WriteInt32(this.TutorialsDone);
|
|
writer.WriteInt32(this.NewTeam);
|
|
writer.WriteInt32((int)this.Skill);
|
|
writer.WriteInt32(this.Grave);
|
|
writer.WriteInt32(this.SWeapon);
|
|
writer.WriteCompressedInt(this.Flag.Id);
|
|
writer.WriteCompressedInt(this.Speech.Id);
|
|
writer.WriteBool(this.InGame);
|
|
writer.WriteBool(this.AllTutorialsDone);
|
|
writer.WriteBool(this.AllMissionsDone);
|
|
writer.WriteCompressedInt(this.Player.Id);
|
|
|
|
writer.WriteCompressedInt(this.SecretWeapon.containerId);
|
|
writer.WriteCompressedInt(this.SecretWeaponCluster.containerId);
|
|
writer.WriteCompressedInt(this.CustomWeapon.Id);
|
|
|
|
writer.WriteCompressedInt(this.Hat.Id);
|
|
writer.WriteCompressedInt(this.Gloves.Id);
|
|
writer.WriteCompressedInt(this.Glasses.Id);
|
|
writer.WriteCompressedInt(this.Tash.Id);
|
|
|
|
writer.WriteInt32Array(this.StoryMissionsCompleted);
|
|
writer.WriteInt32(this.StoryChapter);
|
|
|
|
ms.Seek(0x00, SeekOrigin.Begin);
|
|
mainContainer.SetData(ms.ToArray());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|