211 lines
6.9 KiB
C#
211 lines
6.9 KiB
C#
using System;
|
|
using GeometryTD.Definition;
|
|
using UnityEngine;
|
|
|
|
namespace GeometryTD.CustomUtility
|
|
{
|
|
public static class InventoryCloneUtility
|
|
{
|
|
public static BackpackInventoryData CloneInventory(BackpackInventoryData source)
|
|
{
|
|
BackpackInventoryData cloned = new BackpackInventoryData();
|
|
if (source == null)
|
|
{
|
|
return cloned;
|
|
}
|
|
|
|
cloned.Gold = Mathf.Max(0, source.Gold);
|
|
|
|
if (source.MuzzleComponents != null)
|
|
{
|
|
for (int i = 0; i < source.MuzzleComponents.Count; i++)
|
|
{
|
|
MuzzleCompItemData item = source.MuzzleComponents[i];
|
|
if (item != null)
|
|
{
|
|
cloned.MuzzleComponents.Add(CloneMuzzleComp(item));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (source.BearingComponents != null)
|
|
{
|
|
for (int i = 0; i < source.BearingComponents.Count; i++)
|
|
{
|
|
BearingCompItemData item = source.BearingComponents[i];
|
|
if (item != null)
|
|
{
|
|
cloned.BearingComponents.Add(CloneBearingComp(item));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (source.BaseComponents != null)
|
|
{
|
|
for (int i = 0; i < source.BaseComponents.Count; i++)
|
|
{
|
|
BaseCompItemData item = source.BaseComponents[i];
|
|
if (item != null)
|
|
{
|
|
cloned.BaseComponents.Add(CloneBaseComp(item));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (source.Towers != null)
|
|
{
|
|
for (int i = 0; i < source.Towers.Count; i++)
|
|
{
|
|
TowerItemData item = source.Towers[i];
|
|
if (item != null)
|
|
{
|
|
cloned.Towers.Add(CloneTower(item));
|
|
}
|
|
}
|
|
}
|
|
|
|
if (source.ParticipantTowerInstanceIds != null)
|
|
{
|
|
for (int i = 0; i < source.ParticipantTowerInstanceIds.Count; i++)
|
|
{
|
|
long id = source.ParticipantTowerInstanceIds[i];
|
|
if (id > 0)
|
|
{
|
|
cloned.ParticipantTowerInstanceIds.Add(id);
|
|
}
|
|
}
|
|
}
|
|
|
|
return cloned;
|
|
}
|
|
|
|
public static MuzzleCompItemData CloneMuzzleComp(MuzzleCompItemData source)
|
|
{
|
|
if (source == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new MuzzleCompItemData
|
|
{
|
|
InstanceId = source.InstanceId,
|
|
ConfigId = source.ConfigId,
|
|
Name = source.Name,
|
|
Rarity = source.Rarity,
|
|
Endurance = source.Endurance,
|
|
IsAssembledIntoTower = source.IsAssembledIntoTower,
|
|
Constraint = source.Constraint,
|
|
Tags = CloneTags(source.Tags),
|
|
AttackDamage = CloneIntArray(source.AttackDamage),
|
|
DamageRandomRate = source.DamageRandomRate,
|
|
AttackMethodType = source.AttackMethodType
|
|
};
|
|
}
|
|
|
|
public static BearingCompItemData CloneBearingComp(BearingCompItemData source)
|
|
{
|
|
if (source == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BearingCompItemData
|
|
{
|
|
InstanceId = source.InstanceId,
|
|
ConfigId = source.ConfigId,
|
|
Name = source.Name,
|
|
Rarity = source.Rarity,
|
|
Endurance = source.Endurance,
|
|
IsAssembledIntoTower = source.IsAssembledIntoTower,
|
|
Constraint = source.Constraint,
|
|
Tags = CloneTags(source.Tags),
|
|
RotateSpeed = CloneFloatArray(source.RotateSpeed),
|
|
AttackRange = CloneFloatArray(source.AttackRange)
|
|
};
|
|
}
|
|
|
|
public static BaseCompItemData CloneBaseComp(BaseCompItemData source)
|
|
{
|
|
if (source == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new BaseCompItemData
|
|
{
|
|
InstanceId = source.InstanceId,
|
|
ConfigId = source.ConfigId,
|
|
Name = source.Name,
|
|
Rarity = source.Rarity,
|
|
Endurance = source.Endurance,
|
|
IsAssembledIntoTower = source.IsAssembledIntoTower,
|
|
Constraint = source.Constraint,
|
|
Tags = CloneTags(source.Tags),
|
|
AttackSpeed = CloneFloatArray(source.AttackSpeed),
|
|
AttackPropertyType = source.AttackPropertyType
|
|
};
|
|
}
|
|
|
|
public static TowerItemData CloneTower(TowerItemData source)
|
|
{
|
|
if (source == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new TowerItemData
|
|
{
|
|
InstanceId = source.InstanceId,
|
|
Name = source.Name,
|
|
Rarity = source.Rarity,
|
|
IsParticipatingInCombat = source.IsParticipatingInCombat,
|
|
MuzzleComponentInstanceId = source.MuzzleComponentInstanceId,
|
|
BearingComponentInstanceId = source.BearingComponentInstanceId,
|
|
BaseComponentInstanceId = source.BaseComponentInstanceId,
|
|
Stats = CloneTowerStats(source.Stats),
|
|
ComposedIconSprite = source.ComposedIconSprite,
|
|
ComposedIconKey = source.ComposedIconKey
|
|
};
|
|
}
|
|
|
|
public static TowerStatsData CloneTowerStats(TowerStatsData source)
|
|
{
|
|
if (source == null)
|
|
{
|
|
return new TowerStatsData();
|
|
}
|
|
|
|
return new TowerStatsData
|
|
{
|
|
AttackDamage = CloneIntArray(source.AttackDamage),
|
|
DamageRandomRate = source.DamageRandomRate,
|
|
RotateSpeed = CloneFloatArray(source.RotateSpeed),
|
|
AttackRange = CloneFloatArray(source.AttackRange),
|
|
AttackSpeed = CloneFloatArray(source.AttackSpeed),
|
|
AttackMethodType = source.AttackMethodType,
|
|
AttackPropertyType = source.AttackPropertyType,
|
|
Tags = CloneTags(source.Tags)
|
|
};
|
|
}
|
|
|
|
public static int[] CloneIntArray(int[] source)
|
|
{
|
|
return source != null ? (int[])source.Clone() : Array.Empty<int>();
|
|
}
|
|
|
|
public static float[] CloneFloatArray(float[] source)
|
|
{
|
|
return source != null ? (float[])source.Clone() : Array.Empty<float>();
|
|
}
|
|
|
|
public static TagType[] CloneTags(TagType[] source)
|
|
{
|
|
return source != null ? (TagType[])source.Clone() : Array.Empty<TagType>();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|