Esempio n. 1
0
        public virtual float Score(IAIContext context, BasePlayer option)
        {
            PlayerTargetContext playerTargetContext = context as PlayerTargetContext;

            if (playerTargetContext != null)
            {
                Scientist self = playerTargetContext.Self as Scientist;
                if (Object.op_Implicit((Object)self))
                {
                    Memory.ExtendedInfo extendedInfo = self.AiContext.Memory.GetExtendedInfo((BaseEntity)option);
                    if (Object.op_Inequality((Object)extendedInfo.Entity, (Object)null))
                    {
                        if ((double)Time.get_time() < (double)extendedInfo.LastHurtUsTime + (double)this.Timeout || self.HostilityConsideration(option))
                        {
                            return(this.score);
                        }
                        return(0.0f);
                    }
                    if (!self.HostilityConsideration(option))
                    {
                        return(0.0f);
                    }
                    return(this.score);
                }
            }
            return(0.0f);
        }
        public override void Execute(PlayerTargetContext context)
        {
            BaseContext baseContext = context.Self.GetContext(Guid.Empty) as BaseContext;

            if (baseContext != null)
            {
                float      danger          = 0f;
                BasePlayer basePlayer      = null;
                Vector3    position        = Vector3.zero;
                float      aggressionRange = baseContext.AIAgent.GetStats.AggressionRange * baseContext.AIAgent.GetStats.AggressionRange;
                for (int i = 0; i < baseContext.Memory.All.Count; i++)
                {
                    Memory.SeenInfo item   = baseContext.Memory.All[i];
                    BasePlayer      entity = item.Entity as BasePlayer;
                    if (entity != null)
                    {
                        Memory.ExtendedInfo extendedInfo = baseContext.Memory.GetExtendedInfo(item.Entity);
                        if (Time.time < extendedInfo.LastHurtUsTime + this.HostilityTimeout && item.Danger > danger && (item.Position - baseContext.Position).sqrMagnitude <= aggressionRange)
                        {
                            danger     = item.Danger;
                            basePlayer = entity;
                            position   = item.Position;
                        }
                    }
                }
                if (basePlayer != null)
                {
                    context.Target            = basePlayer;
                    context.Score             = danger;
                    context.LastKnownPosition = position;
                }
            }
        }
        public override float Score(IAIContext context, BasePlayer option)
        {
            PlayerTargetContext playerTargetContext = context as PlayerTargetContext;

            if (playerTargetContext != null)
            {
                Scientist self = playerTargetContext.Self as Scientist;
                if (self)
                {
                    Memory.ExtendedInfo extendedInfo = self.AiContext.Memory.GetExtendedInfo(option);
                    if (extendedInfo.Entity == null)
                    {
                        if (!self.HostilityConsideration(option))
                        {
                            return(0f);
                        }
                        return(this.score);
                    }
                    if (Time.time < extendedInfo.LastHurtUsTime + this.Timeout)
                    {
                        return(this.score);
                    }
                    if (!self.HostilityConsideration(option))
                    {
                        return(0f);
                    }
                    return(this.score);
                }
            }
            return(0f);
        }
Esempio n. 4
0
 public Memory.SeenInfo Update(
     BaseEntity entity,
     float score,
     Vector3 direction,
     float dot,
     float distanceSqr,
     byte lineOfSight,
     bool updateLastHurtUsTime,
     float lastHurtUsTime,
     out Memory.ExtendedInfo extendedInfo)
 {
     return(this.Update(entity, entity.ServerPosition, score, direction, dot, distanceSqr, lineOfSight, updateLastHurtUsTime, lastHurtUsTime, out extendedInfo));
 }
Esempio n. 5
0
 public Memory.ExtendedInfo GetExtendedInfo(BaseEntity entity)
 {
     Memory.ExtendedInfo extendedInfo;
     List <Memory.ExtendedInfo> .Enumerator enumerator = this.AllExtended.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             Memory.ExtendedInfo current = enumerator.Current;
             if (current.Entity != entity)
             {
                 continue;
             }
             extendedInfo = current;
             return(extendedInfo);
         }
         return(new Memory.ExtendedInfo());
     }
     finally
     {
         ((IDisposable)enumerator).Dispose();
     }
     return(extendedInfo);
 }
Esempio n. 6
0
 internal void Forget(float maxSecondsOld)
 {
     for (int i = 0; i < this.All.Count; i++)
     {
         float timestamp = Time.realtimeSinceStartup - this.All[i].Timestamp;
         if (timestamp > maxSecondsOld)
         {
             if (this.All[i].Entity != null)
             {
                 this.Visible.Remove(this.All[i].Entity);
                 int num = 0;
                 while (num < this.AllExtended.Count)
                 {
                     if (this.AllExtended[num].Entity != this.All[i].Entity)
                     {
                         num++;
                     }
                     else
                     {
                         this.AllExtended.RemoveAt(num);
                         break;
                     }
                 }
             }
             this.All.RemoveAt(i);
             i--;
         }
         else if (timestamp > 0f)
         {
             float single = timestamp / maxSecondsOld;
             if (this.All[i].Danger > 0f)
             {
                 Memory.SeenInfo item = this.All[i];
                 item.Danger -= single;
                 this.All[i]  = item;
             }
             if (timestamp >= 1f)
             {
                 int num1 = 0;
                 while (num1 < this.AllExtended.Count)
                 {
                     if (this.AllExtended[num1].Entity != this.All[i].Entity)
                     {
                         num1++;
                     }
                     else
                     {
                         Memory.ExtendedInfo extendedInfo = this.AllExtended[num1];
                         extendedInfo.LineOfSight = 0;
                         this.AllExtended[num1]   = extendedInfo;
                         break;
                     }
                 }
             }
         }
     }
     for (int j = 0; j < this.Visible.Count; j++)
     {
         if (this.Visible[j] == null)
         {
             this.Visible.RemoveAt(j);
             j--;
         }
     }
     for (int k = 0; k < this.AllExtended.Count; k++)
     {
         if (this.AllExtended[k].Entity == null)
         {
             this.AllExtended.RemoveAt(k);
             k--;
         }
     }
 }
Esempio n. 7
0
        public Memory.SeenInfo Update(BaseEntity entity, Vector3 position, float score, Vector3 direction, float dot, float distanceSqr, byte lineOfSight, bool updateLastHurtUsTime, float lastHurtUsTime, out Memory.ExtendedInfo extendedInfo)
        {
            Memory.ExtendedInfo extendedInfo1;
            extendedInfo = new Memory.ExtendedInfo();
            bool flag = false;
            int  num  = 0;

            while (num < this.AllExtended.Count)
            {
                if (this.AllExtended[num].Entity != entity)
                {
                    num++;
                }
                else
                {
                    Memory.ExtendedInfo item = this.AllExtended[num];
                    item.Direction   = direction;
                    item.Dot         = dot;
                    item.DistanceSqr = distanceSqr;
                    item.LineOfSight = lineOfSight;
                    if (updateLastHurtUsTime)
                    {
                        item.LastHurtUsTime = lastHurtUsTime;
                    }
                    this.AllExtended[num] = item;
                    extendedInfo          = item;
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                if (!updateLastHurtUsTime)
                {
                    extendedInfo1 = new Memory.ExtendedInfo()
                    {
                        Entity      = entity,
                        Direction   = direction,
                        Dot         = dot,
                        DistanceSqr = distanceSqr,
                        LineOfSight = lineOfSight
                    };
                    Memory.ExtendedInfo extendedInfo2 = extendedInfo1;
                    this.AllExtended.Add(extendedInfo2);
                    extendedInfo = extendedInfo2;
                }
                else
                {
                    extendedInfo1 = new Memory.ExtendedInfo()
                    {
                        Entity         = entity,
                        Direction      = direction,
                        Dot            = dot,
                        DistanceSqr    = distanceSqr,
                        LineOfSight    = lineOfSight,
                        LastHurtUsTime = lastHurtUsTime
                    };
                    Memory.ExtendedInfo extendedInfo3 = extendedInfo1;
                    this.AllExtended.Add(extendedInfo3);
                    extendedInfo = extendedInfo3;
                }
            }
            return(this.Update(entity, position, score));
        }
Esempio n. 8
0
        public Memory.SeenInfo Update(
            BaseEntity entity,
            Vector3 position,
            float score,
            Vector3 direction,
            float dot,
            float distanceSqr,
            byte lineOfSight,
            bool updateLastHurtUsTime,
            float lastHurtUsTime,
            out Memory.ExtendedInfo extendedInfo)
        {
            extendedInfo = new Memory.ExtendedInfo();
            bool flag = false;

            for (int index = 0; index < this.AllExtended.Count; ++index)
            {
                if (Object.op_Equality((Object)this.AllExtended[index].Entity, (Object)entity))
                {
                    Memory.ExtendedInfo extendedInfo1 = this.AllExtended[index];
                    extendedInfo1.Direction   = direction;
                    extendedInfo1.Dot         = dot;
                    extendedInfo1.DistanceSqr = distanceSqr;
                    extendedInfo1.LineOfSight = lineOfSight;
                    if (updateLastHurtUsTime)
                    {
                        extendedInfo1.LastHurtUsTime = lastHurtUsTime;
                    }
                    this.AllExtended[index] = extendedInfo1;
                    extendedInfo            = extendedInfo1;
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                if (updateLastHurtUsTime)
                {
                    Memory.ExtendedInfo extendedInfo1 = new Memory.ExtendedInfo()
                    {
                        Entity         = entity,
                        Direction      = direction,
                        Dot            = dot,
                        DistanceSqr    = distanceSqr,
                        LineOfSight    = lineOfSight,
                        LastHurtUsTime = lastHurtUsTime
                    };
                    this.AllExtended.Add(extendedInfo1);
                    extendedInfo = extendedInfo1;
                }
                else
                {
                    Memory.ExtendedInfo extendedInfo1 = new Memory.ExtendedInfo()
                    {
                        Entity      = entity,
                        Direction   = direction,
                        Dot         = dot,
                        DistanceSqr = distanceSqr,
                        LineOfSight = lineOfSight
                    };
                    this.AllExtended.Add(extendedInfo1);
                    extendedInfo = extendedInfo1;
                }
            }
            return(this.Update(entity, position, score));
        }
Esempio n. 9
0
 internal void Forget(float maxSecondsOld)
 {
     for (int index1 = 0; index1 < this.All.Count; ++index1)
     {
         float num1 = Time.get_realtimeSinceStartup() - this.All[index1].Timestamp;
         if ((double)num1 > (double)maxSecondsOld)
         {
             if (Object.op_Inequality((Object)this.All[index1].Entity, (Object)null))
             {
                 this.Visible.Remove(this.All[index1].Entity);
                 for (int index2 = 0; index2 < this.AllExtended.Count; ++index2)
                 {
                     if (Object.op_Equality((Object)this.AllExtended[index2].Entity, (Object)this.All[index1].Entity))
                     {
                         this.AllExtended.RemoveAt(index2);
                         break;
                     }
                 }
             }
             this.All.RemoveAt(index1);
             --index1;
         }
         else if ((double)num1 > 0.0)
         {
             float num2 = num1 / maxSecondsOld;
             if ((double)this.All[index1].Danger > 0.0)
             {
                 Memory.SeenInfo seenInfo = this.All[index1];
                 seenInfo.Danger -= num2;
                 this.All[index1] = seenInfo;
             }
             if ((double)num1 >= 1.0)
             {
                 for (int index2 = 0; index2 < this.AllExtended.Count; ++index2)
                 {
                     if (Object.op_Equality((Object)this.AllExtended[index2].Entity, (Object)this.All[index1].Entity))
                     {
                         Memory.ExtendedInfo extendedInfo = this.AllExtended[index2];
                         extendedInfo.LineOfSight = (byte)0;
                         this.AllExtended[index2] = extendedInfo;
                         break;
                     }
                 }
             }
         }
     }
     for (int index = 0; index < this.Visible.Count; ++index)
     {
         if (Object.op_Equality((Object)this.Visible[index], (Object)null))
         {
             this.Visible.RemoveAt(index);
             --index;
         }
     }
     for (int index = 0; index < this.AllExtended.Count; ++index)
     {
         if (Object.op_Equality((Object)this.AllExtended[index].Entity, (Object)null))
         {
             this.AllExtended.RemoveAt(index);
             --index;
         }
     }
 }