Ejemplo n.º 1
0
        private static bool IsWantedTargetForRandomTarget(CharacterInfo srcObj, CharacterRelation relation, AiTargetType type, ISpaceObject obj)
        {
            if (type == AiTargetType.USER && obj.GetObjType() != SpatialObjType.kUser)
            {
                return(false);
            }
            if (type == AiTargetType.NPC && obj.GetObjType() != SpatialObjType.kNPC)
            {
                return(false);
            }
            CharacterInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, (int)obj.GetID());

            if (null != target && !target.IsDead())
            {
                if (target.IsControlMecha)
                {
                    return(false);
                }
                NpcInfo npcTarget = target.CastNpcInfo();
                if (null != npcTarget && npcTarget.NpcType == (int)NpcTypeEnum.Skill)
                {
                    return(false);
                }
                if (relation == CharacterInfo.GetRelation(srcObj, target))
                {
                    if (CanSee(srcObj, target))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
 // private functions------------------------------------------------------
 private bool IsPassableCollide(ISpaceObject hiter, ISpaceObject dest)
 {
     if ((hiter.GetObjType() == SpatialObjType.kNPC || hiter.GetObjType() == SpatialObjType.kUser) &&
         (dest.GetObjType() == SpatialObjType.kNPC || dest.GetObjType() == SpatialObjType.kUser))
     {
         return(false);
     }
     if (hiter.GetID() == dest.GetID() && hiter.GetObjType() == dest.GetObjType())
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
        private static void GetInterestestTarget(CharacterInfo srcObj, CharacterRelation relation, AiTargetType type, float powDist, ISpaceObject obj, ref float minPowDist, ref CharacterInfo interestestTarget)
        {
            if (type == AiTargetType.USER && obj.GetObjType() != SpatialObjType.kUser)
            {
                return;
            }
            if (type == AiTargetType.TOWER && obj.GetObjType() != SpatialObjType.kNPC)
            {
                return;
            }
            if (type == AiTargetType.SOLDIER && obj.GetObjType() != SpatialObjType.kNPC)
            {
                return;
            }
            CharacterInfo target = GetSeeingLivingCharacterInfoHelper(srcObj, (int)obj.GetID());

            if (null != target && !target.IsDead())
            {
                if (target.IsControlMecha)
                {
                    return;
                }
                NpcInfo npcTarget = target.CastNpcInfo();
                if (null != npcTarget && npcTarget.NpcType == (int)NpcTypeEnum.Skill)
                {
                    return;
                }
                if (type == AiTargetType.SOLDIER && npcTarget.IsPvpTower)
                {
                    return;
                }
                if (type == AiTargetType.TOWER && !npcTarget.IsPvpTower)
                {
                    return;
                }

                if (relation == CharacterInfo.GetRelation(srcObj, target))
                {
                    if (powDist < minPowDist)
                    {
                        if (powDist > c_MaxViewRangeSqr || CanSee(srcObj, target))
                        {
                            interestestTarget = target;
                            minPowDist        = powDist;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public bool CheckCollide(ISpaceObject hiter, ISpaceObject dest)
        {
            Shape srcShape  = hiter.GetCollideShape();
            Shape destShape = dest.GetCollideShape();

            if (null == srcShape)
            {
                LogSystem.Error("CheckCollide:hiter obj({0}[{1}])'s shape is null", hiter.GetID(), hiter.GetObjType());
                return(false);
            }
            if (null == destShape)
            {
                LogSystem.Error("CheckCollide:dest obj({0}[{1}])'s shape is null", dest.GetID(), dest.GetObjType());
                return(false);
            }
            bool is_collide          = collide_detector_.Intersect(srcShape, destShape);
            bool is_allready_collide = IsAllreadyCollide(hiter, dest);

            if (is_collide)               // 碰撞
            {
                if (!is_allready_collide) // 之前没有碰撞,记录下相撞的物体
                //DLog._("spatialsystem", "{4} spatial collide obj({0},{1}) with obj({2},{3})",
                //           hiter.GetID(), hiter.GetObjType(), dest.GetID(),
                //           dest.GetObjType(), current_spatial_id_);
                {
                    hiter.OnCollideObject(dest);
                    dest.OnCollideObject(hiter);
                }
            }
            else if (is_allready_collide) // 当前没有碰撞,但是之前碰撞,即分离的情况
            //DLog._("spatialsystem", "{4} spatial depart obj({0},{1}) with obj({2},{3})",
            //           hiter.GetID(), hiter.GetObjType(),
            //           dest.GetID(), dest.GetObjType(), current_spatial_id_);
            {
                hiter.OnDepartObject(dest);
                dest.OnDepartObject(hiter);
            }
            return(is_collide);
        }
Ejemplo n.º 5
0
        private List <ISpaceObject> GetObjectCrossByLine(Vector3 startpos, Vector3 endpos, bool includeCanShoot, bool includeCanLeap, bool includeCantLeap, bool includeLevel, MyFunc <float, ISpaceObject, bool> pred)
        {
            List <ISpaceObject> crossed_objects = new List <ISpaceObject>();
            Line line = new Line(startpos, endpos);

            line.IdenticalTransform();

            // 考虑阻挡对结果的影响
            float distance_with_block = -1;
            bool  considerblock       = (includeCanShoot || includeCanLeap || includeCantLeap);

            if (considerblock)
            {
                distance_with_block = (float)GetFirstBlockCellDistance(startpos, endpos, includeCanShoot, includeCanLeap, includeCantLeap, includeLevel);
                if (distance_with_block < 0)
                {
                    considerblock = false;
                }
            }

            m_KdTree.Query(line.GetCenter(), (float)line.GetRadius(), (float distSqr, KdTreeObject kdObj) => {
                ISpaceObject obj = kdObj.SpaceObject;
                if (null != obj)
                {
                    Shape shape = obj.GetCollideShape();
                    if (null != shape)
                    {
                        if (collide_detector_.IsLineCrossShape(line, obj.GetCollideShape()) && pred(distSqr, obj))
                        {
                            if (considerblock)
                            {
                                if (GetDistanceWithPos(obj, startpos) < distance_with_block)
                                {
                                    crossed_objects.Add(obj);
                                }
                            }
                            else
                            {
                                crossed_objects.Add(obj);
                            }
                        }
                    }
                    else
                    {
                        LogSystem.Error("GetObjectCrossByLine:obj({0}[{1}])'s shape is null", obj.GetID(), obj.GetObjType());
                    }
                }
            });

            crossed_objects.Sort((obj1, obj2) => {
                float d1 = GetDistanceWithPos(obj1, startpos);
                float d2 = GetDistanceWithPos(obj2, startpos);
                if (d1 > d2)
                {
                    return(1);
                }
                else if (Math.Abs(d1 - d2) < 0.0001)
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            });
            return(crossed_objects);
        }
Ejemplo n.º 6
0
        public bool IsObjectInArea(ISpaceObject obj, Shape area)
        {
            if (null == obj || null == area)
            {
                return(false);
            }
            Shape shape = obj.GetCollideShape();

            if (null == shape)
            {
                LogSystem.Error("IsObjectInArea:obj({0}[{1}])'s shape is null", obj.GetID(), obj.GetObjType());
                return(false);
            }
            return(collide_detector_.Intersect(shape, area));
        }
Ejemplo n.º 7
0
 private uint CalcSpaceObjectKey(ISpaceObject obj)
 {
     //注意:这里假设obj.GetID()<0x10000000,应该不会有超过这个的id
     return(((uint)obj.GetObjType() << 24) | obj.GetID());
 }
Ejemplo n.º 8
0
 private bool IsAllreadyCollide(ISpaceObject hiter, ISpaceObject dest)
 {
     foreach (ISpaceObject collide_obj in hiter.GetCollideObjects())
     {
         if (collide_obj.GetID() == dest.GetID() && collide_obj.GetObjType() == dest.GetObjType())
         {
             return(true);
         }
     }
     return(false);
 }