Exemple #1
0
    public void OnHit(
        int damage          = 0,
        int targetIndex     = 0,
        IAm targetIndexTeam = IAm.Ally
        )
    {
        if (_targetEnemyIndex != null)
        {
            var targetEnemy = Fight._.GetUnit(_targetEnemyTeam, _targetEnemyIndex.Value);

            var curHealth = targetEnemy.Stats.CurrentHealth - _unit.Stats.AttackDamage;
            if (curHealth < 0)
            {
                KillTarget(targetEnemy);
            }
            else
            {
                targetEnemy.Stats.CurrentHealth = curHealth;
            }
        }
        else if (Intell.IsEnemyInViewRange() == false)
        {
            Fight.ExecuteOrder66(GetComponent <Unit>(), ally: Intell.IAm == IAm.Ally);
        }
    }
Exemple #2
0
    public void TrySetTarget(GameObject unitGo)
    {
        if (_targetEnemyIndex == null)
        {
            var unit = unitGo.GetComponent <Unit>();
            if (unit.Stats.IsDead)
            {
                return;
            }
            _targetEnemyIndex = unit._unit.Index;
            _targetEnemyTeam  = unit.Intell.IAm;
        }

        if (_targetEnemyIndex == null)
        {
            return;
        }

        //Debug.Log(gameObject.name + ": I will deal with the enemy (" + TargetEnemy.gameObject.name + ")");

        var targetEnemy = Fight._.GetUnit(_targetEnemyTeam, _targetEnemyIndex.Value);

        var distance = Vector3.Distance(transform.position, targetEnemy.transform.position);

        if (_unit.Stats.AttackRange >= distance)
        {
            EnemyInRange(unitGo);
        }
        else
        {
            Intell.AtackSensor.gameObject.SetActive(true);
            _moveController.FollowObject(targetEnemy.transform);
        }
    }
Exemple #3
0
    /// <summary>
    ///                                                                         THE ORDER HERE IS VERY IMPORTANT !!!!!
    /// </summary>
    /// <param name="iAm"></param>
    public void Init(int index, IAm iAm = IAm.Ally, bool startImobilized = false)
    {
        _unit = GetComponent <IUnit>();

        _unit.Index = index;

        SetupInteligence(iAm);

        SetupStats();

        SetupMovement(startImobilized);

        SetupAttack();

        _unit.Init(_attackController.OnHit);

        //var navAgent = GetComponent<NavMeshAgent>();
        //if (navAgent == null)
        //{
        //    Debug.LogError("Unit has no navAgent. You can't move without it.");
        //    return;
        //}
        //MoveController.Init(UnitName, navAgent, _unit, startImobilized);
        //MoveController.StopMoving(targetReached: false);
    }
Exemple #4
0
    public void EnemyInRange(GameObject unitGo = null)
    {
        if (unitGo == null)
        {
            return;
        }

        var unit = unitGo.GetComponent <Unit>();

        if (unit.Stats.IsDead)
        {
            return;
        }
        _targetEnemyIndex = unit._unit.Index;
        _targetEnemyTeam  = unit.Intell.IAm;

        //Debug.Log(gameObject.name + ": enemy (" + TargetEnemy.gameObject.name + ") is in range.");

        _moveController.StopMoving(false);
        _unit.Attack();

        FightUtils.FaceEnemy(unitGo.transform.position, transform, onlyY: false);

        Intell.AtackSensor.gameObject.SetActive(false);
    }
Exemple #5
0
 public Unit GetUnit(IAm targetEnemyTeam, int targetEnemyIndex)
 {
     if (targetEnemyTeam == IAm.Ally)
     {
         return(_.PlayerUnits[targetEnemyIndex]);
     }
     return(_.EnemyUnits[targetEnemyIndex]);
 }
Exemple #6
0
 public void InitUnit(int index, Unit unit, IAm iAm)
 {
     if (unit)
     {
         unit.Init(index, iAm);
     }
     else
     {
         Debug.Log("No " + iAm.ToString() + " unit !");
     }
 }
        public void IAm()
        {
            var apdu = new IAm();
            apdu.deviceObject = new BacNetObject {ObjectId = BacNetDevice.Instance.DeviceId, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_DEVICE};
            apdu.MaxApduLength = new BacNetUInt {Value = 480};
            apdu.SegmentationSupported = BacNetEnums.BACNET_SEGMENTATION.SEGMENTATION_NONE;
            apdu.VendorId = new BacNetUInt { Value = 500 };

            var npdu = new BacNetIpNpdu();
            npdu.Source = new BacNetAddress { Address = ByteConverter.GetBytes(BacNetDevice.Instance.DeviceId), Network = ByteConverter.GetBytes((ushort)60001), HopCount = 255};

            BacNetDevice.Instance.Services.Execute(npdu, apdu);
        }
Exemple #8
0
 private void SetupInteligence(IAm iAm)
 {
     Intell = GetComponent <Intell>();
     if (Intell == null)
     {
         Debug.LogError("Unit has no inteligence.");
         return;
     }
     _unit.Intell = Intell;
     Intell.IAm   = iAm;
     Intell.Init(_unit);
     gameObject.tag = iAm.ToString();
 }
Exemple #9
0
        internal static Projectile GetAvailableProjectile(
            List <Projectile> gameObjects,
            CreateProjectile createProjectile,
            Unit.OnHit onHit,
            IAm iAm,
            ref int?projectileIndex
            )
        {
            Projectile go = null;
            int        i  = 0;

            foreach (Projectile obj in gameObjects)
            {
                if (obj.Available == true)
                {
                    go = obj;
                    projectileIndex = i;
                    //Debug.Log(obj.gameObject.activeSelf + " :" + DateTime.Now);
                    break;
                }
                i++;
            }

            if (go == null)
            {
                HitArea arrowHitArea = null;
                go = createProjectile(go);
                foreach (Transform hA in go.transform)
                {
                    arrowHitArea = hA.GetComponent <HitArea>();
                    if (arrowHitArea != null)
                    {
                        break;
                    }
                }
                if (arrowHitArea != null)
                {
                    arrowHitArea.Init(onHit, iAm.ToString(), isProjectile: true, projectile: go);
                }

                return(go);
            }
            else
            {
                return(null);
            }
        }
Exemple #10
0
        public void ReceivedIAm(BacNetRawMessage msg, IPEndPoint endPoint)
        {
            BacNetRemoteDevice newDevice = new BacNetRemoteDevice();

            newDevice.EndPoint = endPoint;

            BacNetIpNpdu npdu;
            IAm          apdu;

            try
            {
                npdu = new BacNetIpNpdu(msg.Npdu);
                apdu = new IAm(msg.Apdu);
            }
            catch (Exception ex)
            {
                _logger.WarnException("Received malformed I-am", ex);
                return;
            }

            if (npdu.Source != null)
            {
                newDevice.BacAddress = npdu.Source;
            }
            newDevice.MaxApduLength  = apdu.MaxApduLength;
            newDevice.InstanceNumber = apdu.deviceObject.ObjectId;
            newDevice.Segmentation   = apdu.SegmentationSupported;
            newDevice.VendorId       = apdu.VendorId;

            if (newDevice.InstanceNumber == BacNetDevice.Instance.DeviceId)
            {
                return;
            }

            BacNetRemoteDevice rem =
                BacNetDevice.Instance.Remote.FirstOrDefault(s => s.InstanceNumber == newDevice.InstanceNumber);

            if (rem != null)
            {
                BacNetDevice.Instance.Remote.Remove(rem);
            }

            BacNetDevice.Instance.Remote.Add(newDevice);
        }
Exemple #11
0
    public static HealthBar CreateHPBar(IUnit unit, Transform hpTarget, IAm iAm)
    {
        if (HealthBarController._.gameObject.activeSelf == false)
        {
            HealthBarController._.gameObject.SetActive(true);
        }

        GameObject go = Instantiate(
            Resources.Load("Prefabs/UI/HealthBar", typeof(GameObject)),
            Vector3.zero, Quaternion.identity, HealthBarController._.transform
            ) as GameObject;
        var rect = go.GetComponent <RectTransform>();

        rect.localPosition    = Vector3.zero;
        rect.localEulerAngles = Vector3.zero;

        var hp      = go.GetComponent <HealthBar>();
        var hpColor = (iAm == IAm.Ally) ? ColorBank._.Green_Pastel_Darker : ColorBank._.Red_Maroon_Flush;

        hp.HealthImage.color = hpColor;
        hp.Init(unit, hpTarget, HealthBarController._.CanvasRect);
        return(hp);
    }
Exemple #12
0
 internal static IAm OppositeTeam(IAm iam)
 {
     return(iam == IAm.Ally ? IAm.Enemy : IAm.Ally);
 }
Exemple #13
0
        public void ReceivedIAm(BacNetRawMessage msg, IPEndPoint endPoint)
        {
            BacNetRemoteDevice newDevice = new BacNetRemoteDevice();
            newDevice.EndPoint = endPoint;

            BacNetIpNpdu npdu;
            IAm apdu;
            try
            {
                npdu = new BacNetIpNpdu(msg.Npdu);
                apdu = new IAm(msg.Apdu);
            }
            catch (Exception ex)
            {
                _logger.WarnException("Received malformed I-am", ex);
                return;
            }

            if (npdu.Source != null)
                newDevice.BacAddress = npdu.Source;
            newDevice.MaxApduLength = apdu.MaxApduLength;
            newDevice.InstanceNumber = apdu.deviceObject.ObjectId;
            newDevice.Segmentation = apdu.SegmentationSupported;
            newDevice.VendorId = apdu.VendorId;

            if (newDevice.InstanceNumber == BacNetDevice.Instance.DeviceId)
                return;

            BacNetRemoteDevice rem =
                BacNetDevice.Instance.Remote.FirstOrDefault(s => s.InstanceNumber == newDevice.InstanceNumber);
            if (rem != null)
                BacNetDevice.Instance.Remote.Remove(rem);

            BacNetDevice.Instance.Remote.Add(newDevice);
        }