Worms4Editor/LibW4M/Data/WeaponFactory/WeaponContainer.cs

182 lines
6.8 KiB
C#

using LibXom.Data;
using LibXom.Streams;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace LibW4M.Data.WeaponFactory
{
public class WeaponContainer
{
private W4SaveFile saveFile;
public W4SaveFile OriginalSave
{
get
{
return this.saveFile;
}
}
public XomString Name;
public int Type;
public DetonationType DetonationType;
public bool Homing;
public bool HomingAvoidLand;
public bool EffectedByWind;
public bool FireOnGround;
public bool Poison;
public int RetreatTime;
public float WormDamageRadius;
public float WormDamageMagnitude;
public float LandDamageRadius;
public float ProjectileCollisionRadius;
public float Push;
public int FuseTime;
public XomString[] GraphicalResources;
public XomString[] GraphicalLocators;
public XomString LaunchFX;
public XomString ArielFX;
public XomString DetonationFX;
public int PayloadResourceId;
public ProjectileLaunchType ProjectileLaunchType;
public bool ProjectilePowersUp;
public int ProjectileNumClusters;
public float ProjectileMaxPower;
public float ClusterSpread;
public float ClusterMaxSpeed;
internal byte[] serialize()
{
using (MemoryStream ms = new MemoryStream())
{
using (XomStreamWriter writer = new XomStreamWriter(ms))
{
writer.Skip(3);
writer.WriteCompressedInt(this.Name.Id);
writer.WriteInt32(this.Type);
writer.WriteInt32((int)this.DetonationType);
writer.WriteBool(this.Homing);
writer.WriteBool(this.HomingAvoidLand);
writer.WriteBool(this.EffectedByWind);
writer.WriteBool(this.FireOnGround);
writer.WriteBool(this.Poison);
writer.WriteInt32(this.RetreatTime);
writer.WriteFloat(this.WormDamageRadius);
writer.WriteFloat(this.WormDamageMagnitude);
writer.WriteFloat(this.LandDamageRadius);
writer.WriteFloat(this.ProjectileCollisionRadius);
writer.WriteFloat(this.Push);
writer.WriteInt32(this.FuseTime);
// Write Graphical Resources list
int[] graphicalResourceIds = new int[this.GraphicalResources.Length];
for (int i = 0; i < graphicalResourceIds.Length; i++)
graphicalResourceIds[i] = this.GraphicalResources[i].Id;
writer.WriteCompressedIntArray(graphicalResourceIds);
// Write Graphical Locators list
int[] graphicalLocatorIds = new int[this.GraphicalLocators.Length];
for (int i = 0; i < graphicalLocatorIds.Length; i++)
graphicalLocatorIds[i] = this.GraphicalLocators[i].Id;
writer.WriteCompressedIntArray(graphicalLocatorIds);
writer.WriteCompressedInt(this.LaunchFX.Id);
writer.WriteCompressedInt(this.ArielFX.Id);
writer.WriteCompressedInt(this.DetonationFX.Id);
writer.WriteInt32(this.PayloadResourceId);
writer.WriteInt32((int)this.ProjectileLaunchType);
writer.WriteBool(this.ProjectilePowersUp);
writer.WriteInt32(this.ProjectileNumClusters);
writer.WriteFloat(this.ProjectileMaxPower);
writer.WriteFloat(this.ClusterSpread);
writer.WriteFloat(this.ClusterMaxSpeed);
ms.Seek(0x00, SeekOrigin.Begin);
return ms.ToArray();
}
}
}
internal void deserailize(byte[] data)
{
using (XomStreamReader reader = new XomStreamReader(new MemoryStream(data)))
{
reader.Skip(3);
this.Name = saveFile.xomFile.GetStringById(reader.ReadCompressedInt());
this.Type = reader.ReadInt32();
this.DetonationType = (DetonationType)reader.ReadInt32();
this.Homing = reader.ReadBool();
this.HomingAvoidLand = reader.ReadBool();
this.EffectedByWind = reader.ReadBool();
this.FireOnGround = reader.ReadBool();
this.Poison = reader.ReadBool();
this.RetreatTime = reader.ReadInt32();
this.WormDamageRadius = reader.ReadFloat();
this.WormDamageMagnitude = reader.ReadFloat();
this.LandDamageRadius = reader.ReadFloat();
this.ProjectileCollisionRadius = reader.ReadFloat();
this.Push = reader.ReadFloat();
this.FuseTime = reader.ReadInt32();
// Read graphical resources list.
int[] graphicalResourceIds = reader.ReadCompressedIntArray();
this.GraphicalResources = new XomString[graphicalResourceIds.Length];
for (int i = 0; i < graphicalResourceIds.Length; i++)
this.GraphicalResources[i] = saveFile.xomFile.GetStringById(graphicalResourceIds[i]);
// Read graphical locators list.
int[] graphicalLocatorIds = reader.ReadCompressedIntArray();
this.GraphicalLocators = new XomString[graphicalLocatorIds.Length];
for (int i = 0; i < graphicalLocatorIds.Length; i++)
this.GraphicalLocators[i] = saveFile.xomFile.GetStringById(graphicalLocatorIds[i]);
this.LaunchFX = saveFile.xomFile.GetStringById(reader.ReadCompressedInt());
this.ArielFX = saveFile.xomFile.GetStringById(reader.ReadCompressedInt());
this.DetonationFX = saveFile.xomFile.GetStringById(reader.ReadCompressedInt());
this.PayloadResourceId = reader.ReadInt32();
this.ProjectileLaunchType = (ProjectileLaunchType)reader.ReadInt32();
this.ProjectilePowersUp = reader.ReadBool();
this.ProjectileNumClusters = reader.ReadInt32();
this.ProjectileMaxPower = reader.ReadFloat();
this.ClusterSpread = reader.ReadFloat();
this.ClusterMaxSpeed = reader.ReadFloat();
}
}
internal WeaponContainer(byte[] data, W4SaveFile saveFile)
{
this.saveFile = saveFile;
this.deserailize(data);
}
}
}