- public int AgentShotAgent(Agent agent, Agent vagent)//自瞄步骤2,决定实际射击的位置,添加预瞄功能
- {
- if (agent.Equipment != null && agent.Equipment[0].Item != null)
- {
- // 获取Agent主手中武器的Index索引
- EquipmentIndex mainHandIndex = agent.GetWieldedItemIndex(Agent.HandIndex.MainHand);
- if (mainHandIndex == EquipmentIndex.None)
- {
- return 0;
- }
- // EquipmentIndex转MissionWeapon
- MissionWeapon mainHandEquipmentElement = agent.Equipment[mainHandIndex];
- // 获取主手装备元素的修正后的导弹速度
- float baseSpeed = (float)mainHandEquipmentElement.GetModifiedMissileSpeedForCurrentUsage();
- bool ThrewMeleeWeapon;
- mainHandEquipmentElement = getMissionWeaponFromAgentInventory(agent, out ThrewMeleeWeapon);
- if (ThrewMeleeWeapon)
- { baseSpeed = -1; }
- Vec3 headPosition = agent.GetEyeGlobalPosition();
- Vec3 VheadPosition = vagent.GetEyeGlobalPosition();
- Vec3 VAgenSpeed=Vec3.Invalid;
- if (WoW_MissionSetting.WoW_Agents.TryGetValue(vagent.Index, out var data))
- {
- VAgenSpeed = data.speed.speed;
- }
- Vec3 shotDir = CalculateProjectileFiringSolution(headPosition, VheadPosition, baseSpeed, 9.81f);
- float timeOld = (headPosition - VheadPosition).AsVec2.Length / (baseSpeed * shotDir.AsVec2.Length);
- float timeNew = float.MaxValue;
- //VheadPosition.z -= 15 / 100f;
- //VheadPosition.y += 15 / 100f;
- while (TaleWorlds.Library.MathF.Abs(timeOld- timeNew)>0.001f)
- {
- timeNew = timeOld;
- Vec3 s= MultiplyVectorByScalar(VAgenSpeed,timeOld);
- //s = vagent.LookDirection.AsVec2 * VAgenSpeed.Length * timeOld;
- VheadPosition = vagent.GetEyeGlobalPosition()+s;
- shotDir = CalculateProjectileFiringSolution(headPosition, VheadPosition, baseSpeed, 9.81f);
- timeOld = (headPosition - VheadPosition).AsVec2.Length / (baseSpeed * shotDir.AsVec2.Length);
-
- }
- //GameEntity gameEntity = GameEntity.CreateEmpty(Mission.Current.Scene);
- //gameEntity.AddAllMeshesOfGameEntity(GameEntity.Instantiate(Mission.Current.Scene, "mangonel_mapicon_projectile", true));
- //gameEntity.SetLocalPosition(VheadPosition);
- int index = WoW_Scripts.FireProjectileFromAgentWithWeaponAtPosition(agent, agent.Equipment[mainHandIndex], mainHandEquipmentElement, headPosition, VheadPosition, baseSpeed);
- mainHandEquipmentElement.Amount = (short)(mainHandEquipmentElement.Amount - 1);
- return index;
- }
- return 0;
- }
复制代码
|