Exemple #1
0
        public void Reset(bool resetPlayer = true)
        {
            if (resetPlayer)
            {
                Player.Reset();
            }

            m_Creatures.ForEach(creature => creature.Reset());

            m_Creatures.Clear();
            m_CreatureCount = 0;
            m_CreatureIndex = 0;

            if (!resetPlayer)
            {
                ReplaceCreature(Player);
            }

            m_Opponents.Clear();
            m_OpponentState = OpponentStates.NoAction;
            Aim             = null;
            AttackTarget    = null;
            FollowTarget    = null;
            Trappers        = null;
        }
Exemple #2
0
        public void RefreshOpponents()
        {
            switch (m_OpponentState)
            {
            case OpponentStates.NoAction:
                break;

            case OpponentStates.Refresh:
            case OpponentStates.Rebuild: {
                m_Opponents.Clear();
                for (int i = 0; i < m_CreatureCount; i++)
                {
                    Creature creature = m_Creatures[i];
                    if (IsOpponent(creature, true))
                    {
                        m_Opponents.Add(creature);
                    }
                }

                m_Opponents.Sort(OpponentComparator);
                onOpponentsRebuilt.Invoke(m_Opponents);
                break;
            }
            }

            m_OpponentState = OpponentStates.NoAction;
        }
Exemple #3
0
 public void InvalidateOpponents()
 {
     if (m_OpponentState < OpponentStates.Refresh)
     {
         m_OpponentState = OpponentStates.Refresh;
     }
 }
Exemple #4
0
        public Creature ReplaceCreature(Creature creature, uint id = 0)
        {
            if (!creature)
            {
                throw new System.ArgumentException("CreatureStorage.replaceCreature: Invalid creature.");
            }

            if (id != 0)
            {
                RemoveCreature(id);
            }

            if (m_CreatureCount >= m_MaxCreaturesCount)
            {
                throw new System.ArgumentException("CreatureStorage.replaceCreature: No space left to append " + creature.ID);
            }

            int index     = 0;
            int lastIndex = m_CreatureCount - 1;

            while (index <= lastIndex)
            {
                int tmpIndex      = index + lastIndex >> 1;
                var foundCreature = m_Creatures[tmpIndex];
                if (foundCreature.ID < creature.ID)
                {
                    index = tmpIndex + 1;
                }
                else if (foundCreature.ID > creature.ID)
                {
                    lastIndex = tmpIndex - 1;
                }
                else
                {
                    return(foundCreature);
                }
            }

            creature.KnownSince = ++m_CreatureIndex;
            m_Creatures.Insert(index, creature);
            m_CreatureCount++;
            m_OpponentState = OpponentStates.Rebuild;
            return(creature);
        }
Exemple #5
0
        public void RemoveCreature(uint id)
        {
            int currentIndex = 0;
            int lastIndex    = m_CreatureCount - 1;

            int      foundIndex    = -1;
            Creature foundCreature = null;

            while (currentIndex <= lastIndex)
            {
                int tmpIndex = currentIndex + lastIndex >> 1;
                foundCreature = m_Creatures[tmpIndex];
                if (foundCreature.ID < id)
                {
                    currentIndex = tmpIndex + 1;
                }
                else if (foundCreature.ID > id)
                {
                    lastIndex = tmpIndex - 1;
                }
                else
                {
                    foundIndex = tmpIndex;
                    break;
                }
            }

            if (!foundCreature || foundIndex < 0)
            {
                throw new System.ArgumentException("CreatureStorage.RemoveCreature: creature " + id + " not found");
            }
            else if (foundCreature == Player)
            {
                throw new System.Exception("CreatureStorage.RemoveCreature: cannot remove player.");
            }

            if (foundCreature == Aim)
            {
                Aim = null;
                UpdateExtendedMark(foundCreature);
            }

            if (foundCreature == AttackTarget)
            {
                AttackTarget = null;
                UpdateExtendedMark(foundCreature);
            }

            if (foundCreature == FollowTarget)
            {
                FollowTarget = null;
                UpdateExtendedMark(foundCreature);
            }

            if (Trappers != null)
            {
                int index = Trappers.FindIndex((x) => x == foundCreature);
                if (index > 0)
                {
                    Trappers[index].Trapper = false;
                    Trappers.RemoveAt(index);
                }
            }

            foundCreature.Reset();
            m_Creatures.RemoveAt(foundIndex);
            m_CreatureCount--;
            m_OpponentState = OpponentStates.Rebuild;
        }