//Enter attack
        //Send back targets
        //Select Primary Target or Cancel
        //Fire attack
        public List <BlobScript> GetPossibleTargets(BlobScript attacker, List <BlobScript> pTargets)
        {
            //Empty target list
            possibleTargets = pTargets;
            var tempTargets = new List <BlobScript>(pTargets);

            //get input attacker
            myBlob = attacker;
            //Where are they?
            //Get the blobs location
            //What is my range?

            //Search map for targets
            foreach (BlobScript thisBlob in possibleTargets)
            {
                if (!InRange(myBlob, thisBlob))
                {
                    bool removeSuccess = tempTargets.Remove(thisBlob);
                    if (!removeSuccess)
                    {
                        Debug.Log("Failed to remove blobscript, " + thisBlob + "from attack targets. Error may have occured.");
                    }
                }
            }
            possibleTargets = tempTargets; //TODO fritz is this the expected behavior of this method? I modefied it a touch

            return(tempTargets);
        }
        public override void TakeTurn(BlobScript source, List <BlobScript> allyBlobs, List <BlobScript> enemyBlobs)
        {
            _me         = source;
            _allyBlobs  = allyBlobs;
            _enemyBlobs = enemyBlobs;

            //if there are no allies to protect behave like a warrior
            if (!PriorityTargetsToDefend())
            {
                var a       = new PunchAttack();
                var targets = a.GetPossibleTargets(source, enemyBlobs.ToList());
                if (targets.Count > 0)
                {
                    a.FireAttack(source, targets.First());
                    return;
                }

                var target = DetermineTarget();

                source.transform.position = MoveTo(source.transform.position, target.transform.position, 5f);
            }

            var moveTo = DetermineAverageOfPos();

            source.transform.position = MoveTo(source.transform.position, moveTo, 5f);


            UnityEngine.Object.FindObjectOfType <God>().EndTurn();
        }
Example #3
0
        private void CreateLineup()
        {
            TeamOneBlobs = new List <BlobScript>();
            TeamTwoBlobs = new List <BlobScript>();

            var texts = FindObjectsOfType(typeof(Text)).ToList().OrderBy(x => ((Text)x).text);
            var stats = texts.ToList();

            stats.RemoveAt(0);

            for (int i = 0; i < 3; i++)
            {
                var blobT1 = Instantiate(blobPrefab, _blueStartPos[i], Quaternion.identity);
                blobT1.GetComponent <SpriteRenderer>().color = Color.blue;
                blobT1.GetComponent <BlobScript>().SetClass(_teamOneClasses[i], _teamOneBrains[i], this);
                blobT1.GetComponentInChildren <Canvas>().enabled = false;
                blobT1.transform.localScale = new Vector2(_vsScale, _vsScale);
                TeamOneBlobs.Add(blobT1.GetComponent <BlobScript>());
                BlobScript blobT1Script = blobT1.GetComponent <BlobScript>();
                ((Text)stats.ElementAt(i)).text = string.Format(BlobStatsFormat, i + 1, blobT1Script.GetClass().ToString(), blobT1Script.GetHealth(), blobT1Script.GetAttack(), blobT1Script.GetDefense(), blobT1Script.GetInitiative(), blobT1Script.GetInitiativBonus());

                var blobT2 = Instantiate(kappa, _redStartPos[i], Quaternion.identity);
                blobT2.GetComponent <SpriteRenderer>().color = Color.red;
                blobT2.GetComponent <BlobScript>().SetClass(_teamTwoClasses[i], _teamTwoBrains[i], this);
                blobT2.GetComponentInChildren <Canvas>().enabled = false;
                blobT2.transform.localScale = new Vector2(_vsScale, _vsScale);
                TeamTwoBlobs.Add(blobT2.GetComponent <BlobScript>());
                BlobScript blobT2Script = blobT2.GetComponent <BlobScript>();
                ((Text)stats.ElementAt(i + 3)).text = string.Format(BlobStatsFormat, i + 3 + 1, blobT2Script.GetClass().ToString(), blobT2Script.GetHealth(), blobT2Script.GetAttack(), blobT2Script.GetDefense(), blobT2Script.GetInitiative(), blobT2Script.GetInitiativBonus());
            }
        }
Example #4
0
        public override void TakeTurn(BlobScript source, List <BlobScript> allyBlobs, List <BlobScript> enemyBlobs)
        {
            _me         = source;
            _allyBlobs  = allyBlobs;
            _enemyBlobs = enemyBlobs;

            BaseAttack a       = new PunchAttack();
            var        targets = a.GetPossibleTargets(source, enemyBlobs.ToList());

            /*
             * if (source.GetUltCharge() >= 100)
             * {
             *  a = new WhirlwindStrikeUlt();
             *  a.FireAttack(_me, targets);
             *  _me.ResetUltCharge();
             *  return;
             * }*/

            if (targets.Count > 0)
            {
                a.FireAttack(source, targets.First());
                return;
            }


            var close  = 1000;
            var x      = 0;
            var y      = 0;
            var target = DetermineTarget();
            var loc    = target.GetGridLocation();
            var myLoc  = _me.GetGridLocation();

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    if (GridService.Instance.SpaceOccupied((int)loc.x + i, (int)loc.y + j) || !GridService.Instance.IsInGrid((int)loc.x + i, (int)loc.y + j))
                    {
                        continue;
                    }
                    var dis = GridService.Instance.GetDistance(myLoc, new Vector2(loc.x + i, loc.y + j));
                    if (dis < close && dis != 0)
                    {
                        close = dis;
                        x     = (int)loc.x + i;
                        y     = (int)loc.y + j;
                    }
                }
            }

            var newGridLoc = MoveTo(myLoc, new Vector2(x, y), 5f);

            source.SetGridLocation((int)newGridLoc.x, (int)newGridLoc.y);
            source.transform.position = GridService.Instance.ConvertToPoint(newGridLoc);
            //source.GetComponent<Rigidbody2D>().MovePosition(MoveTo(source.transform.position, target.transform.position, 5f));

            God.Instance.EndTurn();
        }
Example #5
0
 //clean up parent/attacker references
 //this should be moved into base attack, with the arrow being passed in as a references
 public void ShowAttack(BlobScript target, BlobScript source)
 {
     //var NewArrow = Instantiate()
     var pointyThing = (GameObject)Resources.Load("Prefabs/PointyArrow", typeof(GameObject));
     //Debug.Log(pointyThing);
     var myThing = UnityEngine.Object.Instantiate(pointyThing, new Vector3(source.transform.position.x, source.transform.position.y, source.transform.position.z - 1), Quaternion.identity);
     //ArrowScript myScript = myThing.GetComponent<ArrowScript>();
     //myScript.setTargetAndParent(source, target, this);
 }
Example #6
0
        public void setTargetAndParent(BlobScript parent, BlobScript enemy, BaseAttack source, int code)
        {
            creator      = parent;
            target       = enemy;
            sourceAttack = source;
            trackingCode = code;


            setState(2);
        }
        public override void TakeTurn(BlobScript source, List <BlobScript> allyBlobs, List <BlobScript> enemyBlobs)
        {
            _me         = source;
            _allyBlobs  = allyBlobs;
            _enemyBlobs = enemyBlobs;

            var criticalList = new List <BlobScript>();
            var lowList      = new List <BlobScript>();

            //prioritize low health allies

            /*
             * foreach (var ally in _allyBlobs)
             * {
             *  if (ally.GetHealth() < 50)
             *  {
             *      criticalList.Add(ally);
             *  }
             *  else if (ally.GetHealth() < 150)
             *  {
             *      lowList.Add(ally);
             *  }
             * }
             * Debug.Log(criticalList.Count);
             * if (criticalList.Count > 0)
             * {
             *  foreach (var criticalAlly in criticalList)
             *  {
             *      if (_me.MoveSet().ElementAt(1).InRange(_me, criticalAlly))
             *      {
             *          _me.MoveSet().ElementAt(1).FireSpell(source, criticalList.First());
             *          return;
             *      }
             *  }
             *  var close = FindClosestAlly(criticalList);
             *
             *
             *
             * }
             *
             * if (EnemyInRange())
             * {
             *
             * }
             *
             * var target = DetermineTarget();*/

            var safe = MovementService.Instance.FindSafestInRange(_me, _enemyBlobs, _me.GetMovement());

            source.transform.position = MoveTo(source.transform.position, safe, 5f);
            //source.GetComponent<Rigidbody2D>().MovePosition(MoveTo(source.transform.position, target.transform.position, 5f));

            UnityEngine.Object.FindObjectOfType <God>().EndTurn();
        }
Example #8
0
 public bool IsInRange(BlobScript target)
 {
     foreach (var attack in _class.AttackList)
     {
         if (attack.InRange(this, target))
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// Gets a sorted list of distnaces from a position
        /// </summary>
        /// <param name="myPos"></param>
        /// <param name="otherPositions"></param>
        /// <returns></returns>
        public List <Tuple <float, BlobScript> > DistancesToMulti(BlobScript myPos, List <BlobScript> otherPositions)
        {
            List <Tuple <float, BlobScript> > distances = new List <Tuple <float, BlobScript> >();

            foreach (var pos in otherPositions)
            {
                distances.Add(new Tuple <float, BlobScript>(Vector3.Distance(myPos.transform.position, pos.transform.position), pos));
            }


            return(distances.OrderBy(x => x.Item1).ToList());
        }
Example #10
0
        public void KillBlob(BlobScript blob)
        {
            TeamOneBlobs.Remove(blob);
            TeamTwoBlobs.Remove(blob);

            var temp = _turnOrder.ToList();

            temp.Remove(blob);

            _turnOrder = new Queue <BlobScript>(temp);

            GameObject.Destroy(blob.gameObject);
        }
        public bool InRangeC(BlobScript attacker, BlobScript target)
        {
            var attackerLoc = attacker.GetGridLocation();
            var targetLoc   = target.GetGridLocation();
            var xdis        = Math.Pow(targetLoc.x - attackerLoc.x, 2);
            var ydis        = Math.Pow(targetLoc.y - attackerLoc.y, 2);

            var c = (int)Math.Sqrt(xdis + ydis);

            //for close distances calculating the hypotenuse is a resonable approximation of diagonals counting as 1 square
            if (attackRange <= 2 && c <= attackRange)
            {
                return(true);
            }

            return(GridService.Instance.GetDistance(attackerLoc, targetLoc) <= attackRange);
        }
        public bool InRange(BlobScript attacker, BlobScript target)
        {
            var attackerLoc = attacker.GetGridLocation();
            var targetLoc   = target.GetGridLocation();
            var xdis        = Math.Abs(targetLoc.x - attackerLoc.x);
            var ydis        = Math.Abs(targetLoc.y - attackerLoc.y);

            if (xdis > ydis)
            {
                return(xdis <= attackRange);
            }

            if (ydis > xdis)
            {
                return(ydis <= attackRange);
            }

            return(ydis <= attackRange);
        }
Example #13
0
        public override bool FireSpell(BlobScript source, BlobScript target)
        {
            //Debug.Log("Firing Punch Attack");
            //Not done, needs a lot of work.
            if (true)
            //replace above statement with a range checker
            {
                ShowAttack(target, source);
                int dmg = source.GetSpecialAttack();
                if (dmg < 0)
                {
                    dmg = 0;
                }
                //Debug.Log(dmg);
                target.RestoreHealth(dmg);
            }



            return(true);
        }
Example #14
0
        public override bool FireAttack(BlobScript source, BlobScript target)
        {
            _target = target;
            _source = source;
            //Debug.Log("Firing Punch Attack");
            //Not done, needs a lot of work.
            if (true)
            //replace above statement with a range checker
            {
                ShowAttack(target, source);
                int dmg = source.GetAttack() - target.GetDefense();
                if (dmg < 0)
                {
                    dmg = 0;
                }
                //Debug.Log(dmg);
                target.TakeDamage(dmg);
                source.ChargeUlt(dmg, 0);
            }

            return(true);
        }
Example #15
0
 public void TakeTurn(BlobScript me, List <BlobScript> allyBlobs, List <BlobScript> enemyBlobs)
 {
     _brain.TakeTurn(me, allyBlobs, enemyBlobs);
 }
Example #16
0
 public override void TakeTurn(BlobScript source, List <BlobScript> allyBlobs, List <BlobScript> enemyBlobs)
 {
     //me.transform.position = new Vector3(me.transform.position.x + 3, me.transform.position.y);
 }
Example #17
0
        public BlobScript FarthestBlob(BlobScript myPos, List <BlobScript> otherPositions)
        {
            var distances = DistancesToMulti(myPos, otherPositions);

            return(distances.LastOrDefault().Item2);
        }
Example #18
0
        public BlobScript ClostedBlob(BlobScript myPos, List <BlobScript> otherPositions)
        {
            var distances = DistancesToMulti(myPos, otherPositions);

            return(distances.FirstOrDefault().Item2);
        }
Example #19
0
 private const int _blobDistance = 4; // The distance where two blobs are next to each other
 public virtual void TakeTurn(BlobScript me, List <BlobScript> allyBlobs, List <BlobScript> enemyBlobs)
 {
 }
 protected float calcDistince(BlobScript attacker, BlobScript target)
 {
     //calculate range between blob attacker, and blob target
     return(Vector3.Distance(attacker.transform.position, target.transform.position));
 }
 //Returns true if attack successfully fires. Returns false if target is illegal, or attack fails for some reason.
 public virtual bool FireAttack(BlobScript attacker, List <BlobScript> targets)
 {
     //Not done, needs a lot of work.
     return(false);
 }
 private BlobScript DetermineBlobTarget(BlobScript blob)
 {
     return(ClostedBlob(blob, _enemyBlobs.ToList()));
 }
 //Returns true if attack successfully fires. Returns false if target is illegal, or attack fails for some reason.
 public virtual bool FireSpell(BlobScript attacker, BlobScript target)
 {
     return(false);
 }