Worms4Editor/LibW4M/Data/WeaponFactory/WeaponData.cs

154 lines
5.3 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
{
internal class WeaponData
{
private XomFile saveFile;
private XomString WeaponName;
public int Type;
public Detonation 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 int[] GraphicalResourceIds;
public int[] GraphicalLocatorIds;
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 (XomStreamWriter writer = new XomStreamWriter(new MemoryStream()))
{
writer.Skip(3);
writer.WriteCompressedInt(this.WeaponName.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);
writer.WriteCompressedIntArray(this.GraphicalResourceIds);
writer.WriteCompressedIntArray(this.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);
writer.Skip(1);
writer.BaseStream.Seek(0x00, SeekOrigin.Begin);
MemoryStream ms = (MemoryStream)(writer.BaseStream).ToArray();
}
}
internal void deserailize(byte[] data)
{
using (XomStreamReader reader = new XomStreamReader(new MemoryStream(data)))
{
reader.Skip(3);
this.WeaponName = saveFile.GetStringById(reader.ReadCompressedInt());
this.Type = reader.ReadInt32();
this.DetonationType = (Detonation)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();
this.GraphicalResourceIds = reader.ReadCompressedIntArray();
this.GraphicalLocatorIds = reader.ReadCompressedIntArray();
this.LaunchFX = saveFile.GetStringById(reader.ReadCompressedInt());
this.ArielFX = saveFile.GetStringById(reader.ReadCompressedInt());
this.DetonationFX = saveFile.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();
reader.Skip(1);
}
}
internal WeaponData(byte[] data, XomFile saveFile)
{
this.saveFile = saveFile;
this.deserailize(data);
}
}
}