123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- class CatchingResultBasic
- {
- protected EntityAI m_Owner;
- protected bool m_OverrideChanceActive = false; //do not perform chance updates
- protected bool m_OverrideQualityActive = false; //overrides quality
- protected float m_CatchChance = 1.0; //guaranteed catch by default
- protected float m_Quality = 1.0; //max quality default
- protected YieldItemBase m_YItem;
-
- void CatchingResultBasic(EntityAI owner)
- {
- m_Owner = owner;
- }
-
- void SetYieldItem(YieldItemBase yItem)
- {
- m_YItem = yItem;
- }
-
- int GetYieldItemParticleId()
- {
- if (m_YItem)
- return m_YItem.GetCatchParticleID();
-
- return ParticleList.INVALID;
- }
-
- protected void SetCatchChance(float val)
- {
- m_CatchChance = Math.Clamp(val,0,1);
- }
-
- protected void SetQuality(float val)
- {
- m_Quality = Math.Clamp(val,0,1);
- }
-
- void SetCatchChanceOverride(bool ovrd, float val = 0.0)
- {
- if (ovrd)
- m_CatchChance = val;
- m_OverrideChanceActive = ovrd;
- }
-
- void SetQualityOverride(bool ovrd, float val = 0.0)
- {
- if (ovrd)
- m_Quality = val;
- m_OverrideQualityActive = ovrd;
- }
-
- void UpdateCatchQuality(CatchingContextBase ctx)
- {
- if (m_OverrideQualityActive)
- return;
-
- if (!m_YItem)
- return;
-
- float val = m_YItem.GetQualityForYieldItem(ctx);
- SetQuality(val);
- }
-
- void UpdateCatchChance(CatchingContextBase ctx)
- {
- if (m_OverrideChanceActive)
- return;
-
- if (!m_YItem)
- return;
-
- float val = m_YItem.GetChanceForYieldItem(ctx);
- SetCatchChance(val);
- }
-
- bool RollChance()
- {
- if (m_CatchChance >= 1)
- return true;
- if (m_CatchChance <= 0)
- return false;
-
- float roll;
- if (m_Owner && m_Owner.GetHierarchyRootPlayer())
- roll = RollChanceSeeded();
- else
- roll = Math.RandomFloat01();
-
- return roll < m_CatchChance;
- }
-
- protected float RollChanceSeeded()
- {
- return 1.0;
- }
-
- EntityAI SpawnAndSetup(out int yItemIdx, vector v = vector.Zero)
- {
- vector pos = v;
- if (v == vector.Zero && m_Owner != null)
- pos = m_Owner.GetPosition();
-
- if (!m_YItem)
- return null;
-
- yItemIdx = m_YItem.GetRegistrationIdx();
-
- return EntityAI.Cast(GetGame().CreateObjectEx(m_YItem.GetType(), pos, ECE_PLACE_ON_SURFACE));
- }
- };
|