123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- enum EHarvestType
- {
- NORMAL,
- BARK
- }
- class WoodBase extends Plant
- {
-
- static bool m_IsCuttable;
- static int m_PrimaryDropsAmount = -1;
- static int m_SecondaryDropsAmount = -1;
- static float m_ToolDamage = -1.0;
- static float m_CycleTimeOverride = -1.0;
- static string m_PrimaryOutput = ""; //some nonsensical item for debugging purposes
- static string m_SecondaryOutput = ""; //some nonsensical item for debugging purposes
- static string m_BarkType = "";
-
- /*
- bool m_IsCuttable;
- int m_PrimaryDropsAmount = -1;
- int m_SecondaryDropsAmount = -1;
- float m_ToolDamage = -1.0;
- float m_CycleTimeOverride = -1.0;
- string m_PrimaryOutput = ""; //some nonsensical item for debugging purposes
- string m_SecondaryOutput = ""; //some nonsensical item for debugging purposes
- string m_BarkType = "";
- */
-
- void WoodBase()
- {
- //InitMiningValues();
- }
-
-
- void InitMiningValues()
- {
- //m_IsCuttable = false;
- };
-
- override bool IsWoodBase()
- {
- return true;
- }
- override bool IsCuttable()
- {
- return ConfigGetBool("isCuttable");
- }
-
- int GetPrimaryDropsAmount()
- {
- return ConfigGetInt("primaryDropsAmount");
- }
-
- int GetSecondaryDropsAmount()
- {
- return ConfigGetInt("secondaryDropsAmount");
- }
-
- float GetToolDamage()
- {
- return ConfigGetFloat("toolDamage");
- }
-
- float GetCycleTimeOverride()
- {
- return ConfigGetFloat("cycleTimeOverride");
- }
-
- string GetPrimaryOutput()
- {
- return ConfigGetString("primaryOutput");
- }
-
- string GetSecondaryOutput()
- {
- return ConfigGetString("secondaryOutput");
- }
-
- string GetBarkType()
- {
- return ConfigGetString("barkType");
- }
-
-
-
- int GetAmountOfDrops(ItemBase item)
- {
- if ( GetPrimaryDropsAmount() > 0 )
- {
- if ( IsTree() && item && ( item.KindOf("Knife") || item.IsInherited(Screwdriver) ) )
- {
- return -1;
- }
- else
- {
- return GetPrimaryDropsAmount();
- }
- }
- else
- {
- if ( item && ( item.KindOf("Knife") || item.IsInherited(Screwdriver) ) )
- {
- return -1;
- }
- else if ( item && item.KindOf("Axe") )
- {
- return 3;
- }
- else
- {
- return 100;
- }
- }
- }
-
- int GetAmountOfDropsEx(ItemBase item, EHarvestType type)
- {
- if ( GetPrimaryDropsAmount() > 0 )
- {
- if ( IsTree() && item && type == EHarvestType.BARK )
- {
- return -1;
- }
- else
- {
- return GetPrimaryDropsAmount();
- }
- }
- else
- {
- if ( item && type == EHarvestType.BARK )
- {
- return -1;
- }
- else if ( item && type == EHarvestType.NORMAL )
- {
- return 3;
- }
- else
- {
- return 100;
- }
- }
- }
-
- void GetMaterialAndQuantityMap(ItemBase item, out map<string,int> output_map)
- {
- if ( IsTree() && item && ( item.KindOf("Knife") || item.IsInherited(Screwdriver) ) && GetBarkType() != "" )
- {
- output_map.Insert(GetBarkType(),1);
- }
- else
- {
- output_map.Insert(GetPrimaryOutput(),1);
- }
- }
-
- void GetMaterialAndQuantityMapEx(ItemBase item, out map<string,int> output_map, EHarvestType type)
- {
- if ( IsTree() && item && type == EHarvestType.BARK && GetBarkType() != "" )
- {
- output_map.Insert(GetBarkType(),1);
- }
- else
- {
- output_map.Insert(GetPrimaryOutput(),1);
- }
- }
-
- float GetDamageToMiningItemEachDrop(ItemBase item)
- {
- if (GetToolDamage() > -1)
- return GetToolDamage();
-
- if ( IsTree() )
- {
- if ( item && item.KindOf("Knife") )
- {
- return 20;
- }
- else if ( item && item.KindOf("Axe") )
- {
- return 20;
- }
- else
- {
- return 0;
- }
- }
- else
- {
- if ( item && item.KindOf("Knife") )
- {
- return 30;
- }
- else if ( item && item.KindOf("Axe") )
- {
- return 30;
- }
- else
- {
- return 0;
- }
- }
- }
-
- float GetDamageToMiningItemEachDropEx(ItemBase item, EHarvestType type)
- {
- if (GetToolDamage() > -1)
- return GetToolDamage();
-
- if ( IsTree() )
- {
- if ( item && type == EHarvestType.BARK )
- {
- return 20;
- }
- else if ( item && type == EHarvestType.NORMAL )
- {
- return 20;
- }
- else
- {
- return 0;
- }
- }
- else
- {
- if ( item && type == EHarvestType.BARK )
- {
- return 30;
- }
- else if ( item && type == EHarvestType.NORMAL )
- {
- return 30;
- }
- else
- {
- return 0;
- }
- }
- }
-
- override bool CanBeActionTarget()
- {
- return super.CanBeActionTarget() && !IsDamageDestroyed();
- }
- }
- class TreeEffecterParameters : EffecterParameters
- {
- float m_Radius;
- void TreeEffecterParameters(string type, float lifespan, int radius)
- {
- m_Radius = radius;
- }
- }
- class TreeEffecter : EffecterBase
- {
- ref array<WoodBase> m_Plants;
- protected ref array<EffectParticleGeneral> m_Effects = null;
- private float m_Radius = -1;
- private float m_RadiusSync = -1;
-
- void TreeEffecter()
- {
- if (!GetGame().IsServer() || !GetGame().IsMultiplayer())
- {
- m_Plants = new array<WoodBase>;
- m_Effects = new array<EffectParticleGeneral>;
- }
-
- RegisterNetSyncVariableFloat("m_RadiusSync");
- }
-
- override void Init(int id, EffecterParameters parameters)
- {
- super.Init(id, parameters);
- TreeEffecterParameters par = TreeEffecterParameters.Cast(parameters);
- SetRadius(par.m_Radius);
- }
-
- void SetRadius(float radius)
- {
- m_RadiusSync = radius;
- Process();
- }
-
- override void OnVariablesSynchronized()
- {
- if (m_RadiusSync != m_Radius)
- {
- array<Object> objects = new array<Object>;
- array<CargoBase> proxies = new array<CargoBase>;
- EffectParticleGeneral newEffect;
-
- foreach (EffectParticleGeneral oldEffect : m_Effects)
- {
- SEffectManager.DestroyEffect(oldEffect);
- }
-
- m_Effects.Clear();
- m_Plants.Clear();
-
- GetGame().GetObjectsAtPosition(GetWorldPosition(), m_RadiusSync, objects, proxies);
- for (int i = 0; i < objects.Count(); i++)
- {
- WoodBase plant = WoodBase.Cast(objects[i]);
- if (plant)
- {
- string particle;
- int particleID;
- string configPath = "CfgNonAIVehicles " + plant.GetType() + " FxFallingParticleEffect particle";
- GetGame().ConfigGetText(configPath, particle);
-
- if (particle != "")
- {
- particleID = ParticleList.RegisterParticle(particle);
- }
- else
- {
- particleID = ParticleList.TREE_FALLING_LEAF;
- }
-
- LOD lod = plant.GetLODByName(LOD.NAME_MEMORY);
- Selection selection = lod.GetSelectionByName("ptcFalling");
- if (selection)
- {
- vector selectionPos;
- for (int j = 0; j < selection.GetVertexCount(); j++)
- {
- newEffect = new EffectParticleGeneral();
- newEffect.SetParticle(particleID);
- selectionPos = selection.GetVertexPosition(lod, j);
- SEffectManager.PlayInWorld(newEffect, plant.GetPosition() + selectionPos);
- m_Effects.Insert(newEffect);
- }
- }
- else
- {
- newEffect = new EffectParticleGeneral();
- newEffect.SetParticle(particleID);
- SEffectManager.PlayInWorld(newEffect, plant.GetPosition());
- m_Effects.Insert(newEffect);
- }
-
- m_Plants.Insert(plant);
- }
- }
- }
-
- if (m_CommandSync != m_Command)
- {
- foreach (EffectParticleGeneral effect : m_Effects)
- {
- switch (m_CommandSync)
- {
- case EffecterCommands.START:
- if (effect && !effect.IsPlaying())
- {
- effect.SetParticle(effect.m_LastParticleID);
- effect.Start();
- }
- break;
-
- case EffecterCommands.STOP:
- if (effect && effect.IsPlaying())
- {
- effect.Stop();
- }
- break;
-
- case EffecterCommands.REACTIVATE0:
- case EffecterCommands.REACTIVATE1:
- if (effect)
- {
- effect.SetParticle(effect.m_LastParticleID);
- }
- if (!effect.IsPlaying())
- {
- effect.Start();
- }
- break;
-
- default:
- break;
- }
- }
- m_Command = m_CommandSync;
- }
- }
-
- void ~TreeEffecter()
- {
- if (m_Effects)
- {
- foreach (EffectParticleGeneral effect : m_Effects)
- {
- SEffectManager.DestroyEffect(effect);
- }
- }
- }
- }
|