133 lines
4.5 KiB
C#
133 lines
4.5 KiB
C#
using LibW4M.Data.Teams;
|
|
using LibXom.Data;
|
|
using LibXom.Streams;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LibW4M.Data.WeaponFactory
|
|
{
|
|
public class WeaponStore : SaveDataEntry
|
|
{
|
|
|
|
public WeaponData Weapon;
|
|
public WeaponData Cluster;
|
|
public bool StockWeapon;
|
|
|
|
|
|
|
|
internal WeaponStore(W4SaveFile fileBelongs, XomContainer mainContainer, bool load=true) : base(fileBelongs, mainContainer, load)
|
|
{
|
|
|
|
}
|
|
|
|
public override void Load()
|
|
{
|
|
using (XomStreamReader reader = new XomStreamReader(new MemoryStream(mainContainer.GetData())))
|
|
{
|
|
reader.Skip(3);
|
|
|
|
this.StockWeapon = reader.ReadBool();
|
|
this.Weapon = new WeaponData(this.fileBelongs, this.fileBelongs.LookupContainerById(reader.ReadCompressedInt()));
|
|
this.Cluster = new WeaponData(this.fileBelongs, this.fileBelongs.LookupContainerById(reader.ReadCompressedInt()));
|
|
}
|
|
}
|
|
|
|
public override void Save()
|
|
{
|
|
this.Weapon.Save();
|
|
this.Cluster.Save();
|
|
using (MemoryStream ms = new MemoryStream())
|
|
{
|
|
using (XomStreamWriter writer = new XomStreamWriter(ms))
|
|
{
|
|
writer.Skip(3);
|
|
|
|
writer.WriteBool(this.StockWeapon);
|
|
writer.WriteCompressedInt(this.Weapon.mainContainer.Id);
|
|
writer.WriteCompressedInt(this.Cluster.mainContainer.Id);
|
|
|
|
ms.Seek(0x00, SeekOrigin.Begin);
|
|
mainContainer.SetData(ms.ToArray());
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
internal override void loadDefaults()
|
|
{
|
|
this.StockWeapon = false;
|
|
this.Weapon = new WeaponData(this.fileBelongs, this.fileBelongs.CreateContainer("WeaponFactoryContainer"), false);
|
|
this.Cluster = new WeaponData(this.fileBelongs, this.fileBelongs.CreateContainer("WeaponFactoryContainer"), false);
|
|
|
|
// Clusters should have different defaults, lets just go fix that :)
|
|
this.Cluster.Name = this.fileBelongs.LookupString("");
|
|
this.Cluster.Type = 1;
|
|
this.Cluster.DetonationType = DetonationType.Impact;
|
|
|
|
this.Cluster.Homing = false;
|
|
this.Cluster.HomingAvoidLand = false;
|
|
this.Cluster.Poison = false;
|
|
this.Cluster.EffectedByWind = false;
|
|
this.Cluster.FireOnGround = false;
|
|
|
|
this.Cluster.RetreatTime = 0;
|
|
|
|
this.Cluster.WormDamageRadius = 0.75f;
|
|
|
|
this.Cluster.WormDamageMagnitude = 0.5f;
|
|
this.Cluster.LandDamageRadius = 0.5f;
|
|
this.Cluster.Push = 0.5f;
|
|
|
|
this.Cluster.ProjectileCollisionRadius = 1.0f;
|
|
this.Cluster.FuseTime = -1;
|
|
|
|
this.Cluster.GraphicalResources = new XomString[0];
|
|
this.Cluster.GraphicalLocators = new XomString[0];
|
|
|
|
this.Cluster.LaunchFX = this.fileBelongs.LookupString("");
|
|
this.Cluster.ArielFX = this.fileBelongs.LookupString("");
|
|
this.Cluster.DetonationFX = this.fileBelongs.LookupString("WXP_ExploCluster");
|
|
|
|
this.Cluster.PayloadResourceId = 16;
|
|
this.Cluster.ProjectileLaunchType = ProjectileLaunchType.Thrown;
|
|
this.Cluster.ProjectilePowersUp = false;
|
|
this.Cluster.ProjectileNumClusters = 0;
|
|
this.Cluster.ProjectileMaxPower = 0.0f;
|
|
this.Cluster.ClusterSpread = 0.5f;
|
|
this.Cluster.ClusterMaxSpeed = 0.0f;
|
|
|
|
base.loadDefaults();
|
|
}
|
|
|
|
public override void DeleteEntries()
|
|
{
|
|
bool clusterUsed = false;
|
|
bool weaponUsed = false;
|
|
|
|
foreach (TeamData team in fileBelongs.TeamDataColective)
|
|
{
|
|
if (team.SecretWeapon.Equals(this.Weapon)) weaponUsed = true;
|
|
if (team.SecretWeaponCluster.Equals(this.Cluster)) clusterUsed = true;
|
|
}
|
|
|
|
if (!clusterUsed) { this.Cluster.DeleteEntries(); }
|
|
if (!weaponUsed) { this.Weapon.DeleteEntries(); }
|
|
|
|
base.DeleteEntries();
|
|
}
|
|
|
|
public override string FriendlyName
|
|
{
|
|
get
|
|
{
|
|
return Weapon.Name.Value;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|