-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from nexus4880/item-templates
Item templates
- Loading branch information
Showing
150 changed files
with
3,642 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Fuyu.Backend.BSG.ItemTemplates; | ||
using Fuyu.Backend.BSG.Models.Items; | ||
using Fuyu.Backend.BSG.Models.Responses; | ||
using Fuyu.Common.Hashing; | ||
using Fuyu.Common.IO; | ||
using Fuyu.Common.Serialization; | ||
|
||
namespace Fuyu.Backend.BSG.DTO.Services | ||
{ | ||
// TODO: split UPD factory and Item Factory | ||
public static class ItemFactoryService | ||
{ | ||
public static Dictionary<MongoId, ItemTemplate> ItemTemplates { get; private set; } | ||
|
||
public static void Load() | ||
{ | ||
var itemsText = Resx.GetText("eft", "database.client.items.json"); | ||
ItemTemplates = Json.Parse<ResponseBody<Dictionary<MongoId, ItemTemplate>>>(itemsText).data; | ||
} | ||
|
||
public static ItemInstance CreateItem(MongoId tpl, MongoId? id = null) | ||
{ | ||
var template = ItemTemplates[tpl]; | ||
var itemId = id.GetValueOrDefault(new MongoId(true)); | ||
ItemUpdatable upd = CreateItemUpdatable(template); | ||
|
||
var item = new ItemInstance | ||
{ | ||
Id = itemId, | ||
TemplateId = tpl, | ||
Updatable = upd | ||
}; | ||
|
||
return item; | ||
} | ||
|
||
public static ItemUpdatable CreateItemUpdatable(ItemTemplate template) | ||
{ | ||
ItemUpdatable upd = null; | ||
var updProperties = typeof(ItemUpdatable).GetProperties(); | ||
|
||
foreach (var updProperty in updProperties) | ||
{ | ||
var component = CreateItemComponent(template, updProperty.PropertyType, false); | ||
if (component != null) | ||
{ | ||
if (upd == null) | ||
{ | ||
upd = new ItemUpdatable(); | ||
} | ||
|
||
updProperty.SetValue(upd, component); | ||
} | ||
} | ||
|
||
return upd; | ||
} | ||
|
||
public static object CreateItemComponent(ItemTemplate template, Type componentType, bool createDefault) | ||
{ | ||
var isItemComponentInterface = typeof(IItemComponent).IsAssignableFrom(componentType); | ||
if (!isItemComponentInterface) | ||
{ | ||
return null; | ||
} | ||
|
||
var bindingFlags = BindingFlags.Public | BindingFlags.Static; | ||
var createComponentMethodName = nameof(IItemComponent.CreateComponent); | ||
var createComponentMethod = componentType.GetMethod(createComponentMethodName, bindingFlags); | ||
if (createComponentMethod == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var result = createComponentMethod.Invoke(null, [template.Props]); | ||
if (result == null && createDefault) | ||
{ | ||
result = Activator.CreateInstance(componentType); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static ItemUpdatable CreateItemUpdatable(MongoId tpl) | ||
{ | ||
return CreateItemUpdatable(ItemTemplates[tpl]); | ||
} | ||
|
||
public static object CreateItemComponent(MongoId tpl, Type componentType, bool createDefault) | ||
{ | ||
return CreateItemComponent(ItemTemplates[tpl], componentType, createDefault); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Fuyu.Backend.BSG | ||
{ | ||
public interface IItemComponent | ||
{ | ||
static abstract object CreateComponent(JObject templateProperties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Fuyu.Backend.BSG.ItemTemplates | ||
{ | ||
[DataContract] | ||
public class AmmoBoxItemProperties : StackableItemItemProperties | ||
{ | ||
[DataMember(Name = "magAnimationIndex")] | ||
public int magAnimationIndex; | ||
|
||
[DataMember(Name = "StackSlots")] | ||
public object[] StackSlots = []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
using System.Runtime.Serialization; | ||
using Fuyu.Backend.BSG.DTO.Common; | ||
using Fuyu.Backend.BSG.Models.Common; | ||
|
||
namespace Fuyu.Backend.BSG.ItemTemplates | ||
{ | ||
[DataContract] | ||
public class AmmoItemProperties : StackableItemItemProperties | ||
{ | ||
[DataMember(Name = "ammoType")] | ||
public string ammoType; | ||
|
||
[DataMember(Name = "Damage")] | ||
public int Damage; | ||
|
||
[DataMember(Name = "ammoAccr")] | ||
public int ammoAccr; | ||
|
||
[DataMember(Name = "ammoRec")] | ||
public int ammoRec; | ||
|
||
[DataMember(Name = "ammoDist")] | ||
public int ammoDist; | ||
|
||
[DataMember(Name = "buckshotBullets")] | ||
public int buckshotBullets; | ||
|
||
[DataMember(Name = "PenetrationPower")] | ||
public int PenetrationPower = 40; | ||
|
||
[DataMember(Name = "PenetrationPowerDiviation")] | ||
public float PenetrationPowerDiviation; | ||
|
||
[DataMember(Name = "ammoHear")] | ||
public int ammoHear; | ||
|
||
[DataMember(Name = "ammoSfx")] | ||
public string ammoSfx; | ||
|
||
[DataMember(Name = "MisfireChance")] | ||
public float MisfireChance; | ||
|
||
[DataMember(Name = "MinFragmentsCount")] | ||
public int MinFragmentsCount = 2; | ||
|
||
[DataMember(Name = "MaxFragmentsCount")] | ||
public int MaxFragmentsCount = 3; | ||
|
||
[DataMember(Name = "ammoShiftChance")] | ||
public int ammoShiftChance; | ||
|
||
[DataMember(Name = "casingName")] | ||
public string casingName; | ||
|
||
[DataMember(Name = "casingEjectPower")] | ||
public float casingEjectPower; | ||
|
||
[DataMember(Name = "casingMass")] | ||
public float casingMass; | ||
|
||
[DataMember(Name = "casingSounds")] | ||
public string casingSounds; | ||
|
||
[DataMember(Name = "ProjectileCount")] | ||
public int ProjectileCount = 1; | ||
|
||
[DataMember(Name = "InitialSpeed")] | ||
public float InitialSpeed = 700f; | ||
|
||
[DataMember(Name = "PenetrationDamageMod")] | ||
public float PenetrationDamageMod = 0.1f; | ||
|
||
[DataMember(Name = "PenetrationChanceObstacle")] | ||
public float PenetrationChanceObstacle = 0.2f; | ||
|
||
[DataMember(Name = "RicochetChance")] | ||
public float RicochetChance = 0.1f; | ||
|
||
[DataMember(Name = "FragmentationChance")] | ||
public float FragmentationChance = 0.03f; | ||
|
||
[DataMember(Name = "BallisticCoeficient")] | ||
public float BallisticCoeficient = 1f; | ||
|
||
[DataMember(Name = "Tracer")] | ||
public bool Tracer; | ||
|
||
[DataMember(Name = "TracerColor")] | ||
public ETaxonomyColor TracerColor; | ||
|
||
[DataMember(Name = "TracerDistance")] | ||
public float TracerDistance; | ||
|
||
[DataMember(Name = "ArmorDamage")] | ||
public int ArmorDamage; | ||
|
||
[DataMember(Name = "Caliber")] | ||
public string Caliber; | ||
|
||
[DataMember(Name = "StaminaBurnPerDamage")] | ||
public float StaminaBurnPerDamage; | ||
|
||
[DataMember(Name = "HasGrenaderComponent")] | ||
public bool HasGrenaderComponent; | ||
|
||
[DataMember(Name = "FuzeArmTimeSec")] | ||
public float FuzeArmTimeSec; | ||
|
||
[DataMember(Name = "MinExplosionDistance")] | ||
public float MinExplosionDistance; | ||
|
||
[DataMember(Name = "MaxExplosionDistance")] | ||
public float MaxExplosionDistance; | ||
|
||
[DataMember(Name = "FragmentsCount")] | ||
public int FragmentsCount; | ||
|
||
[DataMember(Name = "FragmentType")] | ||
public string FragmentType; | ||
|
||
[DataMember(Name = "ExplosionType")] | ||
public string ExplosionType; | ||
|
||
[DataMember(Name = "ShowHitEffectOnExplode")] | ||
public bool ShowHitEffectOnExplode; | ||
|
||
[DataMember(Name = "ExplosionStrength")] | ||
public float ExplosionStrength; | ||
|
||
[DataMember(Name = "ShowBullet")] | ||
public bool ShowBullet; | ||
|
||
[DataMember(Name = "AmmoLifeTimeSec")] | ||
public float AmmoLifeTimeSec = 2f; | ||
|
||
[DataMember(Name = "MalfMisfireChance")] | ||
public float MalfMisfireChance; | ||
|
||
[DataMember(Name = "MalfFeedChance")] | ||
public float MalfFeedChance; | ||
|
||
[DataMember(Name = "ArmorDistanceDistanceDamage")] | ||
public Vector3 ArmorDistanceDistanceDamage; | ||
|
||
[DataMember(Name = "Contusion")] | ||
public Vector3 Contusion; | ||
|
||
[DataMember(Name = "Blindness")] | ||
public Vector3 Blindness; | ||
|
||
[DataMember(Name = "LightBleedingDelta")] | ||
public float LightBleedingDelta; | ||
|
||
[DataMember(Name = "HeavyBleedingDelta")] | ||
public float HeavyBleedingDelta; | ||
|
||
[DataMember(Name = "IsLightAndSoundShot")] | ||
public bool IsLightAndSoundShot; | ||
|
||
[DataMember(Name = "LightAndSoundShotAngle")] | ||
public float LightAndSoundShotAngle; | ||
|
||
[DataMember(Name = "LightAndSoundShotSelfContusionTime")] | ||
public float LightAndSoundShotSelfContusionTime; | ||
|
||
[DataMember(Name = "LightAndSoundShotSelfContusionStrength")] | ||
public float LightAndSoundShotSelfContusionStrength; | ||
|
||
[DataMember(Name = "DurabilityBurnModificator")] | ||
public float DurabilityBurnModificator = 1f; | ||
|
||
[DataMember(Name = "HeatFactor")] | ||
public float HeatFactor = 1f; | ||
|
||
[DataMember(Name = "BulletMassGram")] | ||
public float BulletMassGram; | ||
|
||
[DataMember(Name = "BulletDiameterMilimeters")] | ||
public float BulletDiameterMilimeters; | ||
|
||
[DataMember(Name = "RemoveShellAfterFire")] | ||
public bool RemoveShellAfterFire; | ||
|
||
[DataMember(Name = "airDropTemplateId")] | ||
public string airDropTemplateId; | ||
|
||
[DataMember(Name = "FlareTypes")] | ||
public EFlareEventType[] FlareTypes; | ||
} | ||
|
||
public enum EFlareEventType | ||
{ | ||
Airdrop, | ||
ExitActivate, | ||
AIFollowEvent, | ||
CallArtilleryOnMyself | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Fuyu.Backend.BSG.ItemTemplates | ||
{ | ||
[DataContract] | ||
public class ArmBandItemProperties : EquipmentItemProperties | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Fuyu.Backend.BSG.ItemTemplates | ||
{ | ||
[DataContract] | ||
public class ArmorItemProperties : ArmoredEquipmentItemProperties | ||
{ | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Fuyu.Backend.BSG/ItemTemplates/ArmorPlateItemProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Runtime.Serialization; | ||
using Fuyu.Backend.BSG.DTO.Common; | ||
using Fuyu.Backend.BSG.Models.Common; | ||
|
||
namespace Fuyu.Backend.BSG.ItemTemplates | ||
{ | ||
[DataContract] | ||
public class ArmorPlateItemProperties : ArmoredEquipmentItemProperties | ||
{ | ||
[DataMember(Name = "Lower75Prefab")] | ||
public ResourceKey Lower75Prefab; | ||
|
||
[DataMember(Name = "Lower40Prefab")] | ||
public ResourceKey Lower40Prefab; | ||
} | ||
} |
Oops, something went wrong.