Пример #1
0
        static public void RevisePosition(ZDObject Caller)
        {
            Vector3 UnitLoc = ZDGameRule.WorldToUnit(Caller.transform.position);

            if (Mathf.Abs(UnitLoc.x) > ZDGameRule.MAP_WIDTH_UNIT / 2)
            {
                UnitLoc.x = (UnitLoc.x > 0 ? 1 : -1) * ZDGameRule.MAP_WIDTH_UNIT / 2;
            }
            if (Mathf.Abs(UnitLoc.y) > ZDGameRule.MAP_HEIGHT_UNIT / 2)
            {
                UnitLoc.y = (UnitLoc.y > 0 ? 1 : -1) * ZDGameRule.MAP_HEIGHT_UNIT / 2;
            }
            Caller.transform.position = ZDGameRule.UnitToWorld(UnitLoc);
        }
Пример #2
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);
                }
            }
        }
Пример #3
0
 static public void UnRegister(ZDObject Caller)
 {
     //Chec if caller is registered
     if (IsRegistered(Caller))
     {
         if (RemoveFromRecordGrids(Recorder[Caller]))
         {
             //clear object record.
             Recorder.Remove(Caller);
         }
         else
         {
             //TODO: Log Error -> This must not happen in general.
             return;
         }
     }
 }
Пример #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);
        }
Пример #5
0
 public bool Remove(ZDObject TargetObj)
 {
     if (Passengers.ContainsKey(TargetObj))
     {
         bool Result = true;
         foreach (var Type in Passengers[TargetObj])
         {
             ref List <ZDObject> TargetList = ref CategorizeList[(int)Type];
             if (TargetList == null)
             {
                 return(false);
             }
             Result &= TargetList.Remove(TargetObj);
             if (TargetList.Count == 0)
             {
                 TargetList = null;
             }
         }
         Result &= Passengers.Remove(TargetObj);
         return(Result);
     }
Пример #6
0
 static public List <ZDObject> HitAt(Vector2 input, ZDObject Caller, EObjectType Type)
 {
     return(HitAt((int)input.x, (int)input.y, Caller, Type));
 }
Пример #7
0
 public bool Exists(ZDObject TargetObj)
 {
     return(Passengers.ContainsKey(TargetObj));
 }
Пример #8
0
 static public bool IsRegistered(ZDObject Caller)
 {
     return(Recorder.ContainsKey(Caller));
 }