예제 #1
0
    internal BattleState GetNextState()
    {
        IEnumerable <BattleStateForces> nextAttackers = Attackers.Select(item => item.GetNextState(Defenders, Attackers)).ToArray();
        IEnumerable <BattleStateForces> nextDefenders = Defenders.Select(item => item.GetNextState(Attackers, Defenders)).ToArray();

        return(new BattleState(nextAttackers, nextDefenders));
    }
예제 #2
0
        public bool Damage(Character attacker, uint amount)
        {
            lock (this)
            {
                amount = Math.Min(amount, Health);

                //does the victim knows its attacker?
                if (Attackers.ContainsKey(attacker))
                {
                    //if so then add to his established dmg bill
                    Attackers[attacker] += amount;
                }
                else
                {
                    //if not so then add him as new attacker
                    Attackers.Add(attacker, amount);
                }

                Health -= amount;   //decrease health by amount dealt
                ShowHpTo(attacker); //show monster's remaining hp bar to attacker

                if (Health <= 0)    //???
                {
                    return(true);
                }

                return(false);
            }
        }
예제 #3
0
 private void HandleMultipleEnemies()
 {   //Credits to dgcfus for this snippet.
     if (Local.HasPet)
     {
         if (Attackers.Count >= 2 && Local.HasPet && Pet.IsAlive())
         {
             var attackUnit = Attackers.FirstOrDefault(Mob => Mob.TargetGuid == Local.Guid);
             if (attackUnit != null)
             {
                 Local.SetTarget(attackUnit);
                 if (!Pet.IsOnMyTarget())
                 {
                     Pet.Attack();
                     Pet.Cast("Suffering");
                 }
             }
             else
             {
                 int LowerHP     = Attackers.Min(Mob => Mob.HealthPercent);
                 var LowerHPUnit = Attackers.SingleOrDefault(Mob => Mob.HealthPercent == LowerHP);
                 if (LowerHPUnit != null && LowerHPUnit.Guid != Target.Guid)
                 {
                     Local.SetTarget(LowerHPUnit);
                 }
             }
         }
     }
 }
예제 #4
0
        public override Error CanWatchBattle(IPlayer player, out IEnumerable <string> errorParams)
        {
            // Owner of stronghold gets to peek at the # of units attacking
            if (stronghold.Tribe != null && player.IsInTribe && player.Tribesman.Tribe == stronghold.Tribe)
            {
                var attackingUnits = Attackers.AllCombatObjects().Sum(x => x.Count);
                if (attackingUnits >= 100)
                {
                    attackingUnits = (int)(Math.Round(attackingUnits * precision / 10) * 10);
                }

                errorParams = new[] { stronghold.Gate.ToString("#.##"), attackingUnits.ToString(CultureInfo.InvariantCulture) };
                return(Error.BattleViewableGateAttackingUnits);
            }

            var canWatchBattle = base.CanWatchBattle(player, out errorParams);

            if (canWatchBattle != Error.Ok)
            {
                return(canWatchBattle);
            }

            // Since the gate battle isn't really viewable, we just return an error message that includes the gate HP
            errorParams = new[] { stronghold.Gate.ToString("#.##") };
            return(Error.BattleViewableGateHp);
        }
예제 #5
0
 private void FightBtn_Click(object sender, EventArgs e)
 {
     FightBtn.Enabled = false;
     for (var i = 0; i < 10000; i++)
     {
         var attackersCopy = Attackers.Clone();
         var defendersCopy = Defenders.Clone();
         if (i % 2 == 0)
         {
             attackersCopy.FightWith(defendersCopy);
         }
         else
         {
             defendersCopy.FightWith(attackersCopy);
         }
         for (var j = 0; j < Attackers.Members.Count; j++)
         {
             Attackers.Members[j].Logs.UpdateLogs(attackersCopy.Members[j]);
         }
         for (var j = 0; j < Defenders.Members.Count; j++)
         {
             Defenders.Members[j].Logs.UpdateLogs(defendersCopy.Members[j]);
         }
     }
     SaveLogs();
     FightBtn.Enabled = true;
 }
예제 #6
0
 public void RefreshAttackers()
 {
     if (Attackers.Count >= 1)
     {
         foreach (var attacker in Attackers)
         {
             if (attacker.Value?.Player != null && attacker.Value.LastRefresh.AddSeconds(10) > DateTime.Now)
             {
                 if (attacker.Value.FadedToGray && MainAttacker == attacker.Value.Player)
                 {
                     attacker.Value.Player.SendPacket($"0|n|USH|{Id}");
                     attacker.Value.FadedToGray = false;
                 }
                 if (!attacker.Value.FadedToGray && MainAttacker != attacker.Value.Player)
                 {
                     attacker.Value.Player.SendPacket($"0|n|LSH|{Id}|{Id}");
                     attacker.Value.FadedToGray = true;
                 }
                 continue;
             }
             Attacker removedAttacker;
             Attackers.TryRemove(attacker.Key, out removedAttacker);
         }
     }
     if (MainAttacker != null)
     {
         if (!Attackers.ContainsKey(MainAttacker.Id))
         {
             MainAttacker = null;
         }
     }
 }
예제 #7
0
파일: Team.cs 프로젝트: LordEnigma/UO
        public override void Reset()
        {
            base.Reset();

            if (Flag != null)
            {
                Flag.Delete();
                Flag = null;
            }

            if (Attackers != null)
            {
                Attackers.Clear();
            }
            else
            {
                Attackers = new Dictionary <PlayerMobile, int>();
            }

            if (Defenders != null)
            {
                Defenders.Clear();
            }
            else
            {
                Defenders = new Dictionary <PlayerMobile, int>();
            }

            Caps = 0;
        }
예제 #8
0
        private void BattleEnded(bool writeReport)
        {
            if (writeReport)
            {
                BattleReport.CompleteBattle();
            }

            AboutToExitBattle(this, Attackers, Defenders);
            ExitBattle(this, Attackers, Defenders);

            foreach (var combatObj in Defenders.AllCombatObjects().Where(combatObj => !combatObj.IsDead))
            {
                combatObj.ExitBattle();
            }

            foreach (var combatObj in Attackers.AllCombatObjects().Where(combatObj => !combatObj.IsDead))
            {
                combatObj.ExitBattle();
            }

            foreach (var group in Attackers)
            {
                WithdrawAttacker(this, group);
            }

            foreach (var group in Defenders)
            {
                WithdrawDefender(this, group);
            }

            // Delete all groups
            Attackers.Clear();
            Defenders.Clear();
        }
예제 #9
0
        public void RunAll()
        {
            resetEvent = new AutoResetEvent(false);

            Attackers.ForEach(a => a.Attack());

            resetEvent.WaitOne();
        }
예제 #10
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        Attackers attacker = collision.gameObject.GetComponent <Attackers>();

        if (attacker)
        {
            animator.SetTrigger("underAttack trigger");
        }
    }
예제 #11
0
    void OnTriggerStay2D(Collider2D collider)
    {
        Attackers attackers = collider.gameObject.GetComponent <Attackers>();

        if (attackers)
        {
            animator.SetTrigger("underAttackTrigger");
        }
    }
예제 #12
0
        private bool IsBattleValid()
        {
            if (Attackers.Count == 0 || Defenders.Count == 0)
            {
                return(false);
            }

            // Check to see if all units in the defense is dead
            // and make sure units can still see each other
            return(Attackers.AllAliveCombatObjects().Any(combatObj => Defenders.HasInRange(combatObj)));
        }
예제 #13
0
    void OnTriggerEnter2D(Collider2D col)
    {
        Attackers a      = col.gameObject.GetComponent <Attackers>();
        Health    health = col.gameObject.GetComponent <Health>();

        if (a && health)
        {
            health.DealDamage(damage);
            Destroy(gameObject);
        }
    }
예제 #14
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Attackers attacker = collision.gameObject.GetComponent <Attackers>();
        Health    health   = collision.gameObject.GetComponent <Health>();

        if (attacker && health)
        {
            health.doDamage(damage);
            Destroy(gameObject);
        }
    }
예제 #15
0
    // Use this for initialization
    void Start()
    {
        projectileParent = GameObject.Find("Projectiles");
        if (!projectileParent)
        {
            projectileParent = new GameObject("Projectiles");
        }

        anim      = GetComponent <Animator>();
        attackers = GetComponent <Attackers>();
    }
예제 #16
0
 public void Respawn()
 {
     LastCombatTime      = DateTime.Now.AddSeconds(-999);
     CurrentHitPoints    = MaxHitPoints;
     CurrentShieldPoints = MaxShieldPoints;
     SetPosition(Position.Random(Spacemap, 0, 20800, 0, 12800));
     Spacemap.AddCharacter(this);
     Attackers.Clear();
     MainAttacker = null;
     Destroyed    = false;
 }
예제 #17
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        Attackers    attackers    = collider.gameObject.GetComponent <Attackers>();
        HealthSystem healthsystem = collider.gameObject.GetComponent <HealthSystem>();

        if (attackers && healthsystem)
        {
            healthsystem.DealDamage(damage);
            Destroy(gameObject);
        }
    }
예제 #18
0
    void OnTriggerEnter2D(Collider2D other)
    {
        Attackers attacker = other.gameObject.GetComponent <Attackers>();
        Health    health   = other.gameObject.GetComponent <Health>();

        if (attacker && health)
        {
            health.DealDamage(damage);
            Destroy(gameObject);
        }
    }
예제 #19
0
    private void SetAttackAndDefense()
    {
        Attackers.Clear();
        Defenders.Clear();

        List <Actor> units_within_range = FindObjectsOfType <Actor>().
                                          Where(actor => Vector3.Distance(actor.transform.position, transform.position) < influence_zone_radius).
                                          ToList();

        if (NodeFaction != null)
        {
            // attack and defense is determined by who currently claims the node

            for (int i = 0; i < units_within_range.Count; i++)
            {
                Actor actor = units_within_range[i];

                if (actor != null)
                {
                    if (actor.CurrentFaction.IsHostileTo(NodeFaction))
                    {
                        if (!Attackers.Contains(actor) && actor != null)
                        {
                            Attackers.Add(actor);
                        }
                    }
                    else
                    {
                        if (!Defenders.Contains(actor) && actor != null)
                        {
                            Defenders.Add(actor);
                        }
                    }
                }
            }
        }
        else
        {
            // the attackers are the faction with the most units; everybody else can try to kill them
            // NOTE: the faction that has the most units for the last boost gains the node (of course, then they have to keep it)

            var faction_units = units_within_range
                                .GroupBy(unit => unit.CurrentFaction,
                                         (faction, factions) => new {
                Key   = faction,
                Count = factions.Count()
            })
                                .OrderByDescending(faction => faction.Count);

            Attackers.AddRange(units_within_range.Where(unit => unit.CurrentFaction == faction_units.First().Key));
        }
    }
예제 #20
0
        public void Remove(ICombatGroup group, BattleSide side, ReportState state)
        {
            lock (battleLock)
            {
                // Remove from appropriate combat list
                if (side == BattleSide.Attack)
                {
                    if (!Attackers.Remove(group))
                    {
                        return;
                    }

                    group.CombatObjectAdded   -= AttackerGroupOnCombatObjectAdded;
                    group.CombatObjectRemoved -= AttackerGroupOnCombatObjectRemoved;
                }
                else
                {
                    if (!Defenders.Remove(group))
                    {
                        return;
                    }

                    group.CombatObjectAdded   -= DefenderGroupOnCombatObjectAdded;
                    group.CombatObjectRemoved -= DefenderGroupOnCombatObjectRemoved;
                }

                // If battle hasnt started then dont worry about cleaning anything up since nothing has happened to these objects
                if (!BattleStarted)
                {
                    return;
                }

                // Snap a report of exit
                BattleReport.WriteReportGroup(group, side == BattleSide.Attack, state);

                // Tell objects to exit from battle
                foreach (var co in group.Where(co => !co.Disposed))
                {
                    co.ExitBattle();
                }

                // Send exit events
                if (side == BattleSide.Attack)
                {
                    WithdrawAttacker(this, group);
                }
                else
                {
                    WithdrawDefender(this, group);
                }
            }
        }
예제 #21
0
 private void AddFighter(Fighter f)
 {
     if (AddToAttackers)
     {
         Attackers.Add(f);
         AttackersList.Items.Add(f.ToString());
     }
     else
     {
         Defenders.Add(f);
         DefendersList.Items.Add(f.ToString());
     }
 }
예제 #22
0
        public void DbLoaderAddToCombatList(ICombatGroup group, BattleSide side)
        {
            if (side == BattleSide.Defense)
            {
                Defenders.Add(group, false);
            }
            else
            {
                Attackers.Add(group, false);
            }

            groupIdGen.Set(group.Id);
        }
예제 #23
0
        public void DbFinishedLoading()
        {
            uint maxId =
                Math.Max(
                    Attackers.SelectMany(group => group)
                    .DefaultIfEmpty()
                    .Max(combatObject => combatObject == null ? 0 : combatObject.Id),
                    Defenders.SelectMany(group => group)
                    .DefaultIfEmpty()
                    .Max(combatObject => combatObject == null ? 0 : combatObject.Id));

            idGen.Set(maxId);
        }
예제 #24
0
    bool isTimeToSpawn(GameObject attackerObject)
    {
        Attackers a = attackerObject.GetComponent <Attackers>();
        float     meanSpwanDelay = a.seenEverySeconds;
        float     spawnpersecond = 1 / meanSpwanDelay;

        if (Time.deltaTime > meanSpwanDelay)
        {
            Debug.LogWarning("Spawn rate capped by frame rate");
        }
        float threshold = (spawnpersecond * Time.deltaTime) / 5;

        return(Random.value < threshold);
    }
예제 #25
0
    private bool IsTimeToSpawn(GameObject attackerGameObject)
    {
        Attackers attackers       = attackerGameObject.GetComponent <Attackers>();
        float     spawnDelay      = attackers.seenEverySeconds;
        float     spawnsPerSecond = 1 / spawnDelay;

        if (Time.deltaTime > spawnsPerSecond)
        {
            Debug.LogWarning("Spawn rate capped by frame rate");
        }
        float threshold = spawnsPerSecond * Time.deltaTime / 5;

        return(Random.value < threshold);
    }
예제 #26
0
    private void Start()
    {
        animator  = GetComponent <Animator>();
        attackers = GetComponent <Attackers>();

        if (PlayerPrefsManager.GetDifficulty() == 2)
        {
            attackers.seenEverySeconds = 6;
        }
        else if (PlayerPrefsManager.GetDifficulty() == 3)
        {
            attackers.seenEverySeconds = 5;
        }
    }
예제 #27
0
        private void BringWaitingTroopsIntoBattle()
        {
            foreach (var defender in Defenders.AllCombatObjects().Where(co => co.IsWaitingToJoinBattle))
            {
                defender.JoinBattle(Round);
                dbManager.Save(defender);
            }

            foreach (var attacker in Attackers.AllCombatObjects().Where(co => co.IsWaitingToJoinBattle))
            {
                attacker.JoinBattle(Round);
                dbManager.Save(attacker);
            }
        }
예제 #28
0
    bool isTimeToSpawn(GameObject attackerGameObject)
    {
        Attackers attackers       = attackerGameObject.GetComponent <Attackers>();
        float     meanSpawnDelay  = attackers.seenEverySeconds;
        float     spawnsPerSecond = 1 / meanSpawnDelay;

        if (Time.deltaTime > meanSpawnDelay)
        {
            Debug.LogWarning("Spawn Rate Capped Reached");
        }
        //Divided by 5 because we have 5 lanes
        float threshold = spawnsPerSecond * Time.deltaTime / 5;

        return(Random.value < threshold);
    }
예제 #29
0
    bool canSpawnCheck(GameObject objectToCheck)
    {
        Attackers attacker        = objectToCheck.GetComponent <Attackers>();
        float     meanSpawnDelay  = attacker.seenEverySeconds;
        float     spawnsPerSecond = 1 / meanSpawnDelay;
        int       numSpawners     = ResourceManager.GetNumSpawners() - 1;
        // threshold should be divided by num of attacker spawners or lanes

        float threshold = (spawnsPerSecond * Time.deltaTime) / numSpawners;
        float ranValue  = Random.value;

        //print("Spawn threshold is " + threshold + " With num spawners " + numSpawners);

        return(ranValue < threshold);
    }
예제 #30
0
        public Card FindAttackerWhichWillDealGreatestDamageToDefender(Func <Card, bool> filter = null)
        {
            filter = filter ?? delegate { return(true); };

            return(Attackers
                   .Where(x => filter(x))
                   .Select(x => new
            {
                Attacker = x,
                Damage = x.CalculateDefendingPlayerLifeloss()
            })
                   .Where(x => x.Damage > 0)
                   .OrderByDescending(x => x.Damage)
                   .Select(x => x.Attacker)
                   .FirstOrDefault());
        }
예제 #31
0
 // Use this for initialization
 void Start()
 {
     atkObj = GetComponent<Attackers>();
     anim = GetComponent<Animator>();
 }
예제 #32
0
파일: Lizard.cs 프로젝트: dustinbrink/unity
	// Use this for initialization
	void Start () {
		anim = GetComponent<Animator>();
		attacker = GetComponent<Attackers>();
	}