コード例 #1
0
        public static void ResetAiming(this IAimable aiming, IActor actor)
        {
            var dstManager = World.DefaultGameObjectInjectionWorld.EntityManager;

            if (aiming.SpawnedAimingPrefab == null)
            {
                return;
            }

            if (!dstManager.HasComponent <ActorEvaluateAimingAnimData>(actor.ActorEntity))
            {
                dstManager.AddComponentData(actor.ActorEntity, new ActorEvaluateAimingAnimData {
                    AimingActive = false
                });
            }
            else
            {
                var existingComponent = dstManager.GetComponentData <ActorEvaluateAimingAnimData>(actor.ActorEntity);
                existingComponent.AimingActive = false;

                dstManager.SetComponentData(actor.ActorEntity, existingComponent);
            }

            Object.Destroy(aiming.SpawnedAimingPrefab);
        }
コード例 #2
0
 public static AIActionCommand ShootTG(TurretGroup group, IAimable target)
 {
     return(new AIActionCommand(CommandType.shoot_tgs)
     {
         target = target
     });
 }
コード例 #3
0
 public static AIActionCommand FireMain(IAimable target)
 {
     return(new AIActionCommand(CommandType.fire_main)
     {
         target = target
     });
 }
コード例 #4
0
 private void HandleAimableWeapon(IWeapon baseWeapon)
 {
     if (baseWeapon is IAimable)
     {
         _aimableWeapon = baseWeapon as IAimable;
     }
 }
コード例 #5
0
 public static AIMouvementCommand StayLocked(double p_time, Ship ship, IAimable tgt, bool directly = false)
 {
     return(new AIMouvementCommand(CommandType.stay_locked, new ShipState()
     {
         Target = tgt,
         Time = directly ? p_time : GeneralExecution.TotalTime + p_time
     }));
 }
コード例 #6
0
ファイル: Vehicle.cs プロジェクト: Lomztein/Project-Incoming
    public virtual void Start()
    {
        healthbar = HealthbarManager.CreateHealthbar();

        if (turret)
        {
            _turret = turret.GetComponent <IAimable> ();
        }
    }
コード例 #7
0
 public ShipState(Ship ship)
 {
     Position        = ship.Position;
     Velocity        = ship.Velocity;
     Orientation     = ship.Orientation;
     AngularVelocity = ship.AngularVelocity;
     Target          = ship.TurretAim;
     Time            = GeneralExecution.TotalTime;
 }
コード例 #8
0
        public static Vector3 EvaluateAimBySight(this IAimable aiming, IActor actor, Vector2 pos)
        {
            var newSightPos = actor.GameObject.transform.position - new Vector3(
                pos.x * aiming.AimingProperties.sightDistance,
                0, pos.y * aiming.AimingProperties.sightDistance);

            aiming.SpawnedAimingPrefab.transform.position = newSightPos;

            return(aiming.SpawnedAimingPrefab.transform.position);
        }
コード例 #9
0
 /// <param name="target_"> The target, that the turrets should follow </param>
 /// <param name="turret_array"> The turrets concerned to beginn with </param>
 /// <param name="name_"> The name of the turretgroup </param>
 public TurretGroup(IAimable target_, Turret [] turret_array, string name_)
 {
     name = name_;
     foreach (Turret turr in turret_array)
     {
         turr.Group = this;
     }
     target        = target_;
     follow_target = true;
     Enabled       = true;
 }
コード例 #10
0
ファイル: TargetBox.cs プロジェクト: bionick7/4040Machines
    private void Update()
    {
        parent = is_aim ? SceneGlobals.Player.TurretAim : SceneGlobals.Player.Target;
        Shown  = parent != null && parent.Exists;

        if (Shown && Vector3.Angle(parent.Position - cam.transform.position, cam.transform.forward) < 90)
        {
            transform.position = cam.WorldToScreenPoint(parent.Position);
        }
        UpdateColor_Size();
    }
コード例 #11
0
        public static Vector3 EvaluateAimByArea(this IAimable aiming, Vector2 pos)
        {
            var currentRotation = Mathf.Atan2(pos.x, pos.y) * Mathf.Rad2Deg;

            var newRot = aiming.SpawnedAimingPrefab.transform.eulerAngles;

            newRot.y = currentRotation;
            aiming.SpawnedAimingPrefab.transform.eulerAngles = newRot;

            return(aiming.SpawnedAimingPrefab.transform.forward);
        }
コード例 #12
0
    public void Update_()
    {
        if (target == null | Time.frameCount % 100 == net_id % 100)
        {
            SearchTgt();
        }

        if (turret_aim == null)
        {
            turret_aim = target;
        }

        if (Time.frameCount == 0)
        {
            low_ai.action_list.Add(AIActionCommand.ShootTG(own_ship.TurretGroups[0], turret_aim));
        }

        Execute("ShootFixedOn");
        Execute("ShootFixedOff");
        Execute("ShootMissile");
    }
コード例 #13
0
ファイル: FirstPersonShooter.cs プロジェクト: ArcAids/BHole
        /// <summary>
        /// drops weapon of index index.
        /// </summary>
        /// <param name="index"></param>
        void DropWeapon(int index)
        {
            DropWeapon(weapons[index]);
            if (index == currentEquippedWeaponIndex)    //if it was equipped weapon, reset values.
            {
                aimable    = null;
                shootable  = null;
                reloadable = null;
            }

            weapons[index] = null;
            if (index == currentEquippedWeaponIndex)        //equip something else instead.
            {
                if (secondaryWeaponIndex >= 0)
                {
                    EquipWeapon(secondaryWeaponIndex);
                }
                if (primaryWeaponIndex >= 0)
                {
                    EquipWeapon(primaryWeaponIndex);
                }
            }
        }
コード例 #14
0
ファイル: FirstPersonShooter.cs プロジェクト: ArcAids/BHole
        /// <summary>
        /// don't call directly. pass index instead.
        /// </summary>
        /// <param name="weapon">weapons to be equipped</param>
        /// <returns></returns>
        protected bool EquipWeapon(WeaponBehaviour weapon)
        {
            if (weapon == null || (weapon is MeleeBehaviour && !isMeleeEquippable))
            {
                return(false);
            }

            if (currentEquippedWeaponIndex >= 0)
            {
                Dequip(weapons[currentEquippedWeaponIndex]);
            }

            if (weapon is WeaponBehaviour)     //place it in right position
            {
                weapon.gameObject.transform.parent = gunHolder;
                weapon.transform.localPosition     = Vector3.zero;
                weapon.transform.localRotation     = Quaternion.identity;
                gunName.text = weapon.name;
            }

            Debug.Log("EquippingWeapon: " + weapon.name);
            weapon.Equip();

            //set references for current gun.

            reloadable = weapon.GetComponent <IReloadable>();
            if (reloadable != null)
            {
                shootable = reloadable;
            }
            else
            {
                shootable = weapon.GetComponent <IAttack>();
            }
            aimable = weapon.GetComponent <IAimable>();
            return(true);
        }
コード例 #15
0
 private AIActionCommand(CommandType p_command_type)
 {
     command_type = p_command_type;
     target       = Target.None;
     is_first     = true;
 }
コード例 #16
0
        public static void EvaluateAim(this IAimable aiming, IActor actor, Vector2 pos)
        {
            var dstManager = World.DefaultGameObjectInjectionWorld.EntityManager;

            if (aiming.SpawnedAimingPrefab == null)
            {
                GameObject prefabToSpawn = null;

                switch (aiming.AimingProperties.aimingType)
                {
                case AimingType.AimingArea:
                    prefabToSpawn = aiming.AimingProperties.aimingAreaPrefab;
                    break;

                case AimingType.SightControl:
                    prefabToSpawn = aiming.AimingProperties.sightPrefab;
                    break;

                case AimingType.Circle:
                    prefabToSpawn = aiming.AimingProperties.circlePrefab;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (prefabToSpawn == null)
                {
                    return;
                }

                var spawnAbility = actor.GameObject.AddComponent <AbilityActorSimpleSpawn>();

                spawnAbility.Actor = actor;

                spawnAbility.objectToSpawn     = prefabToSpawn;
                spawnAbility.ownerType         = OwnerType.CurrentActor;
                spawnAbility.spawnerType       = SpawnerType.CurrentActor;
                spawnAbility.DestroyAfterSpawn = true;

                spawnAbility.Execute();

                if (spawnAbility.spawnedObject == null)
                {
                    return;
                }

                aiming.SpawnedAimingPrefab = spawnAbility.spawnedObject;
            }

            if (!dstManager.HasComponent <ActorEvaluateAimingAnimData>(actor.ActorEntity))
            {
                dstManager.AddComponentData(actor.ActorEntity, new ActorEvaluateAimingAnimData {
                    AimingActive = true
                });
            }
            else
            {
                var existingComponent = dstManager.GetComponentData <ActorEvaluateAimingAnimData>(actor.ActorEntity);
                existingComponent.AimingActive = true;

                dstManager.SetComponentData(actor.ActorEntity, existingComponent);
            }

            aiming.EvaluateAimBySelectedType(pos);


            aiming.OnHoldAttackActive = true;
        }
コード例 #17
0
    private void Update()
    {
        transform.position = Input.mousePosition + offset;
        if (Shown)
        {
            Ray        screenray = SceneGlobals.map_camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit currenthit;
            if (Physics.Raycast(screenray, out currenthit))
            {
                IAimable aimable = GetAimable(currenthit.transform);
                ShipPart part    = (ShipPart)aimable;
                if (part != null)
                {
                    // If target is part
                    Object    = new PartOffsetAim(currenthit.point, part);
                    text.text = part.Name();
                }
                else
                {
                    DestroyableTarget dest_tgt = (DestroyableTarget)aimable;
                    if (dest_tgt != null)
                    {
                        // If target is destroyable target
                        Object    = new PhysicsOffsetAim(currenthit.point, dest_tgt);
                        text.text = part.Name();
                    }
                    else
                    {
                        // void
                        text.text = currenthit.transform.name;
                    }
                }
            }
            else
            {
                Object = null;
                foreach (MapTgtMarker marker in MapTgtMarker.marker_list)
                {
                    if (marker.RectTransform.rect.Contains((Vector2)Input.mousePosition - marker.Position))
                    {
                        // If target is ship
                        Object    = marker.LinkedObject;
                        text.text = marker.LinkedObject.Name;
                        //Debug.DrawLine(Vector3.zero, Object.Position, Color.red, 100);
                    }
                }
                if (Object == null)
                {
                    // If no object selected
                    text.text = "";
                }
            }

            // Mousebutton unleashed
            if (!Input.GetMouseButton(0) && Dragging)
            {
                Dragging = false;
                switch (Context)
                {
                default:
                case PinContext.turret:
                    break;

                case PinContext.selector:
                    MapCore.Active.selector_event_system.DraggedTo(Object);
                    break;
                }
                Context = PinContext.none;
            }
        }
    }
コード例 #18
0
ファイル: SceneObjects.cs プロジェクト: bionick7/4040Machines
 public PrecisePosition(IAimable parent, Vector3 offset)
 {
     Parent = parent;
     Offset = offset;
 }
コード例 #19
0
    /// <summary>
    ///		Should be called, if the pin label is dragget to a part in response to a selector event
    /// </summary>
    /// <param name="aimable"> The aimable, where the pointer lands </param>
    public void DraggedTo(IAimable aimable)
    {
        /*
         * Debug.Log("-----------");
         * Debug.Log(lasting_command.ToString("x"));
         * Debug.Log(concerned_objects);
         */

        Target tgt = Target.None;

        if (aimable is ITargetable)
        {
            tgt = ((ITargetable)aimable).Associated;
        }

        switch (lasting_command)
        {
        case 0x39:

            // Match Velocity Closest

            if (tgt.is_none)
            {
                foreach (Ship concerned in System.Array.ConvertAll(concerned_objects, x => x is Target ? ((Target)x).Ship : x as Ship))
                {
                    Debug.Log(concerned);
                    if (concerned != null)
                    {
                        concerned.low_ai.MatchVelocityNearTarget(tgt);
                        Debug.Log(concerned.low_ai.ShowCommands());
                    }
                }
            }
            break;

        case 0x3a:

            // Match Velocity

            if (tgt.is_none)
            {
                foreach (Ship concerned in System.Array.ConvertAll(concerned_objects, x => x as Ship))
                {
                    if (concerned != null)
                    {
                        concerned.low_ai.MatchVelocity(tgt);
                    }
                }
            }
            break;

        case 0x3b:

            // Attack

            if (tgt.is_none)
            {
                foreach (Ship concerned in System.Array.ConvertAll(concerned_objects, x => x as Ship))
                {
                    if (concerned != null)
                    {
                        concerned.low_ai.Attack(tgt);
                    }
                }
            }
            break;

        case 0x3c:

            // Turret Attack

            if (tgt.is_none)
            {
                foreach (Ship concerned in System.Array.ConvertAll(concerned_objects, x => x as Ship))
                {
                    if (concerned != null)
                    {
                        concerned.low_ai.TurretAttack(tgt);
                    }
                }
            }
            break;

        case 0x3e:

            // Target Part

            foreach (Ship concerned in System.Array.ConvertAll(concerned_objects, x => x as Ship))
            {
                if (concerned != null)
                {
                    concerned.TurretAim = aimable;
                }
            }
            break;

        default:
            break;
        }
        concerned_objects = new IMarkerParentObject [0];
        lasting_command   = -1;
    }