Exemplo n.º 1
0
 static public List <ZDObject> HitAtObject(ZDObject Target, EObjectType Type)
 {
     if (Recorder.ContainsKey(Target))
     {
         List <ZDObject> Result       = new List <ZDObject>();
         ZDObjectRecord  TargetRecord = Recorder[Target];
         (uint, uint)Origin = TargetRecord.Location;
         ZDObject Caller = TargetRecord.Owner;
         (int, int)OffsetLoc;
         foreach (var region in Caller.Regions)
         {
             OffsetLoc = ((int)Origin.Item1 + region.Key.x, (int)Origin.Item2 + region.Key.y);
             if (IsValidMapLoc(OffsetLoc.Item1, OffsetLoc.Item2))
             {
                 List <ZDObject> GetList = RecordGrid[OffsetLoc.Item1, OffsetLoc.Item2].GetTypeList(Type);
                 if (GetList != null)
                 {
                     Result.AddRange(GetList);
                 }
             }
         }
         if (Result.Count != 0)
         {
             return(Result);
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        static public void Register(ZDObject Caller)
        {
            // -- Preparation --
            //Force caller to adjust its position on the map.
            RevisePosition(Caller);

            // -- Register start --
            // Check if caller already registered.
            if (IsRegistered(Caller))
            {
                //if registed update its location in map.
                UpdateLocation(Caller);
                return;
            }
            //if caller is not registered
            (uint, uint)MapLoc = WorldToMap(Caller.transform.position);

            //Create Caller Record.
            Recorder[Caller] = new ZDObjectRecord
            {
                Location = MapLoc,
                Owner    = Caller,
            };
            AddToRecordGrids(Recorder[Caller]);
            return;
        }
Exemplo n.º 3
0
        static void AddToRecordGrids(ZDObjectRecord CallerRecord)
        {
            (uint, uint)Origin = CallerRecord.Location;
            ZDObject Caller = CallerRecord.Owner;

            (int, int)OffsetLoc;
            foreach (var region in Caller.Regions)
            {
                OffsetLoc = ((int)Origin.Item1 + region.Key.x, (int)Origin.Item2 + region.Key.y);
                if (IsValidMapLoc(OffsetLoc.Item1, OffsetLoc.Item2))
                {
                    //add caller into new location
                    RecordGrid[OffsetLoc.Item1, OffsetLoc.Item2].Add(Caller, region.Value);
                }
            }
        }
Exemplo n.º 4
0
        static bool RemoveFromRecordGrids(ZDObjectRecord CallerRecord)
        {
            bool Result = true;

            (uint, uint)Origin = CallerRecord.Location;
            ZDObject Caller = CallerRecord.Owner;

            (int, int)OffsetLoc;
            foreach (var region in Caller.Regions)
            {
                OffsetLoc = ((int)Origin.Item1 + region.Key.x, (int)Origin.Item2 + region.Key.y);
                if (IsValidMapLoc(OffsetLoc.Item1, OffsetLoc.Item2))
                {
                    //add caller into new location
                    Result &= RecordGrid[OffsetLoc.Item1, OffsetLoc.Item2].Remove(Caller);
                }
            }
            return(Result);
        }