Worms4Editor/LibW4M/Data/WeaponFactory/WeaponData.cs

215 lines
8.2 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 WeaponData : SaveDataEntry
{
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;
public WeaponData(W4SaveFile fileBelongs, XomContainer mainContainer, bool load=true) : base(fileBelongs, mainContainer, load)
{
}
public override string FriendlyName
{
get
{
return this.Name.Value;
}
}
public override void Save()
{
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);
mainContainer.SetData(ms.ToArray());
}
}
}
internal override void loadDefaults()
{
this.Name = this.fileBelongs.LookupString("Untitled Weapon");
this.Type = 0;
this.DetonationType = DetonationType.Impact;
this.Homing = false;
this.HomingAvoidLand = false;
this.Poison = false;
this.EffectedByWind = true;
this.FireOnGround = false;
this.RetreatTime = -1;
this.WormDamageRadius = 0.75f;
this.WormDamageMagnitude = 0.5f;
this.LandDamageRadius = 0.5f;
this.Push = 0.5f;
this.ProjectileCollisionRadius = 1.0f;
this.FuseTime = -1;
this.GraphicalResources = new XomString[4] { this.fileBelongs.LookupString("Factory.TankGunBody"), this.fileBelongs.LookupString("Factory.TankGunBarrel"), this.fileBelongs.LookupString("Factory.TankGunButt"), this.fileBelongs.LookupString("Factory.TankGunSight") };
this.GraphicalLocators = new XomString[4] { this.fileBelongs.LookupString("TANK_body_locator"), this.fileBelongs.LookupString("TANK_barrel_root_locator"), this.fileBelongs.LookupString("TANK_butt_root_locator"), this.fileBelongs.LookupString("TANK_sight_root_locator") };
this.LaunchFX = this.fileBelongs.LookupString("");
this.ArielFX = this.fileBelongs.LookupString("WXP_BazookaTrailPack");
this.DetonationFX = this.fileBelongs.LookupString("WXP_ExplosionX_Med");
this.PayloadResourceId = 55;
this.ProjectileLaunchType = ProjectileLaunchType.Launched;
this.ProjectilePowersUp = true;
this.ProjectileNumClusters = 0;
this.ProjectileMaxPower = 0.5f;
this.ClusterSpread = 0.300000012f;
this.ClusterMaxSpeed = 0.0f;
base.loadDefaults();
}
public override void Load()
{
using (XomStreamReader reader = new XomStreamReader(new MemoryStream(this.mainContainer.GetData())))
{
reader.Skip(3);
this.Name = this.fileBelongs.LookupStringFromId(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.
this.GraphicalResources = this.fileBelongs.IntArrayToXomStringArray(reader.ReadCompressedIntArray());
// Read graphical locators list.
this.GraphicalLocators = this.fileBelongs.IntArrayToXomStringArray(reader.ReadCompressedIntArray());
this.LaunchFX = this.fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
this.ArielFX = this.fileBelongs.LookupStringFromId(reader.ReadCompressedInt());
this.DetonationFX = this.fileBelongs.LookupStringFromId(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();
}
}
}
}