123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- class ArrowManagerPlayer : ArrowManagerBase
- {
- private static ref map<int,typename> m_TypeHashTable;
-
- void ArrowManagerPlayer(PlayerBase player)
- {
- if (!m_TypeHashTable)
- {
- InitializeHash();
- }
- }
-
- private static void InitializeHash()
- {
- m_TypeHashTable = new map<int,typename>();
-
- AddArrowTypeToHash("Ammo_HuntingBolt");
- AddArrowTypeToHash("Ammo_ImprovisedBolt_1");
- AddArrowTypeToHash("Ammo_ImprovisedBolt_2");
- AddArrowTypeToHash("Ammo_ImprovisedBolt_3");
- }
-
- private static void AddArrowTypeToHash(string ArrowType)
- {
- m_TypeHashTable.Insert(ArrowType.Hash(), ArrowType.ToType());
- }
-
- private static typename GetArrowTypeFromHash(int hash)
- {
- return m_TypeHashTable.Get(hash);
- }
-
- bool Save(ParamsWriteContext ctx)
- {
- ctx.Write(VERSION);
- int count = m_Arrows.Count();
- int i;
- //TODO MW Delete after find why sometimes arrow missing - most likely Life span
- for (i = count - 1; i >= 0; i--)
- {
- if (!m_Arrows.Get(i))
- {
- m_Arrows.Remove(i);
- }
- }
- count = m_Arrows.Count();
-
- ctx.Write(count);
-
- for (i = 0; i < count; i++)
- {
- EntityAI arrow = m_Arrows.Get(i);
-
- string type = arrow.GetType();
- ctx.Write(type.Hash());
-
- vector angle = arrow.GetLocalYawPitchRoll();
- vector pos = arrow.GetLocalPosition();
-
- ctx.Write(angle[0]);
- ctx.Write(angle[1]);
- ctx.Write(angle[2]);
- ctx.Write(pos[0]);
- ctx.Write(pos[1]);
- ctx.Write(pos[2]);
-
- int pivot = arrow.GetHierarchyPivot();
- ctx.Write(pivot);
- }
- return true;
- }
-
- bool Load(ParamsReadContext ctx)
- {
- int version;
- if (!ctx.Read(version))
- {
- return false;
- }
-
- int count;
- if (!ctx.Read(count))
- {
- return false;
- }
-
- for (int i = 0; i < count; i++)
- {
-
- if (version >= 1)
- {
- int hash;
- if (!ctx.Read(hash))
- {
- return false;
- }
- float angleF[3];
- float posF[3];
- float value;
-
- if (!ctx.Read(value))
- {
- return false;
- }
- angleF[0] = value;
-
- if (!ctx.Read(value))
- {
- return false;
- }
- angleF[1] = value;
-
- if (!ctx.Read(value))
- {
- return false;
- }
- angleF[2] = value;
-
- if (!ctx.Read(value))
- {
- return false;
- }
- posF[0] = value;
-
- if (!ctx.Read(value))
- {
- return false;
- }
- posF[1] = value;
-
- if (!ctx.Read(value))
- {
- return false;
- }
- posF[2] = value;
-
- vector angle = "0 0 0";
- vector pos = "0 0 0";
- angle = vector.ArrayToVec(angleF);
- pos = vector.ArrayToVec(posF);
-
- int pivot;
- if (!ctx.Read(pivot))
- {
- return false;
- }
-
- if (version >= 2)
- {
- #ifdef SERVER
- int spawnFlags = ECE_KEEPHEIGHT|ECE_DYNAMIC_PERSISTENCY;
- #else
- int spawnFlags = ECE_LOCAL|ECE_KEEPHEIGHT|ECE_DYNAMIC_PERSISTENCY;
- #endif
-
- typename arrowType = GetArrowTypeFromHash(hash);
- EntityAI arrow = EntityAI.Cast(GetGame().CreateObjectEx(arrowType.ToString(), pos, spawnFlags));
- if (arrow)
- {
- arrow.SetQuantityToMinimum();
- arrow.SetYawPitchRoll(angle);
- m_Owner.AddChild(arrow, pivot);
- }
- }
- }
-
- }
- return true;
- }
- }
|